From fe3f6fb6c819bb33cff00ed57136956488d2a867 Mon Sep 17 00:00:00 2001 From: Ingmar Goudt Date: Sun, 30 Sep 2018 12:48:03 +0200 Subject: [PATCH] make plane and emblem implement Controllable to give access to the isControlledBy method --- Mage.Sets/src/mage/cards/c/CelestialDawn.java | 2 +- Mage.Sets/src/mage/cards/c/CoverOfWinter.java | 2 +- Mage.Sets/src/mage/cards/e/EmissaryOfGrudges.java | 4 ++-- Mage.Sets/src/mage/cards/s/SavageSummoning.java | 2 +- Mage/src/main/java/mage/abilities/ActivatedAbilityImpl.java | 4 ++-- Mage/src/main/java/mage/game/Controllable.java | 3 +++ Mage/src/main/java/mage/game/GameImpl.java | 2 +- Mage/src/main/java/mage/game/command/CommandObject.java | 5 ++--- 8 files changed, 13 insertions(+), 11 deletions(-) diff --git a/Mage.Sets/src/mage/cards/c/CelestialDawn.java b/Mage.Sets/src/mage/cards/c/CelestialDawn.java index 787eaf39cc..babf9c8d24 100644 --- a/Mage.Sets/src/mage/cards/c/CelestialDawn.java +++ b/Mage.Sets/src/mage/cards/c/CelestialDawn.java @@ -135,7 +135,7 @@ class CelestialDawnToWhiteEffect extends ContinuousEffectImpl { // Command for (CommandObject commandObject : game.getState().getCommand()) { if (commandObject instanceof Commander) { - if (commandObject.getControllerId().equals(controller.getId())) { + if (commandObject.isControlledBy(controller.getId())) { setColor(commandObject.getColor(game), game); } } diff --git a/Mage.Sets/src/mage/cards/c/CoverOfWinter.java b/Mage.Sets/src/mage/cards/c/CoverOfWinter.java index 5497f041bb..7d9fdfa426 100644 --- a/Mage.Sets/src/mage/cards/c/CoverOfWinter.java +++ b/Mage.Sets/src/mage/cards/c/CoverOfWinter.java @@ -88,7 +88,7 @@ class CoverOfWinterEffect extends PreventionEffectImpl { if (event.getType() == GameEvent.EventType.DAMAGE_CREATURE) { Permanent permanent = game.getPermanent(event.getTargetId()); - if (permanent != null && permanent.getControllerId().equals(source.getControllerId())) { + if (permanent != null && permanent.isControlledBy(source.getControllerId())) { return super.applies(event, source, game); } } diff --git a/Mage.Sets/src/mage/cards/e/EmissaryOfGrudges.java b/Mage.Sets/src/mage/cards/e/EmissaryOfGrudges.java index 9bd4c2fa1f..0f1f1141c2 100644 --- a/Mage.Sets/src/mage/cards/e/EmissaryOfGrudges.java +++ b/Mage.Sets/src/mage/cards/e/EmissaryOfGrudges.java @@ -94,11 +94,11 @@ class EmissaryOfGrudgesEffect extends OneShotEffect { Mode mode = stackObject.getStackAbility().getModes().get(modeId); for (Target target : mode.getTargets()) { for (UUID targetId : target.getTargets()) { - if (source.getControllerId().equals(targetId)) { + if (source.isControlledBy(targetId)) { targetsYouOrAPermanentYouControl = true; } Permanent permanent = game.getPermanent(targetId); - if (permanent != null && source.getControllerId().equals(permanent.getControllerId())) { + if (permanent != null && source.isControlledBy(permanent.getControllerId())) { targetsYouOrAPermanentYouControl = true; } } diff --git a/Mage.Sets/src/mage/cards/s/SavageSummoning.java b/Mage.Sets/src/mage/cards/s/SavageSummoning.java index 2d19dea4fb..df81be34d6 100644 --- a/Mage.Sets/src/mage/cards/s/SavageSummoning.java +++ b/Mage.Sets/src/mage/cards/s/SavageSummoning.java @@ -100,7 +100,7 @@ class SavageSummoningAsThoughEffect extends AsThoughEffectImpl { MageObject mageObject = game.getBaseObject(objectId); if (mageObject instanceof Commander) { Commander commander = (Commander) mageObject; - if (commander.isCreature() && commander.getControllerId().equals(source.getControllerId())) { + if (commander.isCreature() && commander.isControlledBy(source.getControllerId())) { return true; } } else if (mageObject instanceof Card) { diff --git a/Mage/src/main/java/mage/abilities/ActivatedAbilityImpl.java b/Mage/src/main/java/mage/abilities/ActivatedAbilityImpl.java index 6b48461d8f..21fac77d7a 100644 --- a/Mage/src/main/java/mage/abilities/ActivatedAbilityImpl.java +++ b/Mage/src/main/java/mage/abilities/ActivatedAbilityImpl.java @@ -219,9 +219,9 @@ public abstract class ActivatedAbilityImpl extends AbilityImpl implements Activa } else { MageObject mageObject = game.getObject(this.sourceId); if (mageObject instanceof Emblem) { - return ((Emblem) mageObject).getControllerId().equals(playerId); + return ((Emblem) mageObject).isControlledBy(playerId); } else if (mageObject instanceof Plane) { - return ((Plane) mageObject).getControllerId().equals(playerId); + return ((Plane) mageObject).isControlledBy(playerId); } else if (game.getState().getZone(this.sourceId) != Zone.BATTLEFIELD) { return ((Card) mageObject).isOwnedBy(playerId); } diff --git a/Mage/src/main/java/mage/game/Controllable.java b/Mage/src/main/java/mage/game/Controllable.java index 025b8f3720..ac7507e508 100644 --- a/Mage/src/main/java/mage/game/Controllable.java +++ b/Mage/src/main/java/mage/game/Controllable.java @@ -12,6 +12,9 @@ public interface Controllable { UUID getId(); default boolean isControlledBy(UUID controllerID){ + if(getControllerId() == null){ + return false; + } return getControllerId().equals(controllerID); } } diff --git a/Mage/src/main/java/mage/game/GameImpl.java b/Mage/src/main/java/mage/game/GameImpl.java index e745c75e12..8f5234fb00 100644 --- a/Mage/src/main/java/mage/game/GameImpl.java +++ b/Mage/src/main/java/mage/game/GameImpl.java @@ -2594,7 +2594,7 @@ public abstract class GameImpl implements Game, Serializable { boolean addPlaneAgain = false; for (Iterator it = this.getState().getCommand().iterator(); it.hasNext();) { CommandObject obj = it.next(); - if (obj.getControllerId().equals(playerId)) { + if (obj.isControlledBy(playerId)) { if (obj instanceof Emblem) { ((Emblem) obj).discardEffects();// This may not be the best fix but it works } diff --git a/Mage/src/main/java/mage/game/command/CommandObject.java b/Mage/src/main/java/mage/game/command/CommandObject.java index b537d823ea..2a376c6b3f 100644 --- a/Mage/src/main/java/mage/game/command/CommandObject.java +++ b/Mage/src/main/java/mage/game/command/CommandObject.java @@ -3,17 +3,16 @@ package mage.game.command; import java.util.UUID; import mage.MageObject; +import mage.game.Controllable; /** * * @author Viserion, nantuko */ -public interface CommandObject extends MageObject { +public interface CommandObject extends MageObject, Controllable { UUID getSourceId(); - UUID getControllerId(); - void assignNewId(); MageObject getSourceObject();