Skip to content

Commit

Permalink
Implement friendly fire (#981)
Browse files Browse the repository at this point in the history
Signed-off-by: uozuols <[email protected]>
  • Loading branch information
uozuols authored Apr 2, 2022
1 parent a10e032 commit c2e2388
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 5 deletions.
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
2 changes: 1 addition & 1 deletion core/src/main/java/tc/oc/pgm/damage/DamageMatchModule.java
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

0 comments on commit c2e2388

Please sign in to comment.