2013-07-09 23:26:56 -07:00
|
|
|
package magic.model.action;
|
|
|
|
|
2015-01-20 02:41:48 -08:00
|
|
|
import java.util.List;
|
|
|
|
import java.util.LinkedList;
|
2015-04-24 18:57:38 -07:00
|
|
|
import java.util.regex.Pattern;
|
2015-01-20 02:41:48 -08:00
|
|
|
|
2014-07-27 18:59:45 -07:00
|
|
|
import magic.model.MagicGame;
|
|
|
|
import magic.model.MagicPlayer;
|
|
|
|
import magic.model.MagicPermanent;
|
|
|
|
import magic.model.MagicPermanentState;
|
|
|
|
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;
|
2015-01-20 02:41:48 -08:00
|
|
|
import magic.model.MagicManaCost;
|
|
|
|
import magic.model.MagicSource;
|
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;
|
2015-01-20 02:41:48 -08:00
|
|
|
import magic.model.event.MagicEvent;
|
|
|
|
import magic.model.event.MagicMorphActivation;
|
|
|
|
import magic.model.event.MagicMatchedCostEvent;
|
|
|
|
import magic.model.event.MagicPayManaCostEvent;
|
2014-07-27 18:59:45 -07:00
|
|
|
|
|
|
|
public enum MagicPlayMod implements MagicPermanentAction {
|
2015-04-10 22:43:42 -07:00
|
|
|
EXILE_AT_END_OF_COMBAT("Exile that token at end of combat") {
|
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") {
|
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") {
|
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") {
|
|
|
|
protected void doAction(final MagicGame game, final MagicPermanent perm) {
|
|
|
|
EXILE_AT_END_OF_YOUR_TURN.doAction(game, perm);
|
|
|
|
}
|
|
|
|
},
|
2015-04-11 02:26:46 -07:00
|
|
|
EXILE_WHEN_LEAVES("If it would leave the battlefield, exile it instead of putting it anywhere else") {
|
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") {
|
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
|
|
|
}
|
|
|
|
},
|
2015-01-18 17:06:16 -08:00
|
|
|
RETURN_AT_END_OF_TURN() {
|
|
|
|
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") {
|
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") {
|
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") {
|
|
|
|
protected void doAction(final MagicGame game, final MagicPermanent perm) {
|
|
|
|
TAPPED.doAction(game, perm);
|
|
|
|
ATTACKING.doAction(game, perm);
|
|
|
|
}
|
|
|
|
},
|
2016-01-22 17:44:43 -08:00
|
|
|
HASTE_UEOT("(it|that creature) gains haste until end of turn") {
|
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:11:05 -07:00
|
|
|
HASTE("(it|that token) gains haste") {
|
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
|
|
|
}
|
|
|
|
},
|
|
|
|
PERSIST() {
|
|
|
|
protected void doAction(final MagicGame game, final MagicPermanent perm) {
|
|
|
|
perm.changeCounters(MagicCounterType.MinusOne,1);
|
|
|
|
}
|
|
|
|
},
|
|
|
|
UNDYING() {
|
|
|
|
protected void doAction(final MagicGame game, final MagicPermanent perm) {
|
|
|
|
perm.changeCounters(MagicCounterType.PlusOne,1);
|
|
|
|
}
|
|
|
|
},
|
2015-06-10 10:22:52 -07:00
|
|
|
DEATH_COUNTER() {
|
|
|
|
protected void doAction(final MagicGame game, final MagicPermanent perm) {
|
|
|
|
perm.changeCounters(MagicCounterType.Death,1);
|
|
|
|
}
|
|
|
|
},
|
2015-12-09 14:22:23 -08:00
|
|
|
ARTIFACT() {
|
|
|
|
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() {
|
|
|
|
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
|
|
|
}
|
|
|
|
},
|
2015-04-24 20:28:58 -07:00
|
|
|
BLACK_ZOMBIE("It is a black Zombie in addition to its other colors and types") {
|
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") {
|
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() {
|
|
|
|
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() {
|
|
|
|
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
|
|
|
}
|
|
|
|
},
|
2014-08-03 05:11:17 -07:00
|
|
|
MORPH() {
|
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
|
|
|
}
|
|
|
|
},
|
2014-08-05 15:04:25 -07:00
|
|
|
FLIPPED() {
|
|
|
|
protected void doAction(final MagicGame game, final MagicPermanent perm) {
|
|
|
|
perm.setState(MagicPermanentState.Flipped);
|
|
|
|
}
|
|
|
|
},
|
2014-08-06 09:16:00 -07:00
|
|
|
TRANSFORMED() {
|
|
|
|
protected void doAction(final MagicGame game, final MagicPermanent perm) {
|
|
|
|
perm.setState(MagicPermanentState.Transformed);
|
|
|
|
}
|
|
|
|
},
|
2014-07-27 18:59:45 -07:00
|
|
|
NONE() {
|
|
|
|
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
|
|
|
}
|
|
|
|
|
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
|
|
|
}
|