2013-07-09 23:26:56 -07:00
|
|
|
package magic.model.action;
|
|
|
|
|
2015-01-20 02:41:48 -08:00
|
|
|
import java.util.LinkedList;
|
2016-06-17 04:45:33 -07:00
|
|
|
import java.util.List;
|
2015-04-24 18:57:38 -07:00
|
|
|
import java.util.regex.Pattern;
|
2015-01-20 02:41:48 -08:00
|
|
|
|
2020-01-15 12:02:42 -08:00
|
|
|
import magic.model.ARG;
|
2014-07-27 18:59:45 -07:00
|
|
|
import magic.model.MagicAbility;
|
2015-01-20 02:41:48 -08:00
|
|
|
import magic.model.MagicAbilityList;
|
2014-07-27 18:59:45 -07:00
|
|
|
import magic.model.MagicCounterType;
|
2016-06-17 04:45:33 -07:00
|
|
|
import magic.model.MagicGame;
|
|
|
|
import magic.model.MagicPermanent;
|
|
|
|
import magic.model.MagicPermanentState;
|
|
|
|
import magic.model.MagicPlayer;
|
2017-08-06 21:09:49 -07:00
|
|
|
import magic.model.condition.MagicConditionFactory;
|
2016-06-17 04:45:33 -07:00
|
|
|
import magic.model.event.MagicMorphActivation;
|
2014-07-27 18:59:45 -07:00
|
|
|
import magic.model.mstatic.MagicStatic;
|
2015-11-20 17:42:52 -08:00
|
|
|
import magic.model.trigger.AtEndOfCombatTrigger;
|
2015-11-20 17:48:46 -08:00
|
|
|
import magic.model.trigger.AtEndOfTurnTrigger;
|
2015-11-22 07:29:16 -08:00
|
|
|
import magic.model.trigger.LeavesBattlefieldTrigger;
|
2014-07-27 18:59:45 -07:00
|
|
|
|
|
|
|
public enum MagicPlayMod implements MagicPermanentAction {
|
2016-06-09 04:44:26 -07:00
|
|
|
EXILE_AT_END_OF_COMBAT("Exile (that|the) token at end of combat") {
|
2017-06-16 20:19:03 -07:00
|
|
|
@Override
|
2014-07-27 18:59:45 -07:00
|
|
|
protected void doAction(final MagicGame game, final MagicPermanent perm) {
|
2015-11-20 17:42:52 -08:00
|
|
|
game.doAction(new AddTriggerAction(perm, AtEndOfCombatTrigger.Exile));
|
2014-07-27 18:59:45 -07:00
|
|
|
}
|
|
|
|
},
|
2015-11-17 11:12:00 -08:00
|
|
|
EXILE_AT_END_OF_TURN("Exile (it|them|that token) at the beginning of the next end step") {
|
2017-06-16 20:19:03 -07:00
|
|
|
@Override
|
2014-07-27 18:59:45 -07:00
|
|
|
protected void doAction(final MagicGame game, final MagicPermanent perm) {
|
2015-11-20 17:48:46 -08:00
|
|
|
game.doAction(new AddTriggerAction(perm, AtEndOfTurnTrigger.ExileAtEnd));
|
2014-07-27 18:59:45 -07:00
|
|
|
}
|
|
|
|
},
|
2015-04-24 08:15:47 -07:00
|
|
|
EXILE_AT_END_OF_YOUR_TURN("Exile it at the beginning of your next end step") {
|
2017-06-16 20:19:03 -07:00
|
|
|
@Override
|
2014-07-27 18:59:45 -07:00
|
|
|
protected void doAction(final MagicGame game, final MagicPermanent perm) {
|
|
|
|
final MagicPlayer controller = perm.getController();
|
2015-11-20 17:48:46 -08:00
|
|
|
game.doAction(new AddTriggerAction(perm, AtEndOfTurnTrigger.ExileAtYourEnd(controller)));
|
2014-07-27 18:59:45 -07:00
|
|
|
}
|
|
|
|
},
|
2015-04-24 19:11:47 -07:00
|
|
|
EXILE_AT_END_OF_YOUR_TURN2("At the beginning of your next end step, exile it") {
|
2017-06-16 20:19:03 -07:00
|
|
|
@Override
|
2015-04-24 19:11:47 -07:00
|
|
|
protected void doAction(final MagicGame game, final MagicPermanent perm) {
|
|
|
|
EXILE_AT_END_OF_YOUR_TURN.doAction(game, perm);
|
|
|
|
}
|
|
|
|
},
|
2017-07-19 19:42:24 -07:00
|
|
|
EXILE_WHEN_LEAVES("If (it|that creature) would leave the battlefield, exile it instead of putting it anywhere else") {
|
2017-06-16 20:19:03 -07:00
|
|
|
@Override
|
2014-07-27 18:59:45 -07:00
|
|
|
protected void doAction(final MagicGame game, final MagicPermanent perm) {
|
2015-11-22 07:29:16 -08:00
|
|
|
game.doAction(new AddTriggerAction(perm, LeavesBattlefieldTrigger.Exile));
|
2014-07-27 18:59:45 -07:00
|
|
|
}
|
|
|
|
},
|
2015-04-24 19:11:47 -07:00
|
|
|
SACRIFICE_AT_END_OF_TURN("Sacrifice (it|those tokens) at the beginning of the next end step") {
|
2017-06-16 20:19:03 -07:00
|
|
|
@Override
|
2014-07-27 18:59:45 -07:00
|
|
|
protected void doAction(final MagicGame game, final MagicPermanent perm) {
|
2015-11-20 17:48:46 -08:00
|
|
|
game.doAction(new AddTriggerAction(perm, AtEndOfTurnTrigger.Sacrifice));
|
2014-07-27 18:59:45 -07:00
|
|
|
}
|
|
|
|
},
|
2016-06-17 04:45:33 -07:00
|
|
|
SACRIFICE_AT_END_OF_COMBAT("Sacrifice (it|the token) at end of combat") {
|
2017-06-16 20:19:03 -07:00
|
|
|
@Override
|
2016-06-17 04:45:33 -07:00
|
|
|
protected void doAction(final MagicGame game, final MagicPermanent perm) {
|
|
|
|
game.doAction(new AddTriggerAction(perm, AtEndOfCombatTrigger.Sacrifice));
|
|
|
|
}
|
|
|
|
},
|
2016-06-09 05:58:31 -07:00
|
|
|
DESTROY_AT_END_OF_TURN("Destroy (it|those tokens) at the beginning of the next end step") {
|
2017-06-16 20:19:03 -07:00
|
|
|
@Override
|
2016-06-09 05:58:31 -07:00
|
|
|
protected void doAction(final MagicGame game, final MagicPermanent perm) {
|
|
|
|
game.doAction(new AddTriggerAction(perm, AtEndOfTurnTrigger.Destroy));
|
|
|
|
}
|
|
|
|
},
|
2017-07-20 21:05:20 -07:00
|
|
|
RETURN_AT_END_OF_TURN("Return it to your hand at the beginning of the next end step") {
|
2017-06-16 20:19:03 -07:00
|
|
|
@Override
|
2015-01-18 17:06:16 -08:00
|
|
|
protected void doAction(final MagicGame game, final MagicPermanent perm) {
|
2015-11-20 17:48:46 -08:00
|
|
|
game.doAction(new AddTriggerAction(perm, AtEndOfTurnTrigger.Return));
|
2015-01-18 17:06:16 -08:00
|
|
|
}
|
|
|
|
},
|
2015-04-10 22:43:42 -07:00
|
|
|
ATTACKING("attacking") {
|
2017-06-16 20:19:03 -07:00
|
|
|
@Override
|
2014-07-27 18:59:45 -07:00
|
|
|
protected void doAction(final MagicGame game, final MagicPermanent perm) {
|
|
|
|
perm.setState(MagicPermanentState.Attacking);
|
|
|
|
}
|
|
|
|
},
|
2015-04-10 22:43:42 -07:00
|
|
|
TAPPED("tapped") {
|
2017-06-16 20:19:03 -07:00
|
|
|
@Override
|
2014-07-27 18:59:45 -07:00
|
|
|
protected void doAction(final MagicGame game, final MagicPermanent perm) {
|
|
|
|
perm.setState(MagicPermanentState.Tapped);
|
|
|
|
}
|
|
|
|
},
|
2015-04-24 20:28:58 -07:00
|
|
|
TAPPED_AND_ATTACKING("tapped and attacking") {
|
2017-06-16 20:19:03 -07:00
|
|
|
@Override
|
2015-04-24 20:28:58 -07:00
|
|
|
protected void doAction(final MagicGame game, final MagicPermanent perm) {
|
|
|
|
TAPPED.doAction(game, perm);
|
|
|
|
ATTACKING.doAction(game, perm);
|
|
|
|
}
|
|
|
|
},
|
2016-10-04 17:16:12 -07:00
|
|
|
HASTE_UEOT("(it|that " + ARG.WORD1 + ") gains haste until end of turn") {
|
2017-06-16 20:19:03 -07:00
|
|
|
@Override
|
2014-07-27 18:59:45 -07:00
|
|
|
protected void doAction(final MagicGame game, final MagicPermanent perm) {
|
2015-04-14 03:53:13 -07:00
|
|
|
game.doAction(new GainAbilityAction(perm, MagicAbility.Haste));
|
2014-07-27 18:59:45 -07:00
|
|
|
}
|
|
|
|
},
|
2016-06-04 05:31:10 -07:00
|
|
|
HASTE("(it|that token) (gains|has) haste") {
|
2017-06-16 20:19:03 -07:00
|
|
|
@Override
|
2014-07-27 18:59:45 -07:00
|
|
|
protected void doAction(final MagicGame game, final MagicPermanent perm) {
|
2015-04-14 03:53:13 -07:00
|
|
|
game.doAction(new GainAbilityAction(perm, MagicAbility.Haste, MagicStatic.Forever));
|
2014-07-27 18:59:45 -07:00
|
|
|
}
|
|
|
|
},
|
2017-08-06 21:09:49 -07:00
|
|
|
HASTE_SUSPEND() {
|
|
|
|
@Override
|
|
|
|
protected void doAction(final MagicGame game, final MagicPermanent perm) {
|
|
|
|
game.doAction(new AddStaticAction(perm, MagicStatic.AsLongAsCond(
|
|
|
|
perm,
|
|
|
|
MagicAbility.Haste,
|
|
|
|
MagicConditionFactory.PlayerControlsSource(perm.getController())
|
|
|
|
)));
|
|
|
|
}
|
|
|
|
},
|
2014-07-27 18:59:45 -07:00
|
|
|
PERSIST() {
|
2017-06-16 20:19:03 -07:00
|
|
|
@Override
|
2014-07-27 18:59:45 -07:00
|
|
|
protected void doAction(final MagicGame game, final MagicPermanent perm) {
|
|
|
|
perm.changeCounters(MagicCounterType.MinusOne,1);
|
|
|
|
}
|
|
|
|
},
|
|
|
|
UNDYING() {
|
2017-06-16 20:19:03 -07:00
|
|
|
@Override
|
2014-07-27 18:59:45 -07:00
|
|
|
protected void doAction(final MagicGame game, final MagicPermanent perm) {
|
|
|
|
perm.changeCounters(MagicCounterType.PlusOne,1);
|
|
|
|
}
|
|
|
|
},
|
2015-06-10 10:22:52 -07:00
|
|
|
DEATH_COUNTER() {
|
2017-06-16 20:19:03 -07:00
|
|
|
@Override
|
2015-06-10 10:22:52 -07:00
|
|
|
protected void doAction(final MagicGame game, final MagicPermanent perm) {
|
|
|
|
perm.changeCounters(MagicCounterType.Death,1);
|
|
|
|
}
|
|
|
|
},
|
2018-11-08 13:40:37 -08:00
|
|
|
CORPSE_COUNTER() {
|
|
|
|
@Override
|
|
|
|
protected void doAction(final MagicGame game, final MagicPermanent perm) {
|
|
|
|
perm.changeCounters(MagicCounterType.Corpse,1);
|
|
|
|
}
|
|
|
|
},
|
2015-12-09 14:22:23 -08:00
|
|
|
ARTIFACT() {
|
2017-06-16 20:19:03 -07:00
|
|
|
@Override
|
2015-12-09 14:22:23 -08:00
|
|
|
protected void doAction(final MagicGame game, final MagicPermanent perm) {
|
|
|
|
game.doAction(new AddStaticAction(perm, MagicStatic.Artifact));
|
|
|
|
}
|
|
|
|
},
|
2014-07-27 18:59:45 -07:00
|
|
|
ZOMBIE() {
|
2017-06-16 20:19:03 -07:00
|
|
|
@Override
|
2014-07-27 18:59:45 -07:00
|
|
|
protected void doAction(final MagicGame game, final MagicPermanent perm) {
|
2015-04-13 00:12:57 -07:00
|
|
|
game.doAction(new AddStaticAction(perm, MagicStatic.Zombie));
|
2014-07-27 18:59:45 -07:00
|
|
|
}
|
|
|
|
},
|
2016-09-22 07:26:40 -07:00
|
|
|
SPIRIT() {
|
2017-06-16 20:19:03 -07:00
|
|
|
@Override
|
2016-09-22 07:26:40 -07:00
|
|
|
protected void doAction(final MagicGame game, final MagicPermanent perm) {
|
|
|
|
game.doAction(new AddStaticAction(perm, MagicStatic.Spirit));
|
|
|
|
}
|
|
|
|
},
|
2016-09-09 08:36:03 -07:00
|
|
|
BLACK_ZOMBIE("(it|that creature) is a black Zombie in addition to its other colors and types") {
|
2017-06-16 20:19:03 -07:00
|
|
|
@Override
|
2015-04-24 18:38:43 -07:00
|
|
|
protected void doAction(final MagicGame game, final MagicPermanent perm) {
|
|
|
|
game.doAction(new AddStaticAction(perm, MagicStatic.AddBlack));
|
|
|
|
game.doAction(new AddStaticAction(perm, MagicStatic.Zombie));
|
|
|
|
}
|
|
|
|
},
|
2015-04-24 20:28:58 -07:00
|
|
|
BLACK_NIGHTMARE("It is black and is a Nightmare in addition to its other creature types") {
|
2017-06-16 20:19:03 -07:00
|
|
|
@Override
|
2014-07-27 18:59:45 -07:00
|
|
|
protected void doAction(final MagicGame game, final MagicPermanent perm) {
|
2015-04-24 20:28:58 -07:00
|
|
|
game.doAction(new AddStaticAction(perm, MagicStatic.IsBlack));
|
2015-04-13 00:12:57 -07:00
|
|
|
game.doAction(new AddStaticAction(perm, MagicStatic.Nightmare));
|
2014-07-27 18:59:45 -07:00
|
|
|
}
|
|
|
|
},
|
|
|
|
BESTOWED() {
|
2017-06-16 20:19:03 -07:00
|
|
|
@Override
|
2014-07-27 18:59:45 -07:00
|
|
|
protected void doAction(final MagicGame game, final MagicPermanent perm) {
|
2015-04-13 00:12:57 -07:00
|
|
|
game.doAction(new AddStaticAction(perm, MagicStatic.Bestowed));
|
2014-07-27 18:59:45 -07:00
|
|
|
}
|
|
|
|
},
|
2015-01-20 02:41:48 -08:00
|
|
|
MANIFEST() {
|
2017-06-16 20:19:03 -07:00
|
|
|
@Override
|
2015-01-20 02:41:48 -08:00
|
|
|
protected void doAction(final MagicGame game, final MagicPermanent perm) {
|
2016-02-03 19:24:29 -08:00
|
|
|
if (perm.isCreature() && perm.getCardDefinition().hasCost()) {
|
2015-01-20 02:41:48 -08:00
|
|
|
final MagicAbilityList morphAct = new MagicAbilityList();
|
2016-02-03 19:16:08 -08:00
|
|
|
morphAct.add(MagicMorphActivation.Manifest);
|
2015-04-14 03:53:13 -07:00
|
|
|
game.doAction(new GainAbilityAction(perm, morphAct, MagicStatic.Forever));
|
2015-01-20 02:41:48 -08:00
|
|
|
}
|
|
|
|
perm.setState(MagicPermanentState.FaceDown);
|
2015-09-08 06:28:29 -07:00
|
|
|
perm.setState(MagicPermanentState.Manifest);
|
2015-01-20 02:41:48 -08:00
|
|
|
}
|
|
|
|
},
|
2017-06-29 09:53:50 -07:00
|
|
|
MORPH("face down") {
|
2017-06-16 20:19:03 -07:00
|
|
|
@Override
|
2014-07-28 04:57:19 -07:00
|
|
|
protected void doAction(final MagicGame game, final MagicPermanent perm) {
|
2014-07-31 09:32:22 -07:00
|
|
|
perm.setState(MagicPermanentState.FaceDown);
|
2014-07-28 04:57:19 -07:00
|
|
|
}
|
|
|
|
},
|
2016-12-06 17:51:03 -08:00
|
|
|
FLIPPED("flipped") {
|
2017-06-16 20:19:03 -07:00
|
|
|
@Override
|
2014-08-05 15:04:25 -07:00
|
|
|
protected void doAction(final MagicGame game, final MagicPermanent perm) {
|
|
|
|
perm.setState(MagicPermanentState.Flipped);
|
|
|
|
}
|
|
|
|
},
|
2014-08-06 09:16:00 -07:00
|
|
|
TRANSFORMED() {
|
2017-06-16 20:19:03 -07:00
|
|
|
@Override
|
2014-08-06 09:16:00 -07:00
|
|
|
protected void doAction(final MagicGame game, final MagicPermanent perm) {
|
|
|
|
perm.setState(MagicPermanentState.Transformed);
|
|
|
|
}
|
|
|
|
},
|
2014-07-27 18:59:45 -07:00
|
|
|
NONE() {
|
2017-06-16 20:19:03 -07:00
|
|
|
@Override
|
2014-07-27 18:59:45 -07:00
|
|
|
protected void doAction(final MagicGame game, final MagicPermanent perm) {
|
|
|
|
}
|
|
|
|
},
|
|
|
|
;
|
2015-04-10 22:14:13 -07:00
|
|
|
|
2015-04-24 18:57:38 -07:00
|
|
|
private final Pattern pattern;
|
2015-04-10 22:43:42 -07:00
|
|
|
|
2015-04-24 18:57:38 -07:00
|
|
|
private MagicPlayMod(final String regex) {
|
|
|
|
pattern = Pattern.compile(regex, Pattern.CASE_INSENSITIVE);
|
2015-04-10 22:43:42 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
private MagicPlayMod() {
|
2015-05-12 21:26:51 -07:00
|
|
|
this("NONE");
|
2015-04-10 22:43:42 -07:00
|
|
|
}
|
|
|
|
|
2017-06-16 20:19:03 -07:00
|
|
|
@Override
|
2014-07-27 18:59:45 -07:00
|
|
|
public void doAction(final MagicPermanent perm) {
|
|
|
|
doAction(perm.getGame(), perm);
|
|
|
|
}
|
|
|
|
|
|
|
|
abstract protected void doAction(final MagicGame game, final MagicPermanent perm);
|
2015-06-10 10:22:52 -07:00
|
|
|
|
2015-04-10 22:14:13 -07:00
|
|
|
public static MagicPlayMod getPlayMod(final String name) {
|
|
|
|
for (final MagicPlayMod mod : values()) {
|
2015-04-24 18:57:38 -07:00
|
|
|
if (mod.pattern.matcher(name).matches()) {
|
2015-04-10 22:14:13 -07:00
|
|
|
return mod;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
throw new RuntimeException("unknown play mod \"" + name + "\"");
|
|
|
|
}
|
2015-06-10 10:22:52 -07:00
|
|
|
|
2015-04-10 22:14:13 -07:00
|
|
|
public static List<MagicPlayMod> build(final String text) {
|
2015-04-24 20:28:58 -07:00
|
|
|
final String[] tokens = text != null ? text.split("\\. ") : new String[0];
|
2015-04-10 22:14:13 -07:00
|
|
|
final List<MagicPlayMod> mods = new LinkedList<>();
|
|
|
|
for (final String name : tokens) {
|
|
|
|
mods.add(MagicPlayMod.getPlayMod(name));
|
|
|
|
}
|
|
|
|
return mods;
|
|
|
|
}
|
2013-07-09 23:26:56 -07:00
|
|
|
}
|