Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Reintroduce friendly fire #981

Merged
merged 1 commit into from
Apr 2, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions core/src/main/java/tc/oc/pgm/api/map/MapInfo.java
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,13 @@ default String getStyledNameLegacy(MapNameStyle style, @Nullable CommandSender s
*/
Phase getPhase();

/**
* Get whether friendly fire should be on or off.
*
* @return True if friendly fire is on.
*/
boolean getFriendlyFire();

/**
* Create an immutable copy of this info.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ public Filter.QueryResponse queryDefaultRules(ParticipantState victim, DamageInf
}

case ALLY:
if (!isAllowedTeamDamage(damageInfo)) {
if (!match.getMap().getFriendlyFire() && !isAllowedTeamDamage(damageInfo)) {
return Filter.QueryResponse.DENY;
}

Expand Down
17 changes: 14 additions & 3 deletions core/src/main/java/tc/oc/pgm/map/MapInfoImpl.java
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ public class MapInfoImpl implements MapInfo {
private final Component gamemode;
private final int difficulty;
private final WorldInfo world;
private final boolean friendlyFire;

protected final Collection<MapTag> tags;
protected final Collection<Integer> players;
Expand All @@ -66,7 +67,8 @@ public MapInfoImpl(
@Nullable WorldInfo world,
@Nullable Component gamemode,
@Nullable Collection<Gamemode> gamemodes,
Phase phase) {
Phase phase,
@Nullable boolean friendlyFire) {
this.name = checkNotNull(name);
this.id = checkNotNull(MapInfo.normalizeName(id == null ? name : id));
this.proto = checkNotNull(proto);
Expand All @@ -83,6 +85,7 @@ public MapInfoImpl(
this.gamemode = gamemode;
this.gamemodes = gamemodes;
this.phase = phase;
this.friendlyFire = friendlyFire;
}

public MapInfoImpl(MapInfo info) {
Expand All @@ -102,7 +105,8 @@ public MapInfoImpl(MapInfo info) {
info.getWorld(),
info.getGamemode(),
info.getGamemodes(),
info.getPhase());
info.getPhase(),
info.getFriendlyFire());
}

public MapInfoImpl(Element root) throws InvalidXMLException {
Expand All @@ -128,7 +132,9 @@ public MapInfoImpl(Element root) throws InvalidXMLException {
XMLUtils.parseFormattedText(root, "game"),
parseGamemodes(root),
XMLUtils.parseEnum(
Node.fromLastChildOrAttr(root, "phase"), Phase.class, "phase", Phase.PRODUCTION));
Node.fromLastChildOrAttr(root, "phase"), Phase.class, "phase", Phase.PRODUCTION),
XMLUtils.parseBoolean(
Node.fromLastChildOrAttr(root, "friendlyfire", "friendly-fire"), false));
}

@Override
Expand Down Expand Up @@ -211,6 +217,11 @@ public Phase getPhase() {
return phase;
}

@Override
public boolean getFriendlyFire() {
return friendlyFire;
}

@Override
public int hashCode() {
return getId().hashCode();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ protected void updatePartyScoreboardTeam(Party party, Team team, boolean forObse
team.setSuffix(ChatColor.WHITE.toString());

team.setCanSeeFriendlyInvisibles(true);
team.setAllowFriendlyFire(false);
team.setAllowFriendlyFire(match.getMap().getFriendlyFire());

if (!forObservers && party instanceof Competitor) {
NameTagVisibility nameTags = ((Competitor) party).getNameTagVisibility();
Expand Down