replace multiple abilities with generic ProtectionFromPermanent

master
melvin 2014-08-28 14:19:45 +08:00
parent 60fc96d20b
commit 5ec1750278
6 changed files with 53 additions and 113 deletions

View File

@ -71,25 +71,8 @@ public enum MagicAbility {
ProtectionFromWhite("(protection )?from white(\\.)?",20),
ProtectionFromMonoColored("protection from monocolored",50),
ProtectionFromAllColors("protection from all colors(\\.)?",150),
ProtectionFromCreatures("protection from creatures(\\.)?",100),
ProtectionFromArtifacts("protection from artifacts",50),
ProtectionFromBeasts("protection from beasts",10),
ProtectionFromClerics("protection from Clerics",10),
ProtectionFromDemons("protection from Demons",10),
ProtectionFromDragons("protection from Dragons",10),
ProtectionFromVampires("protection from Vampires",10),
ProtectionFromWerewolves("protection from Werewolves",10),
ProtectionFromColoredSpells("protection from colored spells",100),
ProtectionFromEverything("protection from everything",200),
ProtectionFromZombies("protection from Zombies(\\.)?",10),
ProtectionFromLands("protection from lands",10),
ProtectionFromSpirits("protection from Spirits",10),
ProtectionFromArcane("protection from Arcane",10),
ProtectionFromElves("protection from Elves",10),
ProtectionFromGoblins("protection from Goblins",10),
ProtectionFromKavu("protection from Kavu",10),
ProtectionFromSnow("protection from snow",10),
ProtectionFromLegendaryCreatures("protection from legendary creatures",10),
Reach("reach(\\.)?",20),
Shadow("shadow(\\.)?",30),
Shroud("shroud(\\.)?",60),
@ -1209,9 +1192,16 @@ public enum MagicAbility {
));
}
},
ProtectionFromPermanent("protection from " + ARG.WORDRUN + "(\\.)?", 10) {
protected void addAbilityImpl(final MagicAbilityStore card, final Matcher arg) {
card.add(MagicProtectionTrigger.create(
MagicTargetFilterFactory.multiple(ARG.wordrun(arg))
));
}
}
;
public static final Set<MagicAbility> PROTECTION_FLAGS = EnumSet.range(ProtectionFromBlack, ProtectionFromZombies);
public static final Set<MagicAbility> PROTECTION_FLAGS = EnumSet.range(ProtectionFromBlack, ProtectionFromEverything);
public static final Set<MagicAbility> LANDWALK_FLAGS = EnumSet.range(Plainswalk, NonbasicLandwalk);

View File

