refactor: improved usage of one time turn modifications (skip step, extra turn, etc)

This commit is contained in:
Oleg Agafonov 2023-07-31 20:16:28 +04:00
parent 4554fbc408
commit 8d938926b6
46 changed files with 222 additions and 190 deletions

View file

@ -60,7 +60,7 @@ public class CustomPillarOfTheParunsDuel extends GameImpl {
addDelayedTriggeredAbility(new AtTheBeginOfPlayerFirstMainPhase(playerId, "Pillar of the Paruns"), null); addDelayedTriggeredAbility(new AtTheBeginOfPlayerFirstMainPhase(playerId, "Pillar of the Paruns"), null);
}); });
state.getTurnMods().add(new TurnMod(startingPlayerId, PhaseStep.DRAW)); state.getTurnMods().add(new TurnMod(startingPlayerId).withSkipStep(PhaseStep.DRAW));
} }
public CustomPillarOfTheParunsDuel(final CustomPillarOfTheParunsDuel game) { public CustomPillarOfTheParunsDuel(final CustomPillarOfTheParunsDuel game) {

View file

@ -54,7 +54,7 @@ public class MomirDuel extends GameImpl {
} }
getState().addAbility(ability, null); getState().addAbility(ability, null);
super.init(choosingPlayerId); super.init(choosingPlayerId);
state.getTurnMods().add(new TurnMod(startingPlayerId, PhaseStep.DRAW)); state.getTurnMods().add(new TurnMod(startingPlayerId).withSkipStep(PhaseStep.DRAW));
} }
@Override @Override

View file

@ -60,7 +60,7 @@ public class MomirGame extends GameImpl {
} }
getState().addAbility(ability, null); getState().addAbility(ability, null);
super.init(choosingPlayerId); super.init(choosingPlayerId);
state.getTurnMods().add(new TurnMod(startingPlayerId, PhaseStep.DRAW)); state.getTurnMods().add(new TurnMod(startingPlayerId).withSkipStep(PhaseStep.DRAW));
} }
@Override @Override

View file

@ -40,7 +40,7 @@ public class TwoPlayerDuel extends GameImpl {
@Override @Override
protected void init(UUID choosingPlayerId) { protected void init(UUID choosingPlayerId) {
super.init(choosingPlayerId); super.init(choosingPlayerId);
state.getTurnMods().add(new TurnMod(startingPlayerId, PhaseStep.DRAW)); state.getTurnMods().add(new TurnMod(startingPlayerId).withSkipStep(PhaseStep.DRAW));
} }
@Override @Override

View file

@ -1,4 +1,3 @@
package mage.cards.b; package mage.cards.b;
import java.util.UUID; import java.util.UUID;
@ -26,6 +25,7 @@ public final class BeaconOfTomorrows extends CardImpl {
// Target player takes an extra turn after this one. // Target player takes an extra turn after this one.
this.getSpellAbility().addTarget(new TargetPlayer()); this.getSpellAbility().addTarget(new TargetPlayer());
this.getSpellAbility().addEffect(new BeaconOfTomorrowsEffect()); this.getSpellAbility().addEffect(new BeaconOfTomorrowsEffect());
// Shuffle Beacon of Tomorrows into its owner's library. // Shuffle Beacon of Tomorrows into its owner's library.
this.getSpellAbility().addEffect(ShuffleSpellEffect.getInstance()); this.getSpellAbility().addEffect(ShuffleSpellEffect.getInstance());
} }
@ -58,7 +58,11 @@ class BeaconOfTomorrowsEffect extends OneShotEffect {
@Override @Override
public boolean apply(Game game, Ability source) { public boolean apply(Game game, Ability source) {
game.getState().getTurnMods().add(new TurnMod(source.getFirstTarget(), false)); if (source.getFirstTarget() == null) {
return false;
}
game.getState().getTurnMods().add(new TurnMod(source.getFirstTarget()).withExtraTurn());
return true; return true;
} }
} }

View file

@ -150,8 +150,7 @@ class BreathOfFuryEffect extends OneShotEffect {
for (Permanent permanent : game.getBattlefield().getAllActivePermanents(new FilterControlledCreaturePermanent(), controller.getId(), game)) { for (Permanent permanent : game.getBattlefield().getAllActivePermanents(new FilterControlledCreaturePermanent(), controller.getId(), game)) {
permanent.untap(game); permanent.untap(game);
} }
game.getState().getTurnMods().add(new TurnMod(source.getControllerId()).withExtraPhase(TurnPhase.COMBAT));
game.getState().getTurnMods().add(new TurnMod(source.getControllerId(), TurnPhase.COMBAT, null, false));
} }
return true; return true;
} }

View file

