Fixed potential NPE errors in getPhase usage (fixed Berserker's Frenzy, etc)

This commit is contained in:
Oleg Agafonov 2023-03-25 16:01:27 +04:00
parent cfd7464b49
commit a15a0daa04
81 changed files with 162 additions and 130 deletions

View file

@ -164,8 +164,8 @@ public class GameView implements Serializable {
companion.add(new RevealedView(name, state.getCompanion().get(name), game)); companion.add(new RevealedView(name, state.getCompanion().get(name), game));
} }
} }
this.phase = state.getTurn().getPhaseType(); this.phase = state.getTurnPhaseType();
this.step = state.getTurn().getStepType(); this.step = state.getTurnStepType();
this.turn = state.getTurnNum(); this.turn = state.getTurnNum();
this.activePlayerId = state.getActivePlayerId(); this.activePlayerId = state.getActivePlayerId();
if (state.getActivePlayerId() != null) { if (state.getActivePlayerId() != null) {

View file

@ -248,7 +248,7 @@ public class ComputerPlayer6 extends ComputerPlayer /*implements Player*/ {
} }
val = minimaxAB(node, depth - 1, alpha, beta); val = minimaxAB(node, depth - 1, alpha, beta);
} else { } else {
logger.trace("Add Action -- alpha: " + alpha + " beta: " + beta + " depth:" + depth + " step:" + game.getTurn().getStepType() + " for player:" + game.getPlayer(game.getActivePlayerId()).getName()); logger.trace("Add Action -- alpha: " + alpha + " beta: " + beta + " depth:" + depth + " step:" + game.getTurnStepType() + " for player:" + game.getPlayer(game.getActivePlayerId()).getName());
if (allPassed(game)) { if (allPassed(game)) {
if (!game.getStack().isEmpty()) { if (!game.getStack().isEmpty()) {
resolve(node, depth, game); resolve(node, depth, game);
@ -291,7 +291,7 @@ public class ComputerPlayer6 extends ComputerPlayer /*implements Player*/ {
} }
} }
node.setScore(val); node.setScore(val);
logger.trace("returning -- score: " + val + " depth:" + depth + " step:" + game.getTurn().getStepType() + " for player:" + game.getPlayer(node.getPlayerId()).getName()); logger.trace("returning -- score: " + val + " depth:" + depth + " step:" + game.getTurnStepType() + " for player:" + game.getPlayer(node.getPlayerId()).getName());
return val; return val;
} }

View file

