From a22d8d8309935943a6cde847c557deef8b1489f0 Mon Sep 17 00:00:00 2001 From: LevelX2 Date: Thu, 18 Apr 2013 16:03:02 +0200 Subject: [PATCH] Added some options to create token functions, so that tapping and set attacking works with effects that change the amounts of tokens that comes into play. --- .../effects/common/CreateTokenEffect.java | 30 +++++++++++++++++-- Mage/src/mage/game/permanent/token/Token.java | 26 +++++++++++----- 2 files changed, 45 insertions(+), 11 deletions(-) diff --git a/Mage/src/mage/abilities/effects/common/CreateTokenEffect.java b/Mage/src/mage/abilities/effects/common/CreateTokenEffect.java index 6ce5c35f57..9cc7986241 100644 --- a/Mage/src/mage/abilities/effects/common/CreateTokenEffect.java +++ b/Mage/src/mage/abilities/effects/common/CreateTokenEffect.java @@ -35,6 +35,7 @@ import mage.abilities.dynamicvalue.common.StaticValue; import mage.abilities.effects.OneShotEffect; import mage.game.Game; import mage.game.permanent.token.Token; +import mage.util.CardUtil; /** * @@ -44,6 +45,8 @@ public class CreateTokenEffect extends OneShotEffect { private Token token; private DynamicValue amount; + private boolean tapped; + private boolean attacking; public CreateTokenEffect(Token token) { this(token, new StaticValue(1)); @@ -54,9 +57,19 @@ public class CreateTokenEffect extends OneShotEffect { } public CreateTokenEffect(Token token, DynamicValue amount) { + this(token, amount, false, false); + } + + public CreateTokenEffect(Token token, int amount, boolean tapped, boolean attacking) { + this(token, new StaticValue(amount), tapped, attacking); + } + + public CreateTokenEffect(Token token, DynamicValue amount, boolean tapped, boolean attacking) { super(Outcome.PutCreatureInPlay); this.token = token; this.amount = amount.copy(); + this.tapped = tapped; + this.attacking = attacking; setText(); } @@ -64,6 +77,8 @@ public class CreateTokenEffect extends OneShotEffect { super(effect); this.amount = effect.amount.copy(); this.token = effect.token.copy(); + this.tapped = effect.tapped; + this.attacking = effect.attacking; } @Override @@ -76,21 +91,30 @@ public class CreateTokenEffect extends OneShotEffect { int value = amount.calculate(game, source); Token tokenCopy = token.copy(); tokenCopy.getAbilities().newId(); // neccessary if token has ability like DevourAbility() - tokenCopy.putOntoBattlefield(value, game, source.getSourceId(), source.getControllerId()); + tokenCopy.putOntoBattlefield(value, game, source.getSourceId(), source.getControllerId(), tapped, attacking); return true; } - + private void setText() { StringBuilder sb = new StringBuilder("put "); if (amount.toString().equals("1")) { sb.append("a ").append(token.getDescription()); } else { - sb.append(amount.toString()).append(" ").append(token.getDescription()); + sb.append(CardUtil.numberToText(amount.toString())).append(" ").append(token.getDescription()); if (token.getDescription().endsWith("token")) { sb.append("s "); } } sb.append(" onto the battlefield"); + if (tapped) { + sb.append(" tapped"); + } + if (attacking) { + if (tapped) { + sb.append(" and"); + } + sb.append(" attacking"); + } String message = amount.getMessage(); if (message.length() > 0) { if (amount.toString().equals("X")) { diff --git a/Mage/src/mage/game/permanent/token/Token.java b/Mage/src/mage/game/permanent/token/Token.java index d7f2cc480f..393f654c0c 100644 --- a/Mage/src/mage/game/permanent/token/Token.java +++ b/Mage/src/mage/game/permanent/token/Token.java @@ -28,6 +28,8 @@ package mage.game.permanent.token; +import java.util.List; +import java.util.UUID; import mage.Constants.CardType; import mage.Constants.Zone; import mage.MageObjectImpl; @@ -41,8 +43,6 @@ import mage.game.events.GameEvent.EventType; import mage.game.events.ZoneChangeEvent; import mage.game.permanent.PermanentToken; -import java.util.List; -import java.util.UUID; public class Token extends MageObjectImpl { @@ -107,22 +107,32 @@ public class Token extends MageObjectImpl { } public boolean putOntoBattlefield(int amount, Game game, UUID sourceId, UUID controllerId) { + return this.putOntoBattlefield(amount, game, sourceId, controllerId, false, false); + } + + public boolean putOntoBattlefield(int amount, Game game, UUID sourceId, UUID controllerId, boolean tapped, boolean attacking) { Card source = game.getCard(sourceId); String setCode = source != null ? source.getExpansionSetCode() : null; GameEvent event = GameEvent.getEvent(EventType.CREATE_TOKEN, null, sourceId, controllerId, amount); if (!game.replaceEvent(event)) { amount = event.getAmount(); for (int i = 0; i < amount; i++) { - PermanentToken permanent = new PermanentToken(this, controllerId, setCode, game); - game.getState().addCard(permanent); - game.addPermanent(permanent); - this.lastAddedTokenId = permanent.getId(); + PermanentToken newToken = new PermanentToken(this, controllerId, setCode, game); + game.getState().addCard(newToken); + game.addPermanent(newToken); + if (tapped) { + newToken.setTapped(true); + } + this.lastAddedTokenId = newToken.getId(); game.setScopeRelevant(true); game.applyEffects(); - permanent.entersBattlefield(sourceId, game, Zone.OUTSIDE, true); + newToken.entersBattlefield(sourceId, game, Zone.OUTSIDE, true); game.setScopeRelevant(false); game.applyEffects(); - game.fireEvent(new ZoneChangeEvent(permanent, controllerId, Zone.OUTSIDE, Zone.BATTLEFIELD)); + game.fireEvent(new ZoneChangeEvent(newToken, controllerId, Zone.OUTSIDE, Zone.BATTLEFIELD)); + if (attacking && game.getCombat() != null) { + game.getCombat().addAttackingCreature(newToken.getId(), game); + } } return true; }