mirror of
https://github.com/magefree/mage.git
synced 2025-12-24 12:31:59 -08:00
add nullchecks on watchers
This commit is contained in:
parent
5cab28182d
commit
95a31759b5
53 changed files with 134 additions and 85 deletions
|
|
@ -20,6 +20,6 @@ public enum AttackedThisTurnCondition implements Condition {
|
|||
@Override
|
||||
public boolean apply(Game game, Ability source) {
|
||||
AttackedThisTurnWatcher watcher = (AttackedThisTurnWatcher) game.getState().getWatchers().get(AttackedThisTurnWatcher.class.getSimpleName());
|
||||
return !watcher.getAttackedThisTurnCreatures().isEmpty();
|
||||
return watcher != null && !watcher.getAttackedThisTurnCreatures().isEmpty();
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -19,7 +19,7 @@ public enum LiveLostLastTurnCondition implements Condition {
|
|||
public boolean apply(Game game, Ability source) {
|
||||
PlayerLostLifeWatcher watcher = (PlayerLostLifeWatcher) game.getState().getWatchers().get(PlayerLostLifeWatcher.class.getSimpleName());
|
||||
if (watcher != null) {
|
||||
return watcher.getLiveLostLastTurn(source.getControllerId()) > 0;
|
||||
return watcher.getLifeLostLastTurn(source.getControllerId()) > 0;
|
||||
} else {
|
||||
WatcherUtils.logMissingWatcher(game, source, PlayerLostLifeWatcher.class, this.getClass());
|
||||
}
|
||||
|
|
|
|||
|
|
@ -17,7 +17,7 @@ public enum MorbidCondition implements Condition {
|
|||
@Override
|
||||
public boolean apply(Game game, Ability source) {
|
||||
Watcher watcher = game.getState().getWatchers().get(MorbidWatcher.class.getSimpleName());
|
||||
return watcher.conditionMet();
|
||||
return watcher != null && watcher.conditionMet();
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
|||
|
|
@ -24,6 +24,9 @@ public enum NoSpellsWereCastLastTurnCondition implements Condition {
|
|||
}
|
||||
|
||||
CastSpellLastTurnWatcher watcher = (CastSpellLastTurnWatcher) game.getState().getWatchers().get(CastSpellLastTurnWatcher.class.getSimpleName());
|
||||
if(watcher == null){
|
||||
return false;
|
||||
}
|
||||
// if any player cast spell, return false
|
||||
for (Integer count : watcher.getAmountOfSpellsCastOnPrevTurn().values()) {
|
||||
if (count > 0) {
|
||||
|
|
|
|||
|
|
@ -26,7 +26,7 @@ public class OpponentLostLifeCondition extends IntCompareCondition {
|
|||
PlayerLostLifeWatcher watcher = (PlayerLostLifeWatcher) game.getState().getWatchers().get(PlayerLostLifeWatcher.class.getSimpleName());
|
||||
if (watcher != null) {
|
||||
for (UUID opponentId : game.getOpponents(source.getControllerId())) {
|
||||
int lostLive = watcher.getLiveLost(opponentId);
|
||||
int lostLive = watcher.getLifeLost(opponentId);
|
||||
if (lostLive > maxLostLive) {
|
||||
maxLostLive = lostLive;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -16,6 +16,9 @@ public enum TwoOrMoreSpellsWereCastLastTurnCondition implements Condition {
|
|||
@Override
|
||||
public boolean apply(Game game, Ability source) {
|
||||
CastSpellLastTurnWatcher watcher = (CastSpellLastTurnWatcher) game.getState().getWatchers().get(CastSpellLastTurnWatcher.class.getSimpleName());
|
||||
if(watcher == null){
|
||||
return false;
|
||||
}
|
||||
// if any player cast more than two spells, return true
|
||||
for (Integer count : watcher.getAmountOfSpellsCastOnPrevTurn().values()) {
|
||||
if (count >= 2) {
|
||||
|
|
|
|||
|
|
@ -14,7 +14,10 @@ public class ZuberasDiedDynamicValue implements DynamicValue {
|
|||
@Override
|
||||
public int calculate(Game game, Ability sourceAbility, Effect effect) {
|
||||
ZuberasDiedWatcher watcher = (ZuberasDiedWatcher) game.getState().getWatchers().get(ZuberasDiedWatcher.class.getSimpleName());
|
||||
return watcher.zuberasDiedThisTurn;
|
||||
if(watcher == null){
|
||||
return 0;
|
||||
}
|
||||
return watcher.zuberasDiedThisTurn;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
|||
|
|
@ -75,19 +75,21 @@ class GravestormEffect extends OneShotEffect {
|
|||
MageObjectReference spellRef = (MageObjectReference) this.getValue("GravestormSpellRef");
|
||||
if (spellRef != null) {
|
||||
GravestormWatcher watcher = (GravestormWatcher) game.getState().getWatchers().get(GravestormWatcher.class.getSimpleName());
|
||||
int gravestormCount = watcher.getGravestormCount();
|
||||
if (gravestormCount > 0) {
|
||||
Spell spell = (Spell) this.getValue("GravestormSpell");
|
||||
if (spell != null) {
|
||||
if (!game.isSimulation()) {
|
||||
game.informPlayers("Gravestorm: " + spell.getName() + " will be copied " + gravestormCount + " time" + (gravestormCount > 1 ? "s" : ""));
|
||||
}
|
||||
for (int i = 0; i < gravestormCount; i++) {
|
||||
spell.createCopyOnStack(game, source, source.getControllerId(), true);
|
||||
if(watcher != null) {
|
||||
int gravestormCount = watcher.getGravestormCount();
|
||||
if (gravestormCount > 0) {
|
||||
Spell spell = (Spell) this.getValue("GravestormSpell");
|
||||
if (spell != null) {
|
||||
if (!game.isSimulation()) {
|
||||
game.informPlayers("Gravestorm: " + spell.getName() + " will be copied " + gravestormCount + " time" + (gravestormCount > 1 ? "s" : ""));
|
||||
}
|
||||
for (int i = 0; i < gravestormCount; i++) {
|
||||
spell.createCopyOnStack(game, source, source.getControllerId(), true);
|
||||
}
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -49,7 +49,7 @@ public class PlayerLostLifeWatcher extends Watcher {
|
|||
}
|
||||
}
|
||||
|
||||
public int getLiveLost(UUID playerId) {
|
||||
public int getLifeLost(UUID playerId) {
|
||||
return amountOfLifeLostThisTurn.getOrDefault(playerId, 0);
|
||||
}
|
||||
|
||||
|
|
@ -64,7 +64,7 @@ public class PlayerLostLifeWatcher extends Watcher {
|
|||
return amount;
|
||||
}
|
||||
|
||||
public int getLiveLostLastTurn(UUID playerId) {
|
||||
public int getLifeLostLastTurn(UUID playerId) {
|
||||
return amountOfLifeLostLastTurn.getOrDefault(playerId, 0);
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue