Move the Token field added from GameEvent to a subclass.

This commit is contained in:
dilnu 2020-02-03 21:57:10 -05:00
parent cc9629ed51
commit 0d382d3875
5 changed files with 33 additions and 18 deletions

View file

@ -12,6 +12,7 @@ import mage.constants.Duration;
import mage.constants.Outcome;
import mage.constants.Zone;
import mage.game.Game;
import mage.game.events.CreateTokenEvent;
import mage.game.events.EntersTheBattlefieldEvent;
import mage.game.events.GameEvent;
import mage.game.permanent.Permanent;
@ -68,7 +69,7 @@ class DivineVisitationEffect extends ReplacementEffectImpl {
@Override
public boolean replaceEvent(GameEvent event, Ability source, Game game) {
event.setToken(new AngelVigilanceToken());
((CreateTokenEvent) event).setToken(new AngelVigilanceToken());
return false;
}

View file

@ -10,6 +10,7 @@ import mage.constants.Duration;
import mage.constants.Outcome;
import mage.constants.Zone;
import mage.game.Game;
import mage.game.events.CreateTokenEvent;
import mage.game.events.GameEvent;
import mage.game.events.ZoneChangeEvent;
import mage.players.Player;
@ -76,7 +77,7 @@ class GatherSpecimensReplacementEffect extends ReplacementEffectImpl {
}
}
}
if (event.getType() == GameEvent.EventType.CREATE_TOKEN && event.getToken().isCreature()) {
if (event.getType() == GameEvent.EventType.CREATE_TOKEN && ((CreateTokenEvent) event).getToken().isCreature()) {
Player controller = game.getPlayer(source.getControllerId());
return controller != null && controller.hasOpponent(event.getPlayerId(), game);
}

View file

@ -0,0 +1,23 @@
package mage.game.events;
import mage.game.Game;
import mage.game.permanent.token.Token;
import java.util.UUID;
public class CreateTokenEvent extends GameEvent {
private Token token;
public CreateTokenEvent(UUID sourceId, UUID controllerId, int amount, Token token) {
super(EventType.CREATE_TOKEN, null, sourceId, controllerId, amount, false);
this.token = token;
}
public Token getToken() {
return token;
}
public void setToken(Token token) {
this.token = token;
}
}

View file

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

View file

@ -7,6 +7,7 @@ import mage.abilities.Ability;
import mage.cards.Card;
import mage.constants.Zone;
import mage.game.Game;
import mage.game.events.CreateTokenEvent;
import mage.game.events.GameEvent;
import mage.game.events.GameEvent.EventType;
import mage.game.events.ZoneChangeEvent;
@ -165,7 +166,7 @@ public abstract class TokenImpl extends MageObjectImpl implements Token {
}
lastAddedTokenIds.clear();
GameEvent event = new GameEvent(EventType.CREATE_TOKEN, sourceId, controllerId, amount, this);
CreateTokenEvent event = new CreateTokenEvent(sourceId, controllerId, amount, this);
if (!game.replaceEvent(event)) {
putOntoBattlefieldHelper(event, game, tapped, attacking, attackedPlayer);
return true;
@ -173,7 +174,7 @@ public abstract class TokenImpl extends MageObjectImpl implements Token {
return false;
}
private static void putOntoBattlefieldHelper(GameEvent event, Game game, boolean tapped, boolean attacking, UUID attackedPlayer) {
private static void putOntoBattlefieldHelper(CreateTokenEvent event, Game game, boolean tapped, boolean attacking, UUID attackedPlayer) {
Player controller = game.getPlayer(event.getPlayerId());
Token token = event.getToken();
int amount = event.getAmount();