Merge pull request #5351 from magefree/plane-and-emblem-implements-controllable

Refactor: make plane and emblem implement Controllable
This commit is contained in:
Oleg Agafonov 2018-11-04 23:38:54 +04:00 committed by GitHub
commit 08e88b8a65
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
8 changed files with 13 additions and 11 deletions

View file

@ -135,7 +135,7 @@ class CelestialDawnToWhiteEffect extends ContinuousEffectImpl {
// Command // Command
for (CommandObject commandObject : game.getState().getCommand()) { for (CommandObject commandObject : game.getState().getCommand()) {
if (commandObject instanceof Commander) { if (commandObject instanceof Commander) {
if (commandObject.getControllerId().equals(controller.getId())) { if (commandObject.isControlledBy(controller.getId())) {
setColor(commandObject.getColor(game), game); setColor(commandObject.getColor(game), game);
} }
} }

View file

@ -88,7 +88,7 @@ class CoverOfWinterEffect extends PreventionEffectImpl {
if (event.getType() == GameEvent.EventType.DAMAGE_CREATURE) { if (event.getType() == GameEvent.EventType.DAMAGE_CREATURE) {
Permanent permanent = game.getPermanent(event.getTargetId()); 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); return super.applies(event, source, game);
} }
} }

View file

@ -94,11 +94,11 @@ class EmissaryOfGrudgesEffect extends OneShotEffect {
Mode mode = stackObject.getStackAbility().getModes().get(modeId); Mode mode = stackObject.getStackAbility().getModes().get(modeId);
for (Target target : mode.getTargets()) { for (Target target : mode.getTargets()) {
for (UUID targetId : target.getTargets()) { for (UUID targetId : target.getTargets()) {
if (source.getControllerId().equals(targetId)) { if (source.isControlledBy(targetId)) {
targetsYouOrAPermanentYouControl = true; targetsYouOrAPermanentYouControl = true;
} }
Permanent permanent = game.getPermanent(targetId); Permanent permanent = game.getPermanent(targetId);
if (permanent != null && source.getControllerId().equals(permanent.getControllerId())) { if (permanent != null && source.isControlledBy(permanent.getControllerId())) {
targetsYouOrAPermanentYouControl = true; targetsYouOrAPermanentYouControl = true;
} }
} }

View file

@ -100,7 +100,7 @@ class SavageSummoningAsThoughEffect extends AsThoughEffectImpl {
MageObject mageObject = game.getBaseObject(objectId); MageObject mageObject = game.getBaseObject(objectId);
if (mageObject instanceof Commander) { if (mageObject instanceof Commander) {
Commander commander = (Commander) mageObject; Commander commander = (Commander) mageObject;
if (commander.isCreature() && commander.getControllerId().equals(source.getControllerId())) { if (commander.isCreature() && commander.isControlledBy(source.getControllerId())) {
return true; return true;
} }
} else if (mageObject instanceof Card) { } else if (mageObject instanceof Card) {

View file

@ -219,9 +219,9 @@ public abstract class ActivatedAbilityImpl extends AbilityImpl implements Activa
} else { } else {
MageObject mageObject = game.getObject(this.sourceId); MageObject mageObject = game.getObject(this.sourceId);
if (mageObject instanceof Emblem) { if (mageObject instanceof Emblem) {
return ((Emblem) mageObject).getControllerId().equals(playerId); return ((Emblem) mageObject).isControlledBy(playerId);
} else if (mageObject instanceof Plane) { } 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) { } else if (game.getState().getZone(this.sourceId) != Zone.BATTLEFIELD) {
return ((Card) mageObject).isOwnedBy(playerId); return ((Card) mageObject).isOwnedBy(playerId);
} }

View file

@ -12,6 +12,9 @@ public interface Controllable {
UUID getId(); UUID getId();
default boolean isControlledBy(UUID controllerID){ default boolean isControlledBy(UUID controllerID){
if(getControllerId() == null){
return false;
}
return getControllerId().equals(controllerID); return getControllerId().equals(controllerID);
} }
} }

View file

@ -2600,7 +2600,7 @@ public abstract class GameImpl implements Game, Serializable {
boolean addPlaneAgain = false; boolean addPlaneAgain = false;
for (Iterator<CommandObject> it = this.getState().getCommand().iterator(); it.hasNext();) { for (Iterator<CommandObject> it = this.getState().getCommand().iterator(); it.hasNext();) {
CommandObject obj = it.next(); CommandObject obj = it.next();
if (obj.getControllerId().equals(playerId)) { if (obj.isControlledBy(playerId)) {
if (obj instanceof Emblem) { if (obj instanceof Emblem) {
((Emblem) obj).discardEffects();// This may not be the best fix but it works ((Emblem) obj).discardEffects();// This may not be the best fix but it works
} }

View file

@ -3,17 +3,16 @@ package mage.game.command;
import java.util.UUID; import java.util.UUID;
import mage.MageObject; import mage.MageObject;
import mage.game.Controllable;
/** /**
* *
* @author Viserion, nantuko * @author Viserion, nantuko
*/ */
public interface CommandObject extends MageObject { public interface CommandObject extends MageObject, Controllable {
UUID getSourceId(); UUID getSourceId();
UUID getControllerId();
void assignNewId(); void assignNewId();
MageObject getSourceObject(); MageObject getSourceObject();