mirror of
https://github.com/correl/mage.git
synced 2025-01-12 19:25:44 +00:00
Fixed PlayerImpl by adding some missing attributes to copy and restore method (fixes an undo bug). Added new PutTopCardOfTargetPlayerLibraryIntoGraveEffect.
This commit is contained in:
parent
38ea2d91d6
commit
97505873aa
2 changed files with 157 additions and 32 deletions
|
@ -0,0 +1,92 @@
|
|||
/*
|
||||
* 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 mage.abilities.effects.common;
|
||||
|
||||
import mage.Constants;
|
||||
import mage.Constants.Outcome;
|
||||
import mage.abilities.Ability;
|
||||
import mage.abilities.effects.OneShotEffect;
|
||||
import mage.cards.Card;
|
||||
import mage.game.Game;
|
||||
import mage.players.Player;
|
||||
import mage.util.CardUtil;
|
||||
|
||||
|
||||
/**
|
||||
* @author LevelX2
|
||||
*/
|
||||
|
||||
public class PutTopCardOfTargetPlayerLibraryIntoGraveEffect extends OneShotEffect<PutTopCardOfTargetPlayerLibraryIntoGraveEffect> {
|
||||
|
||||
private int numberCards;
|
||||
|
||||
public PutTopCardOfTargetPlayerLibraryIntoGraveEffect(int numberCards) {
|
||||
super(Outcome.Discard);
|
||||
this.numberCards = numberCards;
|
||||
this.staticText = setText();
|
||||
}
|
||||
|
||||
public PutTopCardOfTargetPlayerLibraryIntoGraveEffect(final PutTopCardOfTargetPlayerLibraryIntoGraveEffect effect) {
|
||||
super(effect);
|
||||
this.numberCards = effect.numberCards;
|
||||
}
|
||||
|
||||
@Override
|
||||
public PutTopCardOfTargetPlayerLibraryIntoGraveEffect copy() {
|
||||
return new PutTopCardOfTargetPlayerLibraryIntoGraveEffect(this);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean apply(Game game, Ability source) {
|
||||
Player player = game.getPlayer(targetPointer.getFirst(game, source));
|
||||
if (player != null) {
|
||||
int cardsCount = Math.min(numberCards, player.getLibrary().size());
|
||||
for (int i = 0; i < cardsCount; i++) {
|
||||
Card card = player.getLibrary().removeFromTop(game);
|
||||
if (card != null) {
|
||||
card.moveToZone(Constants.Zone.GRAVEYARD, source.getId(), game, true);
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
private String setText() {
|
||||
StringBuilder sb = new StringBuilder("Target player puts the top ");
|
||||
if (numberCards == 1) {
|
||||
sb.append(" card");
|
||||
} else {
|
||||
sb.append(CardUtil.numberToText(numberCards));
|
||||
sb.append(" cards");
|
||||
}
|
||||
sb.append(" of his or her library into his or her graveyard");
|
||||
return sb.toString();
|
||||
}
|
||||
}
|
|
@ -148,35 +148,97 @@ public abstract class PlayerImpl<T extends PlayerImpl<T>> implements Player, Ser
|
|||
public PlayerImpl(final PlayerImpl<T> player) {
|
||||
this.abort = player.abort;
|
||||
this.playerId = player.playerId;
|
||||
|
||||
this.name = player.name;
|
||||
this.human = player.human;
|
||||
this.life = player.life;
|
||||
this.wins = player.wins;
|
||||
this.loses = player.loses;
|
||||
|
||||
this.library = player.library.copy();
|
||||
this.sideboard = player.sideboard.copy();
|
||||
this.hand = player.hand.copy();
|
||||
this.graveyard = player.graveyard.copy();
|
||||
this.abilities = player.abilities.copy();
|
||||
this.counters = player.counters.copy();
|
||||
|
||||
this.landsPlayed = player.landsPlayed;
|
||||
this.landsPerTurn = player.landsPerTurn;
|
||||
this.maxHandSize = player.maxHandSize;
|
||||
this.manaPool = player.manaPool.copy();
|
||||
this.passed = player.passed;
|
||||
this.passedTurn = player.passedTurn;
|
||||
this.passedAllTurns = player.passedAllTurns;
|
||||
this.turns = player.turns;
|
||||
|
||||
this.left = player.left;
|
||||
this.range = player.range;
|
||||
this.canGainLife = player.canGainLife;
|
||||
this.canLoseLife = player.canLoseLife;
|
||||
this.attachments.addAll(player.attachments);
|
||||
|
||||
this.inRange.addAll(player.inRange);
|
||||
this.userData = player.userData;
|
||||
this.canPayLifeCost = player.canPayLifeCost;
|
||||
this.canPaySacrificeCost = player.canPaySacrificeCost;
|
||||
this.storedBookmark = player.storedBookmark;
|
||||
|
||||
this.topCardRevealed = player.topCardRevealed;
|
||||
this.playersUnderYourControl.clear();
|
||||
this.playersUnderYourControl.addAll(player.playersUnderYourControl);
|
||||
this.isTestMode = player.isTestMode;
|
||||
this.isGameUnderControl = player.isGameUnderControl;
|
||||
|
||||
this.turnController = player.turnController;
|
||||
this.passed = player.passed;
|
||||
|
||||
this.passedTurn = player.passedTurn;
|
||||
this.passedAllTurns = player.passedAllTurns;
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void restore(Player player) {
|
||||
this.name = player.getName();
|
||||
this.human = player.isHuman();
|
||||
this.life = player.getLife();
|
||||
this.wins = player.hasWon();
|
||||
this.loses = player.hasLost();
|
||||
|
||||
this.library = player.getLibrary().copy();
|
||||
this.sideboard = player.getSideboard().copy();
|
||||
this.hand = player.getHand().copy();
|
||||
this.graveyard = player.getGraveyard().copy();
|
||||
this.abilities = player.getAbilities().copy();
|
||||
this.counters = player.getCounters().copy();
|
||||
|
||||
this.landsPlayed = player.getLandsPlayed();
|
||||
this.landsPerTurn = player.getLandsPerTurn();
|
||||
this.maxHandSize = player.getMaxHandSize();
|
||||
this.manaPool = player.getManaPool().copy();
|
||||
this.turns = player.getTurns();
|
||||
|
||||
|
||||
this.left = player.hasLeft();
|
||||
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.userData = player.getUserData();
|
||||
this.canPayLifeCost = player.canPayLifeCost();
|
||||
this.canPaySacrificeCost = player.canPaySacrificeCost();
|
||||
this.storedBookmark = player.getStoredBookmark();
|
||||
|
||||
this.topCardRevealed = player.isTopCardRevealed();
|
||||
this.playersUnderYourControl.clear();
|
||||
this.playersUnderYourControl.addAll(player.getPlayersUnderYourControl());
|
||||
this.isTestMode = player.isTestMode();
|
||||
this.isGameUnderControl = player.isGameUnderControl();
|
||||
|
||||
this.turnController = player.getTurnControlledBy();
|
||||
this.passed = player.isPassed();
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -1038,35 +1100,6 @@ public abstract class PlayerImpl<T extends PlayerImpl<T>> implements Player, Ser
|
|||
@Override
|
||||
public void setResponseInteger(Integer responseInteger) {}
|
||||
|
||||
@Override
|
||||
public void restore(Player player) {
|
||||
this.library = player.getLibrary().copy();
|
||||
this.sideboard = player.getSideboard().copy();
|
||||
this.hand = player.getHand().copy();
|
||||
this.graveyard = player.getGraveyard().copy();
|
||||
this.abilities = player.getAbilities().copy();
|
||||
this.manaPool = player.getManaPool().copy();
|
||||
this.life = player.getLife();
|
||||
this.counters = player.getCounters().copy();
|
||||
this.inRange.clear();
|
||||
this.inRange.addAll(player.getInRange());
|
||||
this.landsPlayed = player.getLandsPlayed();
|
||||
this.name = player.getName();
|
||||
this.range = player.getRange();
|
||||
this.passed = player.isPassed();
|
||||
this.human = player.isHuman();
|
||||
this.wins = player.hasWon();
|
||||
this.loses = player.hasLost();
|
||||
this.landsPerTurn = player.getLandsPerTurn();
|
||||
this.maxHandSize = player.getMaxHandSize();
|
||||
this.left = player.hasLeft();
|
||||
this.canGainLife = player.isCanGainLife();
|
||||
this.canLoseLife = player.isCanLoseLife();
|
||||
this.attachments.clear();
|
||||
this.attachments.addAll(player.getAttachments());
|
||||
this.userData = player.getUserData();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isPassed() {
|
||||
return passed;
|
||||
|
|
Loading…
Reference in a new issue