Skip to content

Commit

Permalink
Implement spread-teammates for spawns
Browse files Browse the repository at this point in the history
Signed-off-by: BT (calcastor/mame) <[email protected]>
  • Loading branch information
calcastor committed Jul 21, 2022
1 parent 5726ad9 commit 2d3f992
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 5 deletions.
10 changes: 8 additions & 2 deletions core/src/main/java/tc/oc/pgm/points/SpreadPointProvider.java
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,12 @@ public class SpreadPointProvider extends AggregatePointProvider {

private static final int SAMPLE_COUNT = 16;

public SpreadPointProvider(Collection<? extends PointProvider> children) {
private final boolean spreadTeammates;

public SpreadPointProvider(
Collection<? extends PointProvider> children, boolean spreadTeammates) {
super(children);
this.spreadTeammates = spreadTeammates;
}

@Override
Expand All @@ -34,7 +38,9 @@ public Location getPoint(Match match, @Nullable Entity entity) {
for (MatchPlayer enemy : match.getParticipants()) {
if (enemy.isParticipating()
&& !enemy.isDead()
&& (player == null || player.getParty() != enemy.getParty())) {
&& (player == null
|| player.getParty() != enemy.getParty()
|| this.spreadTeammates)) {
nearest = Math.min(nearest, pos.distanceSquared(enemy.getBukkit().getLocation()));
}
}
Expand Down
13 changes: 12 additions & 1 deletion core/src/main/java/tc/oc/pgm/spawns/SpawnAttributes.java
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ public class SpawnAttributes {
public final Kit kit;
public final boolean sequential;
public final boolean spread;
public final boolean spreadTeammates;
public final boolean exclusive;
public final boolean persistent;

Expand All @@ -20,18 +21,28 @@ public SpawnAttributes(
Kit kit,
boolean sequential,
boolean spread,
boolean spreadTeammates,
boolean exclusive,
boolean persistent) {
this.filter = filter;
this.providerAttributes = providerAttributes;
this.kit = kit;
this.sequential = sequential;
this.spread = spread;
this.spreadTeammates = spreadTeammates;
this.exclusive = exclusive;
this.persistent = persistent;
}

public SpawnAttributes() {
this(StaticFilter.ABSTAIN, new PointProviderAttributes(), null, false, false, false, false);
this(
StaticFilter.ABSTAIN,
new PointProviderAttributes(),
null,
false,
false,
false,
false,
false);
}
}
8 changes: 6 additions & 2 deletions core/src/main/java/tc/oc/pgm/spawns/SpawnParser.java
Original file line number Diff line number Diff line change
Expand Up @@ -63,8 +63,8 @@ else if (el.getChild("regions") != null
PointProvider provider;
if (attributes.sequential) {
provider = new SequentialPointProvider(providers);
} else if (attributes.spread) {
provider = new SpreadPointProvider(providers);
} else if (attributes.spread || attributes.spreadTeammates) {
provider = new SpreadPointProvider(providers, attributes.spreadTeammates);
} else {
provider = new RandomPointProvider(providers);
}
Expand Down Expand Up @@ -101,6 +101,8 @@ public SpawnAttributes parseAttributes(Element el, SpawnAttributes parent)

boolean sequential = XMLUtils.parseBoolean(el.getAttribute("sequential"), parent.sequential);
boolean spread = XMLUtils.parseBoolean(el.getAttribute("spread"), parent.spread);
boolean spreadTeammates =
XMLUtils.parseBoolean(el.getAttribute("spread-teammates"), parent.spreadTeammates);
boolean exclusive = XMLUtils.parseBoolean(el.getAttribute("exclusive"), parent.exclusive);
boolean persistent = XMLUtils.parseBoolean(el.getAttribute("persistent"), parent.persistent);

Expand Down Expand Up @@ -130,6 +132,7 @@ public SpawnAttributes parseAttributes(Element el, SpawnAttributes parent)
&& kit == parent.kit
&& sequential == parent.sequential
&& spread == parent.spread
&& spreadTeammates == parent.spreadTeammates
&& exclusive == parent.exclusive
&& persistent == parent.persistent
&& !newFilters) {
Expand All @@ -142,6 +145,7 @@ public SpawnAttributes parseAttributes(Element el, SpawnAttributes parent)
kit,
sequential,
spread,
spreadTeammates,
exclusive,
persistent);
}
Expand Down

0 comments on commit 2d3f992

Please sign in to comment.