fix conflicts

This commit is contained in:
Ingmar Goudt 2019-12-29 19:28:20 +01:00
commit ce23f6900d
2451 changed files with 84128 additions and 14873 deletions

View file

@ -1,5 +1,9 @@
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.*;
@ -29,7 +33,7 @@ import mage.filter.Filter;
import mage.filter.FilterCard;
import mage.filter.FilterPermanent;
import mage.filter.StaticFilters;
import mage.filter.common.FilterControlledCreaturePermanent;
import mage.filter.common.FilterControlledPermanent;
import mage.filter.predicate.mageobject.NamePredicate;
import mage.filter.predicate.mageobject.SupertypePredicate;
import mage.filter.predicate.permanent.ControllerIdPredicate;
@ -65,11 +69,6 @@ import mage.util.functions.ApplyToPermanent;
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;
@ -77,7 +76,9 @@ public abstract class GameImpl implements Game, Serializable {
private static final Logger logger = Logger.getLogger(GameImpl.class);
private transient Object customData;
protected boolean simulation = false;
protected boolean checkPlayableState = false;
protected final UUID id;
@ -163,6 +164,7 @@ public abstract class GameImpl implements Game, Serializable {
this.state = game.state.copy();
this.gameCards = game.gameCards;
this.simulation = game.simulation;
this.checkPlayableState = game.checkPlayableState;
this.gameOptions = game.gameOptions;
this.lki.putAll(game.lki);
this.lkiExtended.putAll(game.lkiExtended);
@ -188,6 +190,16 @@ public abstract class GameImpl implements Game, Serializable {
this.simulation = simulation;
}
@Override
public void setCheckPlayableState(boolean checkPlayableState) {
this.checkPlayableState = checkPlayableState;
}
@Override
public boolean inCheckPlayableState() {
return checkPlayableState;
}
@Override
public UUID getId() {
return id;
@ -230,6 +242,12 @@ public abstract class GameImpl implements Game, Serializable {
gameCards.put(rightCard.getId(), rightCard);
state.addCard(rightCard);
}
if (card instanceof AdventureCard) {
Card spellCard = ((AdventureCard) card).getSpellCard();
spellCard.setOwnerId(ownerId);
gameCards.put(spellCard.getId(), spellCard);
state.addCard(spellCard);
}
}
}
@ -445,7 +463,17 @@ public abstract class GameImpl implements Game, Serializable {
public Spell getSpellOrLKIStack(UUID spellId) {
Spell spell = state.getStack().getSpell(spellId);
if (spell == null) {
spell = (Spell) this.getLastKnownInformation(spellId, Zone.STACK);
MageObject obj = this.getLastKnownInformation(spellId, Zone.STACK);
if (obj instanceof Spell) {
spell = (Spell) obj;
} else {
if (obj != null) {
// copied activated abilities is StackAbility (not spell) and must be ignored here
// if not then java.lang.ClassCastException: mage.game.stack.StackAbility cannot be cast to mage.game.stack.Spell
// see SyrCarahTheBoldTest as example
// logger.error("getSpellOrLKIStack got non spell id - " + obj.getClass().getName() + " - " + obj.getName(), new Throwable());
}
}
}
return spell;
}
@ -738,7 +766,7 @@ public abstract class GameImpl implements Game, Serializable {
state.getTurn().resumePlay(this, wasPaused);
if (!isPaused() && !checkIfGameIsOver()) {
endOfTurn();
player = playerList.getNext(this);
player = playerList.getNext(this, true);
state.setTurnNum(state.getTurnNum() + 1);
}
}
@ -763,7 +791,7 @@ public abstract class GameImpl implements Game, Serializable {
if (!playExtraTurns()) {
break;
}
playerByOrder = playerList.getNext(this);
playerByOrder = playerList.getNext(this, true);
state.setPlayerByOrderId(playerByOrder.getId());
}
}
@ -1011,7 +1039,6 @@ public abstract class GameImpl implements Game, Serializable {
}
}
public void initGameDefaultWatchers() {
getState().addWatcher(new MorbidWatcher());
getState().addWatcher(new CastSpellLastTurnWatcher());
@ -1041,11 +1068,11 @@ public abstract class GameImpl implements Game, Serializable {
message.append(choosingPlayer.getLogName()).append(" chooses that ");
}
if (choosingPlayer != null && choosingPlayer.getId().equals(startingPlayer.getId())) {
message.append("he or she");
message.append("they");
} else {
message.append(startingPlayer.getLogName());
}
message.append(" takes the first turn");
message.append(" take the first turn");
this.informPlayers(message.toString());
}
@ -1059,7 +1086,7 @@ public abstract class GameImpl implements Game, Serializable {
break;
}
if (!player.hasLost() && !player.hasLeft()) {
logger.debug(player.getName() + " has not lost so he won gameId: " + this.getId());
logger.debug(player.getName() + " has not lost so they won gameId: " + this.getId());
player.won(this);
winnerIdFound = player.getId();
break;
@ -1303,6 +1330,8 @@ public abstract class GameImpl implements Game, Serializable {
} else {
throw new MageException("Error in testclass");
}
} finally {
setCheckPlayableState(false);
}
state.getPlayerList().getNext();
}
@ -1314,6 +1343,7 @@ public abstract class GameImpl implements Game, Serializable {
} finally {
resetLKI();
clearAllBookmarks();
setCheckPlayableState(false);
}
}
@ -1471,7 +1501,7 @@ public abstract class GameImpl implements Game, Serializable {
/**
* @param emblem
* @param sourceObject
* @param toPlayerId controller and owner of the emblem
* @param toPlayerId controller and owner of the emblem
*/
@Override
public void addEmblem(Emblem emblem, MageObject sourceObject, UUID toPlayerId) {
@ -1489,8 +1519,8 @@ public abstract class GameImpl implements Game, Serializable {
/**
* @param plane
* @param sourceObject
* @param toPlayerId controller and owner of the plane (may only be one per
* game..)
* @param toPlayerId controller and owner of the plane (may only be one per
* game..)
* @return boolean - whether the plane was added successfully or not
*/
@Override
@ -1569,7 +1599,7 @@ public abstract class GameImpl implements Game, Serializable {
}
newBluePrint.assignNewId();
if (copyFromPermanent.isTransformed()) {
TransformAbility.transform(newBluePrint, copyFromPermanent.getSecondCardFace(), this);
TransformAbility.transform(newBluePrint, newBluePrint.getSecondCardFace(), this);
}
}
if (applier != null) {
@ -1585,7 +1615,7 @@ public abstract class GameImpl implements Game, Serializable {
Ability newAbility = source.copy();
newEffect.init(newAbility, this);
// If there are already copy effects with dration = Custom to the same object, remove the existing effects because they no longer have any effect
// If there are already copy effects with duration = Custom to the same object, remove the existing effects because they no longer have any effect
if (duration == Duration.Custom) {
for (Effect effect : getState().getContinuousEffects().getLayeredEffects(this)) {
if (effect instanceof CopyEffect) {
@ -1719,7 +1749,7 @@ public abstract class GameImpl implements Game, Serializable {
break;
}
// triggered abilities that don't use the stack have to be executed first (e.g. Banisher Priest Return exiled creature
for (Iterator<TriggeredAbility> it = abilities.iterator(); it.hasNext(); ) {
for (Iterator<TriggeredAbility> it = abilities.iterator(); it.hasNext();) {
TriggeredAbility triggeredAbility = it.next();
if (!triggeredAbility.isUsesStack()) {
state.removeTriggeredAbility(triggeredAbility);
@ -1774,7 +1804,7 @@ public abstract class GameImpl implements Game, Serializable {
Iterator<Card> copiedCards = this.getState().getCopiedCards().iterator();
while (copiedCards.hasNext()) {
Card card = copiedCards.next();
if (card instanceof SplitCardHalf) {
if (card instanceof SplitCardHalf || card instanceof AdventureCardSpell) {
continue; // only the main card is moves, not the halves
}
Zone zone = state.getZone(card.getId());
@ -1930,8 +1960,8 @@ public abstract class GameImpl implements Game, Serializable {
}
} else {
Filter auraFilter = spellAbility.getTargets().get(0).getFilter();
if (auraFilter instanceof FilterControlledCreaturePermanent) {
if (!((FilterControlledCreaturePermanent) auraFilter).match(attachedTo, perm.getId(), perm.getControllerId(), this)
if (auraFilter instanceof FilterControlledPermanent) {
if (!((FilterControlledPermanent) auraFilter).match(attachedTo, perm.getId(), perm.getControllerId(), this)
|| attachedTo.cantBeAttachedBy(perm, this)) {
if (movePermanentToGraveyardWithInfo(perm)) {
somethingHappened = true;
@ -2435,8 +2465,8 @@ public abstract class GameImpl implements Game, Serializable {
* exist. Then, if there are any objects still controlled by that player,
* those objects are exiled. This is not a state-based action. It happens as
* soon as the player leaves the game. If the player who left the game had
* priority at the time he or she left, priority passes to the next player
* in turn order who's still in the game. #
* priority at the time they left, priority passes to the next player in
* turn order who's still in the game. #
*
* @param playerId
*/
@ -2454,7 +2484,7 @@ public abstract class GameImpl implements Game, Serializable {
}
//20100423 - 800.4a
Set<Card> toOutside = new HashSet<>();
for (Iterator<Permanent> it = getBattlefield().getAllPermanents().iterator(); it.hasNext(); ) {
for (Iterator<Permanent> it = getBattlefield().getAllPermanents().iterator(); it.hasNext();) {
Permanent perm = it.next();
if (perm.isOwnedBy(playerId)) {
if (perm.getAttachedTo() != null) {
@ -2473,7 +2503,6 @@ public abstract class GameImpl implements Game, Serializable {
perm.removeFromCombat(this, true);
}
toOutside.add(perm);
// it.remove();
} else if (perm.isControlledBy(player.getId())) {
// and any effects which give that player control of any objects or players end
Effects:
@ -2497,7 +2526,7 @@ public abstract class GameImpl implements Game, Serializable {
player.moveCards(toOutside, Zone.OUTSIDE, null, this);
// triggered abilities that don't use the stack have to be executed
List<TriggeredAbility> abilities = state.getTriggered(player.getId());
for (Iterator<TriggeredAbility> it = abilities.iterator(); it.hasNext(); ) {
for (Iterator<TriggeredAbility> it = abilities.iterator(); it.hasNext();) {
TriggeredAbility triggeredAbility = it.next();
if (!triggeredAbility.isUsesStack()) {
state.removeTriggeredAbility(triggeredAbility);
@ -2517,7 +2546,7 @@ public abstract class GameImpl implements Game, Serializable {
// Remove cards from the player in all exile zones
for (ExileZone exile : this.getExile().getExileZones()) {
for (Iterator<UUID> it = exile.iterator(); it.hasNext(); ) {
for (Iterator<UUID> it = exile.iterator(); it.hasNext();) {
Card card = this.getCard(it.next());
if (card != null && card.isOwnedBy(playerId)) {
it.remove();
@ -2527,7 +2556,7 @@ public abstract class GameImpl implements Game, Serializable {
//Remove all commander/emblems/plane the player controls
boolean addPlaneAgain = false;
for (Iterator<CommandObject> it = this.getState().getCommand().iterator(); it.hasNext(); ) {
for (Iterator<CommandObject> it = this.getState().getCommand().iterator(); it.hasNext();) {
CommandObject obj = it.next();
if (obj.isControlledBy(playerId)) {
if (obj instanceof Emblem) {
@ -2570,7 +2599,7 @@ public abstract class GameImpl implements Game, Serializable {
if (!isActivePlayer(playerId)) {
setMonarchId(null, getActivePlayerId());
} else {
Player nextPlayer = getPlayerList().getNext(this);
Player nextPlayer = getPlayerList().getNext(this, true);
if (nextPlayer != null) {
setMonarchId(null, nextPlayer.getId());
}
@ -2629,7 +2658,7 @@ public abstract class GameImpl implements Game, Serializable {
return result;
}
DamageEvent damageEvent = (DamageEvent) event;
GameEvent preventEvent = new GameEvent(GameEvent.EventType.PREVENT_DAMAGE, damageEvent.getTargetId(), damageEvent.getSourceId(), source.getControllerId(), damageEvent.getAmount(), false);
GameEvent preventEvent = new PreventDamageEvent(damageEvent.getTargetId(), damageEvent.getSourceId(), source.getControllerId(), damageEvent.getAmount(), damageEvent.isCombatDamage());
if (game.replaceEvent(preventEvent)) {
result.setReplaced(true);
return result;
@ -2877,7 +2906,7 @@ public abstract class GameImpl implements Game, Serializable {
// as commander (only commander games, look at init code in GameCommanderImpl)
if (this instanceof GameCommanderImpl) {
for (Card card : command) {
player.addCommanderId(card.getId());
((GameCommanderImpl) this).addCommander(card, player);
// no needs in initCommander call -- it's uses on game startup (init)
}
} else if (!command.isEmpty()) {
@ -3199,4 +3228,9 @@ public abstract class GameImpl implements Game, Serializable {
return mulligan;
}
@Override
public Set<UUID> getCommandersIds(Player player, CommanderCardType commanderCardType) {
return player.getCommandersIds();
}
}