mirror of
https://github.com/magefree/mage.git
synced 2026-01-23 03:39:54 -08:00
oh boy here I go refactoring ConditionalInterveningIfTriggeredAbility again
This commit is contained in:
parent
d80e0402dd
commit
cc2d234d58
67 changed files with 563 additions and 869 deletions
|
|
@ -1,14 +1,10 @@
|
|||
|
||||
package mage.abilities.common;
|
||||
|
||||
import mage.ObjectColor;
|
||||
import mage.abilities.TriggeredAbility;
|
||||
import mage.abilities.condition.CompoundCondition;
|
||||
import mage.abilities.condition.Condition;
|
||||
import mage.abilities.condition.InvertCondition;
|
||||
import mage.abilities.condition.common.PermanentsOnTheBattlefieldCondition;
|
||||
import mage.abilities.decorator.ConditionalOneShotEffect;
|
||||
import mage.abilities.decorator.ConditionalInterveningIfTriggeredAbility;
|
||||
import mage.abilities.effects.OneShotEffect;
|
||||
import mage.abilities.triggers.BeginningOfUpkeepTriggeredAbility;
|
||||
import mage.filter.FilterPermanent;
|
||||
|
|
@ -18,10 +14,10 @@ import mage.filter.predicate.mageobject.ColorPredicate;
|
|||
/**
|
||||
* @author TheElk801
|
||||
*/
|
||||
public class SanctuaryInterveningIfTriggeredAbility extends ConditionalInterveningIfTriggeredAbility {
|
||||
public class SanctuaryTriggeredAbility extends BeginningOfUpkeepTriggeredAbility {
|
||||
|
||||
private static Condition makeOrCondition(ObjectColor color1, ObjectColor color2) {
|
||||
FilterPermanent filter = new FilterPermanent();
|
||||
FilterPermanent filter = new FilterPermanent("you control a " + color1.getDescription() + " or " + color2.getDescription() + " permanent");
|
||||
filter.add(Predicates.or(
|
||||
new ColorPredicate(color1),
|
||||
new ColorPredicate(color2)
|
||||
|
|
@ -39,24 +35,17 @@ public class SanctuaryInterveningIfTriggeredAbility extends ConditionalInterveni
|
|||
return new CompoundCondition(condition1, condition2);
|
||||
}
|
||||
|
||||
private static TriggeredAbility makeTrigger(OneShotEffect effect1, OneShotEffect effect2, ObjectColor color1, ObjectColor color2) {
|
||||
TriggeredAbility ability = new BeginningOfUpkeepTriggeredAbility(
|
||||
new ConditionalOneShotEffect(effect1, new InvertCondition(makeAndCondition(color1, color2)))
|
||||
);
|
||||
ability.addEffect(new ConditionalOneShotEffect(effect2, makeAndCondition(color1, color2)));
|
||||
return ability;
|
||||
public SanctuaryTriggeredAbility(OneShotEffect effect1, OneShotEffect effect2, ObjectColor color1, ObjectColor color2, String text) {
|
||||
super(new ConditionalOneShotEffect(effect2, effect1, makeAndCondition(color1, color2), text));
|
||||
this.withInterveningIf(makeOrCondition(color1, color2));
|
||||
}
|
||||
|
||||
public SanctuaryInterveningIfTriggeredAbility(OneShotEffect effect1, OneShotEffect effect2, ObjectColor color1, ObjectColor color2, String text) {
|
||||
super(makeTrigger(effect1, effect2, color1, color2), makeOrCondition(color1, color2), text);
|
||||
}
|
||||
|
||||
protected SanctuaryInterveningIfTriggeredAbility(final SanctuaryInterveningIfTriggeredAbility ability) {
|
||||
protected SanctuaryTriggeredAbility(final SanctuaryTriggeredAbility ability) {
|
||||
super(ability);
|
||||
}
|
||||
|
||||
@Override
|
||||
public SanctuaryInterveningIfTriggeredAbility copy() {
|
||||
return new SanctuaryInterveningIfTriggeredAbility(this);
|
||||
public SanctuaryTriggeredAbility copy() {
|
||||
return new SanctuaryTriggeredAbility(this);
|
||||
}
|
||||
}
|
||||
|
|
@ -1,28 +1,24 @@
|
|||
|
||||
package mage.abilities.condition.common;
|
||||
|
||||
import mage.abilities.Ability;
|
||||
import mage.abilities.condition.Condition;
|
||||
import mage.game.Game;
|
||||
import mage.watchers.WatcherUtils;
|
||||
import mage.watchers.common.PlayerLostLifeWatcher;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author LevelX
|
||||
*/
|
||||
public enum LiveLostLastTurnCondition implements Condition {
|
||||
|
||||
instance;
|
||||
|
||||
@Override
|
||||
public boolean apply(Game game, Ability source) {
|
||||
PlayerLostLifeWatcher watcher = game.getState().getWatcher(PlayerLostLifeWatcher.class);
|
||||
if (watcher != null) {
|
||||
return watcher.getLifeLostLastTurn(source.getControllerId()) > 0;
|
||||
} else {
|
||||
WatcherUtils.logMissingWatcher(game, source, PlayerLostLifeWatcher.class, this.getClass());
|
||||
}
|
||||
return false;
|
||||
return watcher != null && watcher.getLifeLostLastTurn(source.getControllerId()) > 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "you lost life last turn";
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,4 +1,3 @@
|
|||
|
||||
package mage.abilities.condition.common;
|
||||
|
||||
import mage.abilities.Ability;
|
||||
|
|
@ -11,8 +10,7 @@ import mage.game.Game;
|
|||
* @author LevelX2
|
||||
*/
|
||||
public enum TributeNotPaidCondition implements Condition {
|
||||
|
||||
instance;
|
||||
instance;
|
||||
|
||||
@Override
|
||||
public boolean apply(Game game, Ability source) {
|
||||
|
|
@ -22,4 +20,9 @@ public enum TributeNotPaidCondition implements Condition {
|
|||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "tribute wasn't paid";
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -41,6 +41,7 @@ public class MeldEffect extends OneShotEffect {
|
|||
this.meldWithName = meldWithName;
|
||||
this.meldIntoName = meldIntoName;
|
||||
this.attacking = attacking;
|
||||
this.staticText = "exile them, then meld them into " + meldWithName;
|
||||
}
|
||||
|
||||
protected MeldEffect(final MeldEffect effect) {
|
||||
|
|
|
|||
|
|
@ -291,4 +291,9 @@ enum MadnessCondition implements Condition {
|
|||
|
||||
return ((Spell) madnessSpell).getSpellAbility().getSpellAbilityCastMode() == SpellAbilityCastMode.MADNESS;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "its madness cost was paid";
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -10,7 +10,6 @@ import mage.abilities.costs.VariableCostType;
|
|||
import mage.abilities.costs.mana.ManaCost;
|
||||
import mage.abilities.costs.mana.ManaCostsImpl;
|
||||
import mage.abilities.costs.mana.VariableManaCost;
|
||||
import mage.abilities.decorator.ConditionalInterveningIfTriggeredAbility;
|
||||
import mage.abilities.effects.ContinuousEffect;
|
||||
import mage.abilities.effects.ContinuousEffectImpl;
|
||||
import mage.abilities.effects.OneShotEffect;
|
||||
|
|
@ -147,7 +146,7 @@ public class SuspendAbility extends SpecialAction {
|
|||
if (card.getManaCost().isEmpty()) {
|
||||
setRuleAtTheTop(true);
|
||||
}
|
||||
addSubAbility(new SuspendBeginningOfUpkeepInterveningIfTriggeredAbility());
|
||||
addSubAbility(new SuspendUpkeepAbility());
|
||||
addSubAbility(new SuspendPlayCardAbility());
|
||||
} else {
|
||||
ruleText = "Suspend";
|
||||
|
|
@ -188,8 +187,7 @@ public class SuspendAbility extends SpecialAction {
|
|||
ability.setControllerId(card.getOwnerId());
|
||||
game.getState().addOtherAbility(card, ability);
|
||||
|
||||
SuspendBeginningOfUpkeepInterveningIfTriggeredAbility ability1
|
||||
= new SuspendBeginningOfUpkeepInterveningIfTriggeredAbility();
|
||||
SuspendUpkeepAbility ability1 = new SuspendUpkeepAbility();
|
||||
ability1.setSourceId(card.getId());
|
||||
ability1.setControllerId(card.getOwnerId());
|
||||
game.getState().addOtherAbility(card, ability1);
|
||||
|
|
@ -434,23 +432,20 @@ class GainHasteEffect extends ContinuousEffectImpl {
|
|||
|
||||
}
|
||||
|
||||
class SuspendBeginningOfUpkeepInterveningIfTriggeredAbility extends ConditionalInterveningIfTriggeredAbility {
|
||||
class SuspendUpkeepAbility extends BeginningOfUpkeepTriggeredAbility {
|
||||
|
||||
SuspendBeginningOfUpkeepInterveningIfTriggeredAbility() {
|
||||
super(new BeginningOfUpkeepTriggeredAbility(Zone.EXILED, TargetController.YOU, new RemoveCounterSourceEffect(CounterType.TIME.createInstance()),
|
||||
false),
|
||||
SuspendedCondition.instance,
|
||||
"At the beginning of your upkeep, if {this} is suspended, remove a time counter from it.");
|
||||
SuspendUpkeepAbility() {
|
||||
super(Zone.EXILED, TargetController.YOU, new RemoveCounterSourceEffect(CounterType.TIME.createInstance()).setText("remove a time counter from it"), false);
|
||||
this.withInterveningIf(SuspendedCondition.instance);
|
||||
this.setRuleVisible(false);
|
||||
|
||||
}
|
||||
|
||||
private SuspendBeginningOfUpkeepInterveningIfTriggeredAbility(final SuspendBeginningOfUpkeepInterveningIfTriggeredAbility effect) {
|
||||
private SuspendUpkeepAbility(final SuspendUpkeepAbility effect) {
|
||||
super(effect);
|
||||
}
|
||||
|
||||
@Override
|
||||
public SuspendBeginningOfUpkeepInterveningIfTriggeredAbility copy() {
|
||||
return new SuspendBeginningOfUpkeepInterveningIfTriggeredAbility(this);
|
||||
public SuspendUpkeepAbility copy() {
|
||||
return new SuspendUpkeepAbility(this);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,20 +0,0 @@
|
|||
|
||||
package mage.watchers;
|
||||
|
||||
import mage.MageObject;
|
||||
import mage.abilities.Ability;
|
||||
import mage.game.Game;
|
||||
import org.apache.log4j.Logger;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author LevelX2
|
||||
*/
|
||||
public final class WatcherUtils {
|
||||
|
||||
public static void logMissingWatcher(Game game, Ability source, Class watcherClass, Class usingClass) {
|
||||
MageObject sourceObject = source.getSourceObject(game);
|
||||
Logger.getLogger(usingClass).error("Needed watcher is not started " + watcherClass.getSimpleName()
|
||||
+ " - " + (sourceObject == null ? " no source object" : sourceObject.getName()));
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue