mirror of
https://github.com/correl/mage.git
synced 2024-12-26 03:00:11 +00:00
ConditionalTriggeredAbility.
This commit is contained in:
parent
42be4090a4
commit
c9ab3fb2fe
1 changed files with 59 additions and 0 deletions
|
@ -0,0 +1,59 @@
|
||||||
|
package mage.abilities.decorator;
|
||||||
|
|
||||||
|
import mage.Constants;
|
||||||
|
import mage.abilities.Ability;
|
||||||
|
import mage.abilities.TriggeredAbility;
|
||||||
|
import mage.abilities.TriggeredAbilityImpl;
|
||||||
|
import mage.abilities.condition.Condition;
|
||||||
|
import mage.abilities.effects.ContinuousEffect;
|
||||||
|
import mage.abilities.effects.ContinuousEffectImpl;
|
||||||
|
import mage.abilities.effects.Effect;
|
||||||
|
import mage.game.Game;
|
||||||
|
import mage.game.events.GameEvent;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Adds condition to {@link mage.abilities.effects.ContinuousEffect}. Acts as decorator.
|
||||||
|
*
|
||||||
|
* @author nantuko
|
||||||
|
*/
|
||||||
|
public class ConditionalTriggeredAbility extends TriggeredAbilityImpl<ConditionalTriggeredAbility> {
|
||||||
|
|
||||||
|
protected TriggeredAbility ability;
|
||||||
|
protected Condition condition;
|
||||||
|
protected Effect effect;
|
||||||
|
protected String text;
|
||||||
|
|
||||||
|
public ConditionalTriggeredAbility(TriggeredAbility ability, Effect effect, Condition condition, String text) {
|
||||||
|
super(ability.getZone(), effect);
|
||||||
|
this.ability = ability;
|
||||||
|
this.effect = effect;
|
||||||
|
this.condition = condition;
|
||||||
|
this.text = text;
|
||||||
|
}
|
||||||
|
|
||||||
|
public ConditionalTriggeredAbility(ConditionalTriggeredAbility triggered) {
|
||||||
|
super(triggered);
|
||||||
|
this.ability = triggered.ability;
|
||||||
|
this.condition = triggered.condition;
|
||||||
|
this.text = triggered.text;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public ConditionalTriggeredAbility copy() {
|
||||||
|
return new ConditionalTriggeredAbility(this);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean checkTrigger(GameEvent event, Game game) {
|
||||||
|
ability.setSourceId(this.getSourceId());
|
||||||
|
if (ability.checkTrigger(event, game)) {
|
||||||
|
return condition.apply(game, this);
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String getRule() {
|
||||||
|
return text;
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in a new issue