From efe55aff7642c5110321f6307e49b46bcf039624 Mon Sep 17 00:00:00 2001 From: "maurer.it" Date: Sun, 26 Dec 2010 14:00:27 -0500 Subject: [PATCH] Modifications to LandfallAbility: Bloodghast's landfall comes only when he's in the yard, added constructor for such a case where the zone may not be battlefield. Modifications to Condition: Javadoc'ed the apply method. Renamed ConditionalEffect to be ConditionalContinousEffect --- .../abilities/common/LandfallAbility.java | 4 + .../mage/abilities/condition/Condition.java | 7 ++ .../abilities/condition/common/Controls.java | 107 ++++++++++++++++++ ...t.java => ConditionalContinousEffect.java} | 10 +- .../decorator/ConditionalOneShotEffect.java | 75 ++++++++++++ 5 files changed, 198 insertions(+), 5 deletions(-) create mode 100644 Mage/src/mage/abilities/condition/common/Controls.java rename Mage/src/mage/abilities/decorator/{ConditionalEffect.java => ConditionalContinousEffect.java} (74%) create mode 100644 Mage/src/mage/abilities/decorator/ConditionalOneShotEffect.java diff --git a/Mage/src/mage/abilities/common/LandfallAbility.java b/Mage/src/mage/abilities/common/LandfallAbility.java index e2fed4ba072..29687987411 100644 --- a/Mage/src/mage/abilities/common/LandfallAbility.java +++ b/Mage/src/mage/abilities/common/LandfallAbility.java @@ -48,6 +48,10 @@ public class LandfallAbility extends TriggeredAbilityImpl { super(Zone.BATTLEFIELD, effect, optional); } + public LandfallAbility ( Zone zone, Effect effect, Boolean optional ) { + super(zone, effect, optional); + } + public LandfallAbility(final LandfallAbility ability) { super(ability); } diff --git a/Mage/src/mage/abilities/condition/Condition.java b/Mage/src/mage/abilities/condition/Condition.java index 67a321ada3d..d9d43341f49 100644 --- a/Mage/src/mage/abilities/condition/Condition.java +++ b/Mage/src/mage/abilities/condition/Condition.java @@ -11,5 +11,12 @@ import java.io.Serializable; * @author nantuko */ public interface Condition extends Serializable { + /** + * Checks the game to see if this condition applies for the given ability. + * + * @param game + * @param source + * @return + */ boolean apply(Game game, Ability source); } diff --git a/Mage/src/mage/abilities/condition/common/Controls.java b/Mage/src/mage/abilities/condition/common/Controls.java new file mode 100644 index 00000000000..b6c81b13927 --- /dev/null +++ b/Mage/src/mage/abilities/condition/common/Controls.java @@ -0,0 +1,107 @@ +/* + * 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.filter.FilterPermanent; +import mage.game.Game; + +/** + * Battlefield checking condition. This condition can decorate other conditions + * as well as be used standalone. + * + * @see #Controls(mage.filter.Filter) + * @see #Controls(mage.filter.Filter, mage.abilities.condition.Condition) + * + * @author matthew.maurer + */ +public class Controls implements Condition { + + public static enum CountType { MORE_THAN, FEWER_THAN, EQUAL_TO }; + private FilterPermanent filter; + private Condition condition; + private CountType type; + private int count; + + /** + * Applies a filter, a {@link CountType}, and count to permanents on the + * battlefield when checking the condition during the + * {@link #apply(mage.game.Game, mage.abilities.Ability) apply} method invocation. + * + * @param filter + */ + public Controls ( FilterPermanent filter, CountType type, int count ) { + this.filter = filter; + this.type = type; + this.count = count; + } + + /** + * Applies a filter, a {@link CountType}, and count to permanents on the + * battlefield and calls the decorated condition to see if it + * {@link #apply(mage.game.Game, mage.abilities.Ability) applies} + * as well. This will force both conditions to apply for this to be true. + * + * @param filter + * @param conditionToDecorate + */ + public Controls ( FilterPermanent filter, CountType type, int count, Condition conditionToDecorate ) { + this(filter, type, count); + this.condition = conditionToDecorate; + } + + /* + * {@inheritDoc} + */ + @Override + public boolean apply(Game game, Ability source) { + boolean conditionApplies = false; + + switch ( this.type ) { + case FEWER_THAN: + conditionApplies = game.getBattlefield().countAll(filter, source.getControllerId()) > this.count; + break; + case MORE_THAN: + conditionApplies = game.getBattlefield().countAll(filter, source.getControllerId()) < this.count; + break; + case EQUAL_TO: + conditionApplies = game.getBattlefield().countAll(filter, source.getControllerId()) == this.count; + break; + } + + //If a decorated condition exists, check it as well and apply them together. + if ( this.condition != null ) { + conditionApplies = conditionApplies && this.condition.apply(game, source); + } + + return conditionApplies; + } + +} diff --git a/Mage/src/mage/abilities/decorator/ConditionalEffect.java b/Mage/src/mage/abilities/decorator/ConditionalContinousEffect.java similarity index 74% rename from Mage/src/mage/abilities/decorator/ConditionalEffect.java rename to Mage/src/mage/abilities/decorator/ConditionalContinousEffect.java index 3ec736493ec..1704196061e 100644 --- a/Mage/src/mage/abilities/decorator/ConditionalEffect.java +++ b/Mage/src/mage/abilities/decorator/ConditionalContinousEffect.java @@ -8,17 +8,17 @@ import mage.abilities.effects.ContinuousEffectImpl; import mage.game.Game; /** - * Adds condition to effect. Acts as decorator. + * Adds condition to {@link ContinuousEffect}. Acts as decorator. * * @author nantuko */ -public class ConditionalEffect extends ContinuousEffectImpl { +public class ConditionalContinousEffect extends ContinuousEffectImpl { protected ContinuousEffect effect; protected Condition condition; protected String text; - public ConditionalEffect(ContinuousEffect effect, Condition condition, String text) { + public ConditionalContinousEffect(ContinuousEffect effect, Condition condition, String text) { super(effect.getDuration(), effect.getLayer(), effect.getSublayer(), effect.getOutcome()); this.effect = effect; this.condition = condition; @@ -47,8 +47,8 @@ public class ConditionalEffect extends ContinuousEffectImpl { } @Override - public ConditionalEffect copy() { - return new ConditionalEffect(effect, condition, text); + public ConditionalContinousEffect copy() { + return new ConditionalContinousEffect(effect, condition, text); } @Override diff --git a/Mage/src/mage/abilities/decorator/ConditionalOneShotEffect.java b/Mage/src/mage/abilities/decorator/ConditionalOneShotEffect.java new file mode 100644 index 00000000000..180dc9c17fe --- /dev/null +++ b/Mage/src/mage/abilities/decorator/ConditionalOneShotEffect.java @@ -0,0 +1,75 @@ +/* + * 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.decorator; + +import mage.abilities.Ability; +import mage.abilities.condition.Condition; +import mage.abilities.effects.OneShotEffect; +import mage.game.Game; + +/** + * Adds condition to {@link OneShotEffect}. Acts as decorator. + * + * @author maurer.it_at_gmail.com + */ +public class ConditionalOneShotEffect extends OneShotEffect { + + private OneShotEffect effect; + private Condition condition; + private String text; + + public ConditionalOneShotEffect ( OneShotEffect effect, Condition condition, String text ) { + super(effect.getOutcome()); + this.effect = effect; + this.condition = condition; + this.text = text; + } + + public ConditionalOneShotEffect ( ConditionalOneShotEffect effect ) { + this(effect, effect.condition, effect.text); + } + + @Override + public boolean apply ( Game game, Ability source ) { + if ( condition.apply(game, source) ) { + return effect.apply(game, source); + } + return false; + } + + @Override + public ConditionalOneShotEffect copy ( ) { + return new ConditionalOneShotEffect ( this ); + } + + @Override + public String getText(Ability source) { + return this.text; + } +}