From 620a3b9a528c031cb28bd52747d97f04011418ae Mon Sep 17 00:00:00 2001 From: betasteward Date: Tue, 24 Feb 2015 15:37:33 -0500 Subject: [PATCH] Moved some setters from Card to Permanent --- .../mage/sets/newphyrexia/PraetorsGrasp.java | 1 - Mage/src/mage/cards/Card.java | 7 -- Mage/src/mage/cards/CardImpl.java | 38 -------- Mage/src/mage/cards/SplitCard.java | 19 ++-- Mage/src/mage/game/GameImpl.java | 1 - Mage/src/mage/game/permanent/Permanent.java | 9 ++ .../mage/game/permanent/PermanentImpl.java | 38 ++++++++ Mage/src/mage/game/stack/Spell.java | 27 ------ Mage/src/mage/util/CardUtil.java | 11 --- .../src/mage/util/functions/CopyFunction.java | 97 ------------------- 10 files changed, 58 insertions(+), 190 deletions(-) delete mode 100644 Mage/src/mage/util/functions/CopyFunction.java diff --git a/Mage.Sets/src/mage/sets/newphyrexia/PraetorsGrasp.java b/Mage.Sets/src/mage/sets/newphyrexia/PraetorsGrasp.java index 91571058e5a..8742b4155d0 100644 --- a/Mage.Sets/src/mage/sets/newphyrexia/PraetorsGrasp.java +++ b/Mage.Sets/src/mage/sets/newphyrexia/PraetorsGrasp.java @@ -99,7 +99,6 @@ class PraetorsGraspEffect extends OneShotEffect { Card card = opponent.getLibrary().remove(targetId, game); if (card != null) { card.setFaceDown(true); - card.setControllerId(player.getId()); card.moveToExile(getId(), sourcePermanent.getName(), source.getSourceId(), game); game.addEffect(new PraetorsGraspPlayEffect(card.getId()), source); game.addEffect(new PraetorsGraspRevealEffect(card.getId()), source); diff --git a/Mage/src/mage/cards/Card.java b/Mage/src/mage/cards/Card.java index d08f7796e04..25f7edc7018 100644 --- a/Mage/src/mage/cards/Card.java +++ b/Mage/src/mage/cards/Card.java @@ -46,10 +46,7 @@ public interface Card extends MageObject { UUID getOwnerId(); int getCardNumber(); - void setCardNumber(int cid); Rarity getRarity(); - void setRarity(Rarity rarity); - void setControllerId(UUID controllerId); void setOwnerId(UUID ownerId); void addAbility(Ability ability); void addWatcher(Watcher watcher); @@ -59,20 +56,16 @@ public interface Card extends MageObject { List getWatchers(); String getExpansionSetCode(); String getTokenSetCode(); - void setExpansionSetCode(String expansionSetCode); void setFaceDown(boolean value); boolean isFaceDown(); boolean turnFaceUp(Game game, UUID playerId); boolean turnFaceDown(Game game, UUID playerId); boolean isFlipCard(); String getFlipCardName(); - void setFlipCard(boolean flipCard); - void setFlipCardName(String flipCardName); boolean isSplitCard(); boolean canTransform(); Card getSecondCardFace(); - void setSecondCardFace(Card card); boolean isNightCard(); void assignNewId(); diff --git a/Mage/src/mage/cards/CardImpl.java b/Mage/src/mage/cards/CardImpl.java index 77d50a35007..6774095dc5e 100644 --- a/Mage/src/mage/cards/CardImpl.java +++ b/Mage/src/mage/cards/CardImpl.java @@ -63,7 +63,6 @@ import mage.game.Game; import mage.game.command.Commander; import mage.game.events.GameEvent; import mage.game.events.ZoneChangeEvent; -import mage.game.permanent.Permanent; import mage.game.permanent.PermanentCard; import mage.game.stack.Spell; import mage.game.stack.StackObject; @@ -218,11 +217,6 @@ public abstract class CardImpl extends MageObjectImpl implements Card { return rarity; } - @Override - public void setRarity(Rarity rarity) { - this.rarity = rarity; - } - @Override public List getRules() { try { @@ -268,11 +262,6 @@ public abstract class CardImpl extends MageObjectImpl implements Card { return spellAbility; } - @Override - public void setControllerId(UUID controllerId) { - abilities.setControllerId(controllerId); - } - @Override public void setOwnerId(UUID ownerId) { this.ownerId = ownerId; @@ -294,11 +283,6 @@ public abstract class CardImpl extends MageObjectImpl implements Card { return tokenSetCode; } - @Override - public void setExpansionSetCode(String expansionSetCode) { - this.expansionSetCode = expansionSetCode; - } - @Override public List getMana() { List mana = new ArrayList<>(); @@ -411,7 +395,6 @@ public abstract class CardImpl extends MageObjectImpl implements Card { .append("] source [").append(sourceCard != null ? sourceCard.getName():"null").append("]").toString()); return false; } - setControllerId(event.getPlayerId()); game.setZone(objectId, event.getToZone()); game.addSimultaneousEvent(event); return game.getState().getZone(objectId) == toZone; @@ -572,11 +555,6 @@ public abstract class CardImpl extends MageObjectImpl implements Card { return false; } - @Override - public void setCardNumber(int cid) { - this.cardNumber = cid; - } - @Override public void setFaceDown(boolean value) { faceDown = value; @@ -626,11 +604,6 @@ public abstract class CardImpl extends MageObjectImpl implements Card { return this.secondSideCard; } - @Override - public void setSecondCardFace(Card card) { - this.secondSideCard = card; - } - @Override public boolean isNightCard() { return this.nightCard; @@ -646,17 +619,6 @@ public abstract class CardImpl extends MageObjectImpl implements Card { return flipCardName; } - @Override - public void setFlipCard(boolean flipCard) { - this.flipCard = flipCard; - } - - @Override - public void setFlipCardName(String flipCardName) { - this.flipCardName = flipCardName; - } - - @Override public boolean isSplitCard() { return splitCard; diff --git a/Mage/src/mage/cards/SplitCard.java b/Mage/src/mage/cards/SplitCard.java index cce2b36ac07..204812c3fec 100644 --- a/Mage/src/mage/cards/SplitCard.java +++ b/Mage/src/mage/cards/SplitCard.java @@ -155,16 +155,9 @@ public abstract class SplitCard extends CardImpl { return rules; } - @Override - public void setControllerId(UUID controllerId) { - abilities.setControllerId(controllerId); - leftHalfCard.getAbilities().setControllerId(controllerId); - rightHalfCard.getAbilities().setControllerId(controllerId); - } - @Override public void setOwnerId(UUID ownerId) { - this.ownerId = ownerId; + super.setOwnerId(ownerId); abilities.setControllerId(ownerId); leftHalfCard.getAbilities().setControllerId(ownerId); leftHalfCard.setOwnerId(ownerId); @@ -205,6 +198,11 @@ class LeftHalfCard extends CardImpl { return new LeftHalfCard(this); } + @Override + public UUID getOwnerId() { + return splitCardParent.getOwnerId(); + } + @Override public String getImageName() { return splitCardParent.getImageName(); @@ -267,6 +265,11 @@ class RightHalfCard extends CardImpl { return new RightHalfCard(this); } + @Override + public UUID getOwnerId() { + return splitCardParent.getOwnerId(); + } + @Override public String getImageName() { return splitCardParent.getImageName(); diff --git a/Mage/src/mage/game/GameImpl.java b/Mage/src/mage/game/GameImpl.java index 99b8de1db20..a3584a11919 100644 --- a/Mage/src/mage/game/GameImpl.java +++ b/Mage/src/mage/game/GameImpl.java @@ -1325,7 +1325,6 @@ public abstract class GameImpl implements Game, Serializable { public Card copyCard(Card cardToCopy, Ability source, UUID newController) { Card copiedCard = cardToCopy.copy(); copiedCard.assignNewId(); - copiedCard.setControllerId(newController); copiedCard.setCopy(true); Set cards = new HashSet<>(); cards.add(copiedCard); diff --git a/Mage/src/mage/game/permanent/Permanent.java b/Mage/src/mage/game/permanent/Permanent.java index 6a081d9f090..fe471e7d5cd 100644 --- a/Mage/src/mage/game/permanent/Permanent.java +++ b/Mage/src/mage/game/permanent/Permanent.java @@ -34,12 +34,14 @@ import java.util.UUID; import mage.MageObject; import mage.abilities.Ability; import mage.cards.Card; +import mage.constants.Rarity; import mage.constants.Zone; import mage.game.Controllable; import mage.game.Game; public interface Permanent extends Card, Controllable { + void setControllerId(UUID controllerId); boolean isTapped(); boolean untap(Game game); boolean tap(Game game); @@ -70,6 +72,13 @@ public interface Permanent extends Card, Controllable { boolean isMonstrous(); void setMonstrous(boolean value); + void setCardNumber(int cid); + void setExpansionSetCode(String expansionSetCode); + void setRarity(Rarity rarity); + void setFlipCard(boolean flipCard); + void setFlipCardName(String flipCardName); + void setSecondCardFace(Card card); + List getAttachments(); UUID getAttachedTo(); void attachTo(UUID permanentId, Game game); diff --git a/Mage/src/mage/game/permanent/PermanentImpl.java b/Mage/src/mage/game/permanent/PermanentImpl.java index 498f207af1e..faa2d2a1437 100644 --- a/Mage/src/mage/game/permanent/PermanentImpl.java +++ b/Mage/src/mage/game/permanent/PermanentImpl.java @@ -57,6 +57,7 @@ import mage.cards.CardImpl; import mage.constants.AsThoughEffectType; import mage.constants.CardType; import mage.constants.EffectType; +import mage.constants.Rarity; import mage.constants.Zone; import mage.counters.Counter; import mage.counters.CounterType; @@ -169,6 +170,12 @@ public abstract class PermanentImpl extends CardImpl implements Permanent { return sb.toString(); } + @Override + public void setControllerId(UUID controllerId) { + this.controllerId = controllerId; + abilities.setControllerId(controllerId); + } + /** * Called before each applyEffects or if after a permanent was copied for the copied object * @@ -1180,4 +1187,35 @@ public abstract class PermanentImpl extends CardImpl implements Permanent { morphed = value; } + @Override + public void setCardNumber(int cid) { + this.cardNumber = cid; + } + + @Override + public void setExpansionSetCode(String expansionSetCode) { + this.expansionSetCode = expansionSetCode; + } + + @Override + public void setRarity(Rarity rarity) { + this.rarity = rarity; + } + + @Override + public void setFlipCard(boolean flipCard) { + this.flipCard = flipCard; + } + + @Override + public void setFlipCardName(String flipCardName) { + this.flipCardName = flipCardName; + } + + @Override + public void setSecondCardFace(Card card) { + this.secondSideCard = card; + } + + } diff --git a/Mage/src/mage/game/stack/Spell.java b/Mage/src/mage/game/stack/Spell.java index 1a2ac5e69df..2ea2c858ebd 100644 --- a/Mage/src/mage/game/stack/Spell.java +++ b/Mage/src/mage/game/stack/Spell.java @@ -548,9 +548,6 @@ public class Spell implements StackObject, Card { return card.getRarity(); } - @Override - public void setRarity(Rarity rarity) {} - @Override public List getCardType() { if (this.getSpellAbility() instanceof BestowAbility) { @@ -678,7 +675,6 @@ public class Spell implements StackObject, Card { return ability; } - @Override public void setControllerId(UUID controllerId) { this.ability.setControllerId(controllerId); for (SpellAbility spellAbility: spellAbilities) { @@ -710,9 +706,6 @@ public class Spell implements StackObject, Card { return card.getTokenSetCode(); } - @Override - public void setExpansionSetCode(String expansionSetCode) {} - @Override public void setFaceDown(boolean value) { faceDown = value; @@ -760,26 +753,11 @@ public class Spell implements StackObject, Card { return null; } - @Override - public void setSecondCardFace(Card card) { - } - @Override public boolean isNightCard() { return false; } - @Override - public void setFlipCard(boolean flipCard) { - throw new UnsupportedOperationException("Not supported."); //To change body of generated methods, choose Tools | Templates. - } - - @Override - public void setFlipCardName(String flipCardName) { - throw new UnsupportedOperationException("Not supported."); //To change body of generated methods, choose Tools | Templates. - } - - @Override public Spell copy() { return new Spell(this); @@ -876,11 +854,6 @@ public class Spell implements StackObject, Card { return card.getCardNumber(); } - @Override - public void setCardNumber(int cid) { - card.setCardNumber(cid); - } - @Override public boolean getUsesVariousArt() { return card.getUsesVariousArt(); diff --git a/Mage/src/mage/util/CardUtil.java b/Mage/src/mage/util/CardUtil.java index 39261435927..b817dba8481 100644 --- a/Mage/src/mage/util/CardUtil.java +++ b/Mage/src/mage/util/CardUtil.java @@ -55,7 +55,6 @@ import mage.game.Game; import mage.game.permanent.Permanent; import mage.game.permanent.token.Token; import mage.game.stack.Spell; -import mage.util.functions.CopyFunction; import mage.util.functions.CopyTokenFunction; @@ -379,16 +378,6 @@ public class CardUtil { spellAbility.getManaCostsToPay().addAll(adjustedCost); } - /** - * Returns function that copies params\abilities from one card to another. - * - * @param target - */ - @Deprecated - //public static CopyFunction copyTo(Card target) { - private static CopyFunction copyTo(Card target) { - return new CopyFunction(target); - } /** * Returns function that copies params\abilities from one card to {@link Token}. diff --git a/Mage/src/mage/util/functions/CopyFunction.java b/Mage/src/mage/util/functions/CopyFunction.java deleted file mode 100644 index 2c335a3fc6f..00000000000 --- a/Mage/src/mage/util/functions/CopyFunction.java +++ /dev/null @@ -1,97 +0,0 @@ -/* - * 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.util.functions; - -import mage.abilities.Ability; -import mage.cards.Card; -import mage.constants.CardType; -import mage.game.Game; -import mage.game.permanent.Permanent; - -/** - * @author nantuko - */ -public class CopyFunction implements Function { - - protected Card target; - protected Game game; - - public CopyFunction(Card target) { - if (target == null) { - throw new IllegalArgumentException("Target can't be null"); - } - this.target = target; - } - - @Override - public Card apply(Card source) { - if (target == null) { - throw new IllegalArgumentException("Target can't be null"); - } - - target.setName(source.getName()); - target.getColor().setColor(source.getColor()); - target.getManaCost().clear(); - target.getManaCost().add(source.getManaCost()); - target.getCardType().clear(); - for (CardType type : source.getCardType()) { - target.getCardType().add(type); - } - target.getSubtype().clear(); - for (String type : source.getSubtype()) { - target.getSubtype().add(type); - } - target.getSupertype().clear(); - for (String type : source.getSupertype()) { - target.getSupertype().add(type); - } - target.setExpansionSetCode(source.getExpansionSetCode()); - target.getAbilities().clear(); - - for (Ability ability0 : source.getAbilities()) { - Ability ability = ability0.copy(); - ability.newId(); - ability.setSourceId(target.getId()); - if(target instanceof Permanent) { - ((Permanent)target).addAbility(ability, game); - } else { - target.addAbility(ability); - } - } - - target.getPower().setValue(source.getPower().getValue()); - target.getToughness().setValue(source.getToughness().getValue()); - - return target; - } - - public Card from(Card source, Game game) { - this.game = game; - return apply(source); - } -}