magarena/src/magic/model/action/MagicPlayMod.java

253 lines
9.5 KiB
Java
Raw Normal View History

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;
import magic.model.MagicAbility;
2015-01-20 02:41:48 -08:00
import magic.model.MagicAbilityList;
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;
import magic.model.condition.MagicConditionFactory;
2016-06-17 04:45:33 -07:00
import magic.model.event.MagicMorphActivation;
import magic.model.mstatic.MagicStatic;
import magic.model.trigger.AtEndOfCombatTrigger;
import magic.model.trigger.AtEndOfTurnTrigger;
import magic.model.trigger.LeavesBattlefieldTrigger;
public enum MagicPlayMod implements MagicPermanentAction {
EXILE_AT_END_OF_COMBAT("Exile (that|the) token at end of combat") {
@Override
protected void doAction(final MagicGame game, final MagicPermanent perm) {
game.doAction(new AddTriggerAction(perm, AtEndOfCombatTrigger.Exile));
}
},
EXILE_AT_END_OF_TURN("Exile (it|them|that token) at the beginning of the next end step") {
@Override
protected void doAction(final MagicGame game, final MagicPermanent perm) {
game.doAction(new AddTriggerAction(perm, AtEndOfTurnTrigger.ExileAtEnd));
}
},
2015-04-24 08:15:47 -07:00
EXILE_AT_END_OF_YOUR_TURN("Exile it at the beginning of your next end step") {
@Override
protected void doAction(final MagicGame game, final MagicPermanent perm) {
final MagicPlayer controller = perm.getController();
game.doAction(new AddTriggerAction(perm, AtEndOfTurnTrigger.ExileAtYourEnd(controller)));
}
},
2015-04-24 19:11:47 -07:00
EXILE_AT_END_OF_YOUR_TURN2("At the beginning of your next end step, exile it") {
@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") {
@Override
protected void doAction(final MagicGame game, final MagicPermanent perm) {
game.doAction(new AddTriggerAction(perm, LeavesBattlefieldTrigger.Exile));
}
},
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") {
@Override
protected void doAction(final MagicGame game, final MagicPermanent perm) {
game.doAction(new AddTriggerAction(perm, AtEndOfTurnTrigger.Sacrifice));
}
},
2016-06-17 04:45:33 -07:00
SACRIFICE_AT_END_OF_COMBAT("Sacrifice (it|the token) at end of combat") {
@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));
}
},
DESTROY_AT_END_OF_TURN("Destroy (it|those tokens) at the beginning of the next end step") {
@Override
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") {
@Override
protected void doAction(final MagicGame game, final MagicPermanent perm) {
game.doAction(new AddTriggerAction(perm, AtEndOfTurnTrigger.Return));
}
},
2015-04-10 22:43:42 -07:00
ATTACKING("attacking") {
@Override
protected void doAction(final MagicGame game, final MagicPermanent perm) {
perm.setState(MagicPermanentState.Attacking);
}
},
2015-04-10 22:43:42 -07:00
TAPPED("tapped") {
@Override
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") {
@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);
}
},
HASTE_UEOT("(it|that " + ARG.WORD1 + ") gains haste until end of turn") {
@Override
protected void doAction(final MagicGame game, final MagicPermanent perm) {
game.doAction(new GainAbilityAction(perm, MagicAbility.Haste));
}
},
2016-06-04 05:31:10 -07:00
HASTE("(it|that token) (gains|has) haste") {
@Override
protected void doAction(final MagicGame game, final MagicPermanent perm) {
game.doAction(new GainAbilityAction(perm, MagicAbility.Haste, MagicStatic.Forever));
}
},
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())
)));
}
},
PERSIST() {
@Override
protected void doAction(final MagicGame game, final MagicPermanent perm) {
perm.changeCounters(MagicCounterType.MinusOne,1);
}
},
UNDYING() {
@Override
protected void doAction(final MagicGame game, final MagicPermanent perm) {
perm.changeCounters(MagicCounterType.PlusOne,1);
}
},
2015-06-10 10:22:52 -07:00
DEATH_COUNTER() {
@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() {
@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));
}
},
ZOMBIE() {
@Override
protected void doAction(final MagicGame game, final MagicPermanent perm) {
game.doAction(new AddStaticAction(perm, MagicStatic.Zombie));
}
},
2016-09-22 07:26:40 -07:00
SPIRIT() {
@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));
}
},
BLACK_ZOMBIE("(it|that creature) is a black Zombie in addition to its other colors and types") {
@Override
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") {
@Override
protected void doAction(final MagicGame game, final MagicPermanent perm) {
2015-04-24 20:28:58 -07:00
game.doAction(new AddStaticAction(perm, MagicStatic.IsBlack));
game.doAction(new AddStaticAction(perm, MagicStatic.Nightmare));
}
},
BESTOWED() {
@Override
protected void doAction(final MagicGame game, final MagicPermanent perm) {
game.doAction(new AddStaticAction(perm, MagicStatic.Bestowed));
}
},
2015-01-20 02:41:48 -08:00
MANIFEST() {
@Override
2015-01-20 02:41:48 -08:00
protected void doAction(final MagicGame game, final MagicPermanent perm) {
if (perm.isCreature() && perm.getCardDefinition().hasCost()) {
2015-01-20 02:41:48 -08:00
final MagicAbilityList morphAct = new MagicAbilityList();
morphAct.add(MagicMorphActivation.Manifest);
game.doAction(new GainAbilityAction(perm, morphAct, MagicStatic.Forever));
2015-01-20 02:41:48 -08:00
}
perm.setState(MagicPermanentState.FaceDown);
perm.setState(MagicPermanentState.Manifest);
2015-01-20 02:41:48 -08:00
}
},
MORPH("face down") {
@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") {
@Override
protected void doAction(final MagicGame game, final MagicPermanent perm) {
perm.setState(MagicPermanentState.Flipped);
}
},
2014-08-06 09:16:00 -07:00
TRANSFORMED() {
@Override
2014-08-06 09:16:00 -07:00
protected void doAction(final MagicGame game, final MagicPermanent perm) {
perm.setState(MagicPermanentState.Transformed);
}
},
NONE() {
@Override
protected void doAction(final MagicGame game, final MagicPermanent perm) {
}
},
;
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() {
this("NONE");
2015-04-10 22:43:42 -07:00
}
@Override
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
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()) {
return mod;
}
}
throw new RuntimeException("unknown play mod \"" + name + "\"");
}
2015-06-10 10:22:52 -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];
final List<MagicPlayMod> mods = new LinkedList<>();
for (final String name : tokens) {
mods.add(MagicPlayMod.getPlayMod(name));
}
return mods;
}
}