From b7c45a70909e8d8a7ac57cdad89b90b85eaf7c5d Mon Sep 17 00:00:00 2001 From: LevelX2 Date: Thu, 21 Nov 2013 10:59:50 +0100 Subject: [PATCH] Added CompoundCondition, AttachedToTappedCondition and EquipmentAttachedCondition. --- .../condition/CompoundCondition.java | 71 +++++++++++++++++++ .../common/AttachedToCounterCondition.java | 8 +-- .../common/AttachedToTappedCondition.java | 60 ++++++++++++++++ .../common/EquipmentAttachedCondition.java | 55 ++++++++++++++ .../condition/common/EquippedCondition.java | 7 +- .../common/SourceTappedCondition.java | 4 +- .../BecomesBasicLandTargetEffect.java | 2 +- .../continious/BoostControlledEffect.java | 5 ++ Mage/src/mage/game/GameState.java | 2 +- 9 files changed, 202 insertions(+), 12 deletions(-) create mode 100644 Mage/src/mage/abilities/condition/CompoundCondition.java create mode 100644 Mage/src/mage/abilities/condition/common/AttachedToTappedCondition.java create mode 100644 Mage/src/mage/abilities/condition/common/EquipmentAttachedCondition.java diff --git a/Mage/src/mage/abilities/condition/CompoundCondition.java b/Mage/src/mage/abilities/condition/CompoundCondition.java new file mode 100644 index 00000000000..65805a10ca4 --- /dev/null +++ b/Mage/src/mage/abilities/condition/CompoundCondition.java @@ -0,0 +1,71 @@ +/* + * Copyright 2010 BetaSteward_at_googlemail.com. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without modification, are + * permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, this list of + * conditions and the following disclaimer. + * + * 2. Redistributions in binary form must reproduce the above copyright notice, this list + * of conditions and the following disclaimer in the documentation and/or other materials + * provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY BetaSteward_at_googlemail.com ``AS IS'' AND ANY EXPRESS OR IMPLIED + * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND + * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL BetaSteward_at_googlemail.com OR + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR + * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON + * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING + * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF + * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + * The views and conclusions contained in the software and documentation are those of the + * authors and should not be interpreted as representing official policies, either expressed + * or implied, of BetaSteward_at_googlemail.com. + */ + +package mage.abilities.condition; + +import java.util.ArrayList; +import java.util.Arrays; +import mage.abilities.Ability; +import mage.game.Game; + +/** + * Combines conditions to one compound conditon, all single conditons + * must be true to return true for the compound condtion. + * + * @author LevelX2 + */ +public class CompoundCondition implements Condition { + + private final ArrayList conditions = new ArrayList(); + private final String text; + + public CompoundCondition(Condition... conditions) { + this("", conditions); + } + + public CompoundCondition(String text, Condition... conditions) { + this.conditions.addAll(Arrays.asList(conditions)); + this.text = text; + } + + @Override + public boolean apply(Game game, Ability source) { + for (Condition condition: conditions) { + if (!condition.apply(game, source)) { + return false; + } + } + return true; + } + + @Override + public String toString() { + return text; + } + +} diff --git a/Mage/src/mage/abilities/condition/common/AttachedToCounterCondition.java b/Mage/src/mage/abilities/condition/common/AttachedToCounterCondition.java index 5cf47628b81..da1608f2d76 100644 --- a/Mage/src/mage/abilities/condition/common/AttachedToCounterCondition.java +++ b/Mage/src/mage/abilities/condition/common/AttachedToCounterCondition.java @@ -39,7 +39,7 @@ import mage.game.permanent.Permanent; */ public class AttachedToCounterCondition implements Condition { - private CounterType counterType; + private final CounterType counterType; private int amount = 1; private int from = -1; private int to; @@ -61,11 +61,11 @@ public class AttachedToCounterCondition implements Condition { @Override public boolean apply(Game game, Ability source) { - Permanent permanent = game.getPermanent(source.getSourceId()); - if (permanent == null || permanent.getAttachedTo() == null) { + Permanent attachment = game.getPermanent(source.getSourceId()); + if (attachment == null || attachment.getAttachedTo() == null) { return false; } - Permanent attachedTo = game.getPermanent(permanent.getAttachedTo()); + Permanent attachedTo = game.getPermanent(attachment.getAttachedTo()); if (attachedTo == null) { return false; } diff --git a/Mage/src/mage/abilities/condition/common/AttachedToTappedCondition.java b/Mage/src/mage/abilities/condition/common/AttachedToTappedCondition.java new file mode 100644 index 00000000000..ec290b9b1da --- /dev/null +++ b/Mage/src/mage/abilities/condition/common/AttachedToTappedCondition.java @@ -0,0 +1,60 @@ +/* + * Copyright 2010 BetaSteward_at_googlemail.com. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without modification, are + * permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, this list of + * conditions and the following disclaimer. + * + * 2. Redistributions in binary form must reproduce the above copyright notice, this list + * of conditions and the following disclaimer in the documentation and/or other materials + * provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY BetaSteward_at_googlemail.com ``AS IS'' AND ANY EXPRESS OR IMPLIED + * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND + * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL BetaSteward_at_googlemail.com OR + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR + * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON + * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING + * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF + * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + * The views and conclusions contained in the software and documentation are those of the + * authors and should not be interpreted as representing official policies, either expressed + * or implied, of BetaSteward_at_googlemail.com. + */ + +package mage.abilities.condition.common; + +import mage.abilities.Ability; +import mage.abilities.condition.Condition; +import mage.game.Game; +import mage.game.permanent.Permanent; + +/** + * + * @author LevelX2 + */ +public class AttachedToTappedCondition implements Condition { + + private static final AttachedToTappedCondition fInstance = new AttachedToTappedCondition(); + + public static AttachedToTappedCondition getInstance() { + return fInstance; + } + + @Override + public boolean apply(Game game, Ability source) { + Permanent attachment = game.getPermanent(source.getSourceId()); + if (attachment == null || attachment.getAttachedTo() == null) { + return false; + } + Permanent attachedTo = game.getPermanent(attachment.getAttachedTo()); + if (attachedTo == null) { + return false; + } + return attachedTo.isTapped(); + } +} diff --git a/Mage/src/mage/abilities/condition/common/EquipmentAttachedCondition.java b/Mage/src/mage/abilities/condition/common/EquipmentAttachedCondition.java new file mode 100644 index 00000000000..f67be3104ca --- /dev/null +++ b/Mage/src/mage/abilities/condition/common/EquipmentAttachedCondition.java @@ -0,0 +1,55 @@ +/* + * Copyright 2010 BetaSteward_at_googlemail.com. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without modification, are + * permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, this list of + * conditions and the following disclaimer. + * + * 2. Redistributions in binary form must reproduce the above copyright notice, this list + * of conditions and the following disclaimer in the documentation and/or other materials + * provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY BetaSteward_at_googlemail.com ``AS IS'' AND ANY EXPRESS OR IMPLIED + * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND + * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL BetaSteward_at_googlemail.com OR + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR + * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON + * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING + * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF + * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + * The views and conclusions contained in the software and documentation are those of the + * authors and should not be interpreted as representing official policies, either expressed + * or implied, of BetaSteward_at_googlemail.com. + */ + +package mage.abilities.condition.common; + +import mage.abilities.Ability; +import mage.abilities.condition.Condition; +import mage.game.Game; +import mage.game.permanent.Permanent; + +/** + * Describes condition when Equipment is attached to an object + * + * @author LevelX2 + */ +public class EquipmentAttachedCondition implements Condition { + + private static final EquipmentAttachedCondition fInstance = new EquipmentAttachedCondition(); + + public static Condition getInstance() { + return fInstance; + } + + @Override + public boolean apply(Game game, Ability source) { + Permanent attachment = game.getPermanent(source.getSourceId()); + return attachment == null || attachment.getAttachedTo() == null; + } + +} diff --git a/Mage/src/mage/abilities/condition/common/EquippedCondition.java b/Mage/src/mage/abilities/condition/common/EquippedCondition.java index e34f1f97bd8..53d25c429f7 100644 --- a/Mage/src/mage/abilities/condition/common/EquippedCondition.java +++ b/Mage/src/mage/abilities/condition/common/EquippedCondition.java @@ -27,13 +27,12 @@ */ package mage.abilities.condition.common; +import java.util.UUID; import mage.abilities.Ability; import mage.abilities.condition.Condition; import mage.game.Game; import mage.game.permanent.Permanent; -import java.util.UUID; - /** * Describes condition when creature is equipped. * @@ -41,7 +40,7 @@ import java.util.UUID; */ public class EquippedCondition implements Condition { - private static EquippedCondition fInstance = new EquippedCondition(); + private static final EquippedCondition fInstance = new EquippedCondition(); public static Condition getInstance() { return fInstance; @@ -53,7 +52,7 @@ public class EquippedCondition implements Condition { if (permanent != null) { for (UUID uuid : permanent.getAttachments()) { Permanent attached = game.getBattlefield().getPermanent(uuid); - if (attached.getSubtype().contains("Equipment")) { + if (attached != null && attached.getSubtype().contains("Equipment")) { return true; } } diff --git a/Mage/src/mage/abilities/condition/common/SourceTappedCondition.java b/Mage/src/mage/abilities/condition/common/SourceTappedCondition.java index b8b0a8522fd..2ca523da3be 100644 --- a/Mage/src/mage/abilities/condition/common/SourceTappedCondition.java +++ b/Mage/src/mage/abilities/condition/common/SourceTappedCondition.java @@ -41,9 +41,9 @@ import mage.game.permanent.Permanent; public class SourceTappedCondition implements Condition { - private static SourceTappedCondition fInstance = new SourceTappedCondition(); + private static final SourceTappedCondition fInstance = new SourceTappedCondition(); - public static Condition getInstance() { + public static SourceTappedCondition getInstance() { return fInstance; } diff --git a/Mage/src/mage/abilities/effects/common/continious/BecomesBasicLandTargetEffect.java b/Mage/src/mage/abilities/effects/common/continious/BecomesBasicLandTargetEffect.java index de7afe34400..73ac8e3ed64 100644 --- a/Mage/src/mage/abilities/effects/common/continious/BecomesBasicLandTargetEffect.java +++ b/Mage/src/mage/abilities/effects/common/continious/BecomesBasicLandTargetEffect.java @@ -70,7 +70,7 @@ public class BecomesBasicLandTargetEffect extends ContinuousEffectImpl { public Permanent getPermanent(UUID permanentId) { if (permanentId != null && battlefield.containsPermanent(permanentId)) { Permanent permanent = battlefield.getPermanent(permanentId); - setZone(permanent.getId(), Zone.BATTLEFIELD); + setZone(permanent.getId(), Zone.BATTLEFIELD); // shouldn't this be set anyway? (LevelX2) return permanent; } return null;