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.game.Game;
import mage.game.permanent.token.Token;
import mage.util.CardUtil;
/**
*
@ -44,6 +45,8 @@ public class CreateTokenEffect extends OneShotEffect<CreateTokenEffect> {
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<CreateTokenEffect> {
}
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<CreateTokenEffect> {
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<CreateTokenEffect> {
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")) {

View file

@ -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<Token> {
@ -107,22 +107,32 @@ public class Token extends MageObjectImpl<Token> {
}
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;
}