From c154b872dcae56040ab40b4b005cb1fe7f433331 Mon Sep 17 00:00:00 2001 From: Sloth Date: Wed, 14 Nov 2012 21:37:58 +0000 Subject: [PATCH] - GlobalRuleChange enum now has an associated text. --- .../StaticAbilityContinuous.java | 20 +---------- .../java/forge/game/GlobalRuleChange.java | 34 ++++++++++++++----- 2 files changed, 26 insertions(+), 28 deletions(-) diff --git a/src/main/java/forge/card/staticability/StaticAbilityContinuous.java b/src/main/java/forge/card/staticability/StaticAbilityContinuous.java index 35b9a2ae475..22484680602 100644 --- a/src/main/java/forge/card/staticability/StaticAbilityContinuous.java +++ b/src/main/java/forge/card/staticability/StaticAbilityContinuous.java @@ -95,25 +95,7 @@ public class StaticAbilityContinuous { //Global rules changes if (params.containsKey("GlobalRule")) { final StaticEffects effects = Singletons.getModel().getGame().getStaticEffects(); - if (params.get("GlobalRule").equals("Damage can't be prevented.")) { - effects.setGlobalRuleChange(GlobalRuleChange.noPrevention); - } else if (params.get("GlobalRule").equals("All damage is dealt as though it's source had wither.")) { - effects.setGlobalRuleChange(GlobalRuleChange.alwaysWither); - } else if (params.get("GlobalRule").equals("The legend rule doesn't apply.")) { - effects.setGlobalRuleChange(GlobalRuleChange.noLegendRule); - } else if (params.get("GlobalRule").equals("Mana pools don't empty as steps and phases end.")) { - effects.setGlobalRuleChange(GlobalRuleChange.manapoolsDontEmpty); - } else if (params.get("GlobalRule").equals("Players can't cycle cards.")) { - effects.setGlobalRuleChange(GlobalRuleChange.noCycling); - } else if (params.get("GlobalRule").equals("Creatures entering the battlefield don't cause abilities to trigger.")) { - effects.setGlobalRuleChange(GlobalRuleChange.noCreatureETBTriggers); - } else if (params.get("GlobalRule").equals("No more than one creature can block each combat.")) { - effects.setGlobalRuleChange(GlobalRuleChange.onlyOneBlocker); - } else if (params.get("GlobalRule").equals("No more than one creature can attack each turn.")) { - effects.setGlobalRuleChange(GlobalRuleChange.onlyOneAttackerATurn); - } else if (params.get("GlobalRule").equals("No more than one creature can attack each combat.")) { - effects.setGlobalRuleChange(GlobalRuleChange.onlyOneAttackerACombat); - } + effects.setGlobalRuleChange(GlobalRuleChange.fromString(params.get("GlobalRule"))); } if (params.containsKey("SetPower")) { diff --git a/src/main/java/forge/game/GlobalRuleChange.java b/src/main/java/forge/game/GlobalRuleChange.java index dd45c1a994d..7caec5a12df 100644 --- a/src/main/java/forge/game/GlobalRuleChange.java +++ b/src/main/java/forge/game/GlobalRuleChange.java @@ -22,13 +22,29 @@ package forge.game; */ public enum GlobalRuleChange { - alwaysWither, - manapoolsDontEmpty, - noCycling, - noCreatureETBTriggers, - noLegendRule, - noPrevention, - onlyOneAttackerATurn, - onlyOneAttackerACombat, - onlyOneBlocker + alwaysWither ("All damage is dealt as though it's source had wither."), + manapoolsDontEmpty ("Mana pools don't empty as steps and phases end."), + noCycling ("Players can't cycle cards."), + noCreatureETBTriggers ("Creatures entering the battlefield don't cause abilities to trigger."), + noLegendRule ("The legend rule doesn't apply."), + noPrevention ("Damage can't be prevented."), + onlyOneAttackerATurn ("No more than one creature can attack each turn."), + onlyOneAttackerACombat ("No more than one creature can attack each combat."), + onlyOneBlocker ("No more than one creature can block each combat."); + + private final String ruleText; + + private GlobalRuleChange(String text) { + ruleText = text; + } + + public static GlobalRuleChange fromString(String text) { + for (final GlobalRuleChange v : GlobalRuleChange.values()) { + if (v.ruleText.compareToIgnoreCase(text) == 0) { + return v; + } + } + + throw new RuntimeException("Element " + text + " not found in GlobalRuleChange enum"); + } }