@ -70,7 +70,7 @@ class BrineElementalEffect extends OneShotEffect {
if (controller != null) { if (controller != null) {
for (UUID playerId: game.getState().getPlayersInRange(controller.getId(), game)) { for (UUID playerId: game.getState().getPlayersInRange(controller.getId(), game)) {
if (controller.hasOpponent(playerId, game)) { if (controller.hasOpponent(playerId, game)) {
game.getState().getTurnMods().add(new TurnMod(playerId, PhaseStep.UNTAP)); game.getState().getTurnMods().add(new TurnMod(playerId).withSkipStep(PhaseStep.UNTAP));
} }
} }
return true; return true;

View file

@ -63,8 +63,8 @@ class CruelEntertainmentEffect extends OneShotEffect {
player2 = game.getPlayer(getTargetPointer().getTargets(game, source).get(1)); player2 = game.getPlayer(getTargetPointer().getTargets(game, source).get(1));
} }
if (player1 != null && player2 != null) { if (player1 != null && player2 != null) {
game.getState().getTurnMods().add(new TurnMod(player1.getId(), player2.getId())); game.getState().getTurnMods().add(new TurnMod(player1.getId()).withNewController(player2.getId()));
game.getState().getTurnMods().add(new TurnMod(player2.getId(), player1.getId())); game.getState().getTurnMods().add(new TurnMod(player2.getId()).withNewController(player1.getId()));
return true; return true;
} }
return false; return false;

View file

@ -94,10 +94,9 @@ class EmrakulThePromisedEndGainControlEffect extends OneShotEffect {
Player controller = game.getPlayer(source.getControllerId()); Player controller = game.getPlayer(source.getControllerId());
Player targetPlayer = game.getPlayer(this.getTargetPointer().getFirst(game, source)); Player targetPlayer = game.getPlayer(this.getTargetPointer().getFirst(game, source));
if (controller != null && targetPlayer != null) { if (controller != null && targetPlayer != null) {
TurnMod controlPlayerTurnMod = new TurnMod(targetPlayer.getId(), controller.getId()); TurnMod extraTurnMod = new TurnMod(targetPlayer.getId()).withExtraTurn();
TurnMod extraTurnMod = new TurnMod(targetPlayer.getId(), false); TurnMod newControllerTurnMod = new TurnMod(targetPlayer.getId()).withNewController(controller.getId(), extraTurnMod);
controlPlayerTurnMod.setSubsequentTurnMod(extraTurnMod); game.getState().getTurnMods().add(newControllerTurnMod);
game.getState().getTurnMods().add(controlPlayerTurnMod);
return true; return true;
} }
return false; return false;

View file

@ -84,7 +84,7 @@ class EonFrolickerEffect extends OneShotEffect {
if (player == null) { if (player == null) {
return false; return false;
} }
game.getState().getTurnMods().add(new TurnMod(player.getId(), false)); game.getState().getTurnMods().add(new TurnMod(player.getId()).withExtraTurn());
FilterPlayer filter = new FilterPlayer(player.getName()); FilterPlayer filter = new FilterPlayer(player.getName());
filter.add(new PlayerIdPredicate(player.getId())); filter.add(new PlayerIdPredicate(player.getId()));
Ability ability = new ProtectionAbility(filter); Ability ability = new ProtectionAbility(filter);

View file

@ -81,7 +81,7 @@ class ExpropriateEffect extends OneShotEffect {
// extra turn // extra turn
int timeCount = vote.getVoteCount(true); int timeCount = vote.getVoteCount(true);
for (int i = 0; i < timeCount; i++) { for (int i = 0; i < timeCount; i++) {
game.getState().getTurnMods().add(new TurnMod(source.getControllerId(), false)); game.getState().getTurnMods().add(new TurnMod(source.getControllerId()).withExtraTurn());
} }
// gain control // gain control

View file

@ -74,7 +74,7 @@ class HellkiteChargerEffect extends OneShotEffect {
cost.clearPaid(); cost.clearPaid();
if (cost.pay(source, game, source, source.getControllerId(), false, null)) { if (cost.pay(source, game, source, source.getControllerId(), false, null)) {
new UntapAllControllerEffect(new FilterAttackingCreature(),"").apply(game, source); new UntapAllControllerEffect(new FilterAttackingCreature(),"").apply(game, source);
game.getState().getTurnMods().add(new TurnMod(source.getControllerId(), TurnPhase.COMBAT, null, false)); game.getState().getTurnMods().add(new TurnMod(source.getControllerId()).withExtraPhase(TurnPhase.COMBAT));
return true; return true;
} }
} }

View file

@ -72,7 +72,7 @@ class IllusionistsGambitRemoveFromCombatEffect extends OneShotEffect {
} }
if (!attackers.isEmpty()) { if (!attackers.isEmpty()) {
Phase phase = game.getTurn().getPhase(); Phase phase = game.getTurn().getPhase();
game.getState().getTurnMods().add(new TurnMod(game.getActivePlayerId(), TurnPhase.COMBAT, null, false)); game.getState().getTurnMods().add(new TurnMod(game.getActivePlayerId()).withExtraPhase(TurnPhase.COMBAT));
ContinuousEffect effect = new IllusionistsGambitRequirementEffect(attackers, phase); ContinuousEffect effect = new IllusionistsGambitRequirementEffect(attackers, phase);
game.addEffect(effect, source); game.addEffect(effect, source);
effect = new IllusionistsGambitRestrictionEffect(attackers, phase); effect = new IllusionistsGambitRestrictionEffect(attackers, phase);

View file

@ -66,13 +66,15 @@ class KarnsTemporalSunderingEffect extends OneShotEffect {
return false; return false;
} }
game.getState().getTurnMods().add(new TurnMod(source.getTargets().getFirstTarget(), false)); if (source.getTargets().getFirstTarget() != null) {
game.getState().getTurnMods().add(new TurnMod(source.getTargets().getFirstTarget()).withExtraTurn());
}
Permanent returnPermanent = game.getPermanent(source.getTargets().get(1).getFirstTarget()); Permanent returnPermanent = game.getPermanent(source.getTargets().get(1).getFirstTarget());
if (returnPermanent != null) { if (returnPermanent != null) {
controller.moveCards(returnPermanent, Zone.HAND, source, game); controller.moveCards(returnPermanent, Zone.HAND, source, game);
} }
return true; return true;
} }

View file

@ -75,7 +75,7 @@ class LostIsleCallingEffect extends OneShotEffect {
int count = permanent.getCounters(game).getCount(CounterType.VERSE); int count = permanent.getCounters(game).getCount(CounterType.VERSE);
player.drawCards(count, source, game); player.drawCards(count, source, game);
if (count >= 7) { if (count >= 7) {
game.getState().getTurnMods().add(new TurnMod(player.getId(), false)); game.getState().getTurnMods().add(new TurnMod(player.getId()).withExtraTurn());
} }
return true; return true;
} }

View file

@ -55,7 +55,7 @@ class SpipTurnEffect extends OneShotEffect {
@Override @Override
public boolean apply(Game game, Ability source) { public boolean apply(Game game, Ability source) {
game.getState().getTurnMods().add(new TurnMod(source.getControllerId(), true)); game.getState().getTurnMods().add(new TurnMod(source.getControllerId()).withSkipTurn());
return true; return true;
} }

View file

@ -119,12 +119,13 @@ class MoraugFuryOfAkoumCombatEffect extends OneShotEffect {
&& turnMod.getPlayerId().equals(source.getControllerId()) && turnMod.getPlayerId().equals(source.getControllerId())
&& turnMod.getAfterPhase() == turnPhase) { && turnMod.getAfterPhase() == turnPhase) {
turnPhase = TurnPhase.COMBAT; turnPhase = TurnPhase.COMBAT;
turnMod.setNote("moraugIgnore"); turnMod.withNote("moraugIgnore");
break; break;
} }
} }
TurnMod combat = new TurnMod(source.getControllerId(), TurnPhase.COMBAT, turnPhase, false); TurnMod combat = new TurnMod(source.getControllerId())
combat.setNote("moraug"); .withExtraPhase(TurnPhase.COMBAT, turnPhase)
.withNote("moraug");
game.getState().getTurnMods().add(combat); game.getState().getTurnMods().add(combat);
game.addDelayedTriggeredAbility(new MoraugFuryOfAkoumDelayedTriggeredAbility(combat.getId()), source); game.addDelayedTriggeredAbility(new MoraugFuryOfAkoumDelayedTriggeredAbility(combat.getId()), source);
return true; return true;
@ -193,7 +194,7 @@ class MoraugFuryOfAkoumWatcher extends Watcher {
} }
for (TurnMod turnMod : game.getState().getTurnMods()) { for (TurnMod turnMod : game.getState().getTurnMods()) {
if ("moraug".equals(turnMod.getNote())) { if ("moraug".equals(turnMod.getNote())) {
turnMod.setNote("moraugIgnore"); turnMod.withNote("moraugIgnore");
} }
} }
} }

