Skip to content

Commit f5e7a45

Browse files
committed
feat: allow multiple gates per flag
1 parent b7b9737 commit f5e7a45

File tree

3 files changed

+32
-12
lines changed

3 files changed

+32
-12
lines changed

src/main/java/io/github/restioson/siege/game/active/SiegeSidebar.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ public void update(long time) {
6868
Text line;
6969
if (capturing || percent > 0) {
7070
line = Text.literal("(" + percent + "%) ").append(flagName);
71-
} else if (flag.gate != null && time - flag.gate.timeOfLastBash < 5 * 20) {
71+
} else if (flag.gateUnderAttack(time)) {
7272
line = Text.literal("(!) ").append(flagName);
7373
} else {
7474
line = flagName;

src/main/java/io/github/restioson/siege/game/map/SiegeFlag.java

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -36,8 +36,7 @@ public final class SiegeFlag {
3636
@Nullable
3737
public SiegeSpawn defenderRespawn;
3838

39-
@Nullable
40-
public SiegeGate gate;
39+
public List<SiegeGate> gates;
4140

4241
public GameTeam team;
4342

@@ -172,6 +171,18 @@ public void closeCaptureBar() {
172171
public boolean isFrontLine(long time) {
173172
CapturingState state = this.capturingState;
174173
return (state != null && state.hasAlert() && state != CapturingState.SECURING)
175-
|| (this.gate != null && time - this.gate.timeOfLastBash < 5 * 20);
174+
|| (this.gateUnderAttack(time));
175+
}
176+
177+
public boolean gateUnderAttack(long time) {
178+
long lastBash = this.gates
179+
.stream()
180+
.map(gate -> gate.timeOfLastBash)
181+
.max(Long::compareTo)
182+
.stream()
183+
.findAny()
184+
.orElse(0L);
185+
186+
return time - lastBash < 5 * 20;
176187
}
177188
}

src/main/java/io/github/restioson/siege/game/map/SiegeMapLoader.java

Lines changed: 17 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -211,18 +211,27 @@ private void addFlagsToMap(SiegeMap map, MapTemplateMetadata metadata) {
211211
.map(region -> {
212212
NbtCompound data = region.getData();
213213

214-
String id = data.getString("id");
215-
SiegeFlag flag = flags.get(id);
214+
String gateId = data.getString("id");
215+
String flagIdRaw = data.getString("flag");
216+
final String flagId = flagIdRaw.isEmpty() ? gateId : flagIdRaw;
217+
218+
SiegeFlag flag = flags.get(flagId);
216219
if (flag == null) {
217-
throw new GameOpenException(Text.literal("Gate missing flag with id '" + id + "'!"));
220+
var text = Text.literal(String.format("Gate (id '%s') missing flag with id '%s'!", gateId, flagId));
221+
222+
if (flagIdRaw.isEmpty()) {
223+
text = text.append(Text.literal("\nNote: flag id was implicitly defined as the gate id, as `flag` was missing in data."));
224+
}
225+
226+
throw new GameOpenException(text);
218227
}
219228

220229
TemplateRegion portcullisRegion = metadata.getRegions("portcullis")
221-
.filter(r -> id.equalsIgnoreCase(r.getData().getString("id")))
230+
.filter(r -> gateId.equalsIgnoreCase(r.getData().getString("id")))
222231
.findFirst()
223232
.orElseThrow(() -> {
224-
Siege.LOGGER.error("Gate \"{}\" missing portcullis!", id);
225-
return new GameOpenException(Text.literal("Gate missing portcullis!"));
233+
Siege.LOGGER.error("Gate \"{}\" missing portcullis!", gateId);
234+
return new GameOpenException(Text.literal(String.format("Gate (id '%s') missing portcullis!", gateId)));
226235
});
227236

228237
NbtCompound portcullisData = portcullisRegion.getData();
@@ -241,13 +250,13 @@ private void addFlagsToMap(SiegeMap map, MapTemplateMetadata metadata) {
241250
}
242251

243252
BlockBounds brace = metadata.getRegions("gate_brace")
244-
.filter(r -> id.equalsIgnoreCase(r.getData().getString("id")))
253+
.filter(r -> flagId.equalsIgnoreCase(r.getData().getString("id")))
245254
.map(TemplateRegion::getBounds)
246255
.findFirst()
247256
.orElse(null);
248257

249258
SiegeGate gate = new SiegeGate(flag, region.getBounds(), portcullisRegion.getBounds(), brace, retractHeight, repairHealthThreshold, maxHealth);
250-
flag.gate = gate;
259+
flag.gates.add(gate);
251260
return gate;
252261
})
253262
.collect(Collectors.toList());

0 commit comments

Comments
 (0)