Search in sources :

Example 1 with Designation

use of mage.designations.Designation in project mage by magefree.

the class PlayerImpl method restore.

@Override
public void restore(Player player) {
    this.name = player.getName();
    this.human = player.isHuman();
    this.life = player.getLife();
    this.passed = player.isPassed();
    // Don't restore more global states. If restored they are probably cause for unintended draws (https://github.com/magefree/mage/issues/1205).
    // this.wins = player.hasWon();
    // this.loses = player.hasLost();
    // this.left = player.hasLeft();
    // this.quit = player.hasQuit();
    // Makes no sense to restore
    // this.priorityTimeLeft = player.getPriorityTimeLeft();
    // this.idleTimeout = player.hasIdleTimeout();
    // this.timerTimeout = player.hasTimerTimeout();
    // can't change so no need to restore
    // this.isTestMode = player.isTestMode();
    // This is meta data and should'nt be restored by rollback
    // this.userData = player.getUserData();
    this.library = player.getLibrary().copy();
    this.sideboard = player.getSideboard().copy();
    this.hand = player.getHand().copy();
    this.graveyard = player.getGraveyard().copy();
    // noinspection deprecation - it's ok to use it in inner methods
    this.commandersIds = new HashSet<>(player.getCommandersIds());
    this.abilities = player.getAbilities().copy();
    this.counters = player.getCounters().copy();
    this.landsPlayed = player.getLandsPlayed();
    this.landsPerTurn = player.getLandsPerTurn();
    this.loyaltyUsePerTurn = player.getLoyaltyUsePerTurn();
    this.maxHandSize = player.getMaxHandSize();
    this.maxAttackedBy = player.getMaxAttackedBy();
    this.manaPool = player.getManaPool().copy();
    // Restore user specific settings in case changed since state save
    this.manaPool.setAutoPayment(this.getUserData().isManaPoolAutomatic());
    this.manaPool.setAutoPaymentRestricted(this.getUserData().isManaPoolAutomaticRestricted());
    this.turns = player.getTurns();
    this.range = player.getRange();
    this.canGainLife = player.isCanGainLife();
    this.canLoseLife = player.isCanLoseLife();
    this.attachments.clear();
    this.attachments.addAll(player.getAttachments());
    this.inRange.clear();
    this.inRange.addAll(player.getInRange());
    this.canPayLifeCost = player.getCanPayLifeCost();
    this.sacrificeCostFilter = player.getSacrificeCostFilter() != null ? player.getSacrificeCostFilter().copy() : null;
    this.loseByZeroOrLessLife = player.canLoseByZeroOrLessLife();
    this.canPlayCardsFromGraveyard = player.canPlayCardsFromGraveyard();
    this.drawsOnOpponentsTurn = player.isDrawsOnOpponentsTurn();
    this.alternativeSourceCosts.clear();
    this.alternativeSourceCosts.addAll(player.getAlternativeSourceCosts());
    this.topCardRevealed = player.isTopCardRevealed();
    this.playersUnderYourControl.clear();
    this.playersUnderYourControl.addAll(player.getPlayersUnderYourControl());
    this.isGameUnderControl = player.isGameUnderControl();
    this.turnController = player.getTurnControlledBy();
    this.turnControllers.clear();
    this.turnControllers.addAll(player.getTurnControllers());
    this.reachedNextTurnAfterLeaving = player.hasReachedNextTurnAfterLeaving();
    this.clearCastSourceIdManaCosts();
    this.castSourceIdWithAlternateMana.clear();
    this.castSourceIdWithAlternateMana.addAll(player.getCastSourceIdWithAlternateMana());
    for (Entry<UUID, ManaCosts<ManaCost>> entry : player.getCastSourceIdManaCosts().entrySet()) {
        this.castSourceIdManaCosts.put(entry.getKey(), (entry.getValue() == null ? null : entry.getValue().copy()));
    }
    for (Entry<UUID, Costs<Cost>> entry : player.getCastSourceIdCosts().entrySet()) {
        this.castSourceIdCosts.put(entry.getKey(), (entry.getValue() == null ? null : entry.getValue().copy()));
    }
    this.phyrexianColors = player.getPhyrexianColors() != null ? player.getPhyrexianColors().copy() : null;
    this.designations.clear();
    for (Designation object : player.getDesignations()) {
        this.designations.add(object.copy());
    }
// Don't restore!
// this.storedBookmark
// this.usersAllowedToSeeHandCards
}
Also used : ManaCosts(mage.abilities.costs.mana.ManaCosts) Designation(mage.designations.Designation) ManaCosts(mage.abilities.costs.mana.ManaCosts)

Example 2 with Designation

use of mage.designations.Designation in project mage by magefree.

the class GameImpl method getObject.

@Override
public MageObject getObject(UUID objectId) {
    if (objectId == null) {
        return null;
    }
    MageObject object;
    if (state.getBattlefield().containsPermanent(objectId)) {
        object = state.getBattlefield().getPermanent(objectId);
        return object;
    }
    if (getPermanentsEntering().containsKey(objectId)) {
        return getPermanentEntering(objectId);
    }
    for (StackObject item : state.getStack()) {
        if (item.getId().equals(objectId)) {
            return item;
        }
        if (item instanceof Spell && item.getSourceId().equals(objectId)) {
            return item;
        }
    }
    for (CommandObject commandObject : state.getCommand()) {
        if (commandObject.getId().equals(objectId)) {
            return commandObject;
        }
    }
    object = getCard(objectId);
    if (object == null) {
        for (Designation designation : state.getDesignations()) {
            if (designation.getId().equals(objectId)) {
                return designation;
            }
        }
        // can be an ability of a sacrificed Token trying to get it's source object
        object = getLastKnownInformation(objectId, Zone.BATTLEFIELD);
    }
    return object;
}
Also used : Designation(mage.designations.Designation) MageObject(mage.MageObject) StackObject(mage.game.stack.StackObject) Spell(mage.game.stack.Spell)

Aggregations

Designation (mage.designations.Designation)2 MageObject (mage.MageObject)1 ManaCosts (mage.abilities.costs.mana.ManaCosts)1 Spell (mage.game.stack.Spell)1 StackObject (mage.game.stack.StackObject)1