View file

@ -17,7 +17,6 @@ public final class Opportunity extends CardImpl {
public Opportunity(UUID ownerId, CardSetInfo setInfo) { public Opportunity(UUID ownerId, CardSetInfo setInfo) {
super(ownerId,setInfo,new CardType[]{CardType.INSTANT},"{4}{U}{U}"); super(ownerId,setInfo,new CardType[]{CardType.INSTANT},"{4}{U}{U}");
// Target player draws four cards. // Target player draws four cards.
this.getSpellAbility().addEffect(new DrawCardTargetEffect(4)); this.getSpellAbility().addEffect(new DrawCardTargetEffect(4));
this.getSpellAbility().addTarget(new TargetPlayer()); this.getSpellAbility().addTarget(new TargetPlayer());

View file

@ -105,7 +105,10 @@ class ParadoxHazeEffect extends OneShotEffect {
@Override @Override
public boolean apply(Game game, Ability source) { public boolean apply(Game game, Ability source) {
game.getState().getTurnMods().add(new TurnMod(this.getTargetPointer().getFirst(game, source), new UpkeepStep(), null)); UUID playerId = this.getTargetPointer().getFirst(game, source);
if (playerId != null) {
game.getState().getTurnMods().add(new TurnMod(playerId).withExtraStep(new UpkeepStep()));
}
return true; return true;
} }
} }

View file

@ -99,7 +99,7 @@ class RalZarekExtraTurnsEffect extends OneShotEffect {
if (controller != null) { if (controller != null) {
for (int i = 0; i < 5; i++) { for (int i = 0; i < 5; i++) {
if (controller.flipCoin(source, game, false)) { if (controller.flipCoin(source, game, false)) {
game.getState().getTurnMods().add(new TurnMod(source.getControllerId(), false)); game.getState().getTurnMods().add(new TurnMod(source.getControllerId()).withExtraTurn());
} }
} }
return true; return true;

View file

@ -78,7 +78,7 @@ class SageOfHoursEffect extends OneShotEffect {
} }
int turns = countersRemoved / 5; int turns = countersRemoved / 5;
for (int i = 0; i < turns; i++) { for (int i = 0; i < turns; i++) {
game.getState().getTurnMods().add(new TurnMod(player.getId(), false)); game.getState().getTurnMods().add(new TurnMod(player.getId()).withExtraTurn());
} }
game.informPlayers("Removed " + countersRemoved + game.informPlayers("Removed " + countersRemoved +
" +1/+1 counters: " + player.getLogName() + " takes " + " +1/+1 counters: " + player.getLogName() + " takes " +

View file

@ -54,7 +54,7 @@ class SkipNextUntapStepSourceControllerEffect extends OneShotEffect {
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 (controller != null) { if (controller != null) {
game.getState().getTurnMods().add(new TurnMod(controller.getId(), PhaseStep.UNTAP)); game.getState().getTurnMods().add(new TurnMod(controller.getId()).withSkipStep(PhaseStep.UNTAP));
return true; return true;
} }
return false; return false;

View file

@ -164,7 +164,7 @@ class SearchTheCityExiledCardToHandEffect extends OneShotEffect {
if (permanent != null) { if (permanent != null) {
permanent.sacrifice(source, game); permanent.sacrifice(source, game);
// extra turn // extra turn
game.getState().getTurnMods().add(new TurnMod(source.getControllerId(), false)); game.getState().getTurnMods().add(new TurnMod(source.getControllerId()).withExtraTurn());
} }
} }
return true; return true;

View file

@ -70,12 +70,13 @@ class SphinxOfTheSecondSunEffect extends OneShotEffect {
&& turnMod.getPlayerId().equals(source.getControllerId()) && turnMod.getPlayerId().equals(source.getControllerId())
&& turnMod.getAfterPhase() == turnPhase) { && turnMod.getAfterPhase() == turnPhase) {
turnPhase = TurnPhase.BEGINNING; turnPhase = TurnPhase.BEGINNING;
turnMod.setNote("sphinxSecondSunIgnore"); turnMod.withNote("sphinxSecondSunIgnore");
break; break;
} }
} }
TurnMod newPhase = new TurnMod(source.getControllerId(), TurnPhase.BEGINNING, turnPhase, false); TurnMod newPhase = new TurnMod(source.getControllerId())
newPhase.setNote("sphinxSecondSun"); .withExtraPhase(TurnPhase.BEGINNING, turnPhase)
.withNote("sphinxSecondSun");
game.getState().getTurnMods().add(newPhase); game.getState().getTurnMods().add(newPhase);
return true; return true;
} }
@ -94,7 +95,7 @@ class SphinxOfTheSecondSunWatcher extends Watcher {
} }
for (TurnMod turnMod : game.getState().getTurnMods()) { for (TurnMod turnMod : game.getState().getTurnMods()) {
if ("sphinxSecondSun".equals(turnMod.getNote())) { if ("sphinxSecondSun".equals(turnMod.getNote())) {
turnMod.setNote("sphinxSecondSunIgnore"); turnMod.withNote("sphinxSecondSunIgnore");
} }
} }
} }

