Stage 13: Perks and Totems
This commit is contained in:
parent
d1f854fc79
commit
37e67ce97d
23 changed files with 2070 additions and 25 deletions
76
src/main/java/dev/loki/hatch/HatchCondition.java
Normal file
76
src/main/java/dev/loki/hatch/HatchCondition.java
Normal file
|
|
@ -0,0 +1,76 @@
|
|||
package dev.loki.hatch;
|
||||
|
||||
import dev.loki.player.BasePlayer;
|
||||
import dev.loki.player.PlayerState;
|
||||
|
||||
import java.util.Collection;
|
||||
|
||||
public class HatchCondition {
|
||||
private final int minSurvivorsForOpen;
|
||||
|
||||
public HatchCondition(int minSurvivorsForOpen) {
|
||||
this.minSurvivorsForOpen = minSurvivorsForOpen;
|
||||
}
|
||||
|
||||
public boolean shouldSpawn(Collection<BasePlayer> players, int repairedGenerators) {
|
||||
int aliveSurvivors = countAliveSurvivors(players);
|
||||
return aliveSurvivors <= repairedGenerators;
|
||||
}
|
||||
|
||||
public boolean shouldOpen(Hatch hatch, Collection<BasePlayer> players, int repairedGenerators) {
|
||||
if (hatch.isOpen()) return false;
|
||||
if (!hatch.isClosed() && !hatch.isHidden()) return false;
|
||||
|
||||
return shouldSpawn(players, repairedGenerators);
|
||||
}
|
||||
|
||||
public boolean canOpen(Hatch hatch, Collection<BasePlayer> players, int repairedGenerators) {
|
||||
if (!hatch.isHidden() && !hatch.isClosed()) return false;
|
||||
|
||||
int aliveSurvivors = countAliveSurvivors(players);
|
||||
int requiredGens = Math.max(minSurvivorsForOpen, aliveSurvivors);
|
||||
|
||||
return repairedGenerators >= requiredGens;
|
||||
}
|
||||
|
||||
public int countAliveSurvivors(Collection<BasePlayer> players) {
|
||||
return (int) players.stream()
|
||||
.filter(p -> !p.isKiller())
|
||||
.filter(this::isAlive)
|
||||
.count();
|
||||
}
|
||||
|
||||
private boolean isAlive(BasePlayer player) {
|
||||
PlayerState state = player.getState();
|
||||
return state != PlayerState.DEAD
|
||||
&& state != PlayerState.ESCAPED
|
||||
&& state != PlayerState.HOOKED;
|
||||
}
|
||||
|
||||
public int getRemainingAlive(Collection<BasePlayer> players) {
|
||||
return countAliveSurvivors(players);
|
||||
}
|
||||
|
||||
public boolean isLastSurvivor(Collection<BasePlayer> players) {
|
||||
return countAliveSurvivors(players) == 1;
|
||||
}
|
||||
|
||||
public boolean checkAndReveal(Hatch hatch, Collection<BasePlayer> players, int repairedGenerators) {
|
||||
if (hatch.isHidden() && shouldSpawn(players, repairedGenerators)) {
|
||||
hatch.reveal();
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public boolean checkAndOpen(Hatch hatch, Collection<BasePlayer> players, int repairedGenerators) {
|
||||
if (canOpen(hatch, players, repairedGenerators)) {
|
||||
if (hatch.isHidden()) {
|
||||
hatch.reveal();
|
||||
}
|
||||
hatch.open();
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue