From 80b61ccbd62d554bd17c5420313fb097349bd320 Mon Sep 17 00:00:00 2001 From: Evan Kranzler Date: Fri, 8 Sep 2017 09:31:06 -0400 Subject: [PATCH] Refactored more subtypes usages to enum --- .../src/mage/cards/c/ConvincingMirage.java | 15 ++++---- .../src/mage/cards/e/ElsewhereFlask.java | 13 ++++--- .../src/mage/cards/p/PhantasmalTerrain.java | 15 ++++---- Mage.Sets/src/mage/cards/r/Realmwright.java | 15 ++++---- Mage.Sets/src/mage/cards/t/Terraformer.java | 13 ++++--- Mage.Sets/src/mage/cards/v/VisionCharm.java | 35 +++++++++---------- 6 files changed, 50 insertions(+), 56 deletions(-) diff --git a/Mage.Sets/src/mage/cards/c/ConvincingMirage.java b/Mage.Sets/src/mage/cards/c/ConvincingMirage.java index 807b40af3d4..cbb6f52f9e2 100644 --- a/Mage.Sets/src/mage/cards/c/ConvincingMirage.java +++ b/Mage.Sets/src/mage/cards/c/ConvincingMirage.java @@ -51,7 +51,7 @@ import mage.target.common.TargetLandPermanent; public class ConvincingMirage extends CardImpl { public ConvincingMirage(UUID ownerId, CardSetInfo setInfo) { - super(ownerId,setInfo,new CardType[]{CardType.ENCHANTMENT},"{1}{U}"); + super(ownerId, setInfo, new CardType[]{CardType.ENCHANTMENT}, "{1}{U}"); this.subtype.add(SubType.AURA); // Enchant land @@ -95,8 +95,7 @@ class ConvincingMirageContinousEffect extends ContinuousEffectImpl { @Override public boolean apply(Layer layer, SubLayer sublayer, Ability source, Game game) { Permanent enchantment = game.getPermanent(source.getSourceId()); - // TODO fix to use SubType enum - String choice = (String) game.getState().getValue(source.getSourceId().toString() + ChooseBasicLandTypeEffect.VALUE_KEY); + SubType choice = SubType.byDescription((String) game.getState().getValue(source.getSourceId().toString() + ChooseBasicLandTypeEffect.VALUE_KEY)); if (enchantment != null && enchantment.getAttachedTo() != null && choice != null) { Permanent land = game.getPermanent(enchantment.getAttachedTo()); if (land != null) { @@ -110,19 +109,19 @@ class ConvincingMirageContinousEffect extends ContinuousEffectImpl { case AbilityAddingRemovingEffects_6: if (sublayer == SubLayer.NA) { land.getAbilities().clear(); - if (choice.equals("Forest")) { + if (choice.equals(SubType.FOREST)) { land.addAbility(new GreenManaAbility(), source.getSourceId(), game); } - if (choice.equals("Plains")) { + if (choice.equals(SubType.PLAINS)) { land.addAbility(new WhiteManaAbility(), source.getSourceId(), game); } - if (choice.equals("Mountain")) { + if (choice.equals(SubType.MOUNTAIN)) { land.addAbility(new RedManaAbility(), source.getSourceId(), game); } - if (choice.equals("Island")) { + if (choice.equals(SubType.ISLAND)) { land.addAbility(new BlueManaAbility(), source.getSourceId(), game); } - if (choice.equals("Swamp")) { + if (choice.equals(SubType.SWAMP)) { land.addAbility(new BlackManaAbility(), source.getSourceId(), game); } } diff --git a/Mage.Sets/src/mage/cards/e/ElsewhereFlask.java b/Mage.Sets/src/mage/cards/e/ElsewhereFlask.java index 4271e123790..7637054ca7b 100644 --- a/Mage.Sets/src/mage/cards/e/ElsewhereFlask.java +++ b/Mage.Sets/src/mage/cards/e/ElsewhereFlask.java @@ -135,8 +135,7 @@ class ElsewhereFlaskContinuousEffect extends ContinuousEffectImpl { @Override public boolean apply(Layer layer, SubLayer sublayer, Ability source, Game game) { - // TODO fix to use SubType enum - String choice = (String) game.getState().getValue(source.getSourceId().toString() + "_ElsewhereFlask"); + SubType choice = SubType.byDescription((String) game.getState().getValue(source.getSourceId().toString() + "_ElsewhereFlask")); if (choice != null) { for (Iterator it = affectedObjectList.iterator(); it.hasNext();) { Permanent land = it.next().getPermanent(game); @@ -151,19 +150,19 @@ class ElsewhereFlaskContinuousEffect extends ContinuousEffectImpl { case AbilityAddingRemovingEffects_6: if (sublayer == SubLayer.NA) { land.getAbilities().clear(); - if (choice.equals("Forest")) { + if (choice.equals(SubType.FOREST)) { land.addAbility(new GreenManaAbility(), source.getSourceId(), game); } - if (choice.equals("Plains")) { + if (choice.equals(SubType.PLAINS)) { land.addAbility(new WhiteManaAbility(), source.getSourceId(), game); } - if (choice.equals("Mountain")) { + if (choice.equals(SubType.MOUNTAIN)) { land.addAbility(new RedManaAbility(), source.getSourceId(), game); } - if (choice.equals("Island")) { + if (choice.equals(SubType.ISLAND)) { land.addAbility(new BlueManaAbility(), source.getSourceId(), game); } - if (choice.equals("Swamp")) { + if (choice.equals(SubType.SWAMP)) { land.addAbility(new BlackManaAbility(), source.getSourceId(), game); } } diff --git a/Mage.Sets/src/mage/cards/p/PhantasmalTerrain.java b/Mage.Sets/src/mage/cards/p/PhantasmalTerrain.java index 8e382bdcff8..08978c7c131 100644 --- a/Mage.Sets/src/mage/cards/p/PhantasmalTerrain.java +++ b/Mage.Sets/src/mage/cards/p/PhantasmalTerrain.java @@ -61,7 +61,7 @@ import mage.target.common.TargetLandPermanent; public class PhantasmalTerrain extends CardImpl { public PhantasmalTerrain(UUID ownerId, CardSetInfo setInfo) { - super(ownerId,setInfo,new CardType[]{CardType.ENCHANTMENT},"{U}{U}"); + super(ownerId, setInfo, new CardType[]{CardType.ENCHANTMENT}, "{U}{U}"); this.subtype.add(SubType.AURA); // Enchant land @@ -105,9 +105,8 @@ class PhantasmalTerrainContinuousEffect extends ContinuousEffectImpl { @Override public boolean apply(Layer layer, SubLayer sublayer, Ability source, Game game) { - // TODO fix to use SubType enum Permanent enchantment = game.getPermanent(source.getSourceId()); - String choice = (String) game.getState().getValue(source.getSourceId().toString() + ChooseBasicLandTypeEffect.VALUE_KEY); + SubType choice = SubType.byDescription((String) game.getState().getValue(source.getSourceId().toString() + ChooseBasicLandTypeEffect.VALUE_KEY)); if (enchantment != null && enchantment.getAttachedTo() != null && choice != null) { Permanent land = game.getPermanent(enchantment.getAttachedTo()); if (land != null) { @@ -121,19 +120,19 @@ class PhantasmalTerrainContinuousEffect extends ContinuousEffectImpl { case AbilityAddingRemovingEffects_6: if (sublayer == SubLayer.NA) { land.getAbilities().clear(); - if (choice.equals("Forest")) { + if (choice.equals(SubType.FOREST)) { land.addAbility(new GreenManaAbility(), source.getSourceId(), game); } - if (choice.equals("Plains")) { + if (choice.equals(SubType.PLAINS)) { land.addAbility(new WhiteManaAbility(), source.getSourceId(), game); } - if (choice.equals("Mountain")) { + if (choice.equals(SubType.MOUNTAIN)) { land.addAbility(new RedManaAbility(), source.getSourceId(), game); } - if (choice.equals("Island")) { + if (choice.equals(SubType.ISLAND)) { land.addAbility(new BlueManaAbility(), source.getSourceId(), game); } - if (choice.equals("Swamp")) { + if (choice.equals(SubType.SWAMP)) { land.addAbility(new BlackManaAbility(), source.getSourceId(), game); } } diff --git a/Mage.Sets/src/mage/cards/r/Realmwright.java b/Mage.Sets/src/mage/cards/r/Realmwright.java index 1cbbeb5066b..af22570bc88 100644 --- a/Mage.Sets/src/mage/cards/r/Realmwright.java +++ b/Mage.Sets/src/mage/cards/r/Realmwright.java @@ -61,7 +61,7 @@ import mage.players.Player; public class Realmwright extends CardImpl { public Realmwright(UUID ownerId, CardSetInfo setInfo) { - super(ownerId,setInfo,new CardType[]{CardType.CREATURE},"{U}"); + super(ownerId, setInfo, new CardType[]{CardType.CREATURE}, "{U}"); this.subtype.add(SubType.VEDALKEN); this.subtype.add(SubType.WIZARD); @@ -103,10 +103,9 @@ class RealmwrightEffect2 extends ContinuousEffectImpl { @Override public boolean apply(Layer layer, SubLayer sublayer, Ability source, Game game) { - // TODO fix to use SubType enum Player you = game.getPlayer(source.getControllerId()); List lands = game.getBattlefield().getAllActivePermanents(new FilterControlledLandPermanent(), source.getControllerId(), game); - String choice = (String) game.getState().getValue(source.getSourceId().toString() + ChooseBasicLandTypeEffect.VALUE_KEY); + SubType choice = SubType.byDescription((String) game.getState().getValue(source.getSourceId().toString() + ChooseBasicLandTypeEffect.VALUE_KEY)); if (you != null && choice != null) { for (Permanent land : lands) { if (land != null) { @@ -119,7 +118,7 @@ class RealmwrightEffect2 extends ContinuousEffectImpl { case AbilityAddingRemovingEffects_6: if (sublayer == SubLayer.NA) { boolean addAbility = true; - if (choice.equals("Forest")) { + if (choice.equals(SubType.FOREST)) { for (Ability existingAbility : land.getAbilities()) { if (existingAbility instanceof GreenManaAbility) { addAbility = false; @@ -130,7 +129,7 @@ class RealmwrightEffect2 extends ContinuousEffectImpl { land.addAbility(new GreenManaAbility(), source.getSourceId(), game); } } - if (choice.equals("Plains")) { + if (choice.equals(SubType.PLAINS)) { for (Ability existingAbility : land.getAbilities()) { if (existingAbility instanceof WhiteManaAbility) { addAbility = false; @@ -141,7 +140,7 @@ class RealmwrightEffect2 extends ContinuousEffectImpl { land.addAbility(new WhiteManaAbility(), source.getSourceId(), game); } } - if (choice.equals("Mountain")) { + if (choice.equals(SubType.MOUNTAIN)) { for (Ability existingAbility : land.getAbilities()) { if (existingAbility instanceof RedManaAbility) { addAbility = false; @@ -152,7 +151,7 @@ class RealmwrightEffect2 extends ContinuousEffectImpl { land.addAbility(new RedManaAbility(), source.getSourceId(), game); } } - if (choice.equals("Island")) { + if (choice.equals(SubType.ISLAND)) { for (Ability existingAbility : land.getAbilities()) { if (existingAbility instanceof BlueManaAbility) { addAbility = false; @@ -163,7 +162,7 @@ class RealmwrightEffect2 extends ContinuousEffectImpl { land.addAbility(new BlueManaAbility(), source.getSourceId(), game); } } - if (choice.equals("Swamp")) { + if (choice.equals(SubType.SWAMP)) { for (Ability existingAbility : land.getAbilities()) { if (existingAbility instanceof BlackManaAbility) { addAbility = false; diff --git a/Mage.Sets/src/mage/cards/t/Terraformer.java b/Mage.Sets/src/mage/cards/t/Terraformer.java index 5a07c94f168..67b7d312ff8 100644 --- a/Mage.Sets/src/mage/cards/t/Terraformer.java +++ b/Mage.Sets/src/mage/cards/t/Terraformer.java @@ -145,8 +145,7 @@ class TerraformerContinuousEffect extends ContinuousEffectImpl { @Override public boolean apply(Layer layer, SubLayer sublayer, Ability source, Game game) { - // TODO fix to use SubType enum - String choice = (String) game.getState().getValue(source.getSourceId().toString() + "_Terraformer"); + SubType choice = SubType.byDescription((String) game.getState().getValue(source.getSourceId().toString() + "_Terraformer")); if (choice != null) { for (Iterator it = affectedObjectList.iterator(); it.hasNext();) { Permanent land = it.next().getPermanent(game); @@ -161,19 +160,19 @@ class TerraformerContinuousEffect extends ContinuousEffectImpl { case AbilityAddingRemovingEffects_6: if (sublayer == SubLayer.NA) { land.getAbilities().clear(); - if (choice.equals("Forest")) { + if (choice.equals(SubType.FOREST)) { land.addAbility(new GreenManaAbility(), source.getSourceId(), game); } - if (choice.equals("Plains")) { + if (choice.equals(SubType.PLAINS)) { land.addAbility(new WhiteManaAbility(), source.getSourceId(), game); } - if (choice.equals("Mountain")) { + if (choice.equals(SubType.MOUNTAIN)) { land.addAbility(new RedManaAbility(), source.getSourceId(), game); } - if (choice.equals("Island")) { + if (choice.equals(SubType.ISLAND)) { land.addAbility(new BlueManaAbility(), source.getSourceId(), game); } - if (choice.equals("Swamp")) { + if (choice.equals(SubType.SWAMP)) { land.addAbility(new BlackManaAbility(), source.getSourceId(), game); } } diff --git a/Mage.Sets/src/mage/cards/v/VisionCharm.java b/Mage.Sets/src/mage/cards/v/VisionCharm.java index b860692a2cd..52d0254810a 100644 --- a/Mage.Sets/src/mage/cards/v/VisionCharm.java +++ b/Mage.Sets/src/mage/cards/v/VisionCharm.java @@ -93,7 +93,7 @@ public class VisionCharm extends CardImpl { class VisionCharmEffect extends ContinuousEffectImpl { private String targetLandType; - private String targetBasicLandType; + private SubType targetBasicLandType; public VisionCharmEffect() { super(Duration.EndOfTurn, Outcome.Neutral); @@ -121,7 +121,7 @@ class VisionCharmEffect extends ContinuousEffectImpl { targetLandType = choice.getChoice(); choice = new ChoiceBasicLandType(); controller.choose(outcome, choice, game); - targetBasicLandType = choice.getChoice(); + targetBasicLandType = SubType.byDescription(choice.getChoice()); if (targetLandType == null || targetBasicLandType == null) { this.discard(); return; @@ -153,22 +153,20 @@ class VisionCharmEffect extends ContinuousEffectImpl { case AbilityAddingRemovingEffects_6: if (sublayer == SubLayer.NA) { land.getAbilities().clear(); - switch (targetBasicLandType) { - case "Swamp": - land.addAbility(new BlackManaAbility(), source.getSourceId(), game); - break; - case "Mountain": - land.addAbility(new RedManaAbility(), source.getSourceId(), game); - break; - case "Forest": - land.addAbility(new GreenManaAbility(), source.getSourceId(), game); - break; - case "Island": - land.addAbility(new BlueManaAbility(), source.getSourceId(), game); - break; - case "Plains": - land.addAbility(new WhiteManaAbility(), source.getSourceId(), game); - break; + if (targetBasicLandType.equals(SubType.FOREST)) { + land.addAbility(new GreenManaAbility(), source.getSourceId(), game); + } + if (targetBasicLandType.equals(SubType.PLAINS)) { + land.addAbility(new WhiteManaAbility(), source.getSourceId(), game); + } + if (targetBasicLandType.equals(SubType.MOUNTAIN)) { + land.addAbility(new RedManaAbility(), source.getSourceId(), game); + } + if (targetBasicLandType.equals(SubType.ISLAND)) { + land.addAbility(new BlueManaAbility(), source.getSourceId(), game); + } + if (targetBasicLandType.equals(SubType.SWAMP)) { + land.addAbility(new BlackManaAbility(), source.getSourceId(), game); } } } @@ -176,6 +174,7 @@ class VisionCharmEffect extends ContinuousEffectImpl { it.remove(); } } + return true; }