View file

@ -53,7 +53,7 @@ class StitchInTimeEffect extends OneShotEffect {
Player player = game.getPlayer(source.getControllerId()); Player player = game.getPlayer(source.getControllerId());
if (player != null) { if (player != null) {
if (player.flipCoin(source, game, true)) { if (player.flipCoin(source, game, true)) {
game.getState().getTurnMods().add(new TurnMod(player.getId(), false)); game.getState().getTurnMods().add(new TurnMod(player.getId()).withExtraTurn());
return true; return true;
} }
} }

View file

@ -107,8 +107,8 @@ class TeferiMasterOfTimeTurnEffect extends OneShotEffect {
@Override @Override
public boolean apply(Game game, Ability source) { public boolean apply(Game game, Ability source) {
game.getState().getTurnMods().add(new TurnMod(source.getControllerId(), false)); game.getState().getTurnMods().add(new TurnMod(source.getControllerId()).withExtraTurn());
game.getState().getTurnMods().add(new TurnMod(source.getControllerId(), false)); game.getState().getTurnMods().add(new TurnMod(source.getControllerId()).withExtraTurn());
return true; return true;
} }
} }

View file

@ -56,8 +56,12 @@ class TimeStretchEffect extends OneShotEffect {
@Override @Override
public boolean apply(Game game, Ability source) { public boolean apply(Game game, Ability source) {
game.getState().getTurnMods().add(new TurnMod(source.getFirstTarget(), false)); if (source.getFirstTarget() == null) {
game.getState().getTurnMods().add(new TurnMod(source.getFirstTarget(), false)); return false;
}
game.getState().getTurnMods().add(new TurnMod(source.getFirstTarget()).withExtraTurn());
game.getState().getTurnMods().add(new TurnMod(source.getFirstTarget()).withExtraTurn());
return true; return true;
} }
} }

View file

@ -55,8 +55,10 @@ class TimeWarpEffect extends OneShotEffect {
@Override @Override
public boolean apply(Game game, Ability source) { public boolean apply(Game game, Ability source) {
game.getState().getTurnMods().add(new TurnMod(source.getFirstTarget(), false)); if (source.getFirstTarget() == null) {
return false;
}
game.getState().getTurnMods().add(new TurnMod(source.getFirstTarget()).withExtraTurn());
return true; return true;
} }
} }

View file

