mirror of
https://github.com/magefree/mage.git
synced 2025-12-25 21:12:04 -08:00
Some rework to end turn logic and removing of stack objects (related to #2977).
This commit is contained in:
parent
2446abcc98
commit
097a8ce0dd
9 changed files with 110 additions and 104 deletions
|
|
@ -27,6 +27,9 @@
|
|||
*/
|
||||
package mage.abilities;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.util.List;
|
||||
import java.util.UUID;
|
||||
import mage.MageObject;
|
||||
import mage.abilities.costs.Cost;
|
||||
import mage.abilities.costs.Costs;
|
||||
|
|
@ -46,11 +49,6 @@ import mage.target.Target;
|
|||
import mage.target.Targets;
|
||||
import mage.watchers.Watcher;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.util.List;
|
||||
import java.util.Optional;
|
||||
import java.util.UUID;
|
||||
|
||||
/**
|
||||
* Practically everything in the game is started from an Ability. This interface
|
||||
* describes what an Ability is composed of at the highest level.
|
||||
|
|
|
|||
|
|
@ -48,7 +48,7 @@ public class EndTurnEffect extends OneShotEffect {
|
|||
if (!game.isSimulation()) {
|
||||
game.informPlayers("The current turn ends");
|
||||
}
|
||||
return game.endTurn();
|
||||
return game.endTurn(source);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
|||
|
|
@ -27,6 +27,8 @@
|
|||
*/
|
||||
package mage.game;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.util.*;
|
||||
import mage.MageItem;
|
||||
import mage.MageObject;
|
||||
import mage.abilities.Ability;
|
||||
|
|
@ -65,9 +67,6 @@ import mage.players.Players;
|
|||
import mage.util.MessageToClient;
|
||||
import mage.util.functions.ApplyToPermanent;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.util.*;
|
||||
|
||||
public interface Game extends MageItem, Serializable {
|
||||
|
||||
MatchType getGameType();
|
||||
|
|
@ -393,7 +392,7 @@ public interface Game extends MageItem, Serializable {
|
|||
|
||||
void playPriority(UUID activePlayerId, boolean resuming);
|
||||
|
||||
boolean endTurn();
|
||||
boolean endTurn(Ability source);
|
||||
|
||||
int doAction(MageAction action);
|
||||
|
||||
|
|
|
|||
|
|
@ -27,6 +27,10 @@
|
|||
*/
|
||||
package mage.game;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.Serializable;
|
||||
import java.util.*;
|
||||
import java.util.Map.Entry;
|
||||
import mage.MageException;
|
||||
import mage.MageObject;
|
||||
import mage.abilities.*;
|
||||
|
|
@ -92,11 +96,6 @@ import mage.watchers.Watchers;
|
|||
import mage.watchers.common.*;
|
||||
import org.apache.log4j.Logger;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.Serializable;
|
||||
import java.util.*;
|
||||
import java.util.Map.Entry;
|
||||
|
||||
public abstract class GameImpl implements Game, Serializable {
|
||||
|
||||
private static final int ROLLBACK_TURNS_MAX = 4;
|
||||
|
|
@ -2672,8 +2671,8 @@ public abstract class GameImpl implements Game, Serializable {
|
|||
}
|
||||
|
||||
@Override
|
||||
public boolean endTurn() {
|
||||
getTurn().endTurn(this, getActivePlayerId());
|
||||
public boolean endTurn(Ability source) {
|
||||
getTurn().endTurn(this, getActivePlayerId(), source);
|
||||
return true;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -27,6 +27,10 @@
|
|||
*/
|
||||
package mage.game.stack;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.EnumSet;
|
||||
import java.util.List;
|
||||
import java.util.UUID;
|
||||
import mage.MageInt;
|
||||
import mage.MageObject;
|
||||
import mage.Mana;
|
||||
|
|
@ -58,11 +62,6 @@ import mage.game.permanent.PermanentCard;
|
|||
import mage.players.Player;
|
||||
import mage.util.GameLog;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.EnumSet;
|
||||
import java.util.List;
|
||||
import java.util.UUID;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author BetaSteward_at_googlemail.com
|
||||
|
|
@ -334,8 +333,8 @@ public class Spell extends StackObjImpl implements Card {
|
|||
* determine whether card was kicked or not. E.g. Desolation Angel
|
||||
*/
|
||||
private void updateOptionalCosts(int index) {
|
||||
spellCards.get(index).getAbilities().get(spellAbilities.get(index).getId()).ifPresent(abilityOrig ->
|
||||
{
|
||||
spellCards.get(index).getAbilities().get(spellAbilities.get(index).getId()).ifPresent(abilityOrig
|
||||
-> {
|
||||
for (Object object : spellAbilities.get(index).getOptionalCosts()) {
|
||||
Cost cost = (Cost) object;
|
||||
for (Cost costOrig : abilityOrig.getOptionalCosts()) {
|
||||
|
|
@ -749,24 +748,7 @@ public class Spell extends StackObjImpl implements Card {
|
|||
|
||||
@Override
|
||||
public boolean moveToExile(UUID exileId, String name, UUID sourceId, Game game, ArrayList<UUID> appliedEffects) {
|
||||
ZoneChangeEvent event = new ZoneChangeEvent(this.getId(), sourceId, this.getOwnerId(), Zone.STACK, Zone.EXILED, appliedEffects);
|
||||
if (!game.replaceEvent(event)) {
|
||||
game.getStack().remove(this);
|
||||
game.rememberLKI(this.getId(), event.getFromZone(), this);
|
||||
|
||||
if (!this.isCopiedSpell()) {
|
||||
if (exileId == null) {
|
||||
game.getExile().getPermanentExile().add(this.card);
|
||||
} else {
|
||||
game.getExile().createZone(exileId, name).add(this.card);
|
||||
}
|
||||
|
||||
game.setZone(this.card.getId(), event.getToZone());
|
||||
}
|
||||
game.fireEvent(event);
|
||||
return event.getToZone() == Zone.EXILED;
|
||||
}
|
||||
return false;
|
||||
return this.card.moveToExile(exileId, name, sourceId, game, appliedEffects);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
|||
|
|
@ -32,6 +32,7 @@ import java.util.ArrayList;
|
|||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
import java.util.UUID;
|
||||
import mage.abilities.Ability;
|
||||
import mage.constants.PhaseStep;
|
||||
import mage.constants.TurnPhase;
|
||||
import mage.counters.CounterType;
|
||||
|
|
@ -268,8 +269,9 @@ public class Turn implements Serializable {
|
|||
*
|
||||
* @param game
|
||||
* @param activePlayerId
|
||||
* @param source
|
||||
*/
|
||||
public void endTurn(Game game, UUID activePlayerId) {
|
||||
public void endTurn(Game game, UUID activePlayerId, Ability source) {
|
||||
// Ending the turn this way (Time Stop) means the following things happen in order:
|
||||
|
||||
setEndTurnRequested(true);
|
||||
|
|
@ -277,9 +279,9 @@ public class Turn implements Serializable {
|
|||
// 1) All spells and abilities on the stack are exiled. This includes Time Stop, though it will continue to resolve.
|
||||
// It also includes spells and abilities that can't be countered.
|
||||
while (!game.getStack().isEmpty()) {
|
||||
StackObject stackObject = game.getStack().removeLast();
|
||||
StackObject stackObject = game.getStack().peekFirst();
|
||||
if (stackObject instanceof Spell) {
|
||||
((Spell) stackObject).moveToExile(null, "", null, game);
|
||||
((Spell) stackObject).moveToExile(null, "", source.getSourceId(), game);
|
||||
}
|
||||
}
|
||||
// 2) All attacking and blocking creatures are removed from combat.
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue