mirror of
https://github.com/correl/mage.git
synced 2025-04-14 01:01:08 -09:00
* Some changes to skip turn handling (turn count and messages).
This commit is contained in:
parent
5fb17ce920
commit
dbff7bedb9
4 changed files with 117 additions and 34 deletions
Mage.Tests/src/test/java/org/mage/test/turnmod
Mage/src/mage
|
@ -0,0 +1,63 @@
|
|||
/*
|
||||
* Copyright 2010 BetaSteward_at_googlemail.com. All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without modification, are
|
||||
* permitted provided that the following conditions are met:
|
||||
*
|
||||
* 1. Redistributions of source code must retain the above copyright notice, this list of
|
||||
* conditions and the following disclaimer.
|
||||
*
|
||||
* 2. Redistributions in binary form must reproduce the above copyright notice, this list
|
||||
* of conditions and the following disclaimer in the documentation and/or other materials
|
||||
* provided with the distribution.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY BetaSteward_at_googlemail.com ``AS IS'' AND ANY EXPRESS OR IMPLIED
|
||||
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
|
||||
* FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL BetaSteward_at_googlemail.com OR
|
||||
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
||||
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
|
||||
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
|
||||
* ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
|
||||
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
|
||||
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
* The views and conclusions contained in the software and documentation are those of the
|
||||
* authors and should not be interpreted as representing official policies, either expressed
|
||||
* or implied, of BetaSteward_at_googlemail.com.
|
||||
*/
|
||||
package org.mage.test.turnmod;
|
||||
|
||||
import mage.constants.PhaseStep;
|
||||
import mage.constants.Zone;
|
||||
import mage.counters.CounterType;
|
||||
import org.junit.Test;
|
||||
import org.mage.test.serverside.base.CardTestPlayerBase;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author LevelX2
|
||||
*/
|
||||
public class SkipTurnTest extends CardTestPlayerBase {
|
||||
|
||||
@Test
|
||||
public void testEaterOfDays() {
|
||||
// At the beginning of your upkeep or whenever you cast a green spell, put a charge counter on Shrine of Boundless Growth.
|
||||
// {T}, Sacrifice Shrine of Boundless Growth: Add {1} to your mana pool for each charge counter on Shrine of Boundless Growth.
|
||||
addCard(Zone.HAND, playerA, "Shrine of Boundless Growth", 1);
|
||||
addCard(Zone.BATTLEFIELD, playerA, "Island", 7);
|
||||
// Flying
|
||||
// Trample
|
||||
// When Eater of Days enters the battlefield, you skip your next two turns.
|
||||
addCard(Zone.HAND, playerA, "Eater of Days", 1);
|
||||
|
||||
castSpell(1, PhaseStep.PRECOMBAT_MAIN, playerA, "Eater of Days");
|
||||
castSpell(1, PhaseStep.PRECOMBAT_MAIN, playerA, "Shrine of Boundless Growth");
|
||||
|
||||
setStopAt(5, PhaseStep.PRECOMBAT_MAIN);
|
||||
execute();
|
||||
|
||||
assertPermanentCount(playerA, "Eater of Days", 1);
|
||||
assertPermanentCount(playerA, "Shrine of Boundless Growth", 1);
|
||||
assertCounterCount("Shrine of Boundless Growth", CounterType.CHARGE, 1);
|
||||
}
|
||||
}
|
|
@ -10,20 +10,29 @@ import mage.abilities.effects.OneShotEffect;
|
|||
import mage.constants.Outcome;
|
||||
import mage.game.Game;
|
||||
import mage.game.turn.TurnMod;
|
||||
import mage.util.CardUtil;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Mael
|
||||
*/
|
||||
public class SkipNextTurnSourceEffect extends OneShotEffect {
|
||||
|
||||
|
||||
int numberOfTurns;
|
||||
|
||||
public SkipNextTurnSourceEffect() {
|
||||
this(1);
|
||||
}
|
||||
|
||||
public SkipNextTurnSourceEffect(int numberOfTurns) {
|
||||
super(Outcome.Neutral);
|
||||
staticText = "You skip your next turn";
|
||||
this.numberOfTurns = numberOfTurns;
|
||||
staticText = "you skip your next " + (numberOfTurns == 1 ? "turn" : CardUtil.numberToText(numberOfTurns) + " turns");
|
||||
}
|
||||
|
||||
public SkipNextTurnSourceEffect(final SkipNextTurnSourceEffect effect) {
|
||||
super(effect);
|
||||
this.numberOfTurns = effect.numberOfTurns;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -33,7 +42,9 @@ public class SkipNextTurnSourceEffect extends OneShotEffect {
|
|||
|
||||
@Override
|
||||
public boolean apply(Game game, Ability source) {
|
||||
game.getState().getTurnMods().add(new TurnMod(source.getControllerId(), true));
|
||||
for (int i = 0; i < numberOfTurns; i++) {
|
||||
game.getState().getTurnMods().add(new TurnMod(source.getControllerId(), true));
|
||||
}
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -700,7 +700,6 @@ public abstract class GameImpl implements Game, Serializable {
|
|||
if (!playTurn(playerByOrder)) {
|
||||
break;
|
||||
}
|
||||
state.setTurnNum(state.getTurnNum() + 1);
|
||||
}
|
||||
playExtraTurns();
|
||||
playerByOrder = playerList.getNext(this);
|
||||
|
@ -741,7 +740,6 @@ public abstract class GameImpl implements Game, Serializable {
|
|||
informPlayers(extraPlayer.getLogName() + " takes an extra turn");
|
||||
}
|
||||
playTurn(extraPlayer);
|
||||
state.setTurnNum(state.getTurnNum() + 1);
|
||||
}
|
||||
}
|
||||
extraTurn = getNextExtraTurn();
|
||||
|
@ -768,6 +766,7 @@ public abstract class GameImpl implements Game, Serializable {
|
|||
}
|
||||
|
||||
private boolean playTurn(Player player) {
|
||||
boolean skipTurn = false;
|
||||
do {
|
||||
if (executingRollback) {
|
||||
executingRollback = false;
|
||||
|
@ -781,41 +780,23 @@ public abstract class GameImpl implements Game, Serializable {
|
|||
state.setActivePlayerId(player.getId());
|
||||
saveRollBackGameState();
|
||||
}
|
||||
this.logStartOfTurn(player);
|
||||
if (checkStopOnTurnOption()) {
|
||||
return false;
|
||||
}
|
||||
state.getTurn().play(this, player);
|
||||
skipTurn = state.getTurn().play(this, player);
|
||||
} while (executingRollback);
|
||||
|
||||
if (isPaused() || gameOver(null)) {
|
||||
return false;
|
||||
}
|
||||
endOfTurn();
|
||||
if (!skipTurn) {
|
||||
endOfTurn();
|
||||
state.setTurnNum(state.getTurnNum() + 1);
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
private void logStartOfTurn(Player player) {
|
||||
StringBuilder sb = new StringBuilder("Turn ").append(state.getTurnNum()).append(" ");
|
||||
sb.append(player.getLogName());
|
||||
sb.append(" (");
|
||||
int delimiter = this.getPlayers().size() - 1;
|
||||
for (Player gamePlayer : this.getPlayers().values()) {
|
||||
sb.append(gamePlayer.getLife());
|
||||
int poison = gamePlayer.getCounters().getCount(CounterType.POISON);
|
||||
if (poison > 0) {
|
||||
sb.append("[P:").append(poison).append("]");
|
||||
}
|
||||
if (delimiter > 0) {
|
||||
sb.append(" - ");
|
||||
delimiter--;
|
||||
}
|
||||
}
|
||||
sb.append(")");
|
||||
fireStatusEvent(sb.toString(), true);
|
||||
}
|
||||
|
||||
private boolean checkStopOnTurnOption() {
|
||||
if (gameOptions.stopOnTurn != null && gameOptions.stopAtStep == PhaseStep.UNTAP) {
|
||||
if (gameOptions.stopOnTurn.equals(state.getTurnNum())) {
|
||||
|
|
|
@ -34,6 +34,7 @@ import java.util.List;
|
|||
import java.util.UUID;
|
||||
import mage.constants.PhaseStep;
|
||||
import mage.constants.TurnPhase;
|
||||
import mage.counters.CounterType;
|
||||
import mage.game.Game;
|
||||
import mage.game.events.GameEvent;
|
||||
import mage.game.permanent.Permanent;
|
||||
|
@ -116,16 +117,24 @@ public class Turn implements Serializable {
|
|||
return null;
|
||||
}
|
||||
|
||||
public void play(Game game, Player activePlayer) {
|
||||
/**
|
||||
*
|
||||
* @param game
|
||||
* @param activePlayer
|
||||
* @return true if turn is skipped
|
||||
*/
|
||||
public boolean play(Game game, Player activePlayer) {
|
||||
activePlayer.becomesActivePlayer();
|
||||
this.setDeclareAttackersStepStarted(false);
|
||||
if (game.isPaused() || game.gameOver(null)) {
|
||||
return;
|
||||
return false;
|
||||
}
|
||||
|
||||
if (game.getState().getTurnMods().skipTurn(activePlayer.getId())) {
|
||||
return;
|
||||
game.informPlayers(activePlayer.getLogName() + " skips his or her turn.");
|
||||
return true;
|
||||
}
|
||||
logStartOfTurn(game, activePlayer);
|
||||
|
||||
checkTurnIsControlledByOtherPlayer(game, activePlayer.getId());
|
||||
|
||||
|
@ -134,7 +143,7 @@ public class Turn implements Serializable {
|
|||
game.getPlayer(activePlayer.getId()).beginTurn(game);
|
||||
for (Phase phase : phases) {
|
||||
if (game.isPaused() || game.gameOver(null)) {
|
||||
return;
|
||||
return false;
|
||||
}
|
||||
if (!isEndTurnRequested() || phase.getType().equals(TurnPhase.END)) {
|
||||
currentPhase = phase;
|
||||
|
@ -142,7 +151,7 @@ public class Turn implements Serializable {
|
|||
if (!game.getState().getTurnMods().skipPhase(activePlayer.getId(), currentPhase.getType())) {
|
||||
if (phase.play(game, activePlayer.getId())) {
|
||||
if (game.executingRollback()) {
|
||||
return;
|
||||
return false;
|
||||
}
|
||||
//20091005 - 500.4/703.4n
|
||||
game.emptyManaPools();
|
||||
|
@ -155,7 +164,7 @@ public class Turn implements Serializable {
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
public void resumePlay(Game game, boolean wasPaused) {
|
||||
|
@ -327,4 +336,23 @@ public class Turn implements Serializable {
|
|||
return sb.toString();
|
||||
}
|
||||
|
||||
private void logStartOfTurn(Game game, Player player) {
|
||||
StringBuilder sb = new StringBuilder("Turn ").append(game.getState().getTurnNum()).append(" ");
|
||||
sb.append(player.getLogName());
|
||||
sb.append(" (");
|
||||
int delimiter = game.getPlayers().size() - 1;
|
||||
for (Player gamePlayer : game.getPlayers().values()) {
|
||||
sb.append(gamePlayer.getLife());
|
||||
int poison = gamePlayer.getCounters().getCount(CounterType.POISON);
|
||||
if (poison > 0) {
|
||||
sb.append("[P:").append(poison).append("]");
|
||||
}
|
||||
if (delimiter > 0) {
|
||||
sb.append(" - ");
|
||||
delimiter--;
|
||||
}
|
||||
}
|
||||
sb.append(")");
|
||||
game.fireStatusEvent(sb.toString(), true);
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue