From 42509dd4f89e6672fe42c4d70ae8cf0abd109820 Mon Sep 17 00:00:00 2001 From: BetaSteward Date: Thu, 10 Mar 2011 22:05:15 -0500 Subject: [PATCH] optimizations + leave game fix --- .../java/mage/client/cards/CardsStorage.java | 2 +- .../plugins/rating/cards/CardsStorage.java | 2 +- .../src/mage/game/TwoPlayerDuel.java | 5 ++ .../plugins/mage-game-twoplayerduel.jar | Bin 4870 -> 4894 bytes Mage.Sets/src/mage/sets/Sets.java | 2 +- .../plugins/mage-game-twoplayerduel.jar | Bin 4870 -> 4894 bytes Mage/src/mage/MageObjectImpl.java | 2 +- Mage/src/mage/abilities/AbilityImpl.java | 2 +- .../abilities/costs/mana/ManaCostsImpl.java | 56 +++++++++------- Mage/src/mage/cards/Card.java | 1 + Mage/src/mage/cards/CardImpl.java | 10 ++- Mage/src/mage/cards/ExpansionSet.java | 62 +++++++++--------- Mage/src/mage/game/Game.java | 3 +- Mage/src/mage/game/GameImpl.java | 40 +++++++++-- Mage/src/mage/game/permanent/Battlefield.java | 5 +- .../mage/game/permanent/PermanentCard.java | 32 +++++---- .../mage/game/permanent/PermanentImpl.java | 7 +- .../mage/game/permanent/PermanentToken.java | 24 ++++--- Mage/src/mage/game/stack/Spell.java | 6 ++ Mage/src/mage/players/Player.java | 3 +- Mage/src/mage/players/PlayerImpl.java | 31 ++------- 21 files changed, 175 insertions(+), 120 deletions(-) diff --git a/Mage.Client/src/main/java/mage/client/cards/CardsStorage.java b/Mage.Client/src/main/java/mage/client/cards/CardsStorage.java index f64a7e2710..00ace7c40a 100644 --- a/Mage.Client/src/main/java/mage/client/cards/CardsStorage.java +++ b/Mage.Client/src/main/java/mage/client/cards/CardsStorage.java @@ -33,7 +33,7 @@ public class CardsStorage { static { for (ExpansionSet set : Sets.getInstance().values()) { setCodes.add(set.getCode()); - Set cards = set.createCards(); + List cards = set.getCards(); allCards.addAll(cards); for (Card card : cards) { if (CardUtil.isLand(card) && !CardUtil.isBasicLand(card)) { diff --git a/Mage.Plugins/Mage.Rating.Plugin/src/main/java/org/mage/plugins/rating/cards/CardsStorage.java b/Mage.Plugins/Mage.Rating.Plugin/src/main/java/org/mage/plugins/rating/cards/CardsStorage.java index f6b1a73db1..de7af43533 100644 --- a/Mage.Plugins/Mage.Rating.Plugin/src/main/java/org/mage/plugins/rating/cards/CardsStorage.java +++ b/Mage.Plugins/Mage.Rating.Plugin/src/main/java/org/mage/plugins/rating/cards/CardsStorage.java @@ -15,7 +15,7 @@ public class CardsStorage { static { for (ExpansionSet set: Sets.getInstance().values()) { - allCards.addAll(set.createCards()); + allCards.addAll(set.getCards()); } Set names = new HashSet(); for (Card card : allCards) { diff --git a/Mage.Server.Plugins/Mage.Game.TwoPlayerDuel/src/mage/game/TwoPlayerDuel.java b/Mage.Server.Plugins/Mage.Game.TwoPlayerDuel/src/mage/game/TwoPlayerDuel.java index b5c1081254..1e2d0b1412 100644 --- a/Mage.Server.Plugins/Mage.Game.TwoPlayerDuel/src/mage/game/TwoPlayerDuel.java +++ b/Mage.Server.Plugins/Mage.Game.TwoPlayerDuel/src/mage/game/TwoPlayerDuel.java @@ -84,6 +84,11 @@ public class TwoPlayerDuel extends GameImpl { return opponents; } + @Override + public void leave(UUID playerId) { + + } + @Override public TwoPlayerDuel copy() { return new TwoPlayerDuel(this); diff --git a/Mage.Server/plugins/mage-game-twoplayerduel.jar b/Mage.Server/plugins/mage-game-twoplayerduel.jar index fb9c6b34063da93d0c52ceee9ac713b6482c8054..0c6f838e0c7a1201994f479114cc94cc48057c4b 100644 GIT binary patch delta 1909 zcmZ9NcT^L|7RDi=hcu8P2~s3<0->Wz6OCq(-m8Fg1ePX*vH?NZK%|A@(xf9zNxGcWZ7)%j_6*;!cJ$>OZige6Oa9ZXjU$15@tj~N*o!K7WD0`cRCT2=HU$C=RwzU(OOroW8s5p^3^JhREI7+I+dW% zSy#^SqCSeX`(=RzKGRmEzTEZou-i)y$X>gByhB<*Cpv|6=Ze5obEUmqW^SsE&Wd@a z(8Fzv(mdU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aCffYBOXkIAknU)9#u#r;nf4HeJ-*k3x2)c%+OT zJ5$YYeLO2&oFCy!;7Ji97D8jf<>yW{%Ai?V){VX5cacm7%lGWe z%o0MU@iC{7ii_j7tz6$W6jM)q|9HAegOAyo9_aG(6yn{rZ|Q=gi*t}IQ**}noquUB zWDO7|1yVmn6J}-2sht(uK`*e3MWu z^6GD0;IG@IY^Td(qRJL+z4J2&{arS`knBD3RyZPBW-J!=3HTlaE2wa9a+`R^|Nhx& zvYl0+&JDbOnTIXu=x9-CQi;Ir8?N{hv$3SgdardO;%d10)=LWcz3uUski|Fk;R(>s z;4T)$LmV#D+98Euqa!OfpX;tJg~tTCOKy?jaCw56^*)=}cwYKF^Fup^;6Wo!`To z>EL8yI;m)D0?WB*%21`vn;YRHqn!BHS`Dr0`7`OvNc5>2CHnV_X1sq@9jvL$vv9`0 zG31Jv!Di5!yX_|C^7li2*8N8k=`NFLaA%aoJ{;J~6=^nv#e8%p;V$b$hz^o7~sLQA$5 z06cK-Xm;D#ILa8q^%u6m zCQpc*=NwBvz##M>#aTi%{kZV*!o!pCi_%C9v!7@mOG6{E7j=?yctR5kc1m-$pJcN+ zbN<2ThtX#N{uWwks~yiO5@zEaHzhpX!~seYe}v4wxMF$pgP5VbkUxDWRtaK!SkFN$ z{x50nKDq*LX(xIlqkyn&j&XvLIE}4KM7lk Kno{wHf_?`^xlqpl diff --git a/Mage.Sets/src/mage/sets/Sets.java b/Mage.Sets/src/mage/sets/Sets.java index a995ab2199..df3c0afa8b 100644 --- a/Mage.Sets/src/mage/sets/Sets.java +++ b/Mage.Sets/src/mage/sets/Sets.java @@ -82,7 +82,7 @@ public class Sets extends HashMap { private void addSet(ExpansionSet set) { this.put(set.getCode(), set); - for (Card card: set.createCards()) { + for (Card card: set.getCards()) { names.add(card.getName()); } } diff --git a/Mage.Tests/plugins/mage-game-twoplayerduel.jar b/Mage.Tests/plugins/mage-game-twoplayerduel.jar index fb9c6b34063da93d0c52ceee9ac713b6482c8054..0c6f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7c7b8abc1e..c70261a9f9 100644 --- a/Mage/src/mage/MageObjectImpl.java +++ b/Mage/src/mage/MageObjectImpl.java @@ -43,7 +43,7 @@ import mage.game.Game; public abstract class MageObjectImpl> implements MageObject { - protected final UUID objectId; + protected UUID objectId; protected String name; protected ManaCosts manaCost; diff --git a/Mage/src/mage/abilities/AbilityImpl.java b/Mage/src/mage/abilities/AbilityImpl.java index 8656bd09f2..5ae697ecc4 100644 --- a/Mage/src/mage/abilities/AbilityImpl.java +++ b/Mage/src/mage/abilities/AbilityImpl.java @@ -96,7 +96,7 @@ public abstract class AbilityImpl> implements Ability { this.choices = new Choices(); } - public AbilityImpl(AbilityImpl ability) { + public AbilityImpl(final AbilityImpl ability) { this.id = ability.id; this.originalId = ability.originalId; this.abilityType = ability.abilityType; diff --git a/Mage/src/mage/abilities/costs/mana/ManaCostsImpl.java b/Mage/src/mage/abilities/costs/mana/ManaCostsImpl.java index f13812f241..e5c37647da 100644 --- a/Mage/src/mage/abilities/costs/mana/ManaCostsImpl.java +++ b/Mage/src/mage/abilities/costs/mana/ManaCostsImpl.java @@ -29,11 +29,12 @@ package mage.abilities.costs.mana; import java.util.ArrayList; +import java.util.HashMap; import java.util.List; +import java.util.Map; import java.util.UUID; import mage.Constants.ColoredManaSymbol; import mage.Mana; -import mage.abilities.Ability; import mage.abilities.costs.VariableCost; import mage.abilities.mana.ManaOptions; import mage.game.Game; @@ -47,6 +48,8 @@ import mage.target.Targets; */ public class ManaCostsImpl extends ArrayList implements ManaCosts { + private static Map costs = new HashMap(); + public ManaCostsImpl() {} public ManaCostsImpl(String mana) { @@ -196,32 +199,41 @@ public class ManaCostsImpl extends ArrayList implements M @Override public void load(String mana) { this.clear(); - if (mana == null || mana.length() == 0) - return; - String[] symbols = mana.split("^\\{|\\}\\{|\\}$"); - for (String symbol: symbols) { - if (symbol.length() > 0) { - if (symbol.length() == 1 || isNumeric(symbol)) { - if (Character.isDigit(symbol.charAt(0))) { - this.add((T)new GenericManaCost(Integer.valueOf(symbol))); + if (costs.containsKey(mana)) { + ManaCosts savedCosts = costs.get(mana); + for (ManaCost cost: savedCosts) { + this.add((T)cost.copy()); + } + } + else { + if (mana == null || mana.length() == 0) + return; + String[] symbols = mana.split("^\\{|\\}\\{|\\}$"); + for (String symbol: symbols) { + if (symbol.length() > 0) { + if (symbol.length() == 1 || isNumeric(symbol)) { + if (Character.isDigit(symbol.charAt(0))) { + this.add((T)new GenericManaCost(Integer.valueOf(symbol))); + } + else { + if (!symbol.equals("X")) + this.add((T)new ColoredManaCost(ColoredManaSymbol.lookup(symbol.charAt(0)))); + else + this.add((T)new VariableManaCost()); + //TODO: handle multiple {X} and/or {Y} symbols + } } else { - if (!symbol.equals("X")) - this.add((T)new ColoredManaCost(ColoredManaSymbol.lookup(symbol.charAt(0)))); - else - this.add((T)new VariableManaCost()); - //TODO: handle multiple {X} and/or {Y} symbols - } - } - else { - if (Character.isDigit(symbol.charAt(0))) { - this.add((T)new MonoHybridManaCost(ColoredManaSymbol.lookup(symbol.charAt(2)))); - } - else { - this.add((T)new HybridManaCost(ColoredManaSymbol.lookup(symbol.charAt(0)), ColoredManaSymbol.lookup(symbol.charAt(2)))); + if (Character.isDigit(symbol.charAt(0))) { + this.add((T)new MonoHybridManaCost(ColoredManaSymbol.lookup(symbol.charAt(2)))); + } + else { + this.add((T)new HybridManaCost(ColoredManaSymbol.lookup(symbol.charAt(0)), ColoredManaSymbol.lookup(symbol.charAt(2)))); + } } } } + costs.put(mana, this.copy()); } } diff --git a/Mage/src/mage/cards/Card.java b/Mage/src/mage/cards/Card.java index 6b339827f3..3be0150484 100644 --- a/Mage/src/mage/cards/Card.java +++ b/Mage/src/mage/cards/Card.java @@ -57,6 +57,7 @@ public interface Card extends MageObject { public String getExpansionSetCode(); public void setExpansionSetCode(String expansionSetCode); + public void assignNewId(); public boolean moveToZone(Zone zone, UUID sourceId, Game game, boolean flag); public boolean moveToExile(UUID exileId, String name, UUID sourceId, Game game); public boolean cast(Game game, Zone fromZone, SpellAbility ability, UUID controllerId); diff --git a/Mage/src/mage/cards/CardImpl.java b/Mage/src/mage/cards/CardImpl.java index c90f80b7b7..0e5b1909f1 100644 --- a/Mage/src/mage/cards/CardImpl.java +++ b/Mage/src/mage/cards/CardImpl.java @@ -30,6 +30,7 @@ package mage.cards; import java.lang.reflect.Constructor; import java.util.ArrayList; +import java.util.Arrays; import java.util.List; import java.util.UUID; import java.util.logging.Level; @@ -66,8 +67,7 @@ public abstract class CardImpl> extends MageObjectImpl this(ownerId, name); this.rarity = rarity; this.cardNumber = cardNumber; - for (CardType newCardType: cardTypes) - this.cardType.add(newCardType); + this.cardType.addAll(Arrays.asList(cardTypes)); this.manaCost.load(costs); if (cardType.contains(CardType.LAND)) addAbility(new PlayLandAbility(name)); @@ -95,6 +95,12 @@ public abstract class CardImpl> extends MageObjectImpl watchers = card.watchers.copy(); } + @Override + public void assignNewId() { + this.objectId = UUID.randomUUID(); + this.abilities.setSourceId(objectId); + } + public static Card createCard(String name) { try { Class theClass = Class.forName(name); diff --git a/Mage/src/mage/cards/ExpansionSet.java b/Mage/src/mage/cards/ExpansionSet.java index 7b448f493d..d877aaf23c 100644 --- a/Mage/src/mage/cards/ExpansionSet.java +++ b/Mage/src/mage/cards/ExpansionSet.java @@ -61,9 +61,9 @@ public abstract class ExpansionSet implements Serializable { protected String symbolCode; protected Date releaseDate; protected ExpansionSet parentSet; - protected List cards; + protected List cards; protected SetType setType; - protected Map> rarities; + protected Map> rarities; protected String blockName; protected boolean hasBoosters = false; @@ -83,7 +83,7 @@ public abstract class ExpansionSet implements Serializable { this.rarities = getCardsByRarity(); } - public List getCards() { + public List getCards() { return cards; } @@ -107,7 +107,7 @@ public abstract class ExpansionSet implements Serializable { return setType; } - public Card createCard(Class clazz) { + private Card createCard(Class clazz) { try { Constructor con = clazz.getConstructor(new Class[]{UUID.class}); return (Card) con.newInstance(new Object[]{null}); @@ -118,49 +118,46 @@ public abstract class ExpansionSet implements Serializable { } } - public Set createCards() { - Set created = new HashSet(); - for (Class clazz : cards) { - created.add(createCard(clazz)); - } - return created; - } - @Override public String toString() { return name; } public Card findCard(String name) { - for (Card card : createCards()) { - if (name.equals(card.getName())) - return card; + for (Card card : cards) { + if (name.equals(card.getName())) { + Card newCard = card.copy(); + newCard.assignNewId(); + return newCard; + } } return null; } public Card findCard(String name, boolean random) { - List cards = new ArrayList(); - for (Card card : createCards()) { + List foundCards = new ArrayList(); + for (Card card : cards) { if (name.equals(card.getName())) { - cards.add(card); + foundCards.add(card); } } - if (cards.size() > 0) { - return cards.get(rnd.nextInt(cards.size())); + if (foundCards.size() > 0) { + Card newCard = foundCards.get(rnd.nextInt(foundCards.size())).copy(); + newCard.assignNewId(); + return newCard; } return null; } public String findCard(int cardNum) { - for (Card card : createCards()) { + for (Card card : cards) { if (card.getCardNumber() == cardNum) return card.getClass().getCanonicalName(); } return null; } - private ArrayList getCardClassesForPackage(String packageName) { + private List getCardClassesForPackage(String packageName) { ClassLoader classLoader = this.getClass().getClassLoader(); assert classLoader != null; String path = packageName.replace('.', '/'); @@ -187,7 +184,7 @@ public abstract class ExpansionSet implements Serializable { e.printStackTrace(); } } - ArrayList classes = new ArrayList(); + List classes = new ArrayList(); if (isLoadingFromJar) { if (jarPath.contains("!")) { jarPath = jarPath.substring(0, jarPath.lastIndexOf('!')); @@ -214,7 +211,11 @@ public abstract class ExpansionSet implements Serializable { } } } - return classes; + List newCards = new ArrayList(); + for (Class clazz: classes) { + newCards.add(createCard(clazz)); + } + return newCards; } private static List findClasses(File directory, String packageName) throws ClassNotFoundException { @@ -276,14 +277,13 @@ public abstract class ExpansionSet implements Serializable { return classes; } - private Map> getCardsByRarity() { - Map> cardsByRarity = new HashMap>(); + private Map> getCardsByRarity() { + Map> cardsByRarity = new HashMap>(); - for (Class clazz : cards) { - Card card = createCard(clazz); + for (Card card : cards) { if (!cardsByRarity.containsKey(card.getRarity())) - cardsByRarity.put(card.getRarity(), new ArrayList()); - cardsByRarity.get(card.getRarity()).add(clazz); + cardsByRarity.put(card.getRarity(), new ArrayList()); + cardsByRarity.get(card.getRarity()).add(card); } return cardsByRarity; @@ -332,7 +332,7 @@ public abstract class ExpansionSet implements Serializable { return null; int size = rarities.get(rarity).size(); if (size > 0) { - return createCard(rarities.get(rarity).get(rnd.nextInt(size))); + return rarities.get(rarity).get(rnd.nextInt(size)).copy(); } return null; } diff --git a/Mage/src/mage/game/Game.java b/Mage/src/mage/game/Game.java index 0b03427c5d..b960cea9bb 100644 --- a/Mage/src/mage/game/Game.java +++ b/Mage/src/mage/game/Game.java @@ -28,7 +28,6 @@ package mage.game; -import mage.Constants; import mage.game.match.MatchType; import mage.cards.Card; import mage.game.stack.SpellStack; @@ -61,7 +60,6 @@ import mage.game.permanent.PermanentCard; import mage.game.turn.Phase; import mage.game.turn.Step; import mage.game.turn.Turn; -import mage.players.Library; import mage.players.Player; import mage.players.PlayerList; import mage.players.Players; @@ -97,6 +95,7 @@ public interface Game extends MageItem, Serializable { public boolean canPlaySorcery(UUID playerId); public UUID getActivePlayerId(); public UUID getPriorityPlayerId(); + public void leave(UUID playerId); public boolean isGameOver(); public Battlefield getBattlefield(); public SpellStack getStack(); diff --git a/Mage/src/mage/game/GameImpl.java b/Mage/src/mage/game/GameImpl.java index 45d011f96a..dd6e8b0ef0 100644 --- a/Mage/src/mage/game/GameImpl.java +++ b/Mage/src/mage/game/GameImpl.java @@ -53,7 +53,6 @@ import mage.game.stack.StackObject; import mage.game.turn.Phase; import mage.game.turn.Step; import mage.game.turn.Turn; -import mage.players.Library; import mage.players.Player; import mage.players.PlayerList; import mage.players.Players; @@ -114,9 +113,10 @@ public abstract class GameImpl> implements Game, Serializa this.range = game.range; this.attackOption = game.attackOption; this.state = game.state.copy(); - for (Map.Entry entry: game.gameCards.entrySet()) { - this.gameCards.put(entry.getKey(), entry.getValue().copy()); - } +// for (Map.Entry entry: game.gameCards.entrySet()) { +// this.gameCards.put(entry.getKey(), entry.getValue().copy()); +// } + this.gameCards = game.gameCards; } @Override @@ -457,7 +457,7 @@ public abstract class GameImpl> implements Game, Serializa public synchronized void quit(UUID playerId) { Player player = state.getPlayer(playerId); if (player != null) { - player.leaveGame(this); + leave(playerId); fireInformEvent(player.getName() + " has left the game."); } } @@ -869,6 +869,36 @@ public abstract class GameImpl> implements Game, Serializa return getActivePlayerId().equals(playerId) && getStack().isEmpty() && isMainPhase(); } + @Override + public void leave(UUID playerId) { + Player player = getPlayer(playerId); + player.leave(); + //20100423 - 800.4a + for (Iterator it = getBattlefield().getAllPermanents().iterator(); it.hasNext();) { + Permanent perm = it.next(); + if (perm.getOwnerId().equals(playerId)) { + if (perm.getAttachedTo() != null) { + Permanent attachedTo = getPermanent(perm.getAttachedTo()); + if (attachedTo != null) + attachedTo.removeAttachment(perm.getId(), this); + } + it.remove(); + } + } + for (Iterator it = getStack().iterator(); it.hasNext();) { + StackObject object = it.next(); + if (object.getControllerId().equals(playerId)) { + it.remove(); + } + } + for (Iterator it = getBattlefield().getAllPermanents().iterator(); it.hasNext();) { + Permanent perm = it.next(); + if (perm.getControllerId().equals(playerId)) { + perm.moveToExile(null, "", null, this); + } + } + } + @Override public UUID getActivePlayerId() { return state.getActivePlayerId(); diff --git a/Mage/src/mage/game/permanent/Battlefield.java b/Mage/src/mage/game/permanent/Battlefield.java index ad7e681147..22e76ba0c1 100644 --- a/Mage/src/mage/game/permanent/Battlefield.java +++ b/Mage/src/mage/game/permanent/Battlefield.java @@ -34,6 +34,7 @@ import java.util.Collection; import java.util.LinkedHashMap; import java.util.List; import java.util.Map; +import java.util.Map.Entry; import java.util.Set; import java.util.UUID; import mage.Constants.CardType; @@ -54,8 +55,8 @@ public class Battlefield implements Serializable { public Battlefield () {} public Battlefield(final Battlefield battlefield) { - for (UUID permId: battlefield.field.keySet()) { - field.put(permId, battlefield.field.get(permId).copy()); + for (Entry entry: battlefield.field.entrySet()) { + field.put(entry.getKey(), entry.getValue().copy()); } } diff --git a/Mage/src/mage/game/permanent/PermanentCard.java b/Mage/src/mage/game/permanent/PermanentCard.java index bfd47a74b2..b3e54f45b8 100644 --- a/Mage/src/mage/game/permanent/PermanentCard.java +++ b/Mage/src/mage/game/permanent/PermanentCard.java @@ -83,20 +83,32 @@ public class PermanentCard extends PermanentImpl { public void reset(Game game) { // when the permanent is reset copy all original values from the card // must copy card each reset so that the original values don't get modified - Card copy = game.getCard(objectId).copy(); - copyFromCard(copy); +// Card copy = game.getCard(objectId).copy(); + copyFromCard(game.getCard(objectId)); super.reset(game); } protected void copyFromCard(Card card) { this.name = card.getName(); - this.abilities = card.getAbilities(); - this.abilities.setControllerId(this.controllerId); - this.cardType = card.getCardType(); - this.color = card.getColor(); - this.manaCost = card.getManaCost(); - this.power = card.getPower(); - this.toughness = card.getToughness(); + this.manaCost = card.getManaCost().copy(); + this.color = card.getColor().copy(); + this.power = card.getPower().copy(); + this.toughness = card.getToughness().copy(); + this.loyalty = card.getLoyalty().copy(); + this.abilities = card.getAbilities().copy(); + this.abilities.setControllerId(controllerId); + this.cardType.clear(); + for (CardType cType: card.getCardType()) { + this.cardType.add(cType); + } + this.subtype.clear(); + for (String subType: card.getSubtype()) { + this.subtype.add(subType); + } + this.supertype.clear(); + for (String superType: card.getSupertype()) { + this.supertype.add(superType); + } if (card instanceof LevelerCard) { LevelAbility level = ((LevelerCard)card).getLevel(this.getCounters().getCount("Level")); if (level != null) { @@ -107,8 +119,6 @@ public class PermanentCard extends PermanentImpl { } } } - this.subtype = card.getSubtype(); - this.supertype = card.getSupertype(); this.art = card.getArt(); this.expansionSetCode = card.getExpansionSetCode(); this.rarity = card.getRarity(); diff --git a/Mage/src/mage/game/permanent/PermanentImpl.java b/Mage/src/mage/game/permanent/PermanentImpl.java index d92bf9c125..055e325740 100644 --- a/Mage/src/mage/game/permanent/PermanentImpl.java +++ b/Mage/src/mage/game/permanent/PermanentImpl.java @@ -55,6 +55,7 @@ public abstract class PermanentImpl> extends CardImpl protected boolean tapped; protected boolean flipped; + protected UUID originalControllerId; protected UUID controllerId; protected int damage; protected boolean controlledFromStartOfTurn; @@ -72,12 +73,14 @@ public abstract class PermanentImpl> extends CardImpl public PermanentImpl(UUID ownerId, UUID controllerId, String name) { super(ownerId, name); + this.originalControllerId = controllerId; this.controllerId = controllerId; this.counters = new Counters(); } public PermanentImpl(UUID id, UUID ownerId, UUID controllerId, String name) { super(id, ownerId, name); + this.originalControllerId = controllerId; this.controllerId = controllerId; this.counters = new Counters(); } @@ -86,6 +89,7 @@ public abstract class PermanentImpl> extends CardImpl super(permanent); this.tapped = permanent.tapped; this.flipped = permanent.flipped; + this.originalControllerId = permanent.originalControllerId; this.controllerId = permanent.controllerId; this.damage = permanent.damage; this.controlledFromStartOfTurn = permanent.controlledFromStartOfTurn; @@ -111,7 +115,7 @@ public abstract class PermanentImpl> extends CardImpl @Override public void reset(Game game) { -// this.controllerId = ownerId; + this.controllerId = originalControllerId; this.maxBlocks = 1; } @@ -169,7 +173,6 @@ public abstract class PermanentImpl> extends CardImpl for (Ability ability : this.abilities) { ability.reset(game); } - this.controllerId = this.ownerId; } @Override diff --git a/Mage/src/mage/game/permanent/PermanentToken.java b/Mage/src/mage/game/permanent/PermanentToken.java index c73099b531..a4c31648eb 100644 --- a/Mage/src/mage/game/permanent/PermanentToken.java +++ b/Mage/src/mage/game/permanent/PermanentToken.java @@ -30,6 +30,7 @@ package mage.game.permanent; import mage.game.permanent.token.Token; import java.util.UUID; +import mage.Constants.CardType; import mage.Constants.Zone; import mage.abilities.Ability; import mage.game.Game; @@ -56,22 +57,25 @@ public class PermanentToken extends PermanentImpl { @Override public void reset(Game game) { - Token copy = token.copy(); - copyFromToken(copy); +// Token copy = token.copy(); + copyFromToken(token); super.reset(game); } protected void copyFromToken(Token token) { this.name = token.getName(); - this.abilities.clear(); - for (Ability ability: token.getAbilities()) { - this.addAbility(ability); + this.abilities = token.getAbilities().copy(); + this.cardType.clear(); + for (CardType cType: token.getCardType()) { + this.cardType.add(cType); } - this.cardType = token.getCardType(); - this.color = token.getColor(); - this.power = token.getPower(); - this.toughness = token.getToughness(); - this.subtype = token.getSubtype(); + this.subtype.clear(); + for (String subType: token.getSubtype()) { + this.subtype.add(subType); + } + this.color = token.getColor().copy(); + this.power = token.getPower().copy(); + this.toughness = token.getToughness().copy(); } @Override diff --git a/Mage/src/mage/game/stack/Spell.java b/Mage/src/mage/game/stack/Spell.java index 1ef06e63ec..b60cc33595 100644 --- a/Mage/src/mage/game/stack/Spell.java +++ b/Mage/src/mage/game/stack/Spell.java @@ -330,8 +330,14 @@ public class Spell> implements StackObject, Card { throw new UnsupportedOperationException("Unsupported operation"); } + @Override public Ability getStackAbility() { return this.ability; } + + @Override + public void assignNewId() { + throw new UnsupportedOperationException("Unsupported operation"); + } } diff --git a/Mage/src/mage/players/Player.java b/Mage/src/mage/players/Player.java index 3519e39791..880147878e 100644 --- a/Mage/src/mage/players/Player.java +++ b/Mage/src/mage/players/Player.java @@ -55,7 +55,6 @@ import mage.counters.Counters; import mage.filter.FilterAbility; import mage.game.events.GameEvent; import mage.game.Game; -import mage.game.Table; import mage.game.draft.Draft; import mage.game.match.Match; import mage.game.permanent.Permanent; @@ -126,7 +125,7 @@ public interface Player extends MageItem, Copyable { public boolean discard(Card card, Ability source, Game game); public void lost(Game game); public void won(Game game); - public void leaveGame(Game game); + public void leave(); public void concede(Game game); public void abort(); diff --git a/Mage/src/mage/players/PlayerImpl.java b/Mage/src/mage/players/PlayerImpl.java index 22f955ded4..fc01b3df78 100644 --- a/Mage/src/mage/players/PlayerImpl.java +++ b/Mage/src/mage/players/PlayerImpl.java @@ -732,11 +732,13 @@ public abstract class PlayerImpl> implements Player, Ser @Override public void concede(Game game) { - leaveGame(game); + this.loses = true; + this.abort(); + game.leave(playerId); } @Override - public void leaveGame(Game game) { + public void leave() { this.passed = true; this.abort(); this.loses = true; @@ -745,29 +747,6 @@ public abstract class PlayerImpl> implements Player, Ser this.hand.clear(); this.graveyard.clear(); this.library.clear(); - for (Iterator it = game.getBattlefield().getAllPermanents().iterator(); it.hasNext();) { - Permanent perm = it.next(); - if (perm.getOwnerId().equals(playerId)) { - if (perm.getAttachedTo() != null) { - Permanent attachedTo = game.getPermanent(perm.getAttachedTo()); - if (attachedTo != null) - attachedTo.removeAttachment(perm.getId(), game); - } - it.remove(); - } - } - for (Iterator it = game.getStack().iterator(); it.hasNext();) { - StackObject object = it.next(); - if (object.getControllerId().equals(playerId)) { - it.remove(); - } - } - for (Iterator it = game.getBattlefield().getAllPermanents().iterator(); it.hasNext();) { - Permanent perm = it.next(); - if (perm.getControllerId().equals(playerId)) { - perm.moveToExile(null, "", null, game); - } - } } @Override @@ -782,7 +761,7 @@ public abstract class PlayerImpl> implements Player, Ser //20100423 - 603.9 if (!this.wins) game.fireEvent(GameEvent.getEvent(GameEvent.EventType.LOST, null, null, playerId)); - leaveGame(game); + game.leave(playerId); } }