From 611c4b7b2fc443a5ba698b63894046a167a81cc0 Mon Sep 17 00:00:00 2001 From: magenoxx Date: Mon, 13 Jun 2011 17:43:28 +0400 Subject: [PATCH] Now tokens connected to the source by expansionSetCode - results in token image displayed. --- Mage.Common/src/mage/view/CardView.java | 8 +++----- Mage.Common/src/mage/view/PermanentView.java | 1 + .../mage/abilities/effects/common/CreateTokenEffect.java | 5 ++++- Mage/src/mage/game/permanent/PermanentToken.java | 4 +++- Mage/src/mage/game/permanent/token/Token.java | 8 ++++++-- 5 files changed, 17 insertions(+), 9 deletions(-) diff --git a/Mage.Common/src/mage/view/CardView.java b/Mage.Common/src/mage/view/CardView.java index e083ff7a97..b7cba207e9 100644 --- a/Mage.Common/src/mage/view/CardView.java +++ b/Mage.Common/src/mage/view/CardView.java @@ -94,12 +94,10 @@ public class CardView implements Serializable { this.convertedManaCost = card.getManaCost().convertedManaCost(); if (card instanceof PermanentToken) { this.rarity = Rarity.NA; - this.expansionSetCode = ""; - } - else { + } else { this.rarity = card.getRarity(); - this.expansionSetCode = card.getExpansionSetCode(); } + this.expansionSetCode = card.getExpansionSetCode(); this.cardNumber = card.getCardNumber(); if (card instanceof Spell) { @@ -127,7 +125,7 @@ public class CardView implements Serializable { this.color = token.getColor(); this.manaCost = token.getManaCost().getSymbols(); this.rarity = Rarity.NA; - this.expansionSetCode = ""; + //this.expansionSetCode = ""; } protected void setTargets(Targets targets) { diff --git a/Mage.Common/src/mage/view/PermanentView.java b/Mage.Common/src/mage/view/PermanentView.java index 66c72001a6..0f6c6449bf 100644 --- a/Mage.Common/src/mage/view/PermanentView.java +++ b/Mage.Common/src/mage/view/PermanentView.java @@ -74,6 +74,7 @@ public class PermanentView extends CardView { } if (permanent instanceof PermanentToken) { original = new CardView(((PermanentToken)permanent).getToken()); + original.expansionSetCode = permanent.getExpansionSetCode(); } else { original = new CardView(card); diff --git a/Mage/src/mage/abilities/effects/common/CreateTokenEffect.java b/Mage/src/mage/abilities/effects/common/CreateTokenEffect.java index 917e169841..936d5b098c 100644 --- a/Mage/src/mage/abilities/effects/common/CreateTokenEffect.java +++ b/Mage/src/mage/abilities/effects/common/CreateTokenEffect.java @@ -73,7 +73,10 @@ public class CreateTokenEffect extends OneShotEffect { @Override public boolean apply(Game game, Ability source) { for (int i = 0; i < amount.calculate(game, source); i++) { - token.putOntoBattlefield(game, source.getId(), source.getControllerId()); + // we need to specify source.getSourceId(), not source.getId() + // as we most interested in the game object that created effect, + // not in ability uuid + token.putOntoBattlefield(game, source.getSourceId(), source.getControllerId()); } return true; } diff --git a/Mage/src/mage/game/permanent/PermanentToken.java b/Mage/src/mage/game/permanent/PermanentToken.java index da8654dde8..3f75fa700f 100644 --- a/Mage/src/mage/game/permanent/PermanentToken.java +++ b/Mage/src/mage/game/permanent/PermanentToken.java @@ -43,15 +43,17 @@ public class PermanentToken extends PermanentImpl { protected Token token; - public PermanentToken(Token token, UUID controllerId) { + public PermanentToken(Token token, UUID controllerId, String expansionSetCode) { super(controllerId, controllerId, token.getName()); this.token = token; + this.expansionSetCode = expansionSetCode; copyFromToken(token); } public PermanentToken(final PermanentToken permanent) { super(permanent); this.token = permanent.token.copy(); + this.expansionSetCode = permanent.expansionSetCode; } @Override diff --git a/Mage/src/mage/game/permanent/token/Token.java b/Mage/src/mage/game/permanent/token/Token.java index a4b3a51b01..ea18a88fdd 100644 --- a/Mage/src/mage/game/permanent/token/Token.java +++ b/Mage/src/mage/game/permanent/token/Token.java @@ -36,8 +36,10 @@ import mage.MageObjectImpl; import mage.ObjectColor; import mage.abilities.Abilities; import mage.abilities.Ability; +import mage.cards.Card; import mage.game.Game; import mage.game.events.ZoneChangeEvent; +import mage.game.permanent.Permanent; import mage.game.permanent.PermanentToken; public class Token extends MageObjectImpl { @@ -86,9 +88,11 @@ public class Token extends MageObjectImpl { } public boolean putOntoBattlefield(Game game, UUID sourceId, UUID controllerId) { - PermanentToken permanent = new PermanentToken(this, controllerId); + Card source = game.getCard(sourceId); + String setCode = source != null ? source.getExpansionSetCode() : null; + PermanentToken permanent = new PermanentToken(this, controllerId, setCode); game.getBattlefield().addPermanent(permanent); - this.lastAddedTokenId = permanent.getId(); + this.lastAddedTokenId = permanent.getId(); permanent.entersBattlefield(sourceId, game); game.applyEffects(); game.fireEvent(new ZoneChangeEvent(permanent, controllerId, Zone.OUTSIDE, Zone.BATTLEFIELD));