Fix the Divine Visitation replacement effect.

This also gives the CREATE_TOKEN game events access to the Token being created and updates the GatherSpecimens replacement effect to use that access.
This commit is contained in:
dilnu 2020-02-01 15:14:15 -05:00
parent b708494647
commit cc9629ed51
4 changed files with 81 additions and 60 deletions

View file

@ -27,7 +27,6 @@ public final class DivineVisitation extends CardImpl {
public DivineVisitation(UUID ownerId, CardSetInfo setInfo) { public DivineVisitation(UUID ownerId, CardSetInfo setInfo) {
super(ownerId, setInfo, new CardType[]{CardType.ENCHANTMENT}, "{3}{W}{W}"); super(ownerId, setInfo, new CardType[]{CardType.ENCHANTMENT}, "{3}{W}{W}");
// TODO: This implementation is not entirely correct, see https://twitter.com/EliShffrn/status/1042145606582591490
// If one or more creature tokens would be created under your control, that many 4/4 white Angel creature tokens with flying and vigilance are created instead. // If one or more creature tokens would be created under your control, that many 4/4 white Angel creature tokens with flying and vigilance are created instead.
this.addAbility(new SimpleStaticAbility( this.addAbility(new SimpleStaticAbility(
Zone.BATTLEFIELD, new DivineVisitationEffect() Zone.BATTLEFIELD, new DivineVisitationEffect()
@ -59,21 +58,17 @@ class DivineVisitationEffect extends ReplacementEffectImpl {
@Override @Override
public boolean checksEventType(GameEvent event, Game game) { public boolean checksEventType(GameEvent event, Game game) {
return event.getType() == GameEvent.EventType.ENTERS_THE_BATTLEFIELD; return event.getType() == GameEvent.EventType.CREATE_TOKEN;
} }
@Override @Override
public boolean applies(GameEvent event, Ability source, Game game) { public boolean applies(GameEvent event, Ability source, Game game) {
Permanent perm = ((EntersTheBattlefieldEvent) event).getTarget(); return event.getPlayerId().equals(source.getControllerId());
return perm != null
&& perm.isCreature()
&& perm instanceof PermanentToken
&& perm.isControlledBy(source.getControllerId());
} }
@Override @Override
public boolean replaceEvent(GameEvent event, Ability source, Game game) { public boolean replaceEvent(GameEvent event, Ability source, Game game) {
game.addEffect(new CopyEffect(Duration.Custom, new AngelVigilanceToken(), event.getTargetId()), source); event.setToken(new AngelVigilanceToken());
return false; return false;
} }

View file

@ -76,7 +76,7 @@ class GatherSpecimensReplacementEffect extends ReplacementEffectImpl {
} }
} }
} }
if (event.getType() == GameEvent.EventType.CREATE_TOKEN && event.getFlag()) { // flag indicates if it's a creature token if (event.getType() == GameEvent.EventType.CREATE_TOKEN && event.getToken().isCreature()) {
Player controller = game.getPlayer(source.getControllerId()); Player controller = game.getPlayer(source.getControllerId());
return controller != null && controller.hasOpponent(event.getPlayerId(), game); return controller != null && controller.hasOpponent(event.getPlayerId(), game);
} }

View file

@ -2,6 +2,7 @@ package mage.game.events;
import mage.MageObjectReference; import mage.MageObjectReference;
import mage.constants.Zone; import mage.constants.Zone;
import mage.game.permanent.token.Token;
import java.io.Serializable; import java.io.Serializable;
import java.util.ArrayList; import java.util.ArrayList;
@ -13,6 +14,7 @@ import java.util.UUID;
*/ */
public class GameEvent implements Serializable { public class GameEvent implements Serializable {
protected Token token;
protected EventType type; protected EventType type;
protected UUID targetId; protected UUID targetId;
protected UUID sourceId; protected UUID sourceId;
@ -339,13 +341,17 @@ public class GameEvent implements Serializable {
} }
public GameEvent(EventType type, UUID targetId, UUID sourceId, UUID playerId, MageObjectReference reference) { public GameEvent(EventType type, UUID targetId, UUID sourceId, UUID playerId, MageObjectReference reference) {
this(type, null, targetId, sourceId, playerId, 0, false, reference); this(type, null, targetId, sourceId, playerId, 0, false, reference, null);
} }
public GameEvent(EventType type, UUID targetId, UUID sourceId, UUID playerId, int amount, boolean flag) { public GameEvent(EventType type, UUID targetId, UUID sourceId, UUID playerId, int amount, boolean flag) {
this(type, null, targetId, sourceId, playerId, amount, flag); this(type, null, targetId, sourceId, playerId, amount, flag);
} }
public GameEvent(EventType type, UUID sourceId, UUID playerId, int amount, Token token) {
this(type, null, null, sourceId, playerId, amount, false, null, token);
}
public GameEvent(UUID customEventType, UUID targetId, UUID sourceId, UUID playerId) { public GameEvent(UUID customEventType, UUID targetId, UUID sourceId, UUID playerId) {
this(EventType.CUSTOM_EVENT, customEventType, targetId, sourceId, playerId, 0, false); this(EventType.CUSTOM_EVENT, customEventType, targetId, sourceId, playerId, 0, false);
} }
@ -398,11 +404,11 @@ public class GameEvent implements Serializable {
private GameEvent(EventType type, UUID customEventType, private GameEvent(EventType type, UUID customEventType,
UUID targetId, UUID sourceId, UUID playerId, int amount, boolean flag) { UUID targetId, UUID sourceId, UUID playerId, int amount, boolean flag) {
this(type, customEventType, targetId, sourceId, playerId, amount, flag, null); this(type, customEventType, targetId, sourceId, playerId, amount, flag, null, null);
} }
private GameEvent(EventType type, UUID customEventType, private GameEvent(EventType type, UUID customEventType,
UUID targetId, UUID sourceId, UUID playerId, int amount, boolean flag, MageObjectReference reference) { UUID targetId, UUID sourceId, UUID playerId, int amount, boolean flag, MageObjectReference reference, Token token) {
this.type = type; this.type = type;
this.customEventType = customEventType; this.customEventType = customEventType;
this.targetId = targetId; this.targetId = targetId;
@ -411,6 +417,7 @@ public class GameEvent implements Serializable {
this.playerId = playerId; this.playerId = playerId;
this.flag = flag; this.flag = flag;
this.reference = reference; this.reference = reference;
this.token = token;
} }
public EventType getType() { public EventType getType() {
@ -445,6 +452,10 @@ public class GameEvent implements Serializable {
this.amount = amount; this.amount = amount;
} }
public Token getToken() { return token; }
public void setToken(Token token) { this.token = token; }
public void setAmountForCounters(int amount, boolean isEffect) { public void setAmountForCounters(int amount, boolean isEffect) {
this.amount = amount; this.amount = amount;

View file

@ -2,6 +2,7 @@ package mage.game.permanent.token;
import mage.MageObject; import mage.MageObject;
import mage.MageObjectImpl; import mage.MageObjectImpl;
import mage.MageObjectReference;
import mage.abilities.Ability; import mage.abilities.Ability;
import mage.cards.Card; import mage.cards.Card;
import mage.constants.Zone; import mage.constants.Zone;
@ -31,7 +32,7 @@ public abstract class TokenImpl extends MageObjectImpl implements Token {
private boolean expansionSetCodeChecked; private boolean expansionSetCodeChecked;
private Card copySourceCard; // the card the Token is a copy from private Card copySourceCard; // the card the Token is a copy from
// list of set codes tokene images are available for // list of set codes token images are available for
protected List<String> availableImageSetCodes = new ArrayList<>(); protected List<String> availableImageSetCodes = new ArrayList<>();
public enum Type { public enum Type {
@ -131,14 +132,7 @@ public abstract class TokenImpl extends MageObjectImpl implements Token {
return putOntoBattlefield(amount, game, sourceId, controllerId, tapped, attacking, null); return putOntoBattlefield(amount, game, sourceId, controllerId, tapped, attacking, null);
} }
@Override private String getSetCode(Game game, UUID sourceId) {
public boolean putOntoBattlefield(int amount, Game game, UUID sourceId, UUID controllerId, boolean tapped, boolean attacking, UUID attackedPlayer) {
Player controller = game.getPlayer(controllerId);
if (controller == null) {
return false;
}
lastAddedTokenIds.clear();
// moved here from CreateTokenEffect because not all cards that create tokens use CreateTokenEffect // moved here from CreateTokenEffect because not all cards that create tokens use CreateTokenEffect
// they use putOntoBattlefield directly // they use putOntoBattlefield directly
// TODO: Check this setCode handling because it makes no sense if token put into play with e.g. "Feldon of the third Path" // TODO: Check this setCode handling because it makes no sense if token put into play with e.g. "Feldon of the third Path"
@ -156,19 +150,41 @@ public abstract class TokenImpl extends MageObjectImpl implements Token {
} }
} }
} }
if (!expansionSetCodeChecked) { if (!expansionSetCodeChecked) {
expansionSetCodeChecked = this.updateExpansionSetCode(setCode); expansionSetCodeChecked = this.updateExpansionSetCode(setCode);
} }
return setCode;
}
GameEvent event = new GameEvent(EventType.CREATE_TOKEN, null, sourceId, controllerId, amount, this.isCreature()); @Override
public boolean putOntoBattlefield(int amount, Game game, UUID sourceId, UUID controllerId, boolean tapped, boolean attacking, UUID attackedPlayer) {
Player controller = game.getPlayer(controllerId);
if (controller == null) {
return false;
}
lastAddedTokenIds.clear();
GameEvent event = new GameEvent(EventType.CREATE_TOKEN, sourceId, controllerId, amount, this);
if (!game.replaceEvent(event)) { if (!game.replaceEvent(event)) {
amount = event.getAmount(); putOntoBattlefieldHelper(event, game, tapped, attacking, attackedPlayer);
return true;
}
return false;
}
private static void putOntoBattlefieldHelper(GameEvent event, Game game, boolean tapped, boolean attacking, UUID attackedPlayer) {
Player controller = game.getPlayer(event.getPlayerId());
Token token = event.getToken();
int amount = event.getAmount();
List<Permanent> permanents = new ArrayList<>(); List<Permanent> permanents = new ArrayList<>();
List<Permanent> permanentsEntered = new ArrayList<>(); List<Permanent> permanentsEntered = new ArrayList<>();
String setCode = token instanceof TokenImpl ? ((TokenImpl) token).getSetCode(game, event.getSourceId()) : null;
for (int i = 0; i < amount; i++) { for (int i = 0; i < amount; i++) {
PermanentToken newToken = new PermanentToken(this, event.getPlayerId(), setCode, game); // use event.getPlayerId() because it can be replaced by replacement effect PermanentToken newToken = new PermanentToken(token, event.getPlayerId(), setCode, game); // use event.getPlayerId() because it can be replaced by replacement effect
game.getState().addCard(newToken); game.getState().addCard(newToken);
permanents.add(newToken); permanents.add(newToken);
game.getPermanentsEntering().put(newToken.getId(), newToken); game.getPermanentsEntering().put(newToken.getId(), newToken);
@ -176,7 +192,7 @@ public abstract class TokenImpl extends MageObjectImpl implements Token {
} }
game.setScopeRelevant(true); game.setScopeRelevant(true);
for (Permanent permanent : permanents) { for (Permanent permanent : permanents) {
if (permanent.entersBattlefield(sourceId, game, Zone.OUTSIDE, true)) { if (permanent.entersBattlefield(event.getSourceId(), game, Zone.OUTSIDE, true)) {
permanentsEntered.add(permanent); permanentsEntered.add(permanent);
} else { } else {
game.getPermanentsEntering().remove(permanent.getId()); game.getPermanentsEntering().remove(permanent.getId());
@ -188,8 +204,10 @@ public abstract class TokenImpl extends MageObjectImpl implements Token {
permanent.setZone(Zone.BATTLEFIELD, game); permanent.setZone(Zone.BATTLEFIELD, game);
game.getPermanentsEntering().remove(permanent.getId()); game.getPermanentsEntering().remove(permanent.getId());
this.lastAddedTokenIds.add(permanent.getId()); if (token instanceof TokenImpl) {
this.lastAddedTokenId = permanent.getId(); ((TokenImpl) token).lastAddedTokenIds.add(permanent.getId());
((TokenImpl) token).lastAddedTokenId = permanent.getId();
}
game.addSimultaneousEvent(new ZoneChangeEvent(permanent, permanent.getControllerId(), Zone.OUTSIDE, Zone.BATTLEFIELD)); game.addSimultaneousEvent(new ZoneChangeEvent(permanent, permanent.getControllerId(), Zone.OUTSIDE, Zone.BATTLEFIELD));
if (attacking && game.getCombat() != null && game.getActivePlayerId().equals(permanent.getControllerId())) { if (attacking && game.getCombat() != null && game.getActivePlayerId().equals(permanent.getControllerId())) {
game.getCombat().addAttackingCreature(permanent.getId(), game, attackedPlayer); game.getCombat().addAttackingCreature(permanent.getId(), game, attackedPlayer);
@ -200,9 +218,6 @@ public abstract class TokenImpl extends MageObjectImpl implements Token {
} }
game.getState().applyEffects(game); // Needed to do it here without LKIReset i.e. do get SwordOfTheMeekTest running correctly. game.getState().applyEffects(game); // Needed to do it here without LKIReset i.e. do get SwordOfTheMeekTest running correctly.
return true;
}
return false;
} }
@Override @Override