From 0d382d3875f65cebda842245b22a0f574d9bee4f Mon Sep 17 00:00:00 2001 From: dilnu Date: Mon, 3 Feb 2020 21:57:10 -0500 Subject: [PATCH] Move the Token field added from GameEvent to a subclass. --- .../src/mage/cards/d/DivineVisitation.java | 3 ++- .../src/mage/cards/g/GatherSpecimens.java | 3 ++- .../mage/game/events/CreateTokenEvent.java | 23 +++++++++++++++++++ .../main/java/mage/game/events/GameEvent.java | 17 +++----------- .../mage/game/permanent/token/TokenImpl.java | 5 ++-- 5 files changed, 33 insertions(+), 18 deletions(-) create mode 100644 Mage/src/main/java/mage/game/events/CreateTokenEvent.java diff --git a/Mage.Sets/src/mage/cards/d/DivineVisitation.java b/Mage.Sets/src/mage/cards/d/DivineVisitation.java index 6476f60c2d..a503985c70 100644 --- a/Mage.Sets/src/mage/cards/d/DivineVisitation.java +++ b/Mage.Sets/src/mage/cards/d/DivineVisitation.java @@ -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; } diff --git a/Mage.Sets/src/mage/cards/g/GatherSpecimens.java b/Mage.Sets/src/mage/cards/g/GatherSpecimens.java index b257d242c7..241e028bce 100644 --- a/Mage.Sets/src/mage/cards/g/GatherSpecimens.java +++ b/Mage.Sets/src/mage/cards/g/GatherSpecimens.java @@ -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); } diff --git a/Mage/src/main/java/mage/game/events/CreateTokenEvent.java b/Mage/src/main/java/mage/game/events/CreateTokenEvent.java new file mode 100644 index 0000000000..1e5022a3ef --- /dev/null +++ b/Mage/src/main/java/mage/game/events/CreateTokenEvent.java @@ -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; + } +} diff --git a/Mage/src/main/java/mage/game/events/GameEvent.java b/Mage/src/main/java/mage/game/events/GameEvent.java index c79e326a75..fb854bcdf1 100644 --- a/Mage/src/main/java/mage/game/events/GameEvent.java +++ b/Mage/src/main/java/mage/game/events/GameEvent.java @@ -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; diff --git a/Mage/src/main/java/mage/game/permanent/token/TokenImpl.java b/Mage/src/main/java/mage/game/permanent/token/TokenImpl.java index 41008895f4..38c814c2b6 100644 --- a/Mage/src/main/java/mage/game/permanent/token/TokenImpl.java +++ b/Mage/src/main/java/mage/game/permanent/token/TokenImpl.java @@ -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();