@ -22,6 +22,7 @@ import magic.model.target.MagicTarget;
import magic.model.target.MagicTargetFilter;
import magic.model.target.MagicTargetFilterFactory;
import magic.model.trigger.MagicTrigger;
import magic.model.trigger.MagicTriggerType;
import magic.model.trigger.MagicWhenComesIntoPlayTrigger;
import javax.swing.ImageIcon;
@ -841,92 +842,14 @@ public class MagicPermanent extends MagicObjectImpl implements MagicSource,Magic
}
final MagicPermanent permanent = (MagicPermanent)source;
// from creatures
if (permanent.hasType(MagicType.Creature) &&
hasAbility(MagicAbility.ProtectionFromCreatures)) {
return true;
}
// from legendary creatures
if (permanent.hasType(MagicType.Creature) &&
permanent.hasType(MagicType.Legendary) &&
hasAbility(MagicAbility.ProtectionFromLegendaryCreatures)) {
return true;
}
// from Artifacts
if (permanent.hasType(MagicType.Artifact) &&
hasAbility(MagicAbility.ProtectionFromArtifacts)) {
return true;
}
// from Clerics
if (permanent.hasSubType(MagicSubType.Cleric) &&
hasAbility(MagicAbility.ProtectionFromClerics)) {
return true;
}
// from Beasts
if (permanent.hasSubType(MagicSubType.Beast) &&
hasAbility(MagicAbility.ProtectionFromBeasts)) {
return true;
}
// from Demons
if (permanent.hasSubType(MagicSubType.Demon) &&
hasAbility(MagicAbility.ProtectionFromDemons)) {
return true;
}
// from Dragons
if (permanent.hasSubType(MagicSubType.Dragon) &&
hasAbility(MagicAbility.ProtectionFromDragons)) {
return true;
}
// from Vampires
if (permanent.hasSubType(MagicSubType.Vampire) &&
hasAbility(MagicAbility.ProtectionFromVampires)) {
return true;
}
// from Werewolves
if (permanent.hasSubType(MagicSubType.Werewolf) &&
hasAbility(MagicAbility.ProtectionFromWerewolves)) {
return true;
}
// from Zombies
if (permanent.hasSubType(MagicSubType.Zombie) &&
hasAbility(MagicAbility.ProtectionFromZombies)) {
return true;
}
// from Lands
if (permanent.hasType(MagicType.Land) &&
hasAbility(MagicAbility.ProtectionFromLands)) {
return true;
}
// from Spirits
if (permanent.hasSubType(MagicSubType.Spirit) &&
hasAbility(MagicAbility.ProtectionFromSpirits)) {
return true;
}
// from Arcane
if (permanent.hasSubType(MagicSubType.Arcane) &&
hasAbility(MagicAbility.ProtectionFromArcane)) {
return true;
}
// from Elves
if (permanent.hasSubType(MagicSubType.Elf) &&
hasAbility(MagicAbility.ProtectionFromElves)) {
return true;
}
// from Goblins
if (permanent.hasSubType(MagicSubType.Goblin) &&
hasAbility(MagicAbility.ProtectionFromGoblins)) {
return true;
}
// from Kavu
if (permanent.hasSubType(MagicSubType.Kavu) &&
hasAbility(MagicAbility.ProtectionFromKavu)) {
return true;
}
// from Snow
if (permanent.hasType(MagicType.Snow) &&
hasAbility(MagicAbility.ProtectionFromSnow)) {
return true;
for (MagicTrigger<?> trigger: cachedTriggers) {
if (trigger.getType() == MagicTriggerType.Protection) {
final MagicTrigger<MagicPermanent> protection = (MagicTrigger<MagicPermanent>)trigger;
if (protection.accept(this, permanent)) {
return true;
}
}
}
return false;

View File

@ -2444,6 +2444,7 @@ public class MagicTargetFilterFactory {
.replaceAll("\\bslivers\\b", "sliver")
.replaceAll("\\bfaeries\\b", "faerie")
.replaceAll("\\bzombies\\b", "zombie")
.replaceAll("\\bwerewolves\\b", "werewolf")
.replaceAll("\\bface-down creatures\\b", "face-down creature")
.replaceAll("\\btokens\\b", "token")
.replaceAll("\\bhumans\\b", "human")
@ -2460,6 +2461,8 @@ public class MagicTargetFilterFactory {
.replaceAll("\\bmercenaries\\b", "mercenary")
.replaceAll("\\bbirds\\b", "bird")
.replaceAll("\\bbeasts\\b", "beast")
.replaceAll("\\bdemons\\b", "demon")
.replaceAll("\\bdragons\\b", "dragon")
.replaceAll("\\band\\b", "or")
.replaceAll("\\bthem\\b", "it")
.replaceAll("\\bin your hand\\b", "from your hand")

View File

@ -0,0 +1,31 @@
package magic.model.trigger;
import magic.model.MagicGame;
import magic.model.MagicPermanent;
import magic.model.event.MagicEvent;
import magic.model.target.MagicTargetFilter;
public abstract class MagicProtectionTrigger extends MagicTrigger<MagicPermanent> {
public MagicProtectionTrigger(final int priority) {
super(priority);
}
public MagicProtectionTrigger() {}
public MagicTriggerType getType() {
return MagicTriggerType.Protection;
}
public static MagicProtectionTrigger create(final MagicTargetFilter<MagicPermanent> filter) {
return new MagicProtectionTrigger() {
@Override
public boolean accept(final MagicPermanent permanent, final MagicPermanent other) {
return filter.accept(permanent.getGame(), permanent.getController(), other);
}
@Override
public MagicEvent executeTrigger(final MagicGame game,final MagicPermanent permanent, final MagicPermanent other) {
throw new RuntimeException(getClass() + " does not have an executeTrigger method");
}
};
}
}

View File

@ -37,7 +37,8 @@ public enum MagicTriggerType {
IfDamageWouldBeDealt, // item on stack
IfPlayerWouldLose, // player[]
IfLifeWouldChange, // MagicChangeLifeAction
WhenClash // MagicPlayer
WhenClash, // MagicPlayer
Protection, // MagicPermanent
;
public boolean usesStack() {

View File

@ -119,18 +119,10 @@ public class ImageDrawingUtils {
g.drawImage(IconImages.PROTWHITE.getImage(),ax,ay,observer);
ax+=16;
}
if (abilityFlags.contains(MagicAbility.ProtectionFromArtifacts)) {
g.drawImage(IconImages.PROTARTIFACT.getImage(),ax,ay,observer);
ax+=16;
}
if (abilityFlags.contains(MagicAbility.ProtectionFromAllColors)) {
g.drawImage(IconImages.PROTALLCOLORS.getImage(),ax,ay,observer);
ax+=16;
}
if (abilityFlags.contains(MagicAbility.ProtectionFromLands)) {
g.drawImage(IconImages.PROTLAND.getImage(),ax,ay,observer);
ax+=16;
}
if (abilityFlags.contains(MagicAbility.Defender)) {
g.drawImage(IconImages.DEFENDER.getImage(),ax,ay,observer);
ax+=16;