remove getEvent in MagicDiesTrigger, implement should override executeTrigger

instead

added combine static factory method to compose a trigger with MagicSourceEvent
master
melvin 2013-10-19 13:10:30 +08:00
parent b06bacb09a
commit 5fd20a5987
57 changed files with 161 additions and 243 deletions

View File

@ -1,7 +1,7 @@
[
new MagicWhenDiesTrigger() {
@Override
public MagicEvent getEvent(final MagicPermanent permanent) {
public MagicEvent executeTrigger(final MagicGame game, final MagicPermanent permanent, final MagicMoveCardAction data) {
return new MagicEvent(
permanent,
this,

View File

@ -1,7 +1,7 @@
[
new MagicWhenDiesTrigger() {
@Override
public MagicEvent getEvent(final MagicPermanent permanent) {
public MagicEvent executeTrigger(final MagicGame game, final MagicPermanent permanent, final MagicMoveCardAction data) {
final MagicPlayer opponent = permanent.getOpponent();
return new MagicEvent(
permanent,

View File

@ -1,7 +1,7 @@
[
new MagicWhenDiesTrigger() {
@Override
public MagicEvent getEvent(final MagicPermanent permanent) {
public MagicEvent executeTrigger(final MagicGame game, final MagicPermanent permanent, final MagicMoveCardAction data) {
return new MagicEvent(
permanent,
permanent.getOpponent(),

View File

@ -1,7 +1,7 @@
[
new MagicWhenDiesTrigger() {
@Override
public MagicEvent getEvent(final MagicPermanent permanent) {
public MagicEvent executeTrigger(final MagicGame game, final MagicPermanent permanent, final MagicMoveCardAction data) {
return new MagicEvent(
permanent,
this,

View File

@ -22,7 +22,7 @@ def event = {
[
new MagicWhenDiesTrigger() {
@Override
public MagicEvent getEvent(final MagicPermanent permanent) {
public MagicEvent executeTrigger(final MagicGame game, final MagicPermanent permanent, final MagicMoveCardAction data) {
return event(permanent);
}
},

View File

@ -1,7 +1,7 @@
[
new MagicWhenDiesTrigger() {
@Override
public MagicEvent getEvent(final MagicPermanent permanent) {
public MagicEvent executeTrigger(final MagicGame game, final MagicPermanent permanent, final MagicMoveCardAction data) {
return new MagicEvent(
permanent,
this,

View File

@ -1,7 +1,7 @@
[
new MagicWhenDiesTrigger() {
@Override
public MagicEvent getEvent(final MagicPermanent permanent) {
public MagicEvent executeTrigger(final MagicGame game, final MagicPermanent permanent, final MagicMoveCardAction data) {
return permanent.getCounters(MagicCounterType.Charge) == 0 ?
new MagicEvent(
permanent,

View File

@ -1,7 +1,7 @@
[
new MagicWhenDiesTrigger() {
@Override
public MagicEvent getEvent(final MagicPermanent permanent) {
public MagicEvent executeTrigger(final MagicGame game, final MagicPermanent permanent, final MagicMoveCardAction data) {
return permanent.getCounters(MagicCounterType.Charge) == 0 ?
new MagicEvent(
permanent,

View File

@ -1,7 +1,7 @@
[
new MagicWhenDiesTrigger() {
@Override
public MagicEvent getEvent(final MagicPermanent permanent) {
public MagicEvent executeTrigger(final MagicGame game, final MagicPermanent permanent, final MagicMoveCardAction data) {
return new MagicEvent(
permanent,
this,

View File

@ -1,7 +1,7 @@
[
new MagicWhenDiesTrigger() {
@Override
public MagicEvent getEvent(final MagicPermanent permanent) {
public MagicEvent executeTrigger(final MagicGame game, final MagicPermanent permanent, final MagicMoveCardAction data) {
final MagicTargetChoice targetChoice = new MagicTargetChoice(
new MagicTargetFilter.MagicCMCCardFilter(
MagicTargetFilter.TARGET_CREATURE_CARD_FROM_GRAVEYARD,

View File

@ -1,7 +1,7 @@
[
new MagicWhenDiesTrigger() {
@Override
public MagicEvent getEvent(final MagicPermanent permanent) {
public MagicEvent executeTrigger(final MagicGame game, final MagicPermanent permanent, final MagicMoveCardAction data) {
return new MagicEvent(
permanent,
MagicTargetChoice.TARGET_CREATURE_YOU_CONTROL,

View File

@ -1,7 +1,7 @@
[
new MagicWhenDiesTrigger() {
@Override
public MagicEvent getEvent(final MagicPermanent permanent) {
public MagicEvent executeTrigger(final MagicGame game, final MagicPermanent permanent, final MagicMoveCardAction data) {
return new MagicEvent(
permanent,
this,

View File

@ -1,7 +1,7 @@
[
new MagicWhenDiesTrigger() {
@Override
public MagicEvent getEvent(final MagicPermanent permanent) {
public MagicEvent executeTrigger(final MagicGame game, final MagicPermanent permanent, final MagicMoveCardAction data) {
return new MagicEvent(
permanent,
this,

View File

@ -1,7 +1,7 @@
[
new MagicWhenDiesTrigger() {
@Override
public MagicEvent getEvent(final MagicPermanent permanent) {
public MagicEvent executeTrigger(final MagicGame game, final MagicPermanent permanent, final MagicMoveCardAction data) {
return new MagicEvent(
permanent,
new MagicMayChoice(

View File

@ -25,7 +25,7 @@ def event = {
},
new MagicWhenDiesTrigger() {
@Override
public MagicEvent getEvent(final MagicPermanent permanent) {
public MagicEvent executeTrigger(final MagicGame game, final MagicPermanent permanent, final MagicMoveCardAction data) {
return event(permanent);
}
}

View File

@ -1,7 +1,7 @@
[
new MagicWhenDiesTrigger() {
@Override
public MagicEvent getEvent(final MagicPermanent permanent) {
public MagicEvent executeTrigger(final MagicGame game, final MagicPermanent permanent, final MagicMoveCardAction data) {
return new MagicEvent(
permanent,
this,

View File

@ -1,7 +1,7 @@
[
new MagicWhenDiesTrigger() {
@Override
public MagicEvent getEvent(final MagicPermanent permanent) {
public MagicEvent executeTrigger(final MagicGame game, final MagicPermanent permanent, final MagicMoveCardAction data) {
return new MagicEvent(
permanent,
this,

View File

@ -1,7 +1,7 @@
[
new MagicWhenDiesTrigger() {
@Override
public MagicEvent getEvent(final MagicPermanent permanent) {
public MagicEvent executeTrigger(final MagicGame game, final MagicPermanent permanent, final MagicMoveCardAction data) {
return new MagicEvent(
permanent,
MagicTargetChoice.TARGET_CREATURE,

View File

@ -1,7 +1,7 @@
[
new MagicWhenDiesTrigger() {
@Override
public MagicEvent getEvent(final MagicPermanent permanent) {
public MagicEvent executeTrigger(final MagicGame game, final MagicPermanent permanent, final MagicMoveCardAction data) {
return new MagicEvent(
permanent,
this,

View File

@ -1,7 +1,7 @@
[
new MagicWhenDiesTrigger() {
@Override
public MagicEvent getEvent(final MagicPermanent permanent) {
public MagicEvent executeTrigger(final MagicGame game, final MagicPermanent permanent, final MagicMoveCardAction data) {
return new MagicEvent(
permanent,
MagicTargetChoice.NEG_TARGET_CREATURE,

View File

@ -8,12 +8,12 @@
},
new MagicWhenDiesTrigger() {
@Override
public MagicEvent getEvent(final MagicPermanent permanent) {
public MagicEvent executeTrigger(final MagicGame game, final MagicPermanent permanent, final MagicMoveCardAction data) {
final int cmc = permanent.getGame().filterPermanents(
permanent.getController(),
MagicTargetFilter.TARGET_SPIRIT_YOU_CONTROL
).size()+1;
return new MagicSoulshiftTrigger(cmc).getEvent(permanent);
return new MagicSoulshiftTrigger(cmc).executeTrigger(game, permanent, data);
}
}
]

View File

@ -1,7 +1,7 @@
[
new MagicWhenDiesTrigger() {
@Override
public MagicEvent getEvent(final MagicPermanent permanent) {
public MagicEvent executeTrigger(final MagicGame game, final MagicPermanent permanent, final MagicMoveCardAction data) {
return new MagicEvent(
permanent,
this,

View File

@ -1,7 +1,7 @@
[
new MagicWhenDiesTrigger() {
@Override
public MagicEvent getEvent(final MagicPermanent permanent) {
public MagicEvent executeTrigger(final MagicGame game, final MagicPermanent permanent, final MagicMoveCardAction data) {
return new MagicEvent(
permanent,
this,

View File

@ -1,7 +1,7 @@
[
new MagicWhenDiesTrigger() {
@Override
public MagicEvent getEvent(final MagicPermanent permanent) {
public MagicEvent executeTrigger(final MagicGame game, final MagicPermanent permanent, final MagicMoveCardAction data) {
return new MagicEvent(
permanent,
this,

View File

@ -1,7 +1,7 @@
[
new MagicWhenDiesTrigger() {
@Override
public MagicEvent getEvent(final MagicPermanent permanent) {
public MagicEvent executeTrigger(final MagicGame game, final MagicPermanent permanent, final MagicMoveCardAction data) {
return new MagicEvent(
permanent,
this,

View File

@ -24,7 +24,7 @@ def event = {
},
new MagicWhenDiesTrigger() {
@Override
public MagicEvent getEvent(final MagicPermanent permanent) {
public MagicEvent executeTrigger(final MagicGame game, final MagicPermanent permanent, final MagicMoveCardAction data) {
return event(permanent);
}
}

View File

@ -1,7 +1,7 @@
[
new MagicWhenDiesTrigger() {
@Override
public MagicEvent getEvent(final MagicPermanent permanent) {
public MagicEvent executeTrigger(final MagicGame game, final MagicPermanent permanent, final MagicMoveCardAction data) {
return new MagicEvent(
permanent,
this,

View File

@ -22,7 +22,7 @@ def event = {
[
new MagicWhenDiesTrigger() {
@Override
public MagicEvent getEvent(final MagicPermanent permanent) {
public MagicEvent executeTrigger(final MagicGame game, final MagicPermanent permanent, final MagicMoveCardAction data) {
return event(permanent);
}
},

View File

@ -1,7 +1,7 @@
[
new MagicWhenDiesTrigger() {
@Override
public MagicEvent getEvent(final MagicPermanent permanent) {
public MagicEvent executeTrigger(final MagicGame game, final MagicPermanent permanent, final MagicMoveCardAction data) {
return new MagicEvent(
permanent,
this,

View File

@ -1,7 +1,7 @@
[
new MagicWhenDiesTrigger() {
@Override
public MagicEvent getEvent(final MagicPermanent permanent) {
public MagicEvent executeTrigger(final MagicGame game, final MagicPermanent permanent, final MagicMoveCardAction data) {
return new MagicEvent(
permanent,
new MagicMayChoice(

View File

@ -1,7 +1,7 @@
[
new MagicWhenDiesTrigger() {
@Override
public MagicEvent getEvent(final MagicPermanent permanent) {
public MagicEvent executeTrigger(final MagicGame game, final MagicPermanent permanent, final MagicMoveCardAction data) {
return new MagicEvent(
permanent,
this,

View File

@ -1,7 +1,7 @@
[
new MagicWhenDiesTrigger() {
@Override
public MagicEvent getEvent(final MagicPermanent permanent) {
public MagicEvent executeTrigger(final MagicGame game, final MagicPermanent permanent, final MagicMoveCardAction data) {
return new MagicEvent(
permanent,
this,

View File

@ -1,7 +1,7 @@
[
new MagicWhenDiesTrigger() {
@Override
public MagicEvent getEvent(final MagicPermanent permanent) {
public MagicEvent executeTrigger(final MagicGame game, final MagicPermanent permanent, final MagicMoveCardAction data) {
return new MagicEvent(
permanent,
this,

View File

@ -1,7 +1,7 @@
[
new MagicWhenDiesTrigger() {
@Override
public MagicEvent getEvent(final MagicPermanent permanent) {
public MagicEvent executeTrigger(final MagicGame game, final MagicPermanent permanent, final MagicMoveCardAction data) {
return new MagicEvent(
permanent,
this,

View File

@ -1,7 +1,7 @@
[
new MagicWhenDiesTrigger() {
@Override
public MagicEvent getEvent(final MagicPermanent permanent) {
public MagicEvent executeTrigger(final MagicGame game, final MagicPermanent permanent, final MagicMoveCardAction data) {
return new MagicEvent(
permanent,
this,

View File

@ -1,7 +1,7 @@
[
new MagicWhenDiesTrigger() {
@Override
public MagicEvent getEvent(final MagicPermanent permanent) {
public MagicEvent executeTrigger(final MagicGame game, final MagicPermanent permanent, final MagicMoveCardAction data) {
return new MagicEvent(
permanent,
MagicTargetChoice.NEG_TARGET_PLAYER,

View File

@ -1,7 +1,7 @@
[
new MagicWhenDiesTrigger() {
@Override
public MagicEvent getEvent(final MagicPermanent permanent) {
public MagicEvent executeTrigger(final MagicGame game, final MagicPermanent permanent, final MagicMoveCardAction data) {
return new MagicEvent(
permanent,
this,

View File

@ -1,7 +1,7 @@
[
new MagicWhenDiesTrigger() {
@Override
public MagicEvent getEvent(final MagicPermanent permanent) {
public MagicEvent executeTrigger(final MagicGame game, final MagicPermanent permanent, final MagicMoveCardAction data) {
return new MagicEvent(
permanent,
this,

View File

@ -1,7 +1,7 @@
[
new MagicWhenDiesTrigger() {
@Override
public MagicEvent getEvent(final MagicPermanent permanent) {
public MagicEvent executeTrigger(final MagicGame game, final MagicPermanent permanent, final MagicMoveCardAction data) {
return new MagicEvent(
permanent,
this,

View File

@ -1,7 +1,7 @@
[
new MagicWhenDiesTrigger() {
@Override
public MagicEvent getEvent(final MagicPermanent permanent) {
public MagicEvent executeTrigger(final MagicGame game, final MagicPermanent permanent, final MagicMoveCardAction data) {
return new MagicEvent(
permanent,
this,

View File

@ -1,7 +1,7 @@
[
new MagicWhenDiesTrigger() {
@Override
public MagicEvent getEvent(final MagicPermanent permanent) {
public MagicEvent executeTrigger(final MagicGame game, final MagicPermanent permanent, final MagicMoveCardAction data) {
return new MagicEvent(
permanent,
this,

View File

@ -1,7 +1,7 @@
[
new MagicWhenDiesTrigger() {
@Override
public MagicEvent getEvent(final MagicPermanent permanent) {
public MagicEvent executeTrigger(final MagicGame game, final MagicPermanent permanent, final MagicMoveCardAction data) {
return new MagicEvent(
permanent,
new MagicMayChoice(

View File

@ -1,26 +1,30 @@
def WhenDies = new MagicWhenDiesTrigger() {
@Override
public MagicEvent getEvent(final MagicPermanent permanent) {
return new MagicEvent(
permanent,
this,
"PN puts a green and white Elemental creature token onto the battlefield with " +
"\"This creature's power and toughness are each equal to the number of creatures you control.\""
);
}
@Override
public void executeEvent(final MagicGame game, final MagicEvent event) {
game.doAction(new MagicPlayTokenAction(event.getPlayer(), TokenCardDefinitions.get("GW Elemental")));
}
def Action = {
final MagicGame game, final MagicEvent event ->
game.doAction(new MagicPlayTokenAction(event.getPlayer(), TokenCardDefinitions.get("GW Elemental")));
} as MagicEventAction
def Event = {
final MagicPermanent permanent ->
return new MagicEvent(
permanent,
Action,
"PN puts a green and white Elemental creature token onto the battlefield with " +
"\"This creature's power and toughness are each equal to the number of creatures you control.\""
);
}
[
WhenDies,
new MagicWhenDiesTrigger() {
@Override
public MagicEvent executeTrigger(final MagicGame game, final MagicPermanent permanent, final MagicMoveCardAction data) {
return Event(permanent);
}
},
new MagicWhenOtherSpellIsCastTrigger() {
@Override
public MagicEvent executeTrigger(final MagicGame game,final MagicPermanent permanent,final MagicCardOnStack cardOnStack) {
return permanent.isEnemy(cardOnStack) && permanent.isController(game.getTurnPlayer()) ?
WhenDies.getEvent(permanent) : MagicEvent.NONE;
Event(permanent) : MagicEvent.NONE;
}
}
]

View File

@ -1,7 +1,7 @@
[
new MagicWhenDiesTrigger() {
@Override
public MagicEvent getEvent(final MagicPermanent permanent) {
public MagicEvent executeTrigger(final MagicGame game, final MagicPermanent permanent, final MagicMoveCardAction data) {
return new MagicEvent(
permanent,
this,

View File

@ -1,7 +1,7 @@
[
new MagicWhenDiesTrigger() {
@Override
public MagicEvent getEvent(final MagicPermanent permanent) {
public MagicEvent executeTrigger(final MagicGame game, final MagicPermanent permanent, final MagicMoveCardAction data) {
return new MagicEvent(
permanent,
this,

View File

@ -1,7 +1,7 @@
[
new MagicWhenDiesTrigger() {
@Override
public MagicEvent getEvent(final MagicPermanent permanent) {
public MagicEvent executeTrigger(final MagicGame game, final MagicPermanent permanent, final MagicMoveCardAction data) {
return new MagicEvent(
permanent,
this,

View File

@ -26,8 +26,10 @@ import magic.model.event.MagicKickerCost;
import magic.model.event.MagicMultikickerCost;
import magic.model.event.MagicMonstrosityActivation;
import magic.model.event.MagicBestowActivation;
import magic.model.event.MagicRuleEventAction;
import magic.model.mstatic.MagicCDA;
import magic.model.mstatic.MagicStatic;
import magic.model.trigger.MagicTrigger;
import magic.model.trigger.MagicAllyGrowTrigger;
import magic.model.trigger.MagicAnnihilatorTrigger;
import magic.model.trigger.MagicAttacksPumpTrigger;
@ -38,7 +40,6 @@ import magic.model.trigger.MagicComesIntoPlayWithCounterTrigger;
import magic.model.trigger.MagicCumulativeUpkeepTrigger;
import magic.model.trigger.MagicDamageGrowTrigger;
import magic.model.trigger.MagicDevourTrigger;
import magic.model.trigger.MagicDieDrawCardTrigger;
import magic.model.trigger.MagicEchoTrigger;
import magic.model.trigger.MagicEntersDamageTargetTrigger;
import magic.model.trigger.MagicEntersExileCreatureOrSacrificeTrigger;
@ -693,32 +694,50 @@ public enum MagicAbility {
},
EntersEffect("enters effect", 10) {
protected void addAbilityImpl(final MagicAbilityStore card, final String arg) {
card.add(MagicWhenComesIntoPlayTrigger.create(arg));
card.add(MagicTrigger.combine(
MagicWhenComesIntoPlayTrigger.NONE,
MagicRuleEventAction.create(arg)
));
}
},
EntersMayEffect("enters effect PN may", 10) {
protected void addAbilityImpl(final MagicAbilityStore card, final String arg) {
card.add(MagicWhenComesIntoPlayTrigger.createMay(arg));
card.add(MagicTrigger.combine(
MagicWhenComesIntoPlayTrigger.NONE,
MagicRuleEventAction.createMay(arg)
));
}
},
DiesEffect("dies effect", 10) {
protected void addAbilityImpl(final MagicAbilityStore card, final String arg) {
card.add(MagicWhenDiesTrigger.create(arg));
card.add(MagicTrigger.combine(
MagicWhenDiesTrigger.NONE,
MagicRuleEventAction.create(arg)
));
}
},
DiesMayEffect("dies effect PN may", 10) {
protected void addAbilityImpl(final MagicAbilityStore card, final String arg) {
card.add(MagicWhenDiesTrigger.createMay(arg));
card.add(MagicTrigger.combine(
MagicWhenDiesTrigger.NONE,
MagicRuleEventAction.createMay(arg)
));
}
},
LeavesEffect("leaves effect", 10) {
protected void addAbilityImpl(final MagicAbilityStore card, final String arg) {
card.add(MagicWhenLeavesPlayTrigger.create(arg));
card.add(MagicTrigger.combine(
MagicWhenLeavesPlayTrigger.NONE,
MagicRuleEventAction.create(arg)
));
}
},
LeavesMayEffect("leaves effect PN may", 10) {
protected void addAbilityImpl(final MagicAbilityStore card, final String arg) {
card.add(MagicWhenLeavesPlayTrigger.createMay(arg));
card.add(MagicTrigger.combine(
MagicWhenLeavesPlayTrigger.NONE,
MagicRuleEventAction.createMay(arg)
));
}
},
ControlEnchanted("control enchanted", 10) {

View File

@ -1,46 +0,0 @@
package magic.model.event;
import magic.model.MagicGame;
import magic.model.MagicPayedCost;
import magic.model.MagicPermanent;
import magic.model.action.MagicPermanentAction;
import magic.model.action.MagicTapAction;
import magic.model.choice.MagicTargetChoice;
import magic.model.condition.MagicCondition;
import magic.model.target.MagicTapTargetPicker;
public abstract class MagicTapCreatureActivation extends MagicPermanentActivation {
public MagicTapCreatureActivation(
final MagicActivationHints hints,
final String text) {
super(MagicActivation.NO_COND,hints,text);
}
public MagicTapCreatureActivation(
final MagicCondition[] conds,
final MagicActivationHints hints,
final String text) {
super(conds,hints,text);
}
@Override
public MagicEvent getPermanentEvent(final MagicPermanent source,final MagicPayedCost payedCost) {
return new MagicEvent(
source,
MagicTargetChoice.NEG_TARGET_CREATURE,
MagicTapTargetPicker.Tap,
this,
"Tap target creature$."
);
}
@Override
public void executeEvent(final MagicGame game, final MagicEvent event) {
event.processTargetPermanent(game,new MagicPermanentAction() {
public void doAction(final MagicPermanent creature) {
game.doAction(new MagicTapAction(creature,true));
}
});
}
}

View File

@ -1,44 +0,0 @@
package magic.model.trigger;
import magic.model.MagicGame;
import magic.model.MagicLocationType;
import magic.model.MagicPermanent;
import magic.model.action.MagicDrawAction;
import magic.model.choice.MagicSimpleMayChoice;
import magic.model.event.MagicEvent;
//When C is put into a graveyard from the battlefield, you may or must draw a card.
public class MagicDieDrawCardTrigger extends MagicWhenDiesTrigger {
private final boolean mustDraw;
public MagicDieDrawCardTrigger(final boolean mandatory) {
this.mustDraw = mandatory;
}
@Override
public MagicEvent getEvent(final MagicPermanent permanent) {
return mustDraw ?
new MagicEvent(
permanent,
this,
"PN draws a card."
):
new MagicEvent(
permanent,
new MagicSimpleMayChoice(
MagicSimpleMayChoice.DRAW_CARDS,
1,
MagicSimpleMayChoice.DEFAULT_NONE
),
this,
"PN may$ draw a card."
);
}
@Override
public void executeEvent(final MagicGame game, final MagicEvent event) {
if (mustDraw || event.isYes()) {
game.doAction(new MagicDrawAction(event.getPlayer()));
}
}
}

View File

@ -6,12 +6,12 @@ import magic.model.MagicLocationType;
import magic.model.MagicPermanent;
import magic.model.action.MagicChangeCountersAction;
import magic.model.action.MagicPermanentAction;
import magic.model.action.MagicMoveCardAction;
import magic.model.choice.MagicMayChoice;
import magic.model.choice.MagicTargetChoice;
import magic.model.event.MagicEvent;
import magic.model.target.MagicPumpTargetPicker;
public class MagicModularTrigger extends MagicWhenDiesTrigger {
private static final MagicModularTrigger INSTANCE = new MagicModularTrigger();
@ -23,7 +23,7 @@ public class MagicModularTrigger extends MagicWhenDiesTrigger {
}
@Override
public MagicEvent getEvent(final MagicPermanent permanent) {
public MagicEvent executeTrigger(final MagicGame game,final MagicPermanent permanent,final MagicMoveCardAction act) {
final int amount = permanent.getCounters(MagicCounterType.PlusOne);
return new MagicEvent(
permanent,

View File

@ -7,6 +7,7 @@ import magic.model.MagicPermanent;
import magic.model.action.MagicPlayCardAction;
import magic.model.action.MagicPlayMod;
import magic.model.action.MagicReanimateAction;
import magic.model.action.MagicMoveCardAction;
import magic.model.event.MagicEvent;
public class MagicPersistTrigger extends MagicWhenDiesTrigger {
@ -20,7 +21,7 @@ public class MagicPersistTrigger extends MagicWhenDiesTrigger {
}
@Override
public MagicEvent getEvent(final MagicPermanent permanent) {
public MagicEvent executeTrigger(final MagicGame game,final MagicPermanent permanent,final MagicMoveCardAction act) {
return permanent.getCounters(MagicCounterType.MinusOne) == 0 ?
new MagicEvent(
permanent,

View File

@ -23,7 +23,7 @@ public class MagicSoulshiftTrigger extends MagicWhenDiesTrigger {
}
@Override
public MagicEvent getEvent(final MagicPermanent permanent) {
public MagicEvent executeTrigger(final MagicGame game,final MagicPermanent permanent,final MagicMoveCardAction act) {
final MagicTargetFilter<MagicCard> targetFilter =
new MagicTargetFilter.MagicCMCCardFilter(
MagicTargetFilter.TARGET_SPIRIT_CARD_FROM_GRAVEYARD,

View File

@ -5,6 +5,7 @@ import magic.model.MagicChangeCardDefinition;
import magic.model.MagicGame;
import magic.model.MagicPermanent;
import magic.model.event.MagicEvent;
import magic.model.event.MagicSourceEvent;
import magic.model.event.MagicEventAction;
/** Lower priority values trigger before higher priority values. */
@ -19,10 +20,10 @@ public abstract class MagicTrigger<T> implements MagicEventAction,MagicChangeCar
private final int priority;
protected MagicTrigger(final int priority) {
this.priority = priority;
protected MagicTrigger(final int aPriority) {
priority = aPriority;
}
protected MagicTrigger() {
this(DEFAULT_PRIORITY);
}
@ -41,7 +42,7 @@ public abstract class MagicTrigger<T> implements MagicEventAction,MagicChangeCar
}
public abstract MagicTriggerType getType();
public abstract MagicEvent executeTrigger(final MagicGame game,final MagicPermanent permanent, final T data);
public boolean accept(final MagicPermanent permanent, final T data) {
@ -52,4 +53,29 @@ public abstract class MagicTrigger<T> implements MagicEventAction,MagicChangeCar
public void change(final MagicCardDefinition cdef) {
cdef.addTrigger(this);
}
public static <T> MagicTrigger<T> combine(final MagicTrigger<T> trigger, final MagicSourceEvent sourceEvent) {
return new MagicTrigger<T>() {
@Override
public MagicTriggerType getType() {
return trigger.getType();
}
@Override
public boolean accept(final MagicPermanent permanent, final T data) {
return trigger.accept(permanent, data);
}
@Override
public void change(final MagicCardDefinition cdef) {
trigger.change(cdef);
}
@Override
public boolean usesStack() {
return trigger.usesStack();
}
@Override
public MagicEvent executeTrigger(final MagicGame game,final MagicPermanent permanent, final T data) {
return sourceEvent.getEvent(permanent);
}
};
}
}

View File

@ -7,6 +7,7 @@ import magic.model.MagicPermanent;
import magic.model.action.MagicPlayCardAction;
import magic.model.action.MagicPlayMod;
import magic.model.action.MagicReanimateAction;
import magic.model.action.MagicMoveCardAction;
import magic.model.event.MagicEvent;
public class MagicUndyingTrigger extends MagicWhenDiesTrigger {
@ -20,7 +21,7 @@ public class MagicUndyingTrigger extends MagicWhenDiesTrigger {
}
@Override
public MagicEvent getEvent(final MagicPermanent permanent) {
public MagicEvent executeTrigger(final MagicGame game,final MagicPermanent permanent,final MagicMoveCardAction act) {
return permanent.getCounters(MagicCounterType.PlusOne) == 0 ?
new MagicEvent(
permanent,

View File

@ -20,10 +20,18 @@ import magic.model.action.MagicChangeCountersAction;
import magic.data.TokenCardDefinitions;
public abstract class MagicWhenComesIntoPlayTrigger extends MagicTrigger<MagicPayedCost> {
public static final MagicWhenComesIntoPlayTrigger NONE = new MagicWhenComesIntoPlayTrigger() {
@Override
public MagicEvent executeTrigger(final MagicGame game,final MagicPermanent permanent, final MagicPayedCost data) {
throw new RuntimeException("executeTrigger called on NONE");
}
};
public MagicWhenComesIntoPlayTrigger(final int priority) {
super(priority);
}
public MagicWhenComesIntoPlayTrigger() {}
public MagicTriggerType getType() {
@ -35,26 +43,6 @@ public abstract class MagicWhenComesIntoPlayTrigger extends MagicTrigger<MagicPa
cdef.addTrigger(this);
}
public static MagicWhenComesIntoPlayTrigger createMay(final String rule) {
final MagicSourceEvent sourceEvent = MagicRuleEventAction.createMay(rule);
return new MagicWhenComesIntoPlayTrigger() {
@Override
public MagicEvent executeTrigger(final MagicGame game, final MagicPermanent permanent, final MagicPayedCost payedCost) {
return sourceEvent.getEvent(permanent);
}
};
}
public static MagicWhenComesIntoPlayTrigger create(final String rule) {
final MagicSourceEvent sourceEvent = MagicRuleEventAction.create(rule);
return new MagicWhenComesIntoPlayTrigger() {
@Override
public MagicEvent executeTrigger(final MagicGame game, final MagicPermanent permanent, final MagicPayedCost payedCost) {
return sourceEvent.getEvent(permanent);
}
};
}
public static final MagicWhenComesIntoPlayTrigger ChooseOpponent = new MagicWhenComesIntoPlayTrigger() {
@Override
public MagicEvent executeTrigger(final MagicGame game, final MagicPermanent permanent, final MagicPayedCost payedCost) {

View File

@ -15,49 +15,31 @@ import magic.model.action.MagicMoveCardAction;
import magic.model.action.MagicRemoveCardAction;
public abstract class MagicWhenDiesTrigger extends MagicWhenPutIntoGraveyardTrigger {
public static final MagicWhenDiesTrigger NONE = new MagicWhenDiesTrigger() {
@Override
public MagicEvent executeTrigger(final MagicGame game,final MagicPermanent permanent, final MagicMoveCardAction data) {
throw new RuntimeException("executeTrigger called on NONE");
}
};
public MagicWhenDiesTrigger(final int priority) {
super(priority);
}
public MagicWhenDiesTrigger() {}
protected abstract MagicEvent getEvent(final MagicPermanent permanent);
@Override
public MagicEvent executeTrigger(final MagicGame game,final MagicPermanent permanent,final MagicMoveCardAction act) {
return (act.fromLocation == MagicLocationType.Play) ?
getEvent(permanent) : MagicEvent.NONE;
}
public static MagicWhenDiesTrigger createMay(final String rule) {
final MagicSourceEvent sourceEvent = MagicRuleEventAction.createMay(rule);
return new MagicWhenDiesTrigger() {
@Override
public MagicEvent getEvent(final MagicPermanent permanent) {
return sourceEvent.getEvent(permanent);
}
};
}
public static MagicWhenDiesTrigger create(final String rule) {
final MagicSourceEvent sourceEvent = MagicRuleEventAction.create(rule);
return new MagicWhenDiesTrigger() {
@Override
public MagicEvent getEvent(final MagicPermanent permanent) {
return sourceEvent.getEvent(permanent);
}
};
public MagicWhenDiesTrigger() {}
@Override
public boolean accept(final MagicPermanent permanent, final MagicMoveCardAction act) {
return super.accept(permanent,act) && act.fromLocation == MagicLocationType.Play;
}
public static MagicWhenDiesTrigger ReturnToOwnersHand = new MagicWhenDiesTrigger() {
@Override
public MagicEvent getEvent(final MagicPermanent permanent) {
final MagicCard card = permanent.getCard();
public MagicEvent executeTrigger(final MagicGame game,final MagicPermanent permanent,final MagicMoveCardAction act) {
return new MagicEvent(
card,
card.getController(),
permanent.getCard(),
this,
"Return " + card + " to its owner's hand."
"Return SN to its owner's hand."
);
}
@Override

View File

@ -13,10 +13,17 @@ import magic.model.event.MagicRuleEventAction;
import magic.model.action.MagicRemoveFromPlayAction;
public abstract class MagicWhenLeavesPlayTrigger extends MagicTrigger<MagicRemoveFromPlayAction> {
public static final MagicWhenLeavesPlayTrigger NONE = new MagicWhenLeavesPlayTrigger() {
@Override
public MagicEvent executeTrigger(final MagicGame game,final MagicPermanent permanent, final MagicRemoveFromPlayAction data) {
throw new RuntimeException("executeTrigger called on NONE");
}
};
public MagicWhenLeavesPlayTrigger(final int priority) {
super(priority);
}
public MagicWhenLeavesPlayTrigger() {}
public MagicTriggerType getType() {
@ -33,24 +40,4 @@ public abstract class MagicWhenLeavesPlayTrigger extends MagicTrigger<MagicRemov
return MagicEvent.NONE;
}
};
public static MagicWhenLeavesPlayTrigger createMay(final String rule) {
final MagicSourceEvent sourceEvent = MagicRuleEventAction.createMay(rule);
return new MagicWhenLeavesPlayTrigger() {
@Override
public MagicEvent executeTrigger(final MagicGame game, final MagicPermanent permanent, final MagicRemoveFromPlayAction act) {
return sourceEvent.getEvent(permanent);
}
};
}
public static MagicWhenLeavesPlayTrigger create(final String rule) {
final MagicSourceEvent sourceEvent = MagicRuleEventAction.create(rule);
return new MagicWhenLeavesPlayTrigger() {
@Override
public MagicEvent executeTrigger(final MagicGame game, final MagicPermanent permanent, final MagicRemoveFromPlayAction act) {
return sourceEvent.getEvent(permanent);
}
};
}
}