mirror of
https://github.com/magefree/mage.git
synced 2025-12-20 02:30:08 -08:00
refactor some abilities to use TriggeredAbility:: withInterveningIf
This commit is contained in:
parent
562bd9ffeb
commit
b21fe38de2
5 changed files with 26 additions and 32 deletions
|
|
@ -1,5 +1,3 @@
|
|||
|
||||
|
||||
package mage.abilities.condition.common;
|
||||
|
||||
import mage.abilities.Ability;
|
||||
|
|
@ -9,17 +7,21 @@ import mage.game.Game;
|
|||
import mage.util.CardUtil;
|
||||
|
||||
/**
|
||||
* Checks if a the spell was cast with the alternate evoke costs
|
||||
* Checks if a the spell was cast with the alternate evoke costs
|
||||
*
|
||||
* @author LevelX2
|
||||
*/
|
||||
|
||||
public enum EvokedCondition implements Condition {
|
||||
|
||||
instance;
|
||||
|
||||
@Override
|
||||
public boolean apply(Game game, Ability source) {
|
||||
return CardUtil.checkSourceCostsTagExists(game, source, EvokeAbility.getActivationKey());
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "its evoke cost was paid";
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,12 +1,10 @@
|
|||
package mage.abilities.keyword;
|
||||
|
||||
import mage.abilities.Ability;
|
||||
import mage.abilities.common.EntersBattlefieldTriggeredAbility;
|
||||
import mage.abilities.condition.common.EvokedCondition;
|
||||
import mage.abilities.costs.AlternativeSourceCostsImpl;
|
||||
import mage.abilities.costs.Cost;
|
||||
import mage.abilities.costs.mana.ManaCostsImpl;
|
||||
import mage.abilities.decorator.ConditionalInterveningIfTriggeredAbility;
|
||||
import mage.abilities.effects.common.SacrificeSourceEffect;
|
||||
|
||||
/**
|
||||
|
|
@ -24,11 +22,9 @@ public class EvokeAbility extends AlternativeSourceCostsImpl {
|
|||
|
||||
public EvokeAbility(Cost cost) {
|
||||
super(EVOKE_KEYWORD, REMINDER_TEXT, cost);
|
||||
Ability ability = new ConditionalInterveningIfTriggeredAbility(
|
||||
new EntersBattlefieldTriggeredAbility(new SacrificeSourceEffect(true)),
|
||||
EvokedCondition.instance, "When this permanent enters the battlefield, if its evoke cost was paid, its controller sacrifices it.");
|
||||
ability.setRuleVisible(false);
|
||||
addSubAbility(ability);
|
||||
this.addSubAbility(new EntersBattlefieldTriggeredAbility(
|
||||
new SacrificeSourceEffect(true).setText("its controller sacrifices it")
|
||||
).setTriggerPhrase("When this permanent enters, ").withInterveningIf(EvokedCondition.instance).setRuleVisible(false));
|
||||
}
|
||||
|
||||
private EvokeAbility(final EvokeAbility ability) {
|
||||
|
|
@ -40,7 +36,7 @@ public class EvokeAbility extends AlternativeSourceCostsImpl {
|
|||
return new EvokeAbility(this);
|
||||
}
|
||||
|
||||
public static String getActivationKey(){
|
||||
public static String getActivationKey() {
|
||||
return getActivationKey(EVOKE_KEYWORD);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -6,7 +6,6 @@ import mage.abilities.StaticAbility;
|
|||
import mage.abilities.common.EntersBattlefieldTriggeredAbility;
|
||||
import mage.abilities.condition.common.GiftWasPromisedCondition;
|
||||
import mage.abilities.costs.*;
|
||||
import mage.abilities.decorator.ConditionalInterveningIfTriggeredAbility;
|
||||
import mage.abilities.effects.OneShotEffect;
|
||||
import mage.cards.Card;
|
||||
import mage.constants.GiftType;
|
||||
|
|
@ -53,11 +52,10 @@ public class GiftAbility extends StaticAbility implements OptionalAdditionalSour
|
|||
this.rule = additionalCost.getName() + ' ' + additionalCost.getReminderText();
|
||||
this.setRuleAtTheTop(true);
|
||||
if (card.isPermanent()) {
|
||||
this.addSubAbility(new ConditionalInterveningIfTriggeredAbility(
|
||||
new EntersBattlefieldTriggeredAbility(new PromiseGiftEffect(giftType)),
|
||||
GiftWasPromisedCondition.TRUE, "When this permanent enters, " +
|
||||
"if the gift was promised, they " + giftType.getDescription() + '.'
|
||||
).setRuleVisible(false));
|
||||
this.addSubAbility(new EntersBattlefieldTriggeredAbility(new PromiseGiftEffect(giftType))
|
||||
.setTriggerPhrase("When this permanent enters, ")
|
||||
.withInterveningIf(GiftWasPromisedCondition.TRUE)
|
||||
.setRuleVisible(false));
|
||||
} else {
|
||||
card.getSpellAbility().addEffect(new PromiseGiftEffect(giftType));
|
||||
}
|
||||
|
|
@ -154,6 +152,7 @@ class PromiseGiftEffect extends OneShotEffect {
|
|||
PromiseGiftEffect(GiftType giftType) {
|
||||
super(Outcome.Benefit);
|
||||
this.giftType = giftType;
|
||||
staticText = "they " + giftType.getDescription();
|
||||
}
|
||||
|
||||
private PromiseGiftEffect(final PromiseGiftEffect effect) {
|
||||
|
|
|
|||
|
|
@ -7,7 +7,6 @@ import mage.abilities.common.EntersBattlefieldTriggeredAbility;
|
|||
import mage.abilities.condition.Condition;
|
||||
import mage.abilities.costs.*;
|
||||
import mage.abilities.costs.mana.ManaCostsImpl;
|
||||
import mage.abilities.decorator.ConditionalInterveningIfTriggeredAbility;
|
||||
import mage.abilities.effects.OneShotEffect;
|
||||
import mage.abilities.effects.common.CreateTokenCopyTargetEffect;
|
||||
import mage.constants.Outcome;
|
||||
|
|
@ -43,10 +42,8 @@ public class OffspringAbility extends StaticAbility implements OptionalAdditiona
|
|||
this.additionalCost.setRepeatable(false);
|
||||
this.rule = additionalCost.getName() + ' ' + additionalCost.getReminderText();
|
||||
this.setRuleAtTheTop(true);
|
||||
this.addSubAbility(new ConditionalInterveningIfTriggeredAbility(
|
||||
new EntersBattlefieldTriggeredAbility(new OffspringEffect()), OffspringCondition.instance,
|
||||
"When this creature enters, if its offspring cost was paid, create a 1/1 token copy of it."
|
||||
).setRuleVisible(false));
|
||||
this.addSubAbility(new EntersBattlefieldTriggeredAbility(new OffspringEffect())
|
||||
.withInterveningIf(OffspringCondition.instance).setRuleVisible(false));
|
||||
}
|
||||
|
||||
private OffspringAbility(final OffspringAbility ability) {
|
||||
|
|
@ -96,6 +93,7 @@ class OffspringEffect extends OneShotEffect {
|
|||
|
||||
OffspringEffect() {
|
||||
super(Outcome.Benefit);
|
||||
staticText = "create a 1/1 token copy of it";
|
||||
}
|
||||
|
||||
private OffspringEffect(final OffspringEffect effect) {
|
||||
|
|
@ -127,6 +125,6 @@ enum OffspringCondition implements Condition {
|
|||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "Offspring cost was paid";
|
||||
return "its offspring cost was paid";
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -4,7 +4,6 @@ import mage.abilities.Ability;
|
|||
import mage.abilities.common.EntersBattlefieldAbility;
|
||||
import mage.abilities.common.EntersBattlefieldTriggeredAbility;
|
||||
import mage.abilities.condition.Condition;
|
||||
import mage.abilities.decorator.ConditionalInterveningIfTriggeredAbility;
|
||||
import mage.abilities.dynamicvalue.common.GetXValue;
|
||||
import mage.abilities.effects.common.DrawCardSourceControllerEffect;
|
||||
import mage.abilities.effects.common.EntersBattlefieldWithXCountersEffect;
|
||||
|
|
@ -18,13 +17,8 @@ public class RavenousAbility extends EntersBattlefieldAbility {
|
|||
|
||||
public RavenousAbility() {
|
||||
super(new EntersBattlefieldWithXCountersEffect(CounterType.P1P1.createInstance()));
|
||||
Ability ability = new ConditionalInterveningIfTriggeredAbility(
|
||||
new EntersBattlefieldTriggeredAbility(new DrawCardSourceControllerEffect(1)),
|
||||
RavenousAbilityCondition.instance, "When this creature enters, " +
|
||||
"if X is 5 or more, draw a card"
|
||||
);
|
||||
ability.setRuleVisible(false);
|
||||
this.addSubAbility(ability);
|
||||
this.addSubAbility(new EntersBattlefieldTriggeredAbility(new DrawCardSourceControllerEffect(1))
|
||||
.withInterveningIf(RavenousAbilityCondition.instance).setRuleVisible(false));
|
||||
}
|
||||
|
||||
private RavenousAbility(final RavenousAbility ability) {
|
||||
|
|
@ -50,4 +44,9 @@ enum RavenousAbilityCondition implements Condition {
|
|||
public boolean apply(Game game, Ability source) {
|
||||
return GetXValue.instance.calculate(game, source, null) >= 5;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "X is 5 or more";
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue