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

Implement spread-teammates for spawns #1032

Merged
merged 1 commit into from
Jul 22, 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
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