@ -45,10 +45,10 @@ public class ComputerPlayer7 extends ComputerPlayer6 {
logger.info("======================= Turn: " + game.getTurnNum() + " [" + game.getPlayer(game.getActivePlayerId()).getName() + "] ========================================="); logger.info("======================= Turn: " + game.getTurnNum() + " [" + game.getPlayer(game.getActivePlayerId()).getName() + "] =========================================");
} }
logState(game); logState(game);
logger.debug("Priority -- Step: " + (game.getTurn().getStepType() + " ").substring(0, 25) + " ActivePlayer-" + game.getPlayer(game.getActivePlayerId()).getName() + " PriorityPlayer-" + name); logger.debug("Priority -- Step: " + (game.getTurnStepType() + " ").substring(0, 25) + " ActivePlayer-" + game.getPlayer(game.getActivePlayerId()).getName() + " PriorityPlayer-" + name);
game.getState().setPriorityPlayerId(playerId); game.getState().setPriorityPlayerId(playerId);
game.firePriorityEvent(playerId); game.firePriorityEvent(playerId);
switch (game.getTurn().getStepType()) { switch (game.getTurnStepType()) {
case UPKEEP: case UPKEEP:
case DRAW: case DRAW:
pass(game); pass(game);

View file

@ -1266,7 +1266,7 @@ public class ComputerPlayer extends PlayerImpl implements Player {
if (game.isMainPhase() && game.getStack().isEmpty()) { if (game.isMainPhase() && game.getStack().isEmpty()) {
playLand(game); playLand(game);
} }
switch (game.getTurn().getStepType()) { switch (game.getTurnStepType()) {
case UPKEEP: case UPKEEP:
findPlayables(game); findPlayables(game);
break; break;
@ -1331,7 +1331,7 @@ public class ComputerPlayer extends PlayerImpl implements Player {
} }
} else { } else {
//respond to opponent events //respond to opponent events
switch (game.getTurn().getStepType()) { switch (game.getTurnStepType()) {
case UPKEEP: case UPKEEP:
findPlayables(game); findPlayables(game);
break; break;

View file

@ -61,7 +61,7 @@ public class ComputerPlayerMCTS extends ComputerPlayer implements Player {
@Override @Override
public boolean priority(Game game) { public boolean priority(Game game) {
if (game.getStep().getType() == PhaseStep.UPKEEP) { if (game.getTurnStepType() == PhaseStep.UPKEEP) {
if (!lastPhase.equals(game.getTurn().getValue(game.getTurnNum()))) { if (!lastPhase.equals(game.getTurn().getValue(game.getTurnNum()))) {
logList(game.getTurn().getValue(game.getTurnNum()) + name + " hand: ", new ArrayList(hand.getCards(game))); logList(game.getTurn().getValue(game.getTurnNum()) + name + " hand: ", new ArrayList(hand.getCards(game)));
lastPhase = game.getTurn().getValue(game.getTurnNum()); lastPhase = game.getTurn().getValue(game.getTurnNum());
@ -236,7 +236,7 @@ public class ComputerPlayerMCTS extends ComputerPlayer implements Player {
if (root.getNumChildren() > 0) if (root.getNumChildren() > 0)
nodeSizeRatio = root.getVisits() / root.getNumChildren(); nodeSizeRatio = root.getVisits() / root.getNumChildren();
// logger.info("Ratio: " + nodeSizeRatio); // logger.info("Ratio: " + nodeSizeRatio);
PhaseStep curStep = game.getStep().getType(); PhaseStep curStep = game.getTurnStepType();
if (action == NextAction.SELECT_ATTACKERS || action == NextAction.SELECT_BLOCKERS) { if (action == NextAction.SELECT_ATTACKERS || action == NextAction.SELECT_BLOCKERS) {
if (nodeSizeRatio < THINK_MIN_RATIO) { if (nodeSizeRatio < THINK_MIN_RATIO) {
thinkTime = maxThinkTime; thinkTime = maxThinkTime;

View file

@ -89,7 +89,7 @@ public class MCTSNode {
if (game.getStep().getStepPart() == StepPart.PRIORITY) { if (game.getStep().getStepPart() == StepPart.PRIORITY) {
playerId = game.getPriorityPlayerId(); playerId = game.getPriorityPlayerId();
} else { } else {
if (game.getStep().getType() == PhaseStep.DECLARE_BLOCKERS) { if (game.getTurnStepType() == PhaseStep.DECLARE_BLOCKERS) {
playerId = game.getCombat().getDefenders().iterator().next(); playerId = game.getCombat().getDefenders().iterator().next();
} else { } else {
playerId = game.getActivePlayerId(); playerId = game.getActivePlayerId();
@ -129,7 +129,7 @@ public class MCTSNode {
} }
switch (player.getNextAction()) { switch (player.getNextAction()) {
case PRIORITY: case PRIORITY:
// logger.info("Priority for player:" + player.getName() + " turn: " + game.getTurnNum() + " phase: " + game.getPhase().getType() + " step: " + game.getStep().getType()); // logger.info("Priority for player:" + player.getName() + " turn: " + game.getTurnNum() + " phase: " + game.getTurnPhaseType() + " step: " + game.getTurnStepType());
List<Ability> abilities; List<Ability> abilities;
if (!USE_ACTION_CACHE) if (!USE_ACTION_CACHE)
abilities = player.getPlayableOptions(game); abilities = player.getPlayableOptions(game);

View file

@ -1022,7 +1022,7 @@ public class HumanPlayer extends PlayerImpl {
boolean quickStop = false; boolean quickStop = false;
if (isGameUnderControl()) { // TODO: remove to enable quick stop for controlling player if (isGameUnderControl()) { // TODO: remove to enable quick stop for controlling player
// if was attacked - always stop BEFORE blocker step (to cast extra spells) // if was attacked - always stop BEFORE blocker step (to cast extra spells)
if (game.getTurn().getStepType() == PhaseStep.DECLARE_ATTACKERS if (game.getTurnStepType() == PhaseStep.DECLARE_ATTACKERS
&& game.getCombat().getPlayerDefenders(game).contains(playerId)) { && game.getCombat().getPlayerDefenders(game).contains(playerId)) {
FilterCreatureForCombatBlock filter = filterCreatureForCombatBlock.copy(); FilterCreatureForCombatBlock filter = filterCreatureForCombatBlock.copy();
filter.add(new ControllerIdPredicate(playerId)); filter.add(new ControllerIdPredicate(playerId));
@ -1044,7 +1044,7 @@ public class HumanPlayer extends PlayerImpl {
} }
if (passedUntilEndStepBeforeMyTurn) { if (passedUntilEndStepBeforeMyTurn) {
if (game.getTurn().getStepType() != PhaseStep.END_TURN) { if (game.getTurnStepType() != PhaseStep.END_TURN) {
// other step // other step
if (passWithManaPoolCheck(game)) { if (passWithManaPoolCheck(game)) {
return false; return false;
@ -1080,8 +1080,8 @@ public class HumanPlayer extends PlayerImpl {
} }
if (passedUntilNextMain) { if (passedUntilNextMain) {
if (game.getTurn().getStepType() == PhaseStep.POSTCOMBAT_MAIN if (game.getTurnStepType() == PhaseStep.POSTCOMBAT_MAIN
|| game.getTurn().getStepType() == PhaseStep.PRECOMBAT_MAIN) { || game.getTurnStepType() == PhaseStep.PRECOMBAT_MAIN) {
// it's main step // it's main step
if (!skippedAtLeastOnce if (!skippedAtLeastOnce
|| (!playerId.equals(game.getActivePlayerId()) || (!playerId.equals(game.getActivePlayerId())
@ -1103,7 +1103,7 @@ public class HumanPlayer extends PlayerImpl {
} }
if (passedUntilEndOfTurn) { if (passedUntilEndOfTurn) {
if (game.getTurn().getStepType() == PhaseStep.END_TURN) { if (game.getTurnStepType() == PhaseStep.END_TURN) {
// it's end of turn step // it's end of turn step
if (!skippedAtLeastOnce if (!skippedAtLeastOnce
|| (playerId.equals(game.getActivePlayerId()) || (playerId.equals(game.getActivePlayerId())
@ -1271,16 +1271,16 @@ public class HumanPlayer extends PlayerImpl {
try { try {
if (playerId.equals(game.getActivePlayerId())) { if (playerId.equals(game.getActivePlayerId())) {
return !controllingPlayer.getUserData().getUserSkipPrioritySteps().getYourTurn().isPhaseStepSet(game.getStep().getType()); return !controllingPlayer.getUserData().getUserSkipPrioritySteps().getYourTurn().isPhaseStepSet(game.getTurnStepType());
} else { } else {
return !controllingPlayer.getUserData().getUserSkipPrioritySteps().getOpponentTurn().isPhaseStepSet(game.getStep().getType()); return !controllingPlayer.getUserData().getUserSkipPrioritySteps().getOpponentTurn().isPhaseStepSet(game.getTurnStepType());
} }
} catch (NullPointerException ex) { } catch (NullPointerException ex) {
if (controllingPlayer.getUserData() != null) { if (controllingPlayer.getUserData() != null) {
if (controllingPlayer.getUserData().getUserSkipPrioritySteps() != null) { if (controllingPlayer.getUserData().getUserSkipPrioritySteps() != null) {
if (game.getStep() != null) { if (game.getStep() != null) {
if (game.getStep().getType() == null) { if (game.getTurnStepType() == null) {
logger.error("game.getStep().getType() == null"); logger.error("game.getTurnStepType() == null");
} }
} else { } else {
logger.error("game.getStep() == null"); logger.error("game.getStep() == null");
@ -2659,7 +2659,7 @@ public class HumanPlayer extends PlayerImpl {
} }
// TODO: chooseUse and other dialogs must be under controlling player // TODO: chooseUse and other dialogs must be under controlling player
if (!chooseUse(Outcome.Detriment, GameLog.getPlayerConfirmColoredText("You still have mana in your mana pool. Pass regardless?") if (!chooseUse(Outcome.Detriment, GameLog.getPlayerConfirmColoredText("You still have mana in your mana pool. Pass regardless?")
+ GameLog.getSmallSecondLineText(activePlayerText + " / " + game.getStep().getType().toString() + priorityPlayerText), null, game)) { + GameLog.getSmallSecondLineText(activePlayerText + " / " + game.getTurnStepType().toString() + priorityPlayerText), null, game)) {
sendPlayerAction(PlayerAction.PASS_PRIORITY_CANCEL_ALL_ACTIONS, game, null); sendPlayerAction(PlayerAction.PASS_PRIORITY_CANCEL_ALL_ACTIONS, game, null);
return false; return false;
} }

View file

@ -877,7 +877,7 @@ public class GameController implements GameCallback {
private void informOthers(UUID playerId) throws MageException { private void informOthers(UUID playerId) throws MageException {
StringBuilder message = new StringBuilder(); StringBuilder message = new StringBuilder();
if (game.getStep() != null) { if (game.getStep() != null) {
message.append(game.getStep().getType().toString()).append(" - "); message.append(game.getTurnStepType().toString()).append(" - ");
} }
message.append("Waiting for ").append(game.getPlayer(playerId).getLogName()); message.append("Waiting for ").append(game.getPlayer(playerId).getLogName());
for (final Entry<UUID, GameSessionPlayer> entry : getGameSessionsMap().entrySet()) { for (final Entry<UUID, GameSessionPlayer> entry : getGameSessionsMap().entrySet()) {
@ -896,10 +896,10 @@ public class GameController implements GameCallback {
if (players != null && !players.isEmpty()) { if (players != null && !players.isEmpty()) {
controller = game.getPlayer(players.get(0)); controller = game.getPlayer(players.get(0));
} }
if (controller == null || game.getStep() == null || game.getStep().getType() == null) { if (controller == null || game.getStep() == null || game.getTurnStepType() == null) {
return; return;
} }
final String message = new StringBuilder(game.getStep().getType().toString()).append(" - Waiting for ").append(controller.getName()).toString(); final String message = new StringBuilder(game.getTurnStepType().toString()).append(" - Waiting for ").append(controller.getName()).toString();
for (final Entry<UUID, GameSessionPlayer> entry : getGameSessionsMap().entrySet()) { for (final Entry<UUID, GameSessionPlayer> entry : getGameSessionsMap().entrySet()) {
boolean skip = players.stream().anyMatch(playerId -> entry.getKey().equals(playerId)); boolean skip = players.stream().anyMatch(playerId -> entry.getKey().equals(playerId));
if (!skip) { if (!skip) {
@ -1296,10 +1296,10 @@ public class GameController implements GameCallback {
sb.append("<font color='red'>FIX command called by ").append(user.getName()).append("</font>"); sb.append("<font color='red'>FIX command called by ").append(user.getName()).append("</font>");
sb.append("<font size='-2'>"); // font resize start for all next logs sb.append("<font size='-2'>"); // font resize start for all next logs
sb.append("<br>Game ID: ").append(game.getId()); sb.append("<br>Game ID: ").append(game.getId());
if (game.getTurn().getPhaseType() == null) { if (game.getTurnPhaseType() == null) {
sb.append("<br>Phase: not started").append(" Step: not started"); sb.append("<br>Phase: not started").append(" Step: not started");
} else { } else {
sb.append("<br>Phase: ").append(game.getTurn().getPhaseType().toString()).append(" Step: ").append(game.getTurn().getStepType().toString()); sb.append("<br>Phase: ").append(game.getTurnPhaseType().toString()).append(" Step: ").append(game.getTurnStepType().toString());
} }
// pings info // pings info
sb.append("<br>"); sb.append("<br>");

View file

@ -62,7 +62,7 @@ class BeforeCombatDamageCondition implements Condition {
@Override @Override
public boolean apply(Game game, Ability source) { public boolean apply(Game game, Ability source) {
PhaseStep phaseStep = game.getStep().getType(); PhaseStep phaseStep = game.getTurnStepType();
if(phaseStep.getIndex() < PhaseStep.FIRST_COMBAT_DAMAGE.getIndex()) { if(phaseStep.getIndex() < PhaseStep.FIRST_COMBAT_DAMAGE.getIndex()) {
return true; return true;
} }

View file

@ -61,7 +61,7 @@ enum AshenGhoulCondition implements Condition {
@Override @Override
public boolean apply(Game game, Ability source) { public boolean apply(Game game, Ability source) {
Player controller = game.getPlayer(source.getControllerId()); Player controller = game.getPlayer(source.getControllerId());
if (game.getStep().getType() != PhaseStep.UPKEEP if (game.getTurnStepType() != PhaseStep.UPKEEP
|| !game.isActivePlayer(source.getControllerId())) { || !game.isActivePlayer(source.getControllerId())) {
return false; return false;
} }

View file

@ -84,7 +84,7 @@ class BasandraBattleSeraphEffect extends ContinuousRuleModifyingEffectImpl {
@Override @Override
public boolean applies(GameEvent event, Ability source, Game game) { public boolean applies(GameEvent event, Ability source, Game game) {
if (game.getPhase().getType() == TurnPhase.COMBAT) { if (game.getTurnPhaseType() == TurnPhase.COMBAT) {
return true; return true;
} }
return false; return false;

View file

@ -68,8 +68,8 @@ enum BerserkersFrenzyCondition implements Condition {
@Override @Override
public boolean apply(Game game, Ability source) { public boolean apply(Game game, Ability source) {
if (game.getPhase().getType() == TurnPhase.COMBAT) { if (game.getTurnPhaseType() == TurnPhase.COMBAT) {
return game.getStep().getType().isBefore(PhaseStep.DECLARE_BLOCKERS); return game.getTurnStepType().isBefore(PhaseStep.DECLARE_BLOCKERS);
} }
return !game.getTurn().isDeclareAttackersStepStarted(); return !game.getTurn().isDeclareAttackersStepStarted();
} }

View file

@ -132,7 +132,7 @@ class BlindingBeamEffect2 extends ContinuousRuleModifyingEffectImpl {
@Override @Override
public boolean applies(GameEvent event, Ability source, Game game) { public boolean applies(GameEvent event, Ability source, Game game) {
// prevent untap event of creatures of target player // prevent untap event of creatures of target player
if (game.getTurn().getStepType() == PhaseStep.UNTAP) { if (game.getTurnStepType() == PhaseStep.UNTAP) {
Permanent permanent = game.getPermanent(event.getTargetId()); Permanent permanent = game.getPermanent(event.getTargetId());
if (permanent != null && permanent.isControlledBy(targetPlayerId) && filter.match(permanent, game)) { if (permanent != null && permanent.isControlledBy(targetPlayerId) && filter.match(permanent, game)) {
return true; return true;

View file

@ -68,11 +68,11 @@ class BloodFrenzyCastRestriction extends ContinuousRuleModifyingEffectImpl {
@Override @Override
public boolean applies(GameEvent event, Ability source, Game game) { public boolean applies(GameEvent event, Ability source, Game game) {
if(event.getSourceId().equals(source.getSourceId())) { if(event.getSourceId().equals(source.getSourceId())) {
if(game.getPhase().getType() == TurnPhase.COMBAT if(game.getTurnPhaseType() == TurnPhase.COMBAT
// There cannot be a legal target before declare attackers, // There cannot be a legal target before declare attackers,
// so in practice it is limited to these two steps. // so in practice it is limited to these two steps.
&& (game.getStep().getType() == PhaseStep.DECLARE_ATTACKERS && (game.getTurnStepType() == PhaseStep.DECLARE_ATTACKERS
|| game.getStep().getType() == PhaseStep.DECLARE_BLOCKERS)) { || game.getTurnStepType() == PhaseStep.DECLARE_BLOCKERS)) {
return false; return false;
} }
return true; return true;

View file

@ -67,7 +67,7 @@ class CathedralMembraneAbility extends ZoneChangeTriggeredAbility {
@Override @Override
public boolean checkTrigger(GameEvent event, Game game) { public boolean checkTrigger(GameEvent event, Game game) {
if (super.checkTrigger(event, game)) { if (super.checkTrigger(event, game)) {
if (game.getPhase().getType() == TurnPhase.COMBAT) { if (game.getTurnPhaseType() == TurnPhase.COMBAT) {
return true; return true;
} }
} }

View file

@ -153,7 +153,7 @@ class CorrosiveOozeCombatWatcher extends Watcher {
if (event.getType() == GameEvent.EventType.ZONE_CHANGE) { if (event.getType() == GameEvent.EventType.ZONE_CHANGE) {
if (((ZoneChangeEvent) event).getFromZone() == Zone.BATTLEFIELD) { if (((ZoneChangeEvent) event).getFromZone() == Zone.BATTLEFIELD) {
if (game.getTurn() != null && TurnPhase.COMBAT == game.getTurn().getPhaseType()) { if (game.getTurn() != null && TurnPhase.COMBAT == game.getTurnPhaseType()) {
// Check if a previous blocked or blocked by creatures is leaving the battlefield // Check if a previous blocked or blocked by creatures is leaving the battlefield
for (Map.Entry<MageObjectReference, Set<MageObjectReference>> entry : oozeBlocksOrBlocked.entrySet()) { for (Map.Entry<MageObjectReference, Set<MageObjectReference>> entry : oozeBlocksOrBlocked.entrySet()) {
for (MageObjectReference mor : entry.getValue()) { for (MageObjectReference mor : entry.getValue()) {

View file

@ -72,7 +72,7 @@ class BeforeEndCombatCondition implements Condition {
@Override @Override
public boolean apply(Game game, Ability source) { public boolean apply(Game game, Ability source) {
PhaseStep phaseStep = game.getStep().getType(); PhaseStep phaseStep = game.getTurnStepType();
if(phaseStep.getIndex() < PhaseStep.END_COMBAT.getIndex()) { if(phaseStep.getIndex() < PhaseStep.END_COMBAT.getIndex()) {
return true; return true;
} }

View file

@ -127,7 +127,7 @@ class GideonBattleForgedAttacksIfAbleTargetEffect extends RequirementEffect {
if (targetPermanent == null) { if (targetPermanent == null) {
return true; return true;
} }
return game.getPhase().getType() == TurnPhase.END && this.isYourNextTurn(game); // discard on end of their next turn return game.getTurnPhaseType() == TurnPhase.END && this.isYourNextTurn(game); // discard on end of their next turn
} }
@Override @Override

View file

@ -123,7 +123,7 @@ class GideonJuraEffect extends RequirementEffect {
@Override @Override
public boolean isInactive(Ability source, Game game) { public boolean isInactive(Ability source, Game game) {
return (game.getPhase().getType() == TurnPhase.END && this.isYourNextTurn(game)) return (game.getTurnPhaseType() == TurnPhase.END && this.isYourNextTurn(game))
// 6/15/2010: If a creature controlled by the affected player can't attack Gideon Jura // 6/15/2010: If a creature controlled by the affected player can't attack Gideon Jura
// (because he's no longer on the battlefield, for example), that player may have it attack you, // (because he's no longer on the battlefield, for example), that player may have it attack you,
// another one of your planeswalkers, or nothing at all. // another one of your planeswalkers, or nothing at all.

View file

@ -91,7 +91,7 @@ class DontUntapIfAttackedLastTurnSourceEffect extends ContinuousRuleModifyingEff
@Override @Override
public boolean applies(GameEvent event, Ability source, Game game) { public boolean applies(GameEvent event, Ability source, Game game) {
if (game.getTurn().getStepType() == PhaseStep.UNTAP if (game.getTurnStepType() == PhaseStep.UNTAP
&& event.getTargetId().equals(source.getSourceId())) { && event.getTargetId().equals(source.getSourceId())) {
Permanent permanent = game.getPermanent(source.getSourceId()); Permanent permanent = game.getPermanent(source.getSourceId());
if (permanent != null && permanent.isControlledBy(game.getActivePlayerId())) { if (permanent != null && permanent.isControlledBy(game.getActivePlayerId())) {

View file

@ -125,7 +125,7 @@ enum HakimLoreweaverCondition implements Condition {
@Override @Override
public boolean apply(Game game, Ability source) { public boolean apply(Game game, Ability source) {
if (PhaseStep.UPKEEP != game.getStep().getType() if (PhaseStep.UPKEEP != game.getTurnStepType()
|| !game.isActivePlayer(source.getControllerId())) { || !game.isActivePlayer(source.getControllerId())) {
return false; return false;
} }

View file

@ -95,7 +95,7 @@ class HalfdaneSetBasePowerToughnessEffect extends SetBasePowerToughnessSourceEff
@Override @Override
public boolean isInactive(Ability source, Game game) { public boolean isInactive(Ability source, Game game) {
if (super.isInactive(source, game) && game.getStep().getType().isAfter(PhaseStep.UPKEEP)) { if (super.isInactive(source, game) && game.getTurnStepType().isAfter(PhaseStep.UPKEEP)) {
return true; return true;
} }
return false; return false;

View file

@ -69,7 +69,7 @@ class HandToHandEffect extends ContinuousRuleModifyingEffectImpl {
@Override @Override
public boolean applies(GameEvent event, Ability source, Game game) { public boolean applies(GameEvent event, Ability source, Game game) {
if (game.getPhase().getType() == TurnPhase.COMBAT) { if (game.getTurnPhaseType() == TurnPhase.COMBAT) {
MageObject object = game.getObject(event.getSourceId()); MageObject object = game.getObject(event.getSourceId());
if (event.getType() == GameEvent.EventType.CAST_SPELL) { if (event.getType() == GameEvent.EventType.CAST_SPELL) {
if (object != null && object.isInstant(game)) { if (object != null && object.isInstant(game)) {

View file

@ -86,7 +86,7 @@ class HeavyArbalestEffect extends ReplacementEffectImpl {
@Override @Override
public boolean applies(GameEvent event, Ability source, Game game) { public boolean applies(GameEvent event, Ability source, Game game) {
if (game.getTurn().getStepType() == PhaseStep.UNTAP) { if (game.getTurnStepType() == PhaseStep.UNTAP) {
Permanent equipment = game.getPermanent(source.getSourceId()); Permanent equipment = game.getPermanent(source.getSourceId());
if (equipment != null && equipment.getAttachedTo() != null) { if (equipment != null && equipment.getAttachedTo() != null) {
Permanent equipped = game.getPermanent(equipment.getAttachedTo()); Permanent equipped = game.getPermanent(equipment.getAttachedTo());

View file

@ -86,7 +86,7 @@ class HullbreacherReplacementEffect extends ReplacementEffectImpl {
return false; return false;
} }
if (!game.isActivePlayer(event.getPlayerId()) if (!game.isActivePlayer(event.getPlayerId())
|| game.getStep().getType() != PhaseStep.DRAW) { || game.getTurnStepType() != PhaseStep.DRAW) {
return true; return true;
} }
CardsDrawnDuringDrawStepWatcher watcher = game.getState().getWatcher(CardsDrawnDuringDrawStepWatcher.class); CardsDrawnDuringDrawStepWatcher watcher = game.getState().getWatcher(CardsDrawnDuringDrawStepWatcher.class);

View file

@ -116,7 +116,7 @@ class IllusionistsGambitRequirementEffect extends RequirementEffect {
@Override @Override
public boolean isInactive(Ability source, Game game) { public boolean isInactive(Ability source, Game game) {
if (game.getTurn().getStepType() == PhaseStep.END_COMBAT) { if (game.getTurnStepType() == PhaseStep.END_COMBAT) {
return !Objects.equals(game.getTurn().getPhase(), phase); return !Objects.equals(game.getTurn().getPhase(), phase);
} }
return false; return false;
@ -158,7 +158,7 @@ class IllusionistsGambitRestrictionEffect extends RestrictionEffect {
@Override @Override
public boolean isInactive(Ability source, Game game) { public boolean isInactive(Ability source, Game game) {
if (game.getTurn().getStepType() == PhaseStep.END_COMBAT) { if (game.getTurnStepType() == PhaseStep.END_COMBAT) {
return !Objects.equals(game.getTurn().getPhase(), phase); return !Objects.equals(game.getTurn().getPhase(), phase);
} }
return false; return false;

View file

@ -81,7 +81,7 @@ class IslandSanctuaryEffect extends ReplacementEffectImpl {
@Override @Override
public boolean applies(GameEvent event, Ability source, Game game) { public boolean applies(GameEvent event, Ability source, Game game) {
return source.isControlledBy(event.getPlayerId()) && game.getTurn().getStepType() == PhaseStep.DRAW && game.getActivePlayerId().equals(source.getControllerId()); return source.isControlledBy(event.getPlayerId()) && game.getTurnStepType() == PhaseStep.DRAW && game.getActivePlayerId().equals(source.getControllerId());
} }
@Override @Override

View file

@ -109,7 +109,7 @@ class KillSwitchUntapEffect extends ContinuousRuleModifyingEffectImpl {
@Override @Override
public boolean applies(GameEvent event, Ability source, Game game) { public boolean applies(GameEvent event, Ability source, Game game) {
if (game.getTurn().getStepType() != PhaseStep.UNTAP) { if (game.getTurnStepType() != PhaseStep.UNTAP) {
return false; return false;
} }
Permanent sourcePermanent = source.getSourcePermanentIfItStillExists(game); Permanent sourcePermanent = source.getSourcePermanentIfItStillExists(game);

View file

@ -104,7 +104,7 @@ class ManaCacheManaAbility extends ActivatedManaAbilityImpl {
Player player = game.getPlayer(playerId); Player player = game.getPlayer(playerId);
if (player == null if (player == null
|| !playerId.equals(game.getActivePlayerId()) || !playerId.equals(game.getActivePlayerId())
|| !game.getStep().getType().isBefore(PhaseStep.END_TURN)) { || !game.getTurnStepType().isBefore(PhaseStep.END_TURN)) {
return ActivationStatus.getFalse(); return ActivationStatus.getFalse();
} }

View file

@ -79,7 +79,7 @@ class MarisiBreakerOfTheCoilSpellEffect extends ContinuousRuleModifyingEffectImp
@Override @Override
public boolean applies(GameEvent event, Ability source, Game game) { public boolean applies(GameEvent event, Ability source, Game game) {
return game.getPhase().getType() == TurnPhase.COMBAT return game.getTurnPhaseType() == TurnPhase.COMBAT
&& game.getOpponents(source.getControllerId()).contains(event.getPlayerId()); && game.getOpponents(source.getControllerId()).contains(event.getPlayerId());
} }
} }

View file

@ -59,7 +59,7 @@ class MongrelPackAbility extends ZoneChangeTriggeredAbility {
@Override @Override
public boolean checkTrigger(GameEvent event, Game game) { public boolean checkTrigger(GameEvent event, Game game) {
if (super.checkTrigger(event, game)) { if (super.checkTrigger(event, game)) {
if (game.getPhase().getType() == TurnPhase.COMBAT) { if (game.getTurnPhaseType() == TurnPhase.COMBAT) {
return true; return true;
} }
} }

View file

@ -63,7 +63,7 @@ enum MoraugFuryOfAkoumCondition implements Condition {
@Override @Override
public boolean apply(Game game, Ability source) { public boolean apply(Game game, Ability source) {
return game.isActivePlayer(source.getControllerId()) && game.getPhase().getType().isMain(); return game.isActivePlayer(source.getControllerId()) && game.getTurnPhaseType().isMain();
} }
} }
@ -113,7 +113,7 @@ class MoraugFuryOfAkoumCombatEffect extends OneShotEffect {
@Override @Override
public boolean apply(Game game, Ability source) { public boolean apply(Game game, Ability source) {
TurnPhase turnPhase = game.getPhase().getType(); TurnPhase turnPhase = game.getTurnPhaseType();
for (TurnMod turnMod : game.getState().getTurnMods()) { for (TurnMod turnMod : game.getState().getTurnMods()) {
if ("moraug".equals(turnMod.getNote()) if ("moraug".equals(turnMod.getNote())
&& turnMod.getPlayerId().equals(source.getControllerId()) && turnMod.getPlayerId().equals(source.getControllerId())

View file

@ -58,7 +58,7 @@ enum NemesisPhoenixCondition implements Condition {
@Override @Override
public boolean apply(Game game, Ability source) { public boolean apply(Game game, Ability source) {
if (game.getStep().getType() != PhaseStep.DECLARE_ATTACKERS) { if (game.getTurnStepType() != PhaseStep.DECLARE_ATTACKERS) {
return false; return false;
} }
Set<UUID> opponents = game.getOpponents(source.getControllerId()); Set<UUID> opponents = game.getOpponents(source.getControllerId());

View file

@ -89,7 +89,7 @@ class NotionThiefReplacementEffect extends ReplacementEffectImpl {
@Override @Override
public boolean applies(GameEvent event, Ability source, Game game) { public boolean applies(GameEvent event, Ability source, Game game) {
if (game.getOpponents(source.getControllerId()).contains(event.getPlayerId())) { if (game.getOpponents(source.getControllerId()).contains(event.getPlayerId())) {
if (game.isActivePlayer(event.getPlayerId()) && game.getStep().getType() == PhaseStep.DRAW) { if (game.isActivePlayer(event.getPlayerId()) && game.getTurnStepType() == PhaseStep.DRAW) {
CardsDrawnDuringDrawStepWatcher watcher = game.getState().getWatcher(CardsDrawnDuringDrawStepWatcher.class); CardsDrawnDuringDrawStepWatcher watcher = game.getState().getWatcher(CardsDrawnDuringDrawStepWatcher.class);
if (watcher != null && watcher.getAmountCardsDrawn(event.getPlayerId()) > 0) { if (watcher != null && watcher.getAmountCardsDrawn(event.getPlayerId()) > 0) {
return true; return true;

View file

@ -150,7 +150,7 @@ class OracleEnVecMustAttackRequirementEffect extends RequirementEffect {
@Override @Override
public boolean isInactive(Ability source, Game game) { public boolean isInactive(Ability source, Game game) {
return game.getPhase().getType() == TurnPhase.END && this.isYourNextTurn(game); return game.getTurnPhaseType() == TurnPhase.END && this.isYourNextTurn(game);
} }
@Override @Override
@ -199,7 +199,7 @@ class OracleEnVecCantAttackRestrictionEffect extends RestrictionEffect {
@Override @Override
public boolean isInactive(Ability source, Game game) { public boolean isInactive(Ability source, Game game) {
return game.getPhase().getType() == TurnPhase.END && this.isYourNextTurn(game); return game.getTurnPhaseType() == TurnPhase.END && this.isYourNextTurn(game);
} }
} }

View file

@ -92,7 +92,7 @@ class RowanKenrithAttackEffect extends RequirementEffect {
@Override @Override
public boolean isInactive(Ability source, Game game) { public boolean isInactive(Ability source, Game game) {
return (game.getPhase().getType() == TurnPhase.END return (game.getTurnPhaseType() == TurnPhase.END
&& this.isYourNextTurn(game)); && this.isYourNextTurn(game));
} }

View file

@ -75,8 +75,8 @@ class SizzlingSoloistEffect extends RequirementEffect {
return true; return true;
} }
return game.isActivePlayer(game.getControllerId(getTargetPointer().getFirst(game, source))) return game.isActivePlayer(game.getControllerId(getTargetPointer().getFirst(game, source)))
&& game.getPhase().getType() == TurnPhase.COMBAT && game.getTurnPhaseType() == TurnPhase.COMBAT
&& game.getStep().getType() == PhaseStep.END_COMBAT; && game.getTurnStepType() == PhaseStep.END_COMBAT;
} }
@Override @Override

View file

@ -64,7 +64,7 @@ class SphinxOfTheSecondSunEffect extends OneShotEffect {
@Override @Override
public boolean apply(Game game, Ability source) { public boolean apply(Game game, Ability source) {
TurnPhase turnPhase = game.getPhase().getType(); TurnPhase turnPhase = game.getTurnPhaseType();
for (TurnMod turnMod : game.getState().getTurnMods()) { for (TurnMod turnMod : game.getState().getTurnMods()) {
if ("sphinxSecondSun".equals(turnMod.getNote()) if ("sphinxSecondSun".equals(turnMod.getNote())
&& turnMod.getPlayerId().equals(source.getControllerId()) && turnMod.getPlayerId().equals(source.getControllerId())

View file

@ -69,7 +69,7 @@ class StorageMatrixRestrictionEffect extends RestrictionEffect {
@Override @Override
public boolean applies(Permanent permanent, Ability source, Game game) { public boolean applies(Permanent permanent, Ability source, Game game) {
if (game.getStep().getType() == PhaseStep.UNTAP) { if (game.getTurnStepType() == PhaseStep.UNTAP) {
if (game.getTurnNum() != turn) { if (game.getTurnNum() != turn) {
turn = game.getTurnNum(); turn = game.getTurnNum();
applies = false; applies = false;

View file

@ -101,7 +101,7 @@ class DontUntapIfAttackedLastTurnEnchantedEffect extends ContinuousRuleModifying
@Override @Override
public boolean applies(GameEvent event, Ability source, Game game) { public boolean applies(GameEvent event, Ability source, Game game) {
if (game.getTurn().getStepType() == PhaseStep.UNTAP) { if (game.getTurnStepType() == PhaseStep.UNTAP) {
Permanent enchantment = game.getPermanent(source.getSourceId()); Permanent enchantment = game.getPermanent(source.getSourceId());
if (enchantment != null && enchantment.getAttachedTo() != null && event.getTargetId().equals(enchantment.getAttachedTo())) { if (enchantment != null && enchantment.getAttachedTo() != null && event.getTargetId().equals(enchantment.getAttachedTo())) {
Permanent permanent = game.getPermanent(enchantment.getAttachedTo()); Permanent permanent = game.getPermanent(enchantment.getAttachedTo());

View file

@ -59,7 +59,7 @@ class TauntEffect extends RequirementEffect {
@Override @Override
public boolean isInactive(Ability source, Game game) { public boolean isInactive(Ability source, Game game) {
return game.getPhase().getType() == TurnPhase.END && this.isYourNextTurn(game); return game.getTurnPhaseType() == TurnPhase.END && this.isYourNextTurn(game);
} }
@Override @Override

View file

@ -85,8 +85,8 @@ class TrenchBehemothEffect extends RequirementEffect {
return true; return true;
} }
return game.isActivePlayer(game.getControllerId(getTargetPointer().getFirst(game, source))) return game.isActivePlayer(game.getControllerId(getTargetPointer().getFirst(game, source)))
&& game.getPhase().getType() == TurnPhase.COMBAT && game.getTurnPhaseType() == TurnPhase.COMBAT
&& game.getStep().getType() == PhaseStep.END_COMBAT; && game.getTurnStepType() == PhaseStep.END_COMBAT;
} }
@Override @Override

View file

@ -69,7 +69,7 @@ class TsabosWebPreventUntapEffect extends ContinuousRuleModifyingEffectImpl {
@Override @Override
public boolean applies(GameEvent event, Ability source, Game game) { public boolean applies(GameEvent event, Ability source, Game game) {
if (game.getTurn().getStepType() == PhaseStep.UNTAP) { if (game.getTurnStepType() == PhaseStep.UNTAP) {
Permanent permanent = game.getPermanent(event.getTargetId()); Permanent permanent = game.getPermanent(event.getTargetId());
if (permanent != null && permanent.isLand(game)) { if (permanent != null && permanent.isLand(game)) {
for (Ability ability :permanent.getAbilities()) { for (Ability ability :permanent.getAbilities()) {

View file

@ -57,7 +57,7 @@ class UnwindingClockEffect extends ContinuousEffectImpl {
public boolean apply(Layer layer, SubLayer sublayer, Ability source, Game game) { public boolean apply(Layer layer, SubLayer sublayer, Ability source, Game game) {
boolean applied = Boolean.TRUE.equals(game.getState().getValue(source.getSourceId() + "applied")); boolean applied = Boolean.TRUE.equals(game.getState().getValue(source.getSourceId() + "applied"));
if (!applied && layer == Layer.RulesEffects) { if (!applied && layer == Layer.RulesEffects) {
if (!game.isActivePlayer(source.getControllerId()) && game.getStep().getType() == PhaseStep.UNTAP) { if (!game.isActivePlayer(source.getControllerId()) && game.getTurnStepType() == PhaseStep.UNTAP) {
game.getState().setValue(source.getSourceId() + "applied", true); game.getState().setValue(source.getSourceId() + "applied", true);
for (Permanent artifact : game.getBattlefield().getAllActivePermanents(filter, source.getControllerId(), game)) { for (Permanent artifact : game.getBattlefield().getAllActivePermanents(filter, source.getControllerId(), game)) {
boolean untap = true; boolean untap = true;
@ -70,7 +70,7 @@ class UnwindingClockEffect extends ContinuousEffectImpl {
} }
} }
} else if (applied && layer == Layer.RulesEffects) { } else if (applied && layer == Layer.RulesEffects) {
if (game.getStep().getType() == PhaseStep.END_TURN) { if (game.getTurnStepType() == PhaseStep.END_TURN) {
game.getState().setValue(source.getSourceId() + "applied", false); game.getState().setValue(source.getSourceId() + "applied", false);
} }
} }

View file

@ -70,7 +70,7 @@ class UrbanBurgeoningUntapEffect extends ContinuousEffectImpl {
public boolean apply(Layer layer, SubLayer sublayer, Ability source, Game game) { public boolean apply(Layer layer, SubLayer sublayer, Ability source, Game game) {
boolean applied = Boolean.TRUE.equals(game.getState().getValue(source.getSourceId() + "applied")); boolean applied = Boolean.TRUE.equals(game.getState().getValue(source.getSourceId() + "applied"));
if (!applied && layer == Layer.RulesEffects) { if (!applied && layer == Layer.RulesEffects) {
if (!game.isActivePlayer(source.getControllerId()) && game.getStep().getType() == PhaseStep.UNTAP) { if (!game.isActivePlayer(source.getControllerId()) && game.getTurnStepType() == PhaseStep.UNTAP) {
game.getState().setValue(source.getSourceId() + "applied", true); game.getState().setValue(source.getSourceId() + "applied", true);
Permanent land = game.getPermanent(source.getSourceId()); Permanent land = game.getPermanent(source.getSourceId());
boolean untap = true; boolean untap = true;
@ -82,7 +82,7 @@ class UrbanBurgeoningUntapEffect extends ContinuousEffectImpl {
} }
} }
} else if (applied && layer == Layer.RulesEffects) { } else if (applied && layer == Layer.RulesEffects) {
if (game.getStep().getType() == PhaseStep.END_TURN) { if (game.getTurnStepType() == PhaseStep.END_TURN) {
game.getState().setValue(source.getSourceId() + "applied", false); game.getState().setValue(source.getSourceId() + "applied", false);
} }
} }

View file

@ -92,7 +92,7 @@ class VraskaTheUnseenGainAbilityEffect extends ContinuousEffectImpl {
@Override @Override
public boolean isInactive(Ability source, Game game) { public boolean isInactive(Ability source, Game game) {
return game.getPhase().getType() == TurnPhase.END && this.isYourNextTurn(game); return game.getTurnPhaseType() == TurnPhase.END && this.isYourNextTurn(game);
} }
} }

View file

@ -82,7 +82,7 @@ class VulshokGauntletsEffect extends ReplacementEffectImpl {
@Override @Override
public boolean applies(GameEvent event, Ability source, Game game) { public boolean applies(GameEvent event, Ability source, Game game) {
if (game.getTurn().getStepType() == PhaseStep.UNTAP) { if (game.getTurnStepType() == PhaseStep.UNTAP) {
Permanent equipment = game.getPermanent(source.getSourceId()); Permanent equipment = game.getPermanent(source.getSourceId());
if (equipment != null && equipment.getAttachedTo() != null) { if (equipment != null && equipment.getAttachedTo() != null) {
Permanent equipped = game.getPermanent(equipment.getAttachedTo()); Permanent equipped = game.getPermanent(equipment.getAttachedTo());

View file

@ -70,7 +70,7 @@ class WallOfDustRestrictionEffect extends RestrictionEffect {
return true; return true;
} }
return game.getPhase().getType() == TurnPhase.END && this.isYourNextTurn(game); return game.getTurnPhaseType() == TurnPhase.END && this.isYourNextTurn(game);
} }
@Override @Override

View file

@ -71,7 +71,7 @@ class WiretappingTriggeredAbility extends TriggeredAbilityImpl {
@Override @Override
public boolean checkTrigger(GameEvent event, Game game) { public boolean checkTrigger(GameEvent event, Game game) {
return game.isActivePlayer(event.getPlayerId()) return game.isActivePlayer(event.getPlayerId())
&& game.getStep().getType() == PhaseStep.DRAW && game.getTurnStepType() == PhaseStep.DRAW
&& isControlledBy(event.getPlayerId()) && isControlledBy(event.getPlayerId())
&& game && game
.getState() .getState()

View file

@ -73,7 +73,7 @@ class ZursWeirdingReplacementEffect extends ReplacementEffectImpl {
return false; return false;
} }
// Reveals it instead // Reveals it instead
player.revealCards(sourceObject.getIdName() + " next draw of " + player.getName() + " (" + game.getTurnNum() + '|' + game.getPhase().getType() + ')', new CardsImpl(card), game); player.revealCards(sourceObject.getIdName() + " next draw of " + player.getName() + " (" + game.getTurnNum() + '|' + game.getTurnPhaseType() + ')', new CardsImpl(card), game);
// Then any other player may pay 2 life. If a player does, put that card into its owner's graveyard // Then any other player may pay 2 life. If a player does, put that card into its owner's graveyard
String message = "Pay 2 life to put " + card.getLogName() + " into " + player.getLogName() + " graveyard?"; String message = "Pay 2 life to put " + card.getLogName() + " into " + player.getLogName() + " graveyard?";

View file

@ -48,6 +48,6 @@ public class PhageTheUntouchableTest extends CardTestPlayerBase {
Assert.assertTrue("Game has ended.", currentGame.hasEnded()); Assert.assertTrue("Game has ended.", currentGame.hasEnded());
assertWonTheGame(playerA); assertWonTheGame(playerA);
Assert.assertTrue("Game ist At end phase", currentGame.getPhase().getType() == TurnPhase.END); Assert.assertTrue("Game ist At end phase", currentGame.getTurnPhaseType() == TurnPhase.END);
} }
} }

View file

@ -567,7 +567,7 @@ public class TestPlayer implements Player {
if (actionsToRemoveLater.size() > 0) { if (actionsToRemoveLater.size() > 0) {
List<PlayerAction> removed = new ArrayList<>(); List<PlayerAction> removed = new ArrayList<>();
actionsToRemoveLater.forEach((action, step) -> { actionsToRemoveLater.forEach((action, step) -> {
if (game.getStep().getType() != step) { if (game.getTurnStepType() != step) {
action.onActionRemovedLater(game, this); action.onActionRemovedLater(game, this);
actions.remove(action); actions.remove(action);
removed.add(action); removed.add(action);
@ -584,7 +584,7 @@ public class TestPlayer implements Player {
List<PlayerAction> tempActions = new ArrayList<>(); List<PlayerAction> tempActions = new ArrayList<>();
tempActions.addAll(actions); tempActions.addAll(actions);
for (PlayerAction action : tempActions) { for (PlayerAction action : tempActions) {
if (action.getTurnNum() == game.getTurnNum() && action.getStep() == game.getStep().getType()) { if (action.getTurnNum() == game.getTurnNum() && action.getStep() == game.getTurnStepType()) {
if (action.getAction().startsWith(ACTIVATE_ABILITY)) { if (action.getAction().startsWith(ACTIVATE_ABILITY)) {
String command = action.getAction(); String command = action.getAction();
@ -677,9 +677,8 @@ public class TestPlayer implements Player {
printEnd(); printEnd();
// TODO: enable assert and rewrite failed activateManaAbility tests // TODO: enable assert and rewrite failed activateManaAbility tests
// (must use checkAbility instead multiple mana calls) // (must use checkAbility instead multiple mana calls)
LOGGER.warn("WARNING, test must be rewritten to use checkAbility instead multiple mana calls");
//Assert.fail("Can't find mana ability to activate command: " + command); //Assert.fail("Can't find mana ability to activate command: " + command);
new Exception("WARNING, test must be rewritten to use checkAbility instead multiple mana calls")
.printStackTrace();
} else if (action.getAction().startsWith("addCounters:")) { } else if (action.getAction().startsWith("addCounters:")) {
String command = action.getAction(); String command = action.getAction();
command = command.substring(command.indexOf("addCounters:") + 12); command = command.substring(command.indexOf("addCounters:") + 12);
@ -748,7 +747,7 @@ public class TestPlayer implements Player {
// play step // play step
if (command.equals(AI_COMMAND_PLAY_STEP)) { if (command.equals(AI_COMMAND_PLAY_STEP)) {
AIRealGameSimulation = true; // disable on action's remove AIRealGameSimulation = true; // disable on action's remove
actionsToRemoveLater.put(action, game.getStep().getType()); actionsToRemoveLater.put(action, game.getTurnStepType());
computerPlayer.priority(game); computerPlayer.priority(game);
return true; return true;
} }
@ -1966,7 +1965,7 @@ public class TestPlayer implements Player {
} }
Assert.fail("Missing " + choiceType.toUpperCase(Locale.ENGLISH) + " def for" Assert.fail("Missing " + choiceType.toUpperCase(Locale.ENGLISH) + " def for"
+ " turn " + game.getTurnNum() + " turn " + game.getTurnNum()
+ ", step " + (game.getStep() != null ? game.getStep().getType().name() : "not started") + ", step " + (game.getStep() != null ? game.getTurnStepType().name() : "not started")
+ ", " + this.getName() + ", " + this.getName()
+ "\n" + reason); + "\n" + reason);
} }

View file

@ -23,13 +23,13 @@ public class DealsDamageToOneOrMoreCreaturesTriggeredAbility extends DealsDamage
public boolean checkTrigger(GameEvent event, Game game) { public boolean checkTrigger(GameEvent event, Game game) {
if (super.checkTrigger(event, game)) { if (super.checkTrigger(event, game)) {
// check that combat damage does only once trigger also if multiple creatures were damaged because they block or were blocked by source // check that combat damage does only once trigger also if multiple creatures were damaged because they block or were blocked by source
if (game.getTurn().getStepType() == PhaseStep.COMBAT_DAMAGE if (game.getTurnStepType() == PhaseStep.COMBAT_DAMAGE
|| game.getTurn().getStepType() == PhaseStep.FIRST_COMBAT_DAMAGE) { || game.getTurnStepType() == PhaseStep.FIRST_COMBAT_DAMAGE) {
String stepHash = (String) game.getState().getValue("damageStep" + getOriginalId()); String stepHash = (String) game.getState().getValue("damageStep" + getOriginalId());
String newStepHash = game.getStep().getType().toString() + game.getTurnNum(); String newStepHash = game.getTurnStepType().toString() + game.getTurnNum();
if (!newStepHash.equals(stepHash)) { if (!newStepHash.equals(stepHash)) {
// this ability did not trigger during this damage step // this ability did not trigger during this damage step
game.getState().setValue("damageStep" + getOriginalId(), game.getStep().getType().toString() + game.getTurnNum()); game.getState().setValue("damageStep" + getOriginalId(), game.getTurnStepType().toString() + game.getTurnNum());
return true; return true;
} }
} else { } else {

View file

@ -18,7 +18,7 @@ public enum AddendumCondition implements Condition {
@Override @Override
public boolean apply(Game game, Ability source) { public boolean apply(Game game, Ability source) {
if (!game.isActivePlayer(source.getControllerId()) || if (!game.isActivePlayer(source.getControllerId()) ||
!game.getPhase().getType().isMain()) { !game.getTurnPhaseType().isMain()) {
return false; return false;
} }
if (CastFromEverywhereSourceCondition.instance.apply(game, source)) { if (CastFromEverywhereSourceCondition.instance.apply(game, source)) {

View file

@ -18,8 +18,8 @@ public enum AfterBlockersAreDeclaredCondition implements Condition {
@Override @Override
public boolean apply(Game game, Ability source) { public boolean apply(Game game, Ability source) {
return !(game.getStep().getType() == PhaseStep.BEGIN_COMBAT return !(game.getTurnStepType() == PhaseStep.BEGIN_COMBAT
|| game.getStep().getType() == PhaseStep.DECLARE_ATTACKERS); || game.getTurnStepType() == PhaseStep.DECLARE_ATTACKERS);
} }
@Override @Override

View file

@ -15,7 +15,7 @@ public enum AfterCombatCondition implements Condition {
@Override @Override
public boolean apply(Game game, Ability source) { public boolean apply(Game game, Ability source) {
return game.getStep().getType().isAfter(PhaseStep.END_COMBAT); return game.getTurnStepType().isAfter(PhaseStep.END_COMBAT);
} }
@Override @Override

View file

@ -14,7 +14,7 @@ public enum AfterUpkeepStepCondtion implements Condition {
@Override @Override
public boolean apply(Game game, Ability source) { public boolean apply(Game game, Ability source) {
return game.getStep().getType().isAfter(PhaseStep.UPKEEP); return game.getTurnStepType().isAfter(PhaseStep.UPKEEP);
} }
@Override @Override

View file

@ -17,7 +17,7 @@ public enum BeforeBlockersAreDeclaredCondition implements Condition {
@Override @Override
public boolean apply(Game game, Ability source) { public boolean apply(Game game, Ability source) {
return game.getStep().getType().isBefore(PhaseStep.DECLARE_BLOCKERS); return game.getTurnStepType().isBefore(PhaseStep.DECLARE_BLOCKERS);
} }
@Override @Override

View file

@ -28,7 +28,7 @@ public class IsPhaseCondition implements Condition {
@Override @Override
public boolean apply(Game game, Ability source) { public boolean apply(Game game, Ability source) {
return turnPhase == game.getTurn().getPhaseType() && (!yourTurn || game.getActivePlayerId().equals(source.getControllerId())); return turnPhase == game.getTurnPhaseType() && (!yourTurn || game.getActivePlayerId().equals(source.getControllerId()));
} }
@Override @Override

View file

@ -26,7 +26,7 @@ public class IsStepCondition implements Condition {
@Override @Override
public boolean apply(Game game, Ability source) { public boolean apply(Game game, Ability source) {
return phaseStep == game.getStep().getType() && (!onlyDuringYourSteps || game.isActivePlayer(source.getControllerId())); return phaseStep == game.getTurnStepType() && (!onlyDuringYourSteps || game.isActivePlayer(source.getControllerId()));
} }
@Override @Override

View file

@ -201,7 +201,7 @@ public class ContinuousEffects implements Serializable {
updateTimestamps(timestampGroupName, layerEffects); updateTimestamps(timestampGroupName, layerEffects);
layerEffects.sort(Comparator.comparingLong(ContinuousEffect::getOrder)); layerEffects.sort(Comparator.comparingLong(ContinuousEffect::getOrder));
/* debug effects apply order: /* debug effects apply order:
if (game.getStep() != null) System.out.println("layr - " + game.getTurnNum() + "." + game.getStep().getType() + ": layers " + layerEffects.size() if (game.getStep() != null) System.out.println("layr - " + game.getTurnNum() + "." + game.getTurnStepType() + ": layers " + layerEffects.size()
+ " - " + layerEffects.stream().map(l -> l.getClass().getSimpleName()).collect(Collectors.joining(", ")) + " - " + layerEffects.stream().map(l -> l.getClass().getSimpleName()).collect(Collectors.joining(", "))
+ " - " + callName); + " - " + callName);
//*/ //*/

View file

@ -35,8 +35,8 @@ public class AddCombatAndMainPhaseEffect extends OneShotEffect {
@Override @Override
public boolean apply(Game game, Ability source) { public boolean apply(Game game, Ability source) {
// 15.07.2006 If it's somehow not a main phase when Fury of the Horde resolves, all it does is untap all creatures that attacked that turn. No new phases are created. // 15.07.2006 If it's somehow not a main phase when Fury of the Horde resolves, all it does is untap all creatures that attacked that turn. No new phases are created.
if (game.getTurn().getPhaseType() == TurnPhase.PRECOMBAT_MAIN if (game.getTurnPhaseType() == TurnPhase.PRECOMBAT_MAIN
|| game.getTurn().getPhaseType() == TurnPhase.POSTCOMBAT_MAIN) { || game.getTurnPhaseType() == TurnPhase.POSTCOMBAT_MAIN) {
// we can't add two turn modes at once, will add additional post combat on delayed trigger resolution // we can't add two turn modes at once, will add additional post combat on delayed trigger resolution
TurnMod combat = new TurnMod(source.getControllerId(), TurnPhase.COMBAT, TurnPhase.POSTCOMBAT_MAIN, false); TurnMod combat = new TurnMod(source.getControllerId(), TurnPhase.COMBAT, TurnPhase.POSTCOMBAT_MAIN, false);
game.getState().getTurnMods().add(combat); game.getState().getTurnMods().add(combat);

View file

@ -68,7 +68,7 @@ public class DontUntapInControllersNextUntapStepSourceEffect extends ContinuousR
validForTurnNum = game.getTurnNum(); validForTurnNum = game.getTurnNum();
} }
// skip untap action // skip untap action
if (game.getTurn().getStepType() == PhaseStep.UNTAP if (game.getTurnStepType() == PhaseStep.UNTAP
&& event.getType() == GameEvent.EventType.UNTAP && event.getType() == GameEvent.EventType.UNTAP
&& game.isActivePlayer(source.getControllerId()) && game.isActivePlayer(source.getControllerId())
&& event.getTargetId().equals(source.getSourceId())) { && event.getTargetId().equals(source.getSourceId())) {

View file

@ -120,7 +120,7 @@ public class DontUntapInControllersNextUntapStepTargetEffect extends ContinuousR
} }
} }
if (game.getTurn().getStepType() == PhaseStep.UNTAP && event.getType() == GameEvent.EventType.UNTAP) { if (game.getTurnStepType() == PhaseStep.UNTAP && event.getType() == GameEvent.EventType.UNTAP) {
if (handledTargetsDuringTurn.containsKey(event.getTargetId()) if (handledTargetsDuringTurn.containsKey(event.getTargetId())
&& !handledTargetsDuringTurn.get(event.getTargetId()) && !handledTargetsDuringTurn.get(event.getTargetId())
&& getTargetPointer().getTargets(game, source).contains(event.getTargetId())) { && getTargetPointer().getTargets(game, source).contains(event.getTargetId())) {

View file

@ -55,7 +55,7 @@ public class DontUntapInControllersUntapStepAllEffect extends ContinuousRuleModi
@Override @Override
public boolean applies(GameEvent event, Ability source, Game game) { public boolean applies(GameEvent event, Ability source, Game game) {
if (game.getTurn().getStepType() == PhaseStep.UNTAP) { if (game.getTurnStepType() == PhaseStep.UNTAP) {
Permanent permanent = game.getPermanent(event.getTargetId()); Permanent permanent = game.getPermanent(event.getTargetId());
if (permanent != null) { if (permanent != null) {
switch(targetController) { switch(targetController) {

View file

@ -56,7 +56,7 @@ public class DontUntapInControllersUntapStepEnchantedEffect extends ContinuousRu
@Override @Override
public boolean applies(GameEvent event, Ability source, Game game) { public boolean applies(GameEvent event, Ability source, Game game) {
if (game.getTurn().getStepType() == PhaseStep.UNTAP) { if (game.getTurnStepType() == PhaseStep.UNTAP) {
Permanent enchantment = game.getPermanent(source.getSourceId()); Permanent enchantment = game.getPermanent(source.getSourceId());
if (enchantment != null && enchantment.getAttachedTo() != null && event.getTargetId().equals(enchantment.getAttachedTo())) { if (enchantment != null && enchantment.getAttachedTo() != null && event.getTargetId().equals(enchantment.getAttachedTo())) {
Permanent permanent = game.getPermanent(enchantment.getAttachedTo()); Permanent permanent = game.getPermanent(enchantment.getAttachedTo());

View file

@ -47,7 +47,7 @@ public class DontUntapInControllersUntapStepSourceEffect extends ContinuousRuleM
@Override @Override
public boolean applies(GameEvent event, Ability source, Game game) { public boolean applies(GameEvent event, Ability source, Game game) {
if (game.getTurn().getStepType() == PhaseStep.UNTAP if (game.getTurnStepType() == PhaseStep.UNTAP
&& event.getTargetId().equals(source.getSourceId())) { && event.getTargetId().equals(source.getSourceId())) {
Permanent permanent = game.getPermanent(source.getSourceId()); Permanent permanent = game.getPermanent(source.getSourceId());
if (permanent != null && permanent.isControlledBy(game.getActivePlayerId())) { if (permanent != null && permanent.isControlledBy(game.getActivePlayerId())) {

View file

@ -50,7 +50,7 @@ public class DontUntapInControllersUntapStepTargetEffect extends ContinuousRuleM
@Override @Override
public boolean applies(GameEvent event, Ability source, Game game) { public boolean applies(GameEvent event, Ability source, Game game) {
if (game.getTurn().getStepType() != PhaseStep.UNTAP) { if (game.getTurnStepType() != PhaseStep.UNTAP) {
return false; return false;
} }
for (UUID targetId : targetPointer.getTargets(game, source)) { for (UUID targetId : targetPointer.getTargets(game, source)) {

View file

@ -89,7 +89,7 @@ public class DontUntapInPlayersNextUntapStepAllEffect extends ContinuousRuleModi
} }
} }
if (game.getTurn().getStepType() == PhaseStep.UNTAP && event.getType() == GameEvent.EventType.UNTAP) { if (game.getTurnStepType() == PhaseStep.UNTAP && event.getType() == GameEvent.EventType.UNTAP) {
Permanent permanent = game.getPermanent(event.getTargetId()); Permanent permanent = game.getPermanent(event.getTargetId());
if (permanent != null) { if (permanent != null) {
Player controller = game.getPlayer(source.getControllerId()); Player controller = game.getPlayer(source.getControllerId());

View file

@ -33,7 +33,7 @@ public class UntapAllDuringEachOtherPlayersUntapStepEffect extends ContinuousEff
@Override @Override
public boolean apply(Layer layer, SubLayer sublayer, Ability source, Game game) { public boolean apply(Layer layer, SubLayer sublayer, Ability source, Game game) {
if (layer == Layer.RulesEffects && game.getStep().getType() == PhaseStep.UNTAP && !source.isControlledBy(game.getActivePlayerId())) { if (layer == Layer.RulesEffects && game.getTurnStepType() == PhaseStep.UNTAP && !source.isControlledBy(game.getActivePlayerId())) {
Integer appliedTurn = (Integer) game.getState().getValue(source.getSourceId() + "appliedTurn"); Integer appliedTurn = (Integer) game.getState().getValue(source.getSourceId() + "appliedTurn");
if (appliedTurn == null) { if (appliedTurn == null) {
appliedTurn = 0; appliedTurn = 0;

View file

@ -32,7 +32,7 @@ public class UntapSourceDuringEachOtherPlayersUntapStepEffect extends Continuous
if (!applied && layer == Layer.RulesEffects) { if (!applied && layer == Layer.RulesEffects) {
if (!source.isControlledBy(game.getActivePlayerId()) if (!source.isControlledBy(game.getActivePlayerId())
&& game.getStep() != null && game.getStep() != null
&& game.getStep().getType() == PhaseStep.UNTAP) { && game.getTurnStepType() == PhaseStep.UNTAP) {
game.getState().setValue(source.getSourceId() + "applied", true); game.getState().setValue(source.getSourceId() + "applied", true);
Permanent permanent = game.getPermanent(source.getSourceId()); Permanent permanent = game.getPermanent(source.getSourceId());
if (permanent != null) { if (permanent != null) {
@ -46,7 +46,7 @@ public class UntapSourceDuringEachOtherPlayersUntapStepEffect extends Continuous
} }
} }
} else if (applied && layer == Layer.RulesEffects) { } else if (applied && layer == Layer.RulesEffects) {
if (game.getStep() != null && game.getStep().getType() == PhaseStep.END_TURN) { if (game.getStep() != null && game.getTurnStepType() == PhaseStep.END_TURN) {
game.getState().setValue(source.getSourceId() + "applied", false); game.getState().setValue(source.getSourceId() + "applied", false);
} }
} }

View file

@ -46,8 +46,8 @@ public class CastOnlyDuringPhaseStepSourceEffect extends ContinuousRuleModifying
public boolean applies(GameEvent event, Ability source, Game game) { public boolean applies(GameEvent event, Ability source, Game game) {
// has to return true, if the spell cannot be cast in the current phase / step // has to return true, if the spell cannot be cast in the current phase / step
if (event.getSourceId().equals(source.getSourceId())) { if (event.getSourceId().equals(source.getSourceId())) {
if ((turnPhase != null && game.getPhase().getType() != turnPhase) if ((turnPhase != null && game.getTurnPhaseType() != turnPhase)
|| (phaseStep != null && (game.getTurn().getStepType() != phaseStep)) || (phaseStep != null && (game.getTurnStepType() != phaseStep))
|| (condition != null && !condition.apply(game, source))) { || (condition != null && !condition.apply(game, source))) {
return true; return true;
} }

View file

@ -30,7 +30,7 @@ public class ArtificialScoringSystem implements ScoringSystem {
if (game.getStep() == null) { if (game.getStep() == null) {
return 0; return 0;
} }
return ScoringConstants.LOSE_GAME_SCORE + game.getTurnNum() * 2500 + game.getStep().getType().getIndex() * 200; return ScoringConstants.LOSE_GAME_SCORE + game.getTurnNum() * 2500 + game.getTurnStepType().getIndex() * 200;
} }
@Override @Override

View file

@ -180,6 +180,19 @@ public interface Game extends MageItem, Serializable, Copyable<Game> {
Turn getTurn(); Turn getTurn();
/**
* @return can return null in non started games
*/
PhaseStep getTurnStepType();
/**
* @return can return null in non started games
*/
TurnPhase getTurnPhaseType();
/**
* @return can return null in non started games
*/
Phase getPhase(); Phase getPhase();
Step getStep(); Step getStep();

View file

@ -2882,6 +2882,16 @@ public abstract class GameImpl implements Game {
return state.getTurn(); return state.getTurn();
} }
@Override
public PhaseStep getTurnStepType() {
return state.getTurnStepType();
}
@Override
public TurnPhase getTurnPhaseType() {
return state.getTurnPhaseType();
}
@Override @Override
public Phase getPhase() { public Phase getPhase() {
return state.getTurn().getPhase(); return state.getTurn().getPhase();
@ -2919,7 +2929,7 @@ public abstract class GameImpl implements Game {
@Override @Override
public boolean isMainPhase() { public boolean isMainPhase() {
return state.getTurn().getStepType() == PhaseStep.PRECOMBAT_MAIN || state.getTurn().getStepType() == PhaseStep.POSTCOMBAT_MAIN; return state.getTurnStepType() == PhaseStep.PRECOMBAT_MAIN || state.getTurnStepType() == PhaseStep.POSTCOMBAT_MAIN;
} }
@Override @Override

View file

@ -7,6 +7,8 @@ import mage.abilities.effects.ContinuousEffect;
import mage.abilities.effects.ContinuousEffects; import mage.abilities.effects.ContinuousEffects;
import mage.abilities.effects.Effect; import mage.abilities.effects.Effect;
import mage.cards.*; import mage.cards.*;
import mage.constants.PhaseStep;
import mage.constants.TurnPhase;
import mage.constants.Zone; import mage.constants.Zone;
import mage.designations.Designation; import mage.designations.Designation;
import mage.filter.common.FilterCreaturePermanent; import mage.filter.common.FilterCreaturePermanent;
@ -22,6 +24,8 @@ import mage.game.permanent.PermanentCard;
import mage.game.permanent.PermanentToken; import mage.game.permanent.PermanentToken;
import mage.game.stack.SpellStack; import mage.game.stack.SpellStack;
import mage.game.stack.StackObject; import mage.game.stack.StackObject;
import mage.game.turn.Phase;
import mage.game.turn.Step;
import mage.game.turn.Turn; import mage.game.turn.Turn;
import mage.game.turn.TurnMods; import mage.game.turn.TurnMods;
import mage.players.Player; import mage.players.Player;
@ -572,6 +576,19 @@ public class GameState implements Serializable, Copyable<GameState> {
return turn; return turn;
} }
public PhaseStep getTurnStepType() {
Turn turn = this.getTurn();
Phase phase = turn != null ? turn.getPhase() : null;
Step step = phase != null ? phase.getStep() : null;
return step != null ? step.getType() : null;
}
public TurnPhase getTurnPhaseType() {
Turn turn = this.getTurn();
Phase phase = turn != null ? turn.getPhase() : null;
return phase != null ? phase.getType() : null;
}
public Combat getCombat() { public Combat getCombat() {
return combat; return combat;
} }

View file

@ -41,7 +41,7 @@ class LukeSkywalkerEmblemEffect extends PreventionEffectImpl {
@Override @Override
public boolean applies(GameEvent event, Ability source, Game game) { public boolean applies(GameEvent event, Ability source, Game game) {
if (game.getPhase().getType() == TurnPhase.COMBAT if (game.getTurnPhaseType() == TurnPhase.COMBAT
&& super.applies(event, source, game) && super.applies(event, source, game)
&& event.getType() == GameEvent.EventType.DAMAGE_PLAYER) { && event.getType() == GameEvent.EventType.DAMAGE_PLAYER) {
Player controller = game.getPlayer(source.getControllerId()); Player controller = game.getPlayer(source.getControllerId());

View file

@ -90,7 +90,7 @@ class EdgeOfMalacolEffect extends ContinuousRuleModifyingEffectImpl {
@Override @Override
public boolean applies(GameEvent event, Ability source, Game game) { public boolean applies(GameEvent event, Ability source, Game game) {
// Prevent untap event of creatures of target player // Prevent untap event of creatures of target player
if (game.getTurn().getStepType() == PhaseStep.UNTAP) { if (game.getTurnStepType() == PhaseStep.UNTAP) {
Plane cPlane = game.getState().getCurrentPlane(); Plane cPlane = game.getState().getCurrentPlane();
if (cPlane == null) { if (cPlane == null) {
return false; return false;

View file

@ -84,13 +84,6 @@ public class Turn implements Serializable {
return null; return null;
} }
public PhaseStep getStepType() {
if (currentPhase != null && currentPhase.getStep() != null) {
return currentPhase.getStep().getType();
}
return null;
}
/** /**
* @param game * @param game
* @param activePlayer * @param activePlayer
@ -148,8 +141,8 @@ public class Turn implements Serializable {
public void resumePlay(Game game, boolean wasPaused) { public void resumePlay(Game game, boolean wasPaused) {
activePlayerId = game.getActivePlayerId(); activePlayerId = game.getActivePlayerId();
UUID priorityPlayerId = game.getPriorityPlayerId(); UUID priorityPlayerId = game.getPriorityPlayerId();
TurnPhase phaseType = game.getPhase().getType(); TurnPhase phaseType = game.getTurnPhaseType();
PhaseStep stepType = game.getStep().getType(); PhaseStep stepType = game.getTurnStepType();
Iterator<Phase> it = phases.iterator(); Iterator<Phase> it = phases.iterator();
Phase phase; Phase phase;

View file

@ -271,7 +271,7 @@ public class ManaPool implements Serializable {
private int emptyItem(ManaPoolItem item, Emptiable toEmpty, Game game, ManaType manaType) { private int emptyItem(ManaPoolItem item, Emptiable toEmpty, Game game, ManaType manaType) {
if (item.getDuration() == Duration.EndOfTurn if (item.getDuration() == Duration.EndOfTurn
&& game.getPhase().getType() != TurnPhase.END) { && game.getTurnPhaseType() != TurnPhase.END) {
return 0; return 0;
} }
if (!manaBecomesColorless) { if (!manaBecomesColorless) {

View file

@ -2407,7 +2407,7 @@ public abstract class PlayerImpl implements Player, Serializable {
case PASS_PRIORITY_UNTIL_TURN_END_STEP: // F5 case PASS_PRIORITY_UNTIL_TURN_END_STEP: // F5
resetPlayerPassedActions(); resetPlayerPassedActions();
passedUntilEndOfTurn = true; passedUntilEndOfTurn = true;
skippedAtLeastOnce = PhaseStep.END_TURN != game.getTurn().getStepType(); skippedAtLeastOnce = PhaseStep.END_TURN != game.getTurnStepType();
this.skip(); this.skip();
break; break;
case PASS_PRIORITY_UNTIL_NEXT_TURN: // F4 case PASS_PRIORITY_UNTIL_NEXT_TURN: // F4
@ -2423,8 +2423,8 @@ public abstract class PlayerImpl implements Player, Serializable {
case PASS_PRIORITY_UNTIL_NEXT_MAIN_PHASE: //F7 case PASS_PRIORITY_UNTIL_NEXT_MAIN_PHASE: //F7
resetPlayerPassedActions(); resetPlayerPassedActions();
passedUntilNextMain = true; passedUntilNextMain = true;
skippedAtLeastOnce = !(game.getTurn().getStepType() == PhaseStep.POSTCOMBAT_MAIN skippedAtLeastOnce = !(game.getTurnStepType() == PhaseStep.POSTCOMBAT_MAIN
|| game.getTurn().getStepType() == PhaseStep.PRECOMBAT_MAIN); || game.getTurnStepType() == PhaseStep.PRECOMBAT_MAIN);
this.skip(); this.skip();
break; break;
case PASS_PRIORITY_UNTIL_STACK_RESOLVED: // Default F10 - Skips until the current stack is resolved case PASS_PRIORITY_UNTIL_STACK_RESOLVED: // Default F10 - Skips until the current stack is resolved