mirror of
https://github.com/magefree/mage.git
synced 2025-12-20 02:30:08 -08:00
refactor: improved usage of one time turn modifications (skip step, extra turn, etc)
This commit is contained in:
parent
4554fbc408
commit
8d938926b6
46 changed files with 222 additions and 190 deletions
|
|
@ -60,7 +60,7 @@ public class CustomPillarOfTheParunsDuel extends GameImpl {
|
|||
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) {
|
||||
|
|
|
|||
|
|
@ -54,7 +54,7 @@ public class MomirDuel extends GameImpl {
|
|||
}
|
||||
getState().addAbility(ability, null);
|
||||
super.init(choosingPlayerId);
|
||||
state.getTurnMods().add(new TurnMod(startingPlayerId, PhaseStep.DRAW));
|
||||
state.getTurnMods().add(new TurnMod(startingPlayerId).withSkipStep(PhaseStep.DRAW));
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
|||
|
|
@ -60,7 +60,7 @@ public class MomirGame extends GameImpl {
|
|||
}
|
||||
getState().addAbility(ability, null);
|
||||
super.init(choosingPlayerId);
|
||||
state.getTurnMods().add(new TurnMod(startingPlayerId, PhaseStep.DRAW));
|
||||
state.getTurnMods().add(new TurnMod(startingPlayerId).withSkipStep(PhaseStep.DRAW));
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
|||
|
|
@ -40,7 +40,7 @@ public class TwoPlayerDuel extends GameImpl {
|
|||
@Override
|
||||
protected void init(UUID choosingPlayerId) {
|
||||
super.init(choosingPlayerId);
|
||||
state.getTurnMods().add(new TurnMod(startingPlayerId, PhaseStep.DRAW));
|
||||
state.getTurnMods().add(new TurnMod(startingPlayerId).withSkipStep(PhaseStep.DRAW));
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
|||
|
|
@ -1,4 +1,3 @@
|
|||
|
||||
package mage.cards.b;
|
||||
|
||||
import java.util.UUID;
|
||||
|
|
@ -26,6 +25,7 @@ public final class BeaconOfTomorrows extends CardImpl {
|
|||
// Target player takes an extra turn after this one.
|
||||
this.getSpellAbility().addTarget(new TargetPlayer());
|
||||
this.getSpellAbility().addEffect(new BeaconOfTomorrowsEffect());
|
||||
|
||||
// Shuffle Beacon of Tomorrows into its owner's library.
|
||||
this.getSpellAbility().addEffect(ShuffleSpellEffect.getInstance());
|
||||
}
|
||||
|
|
@ -58,7 +58,11 @@ class BeaconOfTomorrowsEffect extends OneShotEffect {
|
|||
|
||||
@Override
|
||||
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;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -150,8 +150,7 @@ class BreathOfFuryEffect extends OneShotEffect {
|
|||
for (Permanent permanent : game.getBattlefield().getAllActivePermanents(new FilterControlledCreaturePermanent(), controller.getId(), game)) {
|
||||
permanent.untap(game);
|
||||
}
|
||||
|
||||
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;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -70,7 +70,7 @@ class BrineElementalEffect extends OneShotEffect {
|
|||
if (controller != null) {
|
||||
for (UUID playerId: game.getState().getPlayersInRange(controller.getId(), 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;
|
||||
|
|
|
|||
|
|
@ -63,8 +63,8 @@ class CruelEntertainmentEffect extends OneShotEffect {
|
|||
player2 = game.getPlayer(getTargetPointer().getTargets(game, source).get(1));
|
||||
}
|
||||
if (player1 != null && player2 != null) {
|
||||
game.getState().getTurnMods().add(new TurnMod(player1.getId(), player2.getId()));
|
||||
game.getState().getTurnMods().add(new TurnMod(player2.getId(), player1.getId()));
|
||||
game.getState().getTurnMods().add(new TurnMod(player1.getId()).withNewController(player2.getId()));
|
||||
game.getState().getTurnMods().add(new TurnMod(player2.getId()).withNewController(player1.getId()));
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
|
|
|
|||
|
|
@ -94,10 +94,9 @@ class EmrakulThePromisedEndGainControlEffect extends OneShotEffect {
|
|||
Player controller = game.getPlayer(source.getControllerId());
|
||||
Player targetPlayer = game.getPlayer(this.getTargetPointer().getFirst(game, source));
|
||||
if (controller != null && targetPlayer != null) {
|
||||
TurnMod controlPlayerTurnMod = new TurnMod(targetPlayer.getId(), controller.getId());
|
||||
TurnMod extraTurnMod = new TurnMod(targetPlayer.getId(), false);
|
||||
controlPlayerTurnMod.setSubsequentTurnMod(extraTurnMod);
|
||||
game.getState().getTurnMods().add(controlPlayerTurnMod);
|
||||
TurnMod extraTurnMod = new TurnMod(targetPlayer.getId()).withExtraTurn();
|
||||
TurnMod newControllerTurnMod = new TurnMod(targetPlayer.getId()).withNewController(controller.getId(), extraTurnMod);
|
||||
game.getState().getTurnMods().add(newControllerTurnMod);
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
|
|
|
|||
|
|
@ -84,7 +84,7 @@ class EonFrolickerEffect extends OneShotEffect {
|
|||
if (player == null) {
|
||||
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());
|
||||
filter.add(new PlayerIdPredicate(player.getId()));
|
||||
Ability ability = new ProtectionAbility(filter);
|
||||
|
|
|
|||
|
|
@ -81,7 +81,7 @@ class ExpropriateEffect extends OneShotEffect {
|
|||
// extra turn
|
||||
int timeCount = vote.getVoteCount(true);
|
||||
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
|
||||
|
|
|
|||
|
|
@ -74,7 +74,7 @@ class HellkiteChargerEffect extends OneShotEffect {
|
|||
cost.clearPaid();
|
||||
if (cost.pay(source, game, source, source.getControllerId(), false, null)) {
|
||||
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;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -72,7 +72,7 @@ class IllusionistsGambitRemoveFromCombatEffect extends OneShotEffect {
|
|||
}
|
||||
if (!attackers.isEmpty()) {
|
||||
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);
|
||||
game.addEffect(effect, source);
|
||||
effect = new IllusionistsGambitRestrictionEffect(attackers, phase);
|
||||
|
|
|
|||
|
|
@ -66,13 +66,15 @@ class KarnsTemporalSunderingEffect extends OneShotEffect {
|
|||
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());
|
||||
|
||||
if (returnPermanent != null) {
|
||||
controller.moveCards(returnPermanent, Zone.HAND, source, game);
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -75,7 +75,7 @@ class LostIsleCallingEffect extends OneShotEffect {
|
|||
int count = permanent.getCounters(game).getCount(CounterType.VERSE);
|
||||
player.drawCards(count, source, game);
|
||||
if (count >= 7) {
|
||||
game.getState().getTurnMods().add(new TurnMod(player.getId(), false));
|
||||
game.getState().getTurnMods().add(new TurnMod(player.getId()).withExtraTurn());
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -55,7 +55,7 @@ class SpipTurnEffect extends OneShotEffect {
|
|||
|
||||
@Override
|
||||
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;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -119,12 +119,13 @@ class MoraugFuryOfAkoumCombatEffect extends OneShotEffect {
|
|||
&& turnMod.getPlayerId().equals(source.getControllerId())
|
||||
&& turnMod.getAfterPhase() == turnPhase) {
|
||||
turnPhase = TurnPhase.COMBAT;
|
||||
turnMod.setNote("moraugIgnore");
|
||||
turnMod.withNote("moraugIgnore");
|
||||
break;
|
||||
}
|
||||
}
|
||||
TurnMod combat = new TurnMod(source.getControllerId(), TurnPhase.COMBAT, turnPhase, false);
|
||||
combat.setNote("moraug");
|
||||
TurnMod combat = new TurnMod(source.getControllerId())
|
||||
.withExtraPhase(TurnPhase.COMBAT, turnPhase)
|
||||
.withNote("moraug");
|
||||
game.getState().getTurnMods().add(combat);
|
||||
game.addDelayedTriggeredAbility(new MoraugFuryOfAkoumDelayedTriggeredAbility(combat.getId()), source);
|
||||
return true;
|
||||
|
|
@ -193,7 +194,7 @@ class MoraugFuryOfAkoumWatcher extends Watcher {
|
|||
}
|
||||
for (TurnMod turnMod : game.getState().getTurnMods()) {
|
||||
if ("moraug".equals(turnMod.getNote())) {
|
||||
turnMod.setNote("moraugIgnore");
|
||||
turnMod.withNote("moraugIgnore");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -17,7 +17,6 @@ public final class Opportunity extends CardImpl {
|
|||
public Opportunity(UUID ownerId, CardSetInfo setInfo) {
|
||||
super(ownerId,setInfo,new CardType[]{CardType.INSTANT},"{4}{U}{U}");
|
||||
|
||||
|
||||
// Target player draws four cards.
|
||||
this.getSpellAbility().addEffect(new DrawCardTargetEffect(4));
|
||||
this.getSpellAbility().addTarget(new TargetPlayer());
|
||||
|
|
|
|||
|
|
@ -105,7 +105,10 @@ class ParadoxHazeEffect extends OneShotEffect {
|
|||
|
||||
@Override
|
||||
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;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -99,7 +99,7 @@ class RalZarekExtraTurnsEffect extends OneShotEffect {
|
|||
if (controller != null) {
|
||||
for (int i = 0; i < 5; i++) {
|
||||
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;
|
||||
|
|
|
|||
|
|
@ -78,7 +78,7 @@ class SageOfHoursEffect extends OneShotEffect {
|
|||
}
|
||||
int turns = countersRemoved / 5;
|
||||
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 +
|
||||
" +1/+1 counters: " + player.getLogName() + " takes " +
|
||||
|
|
|
|||
|
|
@ -54,7 +54,7 @@ class SkipNextUntapStepSourceControllerEffect extends OneShotEffect {
|
|||
public boolean apply(Game game, Ability source) {
|
||||
Player controller = game.getPlayer(source.getControllerId());
|
||||
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 false;
|
||||
|
|
|
|||
|
|
@ -164,7 +164,7 @@ class SearchTheCityExiledCardToHandEffect extends OneShotEffect {
|
|||
if (permanent != null) {
|
||||
permanent.sacrifice(source, game);
|
||||
// extra turn
|
||||
game.getState().getTurnMods().add(new TurnMod(source.getControllerId(), false));
|
||||
game.getState().getTurnMods().add(new TurnMod(source.getControllerId()).withExtraTurn());
|
||||
}
|
||||
}
|
||||
return true;
|
||||
|
|
|
|||
|
|
@ -70,12 +70,13 @@ class SphinxOfTheSecondSunEffect extends OneShotEffect {
|
|||
&& turnMod.getPlayerId().equals(source.getControllerId())
|
||||
&& turnMod.getAfterPhase() == turnPhase) {
|
||||
turnPhase = TurnPhase.BEGINNING;
|
||||
turnMod.setNote("sphinxSecondSunIgnore");
|
||||
turnMod.withNote("sphinxSecondSunIgnore");
|
||||
break;
|
||||
}
|
||||
}
|
||||
TurnMod newPhase = new TurnMod(source.getControllerId(), TurnPhase.BEGINNING, turnPhase, false);
|
||||
newPhase.setNote("sphinxSecondSun");
|
||||
TurnMod newPhase = new TurnMod(source.getControllerId())
|
||||
.withExtraPhase(TurnPhase.BEGINNING, turnPhase)
|
||||
.withNote("sphinxSecondSun");
|
||||
game.getState().getTurnMods().add(newPhase);
|
||||
return true;
|
||||
}
|
||||
|
|
@ -94,7 +95,7 @@ class SphinxOfTheSecondSunWatcher extends Watcher {
|
|||
}
|
||||
for (TurnMod turnMod : game.getState().getTurnMods()) {
|
||||
if ("sphinxSecondSun".equals(turnMod.getNote())) {
|
||||
turnMod.setNote("sphinxSecondSunIgnore");
|
||||
turnMod.withNote("sphinxSecondSunIgnore");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -53,7 +53,7 @@ class StitchInTimeEffect extends OneShotEffect {
|
|||
Player player = game.getPlayer(source.getControllerId());
|
||||
if (player != null) {
|
||||
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;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -107,8 +107,8 @@ class TeferiMasterOfTimeTurnEffect extends OneShotEffect {
|
|||
|
||||
@Override
|
||||
public boolean apply(Game game, Ability source) {
|
||||
game.getState().getTurnMods().add(new TurnMod(source.getControllerId(), false));
|
||||
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()).withExtraTurn());
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -56,8 +56,12 @@ class TimeStretchEffect extends OneShotEffect {
|
|||
|
||||
@Override
|
||||
public boolean apply(Game game, Ability source) {
|
||||
game.getState().getTurnMods().add(new TurnMod(source.getFirstTarget(), false));
|
||||
game.getState().getTurnMods().add(new TurnMod(source.getFirstTarget(), false));
|
||||
if (source.getFirstTarget() == null) {
|
||||
return false;
|
||||
}
|
||||
|
||||
game.getState().getTurnMods().add(new TurnMod(source.getFirstTarget()).withExtraTurn());
|
||||
game.getState().getTurnMods().add(new TurnMod(source.getFirstTarget()).withExtraTurn());
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -55,8 +55,10 @@ class TimeWarpEffect extends OneShotEffect {
|
|||
|
||||
@Override
|
||||
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;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -64,7 +64,7 @@ class WorldAtWarEffect extends OneShotEffect {
|
|||
@Override
|
||||
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
|
||||
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);
|
||||
UntapDelayedTriggeredAbility delayedTriggeredAbility = new UntapDelayedTriggeredAbility();
|
||||
delayedTriggeredAbility.setConnectedTurnMod(combat.getId());
|
||||
|
|
@ -107,7 +107,7 @@ class UntapDelayedTriggeredAbility extends DelayedTriggeredAbility {
|
|||
}
|
||||
if (event.getType() == GameEvent.EventType.COMBAT_PHASE_PRE && enabled) {
|
||||
// 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;
|
||||
return true;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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.
|
||||
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.
|
||||
this.addAbility(new DealsCombatDamageToAPlayerTriggeredAbility(new XyrisTheWrithingStormCombatDamageEffect(), false, true));
|
||||
}
|
||||
|
|
|
|||
|
|
@ -34,9 +34,7 @@ public class OpponentDrawCardExceptFirstCardDrawStepTriggeredAbility extends Tri
|
|||
if (game.isActivePlayer(event.getPlayerId())
|
||||
&& game.getPhase().getStep().getType() == PhaseStep.DRAW) {
|
||||
CardsDrawnDuringDrawStepWatcher watcher = game.getState().getWatcher(CardsDrawnDuringDrawStepWatcher.class);
|
||||
if (watcher != null && watcher.getAmountCardsDrawn(event.getPlayerId()) > 1) {
|
||||
return true;
|
||||
}
|
||||
return watcher != null && watcher.getAmountCardsDrawn(event.getPlayerId()) > 1;
|
||||
} else {
|
||||
return true;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -38,7 +38,7 @@ public class AddCombatAndMainPhaseEffect extends OneShotEffect {
|
|||
if (game.getTurnPhaseType() == TurnPhase.PRECOMBAT_MAIN
|
||||
|| game.getTurnPhaseType() == TurnPhase.POSTCOMBAT_MAIN) {
|
||||
// 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);
|
||||
DelayedAddMainPhaseAbility delayedTriggeredAbility = new DelayedAddMainPhaseAbility();
|
||||
delayedTriggeredAbility.setConnectedTurnMod(combat.getId());
|
||||
|
|
@ -83,7 +83,7 @@ class DelayedAddMainPhaseAbility extends DelayedTriggeredAbility {
|
|||
}
|
||||
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
|
||||
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;
|
||||
}
|
||||
return false;
|
||||
|
|
|
|||
|
|
@ -30,8 +30,7 @@ public class AdditionalCombatPhaseEffect extends OneShotEffect {
|
|||
|
||||
@Override
|
||||
public boolean apply(Game game, Ability source) {
|
||||
game.getState().getTurnMods().add(new TurnMod(game.getState().getActivePlayerId(),
|
||||
TurnPhase.COMBAT, null, false));
|
||||
game.getState().getTurnMods().add(new TurnMod(game.getState().getActivePlayerId()).withExtraPhase(TurnPhase.COMBAT));
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -60,7 +60,7 @@ public class SkipNextDrawStepControllerEffect extends OneShotEffect {
|
|||
public boolean apply(Game game, Ability source) {
|
||||
Player player = game.getPlayer(source.getControllerId());
|
||||
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 false;
|
||||
|
|
|
|||
|
|
@ -68,7 +68,7 @@ public class SkipNextPlayerUntapStepEffect extends OneShotEffect {
|
|||
}
|
||||
}
|
||||
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 false;
|
||||
|
|
|
|||
|
|
@ -59,7 +59,7 @@ public class AddExtraTurnControllerEffect extends OneShotEffect {
|
|||
if (player == null) {
|
||||
return true;
|
||||
}
|
||||
TurnMod extraTurn = new TurnMod(player.getId(), false);
|
||||
TurnMod extraTurn = new TurnMod(player.getId()).withExtraTurn();
|
||||
game.getState().getTurnMods().add(extraTurn);
|
||||
if (loseGameAtEnd) {
|
||||
game.addDelayedTriggeredAbility(new LoseGameDelayedTriggeredAbility(extraTurn.getId()), source);
|
||||
|
|
|
|||
|
|
@ -29,7 +29,7 @@ public class AddExtraTurnTargetEffect extends OneShotEffect {
|
|||
@Override
|
||||
public boolean apply(Game game, Ability source) {
|
||||
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;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -5,7 +5,9 @@ import mage.abilities.effects.OneShotEffect;
|
|||
import mage.constants.Outcome;
|
||||
import mage.game.Game;
|
||||
import mage.game.turn.TurnMod;
|
||||
import mage.players.Player;
|
||||
|
||||
import java.util.Objects;
|
||||
import java.util.UUID;
|
||||
|
||||
/**
|
||||
|
|
@ -24,12 +26,16 @@ public class ControlTargetPlayerNextTurnEffect extends OneShotEffect {
|
|||
|
||||
@Override
|
||||
public boolean apply(Game game, Ability source) {
|
||||
UUID targetId = source.getFirstTarget();
|
||||
UUID controllerId = source.getControllerId();
|
||||
if (targetId != null && controllerId != null && !targetId.equals(controllerId)) {
|
||||
game.getState().getTurnMods().add(new TurnMod(targetId, controllerId));
|
||||
Player targetPlayer = game.getPlayer(source.getFirstTarget());
|
||||
if (targetPlayer == null) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!Objects.equals(source.getControllerId(), targetPlayer.getId())) {
|
||||
game.getState().getTurnMods().add(new TurnMod(targetPlayer.getId()).withNewController(source.getControllerId()));
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -47,7 +47,7 @@ public class SkipNextTurnSourceEffect extends OneShotEffect {
|
|||
playerId = source.getControllerId();
|
||||
}
|
||||
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;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -22,7 +22,9 @@ public abstract class GameCanadianHighlanderImpl extends GameImpl {
|
|||
@Override
|
||||
protected void init(UUID 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));
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -29,6 +29,8 @@ public abstract class GameCommanderImpl extends GameImpl {
|
|||
protected boolean alsoHand = true; // replace commander going to hand
|
||||
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;
|
||||
|
||||
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);
|
||||
if (startingPlayerSkipsDraw) {
|
||||
state.getTurnMods().add(new TurnMod(startingPlayerId, PhaseStep.DRAW));
|
||||
state.getTurnMods().add(new TurnMod(startingPlayerId).withSkipStep(PhaseStep.DRAW));
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -1041,7 +1041,7 @@ public abstract class GameImpl implements Game {
|
|||
|
||||
private boolean playExtraTurns() {
|
||||
//20091005 - 500.7
|
||||
TurnMod extraTurn = getNextExtraTurn();
|
||||
TurnMod extraTurn = useNextExtraTurn();
|
||||
try {
|
||||
while (extraTurn != null) {
|
||||
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());
|
||||
if (extraPlayer != null && extraPlayer.canRespond()) {
|
||||
state.setExtraTurnId(extraTurn.getId());
|
||||
if (!this.isSimulation()) {
|
||||
informPlayers(extraPlayer.getLogName() + " takes an extra turn");
|
||||
}
|
||||
informPlayers(extraPlayer.getLogName() + " takes an extra turn");
|
||||
if (!playTurn(extraPlayer)) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
extraTurn = getNextExtraTurn();
|
||||
extraTurn = useNextExtraTurn();
|
||||
}
|
||||
} finally {
|
||||
state.setExtraTurnId(null);
|
||||
|
|
@ -1065,7 +1063,7 @@ public abstract class GameImpl implements Game {
|
|||
return true;
|
||||
}
|
||||
|
||||
private TurnMod getNextExtraTurn() {
|
||||
private TurnMod useNextExtraTurn() {
|
||||
boolean checkForExtraTurn = true;
|
||||
while (checkForExtraTurn) {
|
||||
TurnMod extraTurn = getState().getTurnMods().getNextExtraTurn();
|
||||
|
|
|
|||
|
|
@ -76,7 +76,7 @@ public class GameState implements Serializable, Copyable<GameState> {
|
|||
private SpecialActions specialActions;
|
||||
private Watchers watchers;
|
||||
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 priorityPlayerId; // player that has currently priority
|
||||
private UUID playerByOrderId; // player that has currently priority
|
||||
|
|
|
|||
|
|
@ -29,6 +29,9 @@ public abstract class GameTinyLeadersImpl extends GameImpl {
|
|||
|
||||
protected boolean alsoHand; // 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;
|
||||
|
||||
public GameTinyLeadersImpl(MultiplayerAttackOption attackOption, RangeOfInfluence range, Mulligan mulligan, int startLife) {
|
||||
|
|
@ -83,7 +86,7 @@ public abstract class GameTinyLeadersImpl extends GameImpl {
|
|||
}
|
||||
super.init(choosingPlayerId);
|
||||
if (startingPlayerSkipsDraw) {
|
||||
state.getTurnMods().add(new TurnMod(startingPlayerId, PhaseStep.DRAW));
|
||||
state.getTurnMods().add(new TurnMod(startingPlayerId).withSkipStep(PhaseStep.DRAW));
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -1,114 +1,55 @@
|
|||
|
||||
|
||||
package mage.game.turn;
|
||||
|
||||
import mage.constants.PhaseStep;
|
||||
import mage.constants.TurnPhase;
|
||||
import mage.util.Copyable;
|
||||
|
||||
import java.io.Serializable;
|
||||
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 playerId;
|
||||
|
||||
private UUID newControllerId;
|
||||
|
||||
private boolean extraTurn;
|
||||
private boolean skipTurn;
|
||||
|
||||
private TurnPhase extraPhase;
|
||||
private TurnPhase skipPhase;
|
||||
|
||||
private Step extraStep;
|
||||
private PhaseStep skipStep;
|
||||
|
||||
private TurnPhase afterPhase;
|
||||
private PhaseStep afterStep;
|
||||
|
||||
private boolean locked = false; // locked for modification, used for wrong code usage protection
|
||||
private String note;
|
||||
|
||||
// Turn mod that should be applied after current turn mod.
|
||||
// Implemented only for control player turn mod!
|
||||
// Added for Emrakul, the Promised End.
|
||||
// Turn mod that should be applied after current turn mod
|
||||
// Implemented only for new controller turn mod
|
||||
private TurnMod subsequentTurnMod;
|
||||
|
||||
/**
|
||||
* 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) {
|
||||
private TurnMod(final TurnMod mod) {
|
||||
this.id = mod.id;
|
||||
this.playerId = mod.playerId;
|
||||
this.newControllerId = mod.newControllerId;
|
||||
|
|
@ -126,6 +67,86 @@ public class TurnMod implements Serializable {
|
|||
this.subsequentTurnMod = mod.subsequentTurnMod.copy();
|
||||
}
|
||||
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() {
|
||||
|
|
@ -168,10 +189,6 @@ public class TurnMod implements Serializable {
|
|||
return newControllerId;
|
||||
}
|
||||
|
||||
public TurnMod copy() {
|
||||
return new TurnMod(this);
|
||||
}
|
||||
|
||||
public UUID getId() {
|
||||
return id;
|
||||
}
|
||||
|
|
@ -180,15 +197,11 @@ public class TurnMod implements Serializable {
|
|||
return subsequentTurnMod;
|
||||
}
|
||||
|
||||
public void setSubsequentTurnMod(TurnMod subsequentTurnMod) {
|
||||
this.subsequentTurnMod = subsequentTurnMod;
|
||||
}
|
||||
|
||||
public void setNote(String note) {
|
||||
this.note = note;
|
||||
}
|
||||
|
||||
public String getNote() {
|
||||
return note;
|
||||
}
|
||||
}
|
||||
|
||||
public boolean isLocked() {
|
||||
return locked;
|
||||
}
|
||||
}
|
||||
|
|
@ -1,37 +1,39 @@
|
|||
|
||||
package mage.game.turn;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.util.ArrayList;
|
||||
import java.util.ListIterator;
|
||||
import java.util.UUID;
|
||||
import mage.constants.PhaseStep;
|
||||
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
|
||||
*/
|
||||
public class TurnMods extends ArrayList<TurnMod> {
|
||||
public class TurnMods extends ArrayList<TurnMod> implements Serializable, Copyable<TurnMods> {
|
||||
|
||||
public TurnMods() {
|
||||
}
|
||||
|
||||
public TurnMods(final TurnMods mods) {
|
||||
private TurnMods(final TurnMods mods) {
|
||||
for (TurnMod mod : mods) {
|
||||
this.add(mod.copy());
|
||||
}
|
||||
}
|
||||
|
||||
public UUID getExtraTurn(UUID playerId) {
|
||||
ListIterator<TurnMod> it = this.listIterator(this.size());
|
||||
while (it.hasPrevious()) {
|
||||
TurnMod turnMod = it.previous();
|
||||
if (turnMod.isExtraTurn() && turnMod.getPlayerId().equals(playerId)) {
|
||||
it.remove();
|
||||
return turnMod.getId();
|
||||
}
|
||||
public TurnMods copy() {
|
||||
return new TurnMods(this);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean add(TurnMod turnMod) {
|
||||
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() {
|
||||
|
|
@ -105,7 +107,6 @@ public class TurnMods extends ArrayList<TurnMod> {
|
|||
if (turnMod.getSkipStep() == step) {
|
||||
it.remove();
|
||||
return true;
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -137,9 +138,4 @@ public class TurnMods extends ArrayList<TurnMod> {
|
|||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public TurnMods copy() {
|
||||
return new TurnMods(this);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue