mirror of
https://github.com/correl/mage.git
synced 2024-12-26 03:00:11 +00:00
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
This commit is contained in:
parent
9ed6145b4b
commit
efe55aff76
5 changed files with 198 additions and 5 deletions
|
@ -48,6 +48,10 @@ public class LandfallAbility extends TriggeredAbilityImpl<LandfallAbility> {
|
||||||
super(Zone.BATTLEFIELD, effect, optional);
|
super(Zone.BATTLEFIELD, effect, optional);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public LandfallAbility ( Zone zone, Effect effect, Boolean optional ) {
|
||||||
|
super(zone, effect, optional);
|
||||||
|
}
|
||||||
|
|
||||||
public LandfallAbility(final LandfallAbility ability) {
|
public LandfallAbility(final LandfallAbility ability) {
|
||||||
super(ability);
|
super(ability);
|
||||||
}
|
}
|
||||||
|
|
|
@ -11,5 +11,12 @@ import java.io.Serializable;
|
||||||
* @author nantuko
|
* @author nantuko
|
||||||
*/
|
*/
|
||||||
public interface Condition extends Serializable {
|
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);
|
boolean apply(Game game, Ability source);
|
||||||
}
|
}
|
||||||
|
|
107
Mage/src/mage/abilities/condition/common/Controls.java
Normal file
107
Mage/src/mage/abilities/condition/common/Controls.java
Normal file
|
@ -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;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
|
@ -8,17 +8,17 @@ import mage.abilities.effects.ContinuousEffectImpl;
|
||||||
import mage.game.Game;
|
import mage.game.Game;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Adds condition to effect. Acts as decorator.
|
* Adds condition to {@link ContinuousEffect}. Acts as decorator.
|
||||||
*
|
*
|
||||||
* @author nantuko
|
* @author nantuko
|
||||||
*/
|
*/
|
||||||
public class ConditionalEffect extends ContinuousEffectImpl<ConditionalEffect> {
|
public class ConditionalContinousEffect extends ContinuousEffectImpl<ConditionalContinousEffect> {
|
||||||
|
|
||||||
protected ContinuousEffect effect;
|
protected ContinuousEffect effect;
|
||||||
protected Condition condition;
|
protected Condition condition;
|
||||||
protected String text;
|
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());
|
super(effect.getDuration(), effect.getLayer(), effect.getSublayer(), effect.getOutcome());
|
||||||
this.effect = effect;
|
this.effect = effect;
|
||||||
this.condition = condition;
|
this.condition = condition;
|
||||||
|
@ -47,8 +47,8 @@ public class ConditionalEffect extends ContinuousEffectImpl<ConditionalEffect> {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public ConditionalEffect copy() {
|
public ConditionalContinousEffect copy() {
|
||||||
return new ConditionalEffect(effect, condition, text);
|
return new ConditionalContinousEffect(effect, condition, text);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
|
@ -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<ConditionalOneShotEffect> {
|
||||||
|
|
||||||
|
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;
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in a new issue