@ -64,7 +64,7 @@ class WorldAtWarEffect extends OneShotEffect {
@Override @Override
public boolean apply(Game game, Ability source) { public boolean apply(Game game, Ability source) {
// 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()).withExtraPhase(TurnPhase.COMBAT, TurnPhase.POSTCOMBAT_MAIN);
game.getState().getTurnMods().add(combat); game.getState().getTurnMods().add(combat);
UntapDelayedTriggeredAbility delayedTriggeredAbility = new UntapDelayedTriggeredAbility(); UntapDelayedTriggeredAbility delayedTriggeredAbility = new UntapDelayedTriggeredAbility();
delayedTriggeredAbility.setConnectedTurnMod(combat.getId()); delayedTriggeredAbility.setConnectedTurnMod(combat.getId());
@ -107,7 +107,7 @@ class UntapDelayedTriggeredAbility extends DelayedTriggeredAbility {
} }
if (event.getType() == GameEvent.EventType.COMBAT_PHASE_PRE && enabled) { if (event.getType() == GameEvent.EventType.COMBAT_PHASE_PRE && enabled) {
// add additional post combat phase after that // add additional post combat phase after that
game.getState().getTurnMods().add(new TurnMod(getControllerId(), TurnPhase.POSTCOMBAT_MAIN, TurnPhase.COMBAT, false)); game.getState().getTurnMods().add(new TurnMod(getControllerId()).withExtraPhase(TurnPhase.POSTCOMBAT_MAIN, TurnPhase.COMBAT));
enabled = false; enabled = false;
return true; return true;
} }

View file

@ -35,6 +35,7 @@ public final class XyrisTheWrithingStorm extends CardImpl {
// Whenever an opponent draws a card except the first one they draw in each of their draw steps, create a 1/1 green Snake creature token. // Whenever an opponent draws a card except the first one they draw in each of their draw steps, create a 1/1 green Snake creature token.
this.addAbility(new OpponentDrawCardExceptFirstCardDrawStepTriggeredAbility(Zone.BATTLEFIELD, new CreateTokenEffect(new SnakeToken(), 1), false)); this.addAbility(new OpponentDrawCardExceptFirstCardDrawStepTriggeredAbility(Zone.BATTLEFIELD, new CreateTokenEffect(new SnakeToken(), 1), false));
// Whenever Xyris, the Writhing Storm deals combat damage to a player, you and that player each draw that many cards. // Whenever Xyris, the Writhing Storm deals combat damage to a player, you and that player each draw that many cards.
this.addAbility(new DealsCombatDamageToAPlayerTriggeredAbility(new XyrisTheWrithingStormCombatDamageEffect(), false, true)); this.addAbility(new DealsCombatDamageToAPlayerTriggeredAbility(new XyrisTheWrithingStormCombatDamageEffect(), false, true));
} }

View file

@ -34,9 +34,7 @@ public class OpponentDrawCardExceptFirstCardDrawStepTriggeredAbility extends Tri
if (game.isActivePlayer(event.getPlayerId()) if (game.isActivePlayer(event.getPlayerId())
&& game.getPhase().getStep().getType() == PhaseStep.DRAW) { && game.getPhase().getStep().getType() == PhaseStep.DRAW) {
CardsDrawnDuringDrawStepWatcher watcher = game.getState().getWatcher(CardsDrawnDuringDrawStepWatcher.class); CardsDrawnDuringDrawStepWatcher watcher = game.getState().getWatcher(CardsDrawnDuringDrawStepWatcher.class);
if (watcher != null && watcher.getAmountCardsDrawn(event.getPlayerId()) > 1) { return watcher != null && watcher.getAmountCardsDrawn(event.getPlayerId()) > 1;
return true;
}
} else { } else {
return true; return true;
} }

View file

@ -38,7 +38,7 @@ public class AddCombatAndMainPhaseEffect extends OneShotEffect {
if (game.getTurnPhaseType() == TurnPhase.PRECOMBAT_MAIN if (game.getTurnPhaseType() == TurnPhase.PRECOMBAT_MAIN
|| game.getTurnPhaseType() == 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()).withExtraPhase(TurnPhase.COMBAT, TurnPhase.POSTCOMBAT_MAIN);
game.getState().getTurnMods().add(combat); game.getState().getTurnMods().add(combat);
DelayedAddMainPhaseAbility delayedTriggeredAbility = new DelayedAddMainPhaseAbility(); DelayedAddMainPhaseAbility delayedTriggeredAbility = new DelayedAddMainPhaseAbility();
delayedTriggeredAbility.setConnectedTurnMod(combat.getId()); delayedTriggeredAbility.setConnectedTurnMod(combat.getId());
@ -83,7 +83,7 @@ class DelayedAddMainPhaseAbility extends DelayedTriggeredAbility {
} }
if (event.getType() == GameEvent.EventType.COMBAT_PHASE_PRE && enabled) { if (event.getType() == GameEvent.EventType.COMBAT_PHASE_PRE && enabled) {
// add additional post combat main phase after that - after phase == null because add it after this combat // add additional post combat main phase after that - after phase == null because add it after this combat
game.getState().getTurnMods().add(new TurnMod(getControllerId(), TurnPhase.POSTCOMBAT_MAIN, null, false)); game.getState().getTurnMods().add(new TurnMod(getControllerId()).withExtraPhase(TurnPhase.POSTCOMBAT_MAIN));
enabled = false; enabled = false;
} }
return false; return false;

View file

@ -30,8 +30,7 @@ public class AdditionalCombatPhaseEffect extends OneShotEffect {
@Override @Override
public boolean apply(Game game, Ability source) { public boolean apply(Game game, Ability source) {
game.getState().getTurnMods().add(new TurnMod(game.getState().getActivePlayerId(), game.getState().getTurnMods().add(new TurnMod(game.getState().getActivePlayerId()).withExtraPhase(TurnPhase.COMBAT));
TurnPhase.COMBAT, null, false));
return true; return true;
} }
} }

View file

@ -60,7 +60,7 @@ public class SkipNextDrawStepControllerEffect extends OneShotEffect {
public boolean apply(Game game, Ability source) { public boolean apply(Game game, Ability source) {
Player player = game.getPlayer(source.getControllerId()); Player player = game.getPlayer(source.getControllerId());
if (player != null) { if (player != null) {
game.getState().getTurnMods().add(new TurnMod(player.getId(), PhaseStep.DRAW)); game.getState().getTurnMods().add(new TurnMod(player.getId()).withSkipStep(PhaseStep.DRAW));
return true; return true;
} }
return false; return false;

View file

@ -68,7 +68,7 @@ public class SkipNextPlayerUntapStepEffect extends OneShotEffect {
} }
} }
if (player != null) { if (player != null) {
game.getState().getTurnMods().add(new TurnMod(player.getId(), PhaseStep.UNTAP)); game.getState().getTurnMods().add(new TurnMod(player.getId()).withSkipStep(PhaseStep.UNTAP));
return true; return true;
} }
return false; return false;

View file

@ -59,7 +59,7 @@ public class AddExtraTurnControllerEffect extends OneShotEffect {
if (player == null) { if (player == null) {
return true; return true;
} }
TurnMod extraTurn = new TurnMod(player.getId(), false); TurnMod extraTurn = new TurnMod(player.getId()).withExtraTurn();
game.getState().getTurnMods().add(extraTurn); game.getState().getTurnMods().add(extraTurn);
if (loseGameAtEnd) { if (loseGameAtEnd) {
game.addDelayedTriggeredAbility(new LoseGameDelayedTriggeredAbility(extraTurn.getId()), source); game.addDelayedTriggeredAbility(new LoseGameDelayedTriggeredAbility(extraTurn.getId()), source);

View file

@ -29,7 +29,7 @@ public class AddExtraTurnTargetEffect extends OneShotEffect {
@Override @Override
public boolean apply(Game game, Ability source) { public boolean apply(Game game, Ability source) {
if (this.getTargetPointer().getFirst(game, source) != null) { if (this.getTargetPointer().getFirst(game, source) != null) {
game.getState().getTurnMods().add(new TurnMod(this.getTargetPointer().getFirst(game, source), false)); game.getState().getTurnMods().add(new TurnMod(this.getTargetPointer().getFirst(game, source)).withExtraTurn());
} }
return true; return true;
} }

View file

@ -5,7 +5,9 @@ import mage.abilities.effects.OneShotEffect;
import mage.constants.Outcome; import mage.constants.Outcome;
import mage.game.Game; import mage.game.Game;
import mage.game.turn.TurnMod; import mage.game.turn.TurnMod;
import mage.players.Player;
import java.util.Objects;
import java.util.UUID; import java.util.UUID;
/** /**
@ -24,12 +26,16 @@ public class ControlTargetPlayerNextTurnEffect extends OneShotEffect {
@Override @Override
public boolean apply(Game game, Ability source) { public boolean apply(Game game, Ability source) {
UUID targetId = source.getFirstTarget(); Player targetPlayer = game.getPlayer(source.getFirstTarget());
UUID controllerId = source.getControllerId(); if (targetPlayer == null) {
if (targetId != null && controllerId != null && !targetId.equals(controllerId)) { return false;
game.getState().getTurnMods().add(new TurnMod(targetId, controllerId)); }
if (!Objects.equals(source.getControllerId(), targetPlayer.getId())) {
game.getState().getTurnMods().add(new TurnMod(targetPlayer.getId()).withNewController(source.getControllerId()));
return true; return true;
} }
return false; return false;
} }

View file

@ -47,7 +47,7 @@ public class SkipNextTurnSourceEffect extends OneShotEffect {
playerId = source.getControllerId(); playerId = source.getControllerId();
} }
for (int i = 0; i < numberOfTurns; i++) { for (int i = 0; i < numberOfTurns; i++) {
game.getState().getTurnMods().add(new TurnMod(playerId, true)); game.getState().getTurnMods().add(new TurnMod(playerId).withSkipTurn());
} }
return true; return true;
} }

View file

@ -22,7 +22,9 @@ public abstract class GameCanadianHighlanderImpl extends GameImpl {
@Override @Override
protected void init(UUID choosingPlayerId) { protected void init(UUID choosingPlayerId) {
super.init(choosingPlayerId); super.init(choosingPlayerId);
state.getTurnMods().add(new TurnMod(startingPlayerId, PhaseStep.DRAW)); // 103.7a In a two-player game, the player who plays first skips the draw step (see rule 504, "Draw Step")
// of his or her first turn.
state.getTurnMods().add(new TurnMod(startingPlayerId).withSkipStep(PhaseStep.DRAW));
} }
} }

View file

@ -29,6 +29,8 @@ public abstract class GameCommanderImpl extends GameImpl {
protected boolean alsoHand = true; // replace commander going to hand protected boolean alsoHand = true; // replace commander going to hand
protected boolean alsoLibrary = true; // replace commander going to library protected boolean alsoLibrary = true; // replace commander going to library
// 103.7a In a two-player game, the player who plays first skips the draw step
// (see rule 504, "Draw Step") of his or her first turn.
protected boolean startingPlayerSkipsDraw = true; protected boolean startingPlayerSkipsDraw = true;
public GameCommanderImpl(MultiplayerAttackOption attackOption, RangeOfInfluence range, Mulligan mulligan, int startingLife, int minimumDeckSize) { public GameCommanderImpl(MultiplayerAttackOption attackOption, RangeOfInfluence range, Mulligan mulligan, int startingLife, int minimumDeckSize) {
@ -127,7 +129,7 @@ public abstract class GameCommanderImpl extends GameImpl {
super.init(choosingPlayerId); super.init(choosingPlayerId);
if (startingPlayerSkipsDraw) { if (startingPlayerSkipsDraw) {
state.getTurnMods().add(new TurnMod(startingPlayerId, PhaseStep.DRAW)); state.getTurnMods().add(new TurnMod(startingPlayerId).withSkipStep(PhaseStep.DRAW));
} }
} }

View file

@ -1041,7 +1041,7 @@ public abstract class GameImpl implements Game {
private boolean playExtraTurns() { private boolean playExtraTurns() {
//20091005 - 500.7 //20091005 - 500.7
TurnMod extraTurn = getNextExtraTurn(); TurnMod extraTurn = useNextExtraTurn();
try { try {
while (extraTurn != null) { while (extraTurn != null) {
GameEvent event = new GameEvent(GameEvent.EventType.PLAY_TURN, null, null, extraTurn.getPlayerId()); GameEvent event = new GameEvent(GameEvent.EventType.PLAY_TURN, null, null, extraTurn.getPlayerId());
@ -1049,15 +1049,13 @@ public abstract class GameImpl implements Game {
Player extraPlayer = this.getPlayer(extraTurn.getPlayerId()); Player extraPlayer = this.getPlayer(extraTurn.getPlayerId());
if (extraPlayer != null && extraPlayer.canRespond()) { if (extraPlayer != null && extraPlayer.canRespond()) {
state.setExtraTurnId(extraTurn.getId()); state.setExtraTurnId(extraTurn.getId());
if (!this.isSimulation()) { informPlayers(extraPlayer.getLogName() + " takes an extra turn");
informPlayers(extraPlayer.getLogName() + " takes an extra turn");
}
if (!playTurn(extraPlayer)) { if (!playTurn(extraPlayer)) {
return false; return false;
} }
} }
} }
extraTurn = getNextExtraTurn(); extraTurn = useNextExtraTurn();
} }
} finally { } finally {
state.setExtraTurnId(null); state.setExtraTurnId(null);
@ -1065,7 +1063,7 @@ public abstract class GameImpl implements Game {
return true; return true;
} }
private TurnMod getNextExtraTurn() { private TurnMod useNextExtraTurn() {
boolean checkForExtraTurn = true; boolean checkForExtraTurn = true;
while (checkForExtraTurn) { while (checkForExtraTurn) {
TurnMod extraTurn = getState().getTurnMods().getNextExtraTurn(); TurnMod extraTurn = getState().getTurnMods().getNextExtraTurn();

View file

@ -76,7 +76,7 @@ public class GameState implements Serializable, Copyable<GameState> {
private SpecialActions specialActions; private SpecialActions specialActions;
private Watchers watchers; private Watchers watchers;
private Turn turn; private Turn turn;
private TurnMods turnMods; private TurnMods turnMods; // one time turn modifications (turn, phase or step)
private UUID activePlayerId; // playerId which turn it is private UUID activePlayerId; // playerId which turn it is
private UUID priorityPlayerId; // player that has currently priority private UUID priorityPlayerId; // player that has currently priority
private UUID playerByOrderId; // player that has currently priority private UUID playerByOrderId; // player that has currently priority

View file

@ -29,6 +29,9 @@ public abstract class GameTinyLeadersImpl extends GameImpl {
protected boolean alsoHand; // replace also commander going to library protected boolean alsoHand; // replace also commander going to library
protected boolean alsoLibrary; // replace also commander going to library protected boolean alsoLibrary; // replace also commander going to library
// 103.7a In a two-player game, the player who plays first skips the draw step
// (see rule 504, "Draw Step") of his or her first turn.
protected boolean startingPlayerSkipsDraw = true; protected boolean startingPlayerSkipsDraw = true;
public GameTinyLeadersImpl(MultiplayerAttackOption attackOption, RangeOfInfluence range, Mulligan mulligan, int startLife) { public GameTinyLeadersImpl(MultiplayerAttackOption attackOption, RangeOfInfluence range, Mulligan mulligan, int startLife) {
@ -83,7 +86,7 @@ public abstract class GameTinyLeadersImpl extends GameImpl {
} }
super.init(choosingPlayerId); super.init(choosingPlayerId);
if (startingPlayerSkipsDraw) { if (startingPlayerSkipsDraw) {
state.getTurnMods().add(new TurnMod(startingPlayerId, PhaseStep.DRAW)); state.getTurnMods().add(new TurnMod(startingPlayerId).withSkipStep(PhaseStep.DRAW));
} }
} }

View file

@ -1,114 +1,55 @@
package mage.game.turn; package mage.game.turn;
import mage.constants.PhaseStep;
import mage.constants.TurnPhase;
import mage.util.Copyable;
import java.io.Serializable; import java.io.Serializable;
import java.util.UUID; import java.util.UUID;
import mage.constants.PhaseStep;
import mage.constants.TurnPhase;
/** /**
* stores extra turns, phases or steps * Creates a signle turn modification for turn, phase or step
* <p>
* For one time usage only
* <p>
* If you need it in continuous effect then use ContinuousRuleModifyingEffectImpl
* with game events like UNTAP_STEP (example: Sands of Time)
* <p>
* Supports:
* - new controller
* - turn: extra and skip
* - phase: extra and skip
* - step: extra and skip
* *
* @author BetaSteward_at_googlemail.com * @author JayDi85
*/ */
public class TurnMod implements Serializable { public class TurnMod implements Serializable, Copyable<TurnMod> {
private final UUID id; private final UUID id;
private final UUID playerId; private final UUID playerId;
private UUID newControllerId; private UUID newControllerId;
private boolean extraTurn; private boolean extraTurn;
private boolean skipTurn; private boolean skipTurn;
private TurnPhase extraPhase; private TurnPhase extraPhase;
private TurnPhase skipPhase; private TurnPhase skipPhase;
private Step extraStep; private Step extraStep;
private PhaseStep skipStep; private PhaseStep skipStep;
private TurnPhase afterPhase; private TurnPhase afterPhase;
private PhaseStep afterStep; private PhaseStep afterStep;
private boolean locked = false; // locked for modification, used for wrong code usage protection
private String note; private String note;
// Turn mod that should be applied after current turn mod. // Turn mod that should be applied after current turn mod
// Implemented only for control player turn mod! // Implemented only for new controller turn mod
// Added for Emrakul, the Promised End.
private TurnMod subsequentTurnMod; private TurnMod subsequentTurnMod;
/** private TurnMod(final TurnMod mod) {
* Used to define if a player skips the next turn or gets an extra turn.
*
* @param playerId
* @param skip - true = skips next turn, false = player gets extra turn
*/
public TurnMod(UUID playerId, boolean skip) {
this.id = UUID.randomUUID();
this.playerId = playerId;
if (skip) {
this.skipTurn = true;
}
else {
this.extraTurn = true;
}
}
/**
* Used to define that a player controlls the next turn of another player.
*
* @param playerId - id of the player whose next turn is controlled by newControllerId
* @param newControllerId - id of the player that controlls playerId's next turn
*/
public TurnMod(UUID playerId, UUID newControllerId) {
this.id = UUID.randomUUID();
this.playerId = playerId;
this.newControllerId = newControllerId;
}
/**
* Used to define if and when a player gets an extra phase.
*
* @param playerId
* @param phase
* @param afterPhase - set to null if extraPhase is after the next phase
* @param skip
*/
public TurnMod(UUID playerId, TurnPhase phase, TurnPhase afterPhase, boolean skip) {
this.id = UUID.randomUUID();
this.playerId = playerId;
if (skip) {
this.skipPhase = phase;
}
else {
this.extraPhase = phase;
}
this.afterPhase = afterPhase;
}
/**
* Used to define if and when a player gets an extra step.
*
* @param playerId
* @param step - extra step the player gets
* @param afterStep - set to null if extraStep is after the next step
*/
public TurnMod(UUID playerId, Step step, PhaseStep afterStep) {
this.id = UUID.randomUUID();
this.playerId = playerId;
this.extraStep = step;
this.afterStep = afterStep;
}
/**
* Used to define that a player skips the next time the specified step
*
* @param playerId
* @param step - step to skip the next time
*/
public TurnMod(UUID playerId, PhaseStep step) {
this.id = UUID.randomUUID();
this.playerId = playerId;
this.skipStep = step;
}
public TurnMod(final TurnMod mod) {
this.id = mod.id; this.id = mod.id;
this.playerId = mod.playerId; this.playerId = mod.playerId;
this.newControllerId = mod.newControllerId; this.newControllerId = mod.newControllerId;
@ -126,6 +67,86 @@ public class TurnMod implements Serializable {
this.subsequentTurnMod = mod.subsequentTurnMod.copy(); this.subsequentTurnMod = mod.subsequentTurnMod.copy();
} }
this.note = mod.note; this.note = mod.note;
this.locked = mod.locked;
}
public TurnMod copy() {
return new TurnMod(this);
}
public TurnMod(UUID playerId) {
// TODO: delete
this.id = UUID.randomUUID();
this.playerId = playerId;
}
private void lock() {
if (this.locked) {
throw new IllegalStateException("Wrong code usage: you must use only one type of turn modification");
}
this.locked = true;
}
public TurnMod withSkipTurn() {
this.skipTurn = true;
lock();
return this;
}
public TurnMod withExtraTurn() {
this.extraTurn = true;
lock();
return this;
}
public TurnMod withNewController(UUID newControllerId) {
return withNewController(newControllerId, null);
}
public TurnMod withNewController(UUID newControllerId, TurnMod nextSubsequentTurnMod) {
this.newControllerId = newControllerId;
this.subsequentTurnMod = nextSubsequentTurnMod;
lock();
return this;
}
public TurnMod withSkipPhase(TurnPhase skipPhase) {
this.skipPhase = skipPhase;
lock();
return this;
}
public TurnMod withExtraPhase(TurnPhase extraPhase) {
return withExtraPhase(extraPhase, null);
}
public TurnMod withExtraPhase(TurnPhase extraPhase, TurnPhase addAfterPhase) {
this.extraPhase = extraPhase;
this.afterPhase = addAfterPhase;
lock();
return this;
}
public TurnMod withSkipStep(PhaseStep skipStep) {
this.skipStep = skipStep;
lock();
return this;
}
public TurnMod withExtraStep(Step extraStep) {
return withExtraStep(extraStep, null);
}
public TurnMod withExtraStep(Step extraStep, PhaseStep addAfterStep) {
this.extraStep = extraStep;
this.afterStep = addAfterStep;
lock();
return this;
}
public TurnMod withNote(String note) {
this.note = note;
return this;
} }
public UUID getPlayerId() { public UUID getPlayerId() {
@ -168,10 +189,6 @@ public class TurnMod implements Serializable {
return newControllerId; return newControllerId;
} }
public TurnMod copy() {
return new TurnMod(this);
}
public UUID getId() { public UUID getId() {
return id; return id;
} }
@ -180,15 +197,11 @@ public class TurnMod implements Serializable {
return subsequentTurnMod; return subsequentTurnMod;
} }
public void setSubsequentTurnMod(TurnMod subsequentTurnMod) {
this.subsequentTurnMod = subsequentTurnMod;
}
public void setNote(String note) {
this.note = note;
}
public String getNote() { public String getNote() {
return note; return note;
} }
public boolean isLocked() {
return locked;
}
} }

View file

@ -1,37 +1,39 @@
package mage.game.turn; package mage.game.turn;
import java.io.Serializable;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.ListIterator; import java.util.ListIterator;
import java.util.UUID; import java.util.UUID;
import mage.constants.PhaseStep; import mage.constants.PhaseStep;
import mage.constants.TurnPhase; import mage.constants.TurnPhase;
import mage.util.Copyable;
/** /**
* Turn, phase and step modification for extra/skip (use it for one time mod only)
* *
* @author BetaSteward_at_googlemail.com * @author BetaSteward_at_googlemail.com
*/ */
public class TurnMods extends ArrayList<TurnMod> { public class TurnMods extends ArrayList<TurnMod> implements Serializable, Copyable<TurnMods> {
public TurnMods() { public TurnMods() {
} }
public TurnMods(final TurnMods mods) { private TurnMods(final TurnMods mods) {
for (TurnMod mod : mods) { for (TurnMod mod : mods) {
this.add(mod.copy()); this.add(mod.copy());
} }
} }
public UUID getExtraTurn(UUID playerId) { public TurnMods copy() {
ListIterator<TurnMod> it = this.listIterator(this.size()); return new TurnMods(this);
while (it.hasPrevious()) { }
TurnMod turnMod = it.previous();
if (turnMod.isExtraTurn() && turnMod.getPlayerId().equals(playerId)) { @Override
it.remove(); public boolean add(TurnMod turnMod) {
return turnMod.getId(); if (!turnMod.isLocked()) {
} throw new IllegalStateException("Wrong code usage: you must prepare turn mode with modification");
} }
return null; return super.add(turnMod);
} }
public TurnMod getNextExtraTurn() { public TurnMod getNextExtraTurn() {
@ -105,7 +107,6 @@ public class TurnMods extends ArrayList<TurnMod> {
if (turnMod.getSkipStep() == step) { if (turnMod.getSkipStep() == step) {
it.remove(); it.remove();
return true; return true;
} }
} }
} }
@ -137,9 +138,4 @@ public class TurnMods extends ArrayList<TurnMod> {
} }
return false; return false;
} }
public TurnMods copy() {
return new TurnMods(this);
}
} }