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.

This commit is contained in:
LevelX2 2013-04-18 16:03:02 +02:00
parent 9d4d42d184
commit a22d8d8309
2 changed files with 45 additions and 11 deletions

View file

@ -35,6 +35,7 @@ import mage.abilities.dynamicvalue.common.StaticValue;
import mage.abilities.effects.OneShotEffect; import mage.abilities.effects.OneShotEffect;
import mage.game.Game; import mage.game.Game;
import mage.game.permanent.token.Token; import mage.game.permanent.token.Token;
import mage.util.CardUtil;
/** /**
* *
@ -44,6 +45,8 @@ public class CreateTokenEffect extends OneShotEffect<CreateTokenEffect> {
private Token token; private Token token;
private DynamicValue amount; private DynamicValue amount;
private boolean tapped;
private boolean attacking;
public CreateTokenEffect(Token token) { public CreateTokenEffect(Token token) {
this(token, new StaticValue(1)); this(token, new StaticValue(1));
@ -54,9 +57,19 @@ public class CreateTokenEffect extends OneShotEffect<CreateTokenEffect> {
} }
public CreateTokenEffect(Token token, DynamicValue amount) { 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); super(Outcome.PutCreatureInPlay);
this.token = token; this.token = token;
this.amount = amount.copy(); this.amount = amount.copy();
this.tapped = tapped;
this.attacking = attacking;
setText(); setText();
} }
@ -64,6 +77,8 @@ public class CreateTokenEffect extends OneShotEffect<CreateTokenEffect> {
super(effect); super(effect);
this.amount = effect.amount.copy(); this.amount = effect.amount.copy();
this.token = effect.token.copy(); this.token = effect.token.copy();
this.tapped = effect.tapped;
this.attacking = effect.attacking;
} }
@Override @Override
@ -76,7 +91,7 @@ public class CreateTokenEffect extends OneShotEffect<CreateTokenEffect> {
int value = amount.calculate(game, source); int value = amount.calculate(game, source);
Token tokenCopy = token.copy(); Token tokenCopy = token.copy();
tokenCopy.getAbilities().newId(); // neccessary if token has ability like DevourAbility() 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; return true;
} }
@ -85,12 +100,21 @@ public class CreateTokenEffect extends OneShotEffect<CreateTokenEffect> {
if (amount.toString().equals("1")) { if (amount.toString().equals("1")) {
sb.append("a ").append(token.getDescription()); sb.append("a ").append(token.getDescription());
} else { } else {
sb.append(amount.toString()).append(" ").append(token.getDescription()); sb.append(CardUtil.numberToText(amount.toString())).append(" ").append(token.getDescription());
if (token.getDescription().endsWith("token")) { if (token.getDescription().endsWith("token")) {
sb.append("s "); sb.append("s ");
} }
} }
sb.append(" onto the battlefield"); sb.append(" onto the battlefield");
if (tapped) {
sb.append(" tapped");
}
if (attacking) {
if (tapped) {
sb.append(" and");
}
sb.append(" attacking");
}
String message = amount.getMessage(); String message = amount.getMessage();
if (message.length() > 0) { if (message.length() > 0) {
if (amount.toString().equals("X")) { if (amount.toString().equals("X")) {

View file

@ -28,6 +28,8 @@
package mage.game.permanent.token; package mage.game.permanent.token;
import java.util.List;
import java.util.UUID;
import mage.Constants.CardType; import mage.Constants.CardType;
import mage.Constants.Zone; import mage.Constants.Zone;
import mage.MageObjectImpl; import mage.MageObjectImpl;
@ -41,8 +43,6 @@ import mage.game.events.GameEvent.EventType;
import mage.game.events.ZoneChangeEvent; import mage.game.events.ZoneChangeEvent;
import mage.game.permanent.PermanentToken; import mage.game.permanent.PermanentToken;
import java.util.List;
import java.util.UUID;
public class Token extends MageObjectImpl<Token> { public class Token extends MageObjectImpl<Token> {
@ -107,22 +107,32 @@ public class Token extends MageObjectImpl<Token> {
} }
public boolean putOntoBattlefield(int amount, Game game, UUID sourceId, UUID controllerId) { 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); Card source = game.getCard(sourceId);
String setCode = source != null ? source.getExpansionSetCode() : null; String setCode = source != null ? source.getExpansionSetCode() : null;
GameEvent event = GameEvent.getEvent(EventType.CREATE_TOKEN, null, sourceId, controllerId, amount); GameEvent event = GameEvent.getEvent(EventType.CREATE_TOKEN, null, sourceId, controllerId, amount);
if (!game.replaceEvent(event)) { if (!game.replaceEvent(event)) {
amount = event.getAmount(); amount = event.getAmount();
for (int i = 0; i < amount; i++) { for (int i = 0; i < amount; i++) {
PermanentToken permanent = new PermanentToken(this, controllerId, setCode, game); PermanentToken newToken = new PermanentToken(this, controllerId, setCode, game);
game.getState().addCard(permanent); game.getState().addCard(newToken);
game.addPermanent(permanent); game.addPermanent(newToken);
this.lastAddedTokenId = permanent.getId(); if (tapped) {
newToken.setTapped(true);
}
this.lastAddedTokenId = newToken.getId();
game.setScopeRelevant(true); game.setScopeRelevant(true);
game.applyEffects(); game.applyEffects();
permanent.entersBattlefield(sourceId, game, Zone.OUTSIDE, true); newToken.entersBattlefield(sourceId, game, Zone.OUTSIDE, true);
game.setScopeRelevant(false); game.setScopeRelevant(false);
game.applyEffects(); 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; return true;
} }