From afcad4e67218f0e127f2e1e5b95d082fe72a1119 Mon Sep 17 00:00:00 2001 From: drdev Date: Mon, 6 Oct 2014 04:06:42 +0000 Subject: [PATCH] Commit stage 1 of large game view refactoring --- .gitattributes | 11 + .../src/main/java/forge/ai/AiController.java | 14 +- .../main/java/forge/ai/AiCostDecision.java | 2 +- .../src/main/java/forge/ai/ComputerUtil.java | 10 +- .../main/java/forge/ai/ComputerUtilCard.java | 6 +- .../java/forge/ai/ComputerUtilCombat.java | 2 +- .../main/java/forge/ai/ComputerUtilMana.java | 2 +- .../java/forge/ai/PlayerControllerAi.java | 4 +- .../main/java/forge/ai/ability/AnimateAi.java | 2 +- .../main/java/forge/ai/ability/AttachAi.java | 16 +- .../java/forge/ai/ability/ChangeZoneAi.java | 4 +- .../java/forge/ai/ability/ChooseSourceAi.java | 2 +- .../java/forge/ai/ability/DamageDealAi.java | 2 +- .../main/java/forge/ai/ability/DestroyAi.java | 4 +- .../main/java/forge/ai/ability/EffectAi.java | 9 +- .../main/java/forge/ai/ability/FightAi.java | 2 +- .../java/forge/ai/ability/PumpAiBase.java | 2 +- .../java/forge/ai/ability/RegenerateAi.java | 12 +- .../forge/ai/ability/RegenerateAllAi.java | 4 +- .../main/java/forge/ai/ability/TokenAi.java | 2 +- .../java/forge/ai/ability/UnattachAllAi.java | 2 +- forge-game/src/main/java/forge/game/Game.java | 6 + .../src/main/java/forge/game/GameAction.java | 19 +- .../src/main/java/forge/game/GameEntity.java | 1 + .../main/java/forge/game/GameEntityView.java | 22 + .../src/main/java/forge/game/GameView.java | 50 + .../main/java/forge/game/StaticEffects.java | 4 +- .../java/forge/game/ability/AbilityUtils.java | 61 +- .../ability/effects/AnimateAllEffect.java | 2 +- .../game/ability/effects/AnimateEffect.java | 2 +- .../ability/effects/ChangeTargetsEffect.java | 31 +- .../ability/effects/ChangeZoneEffect.java | 8 +- .../ability/effects/ChooseColorEffect.java | 2 +- .../ability/effects/ChooseSourceEffect.java | 14 +- .../game/ability/effects/CloneEffect.java | 6 +- .../ability/effects/ControlGainEffect.java | 2 +- .../game/ability/effects/CounterEffect.java | 4 +- .../ability/effects/DamagePreventEffect.java | 4 +- .../game/ability/effects/DestroyEffect.java | 2 +- .../game/ability/effects/EffectEffect.java | 4 +- .../effects/PlayLandVariantEffect.java | 2 +- .../ability/effects/ProtectAllEffect.java | 2 +- .../game/ability/effects/ProtectEffect.java | 2 +- .../game/ability/effects/PumpEffect.java | 2 +- .../ability/effects/RegenerateEffect.java | 2 +- .../game/ability/effects/SetStateEffect.java | 2 +- .../game/ability/effects/TokenEffect.java | 2 +- .../ability/effects/UnattachAllEffect.java | 4 +- .../game/ability/effects/UnattachEffect.java | 4 +- .../src/main/java/forge/game/card/Card.java | 4997 ++++------------- .../forge/game/card/CardCharacteristics.java | 8 +- .../java/forge/game/card/CardFactory.java | 21 +- .../java/forge/game/card/CardFactoryUtil.java | 6 +- .../main/java/forge/game/card/CardUtil.java | 9 +- .../main/java/forge/game/card/CardView.java | 625 +++ .../main/java/forge/game/combat/Combat.java | 4 +- .../java/forge/game/combat/CombatUtil.java | 6 +- .../java/forge/game/combat/CombatView.java | 150 + .../java/forge/game/cost/CostUnattach.java | 2 +- .../forge/game/io/GameStateSerializer.java | 2 +- .../java/forge/game/phase/PhaseHandler.java | 2 +- .../src/main/java/forge/game/phase/Untap.java | 4 +- .../main/java/forge/game/player/Player.java | 1279 ++--- .../java/forge/game/player/PlayerView.java | 207 + .../game/replacement/ReplacementHandler.java | 4 +- .../game/spellability/AbilityManaPart.java | 6 +- .../forge/game/spellability/SpellAbility.java | 1123 +--- .../spellability/SpellAbilityCondition.java | 2 +- .../spellability/SpellAbilityRestriction.java | 2 +- .../SpellAbilityStackInstance.java | 224 +- .../game/spellability/SpellAbilityView.java | 49 + .../game/spellability/StackItemView.java | 98 + .../StaticAbilityContinuous.java | 16 +- .../forge/game/trigger/TriggerHandler.java | 6 +- .../game/trigger/TriggerSpellAbilityCast.java | 8 +- .../game/trigger/TriggerTapsForMana.java | 2 +- .../forge/game/trigger/WrappedAbility.java | 12 +- .../main/java/forge/game/zone/MagicStack.java | 14 +- .../forge/trackable/TrackableCollection.java | 21 + .../java/forge/trackable/TrackableIndex.java | 9 + .../java/forge/trackable/TrackableObject.java | 48 + .../forge/trackable/TrackableProperty.java | 118 + .../util/PlayerControllerForTests.java | 2 +- .../main/java/forge/card/CardDetailUtil.java | 3 +- .../java/forge/match/input/InputBlock.java | 2 +- .../java/forge/player/HumanCostDecision.java | 2 +- .../forge/player/PlayerControllerHuman.java | 10 +- .../java/forge/player/TargetSelection.java | 4 +- .../src/main/java/forge/view/CardView.java | 11 +- .../main/java/forge/view/LocalGameView.java | 2 +- .../main/java/forge/view/StackItemView.java | 4 +- .../src/main/java/forge/view/ViewUtil.java | 9 +- 92 files changed, 3490 insertions(+), 6023 deletions(-) create mode 100644 forge-game/src/main/java/forge/game/GameEntityView.java create mode 100644 forge-game/src/main/java/forge/game/GameView.java create mode 100644 forge-game/src/main/java/forge/game/card/CardView.java create mode 100644 forge-game/src/main/java/forge/game/combat/CombatView.java create mode 100644 forge-game/src/main/java/forge/game/player/PlayerView.java create mode 100644 forge-game/src/main/java/forge/game/spellability/SpellAbilityView.java create mode 100644 forge-game/src/main/java/forge/game/spellability/StackItemView.java create mode 100644 forge-game/src/main/java/forge/trackable/TrackableCollection.java create mode 100644 forge-game/src/main/java/forge/trackable/TrackableIndex.java create mode 100644 forge-game/src/main/java/forge/trackable/TrackableObject.java create mode 100644 forge-game/src/main/java/forge/trackable/TrackableProperty.java diff --git a/.gitattributes b/.gitattributes index 47cc6c8f09a..2afcf899a31 100644 --- a/.gitattributes +++ b/.gitattributes @@ -271,6 +271,7 @@ forge-game/src/main/java/forge/game/GameAction.java svneol=native#text/plain forge-game/src/main/java/forge/game/GameActionUtil.java svneol=native#text/plain forge-game/src/main/java/forge/game/GameEndReason.java -text forge-game/src/main/java/forge/game/GameEntity.java -text +forge-game/src/main/java/forge/game/GameEntityView.java -text forge-game/src/main/java/forge/game/GameFormat.java -text forge-game/src/main/java/forge/game/GameLog.java -text forge-game/src/main/java/forge/game/GameLogEntry.java -text @@ -281,6 +282,7 @@ forge-game/src/main/java/forge/game/GameOutcome.java -text forge-game/src/main/java/forge/game/GameRules.java -text forge-game/src/main/java/forge/game/GameStage.java -text forge-game/src/main/java/forge/game/GameType.java -text +forge-game/src/main/java/forge/game/GameView.java -text forge-game/src/main/java/forge/game/GlobalRuleChange.java -text forge-game/src/main/java/forge/game/IHasGameType.java -text forge-game/src/main/java/forge/game/IIdentifiable.java -text @@ -441,12 +443,14 @@ forge-game/src/main/java/forge/game/card/CardPredicates.java svneol=native#text/ forge-game/src/main/java/forge/game/card/CardShields.java -text forge-game/src/main/java/forge/game/card/CardType.java svneol=native#text/plain forge-game/src/main/java/forge/game/card/CardUtil.java svneol=native#text/plain +forge-game/src/main/java/forge/game/card/CardView.java -text forge-game/src/main/java/forge/game/card/CounterType.java svneol=native#text/plain forge-game/src/main/java/forge/game/card/package-info.java -text forge-game/src/main/java/forge/game/combat/AttackingBand.java -text forge-game/src/main/java/forge/game/combat/Combat.java svneol=native#text/plain forge-game/src/main/java/forge/game/combat/CombatLki.java -text forge-game/src/main/java/forge/game/combat/CombatUtil.java svneol=native#text/plain +forge-game/src/main/java/forge/game/combat/CombatView.java -text forge-game/src/main/java/forge/game/cost/Cost.java svneol=native#text/plain forge-game/src/main/java/forge/game/cost/CostAddMana.java -text forge-game/src/main/java/forge/game/cost/CostChooseCreatureType.java -text @@ -550,6 +554,7 @@ forge-game/src/main/java/forge/game/player/PlayerActionConfirmMode.java -text forge-game/src/main/java/forge/game/player/PlayerController.java -text forge-game/src/main/java/forge/game/player/PlayerOutcome.java -text forge-game/src/main/java/forge/game/player/PlayerStatistics.java -text +forge-game/src/main/java/forge/game/player/PlayerView.java -text forge-game/src/main/java/forge/game/player/RegisteredPlayer.java -text forge-game/src/main/java/forge/game/player/package-info.java svneol=native#text/plain forge-game/src/main/java/forge/game/replacement/ReplaceAddCounter.java -text @@ -585,7 +590,9 @@ forge-game/src/main/java/forge/game/spellability/SpellAbilityCondition.java svne forge-game/src/main/java/forge/game/spellability/SpellAbilityRestriction.java svneol=native#text/plain forge-game/src/main/java/forge/game/spellability/SpellAbilityStackInstance.java svneol=native#text/plain forge-game/src/main/java/forge/game/spellability/SpellAbilityVariables.java svneol=native#text/plain +forge-game/src/main/java/forge/game/spellability/SpellAbilityView.java -text forge-game/src/main/java/forge/game/spellability/SpellPermanent.java svneol=native#text/plain +forge-game/src/main/java/forge/game/spellability/StackItemView.java -text forge-game/src/main/java/forge/game/spellability/TargetChoices.java svneol=native#text/plain forge-game/src/main/java/forge/game/spellability/TargetRestrictions.java svneol=native#text/plain forge-game/src/main/java/forge/game/spellability/package-info.java svneol=native#text/plain @@ -663,6 +670,10 @@ forge-game/src/main/java/forge/game/zone/PlayerZoneBattlefield.java svneol=nativ forge-game/src/main/java/forge/game/zone/Zone.java -text forge-game/src/main/java/forge/game/zone/ZoneType.java -text forge-game/src/main/java/forge/game/zone/package-info.java svneol=native#text/plain +forge-game/src/main/java/forge/trackable/TrackableCollection.java -text +forge-game/src/main/java/forge/trackable/TrackableIndex.java -text +forge-game/src/main/java/forge/trackable/TrackableObject.java -text +forge-game/src/main/java/forge/trackable/TrackableProperty.java -text forge-game/src/main/java/forge/util/Expressions.java -text forge-game/src/main/java/forge/util/MessageUtil.java -text forge-gui-android/.classpath -text diff --git a/forge-ai/src/main/java/forge/ai/AiController.java b/forge-ai/src/main/java/forge/ai/AiController.java index fdf0802e7da..0580c7a9312 100644 --- a/forge-ai/src/main/java/forge/ai/AiController.java +++ b/forge-ai/src/main/java/forge/ai/AiController.java @@ -27,7 +27,6 @@ import java.util.HashMap; import java.util.List; import java.util.Map; import java.util.Map.Entry; - import com.esotericsoftware.minlog.Log; import com.google.common.base.Function; import com.google.common.base.Predicate; @@ -1147,11 +1146,14 @@ public class AiController { List list = player.getCardsIn(ZoneType.Battlefield); list = CardLists.filter(list, CardPredicates.Presets.PLANEWALKERS); - List type = card.getType(); - final String subtype = type.get(type.size() - 1); - final List cl = CardLists.getType(list, subtype); - if (!cl.isEmpty()) { - return AiPlayDecision.WouldDestroyOtherPlaneswalker; + for (String type : card.getType()) { //determine planewalker subtype + if (!type.equals("Planeswalker")) { + final List cl = CardLists.getType(list, type); + if (!cl.isEmpty()) { + return AiPlayDecision.WouldDestroyOtherPlaneswalker; + } + break; + } } } if (card.isType("World")) { diff --git a/forge-ai/src/main/java/forge/ai/AiCostDecision.java b/forge-ai/src/main/java/forge/ai/AiCostDecision.java index 0c6971fb405..84c8b09432d 100644 --- a/forge-ai/src/main/java/forge/ai/AiCostDecision.java +++ b/forge-ai/src/main/java/forge/ai/AiCostDecision.java @@ -172,7 +172,7 @@ public class AiCostDecision extends CostDecisionMakerBase implements ICostVisito } List chosen = new ArrayList(); for (SpellAbilityStackInstance si :source.getGame().getStack()) { - SpellAbility sp = si.getSpellAbility().getRootAbility(); + SpellAbility sp = si.getSpellAbility(true).getRootAbility(); if (si.getSourceCard().isValid(cost.getType().split(";"), source.getController(), source)) { chosen.add(sp); } diff --git a/forge-ai/src/main/java/forge/ai/ComputerUtil.java b/forge-ai/src/main/java/forge/ai/ComputerUtil.java index 50704c0f724..419f3c2a672 100644 --- a/forge-ai/src/main/java/forge/ai/ComputerUtil.java +++ b/forge-ai/src/main/java/forge/ai/ComputerUtil.java @@ -1196,7 +1196,7 @@ public class ComputerUtil { for (StaticAbility stAb : c.getStaticAbilities()) { Map params = stAb.getMapParams(); if ("Continuous".equals(params.get("Mode")) && params.containsKey("AddKeyword") - && params.get("AddKeyword").contains("Haste") && c.getEquippingCard() == null) { + && params.get("AddKeyword").contains("Haste") && c.getEquipping() == null) { return true; } } @@ -1376,7 +1376,7 @@ public class ComputerUtil { } // already regenerated - if (!c.getShield().isEmpty()) { + if (c.getShieldCount() > 0) { continue; } @@ -1431,13 +1431,13 @@ public class ComputerUtil { if (o instanceof Card) { final Card c = (Card) o; final boolean canRemove = (c.getNetDefense() <= dmg) - || (!c.hasKeyword("Indestructible") && c.getShield().isEmpty() && (dmg >= ComputerUtilCombat.getDamageToKill(c))); + || (!c.hasKeyword("Indestructible") && c.getShieldCount() == 0 && (dmg >= ComputerUtilCombat.getDamageToKill(c))); if (!canRemove) { continue; } if (saviourApi == ApiType.Pump || saviourApi == ApiType.PumpAll ) { final boolean cantSave = c.getNetDefense() + defense <= dmg - || (!c.hasKeyword("Indestructible") && c.getShield().isEmpty() && !grantIndestructible + || (!c.hasKeyword("Indestructible") && c.getShieldCount() == 0 && !grantIndestructible && (dmg >= defense + ComputerUtilCombat.getDamageToKill(c))); if (cantSave && (tgt == null || !grantShroud)) { continue; @@ -1473,7 +1473,7 @@ public class ComputerUtil { } // already regenerated - if (!c.getShield().isEmpty()) { + if (c.getShieldCount() > 0) { continue; } diff --git a/forge-ai/src/main/java/forge/ai/ComputerUtilCard.java b/forge-ai/src/main/java/forge/ai/ComputerUtilCard.java index 85c3fa3610e..55be867bc6d 100644 --- a/forge-ai/src/main/java/forge/ai/ComputerUtilCard.java +++ b/forge-ai/src/main/java/forge/ai/ComputerUtilCard.java @@ -784,9 +784,7 @@ public class ComputerUtilCard { final Map map = new HashMap(); for (final Card c : list) { - final ArrayList typeList = c.getType(); - - for (final String var : typeList) { + for (final String var : c.getType()) { if (CardType.isACreatureType(var)) { if (!map.containsKey(var)) { map.put(var, 1); @@ -987,7 +985,7 @@ public class ComputerUtilCard { Combat currCombat = game.getCombat(); if (currCombat != null && !currCombat.getAllBlockers().isEmpty() && currCombat.getAllBlockers().contains(c)) { for (Card attacker : currCombat.getAttackersBlockedBy(c)) { - if (attacker.getShield().isEmpty() && ComputerUtilCombat.attackerWouldBeDestroyed(ai, attacker, currCombat)) { + if (attacker.getShieldCount() == 0 && ComputerUtilCombat.attackerWouldBeDestroyed(ai, attacker, currCombat)) { List blockers = currCombat.getBlockers(attacker); ComputerUtilCard.sortByEvaluateCreature(blockers); Combat combat = new Combat(ai); diff --git a/forge-ai/src/main/java/forge/ai/ComputerUtilCombat.java b/forge-ai/src/main/java/forge/ai/ComputerUtilCombat.java index b424d16d990..155c45d6d90 100644 --- a/forge-ai/src/main/java/forge/ai/ComputerUtilCombat.java +++ b/forge-ai/src/main/java/forge/ai/ComputerUtilCombat.java @@ -1978,7 +1978,7 @@ public class ComputerUtilCombat { final boolean noPrevention) { final int killDamage = ComputerUtilCombat.getDamageToKill(c); - if (c.hasKeyword("Indestructible") || !c.getShield().isEmpty()) { + if (c.hasKeyword("Indestructible") || c.getShieldCount() > 0) { if (!(source.hasKeyword("Wither") || source.hasKeyword("Infect"))) { return maxDamage + 1; } diff --git a/forge-ai/src/main/java/forge/ai/ComputerUtilMana.java b/forge-ai/src/main/java/forge/ai/ComputerUtilMana.java index 76e141ab96d..bde24f0879c 100644 --- a/forge-ai/src/main/java/forge/ai/ComputerUtilMana.java +++ b/forge-ai/src/main/java/forge/ai/ComputerUtilMana.java @@ -1118,7 +1118,7 @@ public class ComputerUtilMana { && replacementEffect.zonesCheck(game.getZoneOf(crd))) { String repType = crd.getSVar(replacementEffect.getMapParams().get("ManaReplacement")); if (repType.contains("Chosen")) { - repType = repType.replace("Chosen", MagicColor.toShortString(crd.getChosenColor().get(0))); + repType = repType.replace("Chosen", MagicColor.toShortString(crd.getChosenColors().get(0))); } mp.setManaReplaceType(repType); } diff --git a/forge-ai/src/main/java/forge/ai/PlayerControllerAi.java b/forge-ai/src/main/java/forge/ai/PlayerControllerAi.java index aa34b502177..e5244310876 100644 --- a/forge-ai/src/main/java/forge/ai/PlayerControllerAi.java +++ b/forge-ai/src/main/java/forge/ai/PlayerControllerAi.java @@ -634,7 +634,7 @@ public class PlayerControllerAi extends PlayerController { String choice = choices.get(0); if (game.stack.size() > 1) { for (SpellAbilityStackInstance si : game.getStack()) { - SpellAbility spell = si.getSpellAbility(); + SpellAbility spell = si.getSpellAbility(true); if (sa != spell) { String s = ProtectAi.toProtectFrom(spell.getHostCard(), sa); if (s != null) { @@ -786,7 +786,7 @@ public class PlayerControllerAi extends PlayerController { @Override public CardShields chooseRegenerationShield(Card c) { - return Iterables.getFirst(c.getShield(), null); + return Iterables.getFirst(c.getShields(), null); } @Override diff --git a/forge-ai/src/main/java/forge/ai/ability/AnimateAi.java b/forge-ai/src/main/java/forge/ai/ability/AnimateAi.java index b6c03fcfac5..43f05da4c54 100644 --- a/forge-ai/src/main/java/forge/ai/ability/AnimateAi.java +++ b/forge-ai/src/main/java/forge/ai/ability/AnimateAi.java @@ -326,7 +326,7 @@ public class AnimateAi extends SpellAbilityAi { final String colors = sa.getParam("Colors"); if (colors.equals("ChosenColor")) { - tmpDesc = CardUtil.getShortColorsString(source.getChosenColor()); + tmpDesc = CardUtil.getShortColorsString(source.getChosenColors()); } else { tmpDesc = CardUtil.getShortColorsString(new ArrayList(Arrays.asList(colors.split(",")))); } diff --git a/forge-ai/src/main/java/forge/ai/ability/AttachAi.java b/forge-ai/src/main/java/forge/ai/ability/AttachAi.java index 1c5fa56ae96..1a877afcbc1 100644 --- a/forge-ai/src/main/java/forge/ai/ability/AttachAi.java +++ b/forge-ai/src/main/java/forge/ai/ability/AttachAi.java @@ -678,7 +678,7 @@ public class AttachAi extends SpellAbilityAi { //don't equip a worse creature if (card.isEquipping()) { - Card oldTarget = card.getEquipping().get(0); + Card oldTarget = card.getEquipping(); if (ComputerUtilCard.evaluateCreature(oldTarget) > ComputerUtilCard.evaluateCreature(newTarget)) { return false; } @@ -990,7 +990,7 @@ public class AttachAi extends SpellAbilityAi { return null; } // Don't fortify if already fortifying - if (attachSource.getFortifyingCard() != null && attachSource.getFortifyingCard().getController() == aiPlayer) { + if (attachSource.getFortifying() != null && attachSource.getFortifying().getController() == aiPlayer) { return null; } @@ -1019,14 +1019,14 @@ public class AttachAi extends SpellAbilityAi { AiController aic = ((PlayerControllerAi)aiPlayer.getController()).getAi(); if (c != null && attachSource.getType().contains("Equipment") - && attachSource.getEquippingCard() != null - && attachSource.getEquippingCard().getController() == aiPlayer) { - if (c.equals(attachSource.getEquippingCard())) { + && attachSource.isEquipping() + && attachSource.getEquipping().getController() == aiPlayer) { + if (c.equals(attachSource.getEquipping())) { // Do not equip if equipping the same card already return null; } - boolean uselessCreature = isUselessCreature(aiPlayer, attachSource.getEquippingCard()); + boolean uselessCreature = isUselessCreature(aiPlayer, attachSource.getEquipping()); if (aic.getProperty(AiProps.MOVE_EQUIPMENT_TO_BETTER_CREATURES).equals("never")) { // Do not equip other creatures if the AI profile does not allow moving equipment around @@ -1330,9 +1330,7 @@ public class AttachAi extends SpellAbilityAi { return true; } - ArrayList cardTypes = sa.getHostCard().getType(); - - if (cardTypes.contains("Equipment") && isUselessCreature(ai, c)) { + if (sa.getHostCard().getType().contains("Equipment") && isUselessCreature(ai, c)) { // useless to equip a creature that can't attack or block. return false; } diff --git a/forge-ai/src/main/java/forge/ai/ability/ChangeZoneAi.java b/forge-ai/src/main/java/forge/ai/ability/ChangeZoneAi.java index a2a1a2b953e..70040e7994a 100644 --- a/forge-ai/src/main/java/forge/ai/ability/ChangeZoneAi.java +++ b/forge-ai/src/main/java/forge/ai/ability/ChangeZoneAi.java @@ -736,7 +736,7 @@ public class ChangeZoneAi extends SpellAbilityAi { for (Card attacker : attackers) { List blockers = currCombat.getBlockers(attacker); // Save my attacker by bouncing a blocker - if (attacker.getController().equals(ai) && attacker.getShield().isEmpty() + if (attacker.getController().equals(ai) && attacker.getShieldCount() == 0 && ComputerUtilCombat.attackerWouldBeDestroyed(ai, attacker, currCombat) && !currCombat.getBlockers(attacker).isEmpty()) { ComputerUtilCard.sortByEvaluateCreature(blockers); @@ -799,7 +799,7 @@ public class ChangeZoneAi extends SpellAbilityAi { ComputerUtilCard.sortByEvaluateCreature(combatants); for (final Card c : combatants) { - if (c.getShield().isEmpty() && ComputerUtilCombat.combatantWouldBeDestroyed(ai, c, combat) && c.getOwner() == ai && !c.isToken()) { + if (c.getShieldCount() == 0 && ComputerUtilCombat.combatantWouldBeDestroyed(ai, c, combat) && c.getOwner() == ai && !c.isToken()) { sa.getTargets().add(c); return true; } diff --git a/forge-ai/src/main/java/forge/ai/ability/ChooseSourceAi.java b/forge-ai/src/main/java/forge/ai/ability/ChooseSourceAi.java index 4d34c4baa06..cbc94ab7ac6 100644 --- a/forge-ai/src/main/java/forge/ai/ability/ChooseSourceAi.java +++ b/forge-ai/src/main/java/forge/ai/ability/ChooseSourceAi.java @@ -157,7 +157,7 @@ public class ChooseSourceAi extends SpellAbilityAi { private Card chooseCardOnStack(SpellAbility sa, Player ai, Game game) { for (SpellAbilityStackInstance si : game.getStack()) { final Card source = si.getSourceCard(); - final SpellAbility abilityOnStack = si.getSpellAbility(); + final SpellAbility abilityOnStack = si.getSpellAbility(true); if (sa.hasParam("Choices") && !abilityOnStack.getHostCard().isValid(sa.getParam("Choices"), ai, sa.getHostCard())) { continue; diff --git a/forge-ai/src/main/java/forge/ai/ability/DamageDealAi.java b/forge-ai/src/main/java/forge/ai/ability/DamageDealAi.java index eb633ac119e..b6c0dc3483a 100644 --- a/forge-ai/src/main/java/forge/ai/ability/DamageDealAi.java +++ b/forge-ai/src/main/java/forge/ai/ability/DamageDealAi.java @@ -287,7 +287,7 @@ public class DamageDealAi extends DamageAiBase { } final int assignedDamage = ComputerUtilCombat.getEnoughDamageToKill(humanCreature, dmg, source, false, noPrevention); if (assignedDamage <= dmg - && humanCreature.getShield().isEmpty() && !ComputerUtil.canRegenerate(humanCreature.getController(), humanCreature)) { + && humanCreature.getShieldCount() == 0 && !ComputerUtil.canRegenerate(humanCreature.getController(), humanCreature)) { tcs.add(humanCreature); tgt.addDividedAllocation(humanCreature, assignedDamage); lastTgt = humanCreature; diff --git a/forge-ai/src/main/java/forge/ai/ability/DestroyAi.java b/forge-ai/src/main/java/forge/ai/ability/DestroyAi.java index a3e0cc30b58..6c3b7be3329 100644 --- a/forge-ai/src/main/java/forge/ai/ability/DestroyAi.java +++ b/forge-ai/src/main/java/forge/ai/ability/DestroyAi.java @@ -113,7 +113,7 @@ public class DestroyAi extends SpellAbilityAi { list = CardLists.filter(list, new Predicate() { @Override public boolean apply(final Card c) { - return (c.getShield().isEmpty() && !ComputerUtil.canRegenerate(ai, c)); + return (c.getShieldCount() == 0 && !ComputerUtil.canRegenerate(ai, c)); } }); } @@ -237,7 +237,7 @@ public class DestroyAi extends SpellAbilityAi { preferred = CardLists.filter(preferred, new Predicate() { @Override public boolean apply(final Card c) { - return c.getShield().isEmpty(); + return c.getShieldCount() == 0; } }); } diff --git a/forge-ai/src/main/java/forge/ai/ability/EffectAi.java b/forge-ai/src/main/java/forge/ai/ability/EffectAi.java index 295616f38ac..ec35e5b2130 100644 --- a/forge-ai/src/main/java/forge/ai/ability/EffectAi.java +++ b/forge-ai/src/main/java/forge/ai/ability/EffectAi.java @@ -118,10 +118,11 @@ public class EffectAi extends SpellAbilityAi { return false; } boolean threatened = false; - for (final SpellAbilityStackInstance stackSA : game.getStack()) { - if (!stackSA.isSpell()) { continue; } - if (stackSA.getSpellAbility().getApi() == ApiType.DealDamage) { - final SpellAbility saTargeting = stackSA.getSpellAbility().getSATargetingPlayer(); + for (final SpellAbilityStackInstance stackInst : game.getStack()) { + if (!stackInst.isSpell()) { continue; } + SpellAbility stackSpellAbility = stackInst.getSpellAbility(true); + if (stackSpellAbility.getApi() == ApiType.DealDamage) { + final SpellAbility saTargeting = stackSpellAbility.getSATargetingPlayer(); if (saTargeting != null && Iterables.contains(saTargeting.getTargets().getTargetPlayers(), ai)) { threatened = true; } diff --git a/forge-ai/src/main/java/forge/ai/ability/FightAi.java b/forge-ai/src/main/java/forge/ai/ability/FightAi.java index 5021fbeee79..1a3ccbbfc5c 100644 --- a/forge-ai/src/main/java/forge/ai/ability/FightAi.java +++ b/forge-ai/src/main/java/forge/ai/ability/FightAi.java @@ -153,7 +153,7 @@ public class FightAi extends SpellAbilityAi { return true; } if (opponent.hasProtectionFrom(fighter) || !opponent.canBeDestroyed() - || !opponent.getShield().isEmpty() || ComputerUtil.canRegenerate(opponent.getController(), opponent)) { + || opponent.getShieldCount() > 0 || ComputerUtil.canRegenerate(opponent.getController(), opponent)) { return false; } if (fighter.hasKeyword("Deathtouch") || ComputerUtilCombat.getDamageToKill(opponent) <= fighter.getNetAttack() + pumpAttack) { diff --git a/forge-ai/src/main/java/forge/ai/ability/PumpAiBase.java b/forge-ai/src/main/java/forge/ai/ability/PumpAiBase.java index 2245339c249..9e3f26975b6 100644 --- a/forge-ai/src/main/java/forge/ai/ability/PumpAiBase.java +++ b/forge-ai/src/main/java/forge/ai/ability/PumpAiBase.java @@ -138,7 +138,7 @@ public abstract class PumpAiBase extends SpellAbilityAi { return false; } } else if (keyword.endsWith("CARDNAME can't be regenerated.")) { - if (!card.getShield().isEmpty()) { + if (card.getShieldCount() > 0) { return true; } if (card.hasKeyword("If CARDNAME would be destroyed, regenerate it.") && combat != null diff --git a/forge-ai/src/main/java/forge/ai/ability/RegenerateAi.java b/forge-ai/src/main/java/forge/ai/ability/RegenerateAi.java index b98b82af27f..8b531700c0b 100644 --- a/forge-ai/src/main/java/forge/ai/ability/RegenerateAi.java +++ b/forge-ai/src/main/java/forge/ai/ability/RegenerateAi.java @@ -99,7 +99,7 @@ public class RegenerateAi extends SpellAbilityAi { boolean flag = false; for (final Card c : list) { - if (c.getShield().isEmpty()) { + if (c.getShieldCount() == 0) { flag |= ComputerUtilCombat.combatantWouldBeDestroyed(ai, c, combat); } } @@ -128,7 +128,7 @@ public class RegenerateAi extends SpellAbilityAi { final List threatenedTargets = new ArrayList(); for (final Card c : targetables) { - if (objects.contains(c) && c.getShield().isEmpty() && !ComputerUtil.canRegenerate(ai, c)) { + if (objects.contains(c) && c.getShieldCount() == 0 && !ComputerUtil.canRegenerate(ai, c)) { threatenedTargets.add(c); } } @@ -144,7 +144,7 @@ public class RegenerateAi extends SpellAbilityAi { ComputerUtilCard.sortByEvaluateCreature(combatants); for (final Card c : combatants) { - if (c.getShield().isEmpty() && ComputerUtilCombat.combatantWouldBeDestroyed(ai, c, combat)) { + if (c.getShieldCount() == 0 && ComputerUtilCombat.combatantWouldBeDestroyed(ai, c, combat)) { sa.getTargets().add(c); chance = true; break; @@ -200,7 +200,7 @@ public class RegenerateAi extends SpellAbilityAi { if (game.getPhaseHandler().is(PhaseType.COMBAT_DECLARE_BLOCKERS)) { Combat combat = game.getCombat(); for (final Card c : combatants) { - if (c.getShield().isEmpty() && ComputerUtilCombat.combatantWouldBeDestroyed(ai, c, combat)) { + if (c.getShieldCount() == 0 && ComputerUtilCombat.combatantWouldBeDestroyed(ai, c, combat)) { sa.getTargets().add(c); return true; } @@ -213,7 +213,7 @@ public class RegenerateAi extends SpellAbilityAi { // choose my best X without regen if (CardLists.getNotType(compTargetables, "Creature").isEmpty()) { for (final Card c : combatants) { - if (c.getShield().isEmpty()) { + if (c.getShieldCount() == 0) { sa.getTargets().add(c); return true; } @@ -223,7 +223,7 @@ public class RegenerateAi extends SpellAbilityAi { } else { CardLists.sortByCmcDesc(compTargetables); for (final Card c : compTargetables) { - if (c.getShield().isEmpty()) { + if (c.getShieldCount() == 0) { sa.getTargets().add(c); return true; } diff --git a/forge-ai/src/main/java/forge/ai/ability/RegenerateAllAi.java b/forge-ai/src/main/java/forge/ai/ability/RegenerateAllAi.java index 44188f2d666..cf954940785 100644 --- a/forge-ai/src/main/java/forge/ai/ability/RegenerateAllAi.java +++ b/forge-ai/src/main/java/forge/ai/ability/RegenerateAllAi.java @@ -61,7 +61,7 @@ public class RegenerateAllAi extends SpellAbilityAi { final List objects = ComputerUtil.predictThreatenedObjects(sa.getActivatingPlayer(), sa); for (final Card c : list) { - if (objects.contains(c) && c.getShield().isEmpty()) { + if (objects.contains(c) && c.getShieldCount() == 0) { numSaved++; } } @@ -70,7 +70,7 @@ public class RegenerateAllAi extends SpellAbilityAi { final List combatants = CardLists.filter(list, CardPredicates.Presets.CREATURES); final Combat combat = game.getCombat(); for (final Card c : combatants) { - if (c.getShield().isEmpty() && ComputerUtilCombat.combatantWouldBeDestroyed(ai, c, combat)) { + if (c.getShieldCount() == 0 && ComputerUtilCombat.combatantWouldBeDestroyed(ai, c, combat)) { numSaved++; } } diff --git a/forge-ai/src/main/java/forge/ai/ability/TokenAi.java b/forge-ai/src/main/java/forge/ai/ability/TokenAi.java index e382ac27857..a9e9220929e 100644 --- a/forge-ai/src/main/java/forge/ai/ability/TokenAi.java +++ b/forge-ai/src/main/java/forge/ai/ability/TokenAi.java @@ -296,7 +296,7 @@ public class TokenAi extends SpellAbilityAi { for (int i = 0; i < substitutedColors.length; i++) { if (substitutedColors[i].equals("ChosenColor")) { // this currently only supports 1 chosen color - substitutedColors[i] = host.getChosenColor().get(0); + substitutedColors[i] = host.getChosenColors().get(0); } } String colorDesc = ""; diff --git a/forge-ai/src/main/java/forge/ai/ability/UnattachAllAi.java b/forge-ai/src/main/java/forge/ai/ability/UnattachAllAi.java index 1aa54608e2a..00cced54536 100644 --- a/forge-ai/src/main/java/forge/ai/ability/UnattachAllAi.java +++ b/forge-ai/src/main/java/forge/ai/ability/UnattachAllAi.java @@ -83,7 +83,7 @@ public class UnattachAllAi extends SpellAbilityAi { //don't equip a worse creature if (card.isEquipping()) { - Card oldTarget = card.getEquipping().get(0); + Card oldTarget = card.getEquipping(); if (ComputerUtilCard.evaluateCreature(oldTarget) > ComputerUtilCard.evaluateCreature(newTarget)) { return false; } diff --git a/forge-game/src/main/java/forge/game/Game.java b/forge-game/src/main/java/forge/game/Game.java index ed2e0a3f589..da5dc3a91f9 100644 --- a/forge-game/src/main/java/forge/game/Game.java +++ b/forge-game/src/main/java/forge/game/Game.java @@ -100,6 +100,8 @@ public class Game implements IGameStateObject { private GameOutcome outcome; private boolean disableAutoYields; + private final GameView view = new GameView(); + @Override public void loadState(GameStateDeserializer gsd) { gsd.readObject(rules); @@ -202,6 +204,10 @@ public class Game implements IGameStateObject { subscribeToEvents(gameLog.getEventVisitor()); } + public GameView getView() { + return view; + } + /** * Gets the players who are still fighting to win, in turn order. * diff --git a/forge-game/src/main/java/forge/game/GameAction.java b/forge-game/src/main/java/forge/game/GameAction.java index 33b3e20d6a5..957f968b64f 100644 --- a/forge-game/src/main/java/forge/game/GameAction.java +++ b/forge-game/src/main/java/forge/game/GameAction.java @@ -354,14 +354,14 @@ public class GameAction { } // equipment moving off battlefield if (copied.isEquipping()) { - final Card equippedCreature = copied.getEquipping().get(0); + final Card equippedCreature = copied.getEquipping(); if (equippedCreature.isInPlay()) { copied.unEquipCard(equippedCreature); } } // fortifications moving off battlefield if (copied.isFortifying()) { - final Card fortifiedLand = copied.getFortifying().get(0); + final Card fortifiedLand = copied.getFortifying(); if (fortifiedLand.isInPlay()) { copied.unFortifyCard(fortifiedLand); } @@ -1040,7 +1040,7 @@ public class GameAction { } // if isFortified() if (c.isEquipping()) { - final Card equippedCreature = c.getEquipping().get(0); + final Card equippedCreature = c.getEquipping(); if (!equippedCreature.isCreature() || !equippedCreature.isInPlay() || !equippedCreature.canBeEquippedBy(c) || (equippedCreature.isPhasedOut() && !c.isPhasedOut()) @@ -1056,7 +1056,7 @@ public class GameAction { } // if isEquipping() if (c.isFortifying()) { - final Card fortifiedLand = c.getFortifying().get(0); + final Card fortifiedLand = c.getFortifying(); if (!fortifiedLand.isLand() || !fortifiedLand.isInPlay() || (fortifiedLand.isPhasedOut() && !c.isPhasedOut())) { c.unFortifyCard(fortifiedLand); @@ -1071,11 +1071,6 @@ public class GameAction { return checkAgain; } - /** - * TODO: Write javadoc for this method. - * @param c - * @return - */ private boolean stateBasedAction704_5r(Card c) { boolean checkAgain = false; int plusOneCounters = c.getCounters(CounterType.P1P1); @@ -1334,7 +1329,7 @@ public class GameAction { } if (c.canBeShielded() && (!c.isCreature() || c.getNetDefense() > 0) - && (!c.getShield().isEmpty() || c.hasKeyword("If CARDNAME would be destroyed, regenerate it."))) { + && (c.getShieldCount() > 0 || c.hasKeyword("If CARDNAME would be destroyed, regenerate it."))) { c.subtractShield(c.getController().getController().chooseRegenerationShield(c)); c.setDamage(0); c.tap(); @@ -1483,7 +1478,7 @@ public class GameAction { final Card persistCard = newCard; String effect = String.format("AB$ ChangeZone | Cost$ 0 | Defined$ CardUID_%d" + " | Origin$ Graveyard | Destination$ Battlefield | WithCounters$ M1M1_1", - persistCard.getUniqueNumber()); + persistCard.getId()); SpellAbility persistAb = AbilityFactory.getAbility(effect, c); persistAb.setTrigger(true); persistAb.setStackDescription(newCard.getName() + " - Returning from Persist"); @@ -1497,7 +1492,7 @@ public class GameAction { final Card undyingCard = newCard; String effect = String.format("AB$ ChangeZone | Cost$ 0 | Defined$ CardUID_%d |" + " Origin$ Graveyard | Destination$ Battlefield | WithCounters$ P1P1_1", - undyingCard.getUniqueNumber()); + undyingCard.getId()); SpellAbility undyingAb = AbilityFactory.getAbility(effect, c); undyingAb.setTrigger(true); undyingAb.setStackDescription(newCard.getName() + " - Returning from Undying"); diff --git a/forge-game/src/main/java/forge/game/GameEntity.java b/forge-game/src/main/java/forge/game/GameEntity.java index c9e231a8686..9fe0b94ed28 100644 --- a/forge-game/src/main/java/forge/game/GameEntity.java +++ b/forge-game/src/main/java/forge/game/GameEntity.java @@ -438,4 +438,5 @@ public abstract class GameEntity extends GameObject { } public abstract Game getGame(); + public abstract GameEntityView getView(); } diff --git a/forge-game/src/main/java/forge/game/GameEntityView.java b/forge-game/src/main/java/forge/game/GameEntityView.java new file mode 100644 index 00000000000..79dfe283c51 --- /dev/null +++ b/forge-game/src/main/java/forge/game/GameEntityView.java @@ -0,0 +1,22 @@ +package forge.game; + +import forge.trackable.TrackableObject; + +public abstract class GameEntityView> extends TrackableObject { + public static GameEntityView get(GameEntity e) { + return e == null ? null : e.getView(); + } + + protected GameEntityView(int id0, Class propEnum0) { + super(id0, propEnum0); + } + + protected abstract E preventNextDamageProp(); + + public int getPreventNextDamage() { + return get(preventNextDamageProp()); + } + void updatePreventNextDamage(GameEntity e) { + set(preventNextDamageProp(), e.getPreventNextDamageTotalShields()); + } +} diff --git a/forge-game/src/main/java/forge/game/GameView.java b/forge-game/src/main/java/forge/game/GameView.java new file mode 100644 index 00000000000..5e2a745c077 --- /dev/null +++ b/forge-game/src/main/java/forge/game/GameView.java @@ -0,0 +1,50 @@ +package forge.game; + +import java.util.List; + +import forge.game.card.Card; +import forge.game.card.CardView; +import forge.game.combat.AttackingBand; +import forge.game.combat.Combat; +import forge.game.combat.CombatView; +import forge.game.player.PlayerView; +import forge.game.spellability.SpellAbilityView; +import forge.game.spellability.StackItemView; +import forge.trackable.TrackableIndex; + +public class GameView { + private final TrackableIndex cards = new TrackableIndex(); + private final TrackableIndex players = new TrackableIndex(); + private final TrackableIndex spellAbilities = new TrackableIndex(); + private final TrackableIndex stackItems = new TrackableIndex(); + private CombatView combatView; + + public GameView() { + + } + + public CombatView getCombatView() { + return combatView; + } + + public void refreshCombat(Game game) { + final Combat combat = game.getCombat(); + if (combat == null) { + combatView = null; + return; + } + + combatView = new CombatView(); + for (final AttackingBand b : combat.getAttackingBands()) { + if (b == null) continue; + final GameEntity defender = combat.getDefenderByAttacker(b); + final List blockers = combat.getBlockers(b); + final boolean isBlocked = b.isBlocked() == Boolean.TRUE; + combatView.addAttackingBand( + CardView.getCollection(b.getAttackers()), + GameEntityView.get(defender), + isBlocked ? CardView.getCollection(blockers) : null, + CardView.getCollection(blockers)); + } + } +} diff --git a/forge-game/src/main/java/forge/game/StaticEffects.java b/forge-game/src/main/java/forge/game/StaticEffects.java index 55f9ca5ccaf..6514e8977d2 100644 --- a/forge-game/src/main/java/forge/game/StaticEffects.java +++ b/forge-game/src/main/java/forge/game/StaticEffects.java @@ -146,7 +146,7 @@ public class StaticEffects implements IGameStateObject { if (params.containsKey("AddColor")) { final String colors = params.get("AddColor"); if (colors.equals("ChosenColor")) { - addColors = CardUtil.getShortColorsString(se.getSource().getChosenColor()); + addColors = CardUtil.getShortColorsString(se.getSource().getChosenColors()); } else { addColors = CardUtil.getShortColorsString(new ArrayList(Arrays.asList(colors.split(" & ")))); } @@ -155,7 +155,7 @@ public class StaticEffects implements IGameStateObject { if (params.containsKey("SetColor")) { final String colors = params.get("SetColor"); if (colors.equals("ChosenColor")) { - addColors = CardUtil.getShortColorsString(se.getSource().getChosenColor()); + addColors = CardUtil.getShortColorsString(se.getSource().getChosenColors()); } else { addColors = CardUtil.getShortColorsString(new ArrayList(Arrays.asList(colors.split(" & ")))); } diff --git a/forge-game/src/main/java/forge/game/ability/AbilityUtils.java b/forge-game/src/main/java/forge/game/ability/AbilityUtils.java index e54e5060d9e..68f4d241125 100644 --- a/forge-game/src/main/java/forge/game/ability/AbilityUtils.java +++ b/forge-game/src/main/java/forge/game/ability/AbilityUtils.java @@ -89,19 +89,16 @@ public class AbilityUtils { if (defined.equals("Self")) { c = hostCard; } - else if (defined.equals("OriginalHost")) { c = sa.getRootAbility().getOriginalHost(); } - else if (defined.equals("EffectSource")) { if (hostCard.isType("Effect")) { c = AbilityUtils.findEffectRoot(hostCard); } } - else if (defined.equals("Equipped")) { - c = hostCard.getEquippingCard(); + c = hostCard.getEquipping(); } else if (defined.equals("Enchanted")) { @@ -112,7 +109,6 @@ public class AbilityUtils { c = sa.getRootAbility().getPaidList("Sacrificed").get(0).getEnchantingCard(); } } - else if (defined.endsWith("OfLibrary")) { final List lib = hostCard.getController().getCardsIn(ZoneType.Library); if (lib.size() > 0) { // TopOfLibrary or BottomOfLibrary @@ -121,22 +117,26 @@ public class AbilityUtils { // we don't want this to fall through and return the "Self" return cards; } - } else if (defined.equals("Targeted")) { + } + else if (defined.equals("Targeted")) { final SpellAbility saTargeting = sa.getSATargetingCard(); if (saTargeting != null) { Iterables.addAll(cards, saTargeting.getTargets().getTargetCards()); } - } else if (defined.equals("ThisTargetedCard")) { // do not add parent targeted + } + else if (defined.equals("ThisTargetedCard")) { // do not add parent targeted if (sa != null && sa.getTargets() != null) { Iterables.addAll(cards, sa.getTargets().getTargetCards()); } - } else if (defined.equals("ParentTarget")) { + } + else if (defined.equals("ParentTarget")) { final SpellAbility parent = sa.getParentTargetingCard(); if (parent != null) { Iterables.addAll(cards, parent.getTargets().getTargetCards()); } - } else if (defined.startsWith("Triggered") && (sa != null)) { + } + else if (defined.startsWith("Triggered") && (sa != null)) { final SpellAbility root = sa.getRootAbility(); if (defined.contains("LKICopy")) { //TriggeredCardLKICopy final Object crd = root.getTriggeringObject(defined.substring(9, 13)); @@ -154,7 +154,8 @@ public class AbilityUtils { } } } - } else if (defined.startsWith("Replaced") && (sa != null)) { + } + else if (defined.startsWith("Replaced") && (sa != null)) { final SpellAbility root = sa.getRootAbility(); final Object crd = root.getReplacingObject(defined.substring(8)); if (crd instanceof Card) { @@ -164,7 +165,8 @@ public class AbilityUtils { cards.add(cardItem); } } - } else if (defined.equals("Remembered")) { + } + else if (defined.equals("Remembered")) { if (hostCard.getRemembered().isEmpty()) { final Card newCard = game.getCardState(hostCard); for (final Object o : newCard.getRemembered()) { @@ -179,7 +181,8 @@ public class AbilityUtils { cards.add(game.getCardState((Card) o)); } } - } else if (defined.equals("DirectRemembered")) { + } + else if (defined.equals("DirectRemembered")) { if (hostCard.getRemembered().isEmpty()) { final Card newCard = game.getCardState(hostCard); for (final Object o : newCard.getRemembered()) { @@ -194,7 +197,8 @@ public class AbilityUtils { cards.add((Card) o); } } - } else if (defined.equals("DelayTriggerRemembered")) { + } + else if (defined.equals("DelayTriggerRemembered")) { if (sa.getRootAbility().isTrigger()) { for (Object o : sa.getRootAbility().getTriggerRemembered()) { if (o instanceof Card) { @@ -202,20 +206,24 @@ public class AbilityUtils { } } } - } else if (defined.equals("FirstRemembered")) { + } + else if (defined.equals("FirstRemembered")) { Object o = Iterables.getFirst(hostCard.getRemembered(), null); if (o != null && o instanceof Card) { cards.add(game.getCardState((Card) o)); } - } else if (defined.equals("Clones")) { + } + else if (defined.equals("Clones")) { for (final Card clone : hostCard.getClones()) { cards.add(game.getCardState(clone)); } - } else if (defined.equals("Imprinted")) { + } + else if (defined.equals("Imprinted")) { for (final Card imprint : hostCard.getImprinted()) { cards.add(game.getCardState(imprint)); } - } else if (defined.startsWith("ThisTurnEntered")) { + } + else if (defined.startsWith("ThisTurnEntered")) { final String[] workingCopy = defined.split("_"); ZoneType destination, origin; String validFilter; @@ -231,7 +239,8 @@ public class AbilityUtils { for (final Card cl : CardUtil.getThisTurnEntered(destination, origin, validFilter, hostCard)) { cards.add(game.getCardState(cl)); } - } else if (defined.equals("ChosenCard")) { + } + else if (defined.equals("ChosenCard")) { for (final Card chosen : hostCard.getChosenCard()) { cards.add(game.getCardState(chosen)); } @@ -239,11 +248,12 @@ public class AbilityUtils { else if (defined.startsWith("CardUID_")) { String idString = defined.substring(8); for (final Card cardByID : game.getCardsInGame()) { - if (cardByID.getUniqueNumber() == Integer.valueOf(idString)) { + if (cardByID.getId() == Integer.valueOf(idString)) { cards.add(game.getCardState(cardByID)); } } - } else { + } + else { List list = null; if (defined.startsWith("SacrificedCards")) { list = sa.getRootAbility().getPaidList("SacrificedCards"); @@ -251,50 +261,42 @@ public class AbilityUtils { else if (defined.startsWith("Sacrificed")) { list = sa.getRootAbility().getPaidList("Sacrificed"); } - else if (defined.startsWith("DiscardedCards")) { list = sa.getRootAbility().getPaidList("DiscardedCards"); } else if (defined.startsWith("Discarded")) { list = sa.getRootAbility().getPaidList("Discarded"); } - else if (defined.startsWith("ExiledCards")) { list = sa.getRootAbility().getPaidList("ExiledCards"); } else if (defined.startsWith("Exiled")) { list = sa.getRootAbility().getPaidList("Exiled"); } - else if (defined.startsWith("TappedCards")) { list = sa.getRootAbility().getPaidList("TappedCards"); } else if (defined.startsWith("Tapped")) { list = sa.getRootAbility().getPaidList("Tapped"); } - else if (defined.startsWith("UntappedCards")) { list = sa.getRootAbility().getPaidList("UntappedCards"); } else if (defined.startsWith("Untapped")) { list = sa.getRootAbility().getPaidList("Untapped"); } - else if (defined.startsWith("Valid ")) { String validDefined = defined.substring("Valid ".length()); list = CardLists.getValidCards(game.getCardsIn(ZoneType.Battlefield), validDefined.split(","), hostCard.getController(), hostCard); } - else if (defined.startsWith("ValidHand ")) { String validDefined = defined.substring("ValidHand ".length()); list = CardLists.getValidCards(game.getCardsIn(ZoneType.Hand), validDefined.split(","), hostCard.getController(), hostCard); } - else if (defined.startsWith("ValidAll ")) { String validDefined = defined.substring("ValidAll ".length()); list = CardLists.getValidCards(game.getCardsInGame(), validDefined.split(","), hostCard.getController(), hostCard); } - else { return cards; } @@ -307,7 +309,6 @@ public class AbilityUtils { if (c != null) { cards.add(c); } - return cards; } @@ -1151,7 +1152,7 @@ public class AbilityUtils { for (SpellAbility targetSpell : saTargeting.getTargets().getTargetSpells()) { SpellAbilityStackInstance stackInstance = game.getStack().getInstanceFromSpellAbility(targetSpell); if (stackInstance != null) { - SpellAbility instanceSA = stackInstance.getSpellAbility(); + SpellAbility instanceSA = stackInstance.getSpellAbility(true); if (instanceSA != null) { sas.add(instanceSA); } diff --git a/forge-game/src/main/java/forge/game/ability/effects/AnimateAllEffect.java b/forge-game/src/main/java/forge/game/ability/effects/AnimateAllEffect.java index 7d91dfead15..b663591a146 100644 --- a/forge-game/src/main/java/forge/game/ability/effects/AnimateAllEffect.java +++ b/forge-game/src/main/java/forge/game/ability/effects/AnimateAllEffect.java @@ -89,7 +89,7 @@ public class AnimateAllEffect extends AnimateEffectBase { if (sa.hasParam("Colors")) { final String colors = sa.getParam("Colors"); if (colors.equals("ChosenColor")) { - tmpDesc = CardUtil.getShortColorsString(host.getChosenColor()); + tmpDesc = CardUtil.getShortColorsString(host.getChosenColors()); } else { tmpDesc = CardUtil.getShortColorsString(new ArrayList(Arrays.asList(colors.split(",")))); } diff --git a/forge-game/src/main/java/forge/game/ability/effects/AnimateEffect.java b/forge-game/src/main/java/forge/game/ability/effects/AnimateEffect.java index 36483d2166f..e3e6d005716 100644 --- a/forge-game/src/main/java/forge/game/ability/effects/AnimateEffect.java +++ b/forge-game/src/main/java/forge/game/ability/effects/AnimateEffect.java @@ -109,7 +109,7 @@ public class AnimateEffect extends AnimateEffectBase { final String colors = sa.getParam("Colors"); if (colors.equals("ChosenColor")) { - tmpDesc = CardUtil.getShortColorsString(source.getChosenColor()); + tmpDesc = CardUtil.getShortColorsString(source.getChosenColors()); } else { tmpDesc = CardUtil.getShortColorsString(new ArrayList(Arrays.asList(colors.split(",")))); } diff --git a/forge-game/src/main/java/forge/game/ability/effects/ChangeTargetsEffect.java b/forge-game/src/main/java/forge/game/ability/effects/ChangeTargetsEffect.java index 0281bcebe7f..c3cdd033ff3 100644 --- a/forge-game/src/main/java/forge/game/ability/effects/ChangeTargetsEffect.java +++ b/forge-game/src/main/java/forge/game/ability/effects/ChangeTargetsEffect.java @@ -50,21 +50,21 @@ public class ChangeTargetsEffect extends SpellAbilityEffect { // Redirect rules read 'you MAY choose new targets' ... okay! // TODO: Don't even ask to change targets, if the SA and subs don't actually have targets boolean isOptional = sa.hasParam("Optional"); - if( isOptional && !chooser.getController().confirmAction(sa, null, "Do you want to change targets of " + tgtSA.getHostCard() + "?")) + if (isOptional && !chooser.getController().confirmAction(sa, null, "Do you want to change targets of " + tgtSA.getHostCard() + "?")) { continue; - - if( changesOneTarget ) { + } + if (changesOneTarget) { // 1. choose a target of target spell List> allTargets = new ArrayList<>(); while(changingTgtSI != null) { - SpellAbility changedSa = changingTgtSI.getSpellAbility(); - if(changedSa.usesTargeting()) { + SpellAbility changedSa = changingTgtSI.getSpellAbility(true); + if (changedSa.usesTargeting()) { for(GameObject it : changedSa.getTargets().getTargets()) allTargets.add(ImmutablePair.of(changingTgtSI, it)); } changingTgtSI = changingTgtSI.getSubInstance(); } - if( allTargets.isEmpty() ) { + if (allTargets.isEmpty()) { // is it an error or not? System.err.println("Player managed to target a spell without targets with Spellskite's ability."); return; @@ -80,28 +80,33 @@ public class ChangeTargetsEffect extends SpellAbilityEffect { replaceIn.updateTarget(newTargetBlock); // 3. test if updated choices would be correct. GameObject newTarget = Iterables.getFirst(getDefinedCardsOrTargeted(sa), null); - if(replaceIn.getSpellAbility().canTarget(newTarget)) { + if (replaceIn.getSpellAbility(true).canTarget(newTarget)) { newTargetBlock.add(newTarget); replaceIn.updateTarget(newTargetBlock); - } else + } + else { replaceIn.updateTarget(oldTargetBlock); - } else { + } + } + else { while(changingTgtSI != null) { - SpellAbility changingTgtSA = changingTgtSI.getSpellAbility(); + SpellAbility changingTgtSA = changingTgtSI.getSpellAbility(true); if (sa.hasParam("RandomTarget")){ changingTgtSA.resetTargets(); List candidates = changingTgtSA.getTargetRestrictions().getAllCandidates(changingTgtSA, true); GameEntity choice = Aggregates.random(candidates); changingTgtSA.getTargets().add(choice); changingTgtSI.updateTarget(changingTgtSA.getTargets()); - } else if (sa.hasParam("DefinedMagnet")){ + } + else if (sa.hasParam("DefinedMagnet")){ GameObject newTarget = Iterables.getFirst(getDefinedCardsOrTargeted(sa, "DefinedMagnet"), null); - if(changingTgtSA.canTarget(newTarget)) { + if (changingTgtSA.canTarget(newTarget)) { changingTgtSA.resetTargets(); changingTgtSA.getTargets().add(newTarget); changingTgtSI.updateTarget(changingTgtSA.getTargets()); } - } else { + } + else { // Update targets, with a potential new target TargetChoices newTarget = sa.getActivatingPlayer().getController().chooseNewTargetsFor(changingTgtSA); if (null != newTarget) { diff --git a/forge-game/src/main/java/forge/game/ability/effects/ChangeZoneEffect.java b/forge-game/src/main/java/forge/game/ability/effects/ChangeZoneEffect.java index cba1b4c36cc..4e7032994c4 100644 --- a/forge-game/src/main/java/forge/game/ability/effects/ChangeZoneEffect.java +++ b/forge-game/src/main/java/forge/game/ability/effects/ChangeZoneEffect.java @@ -471,14 +471,14 @@ public class ChangeZoneEffect extends SpellAbilityEffect { tgtC.enchantEntity(attachedTo); } else if (tgtC.isEquipment()) { //Equipment if (tgtC.isEquipping()) { - final Card oldEquiped = tgtC.getEquippingCard(); + final Card oldEquiped = tgtC.getEquipping(); if ( null != oldEquiped ) tgtC.unEquipCard(oldEquiped); } tgtC.equipCard(attachedTo); } else { // fortification if (tgtC.isFortifying()) { - final Card oldFortified = tgtC.getFortifyingCard(); + final Card oldFortified = tgtC.getFortifying(); if( oldFortified != null ) tgtC.unFortifyCard(oldFortified); } @@ -856,7 +856,7 @@ public class ChangeZoneEffect extends SpellAbilityEffect { } else if (c.isEquipment()) { //Equipment if (c.isEquipping()) { - final Card oldEquiped = c.getEquippingCard(); + final Card oldEquiped = c.getEquipping(); if ( null != oldEquiped ) c.unEquipCard(oldEquiped); } @@ -864,7 +864,7 @@ public class ChangeZoneEffect extends SpellAbilityEffect { } else { if (c.isFortifying()) { - final Card oldFortified = c.getFortifyingCard(); + final Card oldFortified = c.getFortifying(); if ( null != oldFortified ) c.unFortifyCard(oldFortified); } diff --git a/forge-game/src/main/java/forge/game/ability/effects/ChooseColorEffect.java b/forge-game/src/main/java/forge/game/ability/effects/ChooseColorEffect.java index 7fa8d9b6aa3..855f30c2634 100644 --- a/forge-game/src/main/java/forge/game/ability/effects/ChooseColorEffect.java +++ b/forge-game/src/main/java/forge/game/ability/effects/ChooseColorEffect.java @@ -68,7 +68,7 @@ public class ChooseColorEffect extends SpellAbilityEffect { if (chosenColors.isEmpty()) { return; } - card.setChosenColor(chosenColors); + card.setChosenColors(chosenColors); p.getGame().getAction().nofityOfValue(sa, card, p.getName() + " picked " + Lang.joinHomogenous(chosenColors), p); } } diff --git a/forge-game/src/main/java/forge/game/ability/effects/ChooseSourceEffect.java b/forge-game/src/main/java/forge/game/ability/effects/ChooseSourceEffect.java index c2ed4299543..048026dda77 100644 --- a/forge-game/src/main/java/forge/game/ability/effects/ChooseSourceEffect.java +++ b/forge-game/src/main/java/forge/game/ability/effects/ChooseSourceEffect.java @@ -61,8 +61,9 @@ public class ChooseSourceEffect extends SpellAbilityEffect { stackSources.add(stackinst.getSourceCard()); } // Get the list of cards that are referenced by effects on the stack - if (null != stackinst.getSpellAbility().getTriggeringObjects()) { - for (Object c : stackinst.getSpellAbility().getTriggeringObjects().values()) { + SpellAbility siSpellAbility = stackinst.getSpellAbility(true); + if (siSpellAbility.getTriggeringObjects() != null) { + for (Object c : siSpellAbility.getTriggeringObjects().values()) { if (c instanceof Card) { if (!stackSources.contains((Card) c)) { referencedSources.add((Card) c); @@ -70,12 +71,12 @@ public class ChooseSourceEffect extends SpellAbilityEffect { } } } - if (null != stackinst.getSpellAbility().getTargetCard()) { - referencedSources.add(stackinst.getSpellAbility().getTargetCard()); + if (siSpellAbility.getTargetCard() != null) { + referencedSources.add(siSpellAbility.getTargetCard()); } // TODO: is this necessary? - if (null != stackinst.getSpellAbility().getReplacingObjects()) { - for (Object c : stackinst.getSpellAbility().getReplacingObjects().values()) { + if (siSpellAbility.getReplacingObjects() != null) { + for (Object c : siSpellAbility.getReplacingObjects().values()) { if (c instanceof Card) { if (!stackSources.contains((Card) c)) { referencedSources.add((Card) c); @@ -85,7 +86,6 @@ public class ChooseSourceEffect extends SpellAbilityEffect { } } - if (sa.hasParam("Choices")) { permanentSources = CardLists.getValidCards(permanentSources, sa.getParam("Choices"), host.getController(), host); diff --git a/forge-game/src/main/java/forge/game/ability/effects/CloneEffect.java b/forge-game/src/main/java/forge/game/ability/effects/CloneEffect.java index 7f366f244e1..55b5a07321a 100644 --- a/forge-game/src/main/java/forge/game/ability/effects/CloneEffect.java +++ b/forge-game/src/main/java/forge/game/ability/effects/CloneEffect.java @@ -106,12 +106,12 @@ public class CloneEffect extends SpellAbilityEffect { tgtCard.clearStates(CardCharacteristicName.Cloner); } // add "Cloner" state to clone - tgtCard.addAlternateState(CardCharacteristicName.Cloner); + tgtCard.addAlternateState(CardCharacteristicName.Cloner, false); tgtCard.switchStates(CardCharacteristicName.Original, CardCharacteristicName.Cloner); tgtCard.setState(CardCharacteristicName.Original); } else { //copy Original state to Cloned - tgtCard.addAlternateState(CardCharacteristicName.Cloned); + tgtCard.addAlternateState(CardCharacteristicName.Cloned, false); tgtCard.switchStates(CardCharacteristicName.Original, CardCharacteristicName.Cloned); if (tgtCard.isFlipCard()) { tgtCard.setState(CardCharacteristicName.Original); @@ -285,7 +285,7 @@ public class CloneEffect extends SpellAbilityEffect { if (sa.hasParam("Colors")) { final String colors = sa.getParam("Colors"); if (colors.equals("ChosenColor")) { - shortColors = CardUtil.getShortColorsString(tgtCard.getChosenColor()); + shortColors = CardUtil.getShortColorsString(tgtCard.getChosenColors()); } else { shortColors = CardUtil.getShortColorsString(Arrays.asList(colors.split(","))); } diff --git a/forge-game/src/main/java/forge/game/ability/effects/ControlGainEffect.java b/forge-game/src/main/java/forge/game/ability/effects/ControlGainEffect.java index d5b4ff9513b..bc9b791ccf3 100644 --- a/forge-game/src/main/java/forge/game/ability/effects/ControlGainEffect.java +++ b/forge-game/src/main/java/forge/game/ability/effects/ControlGainEffect.java @@ -37,7 +37,7 @@ public class ControlGainEffect extends SpellAbilityEffect { for (final Card c : getDefinedCards(sa)) { sb.append(" "); if (c.isFaceDown()) { - sb.append("Face-down creature (").append(c.getUniqueNumber()).append(')'); + sb.append("Face-down creature (").append(c.getId()).append(')'); } else { sb.append(c); } diff --git a/forge-game/src/main/java/forge/game/ability/effects/CounterEffect.java b/forge-game/src/main/java/forge/game/ability/effects/CounterEffect.java index d54f9b44116..9042cb8e743 100644 --- a/forge-game/src/main/java/forge/game/ability/effects/CounterEffect.java +++ b/forge-game/src/main/java/forge/game/ability/effects/CounterEffect.java @@ -26,7 +26,7 @@ public class CounterEffect extends SpellAbilityEffect { if (sa.hasParam("AllType")) { sas = new ArrayList(); for (SpellAbilityStackInstance si : game.getStack()) { - SpellAbility spell = si.getSpellAbility(); + SpellAbility spell = si.getSpellAbility(true); if (sa.getParam("AllType").equals("Spell") && !spell.isSpell()) { continue; } @@ -71,7 +71,7 @@ public class CounterEffect extends SpellAbilityEffect { if (sa.hasParam("AllType")) { sas = new ArrayList(); for (SpellAbilityStackInstance si : game.getStack()) { - SpellAbility spell = si.getSpellAbility(); + SpellAbility spell = si.getSpellAbility(true); if (sa.getParam("AllType").equals("Spell") && !spell.isSpell()) { continue; } diff --git a/forge-game/src/main/java/forge/game/ability/effects/DamagePreventEffect.java b/forge-game/src/main/java/forge/game/ability/effects/DamagePreventEffect.java index b5575de5eb7..686248dd8cf 100644 --- a/forge-game/src/main/java/forge/game/ability/effects/DamagePreventEffect.java +++ b/forge-game/src/main/java/forge/game/ability/effects/DamagePreventEffect.java @@ -104,7 +104,7 @@ public class DamagePreventEffect extends SpellAbilityEffect { effTgts = AbilityUtils.getDefinedObjects(host, sa.getParam("ShieldEffectTarget"), sa); for (final Object effTgt : effTgts) { if (effTgt instanceof Card) { - effTgtString = String.valueOf(((Card) effTgt).getUniqueNumber()); + effTgtString = String.valueOf(((Card) effTgt).getId()); effectMap.put("ShieldEffectTarget", "CardUID_" + effTgtString); } else if (effTgt instanceof Player) { effTgtString = ((Player) effTgt).getName(); @@ -131,7 +131,7 @@ public class DamagePreventEffect extends SpellAbilityEffect { effTgts = AbilityUtils.getDefinedObjects(host, sa.getParam("ShieldEffectTarget"), sa); for (final Object effTgt : effTgts) { if (effTgt instanceof Card) { - effTgtString = String.valueOf(((Card) effTgt).getUniqueNumber()); + effTgtString = String.valueOf(((Card) effTgt).getId()); effectMap.put("ShieldEffectTarget", "CardUID_" + effTgtString); } else if (effTgt instanceof Player) { effTgtString = ((Player) effTgt).getName(); diff --git a/forge-game/src/main/java/forge/game/ability/effects/DestroyEffect.java b/forge-game/src/main/java/forge/game/ability/effects/DestroyEffect.java index 0650f5ce58e..1845ac6350b 100644 --- a/forge-game/src/main/java/forge/game/ability/effects/DestroyEffect.java +++ b/forge-game/src/main/java/forge/game/ability/effects/DestroyEffect.java @@ -32,7 +32,7 @@ public class DestroyEffect extends SpellAbilityEffect { while (it.hasNext()) { final Card tgtC = it.next(); if (tgtC.isFaceDown()) { - sb.append("Morph ").append("(").append(tgtC.getUniqueNumber()).append(")"); + sb.append("Morph ").append("(").append(tgtC.getId()).append(")"); } else { sb.append(tgtC); } diff --git a/forge-game/src/main/java/forge/game/ability/effects/EffectEffect.java b/forge-game/src/main/java/forge/game/ability/effects/EffectEffect.java index 8c3fff7c0cb..fcf6e384f26 100644 --- a/forge-game/src/main/java/forge/game/ability/effects/EffectEffect.java +++ b/forge-game/src/main/java/forge/game/ability/effects/EffectEffect.java @@ -189,8 +189,8 @@ public class EffectEffect extends SpellAbilityEffect { } // Set Chosen Color(s) - if (!hostCard.getChosenColor().isEmpty()) { - eff.setChosenColor(hostCard.getChosenColor()); + if (!hostCard.getChosenColors().isEmpty()) { + eff.setChosenColors(hostCard.getChosenColors()); } // Set Chosen name diff --git a/forge-game/src/main/java/forge/game/ability/effects/PlayLandVariantEffect.java b/forge-game/src/main/java/forge/game/ability/effects/PlayLandVariantEffect.java index 332e4ee52fa..9c3b44d2ef4 100644 --- a/forge-game/src/main/java/forge/game/ability/effects/PlayLandVariantEffect.java +++ b/forge-game/src/main/java/forge/game/ability/effects/PlayLandVariantEffect.java @@ -75,7 +75,7 @@ public class PlayLandVariantEffect extends SpellAbilityEffect { } String imageFileName = game.getRules().canCloneUseTargetsImage ? source.getImageKey() : random.getImageKey(); - source.addAlternateState(CardCharacteristicName.Cloner); + source.addAlternateState(CardCharacteristicName.Cloner, false); source.switchStates(CardCharacteristicName.Original, CardCharacteristicName.Cloner); source.setState(CardCharacteristicName.Original); CardCharacteristicName stateToCopy = random.getCurState(); diff --git a/forge-game/src/main/java/forge/game/ability/effects/ProtectAllEffect.java b/forge-game/src/main/java/forge/game/ability/effects/ProtectAllEffect.java index eee0d86e360..1615cc2d261 100644 --- a/forge-game/src/main/java/forge/game/ability/effects/ProtectAllEffect.java +++ b/forge-game/src/main/java/forge/game/ability/effects/ProtectAllEffect.java @@ -56,7 +56,7 @@ public class ProtectAllEffect extends SpellAbilityEffect { game.getAction().nofityOfValue(sa, choser, Lang.joinHomogenous(gains), choser); } else { if (sa.getParam("Gains").equals("ChosenColor")) { - for (final String color : host.getChosenColor()) { + for (final String color : host.getChosenColors()) { gains.add(color.toLowerCase()); } } else if (sa.getParam("Gains").equals("TargetedCardColor")) { diff --git a/forge-game/src/main/java/forge/game/ability/effects/ProtectEffect.java b/forge-game/src/main/java/forge/game/ability/effects/ProtectEffect.java index 9672a96da0a..938b3e15bb7 100644 --- a/forge-game/src/main/java/forge/game/ability/effects/ProtectEffect.java +++ b/forge-game/src/main/java/forge/game/ability/effects/ProtectEffect.java @@ -114,7 +114,7 @@ public class ProtectEffect extends SpellAbilityEffect { game.getAction().nofityOfValue(sa, choser, Lang.joinHomogenous(gains), choser); } else { if (sa.getParam("Gains").equals("ChosenColor")) { - for (final String color : host.getChosenColor()) { + for (final String color : host.getChosenColors()) { gains.add(color.toLowerCase()); } } else { diff --git a/forge-game/src/main/java/forge/game/ability/effects/PumpEffect.java b/forge-game/src/main/java/forge/game/ability/effects/PumpEffect.java index 804884f0183..075405f8f26 100644 --- a/forge-game/src/main/java/forge/game/ability/effects/PumpEffect.java +++ b/forge-game/src/main/java/forge/game/ability/effects/PumpEffect.java @@ -209,7 +209,7 @@ public class PumpEffect extends SpellAbilityEffect { if (defined.equals("ChosenType")) { replaced = host.getChosenType(); } else if (defined.equals("CardUIDSource")) { - replaced = "CardUID_" + String.valueOf(host.getUniqueNumber()); + replaced = "CardUID_" + String.valueOf(host.getId()); } for (int i = 0; i < keywords.size(); i++) { keywords.set(i, keywords.get(i).replaceAll(defined, replaced)); diff --git a/forge-game/src/main/java/forge/game/ability/effects/RegenerateEffect.java b/forge-game/src/main/java/forge/game/ability/effects/RegenerateEffect.java index 5519073276e..c513b0694a1 100644 --- a/forge-game/src/main/java/forge/game/ability/effects/RegenerateEffect.java +++ b/forge-game/src/main/java/forge/game/ability/effects/RegenerateEffect.java @@ -73,7 +73,7 @@ public class RegenerateEffect extends SpellAbilityEffect { } else if (sa.hasParam("ReplaceCardUID")) { // Debt of Loyalty String def = sa.getParam("ReplaceCardUID"); List replaced = AbilityUtils.getDefinedCards(sourceCard, def, sa); - abString = abString.replace(def, replaced.isEmpty() ? "" : Integer.toString(replaced.get(0).getUniqueNumber())); + abString = abString.replace(def, replaced.isEmpty() ? "" : Integer.toString(replaced.get(0).getId())); } triggerSA = AbilityFactory.getAbility(abString, sourceCard); triggerSA.setActivatingPlayer(sa.getActivatingPlayer()); diff --git a/forge-game/src/main/java/forge/game/ability/effects/SetStateEffect.java b/forge-game/src/main/java/forge/game/ability/effects/SetStateEffect.java index 0ee19c42103..4a52f35e06e 100644 --- a/forge-game/src/main/java/forge/game/ability/effects/SetStateEffect.java +++ b/forge-game/src/main/java/forge/game/ability/effects/SetStateEffect.java @@ -28,7 +28,7 @@ public class SetStateEffect extends SpellAbilityEffect { while (it.hasNext()) { final Card tgtC = it.next(); if (tgtC.isFaceDown()) { - sb.append("Morph ").append("(").append(tgtC.getUniqueNumber()).append(")"); + sb.append("Morph ").append("(").append(tgtC.getId()).append(")"); } else { sb.append(tgtC); } diff --git a/forge-game/src/main/java/forge/game/ability/effects/TokenEffect.java b/forge-game/src/main/java/forge/game/ability/effects/TokenEffect.java index 3d87e8a63a9..d733b4a34cc 100644 --- a/forge-game/src/main/java/forge/game/ability/effects/TokenEffect.java +++ b/forge-game/src/main/java/forge/game/ability/effects/TokenEffect.java @@ -170,7 +170,7 @@ public class TokenEffect extends SpellAbilityEffect { for (int i = 0; i < substitutedColors.length; i++) { if (substitutedColors[i].equals("ChosenColor")) { // this currently only supports 1 chosen color - substitutedColors[i] = host.getChosenColor().get(0); + substitutedColors[i] = host.getChosenColors().get(0); } } String colorDesc = ""; diff --git a/forge-game/src/main/java/forge/game/ability/effects/UnattachAllEffect.java b/forge-game/src/main/java/forge/game/ability/effects/UnattachAllEffect.java index 495c2d29c22..e7698add90c 100644 --- a/forge-game/src/main/java/forge/game/ability/effects/UnattachAllEffect.java +++ b/forge-game/src/main/java/forge/game/ability/effects/UnattachAllEffect.java @@ -24,11 +24,11 @@ public class UnattachAllEffect extends SpellAbilityEffect { //AbilityFactoryAttach.handleUnattachAura(cardToUnattach, c, gainControl); } else if (cardToUnattach.isEquipment()) { if (cardToUnattach.isEquipping() && c.getEquippedBy().contains(cardToUnattach)) { - cardToUnattach.unEquipCard(cardToUnattach.getEquipping().get(0)); + cardToUnattach.unEquipCard(cardToUnattach.getEquipping()); } } else if (cardToUnattach.isFortification()) { if (cardToUnattach.isFortifying() && c.getFortifiedBy().contains(cardToUnattach)) { - cardToUnattach.unFortifyCard(cardToUnattach.getFortifying().get(0)); + cardToUnattach.unFortifyCard(cardToUnattach.getFortifying()); } } } else if (o instanceof Player) { diff --git a/forge-game/src/main/java/forge/game/ability/effects/UnattachEffect.java b/forge-game/src/main/java/forge/game/ability/effects/UnattachEffect.java index 1ada2ca58a9..9754b0f6d4f 100644 --- a/forge-game/src/main/java/forge/game/ability/effects/UnattachEffect.java +++ b/forge-game/src/main/java/forge/game/ability/effects/UnattachEffect.java @@ -33,11 +33,11 @@ public class UnattachEffect extends SpellAbilityEffect { //AbilityFactoryAttach.handleUnattachAura(cardToUnattach, c, gainControl); } else if (cardToUnattach.isEquipment()) { if (cardToUnattach.isEquipping()) { - cardToUnattach.unEquipCard(cardToUnattach.getEquipping().get(0)); + cardToUnattach.unEquipCard(cardToUnattach.getEquipping()); } } else if (cardToUnattach.isFortification()) { if (cardToUnattach.isFortifying()) { - cardToUnattach.unFortifyCard(cardToUnattach.getFortifying().get(0)); + cardToUnattach.unFortifyCard(cardToUnattach.getFortifying()); } } } diff --git a/forge-game/src/main/java/forge/game/card/Card.java b/forge-game/src/main/java/forge/game/card/Card.java index ba07d500816..d6e839c83d3 100644 --- a/forge-game/src/main/java/forge/game/card/Card.java +++ b/forge-game/src/main/java/forge/game/card/Card.java @@ -36,6 +36,7 @@ import forge.game.ability.AbilityFactory; import forge.game.ability.AbilityUtils; import forge.game.ability.ApiType; import forge.game.card.CardPredicates.Presets; +import forge.game.card.CardView; import forge.game.combat.AttackingBand; import forge.game.combat.Combat; import forge.game.cost.Cost; @@ -76,13 +77,13 @@ import java.util.concurrent.CopyOnWriteArrayList; *

* * Can now be used as keys in Tree data structures. The comparison is based - * entirely on getUniqueNumber(). + * entirely on id. * * @author Forge * @version $Id$ */ public class Card extends GameEntity implements Comparable, IIdentifiable { - private final int uniqueNumber; + private final int id; private final IPaperCard paperCard; private final Map characteristicsMap @@ -101,15 +102,13 @@ public class Card extends GameEntity implements Comparable, IIdentifiable // which equipment cards are equipping this card? private ArrayList equippedBy = new ArrayList(); - // equipping size will always be 0 or 1 // if this card is of the type equipment, what card is it currently equipping? - private ArrayList equipping = new ArrayList(); + private Card equipping = null; // which fortification cards are fortifying this card? private ArrayList fortifiedBy = new ArrayList(); - // fortifying size will always be 0 or 1 // if this card is of the type fortification, what card is it currently fortifying? - private ArrayList fortifying = new ArrayList(); + private Card fortifying = null; // which auras enchanted this card? // if this card is an Aura, what Entity is it enchanting? @@ -187,7 +186,7 @@ public class Card extends GameEntity implements Comparable, IIdentifiable private int damage; // regeneration - private List nShield = new ArrayList(); + private List shields = new ArrayList(); private int regeneratedThisTurn = 0; private int turnInZone; @@ -214,7 +213,7 @@ public class Card extends GameEntity implements Comparable, IIdentifiable private String echoCost = ""; private Cost miracleCost = null; private String chosenType = ""; - private List chosenColor = new ArrayList(); + private List chosenColors = new ArrayList(); private String namedCard = ""; private int chosenNumber; private Player chosenPlayer; @@ -244,6 +243,9 @@ public class Card extends GameEntity implements Comparable, IIdentifiable private int countersAdded = 0; + private CardRules cardRules; + private final CardView view; + // Enumeration for CMC request types public enum SplitCMCMode { CurrentSideCMC, @@ -256,8 +258,8 @@ public class Card extends GameEntity implements Comparable, IIdentifiable * Instantiates a new card not associated to any paper card. * @param id the unique id of the new card. */ - public Card(final int id) { - this(id, null); + public Card(final int id0) { + this(id0, null); } /** @@ -268,23 +270,16 @@ public class Card extends GameEntity implements Comparable, IIdentifiable * card. * @see IPaperCard */ - public Card(final int id, final IPaperCard paperCard) { - this.uniqueNumber = id; - this.paperCard = paperCard; - this.characteristicsMap.put(CardCharacteristicName.Original, new CardCharacteristics()); - this.characteristicsMap.put(CardCharacteristicName.FaceDown, CardUtil.getFaceDownCharacteristic()); + public Card(final int id0, final IPaperCard paperCard0) { + id = id0; + paperCard = paperCard0; + characteristicsMap.put(CardCharacteristicName.Original, new CardCharacteristics()); + characteristicsMap.put(CardCharacteristicName.FaceDown, CardUtil.getFaceDownCharacteristic()); + view = new CardView(id0); } - /** - * Sets the state. - * - * @param state - * the state - * @return true, if successful - */ public boolean changeToState(final CardCharacteristicName state) { - - CardCharacteristicName cur = this.curCharacteristics; + CardCharacteristicName cur = curCharacteristics; if (!setState(state)) { return false; @@ -304,28 +299,23 @@ public class Card extends GameEntity implements Comparable, IIdentifiable return true; } - /** - * Sets the state. - * - * @param state - * the state - * @return true, if successful - */ public boolean setState(final CardCharacteristicName state) { - if (state == CardCharacteristicName.FaceDown && this.isDoubleFaced()) { + if (state == CardCharacteristicName.FaceDown && isDoubleFaced()) { return false; // Doublefaced cards can't be turned face-down. } - if (!this.characteristicsMap.containsKey(state)) { - System.out.println(this.getName() + " tried to switch to non-existant state \"" + state + "\"!"); + if (!characteristicsMap.containsKey(state)) { + System.out.println(getName() + " tried to switch to non-existant state \"" + state + "\"!"); return false; // Nonexistant state. } - if (state.equals(this.curCharacteristics)) { + if (state.equals(curCharacteristics)) { return false; } - this.curCharacteristics = state; + curCharacteristics = state; + + view.updateState(this, true); Game game = getGame(); if (game != null) { @@ -335,74 +325,43 @@ public class Card extends GameEntity implements Comparable, IIdentifiable return true; } - /** - * Gets the states. - * - * @return the states - */ public Set getStates() { - return this.characteristicsMap.keySet(); + return characteristicsMap.keySet(); } - /** - * Gets the cur state. - * - * @return the cur state - */ public CardCharacteristicName getCurState() { - return this.curCharacteristics; + return curCharacteristics; } - /** - * Switch states. - * - * @param from - * the from - * @param to - * the to - */ public void switchStates(final CardCharacteristicName from, final CardCharacteristicName to) { - final CardCharacteristics tmp = this.characteristicsMap.get(from); - this.characteristicsMap.put(from, this.characteristicsMap.get(to)); - this.characteristicsMap.put(to, tmp); + final CardCharacteristics tmp = characteristicsMap.get(from); + characteristicsMap.put(from, characteristicsMap.get(to)); + characteristicsMap.put(to, tmp); + view.updateState(this, false); } - /** - * Clear states. - * - * @param state - * the state - */ public void clearStates(final CardCharacteristicName state) { - this.characteristicsMap.remove(state); + if (characteristicsMap.remove(state) != null) { + view.updateState(this, false); + } } public void setPreFaceDownCharacteristic(CardCharacteristicName preCharacteristic) { - this.preTFDCharacteristic = preCharacteristic; + preTFDCharacteristic = preCharacteristic; } - /** - * Turn face down. - * - * @return true, if successful - */ public boolean turnFaceDown() { - if (!this.isDoubleFaced()) { - this.preTFDCharacteristic = this.curCharacteristics; - return this.setState(CardCharacteristicName.FaceDown); + if (!isDoubleFaced()) { + preTFDCharacteristic = curCharacteristics; + return setState(CardCharacteristicName.FaceDown); } return false; } - /** - * Turn face up. - * - * @return true, if successful - */ public boolean turnFaceUp() { - if (this.curCharacteristics == CardCharacteristicName.FaceDown) { - boolean result = this.setState(this.preTFDCharacteristic); + if (curCharacteristics == CardCharacteristicName.FaceDown) { + boolean result = setState(preTFDCharacteristic); if (result) { getGame().getTriggerHandler().registerActiveTrigger(this, false); // Run replacement effects @@ -422,75 +381,38 @@ public class Card extends GameEntity implements Comparable, IIdentifiable return false; } - /** - * Gets the state. - * - * @param state - * the state - * @return the state - */ public CardCharacteristics getState(final CardCharacteristicName state) { - return this.characteristicsMap.get(state); + return characteristicsMap.get(state); } - /** - * Gets the characteristics. - * - * @return the characteristics - */ public CardCharacteristics getCharacteristics() { - return this.characteristicsMap.get(this.curCharacteristics); + return characteristicsMap.get(curCharacteristics); } - /** - * addAlternateState. - * - * @param state - * the state - */ - public final void addAlternateState(final CardCharacteristicName state) { - this.characteristicsMap.put(state, new CardCharacteristics()); + public final void addAlternateState(final CardCharacteristicName state, final boolean updateView) { + characteristicsMap.put(state, new CardCharacteristics()); + if (updateView) { + view.updateState(this, false); + } } - /* - * (non-Javadoc) - * - * @see forge.GameEntity#getName() - */ @Override public final String getName() { - return this.getCharacteristics().getName(); + return getCharacteristics().getName(); } - /* - * (non-Javadoc) - * - * @see forge.GameEntity#setName(java.lang.String) - */ @Override public final void setName(final String name0) { - this.getCharacteristics().setName(name0); + getCharacteristics().setName(name0); } - /** - * - * isInAlternateState. - * - * @return boolean - */ public final boolean isInAlternateState() { - return this.curCharacteristics != CardCharacteristicName.Original - && this.curCharacteristics != CardCharacteristicName.Cloned; + return curCharacteristics != CardCharacteristicName.Original + && curCharacteristics != CardCharacteristicName.Cloned; } - /** - * - * hasAlternateState. - * - * @return boolean - */ public final boolean hasAlternateState() { - return this.characteristicsMap.keySet().size() > 2; + return characteristicsMap.keySet().size() > 2; } public final boolean isDoubleFaced() { @@ -504,206 +426,88 @@ public class Card extends GameEntity implements Comparable, IIdentifiable public final boolean isSplitCard() { return characteristicsMap.containsKey(CardCharacteristicName.LeftSplit); } - - /** - * Checks if is cloned. - * - * @return true, if is cloned - */ + public boolean isCloned() { return characteristicsMap.containsKey(CardCharacteristicName.Cloner); } - /** - * - * TODO Write javadoc for this method. - * - * @return a String array - */ public static List getStorableSVars() { return Card.storableSVars; } - /** - * - * TODO Write javadoc for this method. - * - * @param c - * a Card object - */ public final void addDevoured(final Card c) { - this.devouredCards.add(c); + devouredCards.add(c); } - /** - * - * TODO Write javadoc for this method. - */ public final void clearDevoured() { - this.devouredCards.clear(); + devouredCards.clear(); } - /** - * - * TODO Write javadoc for this method. - * - * @return a List object - */ public final List getDevoured() { - return this.devouredCards; + return devouredCards; } public final void addRememberMap(final GameEntity e, final List o) { - this.rememberMap.addAll(e, o); + rememberMap.addAll(e, o); } public MapOfLists getRememberMap() { return rememberMap; } - /** - *

- * addRemembered. - *

- * - * @param o - * a {@link java.lang.Object} object. - */ public final void addRemembered(final Object o) { - this.rememberedObjects.add(o); + rememberedObjects.add(o); } - /** - *

- * removeRemembered. - *

- * - * @param o - * a {@link java.lang.Object} object. - */ public final void removeRemembered(final Object o) { - this.rememberedObjects.remove(o); + rememberedObjects.remove(o); } - /** - *

- * getRemembered. - *

- * - * @return a {@link java.util.ArrayList} object. - */ public final ArrayList getRemembered() { - return this.rememberedObjects; + return rememberedObjects; } - /** - *

- * clearRemembered. - *

- */ public final void clearRemembered() { - this.rememberedObjects.clear(); + rememberedObjects.clear(); } - /** - *

- * addImprinted. - *

- * - * @param c - * a {@link forge.game.card.Card} object. - */ public final void addImprinted(final Card c) { - this.imprintedCards.add(c); + imprintedCards.add(c); } - /** - *

- * addImprinted. - *

- * - * @param list - * a {@link java.util.ArrayList} object. - */ public final void addImprinted(final ArrayList list) { - this.imprintedCards.addAll(list); + imprintedCards.addAll(list); } - /** - * TODO: Write javadoc for this method. - */ public final void removeImprinted(final Object o) { - this.imprintedCards.remove(o); + imprintedCards.remove(o); } - /** - *

- * getImprinted. - *

- * - * @return a {@link java.util.ArrayList} object. - */ public final ArrayList getImprinted() { - return this.imprintedCards; + return imprintedCards; } - /** - *

- * clearImprinted. - *

- */ public final void clearImprinted() { - this.imprintedCards.clear(); + imprintedCards.clear(); } - /** - *

- * addEncoded. - *

- * - * @param c - * a {@link forge.game.card.Card} object. - */ public final void addEncoded(final Card c) { - this.encodedCards.add(c); + encodedCards.add(c); } - /** - *

- * addEncoded. - *

- * - * @param list - * a {@link java.util.ArrayList} object. - */ public final void addEncoded(final ArrayList list) { - this.encodedCards.addAll(list); + encodedCards.addAll(list); } - /** - * TODO: Write javadoc for this method. - */ public final void removeEncoded(final Object o) { - this.encodedCards.remove(o); + encodedCards.remove(o); } - /** - *

- * getEncoded. - *

- * - * @return a {@link java.util.ArrayList} object. - */ public final ArrayList getEncoded() { - return this.encodedCards; + return encodedCards; } - /** - *

- * clearEncoded. - *

- */ public final void clearEncoded() { - this.encodedCards.clear(); + encodedCards.clear(); } /** @@ -715,7 +519,7 @@ public class Card extends GameEntity implements Comparable, IIdentifiable * @param result The result of the coin flip as a String. */ public final void addFlipResult(final Player flipper, final String result) { - this.flipResult.put(flipper, result); + flipResult.put(flipper, result); } /** @@ -727,94 +531,39 @@ public class Card extends GameEntity implements Comparable, IIdentifiable * @return a String result - Heads or Tails. */ public final String getFlipResult(final Player flipper) { - return this.flipResult.get(flipper); + return flipResult.get(flipper); } - /** - *

- * clearFlipResult. - *

- */ public final void clearFlipResult() { - this.flipResult.clear(); + flipResult.clear(); } - /** - *

- * addTrigger. - *

- * - * @param t - * a {@link forge.game.trigger.Trigger} object. - * @return a {@link forge.game.trigger.Trigger} object. - */ public final Trigger addTrigger(final Trigger t) { final Trigger newtrig = t.getCopyForHostCard(this); - this.getCharacteristics().getTriggers().add(newtrig); + getCharacteristics().getTriggers().add(newtrig); return newtrig; } - /** - * - * moveTrigger. - * - * @param t - * a Trigger - */ public final void moveTrigger(final Trigger t) { t.setHostCard(this); - if (!this.getCharacteristics().getTriggers().contains(t)) { - this.getCharacteristics().getTriggers().add(t); + if (!getCharacteristics().getTriggers().contains(t)) { + getCharacteristics().getTriggers().add(t); } } - /** - *

- * removeTrigger. - *

- * - * @param t - * a {@link forge.game.trigger.Trigger} object. - */ public final void removeTrigger(final Trigger t) { - this.getCharacteristics().getTriggers().remove(t); + getCharacteristics().getTriggers().remove(t); } - /** - *

- * removeTrigger. - *

- * - * @param t - * a {@link forge.game.trigger.Trigger} object. - * - * @param state - * a {@link forge.card.CardCharacteristicName} object. - */ public final void removeTrigger(final Trigger t, final CardCharacteristicName state) { - CardCharacteristics stateCharacteristics = this.getState(state); + CardCharacteristics stateCharacteristics = getState(state); stateCharacteristics.getTriggers().remove(t); } - /** - *

- * Getter for the field triggers. - *

- * - * @return a {@link java.util.ArrayList} object. - */ public final List getTriggers() { - return this.getCharacteristics().getTriggers(); + return getCharacteristics().getTriggers(); } - /** - *

- * Setter for the field triggers. - *

- * - * @param trigs - * a {@link java.util.ArrayList} object. - */ public final void setTriggers(final List trigs, boolean intrinsicOnly) { final List copyList = new CopyOnWriteArrayList(); for (final Trigger t : trigs) { @@ -823,31 +572,17 @@ public class Card extends GameEntity implements Comparable, IIdentifiable } } - this.getCharacteristics().setTriggers(copyList); + getCharacteristics().setTriggers(copyList); } - /** - *

- * clearTriggersNew. - *

- */ public final void clearTriggersNew() { - this.getCharacteristics().getTriggers().clear(); + getCharacteristics().getTriggers().clear(); } - /** - *

- * getTriggeringObject. - *

- * - * @param typeIn - * a {@link java.lang.String} object. - * @return a {@link java.lang.Object} object. - */ public final Object getTriggeringObject(final String typeIn) { Object triggered = null; - if (!this.getCharacteristics().getTriggers().isEmpty()) { - for (final Trigger t : this.getCharacteristics().getTriggers()) { + if (!getCharacteristics().getTriggers().isEmpty()) { + for (final Trigger t : getCharacteristics().getTriggers()) { final SpellAbility sa = t.getTriggeredSA(); triggered = sa.getTriggeringObject(typeIn); if (triggered != null) { @@ -858,87 +593,35 @@ public class Card extends GameEntity implements Comparable, IIdentifiable return triggered; } - /** - *

- * Getter for the field sunburstValue. - *

- * - * @return a int. - */ public final int getSunburstValue() { - return this.sunburstValue; + return sunburstValue; } // TODO: Append colors instead of replacing public final void setColorsPaid(final byte s) { - this.colorsPaid = s; + colorsPaid = s; } - /** - *

- * Getter for the field colorsPaid. - *

- * - * @return a String. - */ public final byte getColorsPaid() { - return this.colorsPaid; + return colorsPaid; } - /** - *

- * Setter for the field sunburstValue. - *

- * - * @param valueIn - * a int. - */ public final void setSunburstValue(final int valueIn) { - this.sunburstValue = valueIn; + sunburstValue = valueIn; } - /** - *

- * Setter or the field xManaCostPaid. - *

- * - * @param n - * a int. - */ public final void setXManaCostPaid(final int n) { - this.xManaCostPaid = n; + xManaCostPaid = n; } - /** - *

- * Getter for the field xManaCostPaidByColor. - *

- * - * @return an Map. - */ public final Map getXManaCostPaidByColor() { - return this.xManaCostPaidByColor; + return xManaCostPaidByColor; } - /** - *

- * setXManaCostPaidByColor. - *

- * - * @param xByColor - * an ArrayList. - */ public final void setXManaCostPaidByColor(final Map xByColor) { - this.xManaCostPaidByColor = xByColor; + xManaCostPaidByColor = xByColor; } - /** - *

- * Returns the amount of specific color mana spent on paying X. - *

- * - * @return a int. - */ public final int getXManaCostPaidCount(final String colors) { int count = 0; if (xManaCostPaidByColor != null) { @@ -951,67 +634,38 @@ public class Card extends GameEntity implements Comparable, IIdentifiable return count; } - /** - *

- * Getter for the field xManaCostPaid. - *

- * - * @return a int. - */ public final int getXManaCostPaid() { - return this.xManaCostPaid; + return xManaCostPaid; } - /** - * @return the blockedThisTurn - */ public List getBlockedThisTurn() { return blockedThisTurn; } - /** - * @param attacker the blockedThisTurn to set - */ public void addBlockedThisTurn(Card attacker) { - if (this.blockedThisTurn == null) { - this.blockedThisTurn = new ArrayList(); + if (blockedThisTurn == null) { + blockedThisTurn = new ArrayList(); } - this.blockedThisTurn.add(attacker); + blockedThisTurn.add(attacker); } - /** - *

- * clearBlockedThisTurn. - *

- */ public void clearBlockedThisTurn() { - this.blockedThisTurn = null; + blockedThisTurn = null; } - /** - * @return the blockedByThisTurn - */ public List getBlockedByThisTurn() { return blockedByThisTurn; } - /** - * @param blocker the blockedByThisTurn to set - */ public void addBlockedByThisTurn(Card blocker) { - if (this.blockedByThisTurn == null) { - this.blockedByThisTurn = new ArrayList(); + if (blockedByThisTurn == null) { + blockedByThisTurn = new ArrayList(); } - this.blockedByThisTurn.add(blocker); + blockedByThisTurn.add(blocker); } - /** - *

- * clearBlockedByThisTurn. - *

- */ public void clearBlockedByThisTurn() { - this.blockedByThisTurn = null; + blockedByThisTurn = null; } /** @@ -1027,14 +681,14 @@ public class Card extends GameEntity implements Comparable, IIdentifiable if (mustBlockCards == null) { mustBlockCards = new ArrayList(); } - this.mustBlockCards.add(c); + mustBlockCards.add(c); } public final void addMustBlockCards(final List attackersToBlock) { if (mustBlockCards == null) { mustBlockCards = new ArrayList(); } - this.mustBlockCards.addAll(attackersToBlock); + mustBlockCards.addAll(attackersToBlock); } /** @@ -1045,7 +699,7 @@ public class Card extends GameEntity implements Comparable, IIdentifiable * @since 1.1.6 */ public final ArrayList getMustBlockCards() { - return this.mustBlockCards; + return mustBlockCards; } /** @@ -1054,129 +708,58 @@ public class Card extends GameEntity implements Comparable, IIdentifiable * @since 1.1.6 */ public final void clearMustBlockCards() { - this.mustBlockCards = null; + mustBlockCards = null; } - /** - *

- * Getter for the field clones. - *

- * - * @return a {@link java.util.ArrayList} object. - */ public final List getClones() { - return this.clones; + return clones; } - /** - *

- * Setter for the field clones. - *

- * - * @param c - * a {@link java.util.ArrayList} object. - */ public final void setClones(final Collection c) { - this.clones.clear(); - this.clones.addAll(c); + clones.clear(); + clones.addAll(c); } - /** - *

- * addClone. - *

- * - * @param c - * a {@link forge.game.card.Card} object. - */ public final void addClone(final Card c) { - this.clones.add(c); + clones.add(c); } - /** - *

- * clearClones. - *

- */ public final void clearClones() { - this.clones.clear(); + clones.clear(); } - /** - *

- * Getter for the field cloneOrigin. - *

- * - * @return a {@link forge.game.card.Card} object. - */ public final Card getCloneOrigin() { - return this.cloneOrigin; + return cloneOrigin; } - /** - *

- * Setter for the field cloneOrigin. - *

- * - * @param name - * a {@link forge.game.card.Card} object. - */ public final void setCloneOrigin(final Card name) { - this.cloneOrigin = name; + cloneOrigin = name; } - /** - *

- * hasFirstStrike. - *

- * - * @return a boolean. - */ public final boolean hasFirstStrike() { - return this.hasKeyword("First Strike"); + return hasKeyword("First Strike"); } - /** - *

- * hasDoubleStrike. - *

- * - * @return a boolean. - */ public final boolean hasDoubleStrike() { - return this.hasKeyword("Double Strike"); + return hasKeyword("Double Strike"); } - /** - *

- * hasSecondStrike. - *

- * - * @return a boolean. - */ public final boolean hasSecondStrike() { - return this.hasDoubleStrike() || !this.hasFirstStrike(); + return hasDoubleStrike() || !hasFirstStrike(); } - /** - * Can have counters placed on it. - * - * @param type - * the counter name - * @return true, if successful - */ public final boolean canReceiveCounters(final CounterType type) { - if (this.hasKeyword("CARDNAME can't have counters placed on it.")) { + if (hasKeyword("CARDNAME can't have counters placed on it.")) { return false; } - if (this.isCreature() && type == CounterType.M1M1) { - for (final Card c : this.getController().getCreaturesInPlay()) { // look for Melira, Sylvok Outcast + if (isCreature() && type == CounterType.M1M1) { + for (final Card c : getController().getCreaturesInPlay()) { // look for Melira, Sylvok Outcast if (c.hasKeyword("Creatures you control can't have -1/-1 counters placed on them.")) { return false; } } } else if (type == CounterType.DREAM) { - if (this.hasKeyword("CARDNAME can't have more than seven dream counters on it.") && this.getCounters(CounterType.DREAM) > 6) { + if (hasKeyword("CARDNAME can't have more than seven dream counters on it.") && getCounters(CounterType.DREAM) > 6) { return false; } } @@ -1192,10 +775,10 @@ public class Card extends GameEntity implements Comparable, IIdentifiable } public final void addCounter(final CounterType counterType, final int n, final boolean applyMultiplier) { - this.addCounter(counterType, n, applyMultiplier, true); + addCounter(counterType, n, applyMultiplier, true); } public final void addCounterFireNoEvents(final CounterType counterType, final int n, final boolean applyMultiplier) { - this.addCounter(counterType, n, applyMultiplier, false); + addCounter(counterType, n, applyMultiplier, false); } private void addCounter(final CounterType counterType, final int n, final boolean applyMultiplier, final boolean fireEvents) { @@ -1206,12 +789,12 @@ public class Card extends GameEntity implements Comparable, IIdentifiable repParams.put("CounterType", counterType); repParams.put("CounterNum", addAmount); repParams.put("EffectOnly", applyMultiplier); - if (this.getGame().getReplacementHandler().run(repParams) != ReplacementResult.NotReplaced) { + if (getGame().getReplacementHandler().run(repParams) != ReplacementResult.NotReplaced) { return; } - if (this.canReceiveCounters(counterType)) { - if (counterType == CounterType.DREAM && this.hasKeyword("CARDNAME can't have more than seven dream counters on it.")) { - addAmount = Math.min(7 - this.getCounters(CounterType.DREAM), addAmount); + if (canReceiveCounters(counterType)) { + if (counterType == CounterType.DREAM && hasKeyword("CARDNAME can't have more than seven dream counters on it.")) { + addAmount = Math.min(7 - getCounters(CounterType.DREAM), addAmount); } } else { @@ -1221,17 +804,17 @@ public class Card extends GameEntity implements Comparable, IIdentifiable if (addAmount == 0) { return; } - this.setTotalCountersToAdd(addAmount); + setTotalCountersToAdd(addAmount); if (fireEvents) { - final int powerBonusBefore = this.getPowerBonusFromCounters(); - final int toughnessBonusBefore = this.getToughnessBonusFromCounters(); - final int loyaltyBefore = this.getCurrentLoyalty(); + final int powerBonusBefore = getPowerBonusFromCounters(); + final int toughnessBonusBefore = getToughnessBonusFromCounters(); + final int loyaltyBefore = getCurrentLoyalty(); - final Integer oldValue = this.counters.get(counterType); + final Integer oldValue = counters.get(counterType); final int newValue = addAmount + (oldValue == null ? 0 : oldValue.intValue()); - this.counters.put(counterType, Integer.valueOf(newValue)); - + counters.put(counterType, Integer.valueOf(newValue)); + view.updateCounters(this); //fire card stats changed event if p/t bonuses or loyalty changed from added counters if (powerBonusBefore != getPowerBonusFromCounters() || toughnessBonusBefore != getToughnessBonusFromCounters() || loyaltyBefore != getCurrentLoyalty()) { @@ -1255,46 +838,36 @@ public class Card extends GameEntity implements Comparable, IIdentifiable *

* addCountersAddedBy. *

- * @param source the card adding the counters to this card - * @param counterType the counter type added - * @param counterAmount the amount of counters added + * @param source - the card adding the counters to this card + * @param counterType - the counter type added + * @param counterAmount - the amount of counters added */ public final void addCountersAddedBy(final Card source, final CounterType counterType, final int counterAmount) { final Map counterMap = new TreeMap(); counterMap.put(counterType, counterAmount); - this.countersAddedBy.put(source, counterMap); + countersAddedBy.put(source, counterMap); } /** *

* getCountersAddedBy. *

- * @param source the card the counters were added by - * @param counterType the counter type added + * @param source - the card the counters were added by + * @param counterType - the counter type added * @return the amount of counters added. */ public final int getCountersAddedBy(final Card source, final CounterType counterType) { int counterAmount = 0; - if (this.countersAddedBy.containsKey(source)) { - final Map counterMap = this.countersAddedBy.get(source); + if (countersAddedBy.containsKey(source)) { + final Map counterMap = countersAddedBy.get(source); counterAmount = counterMap.containsKey(counterType) ? counterMap.get(counterType) : 0; - this.countersAddedBy.remove(source); + countersAddedBy.remove(source); } return counterAmount; } - /** - *

- * subtractCounter. - *

- * - * @param counterName - * a {@link forge.game.card.CounterType} object. - * @param n - * a int. - */ public final void subtractCounter(final CounterType counterName, final int n) { - Integer oldValue = this.counters.get(counterName); + Integer oldValue = counters.get(counterName); int newValue = oldValue == null ? 0 : Math.max(oldValue.intValue() - n, 0); final int delta = (oldValue == null ? 0 : oldValue.intValue()) - newValue; @@ -1302,16 +875,17 @@ public class Card extends GameEntity implements Comparable, IIdentifiable return; } - int powerBonusBefore = this.getPowerBonusFromCounters(); - int toughnessBonusBefore = this.getToughnessBonusFromCounters(); - int loyaltyBefore = this.getCurrentLoyalty(); + int powerBonusBefore = getPowerBonusFromCounters(); + int toughnessBonusBefore = getToughnessBonusFromCounters(); + int loyaltyBefore = getCurrentLoyalty(); if (newValue > 0) { - this.counters.put(counterName, Integer.valueOf(newValue)); + counters.put(counterName, Integer.valueOf(newValue)); } else { - this.counters.remove(counterName); + counters.remove(counterName); } + view.updateCounters(this); //fire card stats changed event if p/t bonuses or loyalty changed from subtracted counters if (powerBonusBefore != getPowerBonusFromCounters() || toughnessBonusBefore != getToughnessBonusFromCounters() || loyaltyBefore != getCurrentLoyalty()) { @@ -1332,481 +906,192 @@ public class Card extends GameEntity implements Comparable, IIdentifiable } } - /** - *

- * Getter for the field counters. - *

- * - * @param counterName - * a {@link forge.game.card.CounterType} object. - * @return a int. - */ public final int getCounters(final CounterType counterName) { - Integer value = this.counters.get(counterName); + Integer value = counters.get(counterName); return value == null ? 0 : value.intValue(); } // get all counters from a card - /** - *

- * Getter for the field counters. - *

- * - * @return a Map object. - * @since 1.0.15 - */ public final Map getCounters() { - return this.counters; + return counters; } - /** - *

- * hasCounters. - *

- * - * @return a boolean. - */ public final boolean hasCounters() { - return !this.counters.isEmpty(); + return !counters.isEmpty(); } - /** - *

- * Setter for the field counters. - *

- * - * @param allCounters - * a Map object. - * @since 1.0.15 - */ public final void setCounters(final Map allCounters) { - this.counters = allCounters; + counters = allCounters; + view.updateCounters(this); } - /** - *

- * clearCounters. - *

- * - * @since 1.0.15 - */ public final void clearCounters() { - this.counters.clear(); + if (counters.isEmpty()) { return; } + counters.clear(); + view.updateCounters(this); } - /** - *

- * getSVar. - *

- * - * @param var - * a {@link java.lang.String} object. - * @return a {@link java.lang.String} object. - */ public final String getSVar(final String var) { - return this.getCharacteristics().getSVar(var); + return getCharacteristics().getSVar(var); } - /** - *

- * hasSVar. - *

- * - * @param var - * a {@link java.lang.String} object. - */ public final boolean hasSVar(final String var) { - return this.getCharacteristics().hasSVar(var); + return getCharacteristics().hasSVar(var); } - /** - *

- * setSVar. - *

- * - * @param var - * a {@link java.lang.String} object. - * @param str - * a {@link java.lang.String} object. - */ public final void setSVar(final String var, final String str) { - this.getCharacteristics().setSVar(var, str); + getCharacteristics().setSVar(var, str); } - /** - *

- * getSVars. - *

- * - * @return a Map object. - */ public final Map getSVars() { - return this.getCharacteristics().getSVars(); + return getCharacteristics().getSVars(); } - /** - *

- * setSVars. - *

- * - * @param newSVars - * a Map object. - */ public final void setSVars(final Map newSVars) { - this.getCharacteristics().setSVars(newSVars); + getCharacteristics().setSVars(newSVars); } - /** - *

- * sumAllCounters. - *

- * - * @return a int. - */ public final int sumAllCounters() { int count = 0; - for (final Integer value2 : this.counters.values()) { + for (final Integer value2 : counters.values()) { count += value2.intValue(); } return count; } - - /** - *

- * Getter for the field turnInZone. - *

- * - * @return a int. - */ public final int getTurnInZone() { - return this.turnInZone; + return turnInZone; } - /** - *

- * Setter for the field turnInZone. - *

- * - * @param turn - * a int. - */ public final void setTurnInZone(final int turn) { - this.turnInZone = turn; + turnInZone = turn; } - /** - *

- * Setter for the field echoCost. - *

- * - * @param s - * a {@link java.lang.String} object. - */ public final void setEchoCost(final String s) { - this.echoCost = s; + echoCost = s; } public final String getEchoCost() { - return this.echoCost; + return echoCost; } - /** - *

- * Setter for the field manaCost. - *

- * - * @param s - * a {@link java.lang.String} object. - */ public final void setManaCost(final ManaCost s) { - this.getCharacteristics().setManaCost(s); + getCharacteristics().setManaCost(s); } - /** - *

- * Getter for the field manaCost. - *

- * - * @return a {@link java.lang.String} object. - */ public final ManaCost getManaCost() { - return this.getCharacteristics().getManaCost(); + return getCharacteristics().getManaCost(); } - - /** - *

- * addColor. - *

- * - * @param s - * a {@link java.lang.String} object. - */ public final void addColor(String s) { if (s.equals("")) { s = "0"; } ManaCost mc = new ManaCost(new ManaCostParser(s)); - this.getCharacteristics().getCardColor().add(new CardColor(mc.getColorProfile())); + getCharacteristics().getCardColor().add(new CardColor(mc.getColorProfile())); } - /** - *

- * addColor. - *

- * - * @param s - * a {@link java.lang.String} object. - * @param c - * a {@link forge.game.card.Card} object. - * @param addToColors - * a boolean. - * @param bIncrease - * a boolean. - * @return a long. - */ public final long addColor(final String s, final boolean addToColors, final boolean bIncrease) { if (bIncrease) { CardColor.increaseTimestamp(); } - this.getCharacteristics().getCardColor().add(new CardColor(s, addToColors)); + getCharacteristics().getCardColor().add(new CardColor(s, addToColors)); return CardColor.getTimestamp(); } - /** - *

- * removeColor. - *

- * - * @param s - * a {@link java.lang.String} object. - * @param c - * a {@link forge.game.card.Card} object. - * @param addTo - * a boolean. - * @param timestampIn - * a long. - */ public final void removeColor(final String s, final Card c, final boolean addTo, final long timestampIn) { CardColor removeCol = null; - for (final CardColor cc : this.getCharacteristics().getCardColor()) { + for (final CardColor cc : getCharacteristics().getCardColor()) { if (cc.equals(s, c, addTo, timestampIn)) { removeCol = cc; } } if (removeCol != null) { - this.getCharacteristics().getCardColor().remove(removeCol); + getCharacteristics().getCardColor().remove(removeCol); } } - /** - *

- * setColor. - *

- * - * @param colors - * a {@link java.util.ArrayList} object. - */ public final void setColor(final Iterable colors) { - this.getCharacteristics().setCardColor(colors); + getCharacteristics().setCardColor(colors); } - /** - *

- * getColor. - *

- * - * @return a {@link java.util.ArrayList} object. - */ public final List getColor() { - return this.getCharacteristics().getCardColor(); + return getCharacteristics().getCardColor(); } - /** - * @return a {@link ColorSet}. - * @see CardCharacteristics#determineColor() - */ public final ColorSet determineColor() { - if (this.isImmutable()) { + if (isImmutable()) { return ColorSet.getNullColor(); } - return this.getCharacteristics().determineColor(); + return getCharacteristics().determineColor(); } - /** - *

- * Getter for the field chosenPlayer. - *

- * - * @return a Player - * @since 1.1.6 - */ public final Player getChosenPlayer() { - return this.chosenPlayer; + return chosenPlayer; } - /** - *

- * Setter for the field chosenNumber. - *

- * - * @param p - * an int - * @since 1.1.6 - */ public final void setChosenPlayer(final Player p) { - this.chosenPlayer = p; + chosenPlayer = p; } - /** - *

- * Getter for the field chosenNumber. - *

- * - * @return an int - */ public final int getChosenNumber() { - return this.chosenNumber; + return chosenNumber; } - /** - *

- * Setter for the field chosenNumber. - *

- * - * @param i - * an int - */ public final void setChosenNumber(final int i) { - this.chosenNumber = i; + chosenNumber = i; } // used for cards like Belbe's Portal, Conspiracy, Cover of Darkness, etc. - /** - *

- * Getter for the field chosenType. - *

- * - * @return a {@link java.lang.String} object. - */ public final String getChosenType() { - return this.chosenType; + return chosenType; } - /** - *

- * Setter for the field chosenType. - *

- * - * @param s - * a {@link java.lang.String} object. - */ public final void setChosenType(final String s) { - this.chosenType = s; + chosenType = s; } - /** - *

- * Getter for the field chosenColor. - *

- * - * @return an ArrayList object. - */ - public final List getChosenColor() { - return this.chosenColor; + public final List getChosenColors() { + return chosenColors; } - /** - *

- * Setter for the field chosenColor. - *

- * - * @param s - * an ArrayList object. - */ - public final void setChosenColor(final List s) { - this.chosenColor = s; + public final void setChosenColors(final List s) { + chosenColors = s; } - /** - *

- * Getter for the field chosenCard. - *

- * - * @return an ArrayList object. - */ public final List getChosenCard() { - return this.chosenCard; + return chosenCard; } - /** - *

- * Setter for the field chosenCard. - *

- * - * @param c - * an ArrayList object. - */ public final void setChosenCard(final List c) { - this.chosenCard = c; + chosenCard = c; } public Direction getChosenDirection() { return chosenDirection; } - public void setChosenDirection(Direction chosenDirection) { - this.chosenDirection = chosenDirection; + public void setChosenDirection(Direction chosenDirection0) { + chosenDirection = chosenDirection0; } // used for cards like Meddling Mage... - /** - *

- * Getter for the field namedCard. - *

- * - * @return a {@link java.lang.String} object. - */ public final String getNamedCard() { - return this.namedCard; + return namedCard; } - /** - *

- * Setter for the field namedCard. - *

- * - * @param s - * a {@link java.lang.String} object. - */ public final void setNamedCard(final String s) { - this.namedCard = s; + namedCard = s; } - /** - *

- * Setter for the field drawnThisTurn. - *

- * - * @param b - * a boolean. - */ public final void setDrawnThisTurn(final boolean b) { - this.drawnThisTurn = b; + drawnThisTurn = b; } - /** - *

- * Getter for the field drawnThisTurn. - *

- * - * @return a boolean. - */ public final boolean getDrawnThisTurn() { - return this.drawnThisTurn; + return drawnThisTurn; } /** @@ -1817,7 +1102,7 @@ public class Card extends GameEntity implements Comparable, IIdentifiable * @return a list of cards this card has gained control of */ public final List getGainControlTargets() { - return this.gainControlTargets; + return gainControlTargets; } /** @@ -1829,7 +1114,7 @@ public class Card extends GameEntity implements Comparable, IIdentifiable * a {@link forge.game.card.Card} object. */ public final void addGainControlTarget(final Card c) { - this.gainControlTargets.add(c); + gainControlTargets.add(c); } /** @@ -1838,61 +1123,39 @@ public class Card extends GameEntity implements Comparable, IIdentifiable * used primarily with AbilityFactory_GainControl */ public final void removeGainControlTargets(final Card c) { - this.gainControlTargets.remove(c); + gainControlTargets.remove(c); } - /** - *

- * getSpellText. - *

- * - * @return a {@link java.lang.String} object. - */ public final String getSpellText() { - return this.text; + return text; } - /** - *

- * Setter for the field text. - *

- * - * @param t - * a {@link java.lang.String} object. - */ public final void setText(final String t) { - this.originalText = t; - this.text = this.originalText; + originalText = t; + text = originalText; } // get the text that should be displayed - /** - *

- * Getter for the field text. - *

- * - * @return a {@link java.lang.String} object. - */ public String getText() { final StringBuilder sb = new StringBuilder(); // Vanguard Modifiers - if (this.isType("Vanguard")) { + if (isType("Vanguard")) { sb.append("Hand Modifier: ").append(getRules().getHand()); sb.append("\r\nLife Modifier: ").append(getRules().getLife()); sb.append("\r\n\r\n"); } - if (this.isCommander) { + if (isCommander) { sb.append(getOwner()).append("'s Commander\r\n"); sb.append(CardFactoryUtil.getCommanderInfo(getOwner())).append("\r\n"); } - sb.append(this.getAbilityText()); + sb.append(getAbilityText()); - String nonAbilityText = this.getNonAbilityText(); - if (this.getAmountOfKeyword("CARDNAME can block an additional creature.") > 1) { + String nonAbilityText = getNonAbilityText(); + if (getAmountOfKeyword("CARDNAME can block an additional creature.") > 1) { final StringBuilder ab = new StringBuilder(); ab.append("CARDNAME can block an additional "); - ab.append(this.getAmountOfKeyword("CARDNAME can block an additional creature.")); + ab.append(getAmountOfKeyword("CARDNAME can block an additional creature.")); ab.append(" creatures."); nonAbilityText = nonAbilityText.replaceFirst("CARDNAME can block an additional creature.", ab.toString()); nonAbilityText = nonAbilityText.replaceAll("CARDNAME can block an additional creature.", ""); @@ -1900,13 +1163,13 @@ public class Card extends GameEntity implements Comparable, IIdentifiable } if (nonAbilityText.length() > 0) { sb.append("\r\n \r\nNon ability features: \r\n"); - sb.append(nonAbilityText.replaceAll("CARDNAME", this.getName())); + sb.append(nonAbilityText.replaceAll("CARDNAME", getName())); } // Remembered cards - if (this.rememberedObjects.size() > 0) { + if (rememberedObjects.size() > 0) { sb.append("\r\nRemembered: \r\n"); - for (final Object o : this.rememberedObjects) { + for (final Object o : rememberedObjects) { if (o instanceof Card) { final Card c = (Card) o; if (c.isFaceDown()) { @@ -1915,7 +1178,7 @@ public class Card extends GameEntity implements Comparable, IIdentifiable } else { sb.append(c.getName()); sb.append(" ("); - sb.append(c.getUniqueNumber()); + sb.append(c.id); sb.append(")"); } } else if (o != null) { @@ -1925,40 +1188,40 @@ public class Card extends GameEntity implements Comparable, IIdentifiable } } - if (this.chosenPlayer != null) { + if (chosenPlayer != null) { sb.append("\r\n[Chosen player: "); - sb.append(this.getChosenPlayer()); + sb.append(getChosenPlayer()); sb.append("]\r\n"); } - if (this.chosenDirection != null) { + if (chosenDirection != null) { sb.append("\r\n[Chosen direction: "); - sb.append(this.getChosenDirection()); + sb.append(getChosenDirection()); sb.append("]\r\n"); } - if (this.hauntedBy.size() != 0) { + if (hauntedBy.size() != 0) { sb.append("Haunted by: "); - for (final Card c : this.hauntedBy) { + for (final Card c : hauntedBy) { sb.append(c).append(","); } sb.deleteCharAt(sb.length() - 1); sb.append("\r\n"); } - if (this.haunting != null) { - sb.append("Haunting: ").append(this.haunting); + if (haunting != null) { + sb.append("Haunting: ").append(haunting); sb.append("\r\n"); } - if (this.pairedWith != null) { - sb.append("\r\n \r\nPaired With: ").append(this.pairedWith); + if (pairedWith != null) { + sb.append("\r\n \r\nPaired With: ").append(pairedWith); sb.append("\r\n"); } - if (this.characteristicsMap.get(CardCharacteristicName.Cloner) != null) { - sb.append("\r\nCloned by: ").append(this.characteristicsMap.get(CardCharacteristicName.Cloner).getName()).append(" (") - .append(this.getUniqueNumber()).append(")"); + if (characteristicsMap.get(CardCharacteristicName.Cloner) != null) { + sb.append("\r\nCloned by: ").append(characteristicsMap.get(CardCharacteristicName.Cloner).getName()).append(" (") + .append(id).append(")"); } return sb.toString(); @@ -1975,9 +1238,9 @@ public class Card extends GameEntity implements Comparable, IIdentifiable */ public final String getNonAbilityText() { final StringBuilder sb = new StringBuilder(); - final ArrayList keyword = this.getHiddenExtrinsicKeyword(); + final ArrayList keyword = getHiddenExtrinsicKeyword(); - sb.append(this.keywordsToText(keyword)); + sb.append(keywordsToText(keyword)); return sb.toString(); } @@ -1997,8 +1260,8 @@ public class Card extends GameEntity implements Comparable, IIdentifiable final StringBuilder sbLong = new StringBuilder(); // Prepare text changes - final Map changedColorWords = this.getChangedTextColorWords(), - changedTypes = this.getChangedTextTypeWords(); + final Map changedColorWords = getChangedTextColorWords(), + changedTypes = getChangedTextTypeWords(); final Set> textChanges = Sets.union( changedColorWords.entrySet(), changedTypes.entrySet()); @@ -2011,7 +1274,7 @@ public class Card extends GameEntity implements Comparable, IIdentifiable } // format text changes if (CardUtil.isKeywordModifiable(keyword) - && this.keywordsGrantedByTextChanges.contains(keyword)) { + && keywordsGrantedByTextChanges.contains(keyword)) { for (final Entry e : textChanges) { final String value = e.getValue(); if (keyword.contains(value)) { @@ -2030,7 +1293,7 @@ public class Card extends GameEntity implements Comparable, IIdentifiable } else { final CounterType counter = CounterType.valueOf(p[1]); final String numCounters = p[2]; - s.append(this.getName()); + s.append(getName()); s.append(" enters the battlefield with "); s.append(numCounters); s.append(" "); @@ -2103,7 +1366,7 @@ public class Card extends GameEntity implements Comparable, IIdentifiable final String costString2 = keyword.split(":")[2]; final Cost cost1 = new Cost(costString1, false); final Cost cost2 = new Cost(costString2, false); - sbLong.append("As an additional cost to cast " + this.getName() + ", " + cost1.toSimpleString() + sbLong.append("As an additional cost to cast " + getName() + ", " + cost1.toSimpleString() + " or pay " + cost2.toSimpleString() + ".\r\n"); } else if (keyword.startsWith("Kicker")) { final Cost cost = new Cost(keyword.substring(7), false); @@ -2122,7 +1385,7 @@ public class Card extends GameEntity implements Comparable, IIdentifiable sbLong.append("defending player controls untap and block it if able.)"); } else if (keyword.contains("Haunt")) { sb.append("\r\nHaunt ("); - if (this.isCreature()) { + if (isCreature()) { sb.append("When this creature dies, exile it haunting target creature."); } else { sb.append("When this spell card is put into a graveyard after resolving, "); @@ -2156,13 +1419,13 @@ public class Card extends GameEntity implements Comparable, IIdentifiable // keyword parsing takes care of adding a proper description continue; } else if (keyword.startsWith("CantBeBlockedBy")) { - sbLong.append(this.getName()).append(" can't be blocked "); + sbLong.append(getName()).append(" can't be blocked "); if (keyword.startsWith("CantBeBlockedByAmount")) sbLong.append(getTextForKwCantBeBlockedByAmount(keyword)); else sbLong.append(getTextForKwCantBeBlockedByType(keyword)); } else if (keyword.startsWith("CantBlock")) { - sbLong.append(this.getName()).append(" can't block "); + sbLong.append(getName()).append(" can't block "); if (keyword.contains("CardUID")) { sbLong.append("CardID (").append(Integer.valueOf(keyword.split("CantBlockCardUID_")[1])).append(")"); } else { @@ -2170,7 +1433,7 @@ public class Card extends GameEntity implements Comparable, IIdentifiable sbLong.append(k.length > 1 ? k[1] + ".\r\n" : ""); } } else if (keyword.equals("Unblockable")) { - sbLong.append(this.getName()).append(" can't be blocked.\r\n"); + sbLong.append(getName()).append(" can't be blocked.\r\n"); } else { if ((i != 0) && (sb.length() != 0)) { @@ -2304,19 +1567,12 @@ public class Card extends GameEntity implements Comparable, IIdentifiable } // get the text of the abilities of a card - /** - *

- * getAbilityText. - *

- * - * @return a {@link java.lang.String} object. - */ public String getAbilityText() { - if (this.isInstant() || this.isSorcery()) { - final StringBuilder sb = this.abilityTextInstantSorcery(); + if (isInstant() || isSorcery()) { + final StringBuilder sb = abilityTextInstantSorcery(); - if (this.haunting != null) { - sb.append("Haunting: ").append(this.haunting); + if (haunting != null) { + sb.append("Haunting: ").append(haunting); sb.append("\r\n"); } @@ -2324,50 +1580,50 @@ public class Card extends GameEntity implements Comparable, IIdentifiable sb.delete(sb.lastIndexOf("\r\n"), sb.lastIndexOf("\r\n") + 3); } - return sb.toString().replaceAll("CARDNAME", this.getName()); + return sb.toString().replaceAll("CARDNAME", getName()); } final StringBuilder sb = new StringBuilder(); - final ArrayList keyword = this.getUnhiddenKeyword(); + final ArrayList keyword = getUnhiddenKeyword(); - if (this.monstrous) { + if (monstrous) { sb.append("Monstrous\r\n"); } - sb.append(this.keywordsToText(keyword)); + sb.append(keywordsToText(keyword)); // Give spellText line breaks for easier reading sb.append("\r\n"); - sb.append(this.text.replaceAll("\\\\r\\\\n", "\r\n")); + sb.append(text.replaceAll("\\\\r\\\\n", "\r\n")); sb.append("\r\n"); // Triggered abilities - for (final Trigger trig : this.getCharacteristics().getTriggers()) { + for (final Trigger trig : getCharacteristics().getTriggers()) { if (!trig.isSecondary()) { sb.append(trig.toString() + "\r\n"); } } // Replacement effects - for (final ReplacementEffect replacementEffect : this.getCharacteristics().getReplacementEffects()) { + for (final ReplacementEffect replacementEffect : getCharacteristics().getReplacementEffects()) { if (!replacementEffect.isSecondary()) { sb.append(replacementEffect.toString() + "\r\n"); } } // static abilities - for (final StaticAbility stAb : this.getCharacteristics().getStaticAbilities()) { + for (final StaticAbility stAb : getCharacteristics().getStaticAbilities()) { sb.append(stAb.toString() + "\r\n"); } final ArrayList addedManaStrings = new ArrayList(); boolean primaryCost = true; - for (final SpellAbility sa : this.getSpellAbilities()) { + for (final SpellAbility sa : getSpellAbilities()) { // only add abilities not Spell portions of cards - if (sa == null || !this.isPermanent()) { + if (sa == null || !isPermanent()) { continue; } - if ((sa instanceof SpellPermanent) && primaryCost && !this.isAura()) { + if ((sa instanceof SpellPermanent) && primaryCost && !isAura()) { // For Alt costs, make sure to display the cost! primaryCost = false; continue; @@ -2382,10 +1638,10 @@ public class Card extends GameEntity implements Comparable, IIdentifiable addedManaStrings.add(sAbility); } - if ((sa instanceof SpellPermanent) && !this.isAura()) { + if ((sa instanceof SpellPermanent) && !isAura()) { sb.insert(0, "\r\n"); sb.insert(0, sAbility); - } else if (!sAbility.endsWith(this.getName())) { + } else if (!sAbility.endsWith(getName())) { sb.append(sAbility); sb.append("\r\n"); } @@ -2410,16 +1666,11 @@ public class Card extends GameEntity implements Comparable, IIdentifiable sb.replace(start, start + 4, "\r\n"); } - return sb.toString().replaceAll("CARDNAME", this.getName()).trim(); + return sb.toString().replaceAll("CARDNAME", getName()).trim(); } // getText() - /** - * TODO: Write javadoc for this method. - * - * @return - */ private StringBuilder abilityTextInstantSorcery() { - final String s = this.getSpellText(); + final String s = getSpellText(); final StringBuilder sb = new StringBuilder(); @@ -2436,7 +1687,7 @@ public class Card extends GameEntity implements Comparable, IIdentifiable // I think SpellAbilities should be displayed after Keywords // Add SpellAbilities - for (final SpellAbility element : this.getSpellAbilities()) { + for (final SpellAbility element : getSpellAbilities()) { String elementText = element.toString(); //Determine if a card has multiple choices, then format it in an easier to read list. @@ -2473,22 +1724,22 @@ public class Card extends GameEntity implements Comparable, IIdentifiable } // Add Keywords - final List kw = this.getKeyword(); + final List kw = getKeyword(); // Triggered abilities - for (final Trigger trig : this.getCharacteristics().getTriggers()) { + for (final Trigger trig : getCharacteristics().getTriggers()) { if (!trig.isSecondary()) { sb.append(trig.toString() + "\r\n"); } } // Replacement effects - for (final ReplacementEffect replacementEffect : this.getCharacteristics().getReplacementEffects()) { + for (final ReplacementEffect replacementEffect : getCharacteristics().getReplacementEffects()) { sb.append(replacementEffect.toString() + "\r\n"); } // static abilities - for (final StaticAbility stAb : this.getCharacteristics().getStaticAbilities()) { + for (final StaticAbility stAb : getCharacteristics().getStaticAbilities()) { final String stAbD = stAb.toString(); if (!stAbD.equals("")) { sb.append(stAbD + "\r\n"); @@ -2554,7 +1805,7 @@ public class Card extends GameEntity implements Comparable, IIdentifiable final String costString2 = keyword.split(":")[2]; final Cost cost1 = new Cost(costString1, false); final Cost cost2 = new Cost(costString2, false); - sb.append("As an additional cost to cast " + this.getName() + ", " + cost1.toSimpleString() + sb.append("As an additional cost to cast " + getName() + ", " + cost1.toSimpleString() + " or pay " + cost2.toSimpleString() + ".\r\n"); } else if (keyword.startsWith("Storm")) { if (sb.toString().contains("Target") || sb.toString().contains("target")) { @@ -2577,7 +1828,7 @@ public class Card extends GameEntity implements Comparable, IIdentifiable sb.delete(sb.lastIndexOf("\r\n"), sb.lastIndexOf("\r\n") + 3); } sb.append("Haunt ("); - if (this.isCreature()) { + if (isCreature()) { sb.append("When this creature dies, exile it haunting target creature."); } else { sb.append("When this spell card is put into a graveyard after resolving, "); @@ -2618,19 +1869,12 @@ public class Card extends GameEntity implements Comparable, IIdentifiable return sb; } - /** - *

- * Getter for the field manaAbility. - *

- * - * @return a {@link java.util.ArrayList} object. - */ public final List getManaAbility() { - return Collections.unmodifiableList(this.getCharacteristics().getManaAbility()); + return Collections.unmodifiableList(getCharacteristics().getManaAbility()); } public final boolean canProduceSameManaTypeWith(final Card c) { - final List manaAb = this.getManaAbility(); + final List manaAb = getManaAbility(); if (manaAb.isEmpty()) { return false; } @@ -2659,29 +1903,17 @@ public class Card extends GameEntity implements Comparable, IIdentifiable return false; } - /** - *

- * clearFirstSpellAbility. - *

- */ public final void clearFirstSpell() { - for (int i = 0; i < this.getCharacteristics().getSpellAbility().size(); i++) { - if (this.getCharacteristics().getSpellAbility().get(i).isSpell()) { - this.getCharacteristics().getSpellAbility().remove(i); + for (int i = 0; i < getCharacteristics().getSpellAbility().size(); i++) { + if (getCharacteristics().getSpellAbility().get(i).isSpell()) { + getCharacteristics().getSpellAbility().remove(i); return; } } } - /** - *

- * getFirstSpellAbility. - *

- * - * @return a SpellAbility object. - */ public final SpellAbility getFirstSpellAbility() { - final List sas = this.getCharacteristics().getSpellAbility(); + final List sas = getCharacteristics().getSpellAbility(); return sas.isEmpty() ? null : sas.get(0); } @@ -2692,7 +1924,7 @@ public class Card extends GameEntity implements Comparable, IIdentifiable * @see SpellAbility#isSpell() */ public final SpellAbility getFirstAttachSpell() { - for (final SpellAbility sa : this.getSpells()) { + for (final SpellAbility sa : getSpells()) { if (sa.isSpell() && sa.getApi() == ApiType.Attach) { return sa; } @@ -2700,15 +1932,8 @@ public class Card extends GameEntity implements Comparable, IIdentifiable return null; } - /** - *

- * getSpellPermanent. - *

- * - * @return a {@link forge.game.spellability.SpellPermanent} object. - */ public final SpellPermanent getSpellPermanent() { - for (final SpellAbility sa : this.getCharacteristics().getSpellAbility()) { + for (final SpellAbility sa : getCharacteristics().getSpellAbility()) { if (sa instanceof SpellPermanent) { return (SpellPermanent) sa; } @@ -2716,92 +1941,49 @@ public class Card extends GameEntity implements Comparable, IIdentifiable return null; } - /** - *

- * addSpellAbility. - *

- * - * @param a - * a {@link forge.game.spellability.SpellAbility} object. - */ public final void addSpellAbility(final SpellAbility a) { a.setHostCard(this); if (a.isManaAbility()) { - this.getCharacteristics().getManaAbility().add(a); + getCharacteristics().getManaAbility().add(a); } else { - this.getCharacteristics().getSpellAbility().add(a); + getCharacteristics().getSpellAbility().add(a); } } - /** - *

- * removeSpellAbility. - *

- * - * @param a - * a {@link forge.game.spellability.SpellAbility} object. - */ public final void removeSpellAbility(final SpellAbility a) { if (a.isManaAbility()) { // if (a.isExtrinsic()) //never remove intrinsic mana abilities, is // this the way to go?? - this.getCharacteristics().getManaAbility().remove(a); + getCharacteristics().getManaAbility().remove(a); } else { - this.getCharacteristics().getSpellAbility().remove(a); + getCharacteristics().getSpellAbility().remove(a); } } - /** - *

- * getSpellAbilities. - *

- * - * @return a {@link java.util.ArrayList} object. - */ public final List getSpellAbilities() { - final ArrayList res = new ArrayList(this.getManaAbility()); - res.addAll(this.getCharacteristics().getSpellAbility()); + final ArrayList res = new ArrayList(getManaAbility()); + res.addAll(getCharacteristics().getSpellAbility()); return res; } - /** - *

- * getNonManaSpellAbilities. - *

- * - * @return a {@link java.util.ArrayList} object. - */ public final List getNonManaSpellAbilities() { - return this.getCharacteristics().getSpellAbility(); + return getCharacteristics().getSpellAbility(); } - /** - * - * getAllSpellAbilities. - * - * @return ArrayList - */ public final ArrayList getAllSpellAbilities() { final ArrayList res = new ArrayList(); - for (final CardCharacteristicName key : this.characteristicsMap.keySet()) { - res.addAll(this.getState(key).getSpellAbility()); - res.addAll(this.getState(key).getManaAbility()); + for (final CardCharacteristicName key : characteristicsMap.keySet()) { + res.addAll(getState(key).getSpellAbility()); + res.addAll(getState(key).getManaAbility()); } return res; } - /** - *

- * getSpells. - *

- * - * @return a {@link java.util.ArrayList} object. - */ public final List getSpells() { final List res = new ArrayList(); - for (final SpellAbility sa : this.getCharacteristics().getSpellAbility()) { + for (final SpellAbility sa : getCharacteristics().getSpellAbility()) { if (!sa.isSpell()) { continue; } @@ -2810,17 +1992,10 @@ public class Card extends GameEntity implements Comparable, IIdentifiable return res; } - /** - *

- * getBasicSpells. - *

- * - * @return a {@link java.util.ArrayList} object. - */ public final List getBasicSpells() { final ArrayList res = new ArrayList(); - for (final SpellAbility sa : this.getCharacteristics().getSpellAbility()) { + for (final SpellAbility sa : getCharacteristics().getSpellAbility()) { if (sa.isSpell() && sa.isBasicSpell()) { res.add(sa); } @@ -2829,648 +2004,290 @@ public class Card extends GameEntity implements Comparable, IIdentifiable } // shield = regeneration - /** - *

- * getShield. - *

- * - * @return a int. - */ - public final List getShield() { - return this.nShield; + public final Iterable getShields() { + return shields; + } + public final int getShieldCount() { + return shields.size(); } - /** - *

- * addShield. - *

- */ public final void addShield(final CardShields shield) { - this.nShield.add(shield); + shields.add(shield); + view.updateShieldCount(this); } - /** - *

- * subtractShield. - *

- */ public final void subtractShield(CardShields shield) { if (shield != null && shield.hasTrigger()) { - this.getGame().getStack().addSimultaneousStackEntry(shield.getTriggerSA()); + getGame().getStack().addSimultaneousStackEntry(shield.getTriggerSA()); + } + if (shields.remove(shield)) { + view.updateShieldCount(this); } - this.nShield.remove(shield); } - /** - * Adds the regenerated this turn. - */ - public final void addRegeneratedThisTurn() { - this.regeneratedThisTurn += 1; - } - - /** - * Gets the regenerated this turn. - * - * @return the regenerated this turn - */ - public final int getRegeneratedThisTurn() { - return this.regeneratedThisTurn; - } - - /** - * Sets the regenerated this turn. - * - * @param n - * the new regenerated this turn - */ - public final void setRegeneratedThisTurn(final int n) { - this.regeneratedThisTurn = n; - } - - /** - *

- * resetShield. - *

- */ public final void resetShield() { - this.nShield.clear();; + if (shields.isEmpty()) { return; } + shields.clear(); + view.updateShieldCount(this); + } + + public final void addRegeneratedThisTurn() { + regeneratedThisTurn++; + } + + public final int getRegeneratedThisTurn() { + return regeneratedThisTurn; + } + public final void setRegeneratedThisTurn(final int n) { + regeneratedThisTurn = n; } - /** - *

- * canBeShielded. - *

- * - * @return a boolean. - */ public final boolean canBeShielded() { - return !this.hasKeyword("CARDNAME can't be regenerated."); + return !hasKeyword("CARDNAME can't be regenerated."); } // is this "Card" supposed to be a token? - /** - *

- * Setter for the field token. - *

- * - * @param b - * a boolean. - */ - public final void setToken(final boolean b) { - this.token = b; - } - - /** - *

- * isToken. - *

- * - * @return a boolean. - */ public final boolean isToken() { - return this.token; + return token; + } + public final void setToken(boolean token0) { + if (token == token0) { return; } + token = token0; + view.updateToken(this); } - /** - *

- * Getter for the field copiedPermanent. - *

- * - * @return a Card. - */ public final Card getCopiedPermanent() { - return this.copiedPermanent; + return copiedPermanent; } - - /** - *

- * Setter for the field copiedPermanent. - *

- * - * @param c - * a Card. - */ public final void setCopiedPermanent(final Card c) { - this.copiedPermanent = c; + copiedPermanent = c; } - /** - *

- * Setter for the field copiedSpell. - *

- * - * @param b - * a boolean. - */ - public final void setCopiedSpell(final boolean b) { - this.copiedSpell = b; - } - - /** - *

- * isCopiedSpell. - *

- * - * @return a boolean. - */ public final boolean isCopiedSpell() { - return this.copiedSpell; + return copiedSpell; + } + public final void setCopiedSpell(final boolean b) { + copiedSpell = b; } - /** - *

- * isFaceDown. - *

- * - * @return a boolean. - */ public final boolean isFaceDown() { - return this.curCharacteristics == CardCharacteristicName.FaceDown; + return curCharacteristics == CardCharacteristicName.FaceDown; } - /** - *

- * setCanCounter. - *

- * - * @param b - * a boolean. - */ public final void setCanCounter(final boolean b) { - this.canCounter = b; + canCounter = b; } - /** - *

- * getCanCounter. - *

- * - * @return a boolean. - */ public final boolean getCanCounter() { - return this.canCounter; + return canCounter; } - - /** - *

- * addTrigger. - *

- * - * @param c - * a {@link forge.GameCommand} object. - * @param typeIn - * a {@link forge.game.trigger.ZCTrigger} object. - */ public final void addTrigger(final GameCommand c, final ZCTrigger typeIn) { - this.zcTriggers.add(new AbilityTriggered(this, c, typeIn)); + zcTriggers.add(new AbilityTriggered(this, c, typeIn)); } - /** - *

- * removeTrigger. - *

- * - * @param c - * a {@link forge.GameCommand} object. - * @param typeIn - * a {@link forge.game.trigger.ZCTrigger} object. - */ public final void removeTrigger(final GameCommand c, final ZCTrigger typeIn) { - this.zcTriggers.remove(new AbilityTriggered(this, c, typeIn)); + zcTriggers.remove(new AbilityTriggered(this, c, typeIn)); } - /** - *

- * executeTrigger. - *

- * - * @param type - * a {@link forge.game.trigger.ZCTrigger} object. - */ public final void executeTrigger(final ZCTrigger type) { - for (final AbilityTriggered t : this.zcTriggers) { + for (final AbilityTriggered t : zcTriggers) { if (t.getTrigger().equals(type) && t.isBasic()) { t.run(); } } } - /** - *

- * clearTriggers. - *

- */ public final void clearTriggers() { - this.zcTriggers.clear(); + zcTriggers.clear(); } - /** - *

- * addComesIntoPlayCommand. - *

- * - * @param c - * a {@link forge.GameCommand} object. - */ public final void addComesIntoPlayCommand(final GameCommand c) { - this.addTrigger(c, ZCTrigger.ENTERFIELD); + addTrigger(c, ZCTrigger.ENTERFIELD); } - - - /** - *

- * addDestroyCommand. - *

- * - * @param c - * a {@link forge.GameCommand} object. - */ public final void addDestroyCommand(final GameCommand c) { - this.addTrigger(c, ZCTrigger.DESTROY); + addTrigger(c, ZCTrigger.DESTROY); } - - /** - *

- * addLeavesPlayCommand. - *

- * - * @param c - * a {@link forge.GameCommand} object. - */ public final void addLeavesPlayCommand(final GameCommand c) { - this.addTrigger(c, ZCTrigger.LEAVEFIELD); + addTrigger(c, ZCTrigger.LEAVEFIELD); } - /** - *

- * addUntapCommand. - *

- * - * @param c - * a {@link forge.GameCommand} object. - */ public final void addUntapCommand(final GameCommand c) { - this.untapCommandList.add(c); + untapCommandList.add(c); } - /** - *

- * addChangeControllerCommand. - *

- * - * @param c - * a {@link forge.GameCommand} object. - */ public final void addChangeControllerCommand(final GameCommand c) { - this.changeControllerCommandList.add(c); + changeControllerCommandList.add(c); } public final void runChangeControllerCommands() { - for (final GameCommand c : this.changeControllerCommandList) { + for (final GameCommand c : changeControllerCommandList) { c.run(); } } - /** - *

- * Setter for the field sickness. - *

- * - * @param b - * a boolean. - */ - public final void setSickness(final boolean b) { - this.sickness = b; + public final void setSickness(boolean sickness0) { + if (sickness == sickness0) { return; } + sickness = sickness0; + view.updateSickness(this); } - /** @return boolean */ public final boolean isFirstTurnControlled() { - return this.sickness; + return sickness; } - /** - *

- * hasSickness. - *

- * - * @return a boolean. - */ public final boolean hasSickness() { - return this.sickness && !this.hasKeyword("Haste"); + return sickness && !hasKeyword("Haste"); } - /** - * - * isSick. - * - * @return boolean - */ public final boolean isSick() { - return this.sickness && this.isCreature() && !this.hasKeyword("Haste"); + return sickness && isCreature() && !hasKeyword("Haste"); } - /** - * @return the becameTargetThisTurn - */ public boolean hasBecomeTargetThisTurn() { return becameTargetThisTurn; } - - /** - * @param becameTargetThisTurn0 the becameTargetThisTurn to set - */ - public void setBecameTargetThisTurn(boolean becameTargetThisTurn) { - this.becameTargetThisTurn = becameTargetThisTurn; + public void setBecameTargetThisTurn(boolean becameTargetThisTurn0) { + becameTargetThisTurn = becameTargetThisTurn0; } - /** - * @return the startedTheTurnUntapped - */ public boolean hasStartedTheTurnUntapped() { return startedTheTurnUntapped; } - - /** - * @param startedTheTurnUntapped0 the startedTheTurnUntapped to set - */ public void setStartedTheTurnUntapped(boolean untapped) { - this.startedTheTurnUntapped = untapped; + startedTheTurnUntapped = untapped; } - /** - *

- * Getter for the field owner. - *

- * - * @return a {@link forge.game.player.Player} object. - */ public final Player getOwner() { - return this.owner; + return owner; + } + public final void setOwner(final Player owner0) { + if (owner == owner0) { return; } + owner = owner0; + view.updateOwner(this); } - /** - * Get the controller for this card. - * - * @return a {@link forge.game.player.Player} object. - */ public final Player getController() { - Entry lastEntry = this.tempControllers.lastEntry(); + Entry lastEntry = tempControllers.lastEntry(); if (lastEntry != null) { final long lastTimestamp = lastEntry.getKey(); - if (lastTimestamp > this.controllerTimestamp) { + if (lastTimestamp > controllerTimestamp) { return lastEntry.getValue(); } } - if (this.controller != null) { - return this.controller; + if (controller != null) { + return controller; } - return this.owner; - } - - public final void addTempController(final Player player, final long tstamp) { - this.tempControllers.put(tstamp, player); - } - - public final void removeTempController(final long tstamp) { - this.tempControllers.remove(tstamp); - } - - public final void clearTempControllers() { - this.tempControllers.clear(); - } - - public final void clearControllers() { - clearTempControllers(); - this.controller = null; + return owner; } public final void setController(final Player player, final long tstamp) { - clearTempControllers(); - this.controller = player; - this.controllerTimestamp = tstamp; + tempControllers.clear(); + controller = player; + controllerTimestamp = tstamp; + view.updateController(this); } - /** - *

- * Setter for the field owner. - *

- * - * @param player - * a {@link forge.game.player.Player} object. - */ - public final void setOwner(final Player player) { - this.owner = player; + public final void addTempController(final Player player, final long tstamp) { + tempControllers.put(tstamp, player); + view.updateController(this); } - public final void setMayLookAt(final Player player, final boolean mayLookAt) { - if (mayLookAt) { - this.mayLookAt.add(player); - } else { - this.mayLookAt.remove(player); + public final void removeTempController(final long tstamp) { + if (tempControllers.remove(tstamp) != null) { + view.updateController(this); } } - /** - *

- * Getter for the field equippedBy. - *

- * - * @return a {@link java.util.ArrayList} object. - */ - public final ArrayList getEquippedBy() { - return this.equippedBy; + public final void clearTempControllers() { + if (tempControllers.isEmpty()) { return; } + tempControllers.clear(); + view.updateController(this); } - /** - *

- * Getter for the field fortifiedBy. - *

- * - * @return a {@link java.util.ArrayList} object. - */ - public final ArrayList getFortifiedBy() { - return this.fortifiedBy; + public final void clearControllers() { + if (tempControllers.isEmpty() && controller == null) { return; } + tempControllers.clear(); + controller = null; + view.updateController(this); } - /** - *

- * Setter for the field equippedBy. - *

- * - * @param list - * a {@link java.util.ArrayList} object. - */ - public final void setEquippedBy(final ArrayList list) { - this.equippedBy = list; - } - - /** - *

- * Setter for the field fortifiedBy. - *

- * - * @param list - * a {@link java.util.ArrayList} object. - */ - public final void setFortifiedBy(final ArrayList list) { - this.fortifiedBy = list; - } - - /** - *

- * Getter for the field equipping. - *

- * - * @return a {@link java.util.ArrayList} object. - */ - public final ArrayList getEquipping() { - return this.equipping; - } - - /** - *

- * Getter for the field fortifying. - *

- * - * @return a {@link java.util.ArrayList} object. - */ - public final ArrayList getFortifying() { - return this.fortifying; - } - - /** - *

- * getEquippingCard. - *

- * - * @return a {@link forge.game.card.Card} object. - */ - public final Card getEquippingCard() { - if (this.equipping.isEmpty()) { - return null; + public final void setMayLookAt(final Player player, final boolean mayLookAt0) { + if (mayLookAt0) { + mayLookAt.add(player); } - return this.equipping.get(0); - } - - /** - *

- * getFortifyingCard. - *

- * - * @return a {@link forge.game.card.Card} object. - */ - public final Card getFortifyingCard() { - if (this.fortifying.isEmpty()) { - return null; + else { + mayLookAt.remove(player); } - return this.fortifying.get(0); } - /** - *

- * Setter for the field equipping. - *

- * - * @param list - * a {@link java.util.ArrayList} object. - */ - public final void setEquipping(final ArrayList list) { - this.equipping = list; - } - - /** - *

- * Setter for the field fortifying. - *

- * - * @param list - * a {@link java.util.ArrayList} object. - */ - public final void setFortifying(final ArrayList list) { - this.fortifying = list; - } - - /** - *

- * isEquipped. - *

- * - * @return a boolean. - */ public final boolean isEquipped() { - return !this.equippedBy.isEmpty(); + return !equippedBy.isEmpty(); + } + public final ArrayList getEquippedBy() { + return equippedBy; + } + public final void setEquippedBy(final ArrayList list) { + equippedBy = list; } - /** - *

- * isFortified. - *

- * - * @return a boolean. - */ public final boolean isFortified() { - return !this.fortifiedBy.isEmpty(); + return !fortifiedBy.isEmpty(); + } + public final ArrayList getFortifiedBy() { + return fortifiedBy; + } + public final void setFortifiedBy(final ArrayList list) { + fortifiedBy = list; } - /** - *

- * isEquipping. - *

- * - * @return a boolean. - */ + public final Card getEquipping() { + return equipping; + } + public final void setEquipping(final Card card) { + equipping = card; + } public final boolean isEquipping() { - return this.equipping.size() != 0; + return equipping != null; } - /** - *

- * isFortifying. - *

- * - * @return a boolean. - */ + public final Card getFortifying() { + return fortifying; + } + public final void setFortifying(final Card card) { + fortifying = card; + } public final boolean isFortifying() { - return !this.fortifying.isEmpty(); + return fortifying != null; } - /** - *

- * equipCard. - *

- * equipment.equipCard(cardToBeEquipped) - * - * @param c - * a {@link forge.game.card.Card} object. - */ public final void equipCard(final Card c) { if (c.hasKeyword("CARDNAME can't be equipped.")) { getGame().getGameLog().add(GameLogEntryType.STACK_RESOLVE, "Trying to equip " + c.getName() + " but it can't be equipped."); return; } - if (this.hasStartOfKeyword("CantEquip")) { - final int keywordPosition = this.getKeywordPosition("CantEquip"); - final String parse = this.getKeyword().get(keywordPosition).toString(); + if (hasStartOfKeyword("CantEquip")) { + final int keywordPosition = getKeywordPosition("CantEquip"); + final String parse = getKeyword().get(keywordPosition).toString(); final String[] k = parse.split(" ", 2); final String[] restrictions = k[1].split(","); - if (c.isValid(restrictions, this.getController(), this)) { + if (c.isValid(restrictions, getController(), this)) { getGame().getGameLog().add(GameLogEntryType.STACK_RESOLVE, "Trying to equip " + c.getName() + " but it can't be equipped."); return; } } Card oldTarget = null; - if (this.isEquipping()) { - oldTarget = this.getEquipping().get(0); - this.unEquipCard(oldTarget); + if (isEquipping()) { + oldTarget = equipping; + unEquipCard(oldTarget); } // They use double links... it's doubtful - this.equipping.add(c); - this.setTimestamp(this.getGame().getNextTimestamp()); + equipping = c; + setTimestamp(getGame().getNextTimestamp()); c.equippedBy.add(this); // Play the Equip sound @@ -3480,27 +2297,18 @@ public class Card extends GameEntity implements Comparable, IIdentifiable final HashMap runParams = new HashMap(); runParams.put("AttachSource", this); runParams.put("AttachTarget", c); - this.getController().getGame().getTriggerHandler().runTrigger(TriggerType.Attached, runParams, false); + getController().getGame().getTriggerHandler().runTrigger(TriggerType.Attached, runParams, false); } - /** - *

- * fortifyCard. - *

- * fortification.fortifyCard(cardToBeFortified) - * - * @param c - * a {@link forge.game.card.Card} object. - */ public final void fortifyCard(final Card c) { Card oldTarget = null; - if (this.isFortifying()) { - oldTarget = this.getFortifying().get(0); - this.unFortifyCard(oldTarget); + if (isFortifying()) { + oldTarget = fortifying; + unFortifyCard(oldTarget); } - this.fortifying.add(c); - this.setTimestamp(this.getGame().getNextTimestamp()); + fortifying = c; + setTimestamp(getGame().getNextTimestamp()); c.fortifiedBy.add(this); // Play the Equip sound @@ -3509,19 +2317,13 @@ public class Card extends GameEntity implements Comparable, IIdentifiable final HashMap runParams = new HashMap(); runParams.put("AttachSource", this); runParams.put("AttachTarget", c); - this.getController().getGame().getTriggerHandler().runTrigger(TriggerType.Attached, runParams, false); + getController().getGame().getTriggerHandler().runTrigger(TriggerType.Attached, runParams, false); } - /** - *

- * unEquipCard. - *

- * - * @param c - * a {@link forge.game.card.Card} object. - */ public final void unEquipCard(final Card c) { // equipment.unEquipCard(equippedCard); - this.equipping.remove(c); + if (equipping == c) { + equipping = null; + } c.equippedBy.remove(this); getGame().fireEvent(new GameEventCardAttachment(this, c, null, AttachMethod.Equip)); @@ -3533,115 +2335,54 @@ public class Card extends GameEntity implements Comparable, IIdentifiable getGame().getTriggerHandler().runTrigger(TriggerType.Unequip, runParams, false); } - /** - *

- * unFortifyCard. - *

- * - * @param c - * a {@link forge.game.card.Card} object. - */ public final void unFortifyCard(final Card c) { // fortification.unEquipCard(fortifiedCard); - this.fortifying.remove(c); + if (fortifying == c) { + fortifying = null; + } c.fortifiedBy.remove(this); getGame().fireEvent(new GameEventCardAttachment(this, c, null, AttachMethod.Fortify)); } - /** - *

- * unEquipAllCards. - *

- */ public final void unEquipAllCards() { // while there exists equipment, unequip the first one - while (this.equippedBy.size() > 0) { - this.equippedBy.get(0).unEquipCard(this); + while (equippedBy.size() > 0) { + equippedBy.get(0).unEquipCard(this); } } - /** - *

- * Getter for the field enchanting. - *

- * - * @return a {@link forge.game.GameEntity} object. - */ public final GameEntity getEnchanting() { - return this.enchanting; + return enchanting; } - /** - *

- * getEnchantingCard. - *

- * - * @return a {@link forge.game.card.Card} object. - */ public final Card getEnchantingCard() { - if (this.enchanting instanceof Card) { - return (Card) this.enchanting; + if (enchanting instanceof Card) { + return (Card) enchanting; } return null; } - /** - *

- * getEnchantingPlayer. - *

- * - * @return a {@link forge.game.player.Player} object. - */ public final Player getEnchantingPlayer() { - if (this.enchanting instanceof Player) { - return (Player) this.enchanting; + if (enchanting instanceof Player) { + return (Player) enchanting; } return null; } - /** - *

- * Setter for the field enchanting. - *

- * - * @param e - * a GameEntity object. - */ public final void setEnchanting(final GameEntity e) { - this.enchanting = e; + enchanting = e; } - /** - *

- * isEnchanting. - *

- * - * @return a boolean. - */ public final boolean isEnchanting() { - return this.enchanting != null; + return enchanting != null; } - /** - *

- * isEnchanting. - *

- * - * @return a boolean. - */ public final boolean isEnchantingCard() { - return this.getEnchantingCard() != null; + return getEnchantingCard() != null; } - /** - *

- * isEnchanting. - *

- * - * @return a boolean. - */ public final boolean isEnchantingPlayer() { - return this.getEnchantingPlayer() != null; + return getEnchantingPlayer() != null; } /** @@ -3653,7 +2394,7 @@ public class Card extends GameEntity implements Comparable, IIdentifiable * false otherwise */ public final boolean isEnchantedBy(final String cardName) { - final ArrayList allAuras = this.getEnchantedBy(); + final ArrayList allAuras = getEnchantedBy(); for (final Card aura : allAuras) { if (aura.getName().equals(cardName)) { return true; @@ -3662,28 +2403,12 @@ public class Card extends GameEntity implements Comparable, IIdentifiable return false; } - /** - *

- * removeEnchanting. - *

- * - * @param e - * a {@link forge.game.GameEntity} object. - */ public final void removeEnchanting(final GameEntity e) { - if (this.enchanting.equals(e)) { - this.enchanting = null; + if (enchanting.equals(e)) { + enchanting = null; } } - /** - *

- * enchant. - *

- * - * @param entity - * a {@link forge.game.GameEntity} object. - */ public final void enchantEntity(final GameEntity entity) { if (entity.hasKeyword("CARDNAME can't be enchanted.") || entity.hasKeyword("CARDNAME can't be enchanted in the future.")) { @@ -3691,8 +2416,8 @@ public class Card extends GameEntity implements Comparable, IIdentifiable + " but it can't be enchanted."); return; } - this.enchanting = entity; - this.setTimestamp(this.getGame().getNextTimestamp()); + enchanting = entity; + setTimestamp(getGame().getNextTimestamp()); entity.addEnchantedBy(this); getGame().fireEvent(new GameEventCardAttachment(this, null, entity, AttachMethod.Enchant)); @@ -3701,73 +2426,39 @@ public class Card extends GameEntity implements Comparable, IIdentifiable final HashMap runParams = new HashMap(); runParams.put("AttachSource", this); runParams.put("AttachTarget", entity); - this.getController().getGame().getTriggerHandler().runTrigger(TriggerType.Attached, runParams, false); + getController().getGame().getTriggerHandler().runTrigger(TriggerType.Attached, runParams, false); } - /** - *

- * unEnchant. - *

- * - * @param gameEntity - * a {@link forge.game.GameEntity} object. - */ public final void unEnchantEntity(final GameEntity entity) { - if (this.enchanting == null || !this.enchanting.equals(entity)) + if (enchanting == null || !enchanting.equals(entity)) return; - this.enchanting = null; + enchanting = null; entity.removeEnchantedBy(this); - if (this.isBestowed()) { - this.unanimateBestow(); + if (isBestowed()) { + unanimateBestow(); } getGame().fireEvent(new GameEventCardAttachment(this, entity, null, AttachMethod.Enchant)); } - /** - *

- * Setter for the field type. - *

- * - * @param a - * a {@link java.util.ArrayList} object. - */ public final void setType(final List a) { - this.getCharacteristics().setType(new ArrayList(a)); + getCharacteristics().setType(new ArrayList(a)); } - /** - *

- * addType. - *

- * - * @param a - * a {@link java.lang.String} object. - */ public final void addType(final String a) { - this.getCharacteristics().getType().add(a); + getCharacteristics().getType().add(a); } - - /** - *

- * Getter for the field type. - *

- * - * @return a {@link java.util.ArrayList} object. - */ - public final ArrayList getType() { - + public final HashSet getType() { // see if type changes are in effect - final ArrayList newType = new ArrayList(this.getCharacteristics().getType()); - for (final CardType ct : this.changedCardTypes.values()) { + final HashSet newType = new HashSet(getCharacteristics().getType()); + for (final CardType ct : changedCardTypes.values()) { final ArrayList removeTypes = new ArrayList(); if (ct.getRemoveType() != null) { removeTypes.addAll(ct.getRemoveType()); } // remove old types - for (int i = 0; i < newType.size(); i++) { - final String t = newType.get(i); + for (String t : newType) { if (ct.isRemoveSuperTypes() && forge.card.CardType.isASuperType(t)) { removeTypes.add(t); } @@ -3786,57 +2477,18 @@ public class Card extends GameEntity implements Comparable, IIdentifiable if (ct.getType() != null) { newType.addAll(ct.getType()); } - } return newType; } - /** - * - * TODO Write javadoc for this method. - * - * @param types - * ArrayList - * @param removeTypes - * ArrayList - * @param removeSuperTypes - * boolean - * @param removeCardTypes - * boolean - * @param removeSubTypes - * boolean - * @param removeCreatureTypes - * boolean - * @param timestamp - * long - */ public final void addChangedCardTypes(final ArrayList types, final ArrayList removeTypes, final boolean removeSuperTypes, final boolean removeCardTypes, final boolean removeSubTypes, final boolean removeCreatureTypes, final long timestamp) { - this.changedCardTypes.put(timestamp, new CardType(types, removeTypes, removeSuperTypes, removeCardTypes, removeSubTypes, removeCreatureTypes)); + changedCardTypes.put(timestamp, new CardType(types, removeTypes, removeSuperTypes, removeCardTypes, removeSubTypes, removeCreatureTypes)); } - /** - * - * TODO Write javadoc for this method. - * - * @param types - * String[] - * @param removeTypes - * String[] - * @param removeSuperTypes - * boolean - * @param removeCardTypes - * boolean - * @param removeSubTypes - * boolean - * @param removeCreatureTypes - * boolean - * @param timestamp - * long - */ public final void addChangedCardTypes(final String[] types, final String[] removeTypes, final boolean removeSuperTypes, final boolean removeCardTypes, final boolean removeSubTypes, final boolean removeCreatureTypes, final long timestamp) { @@ -3850,176 +2502,82 @@ public class Card extends GameEntity implements Comparable, IIdentifiable removeTypeList = new ArrayList(Arrays.asList(removeTypes)); } - this.addChangedCardTypes(typeList, removeTypeList, removeSuperTypes, removeCardTypes, removeSubTypes, + addChangedCardTypes(typeList, removeTypeList, removeSuperTypes, removeCardTypes, removeSubTypes, removeCreatureTypes, timestamp); } - /** - * - * TODO Write javadoc for this method. - * - * @param timestamp - * long - */ public final void removeChangedCardTypes(final long timestamp) { - this.changedCardTypes.remove(Long.valueOf(timestamp)); + changedCardTypes.remove(Long.valueOf(timestamp)); } // values that are printed on card - /** - *

- * Getter for the field baseLoyalty. - *

- * - * @return a int. - */ public final int getBaseLoyalty() { - return this.baseLoyalty; + return baseLoyalty; } public final int getCurrentLoyalty() { int loyalty = getCounters(CounterType.LOYALTY); if (loyalty == 0) { - loyalty = this.baseLoyalty; + loyalty = baseLoyalty; } return loyalty; } // values that are printed on card - /** - *

- * Setter for the field baseLoyalty. - *

- * - * @param n - * a int. - */ public final void setBaseLoyalty(final int n) { - this.baseLoyalty = n; + baseLoyalty = n; } // values that are printed on card - /** - *

- * Getter for the field baseAttack. - *

- * - * @return a int. - */ public final int getBaseAttack() { - return this.getCharacteristics().getBaseAttack(); + return getCharacteristics().getBaseAttack(); } - /** - *

- * Getter for the field baseDefense. - *

- * - * @return a int. - */ public final int getBaseDefense() { - return this.getCharacteristics().getBaseDefense(); + return getCharacteristics().getBaseDefense(); } // values that are printed on card - /** - *

- * Setter for the field baseAttack. - *

- * - * @param n - * a int. - */ public final void setBaseAttack(final int n) { - this.getCharacteristics().setBaseAttack(n); + getCharacteristics().setBaseAttack(n); } - /** - *

- * Setter for the field baseDefense. - *

- * - * @param n - * a int. - */ public final void setBaseDefense(final int n) { - this.getCharacteristics().setBaseDefense(n); + getCharacteristics().setBaseDefense(n); } // values that are printed on card - /** - *

- * Getter for the field baseAttackString. - *

- * - * @return a {@link java.lang.String} object. - */ public final String getBaseAttackString() { - return (null == this.baseAttackString) ? "" + this.getBaseAttack() : this.baseAttackString; + return (null == baseAttackString) ? "" + getBaseAttack() : baseAttackString; } - /** - *

- * Getter for the field baseDefenseString. - *

- * - * @return a {@link java.lang.String} object. - */ public final String getBaseDefenseString() { - return (null == this.baseDefenseString) ? "" + this.getBaseDefense() : this.baseDefenseString; + return (null == baseDefenseString) ? "" + getBaseDefense() : baseDefenseString; } // values that are printed on card - /** - *

- * Setter for the field baseAttackString. - *

- * - * @param s - * a {@link java.lang.String} object. - */ public final void setBaseAttackString(final String s) { - this.baseAttackString = s; + baseAttackString = s; } - /** - *

- * Setter for the field baseDefenseString. - *

- * - * @param s - * a {@link java.lang.String} object. - */ public final void setBaseDefenseString(final String s) { - this.baseDefenseString = s; + baseDefenseString = s; } - /** - * - * TODO Write javadoc for this method. - * - * @return int - */ public final int getSetPower() { - if (this.newPT.isEmpty()) { + if (newPT.isEmpty()) { return -1; } - return this.getLatestPT().getLeft(); + return getLatestPT().getLeft(); } - /** - * - * TODO Write javadoc for this method. - * - * @return int - */ public final int getSetToughness() { - if (this.newPT.isEmpty()) { + if (newPT.isEmpty()) { return -1; } - return this.getLatestPT().getRight(); + return getLatestPT().getRight(); } /** @@ -4034,7 +2592,7 @@ public class Card extends GameEntity implements Comparable, IIdentifiable // Find latest set power long maxPowerTimestamp = -2; int latestPower = -1; - for (final CardPowerToughness pt : this.newPT) { + for (final CardPowerToughness pt : newPT) { if (pt.getTimestamp() >= maxPowerTimestamp && pt.getPower() != -1) { maxPowerTimestamp = pt.getTimestamp(); latestPower = pt.getPower(); @@ -4044,7 +2602,7 @@ public class Card extends GameEntity implements Comparable, IIdentifiable // Find latest set toughness long maxToughnessTimestamp = -2; int latestToughness = -1; - for (final CardPowerToughness pt : this.newPT) { + for (final CardPowerToughness pt : newPT) { if (pt.getTimestamp() >= maxToughnessTimestamp && pt.getToughness() != -1) { maxToughnessTimestamp = pt.getTimestamp(); latestToughness = pt.getToughness(); @@ -4054,46 +2612,22 @@ public class Card extends GameEntity implements Comparable, IIdentifiable return Pair.of(latestPower, latestToughness); } - /** - * - * TODO Write javadoc for this method. - * - * @param power - * int - * @param toughness - * int - * @param timestamp - * int - */ public final void addNewPT(final int power, final int toughness, final long timestamp) { - this.newPT.add(new CardPowerToughness(power, toughness, timestamp)); + newPT.add(new CardPowerToughness(power, toughness, timestamp)); } - /** - * - * TODO Write javadoc for this method. - * - * @param timestamp - * long - */ public final void removeNewPT(final long timestamp) { - for (int i = 0; i < this.newPT.size(); i++) { - final CardPowerToughness cardPT = this.newPT.get(i); + for (int i = 0; i < newPT.size(); i++) { + final CardPowerToughness cardPT = newPT.get(i); if (cardPT.getTimestamp() == timestamp) { - this.newPT.remove(cardPT); + newPT.remove(cardPT); } } } - /** - * - * TODO Write javadoc for this method. - * - * @return int - */ public final int getCurrentPower() { - int total = this.getBaseAttack(); - final int setPower = this.getSetPower(); + int total = getBaseAttack(); + final int setPower = getSetPower(); if (setPower != -1) { total = setPower; } @@ -4101,53 +2635,33 @@ public class Card extends GameEntity implements Comparable, IIdentifiable return total; } - /** - *

- * getUnswitchedAttack. - *

- * - * @return a int. - */ public final int getUnswitchedPower() { - int total = this.getCurrentPower(); + int total = getCurrentPower(); - total += this.getTempAttackBoost() + this.getSemiPermanentAttackBoost() + getPowerBonusFromCounters(); + total += getTempAttackBoost() + getSemiPermanentAttackBoost() + getPowerBonusFromCounters(); return total; } public final int getPowerBonusFromCounters() { int total = 0; - total += this.getCounters(CounterType.P1P1) + this.getCounters(CounterType.P1P2) + this.getCounters(CounterType.P1P0) - - this.getCounters(CounterType.M1M1) + 2 * this.getCounters(CounterType.P2P2) - 2 * this.getCounters(CounterType.M2M1) - - 2 * this.getCounters(CounterType.M2M2) - this.getCounters(CounterType.M1M0) + 2 * this.getCounters(CounterType.P2P0); + total += getCounters(CounterType.P1P1) + getCounters(CounterType.P1P2) + getCounters(CounterType.P1P0) + - getCounters(CounterType.M1M1) + 2 * getCounters(CounterType.P2P2) - 2 * getCounters(CounterType.M2M1) + - 2 * getCounters(CounterType.M2M2) - getCounters(CounterType.M1M0) + 2 * getCounters(CounterType.P2P0); return total; } - /** - *

- * getNetAttack. - *

- * - * @return a int. - */ public final int getNetAttack() { - if (this.getAmountOfKeyword("CARDNAME's power and toughness are switched") % 2 != 0) { - return this.getUnswitchedToughness(); + if (getAmountOfKeyword("CARDNAME's power and toughness are switched") % 2 != 0) { + return getUnswitchedToughness(); } - return this.getUnswitchedPower(); + return getUnswitchedPower(); } - /** - * - * TODO Write javadoc for this method. - * - * @return an int - */ public final int getCurrentToughness() { - int total = this.getBaseDefense(); + int total = getBaseDefense(); - final int setToughness = this.getSetToughness(); + final int setToughness = getSetToughness(); if (setToughness != -1) { total = setToughness; } @@ -4155,68 +2669,47 @@ public class Card extends GameEntity implements Comparable, IIdentifiable return total; } - /** - *

- * getUnswitchedDefense. - *

- * - * @return a int. - */ public final int getUnswitchedToughness() { - int total = this.getCurrentToughness(); + int total = getCurrentToughness(); - total += this.getTempDefenseBoost() + this.getSemiPermanentDefenseBoost() + getToughnessBonusFromCounters(); + total += getTempDefenseBoost() + getSemiPermanentDefenseBoost() + getToughnessBonusFromCounters(); return total; } public final int getToughnessBonusFromCounters() { int total = 0; - total += this.getCounters(CounterType.P1P1) + 2 * this.getCounters(CounterType.P1P2) - this.getCounters(CounterType.M1M1) - + this.getCounters(CounterType.P0P1) - 2 * this.getCounters(CounterType.M0M2) + 2 * this.getCounters(CounterType.P2P2) - - this.getCounters(CounterType.M0M1) - this.getCounters(CounterType.M2M1) - 2 * this.getCounters(CounterType.M2M2) - + 2 * this.getCounters(CounterType.P0P2); + total += getCounters(CounterType.P1P1) + 2 * getCounters(CounterType.P1P2) - getCounters(CounterType.M1M1) + + getCounters(CounterType.P0P1) - 2 * getCounters(CounterType.M0M2) + 2 * getCounters(CounterType.P2P2) + - getCounters(CounterType.M0M1) - getCounters(CounterType.M2M1) - 2 * getCounters(CounterType.M2M2) + + 2 * getCounters(CounterType.P0P2); return total; } - /** - *

- * getNetDefense. - *

- * - * @return a int. - */ public final int getNetDefense() { - if (this.getAmountOfKeyword("CARDNAME's power and toughness are switched") % 2 != 0) { - return this.getUnswitchedPower(); + if (getAmountOfKeyword("CARDNAME's power and toughness are switched") % 2 != 0) { + return getUnswitchedPower(); } - return this.getUnswitchedToughness(); + return getUnswitchedToughness(); } // How much combat damage does the card deal - /** - *

- * getNetCombatDamage. - *

- * - * @return a int. - */ public final int getNetCombatDamage() { - if (this.hasKeyword("CARDNAME assigns no combat damage")) { + if (hasKeyword("CARDNAME assigns no combat damage")) { return 0; } if (getGame().getStaticEffects().getGlobalRuleChange(GlobalRuleChange.toughnessAssignsDamage)) { - return this.getNetDefense(); + return getNetDefense(); } - return this.getNetAttack(); + return getNetAttack(); } private int multiKickerMagnitude = 0; - public final void addMultiKickerMagnitude(final int n) { this.multiKickerMagnitude += n; } - public final void setKickerMagnitude(final int n) { this.multiKickerMagnitude = n; } + public final void addMultiKickerMagnitude(final int n) { multiKickerMagnitude += n; } + public final void setKickerMagnitude(final int n) { multiKickerMagnitude = n; } public final int getKickerMagnitude() { - if (this.multiKickerMagnitude > 0) { + if (multiKickerMagnitude > 0) { return multiKickerMagnitude; } boolean hasK1 = costsPaid.contains(OptionalCost.Kicker1); @@ -4224,188 +2717,80 @@ public class Card extends GameEntity implements Comparable, IIdentifiable } private int pseudoKickerMagnitude = 0; - public final void addPseudoMultiKickerMagnitude(final int n) { this.pseudoKickerMagnitude += n; } - public final void setPseudoMultiKickerMagnitude(final int n) { this.pseudoKickerMagnitude = n; } + public final void addPseudoMultiKickerMagnitude(final int n) { pseudoKickerMagnitude += n; } + public final void setPseudoMultiKickerMagnitude(final int n) { pseudoKickerMagnitude = n; } public final int getPseudoKickerMagnitude() { return pseudoKickerMagnitude; } // for cards like Giant Growth, etc. - /** - *

- * Getter for the field tempAttackBoost. - *

- * - * @return a int. - */ public final int getTempAttackBoost() { - return this.tempAttackBoost; + return tempAttackBoost; } - /** - *

- * Getter for the field tempDefenseBoost. - *

- * - * @return a int. - */ public final int getTempDefenseBoost() { - return this.tempDefenseBoost; + return tempDefenseBoost; } - /** - *

- * addTempAttackBoost. - *

- * - * @param n - * a int. - */ public final void addTempAttackBoost(final int n) { - this.tempAttackBoost += n; + tempAttackBoost += n; } - /** - *

- * addTempDefenseBoost. - *

- * - * @param n - * a int. - */ public final void addTempDefenseBoost(final int n) { - this.tempDefenseBoost += n; + tempDefenseBoost += n; } // for cards like Glorious Anthem, etc. - /** - *

- * Getter for the field semiPermanentAttackBoost. - *

- * - * @return a int. - */ public final int getSemiPermanentAttackBoost() { - return this.semiPermanentAttackBoost; + return semiPermanentAttackBoost; } - /** - *

- * Getter for the field semiPermanentDefenseBoost. - *

- * - * @return a int. - */ public final int getSemiPermanentDefenseBoost() { - return this.semiPermanentDefenseBoost; + return semiPermanentDefenseBoost; } - /** - *

- * addSemiPermanentAttackBoost. - *

- * - * @param n - * a int. - */ public final void addSemiPermanentAttackBoost(final int n) { - this.semiPermanentAttackBoost += n; + semiPermanentAttackBoost += n; } - /** - *

- * addSemiPermanentDefenseBoost. - *

- * - * @param n - * a int. - */ public final void addSemiPermanentDefenseBoost(final int n) { - this.semiPermanentDefenseBoost += n; + semiPermanentDefenseBoost += n; } - /** - *

- * Setter for the field semiPermanentAttackBoost. - *

- * - * @param n - * a int. - */ public final void setSemiPermanentAttackBoost(final int n) { - this.semiPermanentAttackBoost = n; + semiPermanentAttackBoost = n; } - /** - *

- * Setter for the field semiPermanentDefenseBoost. - *

- * - * @param n - * a int. - */ public final void setSemiPermanentDefenseBoost(final int n) { - this.semiPermanentDefenseBoost = n; + semiPermanentDefenseBoost = n; } - /** - *

- * isUntapped. - *

- * - * @return a boolean. - */ public final boolean isUntapped() { - return !this.tapped; + return !tapped; } - /** - *

- * isTapped. - *

- * - * @return a boolean. - */ public final boolean isTapped() { - return this.tapped; + return tapped; + } + public final void setTapped(boolean tapped0) { + if (tapped == tapped0) { return; } + tapped = tapped0; + view.updateTapped(this); } - /** - *

- * Setter for the field tapped. - *

- * - * @param b - * a boolean. - */ - public final void setTapped(final boolean b) { - this.tapped = b; - } - - /** - *

- * tap. - *

- */ public final void tap() { - if (this.isTapped()) - return; + if (tapped) { return; } // Run triggers final Map runParams = new TreeMap(); runParams.put("Card", this); getGame().getTriggerHandler().runTrigger(TriggerType.Taps, runParams, false); - this.setTapped(true); + setTapped(true); getGame().fireEvent(new GameEventCardTapped(this, true)); } - /** - *

- * untap. - *

- */ public final void untap() { - if (this.isUntapped()) - return; + if (!tapped) { return; } + // Run Replacement effects final HashMap repRunParams = new HashMap(); repRunParams.put("Event", "Untap"); @@ -4420,62 +2805,34 @@ public class Card extends GameEntity implements Comparable, IIdentifiable runParams.put("Card", this); getGame().getTriggerHandler().runTrigger(TriggerType.Untaps, runParams, false); - for (final GameCommand var : this.untapCommandList) { + for (final GameCommand var : untapCommandList) { var.run(); } - this.setTapped(false); + setTapped(false); getGame().fireEvent(new GameEventCardTapped(this, false)); } // keywords are like flying, fear, first strike, etc... - /** - *

- * getKeyword. - *

- * - * @return a {@link java.util.ArrayList} object. - */ public final List getKeyword() { - final ArrayList keywords = this.getUnhiddenKeyword(); - keywords.addAll(this.getHiddenExtrinsicKeyword()); + final ArrayList keywords = getUnhiddenKeyword(); + keywords.addAll(getHiddenExtrinsicKeyword()); return keywords; } - /** - * Gets the keyword amount. - * - * @param keyword - * the keyword - * @return the keyword amount - */ public final int getKeywordAmount(final String keyword) { int res = 0; - for (final String k : this.getKeyword()) { + for (final String k : getKeyword()) { if (k.equals(keyword)) { res++; } } - return res; } - - /** - * Adds the changed card keywords. - * - * @param keywords - * the keywords - * @param removeKeywords - * the remove keywords - * @param removeAllKeywords - * the remove all keywords - * @param timestamp - * the timestamp - */ public final void addChangedCardKeywords(final List keywords, final List removeKeywords, final boolean removeAllKeywords, final long timestamp) { - keywords.removeAll(this.getCantHaveOrGainKeyword()); + keywords.removeAll(getCantHaveOrGainKeyword()); // if the key already exists - merge entries if (changedCardKeywords.containsKey(timestamp)) { List kws = keywords; @@ -4485,25 +2842,13 @@ public class Card extends GameEntity implements Comparable, IIdentifiable kws.addAll(cks.getKeywords()); rkws.addAll(cks.getRemoveKeywords()); remAll |= cks.isRemoveAllKeywords(); - this.changedCardKeywords.put(timestamp, new KeywordsChange(kws, rkws, remAll)); + changedCardKeywords.put(timestamp, new KeywordsChange(kws, rkws, remAll)); return; } - this.changedCardKeywords.put(timestamp, new KeywordsChange(keywords, removeKeywords, removeAllKeywords)); + changedCardKeywords.put(timestamp, new KeywordsChange(keywords, removeKeywords, removeAllKeywords)); } - /** - * Adds the changed card keywords. - * - * @param keywords - * the keywords - * @param removeKeywords - * the remove keywords - * @param removeAllKeywords - * the remove all keywords - * @param timestamp - * the timestamp - */ public final void addChangedCardKeywords(final String[] keywords, final String[] removeKeywords, final boolean removeAllKeywords, final long timestamp) { ArrayList keywordsList = new ArrayList(); @@ -4516,35 +2861,21 @@ public class Card extends GameEntity implements Comparable, IIdentifiable removeKeywordsList = new ArrayList(Arrays.asList(removeKeywords)); } - this.addChangedCardKeywords(keywordsList, removeKeywordsList, removeAllKeywords, timestamp); + addChangedCardKeywords(keywordsList, removeKeywordsList, removeAllKeywords, timestamp); } - /** - * Removes the changed card keywords. - * - * @param timestamp - * the timestamp - * @return the removed {@link KeywordsChange}. - */ public final KeywordsChange removeChangedCardKeywords(final long timestamp) { return changedCardKeywords.remove(Long.valueOf(timestamp)); } // Hidden keywords will be left out - /** - *

- * getUnhiddenKeyword. - *

- * - * @return a {@link java.util.ArrayList} object. - */ public final ArrayList getUnhiddenKeyword() { final ArrayList keywords = new ArrayList(); - keywords.addAll(this.getIntrinsicKeyword()); - keywords.addAll(this.getExtrinsicKeyword()); + keywords.addAll(getIntrinsicKeyword()); + keywords.addAll(getExtrinsicKeyword()); // see if keyword changes are in effect - for (final KeywordsChange ck : this.changedCardKeywords.values()) { + for (final KeywordsChange ck : changedCardKeywords.values()) { if (ck.isRemoveAllKeywords()) { keywords.clear(); @@ -4572,16 +2903,16 @@ public class Card extends GameEntity implements Comparable, IIdentifiable if (MagicColor.fromName(newWord) == 0) { throw new RuntimeException("Not a color: " + newWord); } - this.changedTextColors.add(timestamp, StringUtils.capitalize(originalWord), StringUtils.capitalize(newWord)); - this.updateKeywordsChangedText(timestamp); - this.updateChangedText(); + changedTextColors.add(timestamp, StringUtils.capitalize(originalWord), StringUtils.capitalize(newWord)); + updateKeywordsChangedText(timestamp); + updateChangedText(); } public final void removeChangedTextColorWord(final Long timestamp) { - this.changedTextColors.remove(timestamp); - this.updateKeywordsOnRemoveChangedText( - this.removeChangedCardKeywords(timestamp.longValue())); - this.updateChangedText(); + changedTextColors.remove(timestamp); + updateKeywordsOnRemoveChangedText( + removeChangedCardKeywords(timestamp.longValue())); + updateChangedText(); } /** @@ -4590,44 +2921,44 @@ public class Card extends GameEntity implements Comparable, IIdentifiable * @param newWord the new type word. */ public final void addChangedTextTypeWord(final String originalWord, final String newWord, final Long timestamp) { - this.changedTextTypes.add(timestamp, originalWord, newWord); - if (this.getType().contains(originalWord)) { - this.addChangedCardTypes(Lists.newArrayList(newWord), Lists.newArrayList(originalWord), false, false, false, false, timestamp); + changedTextTypes.add(timestamp, originalWord, newWord); + if (getType().contains(originalWord)) { + addChangedCardTypes(Lists.newArrayList(newWord), Lists.newArrayList(originalWord), false, false, false, false, timestamp); } - this.updateKeywordsChangedText(timestamp); - this.updateChangedText(); + updateKeywordsChangedText(timestamp); + updateChangedText(); } public final void removeChangedTextTypeWord(final Long timestamp) { - this.changedTextTypes.remove(timestamp); - this.removeChangedCardTypes(timestamp); - this.updateKeywordsOnRemoveChangedText( - this.removeChangedCardKeywords(timestamp.longValue())); - this.updateChangedText(); + changedTextTypes.remove(timestamp); + removeChangedCardTypes(timestamp); + updateKeywordsOnRemoveChangedText( + removeChangedCardKeywords(timestamp.longValue())); + updateChangedText(); } private final void updateKeywordsChangedText(final Long timestamp) { - if (this.hasSVar("LockInKeywords")) { + if (hasSVar("LockInKeywords")) { return; } final List addKeywords = Lists.newArrayList(), - removeKeywords = Lists.newArrayList(this.keywordsGrantedByTextChanges); + removeKeywords = Lists.newArrayList(keywordsGrantedByTextChanges); - for (final String kw : this.getIntrinsicKeyword()) { + for (final String kw : getIntrinsicKeyword()) { final String newKw = AbilityUtils.applyKeywordTextChangeEffects(kw, this); if (!newKw.equals(kw)) { addKeywords.add(newKw); removeKeywords.add(kw); - this.keywordsGrantedByTextChanges.add(newKw); + keywordsGrantedByTextChanges.add(newKw); } } - this.addChangedCardKeywords(addKeywords, removeKeywords, false, timestamp.longValue()); + addChangedCardKeywords(addKeywords, removeKeywords, false, timestamp.longValue()); } private final void updateKeywordsOnRemoveChangedText(final KeywordsChange k) { if (k != null) { - this.keywordsGrantedByTextChanges.removeAll(k.getKeywords()); + keywordsGrantedByTextChanges.removeAll(k.getKeywords()); } } @@ -4637,17 +2968,17 @@ public class Card extends GameEntity implements Comparable, IIdentifiable private final void updateChangedText() { resetChangedSVars(); final List allAbs = ImmutableList.builder() - .addAll(this.getSpellAbilities()) - .addAll(this.getStaticAbilities()) - .addAll(this.getReplacementEffects()) - .addAll(this.getTriggers()) + .addAll(getSpellAbilities()) + .addAll(getStaticAbilities()) + .addAll(getReplacementEffects()) + .addAll(getTriggers()) .build(); for (final CardTraitBase ctb : allAbs) { if (ctb.isIntrinsic()) { ctb.changeText(); } } - this.text = AbilityUtils.applyDescriptionTextChangeEffects(this.originalText, this); + text = AbilityUtils.applyDescriptionTextChangeEffects(originalText, this); } public final ImmutableMap getChangedTextColorWords() { @@ -4663,8 +2994,8 @@ public class Card extends GameEntity implements Comparable, IIdentifiable * one. The original changes of this Card are removed. */ public final void copyChangedTextFrom(final Card other) { - this.changedTextColors.copyFrom(other.changedTextColors); - this.changedTextTypes.copyFrom(other.changedTextTypes); + changedTextColors.copyFrom(other.changedTextColors); + changedTextTypes.copyFrom(other.changedTextTypes); } /** @@ -4677,175 +3008,84 @@ public class Card extends GameEntity implements Comparable, IIdentifiable */ public final void changeSVar(final String key, final String value) { originalSVars.put(key, getSVar(key)); - this.setSVar(key, value); + setSVar(key, value); } private void resetChangedSVars() { for (final Entry svar : originalSVars.entrySet()) { - this.setSVar(svar.getKey(), svar.getValue()); + setSVar(svar.getKey(), svar.getValue()); } originalSVars.clear(); } - /** - *

- * getIntrinsicAbilities. - *

- * - * @return a {@link java.util.ArrayList} object. - */ public final List getUnparsedAbilities() { - return this.getCharacteristics().getUnparsedAbilities(); + return getCharacteristics().getUnparsedAbilities(); } - /** - *

- * Getter for the field intrinsicKeyword. - *

- * - * @return a {@link java.util.ArrayList} object. - */ public final List getIntrinsicKeyword() { // will not create a copy here - due to performance reasons. // Most of other code checks for contains, or creates copy by itself - return this.getCharacteristics().getIntrinsicKeyword(); + return getCharacteristics().getIntrinsicKeyword(); } - /** - *

- * setIntrinsicAbilities. - *

- * - * @param a - * a {@link java.util.ArrayList} object. - */ public final void setIntrinsicAbilities(final List a) { - this.getCharacteristics().setUnparsedAbilities(new ArrayList(a)); + getCharacteristics().setUnparsedAbilities(new ArrayList(a)); } - /** - *

- * addIntrinsicKeyword. - *

- * - * @param s - * a {@link java.lang.String} object. - */ public final void addIntrinsicKeyword(final String s) { if (s.trim().length() != 0) { - this.getCharacteristics().getIntrinsicKeyword().add(s); + getCharacteristics().getIntrinsicKeyword().add(s); } } - /** - *

- * addIntrinsicAbility. - *

- * - * @param s - * a {@link java.lang.String} object. - */ public final void addIntrinsicAbility(final String s) { if (s.trim().length() != 0) { - this.getCharacteristics().getUnparsedAbilities().add(s); + getCharacteristics().getUnparsedAbilities().add(s); } } - /** - *

- * removeIntrinsicKeyword. - *

- * - * @param s - * a {@link java.lang.String} object. - */ public final void removeIntrinsicKeyword(final String s) { - this.getCharacteristics().getIntrinsicKeyword().remove(s); + getCharacteristics().getIntrinsicKeyword().remove(s); } - - /** - *

- * Getter for the field extrinsicKeyword. - *

- * - * @return a {@link java.util.ArrayList} object. - */ public ArrayList getExtrinsicKeyword() { - return this.extrinsicKeyword; + return extrinsicKeyword; } - - /** - *

- * Setter for the field extrinsicKeyword. - *

- * - * @param a - * a {@link java.util.ArrayList} object. - */ public final void setExtrinsicKeyword(final ArrayList a) { - this.extrinsicKeyword = new ArrayList(a); + extrinsicKeyword = new ArrayList(a); } - /** - *

- * addExtrinsicKeyword. - *

- * - * @param s - * a {@link java.lang.String} object. - */ public void addExtrinsicKeyword(final String s) { if (s.startsWith("HIDDEN")) { - this.addHiddenExtrinsicKeyword(s); - } else { - this.extrinsicKeyword.add(s); + addHiddenExtrinsicKeyword(s); + } + else { + extrinsicKeyword.add(s); } } - /** - *

- * removeExtrinsicKeyword. - *

- * - * @param s - * a {@link java.lang.String} object. - */ public void removeExtrinsicKeyword(final String s) { if (s.startsWith("HIDDEN")) { - this.removeHiddenExtrinsicKeyword(s); - } else { - this.extrinsicKeyword.remove(s); + removeHiddenExtrinsicKeyword(s); + } + else { + extrinsicKeyword.remove(s); } } - /** - * Removes the all extrinsic keyword. - * - * @param s - * the s - */ public void removeAllExtrinsicKeyword(final String s) { final ArrayList strings = new ArrayList(); strings.add(s); - this.hiddenExtrinsicKeyword.removeAll(strings); - this.extrinsicKeyword.removeAll(strings); + hiddenExtrinsicKeyword.removeAll(strings); + extrinsicKeyword.removeAll(strings); } - // Hidden Keywords will be returned without the indicator HIDDEN - /** - *

- * getHiddenExtrinsicKeyword. - *

- * - * @return a {@link java.util.ArrayList} object. - */ public final ArrayList getHiddenExtrinsicKeyword() { while (true) { try { final ArrayList keywords = new ArrayList(); - for (String keyword : this.hiddenExtrinsicKeyword) { + for (String keyword : hiddenExtrinsicKeyword) { if (keyword == null) { continue; } @@ -4861,40 +3101,17 @@ public class Card extends GameEntity implements Comparable, IIdentifiable } } - /** - *

- * addHiddenExtrinsicKeyword. - *

- * - * @param s - * a {@link java.lang.String} object. - */ public final void addHiddenExtrinsicKeyword(final String s) { - this.hiddenExtrinsicKeyword.add(s); + hiddenExtrinsicKeyword.add(s); } - /** - *

- * removeHiddenExtrinsicKeyword. - *

- * - * @param s - * a {@link java.lang.String} object. - */ public final void removeHiddenExtrinsicKeyword(final String s) { - this.hiddenExtrinsicKeyword.remove(s); + hiddenExtrinsicKeyword.remove(s); } - /** - *

- * getCantHaveOrGainKeyword. - *

- * - * @return a {@link java.util.ArrayList} object. - */ public final List getCantHaveOrGainKeyword() { final List cantGain = new ArrayList(); - for (String s : this.hiddenExtrinsicKeyword) { + for (String s : hiddenExtrinsicKeyword) { if (s.contains("can't have or gain")) { cantGain.add(s.split("can't have or gain ")[1]); } @@ -4902,107 +3119,66 @@ public class Card extends GameEntity implements Comparable, IIdentifiable return cantGain; } - /** - *

- * setStaticAbilityStrings. - *

- * - * @param a - * a {@link java.util.ArrayList} object. - */ public final void setStaticAbilityStrings(final List a) { - this.getCharacteristics().setStaticAbilityStrings(new ArrayList(a)); + getCharacteristics().setStaticAbilityStrings(new ArrayList(a)); } - /** - * Gets the static ability strings. - * - * @return the static ability strings - */ public final List getStaticAbilityStrings() { - return this.getCharacteristics().getStaticAbilityStrings(); + return getCharacteristics().getStaticAbilityStrings(); + } + public final void setStaticAbilities(final ArrayList a) { + getCharacteristics().setStaticAbilities(new ArrayList(a)); } - - /** - *

- * addStaticAbilityStrings. - *

- * - * @param s - * a {@link java.lang.String} object. - */ public final void addStaticAbilityString(final String s) { if (StringUtils.isNotBlank(s)) { - this.getCharacteristics().getStaticAbilityStrings().add(s); + getCharacteristics().getStaticAbilityStrings().add(s); } } - /** - * Sets the static abilities. - * - * @param a - * the new static abilities - */ - public final void setStaticAbilities(final ArrayList a) { - this.getCharacteristics().setStaticAbilities(new ArrayList(a)); - } - - /** - * Gets the static abilities. - * - * @return the static abilities - */ public final ArrayList getStaticAbilities() { - return new ArrayList(this.getCharacteristics().getStaticAbilities()); + return new ArrayList(getCharacteristics().getStaticAbilities()); } - - /** - * Adds the static ability. - * - * @param s - * the s - */ public final StaticAbility addStaticAbility(final String s) { if (s.trim().length() != 0) { final StaticAbility stAb = new StaticAbility(s, this); - this.getCharacteristics().getStaticAbilities().add(stAb); + getCharacteristics().getStaticAbilities().add(stAb); return stAb; } return null; } public final boolean isPermanent() { - return !(this.isInstant() || this.isSorcery() || this.isImmutable()); + return !(isInstant() || isSorcery() || isImmutable()); } public final boolean isSpell() { - return (this.isInstant() || this.isSorcery() || (this.isAura() && !this.isInZone((ZoneType.Battlefield)))); + return (isInstant() || isSorcery() || (isAura() && !isInZone((ZoneType.Battlefield)))); } - public final boolean isEmblem() { return this.typeContains("Emblem"); } + public final boolean isEmblem() { return typeContains("Emblem"); } - public final boolean isLand() { return this.typeContains("Land"); } - public final boolean isBasicLand() { return this.typeContains("Basic"); } - public final boolean isSnow() { return this.typeContains("Snow"); } + public final boolean isLand() { return typeContains("Land"); } + public final boolean isBasicLand() { return typeContains("Basic"); } + public final boolean isSnow() { return typeContains("Snow"); } - public final boolean isTribal() { return this.typeContains("Tribal"); } - public final boolean isSorcery() { return this.typeContains("Sorcery"); } - public final boolean isInstant() { return this.typeContains("Instant"); } + public final boolean isTribal() { return typeContains("Tribal"); } + public final boolean isSorcery() { return typeContains("Sorcery"); } + public final boolean isInstant() { return typeContains("Instant"); } - public final boolean isCreature() { return this.typeContains("Creature"); } - public final boolean isArtifact() { return this.typeContains("Artifact"); } - public final boolean isEquipment() { return this.typeContains("Equipment"); } - public final boolean isFortification() { return this.typeContains("Fortification"); } - public final boolean isPlaneswalker() { return this.typeContains("Planeswalker"); } - public final boolean isEnchantment() { return this.typeContains("Enchantment"); } - public final boolean isAura() { return this.typeContains("Aura"); } + public final boolean isCreature() { return typeContains("Creature"); } + public final boolean isArtifact() { return typeContains("Artifact"); } + public final boolean isEquipment() { return typeContains("Equipment"); } + public final boolean isFortification() { return typeContains("Fortification"); } + public final boolean isPlaneswalker() { return typeContains("Planeswalker"); } + public final boolean isEnchantment() { return typeContains("Enchantment"); } + public final boolean isAura() { return typeContains("Aura"); } - public final boolean isScheme() { return this.typeContains("Scheme"); } - public final boolean isPhenomenon() { return this.typeContains("Phenomenon"); } - public final boolean isPlane() { return this.typeContains("Plane"); } + public final boolean isScheme() { return typeContains("Scheme"); } + public final boolean isPhenomenon() { return typeContains("Phenomenon"); } + public final boolean isPlane() { return typeContains("Plane"); } private boolean typeContains(final String s) { - final Iterator it = this.getType().iterator(); + final Iterator it = getType().iterator(); while (it.hasNext()) { if (it.next().equals(s)) { return true; @@ -5012,20 +3188,9 @@ public class Card extends GameEntity implements Comparable, IIdentifiable return false; } - /** - *

- * Getter for the field uniqueNumber. - *

- * - * @return a int. - */ - public final int getUniqueNumber() { - return this.uniqueNumber; - } - @Override public int getId() { - return getUniqueNumber(); + return id; } /** {@inheritDoc} */ @@ -5044,9 +3209,9 @@ public class Card extends GameEntity implements Comparable, IIdentifiable * of null as being lowly." --Braids */ return +1; - } else if (this.getUniqueNumber() > that.getUniqueNumber()) { + } else if (id > that.id) { return +1; - } else if (this.getUniqueNumber() < that.getUniqueNumber()) { + } else if (id < that.id) { return -1; } else { return 0; @@ -5058,8 +3223,8 @@ public class Card extends GameEntity implements Comparable, IIdentifiable public final boolean equals(final Object o) { if (o instanceof Card) { final Card c = (Card) o; - final int a = this.getUniqueNumber(); - final int b = c.getUniqueNumber(); + final int a = id; + final int b = c.id; return (a == b); } return false; @@ -5068,192 +3233,108 @@ public class Card extends GameEntity implements Comparable, IIdentifiable /** {@inheritDoc} */ @Override public final int hashCode() { - return this.getUniqueNumber(); + return id; } /** {@inheritDoc} */ @Override public final String toString() { - return this.getName() + " (" + this.getUniqueNumber() + ")"; + return getName() + " (" + id + ")"; } - /** - *

- * isUnearthed. - *

- * - * @return a boolean. - */ public final boolean isUnearthed() { - return this.unearthed; + return unearthed; } - - /** - *

- * Setter for the field unearthed. - *

- * - * @param b - * a boolean. - */ public final void setUnearthed(final boolean b) { - this.unearthed = b; + unearthed = b; } - /** - *

- * Getter for the field miracleCost. - *

- * - * @return a {@link java.lang.String} object. - */ public final Cost getMiracleCost() { - return this.miracleCost; + return miracleCost; } - - /** - *

- * Setter for the field miracleCost. - *

- * - * @param cost - * a {@link java.lang.String} object. - */ public final void setMiracleCost(final Cost cost) { - this.miracleCost = cost; + miracleCost = cost; } - /** - *

- * hasSuspend. - *

- * - * @return a boolean. - */ public final boolean hasSuspend() { - return this.suspend; + return suspend; } - - /** - *

- * Setter for the field suspend. - *

- * - * @param b - * a boolean. - */ public final void setSuspend(final boolean b) { - this.suspend = b; + suspend = b; } - /** - *

- * wasSuspendCast. - *

- * - * @return a boolean. - */ public final boolean wasSuspendCast() { - return this.suspendCast; + return suspendCast; } - - /** - *

- * Setter for the field suspendCast. - *

- * - * @param b - * a boolean. - */ public final void setSuspendCast(final boolean b) { - this.suspendCast = b; + suspendCast = b; } - /** - * Checks if is phased out. - * - * @return true, if is phased out - */ public final boolean isPhasedOut() { - return this.phasedOut; + return phasedOut; + } + public final void setPhasedOut(final boolean phasedOut0) { + if (phasedOut == phasedOut0) { return; } + phasedOut = phasedOut0; + view.updatePhasedOut(this); } - /** - * Sets the phased out. - * - * @param phasedOut - * the new phased out - */ - public final void setPhasedOut(final boolean phasedOut) { - this.phasedOut = phasedOut; - } - - /** - * Phase. - */ public final void phase() { - this.phase(true); + phase(true); } - - /** - * Phase. - * - * @param direct - * the direct - */ public final void phase(final boolean direct) { - final boolean phasingIn = this.isPhasedOut(); + final boolean phasingIn = isPhasedOut(); - if (!this.switchPhaseState()) { + if (!switchPhaseState()) { // Switch Phase State bails early if the Permanent can't Phase Out return; } if (!phasingIn) { - this.setDirectlyPhasedOut(direct); + setDirectlyPhasedOut(direct); } - for (final Card eq : this.getEquippedBy()) { + for (final Card eq : getEquippedBy()) { if (eq.isPhasedOut() == phasingIn) { eq.phase(false); } } - for (final Card f : this.getFortifiedBy()) { + for (final Card f : getFortifiedBy()) { if (f.isPhasedOut() == phasingIn) { f.phase(false); } } - for (final Card aura : this.getEnchantedBy()) { + for (final Card aura : getEnchantedBy()) { if (aura.isPhasedOut() == phasingIn) { aura.phase(false); } } - this.getGame().fireEvent(new GameEventCardPhased(this, this.isPhasedOut())); + getGame().fireEvent(new GameEventCardPhased(this, isPhasedOut())); } private boolean switchPhaseState() { - if (!this.phasedOut && this.hasKeyword("CARDNAME can't phase out.")) { + if (!phasedOut && hasKeyword("CARDNAME can't phase out.")) { return false; } final Map runParams = new TreeMap(); runParams.put("Card", this); - if (!this.isPhasedOut()) { + if (!isPhasedOut()) { // If this is currently PhasedIn, it's about to phase out. // Run trigger before it does because triggers don't work with phased out objects getGame().getTriggerHandler().runTrigger(TriggerType.PhaseOut, runParams, false); } - this.phasedOut = !this.phasedOut; - final Combat combat = this.getGame().getPhaseHandler().getCombat(); - if (combat != null && this.phasedOut) { + setPhasedOut(!phasedOut); + final Combat combat = getGame().getPhaseHandler().getCombat(); + if (combat != null && phasedOut) { combat.removeFromCombat(this); } - if (this.phasedOut && this.isToken()) { + if (phasedOut && isToken()) { // 702.23k Phased-out tokens cease to exist as a state-based action. // See rule 704.5d. // 702.23d The phasing event doesn't actually cause a permanent to @@ -5266,11 +3347,11 @@ public class Card extends GameEntity implements Comparable, IIdentifiable // Just remove it's zone, so we don't run through the exile stuff // This allows auras on phased out tokens to just phase out permanently getGame().getTriggerHandler().suppressMode(TriggerType.ChangesZone); - this.getZone().remove(this); + getZone().remove(this); getGame().getTriggerHandler().clearSuppression(TriggerType.ChangesZone); } - if (!this.phasedOut) { + if (!phasedOut) { // Just phased in, time to run the phased in trigger getGame().getTriggerHandler().registerActiveTrigger(this, false); getGame().getTriggerHandler().runTrigger(TriggerType.PhaseIn, runParams, false); @@ -5279,71 +3360,33 @@ public class Card extends GameEntity implements Comparable, IIdentifiable return true; } - /** - * Checks if is directly phased out. - * - * @return true, if is directly phased out - */ public final boolean isDirectlyPhasedOut() { - return this.directlyPhasedOut; + return directlyPhasedOut; } - - /** - * Sets the directly phased out. - * - * @param direct - * the new directly phased out - */ public final void setDirectlyPhasedOut(final boolean direct) { - this.directlyPhasedOut = direct; + directlyPhasedOut = direct; } - /** - *

- * isReflectedLand. - *

- * - * @return a boolean. - */ public final boolean isReflectedLand() { - for (final SpellAbility a : this.getCharacteristics().getManaAbility()) { + for (final SpellAbility a : getCharacteristics().getManaAbility()) { if (a.getApi() == ApiType.ManaReflected) { return true; } } - return false; } - /** - *

- * hasKeyword. - *

- * - * @param keyword - * a {@link java.lang.String} object. - * @return a boolean. - */ @Override public final boolean hasKeyword(final String keyword) { String kw = keyword; if (kw.startsWith("HIDDEN")) { kw = kw.substring(7); } - return this.getKeyword().contains(kw); + return getKeyword().contains(kw); } - /** - *

- * hasStartOfKeyword. - *

- * - * @param keyword - * a {@link java.lang.String} object. - * @return a boolean. - */ public final boolean hasStartOfKeyword(final String keyword) { - final List a = this.getKeyword(); + final List a = getKeyword(); for (int i = 0; i < a.size(); i++) { if (a.get(i).toString().startsWith(keyword)) { return true; @@ -5352,17 +3395,8 @@ public class Card extends GameEntity implements Comparable, IIdentifiable return false; } - /** - *

- * hasStartOfKeyword. - *

- * - * @param keyword - * a {@link java.lang.String} object. - * @return a boolean. - */ public final boolean hasStartOfUnHiddenKeyword(final String keyword) { - final List a = this.getUnhiddenKeyword(); + final List a = getUnhiddenKeyword(); for (int i = 0; i < a.size(); i++) { if (a.get(i).toString().startsWith(keyword)) { return true; @@ -5371,17 +3405,8 @@ public class Card extends GameEntity implements Comparable, IIdentifiable return false; } - /** - *

- * getKeywordPosition. - *

- * - * @param k - * a {@link java.lang.String} object. - * @return a int. - */ public final int getKeywordPosition(final String k) { - final List a = this.getKeyword(); + final List a = getKeyword(); for (int i = 0; i < a.size(); i++) { if (a.get(i).toString().startsWith(k)) { return i; @@ -5390,18 +3415,9 @@ public class Card extends GameEntity implements Comparable, IIdentifiable return -1; } - /** - *

- * hasAnyKeyword. - *

- * - * @param keywords - * an array of {@link java.lang.String} objects. - * @return a boolean. - */ public final boolean hasAnyKeyword(final Iterable keywords) { for (final String keyword : keywords) { - if (this.hasKeyword(keyword)) { + if (hasKeyword(keyword)) { return true; } } @@ -5410,18 +3426,9 @@ public class Card extends GameEntity implements Comparable, IIdentifiable } // This counts the number of instances of a keyword a card has - /** - *

- * getAmountOfKeyword. - *

- * - * @param k - * a {@link java.lang.String} object. - * @return a int. - */ public final int getAmountOfKeyword(final String k) { int count = 0; - for (String kw : this.getKeyword()) { + for (String kw : getKeyword()) { if (kw.equals(k)) { count++; } @@ -5432,18 +3439,9 @@ public class Card extends GameEntity implements Comparable, IIdentifiable // This is for keywords with a number like Bushido, Annihilator and Rampage. // It returns the total. - /** - *

- * getKeywordMagnitude. - *

- * - * @param k - * a {@link java.lang.String} object. - * @return a int. - */ public final int getKeywordMagnitude(final String k) { int count = 0; - for (final String kw : this.getKeyword()) { + for (final String kw : getKeyword()) { if (kw.startsWith(k)) { final String[] parse = kw.split(" "); final String s = parse[1]; @@ -5467,53 +3465,30 @@ public class Card extends GameEntity implements Comparable, IIdentifiable sb.append(types[i].substring(0, 1).toUpperCase()); sb.append(types[i].substring(1).toLowerCase()); } - return sb.toString(); } // usable to check for changelings - /** - *

- * isType. - *

- * - * @param type - * a {@link java.lang.String} object. - * @return a boolean. - */ public final boolean isType(String type) { if (type == null) { return false; } - type = this.toMixedCase(type); + type = toMixedCase(type); - if (this.typeContains(type) - || ((this.isCreature() || this.isTribal()) && forge.card.CardType.isACreatureType(type) && this + if (typeContains(type) + || ((isCreature() || isTribal()) && forge.card.CardType.isACreatureType(type) && this .typeContains("AllCreatureTypes"))) { return true; } return false; - } // isType + } // Takes one argument like Permanent.Blue+withFlying - /** - *

- * isValid. - *

- * - * @param restriction - * a {@link java.lang.String} object. - * @param sourceController - * a {@link forge.game.player.Player} object. - * @param source - * a {@link forge.game.card.Card} object. - * @return a boolean. - */ @Override public final boolean isValid(final String restriction, final Player sourceController, final Card source) { - if (this.isImmutable() + if (isImmutable() && !source.getRemembered().contains(this)) { // special case exclusion return false; } @@ -5527,14 +3502,14 @@ public class Card extends GameEntity implements Comparable, IIdentifiable incR[0] = incR[0].substring(1); // consume negation sign } - if (incR[0].equals("Spell") && !this.isSpell()) { + if (incR[0].equals("Spell") && !isSpell()) { return testFailed; } - if (incR[0].equals("Permanent") && (this.isInstant() || this.isSorcery())) { + if (incR[0].equals("Permanent") && (isInstant() || isSorcery())) { return testFailed; } if (!incR[0].equals("card") && !incR[0].equals("Card") && !incR[0].equals("Spell") - && !incR[0].equals("Permanent") && !(this.isType(incR[0]))) { + && !incR[0].equals("Permanent") && !(isType(incR[0]))) { return testFailed; // Check for wrong type } @@ -5542,47 +3517,34 @@ public class Card extends GameEntity implements Comparable, IIdentifiable final String excR = incR[1]; final String[] exR = excR.split("\\+"); // Exclusive Restrictions are ... for (int j = 0; j < exR.length; j++) { - if (!this.hasProperty(exR[j], sourceController, source)) { + if (!hasProperty(exR[j], sourceController, source)) { return testFailed; } } } return !testFailed; - } // isValid(String Restriction) + } // Takes arguments like Blue or withFlying - /** - *

- * hasProperty. - *

- * - * @param property - * a {@link java.lang.String} object. - * @param sourceController - * a {@link forge.game.player.Player} object. - * @param source - * a {@link forge.game.card.Card} object. - * @return a boolean. - */ @Override public boolean hasProperty(final String property, final Player sourceController, final Card source) { final Game game = getGame(); final Combat combat = game.getCombat(); // by name can also have color names, so needs to happen before colors. if (property.startsWith("named")) { - if (!this.getName().equals(property.substring(5))) { + if (!getName().equals(property.substring(5))) { return false; } } else if (property.startsWith("notnamed")) { - if (this.getName().equals(property.substring(8))) { + if (getName().equals(property.substring(8))) { return false; } } else if (property.startsWith("sameName")) { - if (!this.getName().equals(source.getName())) { + if (!getName().equals(source.getName())) { return false; } } else if (property.equals("NamedCard")) { - if (!this.getName().equals(source.getNamedCard())) { + if (!getName().equals(source.getNamedCard())) { return false; } } else if (property.equals("NamedByRememberedPlayer")) { @@ -5590,7 +3552,7 @@ public class Card extends GameEntity implements Comparable, IIdentifiable final Card newCard = game.getCardState(source); for (final Object o : newCard.getRemembered()) { if (o instanceof Player) { - if (!this.getName().equals(((Player) o).getNamedCard())) { + if (!getName().equals(((Player) o).getNamedCard())) { return false; } } @@ -5598,17 +3560,17 @@ public class Card extends GameEntity implements Comparable, IIdentifiable } for (final Object o : source.getRemembered()) { if (o instanceof Player) { - if (!this.getName().equals(((Player) o).getNamedCard())) { + if (!getName().equals(((Player) o).getNamedCard())) { return false; } } } } else if (property.equals("Permanent")) { - if (this.isInstant() || this.isSorcery()) { + if (isInstant() || isSorcery()) { return false; } } else if (property.startsWith("CardUID_")) {// Protection with "doesn't remove effect" - if (this.getUniqueNumber() != Integer.parseInt(property.split("CardUID_")[1])) { + if (id != Integer.parseInt(property.split("CardUID_")[1])) { return false; } } else if (property.equals("ChosenCard")) { @@ -5639,39 +3601,39 @@ public class Card extends GameEntity implements Comparable, IIdentifiable if (property.startsWith("non") == CardUtil.getColors(this).isMonoColor()) return false; } else if (property.equals("ChosenColor")) { - if (source.getChosenColor().isEmpty() || !CardUtil.getColors(this).hasAnyColor(MagicColor.fromName(source.getChosenColor().get(0)))) + if (source.getChosenColors().isEmpty() || !CardUtil.getColors(this).hasAnyColor(MagicColor.fromName(source.getChosenColors().get(0)))) return false; } else if (property.equals("AllChosenColors")) { - if (source.getChosenColor().isEmpty() || !CardUtil.getColors(this).hasAllColors(ColorSet.fromNames(source.getChosenColor()).getColor())) + if (source.getChosenColors().isEmpty() || !CardUtil.getColors(this).hasAllColors(ColorSet.fromNames(source.getChosenColors()).getColor())) return false; } else if (property.equals("AnyChosenColor")) { - if (source.getChosenColor().isEmpty() || !CardUtil.getColors(this).hasAnyColor(ColorSet.fromNames(source.getChosenColor()).getColor())) + if (source.getChosenColors().isEmpty() || !CardUtil.getColors(this).hasAnyColor(ColorSet.fromNames(source.getChosenColors()).getColor())) return false; } else if (property.equals("DoubleFaced")) { - if (!this.isDoubleFaced()) { + if (!isDoubleFaced()) { return false; } } else if (property.equals("Flip")) { - if (!this.isFlipCard()) { + if (!isFlipCard()) { return false; } } else if (property.startsWith("YouCtrl")) { - if (!this.getController().equals(sourceController)) { + if (!getController().equals(sourceController)) { return false; } } else if (property.startsWith("YouDontCtrl")) { - if (this.getController().equals(sourceController)) { + if (getController().equals(sourceController)) { return false; } } else if (property.startsWith("OppCtrl")) { - if (!this.getController().getOpponents().contains(sourceController)) { + if (!getController().getOpponents().contains(sourceController)) { return false; } } else if (property.startsWith("ChosenCtrl")) { - if (!this.getController().equals(source.getChosenPlayer())) { + if (!getController().equals(source.getChosenPlayer())) { return false; } } else if (property.startsWith("DefenderCtrl")) { @@ -5683,11 +3645,11 @@ public class Card extends GameEntity implements Comparable, IIdentifiable return false; } if (getGame().getCombat().getDefendingPlayerRelatedTo((Card) source.getRemembered().get(0)) - != this.getController()) { + != getController()) { return false; } } else { - if (getGame().getCombat().getDefendingPlayerRelatedTo(source) != this.getController()) { + if (getGame().getCombat().getDefendingPlayerRelatedTo(source) != getController()) { return false; } } @@ -5695,13 +3657,13 @@ public class Card extends GameEntity implements Comparable, IIdentifiable if (!game.getPhaseHandler().inCombat()) { return false; } - if (!getGame().getCombat().isPlayerAttacked(this.getController())) { + if (!getGame().getCombat().isPlayerAttacked(getController())) { return false; } } else if (property.startsWith("EnchantedPlayerCtrl")) { final Object o = source.getEnchanting(); if (o instanceof Player) { - if (!this.getController().equals(o)) { + if (!getController().equals(o)) { return false; } } else { // source not enchanting a player @@ -5710,14 +3672,14 @@ public class Card extends GameEntity implements Comparable, IIdentifiable } else if (property.startsWith("EnchantedControllerCtrl")) { final Object o = source.getEnchanting(); if (o instanceof Card) { - if (!this.getController().equals(((Card) o).getController())) { + if (!getController().equals(((Card) o).getController())) { return false; } } else { // source not enchanting a card return false; } } else if (property.startsWith("RememberedPlayer")) { - Player p = property.endsWith("Ctrl") ? this.getController() : this.getOwner(); + Player p = property.endsWith("Ctrl") ? getController() : getOwner(); if (source.getRemembered().isEmpty()) { final Card newCard = game.getCardState(source); for (final Object o : newCard.getRemembered()) { @@ -5739,12 +3701,12 @@ public class Card extends GameEntity implements Comparable, IIdentifiable } else if (property.startsWith("nonRememberedPlayerCtrl")) { if (source.getRemembered().isEmpty()) { final Card newCard = game.getCardState(source); - if (newCard.getRemembered().contains(this.getController())) { + if (newCard.getRemembered().contains(getController())) { return false; } } - if (source.getRemembered().contains(this.getController())) { + if (source.getRemembered().contains(getController())) { return false; } } else if (property.equals("TargetedPlayerCtrl")) { @@ -5752,7 +3714,7 @@ public class Card extends GameEntity implements Comparable, IIdentifiable final SpellAbility saTargeting = sa.getSATargetingPlayer(); if (saTargeting != null) { for (final Player p : saTargeting.getTargets().getTargetPlayers()) { - if (!this.getController().equals(p)) { + if (!getController().equals(p)) { return false; } } @@ -5764,35 +3726,35 @@ public class Card extends GameEntity implements Comparable, IIdentifiable final List sas = AbilityUtils.getDefinedSpellAbilities(source, "Targeted", sa); for (final Card c : list) { final Player p = c.getController(); - if (!this.getController().equals(p)) { + if (!getController().equals(p)) { return false; } } for (final SpellAbility s : sas) { final Player p = s.getHostCard().getController(); - if (!this.getController().equals(p)) { + if (!getController().equals(p)) { return false; } } } } else if (property.startsWith("ActivePlayerCtrl")) { - if (!game.getPhaseHandler().isPlayerTurn(this.getController())) { + if (!game.getPhaseHandler().isPlayerTurn(getController())) { return false; } } else if (property.startsWith("NonActivePlayerCtrl")) { - if (game.getPhaseHandler().isPlayerTurn(this.getController())) { + if (game.getPhaseHandler().isPlayerTurn(getController())) { return false; } } else if (property.startsWith("YouOwn")) { - if (!this.getOwner().equals(sourceController)) { + if (!getOwner().equals(sourceController)) { return false; } } else if (property.startsWith("YouDontOwn")) { - if (this.getOwner().equals(sourceController)) { + if (getOwner().equals(sourceController)) { return false; } } else if (property.startsWith("OppOwn")) { - if (!this.getOwner().getOpponents().contains(sourceController)) { + if (!getOwner().getOpponents().contains(sourceController)) { return false; } } else if (property.equals("TargetedPlayerOwn")) { @@ -5800,7 +3762,7 @@ public class Card extends GameEntity implements Comparable, IIdentifiable final SpellAbility saTargeting = sa.getSATargetingPlayer(); if (saTargeting != null) { for (final Player p : saTargeting.getTargets().getTargetPlayers()) { - if (!this.getOwner().equals(p)) { + if (!getOwner().equals(p)) { return false; } } @@ -5808,42 +3770,42 @@ public class Card extends GameEntity implements Comparable, IIdentifiable } } else if (property.startsWith("OwnedBy")) { final String valid = property.substring(8); - if (!this.getOwner().isValid(valid, sourceController, source)) { + if (!getOwner().isValid(valid, sourceController, source)) { return false; } } else if (property.startsWith("OwnerDoesntControl")) { - if (this.getOwner().equals(this.getController())) { + if (getOwner().equals(getController())) { return false; } } else if (property.startsWith("ControllerControls")) { final String type = property.substring(18); if (type.startsWith("AtLeastAsMany")) { String realType = type.split("AtLeastAsMany")[1]; - List list = CardLists.getType(this.getController().getCardsIn(ZoneType.Battlefield), realType); + List list = CardLists.getType(getController().getCardsIn(ZoneType.Battlefield), realType); List yours = CardLists.getType(sourceController.getCardsIn(ZoneType.Battlefield), realType); if (list.size() < yours.size()) { return false; } } else { - final List list = this.getController().getCardsIn(ZoneType.Battlefield); + final List list = getController().getCardsIn(ZoneType.Battlefield); if (CardLists.getType(list, type).isEmpty()) { return false; } } } else if (property.startsWith("Other")) { - if (this.equals(source)) { + if (equals(source)) { return false; } } else if (property.startsWith("Self")) { - if (!this.equals(source)) { + if (!equals(source)) { return false; } } else if (property.startsWith("AttachedBy")) { - if (!this.equippedBy.contains(source) && !this.getEnchantedBy().contains(source) && !this.getFortifiedBy().contains(source)) { + if (!equippedBy.contains(source) && !getEnchantedBy().contains(source) && !getFortifiedBy().contains(source)) { return false; } } else if (property.equals("Attached")) { - if (!this.equipping.contains(source) && !source.equals(this.enchanting) && !this.fortifying.contains(source)) { + if (equipping != source && !source.equals(enchanting) && fortifying != source) { return false; } } else if (property.startsWith("AttachedTo")) { @@ -5854,7 +3816,7 @@ public class Card extends GameEntity implements Comparable, IIdentifiable final SpellAbility sa = t.getTriggeredSA(); final List list = AbilityUtils.getDefinedCards(source, "Targeted", sa); for (final Card c : list) { - if (!this.equipping.contains(c) && !c.equals(this.enchanting)) { + if (equipping != c && !c.equals(enchanting)) { return false; } } @@ -5863,7 +3825,7 @@ public class Card extends GameEntity implements Comparable, IIdentifiable for (final SpellAbility sa : source.getCharacteristics().getSpellAbility()) { final List list = AbilityUtils.getDefinedCards(source, "Targeted", sa); for (final Card c : list) { - if (this.equipping.contains(c) || c.equals(this.enchanting)) { // handle multiple targets + if (equipping == c || c.equals(enchanting)) { // handle multiple targets return true; } } @@ -5871,9 +3833,9 @@ public class Card extends GameEntity implements Comparable, IIdentifiable return false; } } else { - if (((this.enchanting == null) || !this.enchanting.isValid(restriction, sourceController, source)) - && (this.equipping.isEmpty() || !this.equipping.get(0).isValid(restriction, sourceController, source)) - && (this.fortifying.isEmpty() || !this.fortifying.get(0).isValid(restriction, sourceController, source))) { + if ((enchanting == null || !enchanting.isValid(restriction, sourceController, source)) + && (equipping == null || !equipping.isValid(restriction, sourceController, source)) + && (fortifying == null || !fortifying.isValid(restriction, sourceController, source))) { return false; } } @@ -5885,24 +3847,24 @@ public class Card extends GameEntity implements Comparable, IIdentifiable List enchanting = enchantedPlayer.getEnchantedBy(); for (Card c : enchanting) { - if (this.getName().equals(c.getName())) { + if (getName().equals(c.getName())) { return false; } } } else if (property.equals("NotAttachedTo")) { - if (this.equipping.contains(source) || source.equals(this.enchanting) || this.fortifying.contains(source)) { + if (equipping == source || source.equals(enchanting) || fortifying == source) { return false; } } else if (property.startsWith("EnchantedBy")) { if (property.equals("EnchantedBy")) { - if (!this.getEnchantedBy().contains(source) && !this.equals(source.getEnchanting())) { + if (!getEnchantedBy().contains(source) && !equals(source.getEnchanting())) { return false; } } else { final String restriction = property.split("EnchantedBy ")[1]; if (restriction.equals("Imprinted")) { for (final Card card : source.getImprinted()) { - if (!this.getEnchantedBy().contains(card) && !this.equals(card.getEnchanting())) { + if (!getEnchantedBy().contains(card) && !equals(card.getEnchanting())) { return false; } } @@ -5911,14 +3873,14 @@ public class Card extends GameEntity implements Comparable, IIdentifiable final SpellAbility saTargeting = sa.getSATargetingCard(); if (saTargeting != null) { for (final Card c : saTargeting.getTargets().getTargetCards()) { - if (!this.getEnchantedBy().contains(c) && !this.equals(c.getEnchanting())) { + if (!getEnchantedBy().contains(c) && !equals(c.getEnchanting())) { return false; } } } } } else { // EnchantedBy Aura.Other - for (final Card aura : this.getEnchantedBy()){ + for (final Card aura : getEnchantedBy()){ if (aura.isValid(restriction, sourceController, source)) { return true; } @@ -5932,19 +3894,19 @@ public class Card extends GameEntity implements Comparable, IIdentifiable final SpellAbility saTargeting = sa.getSATargetingCard(); if (saTargeting != null) { for (final Card c : saTargeting.getTargets().getTargetCards()) { - if (this.getEnchantedBy().contains(c)) { + if (getEnchantedBy().contains(c)) { return false; } } } } } else { - if (this.getEnchantedBy().contains(source)) { + if (getEnchantedBy().contains(source)) { return false; } } } else if (property.startsWith("Enchanted")) { - if (!source.equals(this.enchanting)) { + if (!source.equals(enchanting)) { return false; } } else if (property.startsWith("CanEnchant")) { @@ -5963,7 +3925,7 @@ public class Card extends GameEntity implements Comparable, IIdentifiable final SpellAbility saTargeting = sa.getSATargetingCard(); if (saTargeting != null) { for (final Card c : saTargeting.getTargets().getTargetCards()) { - if (!this.canBeEnchantedBy(c)) { + if (!canBeEnchantedBy(c)) { return false; } } @@ -5973,13 +3935,13 @@ public class Card extends GameEntity implements Comparable, IIdentifiable for (final Object rem : source.getRemembered()) { if (rem instanceof Card) { final Card card = (Card) rem; - if (!this.canBeEnchantedBy(card)) { + if (!canBeEnchantedBy(card)) { return false; } } } } else { - if (!this.canBeEnchantedBy(source)) { + if (!canBeEnchantedBy(source)) { return false; } } @@ -5989,7 +3951,7 @@ public class Card extends GameEntity implements Comparable, IIdentifiable final SpellAbility saTargeting = sa.getSATargetingCard(); if (saTargeting != null) { for (final Card c : saTargeting.getTargets().getTargetCards()) { - if (!this.equippedBy.contains(c)) { + if (!equippedBy.contains(c)) { return false; } } @@ -5997,74 +3959,74 @@ public class Card extends GameEntity implements Comparable, IIdentifiable } } else if (property.substring(10).equals("Enchanted")) { if (source.getEnchantingCard() == null || - !this.equippedBy.contains(source.getEnchantingCard())) { + !equippedBy.contains(source.getEnchantingCard())) { return false; } } else { - if (!this.equippedBy.contains(source)) { + if (!equippedBy.contains(source)) { return false; } } } else if (property.startsWith("FortifiedBy")) { - if (!this.fortifiedBy.contains(source)) { + if (!fortifiedBy.contains(source)) { return false; } } else if (property.startsWith("CanBeEquippedBy")) { - if (!this.canBeEquippedBy(source)) { + if (!canBeEquippedBy(source)) { return false; } } else if (property.startsWith("Equipped")) { - if (!this.equipping.contains(source)) { + if (equipping != source) { return false; } } else if (property.startsWith("Fortified")) { - if (!this.fortifying.contains(source)) { + if (fortifying != source) { return false; } } else if (property.startsWith("HauntedBy")) { - if (!this.hauntedBy.contains(source)) { + if (!hauntedBy.contains(source)) { return false; } } else if (property.startsWith("notTributed")) { - if (this.tributed) { + if (tributed) { return false; } } else if (property.startsWith("madness")) { - if (!this.madness) { + if (!madness) { return false; } } else if (property.contains("Paired")) { if (property.contains("With")) { // PairedWith - if (!this.isPaired() || this.pairedWith != source) { + if (!isPaired() || pairedWith != source) { return false; } } else if (property.startsWith("Not")) { // NotPaired - if (this.isPaired()) { + if (isPaired()) { return false; } } else { // Paired - if (!this.isPaired()) { + if (!isPaired()) { return false; } } } else if (property.startsWith("Above")) { // "Are Above" Source - final List list = this.getOwner().getCardsIn(ZoneType.Graveyard); + final List list = getOwner().getCardsIn(ZoneType.Graveyard); if (list.indexOf(source) >= list.indexOf(this)) { return false; } } else if (property.startsWith("DirectlyAbove")) { // "Are Directly Above" Source - final List list = this.getOwner().getCardsIn(ZoneType.Graveyard); + final List list = getOwner().getCardsIn(ZoneType.Graveyard); if (list.indexOf(this) - list.indexOf(source) != 1) { return false; } } else if (property.startsWith("TopGraveyardCreature")) { - List list = CardLists.filter(this.getOwner().getCardsIn(ZoneType.Graveyard), CardPredicates.Presets.CREATURES); + List list = CardLists.filter(getOwner().getCardsIn(ZoneType.Graveyard), CardPredicates.Presets.CREATURES); Collections.reverse(list); - if (list.isEmpty() || !this.equals(list.get(0))) { + if (list.isEmpty() || !equals(list.get(0))) { return false; } } else if (property.startsWith("TopGraveyard")) { - final List list = new ArrayList(this.getOwner().getCardsIn(ZoneType.Graveyard)); + final List list = new ArrayList(getOwner().getCardsIn(ZoneType.Graveyard)); Collections.reverse(list); if (property.substring(12).matches("[0-9][0-9]?")) { int n = Integer.parseInt(property.substring(12)); @@ -6077,34 +4039,34 @@ public class Card extends GameEntity implements Comparable, IIdentifiable return false; } } else { - if (list.isEmpty() || !this.equals(list.get(0))) { + if (list.isEmpty() || !equals(list.get(0))) { return false; } } } else if (property.startsWith("BottomGraveyard")) { - final List list = this.getOwner().getCardsIn(ZoneType.Graveyard); - if (list.isEmpty() || !this.equals(list.get(0))) { + final List list = getOwner().getCardsIn(ZoneType.Graveyard); + if (list.isEmpty() || !equals(list.get(0))) { return false; } } else if (property.startsWith("TopLibrary")) { - final List list = this.getOwner().getCardsIn(ZoneType.Library); - if (list.isEmpty() || !this.equals(list.get(0))) { + final List list = getOwner().getCardsIn(ZoneType.Library); + if (list.isEmpty() || !equals(list.get(0))) { return false; } } else if (property.startsWith("Cloned")) { - if ((this.cloneOrigin == null) || !this.cloneOrigin.equals(source)) { + if ((cloneOrigin == null) || !cloneOrigin.equals(source)) { return false; } } else if (property.startsWith("DamagedBy")) { - if (!this.receivedDamageFromThisTurn.containsKey(source)) { + if (!receivedDamageFromThisTurn.containsKey(source)) { return false; } } else if (property.startsWith("Damaged")) { - if (!this.dealtDamageToThisTurn.containsKey(source)) { + if (!dealtDamageToThisTurn.containsKey(source)) { return false; } } else if (property.startsWith("IsTargetingSource")) { - for (final SpellAbility sa : this.getCharacteristics().getSpellAbility()) { + for (final SpellAbility sa : getCharacteristics().getSpellAbility()) { final SpellAbility saTargeting = sa.getSATargetingCard(); if (saTargeting != null) { for (final Card c : saTargeting.getTargets().getTargetCards()) { @@ -6117,31 +4079,31 @@ public class Card extends GameEntity implements Comparable, IIdentifiable return false; } else if (property.startsWith("SharesColorWith")) { if (property.equals("SharesColorWith")) { - if (!this.sharesColorWith(source)) { + if (!sharesColorWith(source)) { return false; } } else { final String restriction = property.split("SharesColorWith ")[1]; if (restriction.equals("TopCardOfLibrary")) { final List list = sourceController.getCardsIn(ZoneType.Library); - if (list.isEmpty() || !this.sharesColorWith(list.get(0))) { + if (list.isEmpty() || !sharesColorWith(list.get(0))) { return false; } } else if (restriction.equals("Remembered")) { for (final Object obj : source.getRemembered()) { - if (!(obj instanceof Card) || !this.sharesColorWith((Card) obj)) { + if (!(obj instanceof Card) || !sharesColorWith((Card) obj)) { return false; } } } else if (restriction.equals("Imprinted")) { for (final Card card : source.getImprinted()) { - if (!this.sharesColorWith(card)) { + if (!sharesColorWith(card)) { return false; } } } else if (restriction.equals("Equipped")) { if (!source.isEquipment() || !source.isEquipping() - || !this.sharesColorWith(source.getEquippingCard())) { + || !sharesColorWith(source.getEquipping())) { return false; } } else if (restriction.equals("MostProminentColor")) { @@ -6150,7 +4112,7 @@ public class Card extends GameEntity implements Comparable, IIdentifiable return false; } else if (restriction.equals("LastCastThisTurn")) { final List c = game.getStack().getCardsCastThisTurn(); - if (c.isEmpty() || !this.sharesColorWith(c.get(c.size() - 1))) { + if (c.isEmpty() || !sharesColorWith(c.get(c.size() - 1))) { return false; } } else if (restriction.equals("ActivationColor")) { @@ -6160,7 +4122,7 @@ public class Card extends GameEntity implements Comparable, IIdentifiable } } else { for (final Card card : sourceController.getCardsIn(ZoneType.Battlefield)) { - if (card.isValid(restriction, sourceController, source) && this.sharesColorWith(card)) { + if (card.isValid(restriction, sourceController, source) && sharesColorWith(card)) { return true; } } @@ -6181,27 +4143,27 @@ public class Card extends GameEntity implements Comparable, IIdentifiable return ColorSet.fromMask(mostProm).hasAnyColor(MagicColor.fromName(color)); } else if (property.startsWith("notSharesColorWith")) { if (property.equals("notSharesColorWith")) { - if (this.sharesColorWith(source)) { + if (sharesColorWith(source)) { return false; } } else { final String restriction = property.split("notSharesColorWith ")[1]; for (final Card card : sourceController.getCardsIn(ZoneType.Battlefield)) { - if (card.isValid(restriction, sourceController, source) && this.sharesColorWith(card)) { + if (card.isValid(restriction, sourceController, source) && sharesColorWith(card)) { return false; } } } } else if (property.startsWith("sharesCreatureTypeWith")) { if (property.equals("sharesCreatureTypeWith")) { - if (!this.sharesCreatureTypeWith(source)) { + if (!sharesCreatureTypeWith(source)) { return false; } } else { final String restriction = property.split("sharesCreatureTypeWith ")[1]; if (restriction.equals("TopCardOfLibrary")) { final List list = sourceController.getCardsIn(ZoneType.Library); - if (list.isEmpty() || !this.sharesCreatureTypeWith(list.get(0))) { + if (list.isEmpty() || !sharesCreatureTypeWith(list.get(0))) { return false; } } else if (restriction.equals("Enchanted")) { @@ -6212,13 +4174,13 @@ public class Card extends GameEntity implements Comparable, IIdentifiable && (root.getPaidList("Sacrificed") != null) && !root.getPaidList("Sacrificed").isEmpty()) { c = root.getPaidList("Sacrificed").get(0).getEnchantingCard(); - if (!this.sharesCreatureTypeWith(c)) { + if (!sharesCreatureTypeWith(c)) { return false; } } } } else if (restriction.equals("Equipped")) { - if (source.isEquipping() && this.sharesCreatureTypeWith(source.getEquippingCard())) { + if (source.isEquipping() && sharesCreatureTypeWith(source.getEquipping())) { return true; } return false; @@ -6226,7 +4188,7 @@ public class Card extends GameEntity implements Comparable, IIdentifiable for (final Object rem : source.getRemembered()) { if (rem instanceof Card) { final Card card = (Card) rem; - if (this.sharesCreatureTypeWith(card)) { + if (sharesCreatureTypeWith(card)) { return true; } } @@ -6236,7 +4198,7 @@ public class Card extends GameEntity implements Comparable, IIdentifiable for (final Object rem : source.getRemembered()) { if (rem instanceof Card) { final Card card = (Card) rem; - if (!this.sharesCreatureTypeWith(card)) { + if (!sharesCreatureTypeWith(card)) { return false; } } @@ -6244,7 +4206,7 @@ public class Card extends GameEntity implements Comparable, IIdentifiable } else { boolean shares = false; for (final Card card : sourceController.getCardsIn(ZoneType.Battlefield)) { - if (card.isValid(restriction, sourceController, source) && this.sharesCreatureTypeWith(card)) { + if (card.isValid(restriction, sourceController, source) && sharesCreatureTypeWith(card)) { shares = true; } } @@ -6255,20 +4217,20 @@ public class Card extends GameEntity implements Comparable, IIdentifiable } } else if (property.startsWith("sharesCardTypeWith")) { if (property.equals("sharesCardTypeWith")) { - if (!this.sharesCardTypeWith(source)) { + if (!sharesCardTypeWith(source)) { return false; } } else { final String restriction = property.split("sharesCardTypeWith ")[1]; if (restriction.equals("Imprinted")) { - if (source.getImprinted().isEmpty() || !this.sharesCardTypeWith(source.getImprinted().get(0))) { + if (source.getImprinted().isEmpty() || !sharesCardTypeWith(source.getImprinted().get(0))) { return false; } } else if (restriction.equals("Remembered")) { for (final Object rem : source.getRemembered()) { if (rem instanceof Card) { final Card card = (Card) rem; - if (this.sharesCardTypeWith(card)) { + if (sharesCardTypeWith(card)) { return true; } } @@ -6281,7 +4243,7 @@ public class Card extends GameEntity implements Comparable, IIdentifiable list.add(top); } for (Card c : list) { - if (this.sharesCardTypeWith(c)) { + if (sharesCardTypeWith(c)) { return true; } } @@ -6289,44 +4251,44 @@ public class Card extends GameEntity implements Comparable, IIdentifiable } } } else if (property.equals("sharesPermanentTypeWith")) { - if (!this.sharesPermanentTypeWith(source)) { + if (!sharesPermanentTypeWith(source)) { return false; } } else if (property.equals("canProduceSameManaTypeWith")) { - if (!this.canProduceSameManaTypeWith(source)) { + if (!canProduceSameManaTypeWith(source)) { return false; } } else if (property.startsWith("sharesNameWith")) { if (property.equals("sharesNameWith")) { - if (!this.getName().equals(source.getName())) { + if (!getName().equals(source.getName())) { return false; } } else { final String restriction = property.split("sharesNameWith ")[1]; if (restriction.equals("YourGraveyard")) { for (final Card card : sourceController.getCardsIn(ZoneType.Graveyard)) { - if (this.getName().equals(card.getName())) { + if (getName().equals(card.getName())) { return true; } } return false; } else if (restriction.equals(ZoneType.Graveyard.toString())) { for (final Card card : game.getCardsIn(ZoneType.Graveyard)) { - if (this.getName().equals(card.getName())) { + if (getName().equals(card.getName())) { return true; } } return false; } else if (restriction.equals(ZoneType.Battlefield.toString())) { for (final Card card : game.getCardsIn(ZoneType.Battlefield)) { - if (this.getName().equals(card.getName())) { + if (getName().equals(card.getName())) { return true; } } return false; } else if (restriction.equals("ThisTurnCast")) { for (final Card card : CardUtil.getThisTurnCast("Card", source)) { - if (this.getName().equals(card.getName())) { + if (getName().equals(card.getName())) { return true; } } @@ -6335,7 +4297,7 @@ public class Card extends GameEntity implements Comparable, IIdentifiable for (final Object rem : source.getRemembered()) { if (rem instanceof Card) { final Card card = (Card) rem; - if (this.getName().equals(card.getName())) { + if (getName().equals(card.getName())) { return true; } } @@ -6343,7 +4305,7 @@ public class Card extends GameEntity implements Comparable, IIdentifiable return false; } else if (restriction.equals("Imprinted")) { for (final Card card : source.getImprinted()) { - if (this.getName().equals(card.getName())) { + if (getName().equals(card.getName())) { return true; } } @@ -6359,7 +4321,7 @@ public class Card extends GameEntity implements Comparable, IIdentifiable if (StringUtils.isEmpty(name)) { name = card.getPaperCard().getName(); } - if (this.getName().equals(name)) { + if (getName().equals(name)) { return true; } } @@ -6370,7 +4332,7 @@ public class Card extends GameEntity implements Comparable, IIdentifiable final List list = CardLists.filter(game.getCardsIn(ZoneType.Battlefield), Presets.NON_TOKEN); for (final Card card : list) { - if (this.getName().equals(card.getName())) { + if (getName().equals(card.getName())) { return true; } } @@ -6379,7 +4341,7 @@ public class Card extends GameEntity implements Comparable, IIdentifiable } } else if (property.startsWith("doesNotShareNameWith")) { if (property.equals("doesNotShareNameWith")) { - if (this.getName().equals(source.getName())) { + if (getName().equals(source.getName())) { return false; } } else { @@ -6388,7 +4350,7 @@ public class Card extends GameEntity implements Comparable, IIdentifiable for (final Object rem : source.getRemembered()) { if (rem instanceof Card) { final Card card = (Card) rem; - if (this.getName().equals(card.getName())) { + if (getName().equals(card.getName())) { return false; } } @@ -6397,7 +4359,7 @@ public class Card extends GameEntity implements Comparable, IIdentifiable } } else if (property.startsWith("sharesControllerWith")) { if (property.equals("sharesControllerWith")) { - if (!this.sharesControllerWith(source)) { + if (!sharesControllerWith(source)) { return false; } } else { @@ -6406,14 +4368,14 @@ public class Card extends GameEntity implements Comparable, IIdentifiable for (final Object rem : source.getRemembered()) { if (rem instanceof Card) { final Card card = (Card) rem; - if (!this.sharesControllerWith(card)) { + if (!sharesControllerWith(card)) { return false; } } } } else if (restriction.equals("Imprinted")) { for (final Card card : source.getImprinted()) { - if (!this.sharesControllerWith(card)) { + if (!sharesControllerWith(card)) { return false; } } @@ -6421,7 +4383,7 @@ public class Card extends GameEntity implements Comparable, IIdentifiable } } else if (property.startsWith("sharesOwnerWith")) { if (property.equals("sharesOwnerWith")) { - if (!this.getOwner().equals(source.getOwner())) { + if (!getOwner().equals(source.getOwner())) { return false; } } else { @@ -6430,7 +4392,7 @@ public class Card extends GameEntity implements Comparable, IIdentifiable for (final Object rem : source.getRemembered()) { if (rem instanceof Card) { final Card card = (Card) rem; - if (!this.getOwner().equals(card.getOwner())) { + if (!getOwner().equals(card.getOwner())) { return false; } } @@ -6447,7 +4409,7 @@ public class Card extends GameEntity implements Comparable, IIdentifiable } } else if (property.equals("ThisTurnCast")) { for (final Card card : CardUtil.getThisTurnCast("Card", source)) { - if (this.equals(card)) { + if (equals(card)) { return true; } } @@ -6480,12 +4442,12 @@ public class Card extends GameEntity implements Comparable, IIdentifiable } else { p = sourceController; } - if (p == null || !this.getController().equals(game.getNextPlayerAfter(p, direction))) { + if (p == null || !getController().equals(game.getNextPlayerAfter(p, direction))) { return false; } } else if (property.startsWith("sharesTypeWith")) { if (property.equals("sharesTypeWith")) { - if (!this.sharesTypeWith(source)) { + if (!sharesTypeWith(source)) { return false; } } else { @@ -6501,21 +4463,21 @@ public class Card extends GameEntity implements Comparable, IIdentifiable return false; } - if (!this.sharesTypeWith(checkCard)) { + if (!sharesTypeWith(checkCard)) { return false; } } } else if (property.startsWith("hasKeyword")) { // "withFlash" would find Flashback cards, add this to fix Mystical Teachings - if (!this.hasKeyword(property.substring(10))) { + if (!hasKeyword(property.substring(10))) { return false; } } else if (property.startsWith("withFlashback")) { boolean fb = false; - if (this.hasStartOfUnHiddenKeyword("Flashback")) { + if (hasStartOfUnHiddenKeyword("Flashback")) { fb = true; } - for (final SpellAbility sa : this.getSpellAbilities()) { + for (final SpellAbility sa : getSpellAbilities()) { if (sa.isFlashBackAbility()) { fb = true; } @@ -6525,131 +4487,131 @@ public class Card extends GameEntity implements Comparable, IIdentifiable } } else if (property.startsWith("with")) { // ... Card keywords - if (property.startsWith("without") && this.hasStartOfUnHiddenKeyword(property.substring(7))) { + if (property.startsWith("without") && hasStartOfUnHiddenKeyword(property.substring(7))) { return false; } - if (!property.startsWith("without") && !this.hasStartOfUnHiddenKeyword(property.substring(4))) { + if (!property.startsWith("without") && !hasStartOfUnHiddenKeyword(property.substring(4))) { return false; } } else if (property.startsWith("tapped")) { - if (!this.isTapped()) { + if (!isTapped()) { return false; } } else if (property.startsWith("untapped")) { - if (!this.isUntapped()) { + if (!isUntapped()) { return false; } } else if (property.startsWith("faceDown")) { - if (!this.isFaceDown()) { + if (!isFaceDown()) { return false; } } else if (property.startsWith("faceUp")) { - if (this.isFaceDown()) { + if (isFaceDown()) { return false; } } else if (property.startsWith("hasLevelUp")) { - for (final SpellAbility sa : this.getSpellAbilities()) { + for (final SpellAbility sa : getSpellAbilities()) { if (sa.getApi() == ApiType.PutCounter && sa.hasParam("LevelUp")) { return true; } } return false; } else if (property.startsWith("DrawnThisTurn")) { - if (!this.getDrawnThisTurn()) { + if (!getDrawnThisTurn()) { return false; } } else if (property.startsWith("enteredBattlefieldThisTurn")) { - if (!(this.getTurnInZone() == game.getPhaseHandler().getTurn())) { + if (!(getTurnInZone() == game.getPhaseHandler().getTurn())) { return false; } } else if (property.startsWith("notEnteredBattlefieldThisTurn")) { - if (this.getTurnInZone() == game.getPhaseHandler().getTurn()) { + if (getTurnInZone() == game.getPhaseHandler().getTurn()) { return false; } } else if (property.startsWith("firstTurnControlled")) { - if (!this.isFirstTurnControlled()) { + if (!isFirstTurnControlled()) { return false; } } else if (property.startsWith("notFirstTurnControlled")) { - if (this.isFirstTurnControlled()) { + if (isFirstTurnControlled()) { return false; } } else if (property.startsWith("startedTheTurnUntapped")) { - if (!this.hasStartedTheTurnUntapped()) { + if (!hasStartedTheTurnUntapped()) { return false; } } else if (property.equals("attackedOrBlockedSinceYourLastUpkeep")) { - if (!this.getDamageHistory().hasAttackedSinceLastUpkeepOf(sourceController) - && !this.getDamageHistory().hasBlockedSinceLastUpkeepOf(sourceController)) { + if (!getDamageHistory().hasAttackedSinceLastUpkeepOf(sourceController) + && !getDamageHistory().hasBlockedSinceLastUpkeepOf(sourceController)) { return false; } } else if (property.equals("blockedOrBeenBlockedSinceYourLastUpkeep")) { - if (!this.getDamageHistory().hasBeenBlockedSinceLastUpkeepOf(sourceController) - && !this.getDamageHistory().hasBlockedSinceLastUpkeepOf(sourceController)) { + if (!getDamageHistory().hasBeenBlockedSinceLastUpkeepOf(sourceController) + && !getDamageHistory().hasBlockedSinceLastUpkeepOf(sourceController)) { return false; } } else if (property.startsWith("dealtDamageToYouThisTurn")) { - if (!this.getDamageHistory().getThisTurnDamaged().contains(sourceController)) { + if (!getDamageHistory().getThisTurnDamaged().contains(sourceController)) { return false; } } else if (property.startsWith("dealtDamageToOppThisTurn")) { - if (!this.hasDealtDamageToOpponentThisTurn()) { + if (!hasDealtDamageToOpponentThisTurn()) { return false; } } else if (property.startsWith("controllerWasDealtCombatDamageByThisTurn")) { - if (!source.getDamageHistory().getThisTurnCombatDamaged().contains(this.getController())) { + if (!source.getDamageHistory().getThisTurnCombatDamaged().contains(getController())) { return false; } } else if (property.startsWith("controllerWasDealtDamageByThisTurn")) { - if (!source.getDamageHistory().getThisTurnDamaged().contains(this.getController())) { + if (!source.getDamageHistory().getThisTurnDamaged().contains(getController())) { return false; } } else if (property.startsWith("wasDealtDamageThisTurn")) { - if ((this.getReceivedDamageFromThisTurn().keySet()).isEmpty()) { + if ((getReceivedDamageFromThisTurn().keySet()).isEmpty()) { return false; } } else if (property.equals("wasDealtDamageByHostThisTurn")) { - if (!this.getReceivedDamageFromThisTurn().keySet().contains(source)) { + if (!getReceivedDamageFromThisTurn().keySet().contains(source)) { return false; } } else if (property.equals("wasDealtDamageByEquipeeThisTurn")) { - Card equipee = source.getEquippingCard(); - if (equipee == null || this.getReceivedDamageFromThisTurn().keySet().isEmpty() - || !this.getReceivedDamageFromThisTurn().keySet().contains(equipee)) { + Card equipee = source.getEquipping(); + if (equipee == null || getReceivedDamageFromThisTurn().keySet().isEmpty() + || !getReceivedDamageFromThisTurn().keySet().contains(equipee)) { return false; } } else if (property.equals("wasDealtDamageByEnchantedThisTurn")) { Card enchanted = source.getEnchantingCard(); - if (enchanted == null || this.getReceivedDamageFromThisTurn().keySet().isEmpty() - || !this.getReceivedDamageFromThisTurn().keySet().contains(enchanted)) { + if (enchanted == null || getReceivedDamageFromThisTurn().keySet().isEmpty() + || !getReceivedDamageFromThisTurn().keySet().contains(enchanted)) { return false; } } else if (property.startsWith("dealtDamageThisTurn")) { - if (this.getTotalDamageDoneBy() == 0) { + if (getTotalDamageDoneBy() == 0) { return false; } } else if (property.startsWith("attackedThisTurn")) { - if (!this.getDamageHistory().getCreatureAttackedThisTurn()) { + if (!getDamageHistory().getCreatureAttackedThisTurn()) { return false; } } else if (property.startsWith("attackedLastTurn")) { - return this.getDamageHistory().getCreatureAttackedLastTurnOf(this.getController()); + return getDamageHistory().getCreatureAttackedLastTurnOf(getController()); } else if (property.startsWith("blockedThisTurn")) { - if (!this.getDamageHistory().getCreatureBlockedThisTurn()) { + if (!getDamageHistory().getCreatureBlockedThisTurn()) { return false; } } else if (property.startsWith("gotBlockedThisTurn")) { - if (!this.getDamageHistory().getCreatureGotBlockedThisTurn()) { + if (!getDamageHistory().getCreatureGotBlockedThisTurn()) { return false; } } else if (property.startsWith("notAttackedThisTurn")) { - if (this.getDamageHistory().getCreatureAttackedThisTurn()) { + if (getDamageHistory().getCreatureAttackedThisTurn()) { return false; } } else if (property.startsWith("notAttackedLastTurn")) { - return !this.getDamageHistory().getCreatureAttackedLastTurnOf(this.getController()); + return !getDamageHistory().getCreatureAttackedLastTurnOf(getController()); } else if (property.startsWith("notBlockedThisTurn")) { - if (this.getDamageHistory().getCreatureBlockedThisTurn()) { + if (getDamageHistory().getCreatureBlockedThisTurn()) { return false; } } else if (property.startsWith("greatestPower")) { @@ -6662,28 +4624,28 @@ public class Card extends GameEntity implements Comparable, IIdentifiable } } for (final Card crd : list) { - if (crd.getNetAttack() > this.getNetAttack()) { + if (crd.getNetAttack() > getNetAttack()) { return false; } } } else if (property.startsWith("yardGreatestPower")) { final List list = CardLists.filter(sourceController.getCardsIn(ZoneType.Graveyard), Presets.CREATURES); for (final Card crd : list) { - if (crd.getNetAttack() > this.getNetAttack()) { + if (crd.getNetAttack() > getNetAttack()) { return false; } } } else if (property.startsWith("leastPower")) { final List list = CardLists.filter(game.getCardsIn(ZoneType.Battlefield), Presets.CREATURES); for (final Card crd : list) { - if (crd.getNetAttack() < this.getNetAttack()) { + if (crd.getNetAttack() < getNetAttack()) { return false; } } } else if (property.startsWith("leastToughness")) { final List list = CardLists.filter(game.getCardsIn(ZoneType.Battlefield), Presets.CREATURES); for (final Card crd : list) { - if (crd.getNetDefense() < this.getNetDefense()) { + if (crd.getNetDefense() < getNetDefense()) { return false; } } @@ -6698,11 +4660,11 @@ public class Card extends GameEntity implements Comparable, IIdentifiable } for (final Card crd : list) { if (crd.isSplitCard()) { - if (crd.getCMC(Card.SplitCMCMode.LeftSplitCMC) > this.getCMC() || crd.getCMC(Card.SplitCMCMode.RightSplitCMC) > this.getCMC()) { + if (crd.getCMC(Card.SplitCMCMode.LeftSplitCMC) > getCMC() || crd.getCMC(Card.SplitCMCMode.RightSplitCMC) > getCMC()) { return false; } } else { - if (crd.getCMC() > this.getCMC()) { + if (crd.getCMC() > getCMC()) { return false; } } @@ -6735,61 +4697,62 @@ public class Card extends GameEntity implements Comparable, IIdentifiable if (!list.contains(this)) { return false; } - } else if (property.startsWith("lowestCMC")) { + } + else if (property.startsWith("lowestCMC")) { final List list = game.getCardsIn(ZoneType.Battlefield); for (final Card crd : list) { if (!crd.isLand() && !crd.isImmutable()) { if (crd.isSplitCard()) { - if (crd.getCMC(Card.SplitCMCMode.LeftSplitCMC) < this.getCMC() || crd.getCMC(Card.SplitCMCMode.RightSplitCMC) < this.getCMC()) { + if (crd.getCMC(Card.SplitCMCMode.LeftSplitCMC) < getCMC() || crd.getCMC(Card.SplitCMCMode.RightSplitCMC) < getCMC()) { return false; } } else { - if (crd.getCMC() < this.getCMC()) { + if (crd.getCMC() < getCMC()) { return false; } } } } } else if (property.startsWith("enchanted")) { - if (!this.isEnchanted()) { + if (!isEnchanted()) { return false; } } else if (property.startsWith("unenchanted")) { - if (this.isEnchanted()) { + if (isEnchanted()) { return false; } } else if (property.startsWith("enchanting")) { - if (!this.isEnchanting()) { + if (!isEnchanting()) { return false; } } else if (property.startsWith("equipped")) { - if (!this.isEquipped()) { + if (!isEquipped()) { return false; } } else if (property.startsWith("unequipped")) { - if (this.isEquipped()) { + if (isEquipped()) { return false; } } else if (property.startsWith("equipping")) { - if (!this.isEquipping()) { + if (!isEquipping()) { return false; } } else if (property.startsWith("token")) { - if (!this.isToken()) { + if (!isToken()) { return false; } } else if (property.startsWith("nonToken")) { - if (this.isToken()) { + if (isToken()) { return false; } } else if (property.startsWith("hasXCost")) { - SpellAbility sa1 = this.getFirstSpellAbility(); + SpellAbility sa1 = getFirstSpellAbility(); if (sa1 != null && !sa1.isXCost()) { return false; } } else if (property.startsWith("suspended")) { - if (!this.hasSuspend() || !game.isCardExiled(this) - || !(this.getCounters(CounterType.getType("TIME")) >= 1)) { + if (!hasSuspend() || !game.isCardExiled(this) + || !(getCounters(CounterType.getType("TIME")) >= 1)) { return false; } @@ -6802,10 +4765,10 @@ public class Card extends GameEntity implements Comparable, IIdentifiable if (property.startsWith("power")) { rhs = property.substring(7); - y = this.getNetAttack(); + y = getNetAttack(); } else if (property.startsWith("toughness")) { rhs = property.substring(11); - y = this.getNetDefense(); + y = getNetDefense(); } else if (property.startsWith("cmc")) { rhs = property.substring(5); if (isSplitCard() && getCurState() == CardCharacteristicName.Original) { @@ -6816,7 +4779,7 @@ public class Card extends GameEntity implements Comparable, IIdentifiable } } else if (property.startsWith("totalPT")) { rhs = property.substring(10); - y = this.getNetAttack() + this.getNetDefense(); + y = getNetAttack() + getNetDefense(); } try { x = Integer.parseInt(rhs); @@ -6866,7 +4829,7 @@ public class Card extends GameEntity implements Comparable, IIdentifiable } counterType = splitProperty[2]; - final int actualnumber = this.getCounters(CounterType.getType(counterType)); + final int actualnumber = getCounters(CounterType.getType(counterType)); if (!Expressions.compare(actualnumber, comparator, number)) { return false; @@ -6883,7 +4846,7 @@ public class Card extends GameEntity implements Comparable, IIdentifiable if (null == combat) return false; final GameEntity defender = combat.getDefenderByAttacker(source); if (defender instanceof Card) { - if (!this.equals((Card) defender)) { + if (!equals((Card) defender)) { return false; } } @@ -6925,9 +4888,9 @@ public class Card extends GameEntity implements Comparable, IIdentifiable } else if (property.startsWith("blockedBySource")) { return null != combat && combat.isBlocking(source, this); } else if (property.startsWith("blockedThisTurn")) { - return this.getBlockedThisTurn() != null; + return getBlockedThisTurn() != null; } else if (property.startsWith("blockedByThisTurn")) { - return this.getBlockedByThisTurn() != null; + return getBlockedByThisTurn() != null; } else if (property.startsWith("blockedBySourceThisTurn")) { return source.getBlockedByThisTurn() != null && source.getBlockedByThisTurn().contains(this); } else if (property.startsWith("blockedSource")) { @@ -6945,7 +4908,7 @@ public class Card extends GameEntity implements Comparable, IIdentifiable for (final Object o : source.getRemembered()) { if (o instanceof Card) { rememberedcard = (Card) o; - if (this.getBlockedThisTurn() == null || !this.getBlockedThisTurn().contains(rememberedcard)) { + if (getBlockedThisTurn() == null || !getBlockedThisTurn().contains(rememberedcard)) { return false; } } @@ -6955,7 +4918,7 @@ public class Card extends GameEntity implements Comparable, IIdentifiable for (final Object o : source.getRemembered()) { if (o instanceof Card) { rememberedcard = (Card) o; - if (this.getBlockedByThisTurn() == null || !this.getBlockedByThisTurn().contains(rememberedcard)) { + if (getBlockedByThisTurn() == null || !getBlockedByThisTurn().contains(rememberedcard)) { return false; } } @@ -6965,7 +4928,7 @@ public class Card extends GameEntity implements Comparable, IIdentifiable return false; } } else if (property.equals("attackersBandedWith")) { - if (this.equals(source)) { + if (equals(source)) { // You don't band with yourself return false; } @@ -6975,45 +4938,45 @@ public class Card extends GameEntity implements Comparable, IIdentifiable } } else if (property.startsWith("kicked")) { if (property.equals("kicked")) { - if (this.getKickerMagnitude() == 0) { + if (getKickerMagnitude() == 0) { return false; } } else { String s = property.split("kicked ")[1]; - if ("1".equals(s) && !this.isOptionalCostPaid(OptionalCost.Kicker1)) return false; - if ("2".equals(s) && !this.isOptionalCostPaid(OptionalCost.Kicker2)) return false; + if ("1".equals(s) && !isOptionalCostPaid(OptionalCost.Kicker1)) return false; + if ("2".equals(s) && !isOptionalCostPaid(OptionalCost.Kicker2)) return false; } } else if (property.startsWith("notkicked")) { - if (this.getKickerMagnitude() > 0) { + if (getKickerMagnitude() > 0) { return false; } } else if (property.startsWith("evoked")) { - if (!this.isEvoked()) { + if (!isEvoked()) { return false; } } else if (property.equals("HasDevoured")) { - if (this.devouredCards.size() == 0) { + if (devouredCards.size() == 0) { return false; } } else if (property.equals("HasNotDevoured")) { - if (this.devouredCards.size() != 0) { + if (devouredCards.size() != 0) { return false; } } else if (property.equals("IsMonstrous")) { - if (!this.isMonstrous()) { + if (!isMonstrous()) { return false; } } else if (property.equals("IsNotMonstrous")) { - if (this.isMonstrous()) { + if (isMonstrous()) { return false; } } else if (property.startsWith("non")) { // ... Other Card types - if (this.isType(property.substring(3))) { + if (isType(property.substring(3))) { return false; } } else if (property.equals("CostsPhyrexianMana")) { - if (!this.getCharacteristics().getManaCost().hasPhyrexian()) { + if (!getCharacteristics().getManaCost().hasPhyrexian()) { return false; } } else if (property.startsWith("RememberMap")) { @@ -7044,112 +5007,95 @@ public class Card extends GameEntity implements Comparable, IIdentifiable return false; } } else if (property.equals("hasActivatedAbilityWithTapCost")) { - for (final SpellAbility sa : this.getSpellAbilities()) { + for (final SpellAbility sa : getSpellAbilities()) { if (sa.isAbility() && (sa.getPayCosts() != null) && sa.getPayCosts().hasTapCost()) { return true; } } return false; } else if (property.equals("hasActivatedAbility")) { - for (final SpellAbility sa : this.getSpellAbilities()) { + for (final SpellAbility sa : getSpellAbilities()) { if (sa.isAbility()) { return true; } } return false; } else if (property.equals("hasManaAbility")) { - for (final SpellAbility sa : this.getSpellAbilities()) { + for (final SpellAbility sa : getSpellAbilities()) { if (sa.isManaAbility()) { return true; } } return false; } else if (property.equals("hasNonManaActivatedAbility")) { - for (final SpellAbility sa : this.getSpellAbilities()) { + for (final SpellAbility sa : getSpellAbilities()) { if (sa.isAbility() && !sa.isManaAbility()) { return true; } } return false; } else if (property.equals("NoAbilities")) { - if (!((this.getAbilityText().trim().equals("") || this.isFaceDown()) && (this.getUnhiddenKeyword().size() == 0))) { + if (!((getAbilityText().trim().equals("") || isFaceDown()) && (getUnhiddenKeyword().size() == 0))) { return false; } } else if (property.equals("HasCounters")) { - if (!this.hasCounters()) { + if (!hasCounters()) { return false; } } else if (property.startsWith("wasCastFrom")) { final String strZone = property.substring(11); final ZoneType realZone = ZoneType.smartValueOf(strZone); - if (realZone != this.getCastFrom()) { + if (realZone != getCastFrom()) { return false; } } else if (property.startsWith("wasNotCastFrom")) { final String strZone = property.substring(14); final ZoneType realZone = ZoneType.smartValueOf(strZone); - if (realZone == this.getCastFrom()) { + if (realZone == getCastFrom()) { return false; } } else if (property.startsWith("set")) { final String setCode = property.substring(3, 6); - if (!this.getCurSetCode().equals(setCode)) { + if (!getCurSetCode().equals(setCode)) { return false; } } else if (property.startsWith("inZone")) { final String strZone = property.substring(6); final ZoneType realZone = ZoneType.smartValueOf(strZone); - if (!this.isInZone(realZone)) { + if (!isInZone(realZone)) { return false; } } else if (property.equals("ChosenType")) { - if (!this.isType(source.getChosenType())) { + if (!isType(source.getChosenType())) { return false; } } else if (property.equals("IsNotChosenType")) { - if (this.isType(source.getChosenType())) { + if (isType(source.getChosenType())) { return false; } } else if (property.equals("IsCommander")) { - if (!this.isCommander) { + if (!isCommander) { return false; } } else { - if (!this.isType(property)) { + if (!isType(property)) { return false; } } return true; - } // hasProperty - - /** - *

- * setImmutable. - *

- * - * @param isImmutable - * a boolean. - */ - public final void setImmutable(final boolean isImmutable) { - this.isImmutable = isImmutable; } - /** - *

- * isImmutable. - *

- * - * @return a boolean. - */ public final boolean isImmutable() { - return this.isImmutable; + return isImmutable; + } + public final void setImmutable(final boolean isImmutable0) { + isImmutable = isImmutable0; } /* * there are easy checkers for Color. The CardUtil functions should be made * part of the Card class, so calling out is not necessary */ - public final boolean isOfColor(final String col) { return CardUtil.getColors(this).hasAnyColor(MagicColor.fromName(col)); } public final boolean isBlack() { return CardUtil.getColors(this).hasBlack(); } public final boolean isBlue() { return CardUtil.getColors(this).hasBlue(); } @@ -7158,41 +5104,22 @@ public class Card extends GameEntity implements Comparable, IIdentifiable public final boolean isWhite() { return CardUtil.getColors(this).hasWhite(); } public final boolean isColorless() { return CardUtil.getColors(this).isColorless(); } - /** - *

- * sharesColorWith. - *

- * - * @param c1 - * a {@link forge.game.card.Card} object. - * @return a boolean. - */ public final boolean sharesColorWith(final Card c1) { boolean shares = false; - shares |= (this.isBlack() && c1.isBlack()); - shares |= (this.isBlue() && c1.isBlue()); - shares |= (this.isGreen() && c1.isGreen()); - shares |= (this.isRed() && c1.isRed()); - shares |= (this.isWhite() && c1.isWhite()); + shares |= (isBlack() && c1.isBlack()); + shares |= (isBlue() && c1.isBlue()); + shares |= (isGreen() && c1.isGreen()); + shares |= (isRed() && c1.isRed()); + shares |= (isWhite() && c1.isWhite()); return shares; } - /** - *

- * sharesCreatureTypeWith. - *

- * - * @param c1 - * a {@link forge.game.card.Card} object. - * @return a boolean. - */ public final boolean sharesCreatureTypeWith(final Card c1) { - if (c1 == null) { return false; } - for (final String type : this.getType()) { + for (final String type : getType()) { if (type.equals("AllCreatureTypes") && c1.hasACreatureType()) { return true; } @@ -7203,22 +5130,12 @@ public class Card extends GameEntity implements Comparable, IIdentifiable return false; } - /** - *

- * sharesPermanentTypeWith. - *

- * - * @param c1 - * a {@link forge.game.card.Card} object. - * @return a boolean. - */ public final boolean sharesPermanentTypeWith(final Card c1) { - if (c1 == null) { return false; } - for (final String type : this.getType()) { + for (final String type : getType()) { if (forge.card.CardType.CoreType.isAPermanentType(type) && c1.isType(type)) { return true; } @@ -7226,18 +5143,8 @@ public class Card extends GameEntity implements Comparable, IIdentifiable return false; } - /** - *

- * sharesTypeWith. - *

- * - * @param c1 - * a {@link forge.game.card.Card} object. - * @return a boolean. - */ public final boolean sharesCardTypeWith(final Card c1) { - - for (final String type : this.getType()) { + for (final String type : getType()) { if (forge.card.CardType.isACardType(type) && c1.isType(type)) { return true; } @@ -7245,18 +5152,8 @@ public class Card extends GameEntity implements Comparable, IIdentifiable return false; } - /** - *

- * sharesTypeWith. - *

- * - * @param c1 - * a {@link forge.game.card.Card} object. - * @return a boolean. - */ public final boolean sharesTypeWith(final Card c1) { - - for (final String type : this.getType()) { + for (final String type : getType()) { if (c1.isType(type)) { return true; } @@ -7264,33 +5161,15 @@ public class Card extends GameEntity implements Comparable, IIdentifiable return false; } - /** - *

- * sharesControllerWith. - *

- * - * @param c1 - * a {@link forge.game.card.Card} object. - * @return a boolean. - */ public final boolean sharesControllerWith(final Card c1) { - if (c1 == null) { return false; } - - return this.getController().equals(c1.getController()); + return getController().equals(c1.getController()); } - /** - *

- * hasACreatureType. - *

- * - * @return a boolean. - */ public final boolean hasACreatureType() { - for (final String type : this.getType()) { + for (final String type : getType()) { if (forge.card.CardType.isACreatureType(type) || type.equals("AllCreatureTypes")) { return true; } @@ -7298,27 +5177,11 @@ public class Card extends GameEntity implements Comparable, IIdentifiable return false; } - /** - *

- * isUsedToPay. - *

- * - * @return a boolean. - */ public final boolean isUsedToPay() { - return this.usedToPayCost; + return usedToPayCost; } - - /** - *

- * setUsedToPay. - *

- * - * @param b - * a boolean. - */ public final void setUsedToPay(final boolean b) { - this.usedToPayCost = b; + usedToPayCost = b; } // ///////////////////////// @@ -7327,159 +5190,56 @@ public class Card extends GameEntity implements Comparable, IIdentifiable // // //////////////////////// - /** - *

- * addReceivedDamageFromThisTurn. - *

- * - * @param c - * a {@link forge.game.card.Card} object. - * @param damage - * a int. - */ - public final void addReceivedDamageFromThisTurn(final Card c, final int damage) { - this.receivedDamageFromThisTurn.put(c, damage); - } - - /** - *

- * Setter for the field receivedDamageFromThisTurn. - *

- * - * @param receivedDamageList - * a Map object. - */ - public final void setReceivedDamageFromThisTurn(final Map receivedDamageList) { - this.receivedDamageFromThisTurn = receivedDamageList; - } - - /** - *

- * Getter for the field receivedDamageFromThisTurn. - *

- * - * @return a Map object. - */ public final Map getReceivedDamageFromThisTurn() { - return this.receivedDamageFromThisTurn; + return receivedDamageFromThisTurn; + } + public final void setReceivedDamageFromThisTurn(final Map receivedDamageList) { + receivedDamageFromThisTurn = receivedDamageList; + } + public final void addReceivedDamageFromThisTurn(final Card c, final int damage) { + receivedDamageFromThisTurn.put(c, damage); } - - /** - *

- * resetReceivedDamageFromThisTurn. - *

- */ public final void resetReceivedDamageFromThisTurn() { - this.receivedDamageFromThisTurn.clear(); + receivedDamageFromThisTurn.clear(); } public final int getTotalDamageRecievedThisTurn() { int total = 0; - for (int damage : this.receivedDamageFromThisTurn.values()) { + for (int damage : receivedDamageFromThisTurn.values()) { total += damage; } return total; } - /** - *

- * addDealtDamageToThisTurn. - *

- * - * @param c - * a {@link forge.game.card.Card} object. - * @param damage - * a int. - */ - public final void addDealtDamageToThisTurn(final Card c, final int damage) { - this.dealtDamageToThisTurn.put(c, damage); - } - - /** - *

- * Setter for the field dealtDamageToThisTurn. - *

- * - * @param dealtDamageList - * a {@link java.util.Map} object. - */ - public final void setDealtDamageToThisTurn(final Map dealtDamageList) { - this.dealtDamageToThisTurn = dealtDamageList; - } - - /** - *

- * Getter for the field dealtDamageToThisTurn. - *

- * - * @return a {@link java.util.Map} object. - */ public final Map getDealtDamageToThisTurn() { - return this.dealtDamageToThisTurn; + return dealtDamageToThisTurn; + } + public final void setDealtDamageToThisTurn(final Map dealtDamageList) { + dealtDamageToThisTurn = dealtDamageList; + } + public final void addDealtDamageToThisTurn(final Card c, final int damage) { + dealtDamageToThisTurn.put(c, damage); } - - /** - *

- * resetDealtDamageToThisTurn. - *

- */ public final void resetDealtDamageToThisTurn() { - this.dealtDamageToThisTurn.clear(); + dealtDamageToThisTurn.clear(); } - /** - *

- * addDealtDamageToPlayerThisTurn. - *

- * - * @param player - * player as name String. - * @param damage - * a int. - */ - public final void addDealtDamageToPlayerThisTurn(final String player, final int damage) { - this.dealtDamageToPlayerThisTurn.put(player, damage); - } - - /** - *

- * Setter for the field dealtDamageToPlayerThisTurn. - *

- * - * @param dealtDamageList - * a {@link java.util.Map} object. - */ - public final void setDealtDamageToPlayerThisTurn(final Map dealtDamageList) { - this.dealtDamageToPlayerThisTurn = dealtDamageList; - } - - /** - *

- * Getter for the field dealtDamageToPlayerThisTurn. - *

- * - * @return a {@link java.util.Map} object. - */ public final Map getDealtDamageToPlayerThisTurn() { - return this.dealtDamageToPlayerThisTurn; + return dealtDamageToPlayerThisTurn; + } + public final void setDealtDamageToPlayerThisTurn(final Map dealtDamageList) { + dealtDamageToPlayerThisTurn = dealtDamageList; + } + public final void addDealtDamageToPlayerThisTurn(final String player, final int damage) { + dealtDamageToPlayerThisTurn.put(player, damage); } - - /** - *

- * resetDealtDamageToPlayerThisTurn. - *

- */ public final void resetDealtDamageToPlayerThisTurn() { - this.dealtDamageToPlayerThisTurn.clear(); + dealtDamageToPlayerThisTurn.clear(); } - /** - * @return {@code true} if and only if this dealt damage to an opponent this - * turn. - */ public final boolean hasDealtDamageToOpponentThisTurn() { - for (final Player p : this.getDamageHistory().getThisTurnDamaged()) { - if (this.getController().isOpponentOf(p)) { + for (final Player p : getDamageHistory().getThisTurnDamaged()) { + if (getController().isOpponentOf(p)) { return true; } } @@ -7487,119 +5247,53 @@ public class Card extends GameEntity implements Comparable, IIdentifiable } // this is the minimal damage a trampling creature has to assign to a blocker - /** - *

- * getLethalDamage. - *

- * - * @return a int. - */ public final int getLethalDamage() { - final int lethalDamage = this.getNetDefense() - this.getDamage() - this.getTotalAssignedDamage(); - - return lethalDamage; + return getNetDefense() - getDamage() - getTotalAssignedDamage(); } - /** - *

- * Setter for the field damage. - *

- * - * @param n - * a int. - */ - public final void setDamage(final int n) { - int oldDamage = damage; - this.damage = n; - if (n != oldDamage) { - getGame().fireEvent(new GameEventCardStatsChanged(this)); - } - } - - /** - *

- * Getter for the field damage. - *

- * - * @return a int. - */ public final int getDamage() { - return this.damage; + return damage; + } + public final void setDamage(int damage0) { + if (damage == damage0) { return; } + damage = damage0; + view.updateDamage(this); + getGame().fireEvent(new GameEventCardStatsChanged(this)); } - /** - *

- * addAssignedDamage. - *

- * - * @param damage - * a int. - * @param sourceCard - * a {@link forge.game.card.Card} object. - */ - public final void addAssignedDamage(int damage, final Card sourceCard) { - if (damage < 0) { - damage = 0; - } - - final int assignedDamage = damage; - - Log.debug(this + " - was assigned " + assignedDamage + " damage, by " + sourceCard); - if (!this.assignedDamageMap.containsKey(sourceCard)) { - this.assignedDamageMap.put(sourceCard, assignedDamage); - } else { - this.assignedDamageMap.put(sourceCard, this.assignedDamageMap.get(sourceCard) + assignedDamage); - } + public final Map getAssignedDamageMap() { + return assignedDamageMap; } - /** - *

- * clearAssignedDamage. - *

- */ + public final void addAssignedDamage(int assignedDamage0, final Card sourceCard) { + if (assignedDamage0 < 0) { + assignedDamage0 = 0; + } + Log.debug(this + " - was assigned " + assignedDamage0 + " damage, by " + sourceCard); + if (!assignedDamageMap.containsKey(sourceCard)) { + assignedDamageMap.put(sourceCard, assignedDamage0); + } + else { + assignedDamageMap.put(sourceCard, assignedDamageMap.get(sourceCard) + assignedDamage0); + } + if (assignedDamage0 > 0) { + view.updateAssignedDamage(this); + } + } public final void clearAssignedDamage() { - this.assignedDamageMap.clear(); + if (assignedDamageMap.isEmpty()) { return; } + assignedDamageMap.clear(); + view.updateAssignedDamage(this); } - /** - *

- * getTotalAssignedDamage. - *

- * - * @return a int. - */ public final int getTotalAssignedDamage() { int total = 0; - - final Collection c = this.assignedDamageMap.values(); - - final Iterator itr = c.iterator(); - while (itr.hasNext()) { - total += itr.next(); + for (Integer assignedDamage : assignedDamageMap.values()) { + total += assignedDamage; } - return total; } - /** - *

- * Getter for the field assignedDamageMap. - *

- * - * @return a {@link java.util.Map} object. - */ - public final Map getAssignedDamageMap() { - return this.assignedDamageMap; - } - - /** - *

- * addCombatDamage. - *

- * - * @param map - * a {@link java.util.Map} object. - */ public final void addCombatDamage(final Map map) { final List list = new ArrayList(); @@ -7608,36 +5302,19 @@ public class Card extends GameEntity implements Comparable, IIdentifiable list.add(source); int damageToAdd = entry.getValue(); - damageToAdd = this.replaceDamage(damageToAdd, source, true); - damageToAdd = this.preventDamage(damageToAdd, source, true); + damageToAdd = replaceDamage(damageToAdd, source, true); + damageToAdd = preventDamage(damageToAdd, source, true); map.put(source, damageToAdd); } - if (this.isInPlay()) { - this.addDamage(map); + if (isInPlay()) { + addDamage(map); } } // This is used by the AI to forecast an effect (so it must not change the game state) - /** - *

- * staticDamagePrevention. - *

- * - * @param damage - * a int. - * @param possiblePrevention - * a int. - * @param source - * a {@link forge.game.card.Card} object. - * @param isCombat - * a boolean. - * @return a int. - */ - public final int staticDamagePrevention(final int damage, final int possiblePrevention, final Card source, - final boolean isCombat) { - + public final int staticDamagePrevention(final int damage, final int possiblePrevention, final Card source, final boolean isCombat) { if (getGame().getStaticEffects().getGlobalRuleChange(GlobalRuleChange.noPrevention)) { return damage; } @@ -7653,7 +5330,7 @@ public class Card extends GameEntity implements Comparable, IIdentifiable continue; } if (params.containsKey("ValidTarget") - && !this.isValid(params.get("ValidTarget"), ca.getController(), ca)) { + && !isValid(params.get("ValidTarget"), ca.getController(), ca)) { continue; } if (params.containsKey("IsCombat")) { @@ -7666,36 +5343,16 @@ public class Card extends GameEntity implements Comparable, IIdentifiable continue; } } - } return 0; } } - - int restDamage = damage - possiblePrevention; - - restDamage = this.staticDamagePrevention(restDamage, source, isCombat, true); - - return restDamage; + return staticDamagePrevention(damage - possiblePrevention, source, isCombat, true); } // This should be also usable by the AI to forecast an effect (so it must not change the game state) - /** - *

- * staticDamagePrevention. - *

- * - * @param damageIn - * a int. - * @param source - * a {@link forge.game.card.Card} object. - * @param isCombat - * a boolean. - * @return a int. - */ @Override public final int staticDamagePrevention(final int damageIn, final Card source, final boolean isCombat, final boolean isTest) { - if (getGame().getStaticEffects().getGlobalRuleChange(GlobalRuleChange.noPrevention)) { return damageIn; } @@ -7706,7 +5363,7 @@ public class Card extends GameEntity implements Comparable, IIdentifiable int restDamage = damageIn; - if (this.hasProtectionFrom(source)) { + if (hasProtectionFrom(source)) { return 0; } @@ -7726,7 +5383,7 @@ public class Card extends GameEntity implements Comparable, IIdentifiable return 0; } } - for (String kw : this.getKeyword()) { + for (String kw : getKeyword()) { if (isCombat) { if (kw.equals("Prevent all combat damage that would be dealt to and dealt by CARDNAME.")) { return 0; @@ -7742,7 +5399,7 @@ public class Card extends GameEntity implements Comparable, IIdentifiable return 0; } if (kw.startsWith("Absorb")) { - final int absorbed = this.getKeywordMagnitude("Absorb"); + final int absorbed = getKeywordMagnitude("Absorb"); if (restDamage > absorbed) { restDamage = restDamage - absorbed; } else { @@ -7750,9 +5407,9 @@ public class Card extends GameEntity implements Comparable, IIdentifiable } } if (kw.startsWith("PreventAllDamageBy")) { - String valid = this.getKeyword().get(this.getKeywordPosition("PreventAllDamageBy")); + String valid = getKeyword().get(getKeywordPosition("PreventAllDamageBy")); valid = valid.split(" ", 2)[1]; - if (source.isValid(valid, this.getController(), this)) { + if (source.isValid(valid, getController(), this)) { return 0; } } @@ -7768,22 +5425,8 @@ public class Card extends GameEntity implements Comparable, IIdentifiable return restDamage > 0 ? restDamage : 0; } - /** - *

- * preventDamage. - *

- * - * @param damage - * a int. - * @param source - * a {@link forge.game.card.Card} object. - * @param isCombat - * a boolean. - * @return a int. - */ @Override public final int preventDamage(final int damage, final Card source, final boolean isCombat) { - if (getGame().getStaticEffects().getGlobalRuleChange(GlobalRuleChange.noPrevention) || source.hasKeyword("Damage that would be dealt by CARDNAME can't be prevented.")) { return damage; @@ -7792,8 +5435,8 @@ public class Card extends GameEntity implements Comparable, IIdentifiable int restDamage = damage; boolean DEBUGShieldsWithEffects = false; - while (!this.getPreventNextDamageWithEffect().isEmpty() && restDamage != 0) { - TreeMap> shieldMap = this.getPreventNextDamageWithEffect(); + while (!getPreventNextDamageWithEffect().isEmpty() && restDamage != 0) { + TreeMap> shieldMap = getPreventNextDamageWithEffect(); List preventionEffectSources = new ArrayList(shieldMap.keySet()); Card shieldSource = preventionEffectSources.get(0); if (preventionEffectSources.size() > 1) { @@ -7808,7 +5451,7 @@ public class Card extends GameEntity implements Comparable, IIdentifiable choices.add(shieldDescription); choiceMap.put(shieldDescription, key); } - shieldSource = this.getController().getController().chooseProtectionShield(this, choices, choiceMap); + shieldSource = getController().getController().chooseProtectionShield(this, choices, choiceMap); } if (DEBUGShieldsWithEffects) { System.out.println("Prevention shield source: " + shieldSource); @@ -7838,18 +5481,18 @@ public class Card extends GameEntity implements Comparable, IIdentifiable boolean apiIsEffect = (shieldSA.getApi() == ApiType.Effect); List cardsInCommand = null; if (apiIsEffect) { - cardsInCommand = this.getGame().getCardsIn(ZoneType.Command); + cardsInCommand = getGame().getCardsIn(ZoneType.Command); } - this.getController().getController().playSpellAbilityNoStack(shieldSA, true); + getController().getController().playSpellAbilityNoStack(shieldSA, true); if (apiIsEffect) { - List newCardsInCommand = this.getGame().getCardsIn(ZoneType.Command); + List newCardsInCommand = getGame().getCardsIn(ZoneType.Command); newCardsInCommand.removeAll(cardsInCommand); if (!newCardsInCommand.isEmpty()) { newCardsInCommand.get(0).setSVar("PreventedDamage", "Number$" + Integer.toString(dmgToBePrevented)); } } - this.subtractPreventNextDamageWithEffect(shieldSource, restDamage); + subtractPreventNextDamageWithEffect(shieldSource, restDamage); restDamage = restDamage - dmgToBePrevented; if (DEBUGShieldsWithEffects) { @@ -7859,7 +5502,6 @@ public class Card extends GameEntity implements Comparable, IIdentifiable } } - final HashMap repParams = new HashMap(); repParams.put("Event", "DamageDone"); repParams.put("Affected", this); @@ -7872,37 +5514,24 @@ public class Card extends GameEntity implements Comparable, IIdentifiable return 0; } - restDamage = this.staticDamagePrevention(restDamage, source, isCombat, false); + restDamage = staticDamagePrevention(restDamage, source, isCombat, false); if (restDamage == 0) { return 0; } - if (restDamage >= this.getPreventNextDamage()) { - restDamage = restDamage - this.getPreventNextDamage(); - this.setPreventNextDamage(0); - } else { - this.setPreventNextDamage(this.getPreventNextDamage() - restDamage); + if (restDamage >= getPreventNextDamage()) { + restDamage = restDamage - getPreventNextDamage(); + setPreventNextDamage(0); + } + else { + setPreventNextDamage(getPreventNextDamage() - restDamage); restDamage = 0; } - return restDamage; } // This is used by the AI to forecast an effect (so it must not change the game state) - /** - *

- * staticReplaceDamage. - *

- * - * @param damage - * a int. - * @param source - * a {@link forge.game.card.Card} object. - * @param isCombat - * a boolean. - * @return a int. - */ @Override public final int staticReplaceDamage(final int damage, final Card source, final boolean isCombat) { @@ -7914,17 +5543,17 @@ public class Card extends GameEntity implements Comparable, IIdentifiable } } else if (c.getName().equals("Pyromancer's Swath")) { if (c.getController().equals(source.getController()) && (source.isInstant() || source.isSorcery()) - && this.isCreature()) { + && isCreature()) { restDamage += 2; } } else if (c.getName().equals("Furnace of Rath")) { - if (this.isCreature()) { + if (isCreature()) { restDamage += restDamage; } } else if (c.getName().equals("Dictate of the Twin Gods")) { restDamage += restDamage; } else if (c.getName().equals("Gratuitous Violence")) { - if (c.getController().equals(source.getController()) && source.isCreature() && this.isCreature()) { + if (c.getController().equals(source.getController()) && source.isCreature() && isCreature()) { restDamage += restDamage; } } else if (c.getName().equals("Fire Servant")) { @@ -7933,53 +5562,39 @@ public class Card extends GameEntity implements Comparable, IIdentifiable restDamage *= 2; } } else if (c.getName().equals("Gisela, Blade of Goldnight")) { - if (!c.getController().equals(this.getController())) { + if (!c.getController().equals(getController())) { restDamage *= 2; } } else if (c.getName().equals("Inquisitor's Flail")) { - if (isCombat && c.getEquippingCard() != null - && (c.getEquippingCard().equals(this) || c.getEquippingCard().equals(source))) { + if (isCombat && c.getEquipping() != null + && (c.getEquipping().equals(this) || c.getEquipping().equals(source))) { restDamage *= 2; } } else if (c.getName().equals("Ghosts of the Innocent")) { - if (this.isCreature()) { + if (isCreature()) { restDamage = restDamage / 2; } } else if (c.getName().equals("Benevolent Unicorn")) { - if (source.isSpell() && this.isCreature()) { + if (source.isSpell() && isCreature()) { restDamage -= 1; } } else if (c.getName().equals("Divine Presence")) { - if (restDamage > 3 && this.isCreature()) { + if (restDamage > 3 && isCreature()) { restDamage = 3; } } else if (c.getName().equals("Lashknife Barrier")) { - if (c.getController().equals(this.getController()) && this.isCreature()) { + if (c.getController().equals(getController()) && isCreature()) { restDamage -= 1; } } } - if (this.getName().equals("Phytohydra")) { + if (getName().equals("Phytohydra")) { return 0; } - return restDamage; } - /** - *

- * replaceDamage. - *

- * - * @param damageIn - * a int. - * @param source - * a {@link forge.game.card.Card} object. - * @param isCombat - * a boolean. - * @return a int. - */ @Override public final int replaceDamage(final int damageIn, final Card source, final boolean isCombat) { // Replacement effects @@ -7997,35 +5612,16 @@ public class Card extends GameEntity implements Comparable, IIdentifiable return damageIn; } - /** - *

- * addDamage. - *

- * - * @param sourcesMap - * a {@link java.util.Map} object. - */ public final void addDamage(final Map sourcesMap) { for (final Entry entry : sourcesMap.entrySet()) { // damage prevention is already checked! - this.addDamageAfterPrevention(entry.getValue(), entry.getKey(), true); + addDamageAfterPrevention(entry.getValue(), entry.getKey(), true); } } /** - *

- * addDamageAfterPrevention. - *

* This function handles damage after replacement and prevention effects are * applied. - * - * @param damageIn - * a int. - * @param source - * a {@link forge.game.card.Card} object. - * @param isCombat - * a boolean. - * @return whether or not damage as dealt */ @Override public final boolean addDamageAfterPrevention(final int damageIn, final Card source, final boolean isCombat) { @@ -8035,7 +5631,7 @@ public class Card extends GameEntity implements Comparable, IIdentifiable return false; // Rule 119.8 } - this.addReceivedDamageFromThisTurn(source, damageToAdd); + addReceivedDamageFromThisTurn(source, damageToAdd); source.addDealtDamageToThisTurn(this, damageToAdd); if (source.hasKeyword("Lifelink")) { @@ -8051,8 +5647,8 @@ public class Card extends GameEntity implements Comparable, IIdentifiable getGame().getTriggerHandler().runTrigger(TriggerType.DamageDone, runParams, false); GameEventCardDamaged.DamageType damageType = DamageType.Normal; - if (this.isPlaneswalker()) { - this.subtractCounter(CounterType.LOYALTY, damageToAdd); + if (isPlaneswalker()) { + subtractCounter(CounterType.LOYALTY, damageToAdd); damageType = DamageType.LoyaltyLoss; } else { @@ -8061,17 +5657,18 @@ public class Card extends GameEntity implements Comparable, IIdentifiable boolean wither = (game.getStaticEffects().getGlobalRuleChange(GlobalRuleChange.alwaysWither) || source.hasKeyword("Wither") || source.hasKeyword("Infect")); - if (this.isInPlay()) { + if (isInPlay()) { if (wither) { - this.addCounter(CounterType.M1M1, damageToAdd, true); + addCounter(CounterType.M1M1, damageToAdd, true); damageType = DamageType.M1M1Counters; } else { - this.damage += damageToAdd; + damage += damageToAdd; + view.updateDamage(this); } } - if (source.hasKeyword("Deathtouch") && this.isCreature()) { + if (source.hasKeyword("Deathtouch") && isCreature()) { game.getAction().destroy(this, null); damageType = DamageType.Deathtouch; } @@ -8079,346 +5676,163 @@ public class Card extends GameEntity implements Comparable, IIdentifiable // Play the Damage sound game.fireEvent(new GameEventCardDamaged(this, source, damageToAdd, damageType)); } - return true; } - /** - *

- * Setter for the field curSetCode. - *

- * - * @param setCode - * a {@link java.lang.String} object. - */ - public final void setCurSetCode(final String setCode) { - this.getCharacteristics().setCurSetCode(setCode); - } - - /** - *

- * Getter for the field curSetCode. - *

- * - * @return a {@link java.lang.String} object. - */ public final String getCurSetCode() { - return this.getCharacteristics().getCurSetCode(); + return getCharacteristics().getCurSetCode(); + } + public final void setCurSetCode(final String setCode) { + if (getCurSetCode().equals(setCode)) { return; } + getCharacteristics().setCurSetCode(setCode); + view.updateSetCode(this); } - /** - *

- * getCurSetRarity. - *

- * - * @return a {@link java.lang.String} object. - */ public final CardRarity getRarity() { - return this.getCharacteristics().getRarity(); + return getCharacteristics().getRarity(); } - public final void setRarity(CardRarity r) { - this.getCharacteristics().setRarity(r); + if (getRarity().equals(r)) { return; } + getCharacteristics().setRarity(r); + view.updateRarity(this); } - /** - *

- * getMostRecentSet. - *

- * - * @return a {@link java.lang.String} object. - */ public final String getMostRecentSet() { - return StaticData.instance().getCommonCards().getCard(this.getName()).getEdition(); - } - - public final void setImageKey(final String iFN) { - this.getCardForUi().getCharacteristics().setImageKey(iFN); + return StaticData.instance().getCommonCards().getCard(getName()).getEdition(); } public final String getImageKey() { - return this.getCardForUi().getCharacteristics().getImageKey(); + return getCardForUi().getCharacteristics().getImageKey(); + } + public final void setImageKey(final String iFN) { + getCardForUi().getCharacteristics().setImageKey(iFN); } public String getImageKey(CardCharacteristicName state) { - CardCharacteristics c = this.getCardForUi().characteristicsMap.get(state); + CardCharacteristics c = getCardForUi().characteristicsMap.get(state); return (c != null ? c.getImageKey() : ""); } - /** - *

- * Setter for the field evoked. - *

- * - * @param evokedIn - * a boolean. - */ - public final void setEvoked(final boolean evokedIn) { - this.evoked = evokedIn; - } - - /** - *

- * isEvoked. - *

- * - * @return a boolean. - */ public final boolean isEvoked() { - return this.evoked; + return evoked; + } + public final void setEvoked(final boolean evokedIn) { + evoked = evokedIn; } - /** - *

- * Setter for the field tributed. - *

- * - * @param b - * a boolean. - */ public final void setTributed(final boolean b) { - this.tributed = b; + tributed = b; } - // Madness public boolean isMadness() { return madness; } - - public void setMadness(boolean madness) { - this.madness = madness; + public void setMadness(boolean madness0) { + madness = madness0; } - /** - *

- * Setter for the field monstrous. - *

- * - * @param monstrous - * a boolean. - */ - public final void setMonstrous(final boolean monstrous) { - this.monstrous = monstrous; - } - - /** - *

- * isMonstrous. - *

- * - * @return a boolean. - */ public final boolean isMonstrous() { - return this.monstrous; + return monstrous; + } + public final void setMonstrous(final boolean monstrous0) { + monstrous = monstrous0; + } + + public final int getMonstrosityNum() { + return monstrosityNum; + } + public final void setMonstrosityNum(final int num) { + monstrosityNum = num; } - /** - *

- * animateBestow. - *

- */ public final void animateBestow() { - this.bestowTimestamp = this.getGame().getNextTimestamp(); - this.addChangedCardTypes(new ArrayList(Arrays.asList("Aura")), + bestowTimestamp = getGame().getNextTimestamp(); + addChangedCardTypes(new ArrayList(Arrays.asList("Aura")), new ArrayList(Arrays.asList("Creature")), false, false, false, true, bestowTimestamp); - this.addChangedCardKeywords(Arrays.asList("Enchant creature"), new ArrayList(), false, bestowTimestamp); + addChangedCardKeywords(Arrays.asList("Enchant creature"), new ArrayList(), false, bestowTimestamp); } - /** - *

- * unanimateBestow. - *

- */ public final void unanimateBestow() { - this.removeChangedCardKeywords(bestowTimestamp); - this.removeChangedCardTypes(bestowTimestamp); + removeChangedCardKeywords(bestowTimestamp); + removeChangedCardTypes(bestowTimestamp); bestowTimestamp = -1; } - /** - *

- * isBestowed. - *

- * - * @return a boolean. - */ public final boolean isBestowed() { - return this.bestowTimestamp != -1; + return bestowTimestamp != -1; } - /** - *

- * Setter for the field monstrosityNum. - *

- * - * @param num - * an int. - */ - public final void setMonstrosityNum(final int num) { - this.monstrosityNum = num; - } - - /** - *

- * getMonstrosityNum. - *

- * - * @return a int. - */ - public final int getMonstrosityNum() { - return this.monstrosityNum; - } - /** - * - * TODO Write javadoc for this method. - * - * @param t - * a long - */ - public final void setTimestamp(final long t) { - this.timestamp = t; - } - - /** - * - * TODO Write javadoc for this method. - * - * @return a long - */ public final long getTimestamp() { - return this.timestamp; + return timestamp; + } + public final void setTimestamp(final long t) { + timestamp = t; } /** * Assign a random foil finish depending on the card edition. * - * @param remove if true, a random foil is assigned, otherwise it is - * removed. + * @param remove if true, a random foil is assigned, otherwise it is removed. */ public final void setRandomFoil() { - this.setFoil(CardEdition.getRandomFoil(this.getCurSetCode())); + setFoil(CardEdition.getRandomFoil(getCurSetCode())); } - /** - * - * TODO Write javadoc for this method. - * - * @param f an int - */ public final void setFoil(final int f) { - this.getCharacteristics().setSVar("Foil", Integer.toString(f)); + getCharacteristics().setSVar("Foil", Integer.toString(f)); } - /** - * Adds the haunted by. - * - * @param c - * the c - */ public final void addHauntedBy(final Card c) { - this.hauntedBy.add(c); + hauntedBy.add(c); if (c != null) { c.setHaunting(this); } } - /** - * Gets the haunted by. - * - * @return the haunted by - */ public final List getHauntedBy() { - return this.hauntedBy; + return hauntedBy; } - /** - * Removes the haunted by. - * - * @param c - * the c - */ public final void removeHauntedBy(final Card c) { - this.hauntedBy.remove(c); + hauntedBy.remove(c); } - /** - * Gets the pairing. - * - * @return the pairedWith - */ public final Card getPairedWith() { - return this.pairedWith; + return pairedWith; } - /** - * Sets the pairing. - * - * @param c - * the new pairedWith - */ public final void setPairedWith(final Card c) { - this.pairedWith = c; + pairedWith = c; } - /** - *

- * isPaired. - *

- * - * @return a boolean. - */ public final boolean isPaired() { - return this.pairedWith != null; + return pairedWith != null; } - /** - * Gets the haunting. - * - * @return the haunting - */ public final Card getHaunting() { - return this.haunting; + return haunting; } - /** - * Sets the haunting. - * - * @param c - * the new haunting - */ public final void setHaunting(final Card c) { - this.haunting = c; + haunting = c; } - /** - * Gets the damage done this turn. - * - * @return the damage done this turn - */ public final int getDamageDoneThisTurn() { int sum = 0; - for (final Card c : this.dealtDamageToThisTurn.keySet()) { - sum += this.dealtDamageToThisTurn.get(c); + for (final Card c : dealtDamageToThisTurn.keySet()) { + sum += dealtDamageToThisTurn.get(c); } return sum; } - /** - * Gets the damage done to a player by card this turn. - * - * @param player - * the player name - * @return the damage done to player p this turn - */ public final int getDamageDoneToPlayerBy(final String player) { int sum = 0; - for (final String p : this.dealtDamageToPlayerThisTurn.keySet()) { + for (final String p : dealtDamageToPlayerThisTurn.keySet()) { if (p.equals(player)) { - sum += this.dealtDamageToPlayerThisTurn.get(p); + sum += dealtDamageToPlayerThisTurn.get(p); } } - return sum; } @@ -8429,22 +5843,15 @@ public class Card extends GameEntity implements Comparable, IIdentifiable */ public final int getTotalDamageDoneBy() { int sum = 0; - for (final Card c : this.dealtDamageToThisTurn.keySet()) { - sum += this.dealtDamageToThisTurn.get(c); + for (final Card c : dealtDamageToThisTurn.keySet()) { + sum += dealtDamageToThisTurn.get(c); } - for (final String p : this.dealtDamageToPlayerThisTurn.keySet()) { - sum += this.dealtDamageToPlayerThisTurn.get(p); + for (final String p : dealtDamageToPlayerThisTurn.keySet()) { + sum += dealtDamageToPlayerThisTurn.get(p); } - return sum; } - - /* - * (non-Javadoc) - * - * @see forge.GameEntity#hasProtectionFrom(forge.Card) - */ @Override public boolean hasProtectionFrom(final Card source) { return hasProtectionFrom(source, false); @@ -8455,11 +5862,11 @@ public class Card extends GameEntity implements Comparable, IIdentifiable return false; } - if (this.isImmutable()) { + if (isImmutable()) { return true; } - final List keywords = this.getKeyword(); + final List keywords = getKeyword(); if (keywords != null) { for (int i = 0; i < keywords.size(); i++) { final String kw = keywords.get(i); @@ -8505,8 +5912,8 @@ public class Card extends GameEntity implements Comparable, IIdentifiable final String characteristic = kws[1]; final String[] characteristics = characteristic.split(","); final String exception = kws.length > 3 ? kws[3] : null; // check "This effect cannot remove sth" - if (source.isValid(characteristics, this.getController(), this) - && (!checkSBA || exception == null || !source.isValid(exception, this.getController(), this))) { + if (source.isValid(characteristics, getController(), this) + && (!checkSBA || exception == null || !source.isValid(exception, getController(), this))) { return true; } } else if (kw.equals("Protection from colored spells")) { @@ -8514,7 +5921,7 @@ public class Card extends GameEntity implements Comparable, IIdentifiable return true; } } else if (kw.equals("Protection from the chosen player")) { - if (source.getController().equals(this.chosenPlayer)) { + if (source.getController().equals(chosenPlayer)) { return true; } } else if (kw.startsWith("Protection from ")) { @@ -8528,41 +5935,26 @@ public class Card extends GameEntity implements Comparable, IIdentifiable return false; } - /** - * - * is In Zone. - * - * @param zone - * Constant.Zone - * @return boolean - */ - public boolean isInZone(final ZoneType zone) { - Zone z = this.getZone(); - return z != null && z.getZoneType() == zone; - } - public Zone getZone() { return currentZone; } - public void setZone(Zone zone) { + if (currentZone == zone) { return; } currentZone = zone; + view.updateZone(this); + } + + public boolean isInZone(final ZoneType zone) { + Zone z = getZone(); + return z != null && z.getZoneType() == zone; } public final boolean canBeDestroyed() { return isInPlay() && (!hasKeyword("Indestructible") || (isCreature() && getNetDefense() <= 0)); } - /** - * Can target. - * - * @param sa - * the sa - * @return a boolean - */ @Override public final boolean canBeTargetedBy(final SpellAbility sa) { - if (sa == null) { return true; } @@ -8578,28 +5970,28 @@ public class Card extends GameEntity implements Comparable, IIdentifiable } // keywords don't work outside battlefield - if (!this.isInZone(ZoneType.Battlefield)) { + if (!isInZone(ZoneType.Battlefield)) { return true; } - if (this.hasProtectionFrom(sa.getHostCard())) { + if (hasProtectionFrom(sa.getHostCard())) { return false; } - if (this.isPhasedOut()) { + if (isPhasedOut()) { return false; } final Card source = sa.getHostCard(); - if (this.getKeyword() != null) { - for (String kw : this.getKeyword()) { + if (getKeyword() != null) { + for (String kw : getKeyword()) { if (kw.equals("Shroud")) { return false; } if (kw.equals("Hexproof")) { - if (sa.getActivatingPlayer().getOpponents().contains(this.getController())) { + if (sa.getActivatingPlayer().getOpponents().contains(getController())) { if (!sa.getActivatingPlayer().getKeywords().contains("Spells and abilities you control can target hexproof creatures")) { return false; } @@ -8654,47 +6046,25 @@ public class Card extends GameEntity implements Comparable, IIdentifiable final String parse = source.getKeyword().get(keywordPosition).toString(); final String[] k = parse.split(":"); final String[] restrictions = k[1].split(","); - if (this.isValid(restrictions, source.getController(), source)) { + if (isValid(restrictions, source.getController(), source)) { return false; } } return true; } - /** - * canBeControlledBy. - * - * @param newController - * a Player - * @return a boolean - */ public final boolean canBeControlledBy(final Player newController) { - if (this.hasKeyword("Other players can't gain control of CARDNAME.") - && !this.getController().equals(newController)) { + if (hasKeyword("Other players can't gain control of CARDNAME.") + && !getController().equals(newController)) { return false; } return true; } - /** - * canBeEnchantedBy. - * - * @param aura - * a Card - * @return a boolean - */ public final boolean canBeEnchantedBy(final Card aura) { return canBeEnchantedBy(aura, false); } - /** - * canBeEnchantedBy. - * - * @param aura - * a Card - * @param checkSBA - * @return a boolean - */ public final boolean canBeEnchantedBy(final Card aura, final boolean checkSBA) { SpellAbility sa = aura.getFirstAttachSpell(); if (aura.isBestowed()) { @@ -8710,134 +6080,84 @@ public class Card extends GameEntity implements Comparable, IIdentifiable tgt = sa.getTargetRestrictions(); } - if (this.hasProtectionFrom(aura, checkSBA) - || (this.hasKeyword("CARDNAME can't be enchanted in the future.") && !this.getEnchantedBy().contains(aura)) - || (this.hasKeyword("CARDNAME can't be enchanted.") && !aura.getName().equals("Anti-Magic Aura") + if (hasProtectionFrom(aura, checkSBA) + || (hasKeyword("CARDNAME can't be enchanted in the future.") && !getEnchantedBy().contains(aura)) + || (hasKeyword("CARDNAME can't be enchanted.") && !aura.getName().equals("Anti-Magic Aura") && !(aura.getName().equals("Consecrate Land") && aura.isInZone(ZoneType.Battlefield))) - || ((tgt != null) && !this.isValid(tgt.getValidTgts(), aura.getController(), aura))) { + || ((tgt != null) && !isValid(tgt.getValidTgts(), aura.getController(), aura))) { return false; } return true; } - /** - * canBeEquippedBy. - * - * @param equip - * a Card - * @return a boolean - */ public final boolean canBeEquippedBy(final Card equip) { if (equip.hasStartOfKeyword("CantEquip")) { final int keywordPosition = equip.getKeywordPosition("CantEquip"); final String parse = equip.getKeyword().get(keywordPosition).toString(); final String[] k = parse.split(" ", 2); final String[] restrictions = k[1].split(","); - if (this.isValid(restrictions, equip.getController(), equip)) { + if (isValid(restrictions, equip.getController(), equip)) { return false; } } - if (this.hasProtectionFrom(equip) - || this.hasKeyword("CARDNAME can't be equipped.") - || !this.isValid("Creature", equip.getController(), equip)) { + if (hasProtectionFrom(equip) + || hasKeyword("CARDNAME can't be equipped.") + || !isValid("Creature", equip.getController(), equip)) { return false; } return true; } - /** - * Gets the replacement effects. - * - * @return the replacement effects - */ public List getReplacementEffects() { - return this.getCharacteristics().getReplacementEffects(); + return getCharacteristics().getReplacementEffects(); } - /** - * Sets the replacement effects. - * - * @param res - * the new replacement effects - */ public void setReplacementEffects(final List res) { - this.getCharacteristics().getReplacementEffects().clear(); + getCharacteristics().getReplacementEffects().clear(); for (final ReplacementEffect replacementEffect : res) { if (replacementEffect.isIntrinsic()) { - this.addReplacementEffect(replacementEffect); + addReplacementEffect(replacementEffect); } } } - /** - * Adds the replacement effect. - * - * @param replacementEffect - * the rE - */ public ReplacementEffect addReplacementEffect(final ReplacementEffect replacementEffect) { final ReplacementEffect replacementEffectCopy = replacementEffect.getCopy(); // doubtful - every caller provides a newly parsed instance, why copy? replacementEffectCopy.setHostCard(this); - this.getCharacteristics().getReplacementEffects().add(replacementEffectCopy); + getCharacteristics().getReplacementEffects().add(replacementEffectCopy); return replacementEffectCopy; } /** - * Returns what zone this card was cast from (from what zone it was moved to - * the stack). - * - * @return the castFrom + * Returns what zone this card was cast from (from what zone it was moved to the stack). */ public ZoneType getCastFrom() { - return this.castFrom; + return castFrom; } - - /** - * @param castFrom0 - * the castFrom to set - */ public void setCastFrom(final ZoneType castFrom0) { - this.castFrom = castFrom0; + castFrom = castFrom0; } - /** - * @return CardDamageHistory - */ public CardDamageHistory getDamageHistory() { return damageHistory; } - /** - * @return the effectSource - */ public Card getEffectSource() { return effectSource; } - - /** - * @param src the effectSource to set - */ public void setEffectSource(Card src) { - this.effectSource = src; + effectSource = src; } - /** - * @return the startsGameInPlay - */ public boolean isStartsGameInPlay() { return startsGameInPlay; } - - /** - * @param startsGameInPlay the startsGameInPlay to set - */ - public void setStartsGameInPlay(boolean startsGameInPlay) { - this.startsGameInPlay = startsGameInPlay; + public void setStartsGameInPlay(boolean startsGameInPlay0) { + startsGameInPlay = startsGameInPlay0; } - /** @return boolean */ public boolean isInPlay() { - return this.isInZone(ZoneType.Battlefield); + return isInZone(ZoneType.Battlefield); } public void onCleanupPhase(final Player turn) { @@ -8860,17 +6180,8 @@ public class Card extends GameEntity implements Comparable, IIdentifiable clearBlockedThisTurn(); } - /** - *

- * hasETBTrigger. - *

- * - * @param card - * a {@link forge.game.card.Card} object. - * @return a boolean. - */ public boolean hasETBTrigger() { - for (final Trigger tr : this.getTriggers()) { + for (final Trigger tr : getTriggers()) { final Map params = tr.getMapParams(); if (tr.getMode() != TriggerType.ChangesZone) { continue; @@ -8888,13 +6199,6 @@ public class Card extends GameEntity implements Comparable, IIdentifiable return false; } - /** - *

- * hasETBTrigger. - *

- * - * @return a boolean. - */ public boolean hasETBReplacement() { for (final ReplacementEffect re : getReplacementEffects()) { final Map params = re.getMapParams(); @@ -8917,10 +6221,10 @@ public class Card extends GameEntity implements Comparable, IIdentifiable public boolean canBeShownTo(final Player viewer) { if (viewer == null) { return false; } - Zone zone = this.getZone(); + Zone zone = getZone(); if (zone == null) { return true; } //cards outside any zone are visible to all - final Player controller = this.getController(); + final Player controller = getController(); switch (zone.getZoneType()) { case Ante: case Command: @@ -8957,7 +6261,7 @@ public class Card extends GameEntity implements Comparable, IIdentifiable } // special viewing permissions for viewer - if (this.mayLookAt.contains(viewer)) { + if (mayLookAt.contains(viewer)) { return true; } @@ -8970,7 +6274,7 @@ public class Card extends GameEntity implements Comparable, IIdentifiable } public boolean canCardFaceBeShownTo(final Player viewer) { - if (!this.isFaceDown()) { + if (!isFaceDown()) { return true; } if (viewer.hasKeyword("CanSeeOpponentsFaceDownCards")) { @@ -8978,7 +6282,7 @@ public class Card extends GameEntity implements Comparable, IIdentifiable } // special viewing permissions for viewer - if (this.mayLookAt.contains(viewer)) { + if (mayLookAt.contains(viewer)) { return true; } @@ -8989,13 +6293,6 @@ public class Card extends GameEntity implements Comparable, IIdentifiable return !getController().isOpponentOf(viewer) || hasKeyword("Your opponent may look at this card."); } - /** - *

- * getConvertedManaCost. - *

- * - * @return a int. - */ public int getCMC() { return getCMC(SplitCMCMode.CurrentSideCMC); } @@ -9035,10 +6332,10 @@ public class Card extends GameEntity implements Comparable, IIdentifiable System.out.println(String.format("Illegal Split Card CMC mode %s passed to getCMC!", mode.toString())); break; } - } else { + } + else { requestedCMC = getManaCost().getCMC() + xPaid; } - return requestedCMC; } @@ -9057,7 +6354,6 @@ public class Card extends GameEntity implements Comparable, IIdentifiable return true; } - CardRules cardRules; public CardRules getRules() { return cardRules; } @@ -9066,12 +6362,11 @@ public class Card extends GameEntity implements Comparable, IIdentifiable } public boolean isCommander() { - // TODO - have a field - return this.isCommander; + return isCommander; } public void setCommander(boolean b) { - this.isCommander = b; + isCommander = b; } public void setSplitStateToPlayAbility(SpellAbility sa) { @@ -9118,13 +6413,6 @@ public class Card extends GameEntity implements Comparable, IIdentifiable return null; } - /** - * TODO: Write javadoc for this method. - * @param card - * @param game TODO - * @param player - * @return - */ public List getAllPossibleAbilities(Player player, boolean removeUnplayable) { // this can only be called by the Human @@ -9178,7 +6466,7 @@ public class Card extends GameEntity implements Comparable, IIdentifiable } public IPaperCard getPaperCard() { - IPaperCard cp = this.paperCard; + IPaperCard cp = paperCard; if (cp != null) { return cp; } @@ -9196,7 +6484,6 @@ public class Card extends GameEntity implements Comparable, IIdentifiable /** * Update Card instance for the given PaperCard if any - * @param pc */ public static void updateCard(PaperCard pc) { Card res = cp2card.get(pc); @@ -9204,15 +6491,13 @@ public class Card extends GameEntity implements Comparable, IIdentifiable cp2card.put(pc, fromPaperCard(pc, null)); } } - - /** return staticCommanderList */ + public List getStaticCommandList() { return staticCommandList; } - /** return staticCommanderList */ public void addStaticCommandList(Object[] objects) { - this.staticCommandList.add(objects); + staticCommandList.add(objects); } //allow special cards to override this function to return another card for the sake of UI logic @@ -9227,5 +6512,9 @@ public class Card extends GameEntity implements Comparable, IIdentifiable } return rules != null ? rules.getOracleText() : ""; } - -} // end Card class + + @Override + public CardView getView() { + return view; + } +} diff --git a/forge-game/src/main/java/forge/game/card/CardCharacteristics.java b/forge-game/src/main/java/forge/game/card/CardCharacteristics.java index f499faec069..80d43e25932 100644 --- a/forge-game/src/main/java/forge/game/card/CardCharacteristics.java +++ b/forge-game/src/main/java/forge/game/card/CardCharacteristics.java @@ -31,8 +31,10 @@ import forge.game.trigger.Trigger; import java.util.ArrayList; import java.util.List; import java.util.Map; +import java.util.Set; import java.util.TreeMap; import java.util.concurrent.CopyOnWriteArrayList; +import java.util.concurrent.CopyOnWriteArraySet; /** * TODO: Write javadoc for this type. @@ -40,7 +42,7 @@ import java.util.concurrent.CopyOnWriteArrayList; */ public class CardCharacteristics { private String name = ""; - private List type = new CopyOnWriteArrayList(); + private Set type = new CopyOnWriteArraySet(); private ManaCost manaCost = ManaCost.NO_COST; private List cardColor = new ArrayList(); private String oracleText = ""; @@ -84,7 +86,7 @@ public class CardCharacteristics { * * @return the type */ - public final List getType() { + public final Set getType() { return this.type; } @@ -438,7 +440,7 @@ public class CardCharacteristics { // String name : just copy reference this.name = source.getName(); // ArrayList type : list of String objects so use copy constructor - this.type = new CopyOnWriteArrayList(source.getType()); + this.type = new CopyOnWriteArraySet(source.getType()); // CardManaCost manaCost : not sure if a deep copy is needed this.manaCost = source.getManaCost(); // ArrayList cardColor : not sure if a deep copy is needed diff --git a/forge-game/src/main/java/forge/game/card/CardFactory.java b/forge-game/src/main/java/forge/game/card/CardFactory.java index b98e748b29b..1a8c186af46 100644 --- a/forge-game/src/main/java/forge/game/card/CardFactory.java +++ b/forge-game/src/main/java/forge/game/card/CardFactory.java @@ -75,9 +75,9 @@ public class CardFactory { Card out; if (!(in.isToken() || in.getCopiedPermanent() != null)) { out = assignNewId ? getCard(in.getPaperCard(), in.getOwner()) - : getCard(in.getPaperCard(), in.getOwner(), in.getUniqueNumber()); + : getCard(in.getPaperCard(), in.getOwner(), in.getId()); } else { // token - out = assignNewId ? new Card(in.getGame().nextCardId(), in.getPaperCard()) : new Card(in.getUniqueNumber(), in.getPaperCard()); + out = assignNewId ? new Card(in.getGame().nextCardId(), in.getPaperCard()) : new Card(in.getId(), in.getPaperCard()); out = CardFactory.copyStats(in, in.getController()); out.setToken(true); @@ -148,7 +148,7 @@ public class CardFactory { String tmp = ""; final String newColor = sourceSA.getParam("CopyIsColor"); if (newColor.equals("ChosenColor")) { - tmp = CardUtil.getShortColorsString(source.getChosenColor()); + tmp = CardUtil.getShortColorsString(source.getChosenColors()); } else { tmp = CardUtil.getShortColorsString(new ArrayList(Arrays.asList(newColor.split(",")))); } @@ -356,20 +356,19 @@ public class CardFactory { } private static Card readCard(final CardRules rules, final IPaperCard paperCard, int cardId) { - final Card card = new Card(cardId, paperCard); // 1. The states we may have: CardSplitType st = rules.getSplitType(); - if ( st == CardSplitType.Split) { - card.addAlternateState(CardCharacteristicName.LeftSplit); + if (st == CardSplitType.Split) { + card.addAlternateState(CardCharacteristicName.LeftSplit, false); card.setState(CardCharacteristicName.LeftSplit); } readCardFace(card, rules.getMainPart()); - if ( st != CardSplitType.None) { - card.addAlternateState(st.getChangedStateName()); + if (st != CardSplitType.None) { + card.addAlternateState(st.getChangedStateName(), false); card.setState(st.getChangedStateName()); readCardFace(card, rules.getOtherPart()); } @@ -570,7 +569,7 @@ public class CardFactory { // get CardCharacteristics for desired state if (!to.getStates().contains(toState)) { - to.addAlternateState(toState); + to.addAlternateState(toState, true); } final CardCharacteristics toCharacteristics = to.getState(toState), fromCharacteristics = from.getState(fromState); @@ -590,7 +589,7 @@ public class CardFactory { final CardCharacteristics fromCharacteristics = from.getState(fromState); final CardCharacteristicName oldToState = to.getCurState(); if (!to.getStates().contains(toState)) { - to.addAlternateState(toState); + to.addAlternateState(toState, false); } to.setState(toState); @@ -688,7 +687,7 @@ public class CardFactory { t.setTriggeringObjects(trig); trig.setTriggerRemembered(t.getTriggerRemembered()); if (t.getStoredTriggeredObjects() != null) { - trig.setAllTriggeringObjects(t.getStoredTriggeredObjects()); + trig.setTriggeringObjects(t.getStoredTriggeredObjects()); } trig.setActivatingPlayer(sa.getActivatingPlayer()); diff --git a/forge-game/src/main/java/forge/game/card/CardFactoryUtil.java b/forge-game/src/main/java/forge/game/card/CardFactoryUtil.java index a41acc359d8..0ed389c7e4d 100644 --- a/forge-game/src/main/java/forge/game/card/CardFactoryUtil.java +++ b/forge-game/src/main/java/forge/game/card/CardFactoryUtil.java @@ -1159,7 +1159,7 @@ public class CardFactoryUtil { ZoneType sourceZone = sq[0].contains("ChromaInGrave") ? ZoneType.Graveyard : ZoneType.Battlefield; String colorName = sq[1]; if (colorName.contains("Chosen")) { - colorName = MagicColor.toShortString(c.getChosenColor().get(0)); + colorName = MagicColor.toShortString(c.getChosenColors().get(0)); } final List cards; if (sq[0].contains("ChromaSource")) { // Runs Chroma for passed in Source card @@ -1250,7 +1250,7 @@ public class CardFactoryUtil { if (sq[0].contains("CardManaCost")) { Card ce; if (sq[0].contains("Equipped") && c.isEquipping()) { - ce = c.getEquipping().get(0); + ce = c.getEquipping(); } else if (sq[0].contains("Remembered")) { ce = (Card) c.getRemembered().get(0); @@ -2027,7 +2027,7 @@ public class CardFactoryUtil { final int magnitude = Integer.parseInt(s); String description = String.format("Bushido %d (When this blocks or becomes blocked, it gets +%d/+%d until end of turn).", magnitude, magnitude, magnitude); - String regularPart = String.format("AB$ Pump | Cost$ 0 | Defined$ CardUID_%d | NumAtt$ +%d | NumDef$ +%d | StackDescription$ %s", c.getUniqueNumber(), magnitude, magnitude, description); + String regularPart = String.format("AB$ Pump | Cost$ 0 | Defined$ CardUID_%d | NumAtt$ +%d | NumDef$ +%d | StackDescription$ %s", c.getId(), magnitude, magnitude, description); SpellAbility ability = AbilityFactory.getAbility(regularPart, c); ability.setDescription(ability.getStackDescription()); diff --git a/forge-game/src/main/java/forge/game/card/CardUtil.java b/forge-game/src/main/java/forge/game/card/CardUtil.java index a91670ae200..2520b411d0d 100644 --- a/forge-game/src/main/java/forge/game/card/CardUtil.java +++ b/forge-game/src/main/java/forge/game/card/CardUtil.java @@ -213,14 +213,13 @@ public final class CardUtil { * @return a copy of C with LastKnownInfo stuff retained. */ public static Card getLKICopy(final Card in) { - - final Card newCopy = new Card(in.getUniqueNumber(), in.getPaperCard()); + final Card newCopy = new Card(in.getId(), in.getPaperCard()); newCopy.setCurSetCode(in.getCurSetCode()); newCopy.setOwner(in.getOwner()); newCopy.setController(in.getController(), 0); newCopy.getCharacteristics().copyFrom(in.getState(in.getCurState())); if (in.isCloned()) { - newCopy.addAlternateState(CardCharacteristicName.Cloner); + newCopy.addAlternateState(CardCharacteristicName.Cloner, false); } newCopy.setType(new ArrayList(in.getType())); newCopy.setToken(in.isToken()); @@ -245,9 +244,9 @@ public final class CardUtil { newCopy.getDamageHistory().setCreatureGotBlockedThisTurn(in.getDamageHistory().getCreatureGotBlockedThisTurn()); newCopy.setEnchanting(in.getEnchanting()); newCopy.setEnchantedBy(new ArrayList (in.getEnchantedBy())); - newCopy.setEquipping(new ArrayList (in.getEquipping())); + newCopy.setEquipping(in.getEquipping()); newCopy.setEquippedBy(new ArrayList (in.getEquippedBy())); - newCopy.setFortifying(new ArrayList (in.getFortifying())); + newCopy.setFortifying(in.getFortifying()); newCopy.setFortifiedBy(new ArrayList (in.getFortifiedBy())); newCopy.setClones(in.getClones()); newCopy.setHaunting(in.getHaunting()); diff --git a/forge-game/src/main/java/forge/game/card/CardView.java b/forge-game/src/main/java/forge/game/card/CardView.java new file mode 100644 index 00000000000..6ded2a15d28 --- /dev/null +++ b/forge-game/src/main/java/forge/game/card/CardView.java @@ -0,0 +1,625 @@ +package forge.game.card; + +import java.util.Set; +import java.util.List; +import java.util.Map; + +import org.apache.commons.lang3.StringUtils; + +import com.google.common.base.Predicates; +import com.google.common.collect.Iterables; + +import forge.card.CardCharacteristicName; +import forge.card.CardRarity; +import forge.card.CardType; +import forge.card.ColorSet; +import forge.card.mana.ManaCost; +import forge.game.GameEntityView; +import forge.game.player.PlayerView; +import forge.game.zone.ZoneType; +import forge.trackable.TrackableCollection; +import forge.trackable.TrackableObject; +import forge.trackable.TrackableProperty.CardProp; +import forge.trackable.TrackableProperty.CardStateProp; + + +public class CardView extends GameEntityView { + public static CardView get(Card c) { + return c == null ? null : c.getView(); + } + + public static TrackableCollection getCollection(Iterable cards) { + if (cards == null) { + return null; + } + TrackableCollection collection = new TrackableCollection(); + for (Card c : cards) { + collection.add(c.getView()); + } + return collection; + } + + public CardView(int id0) { + super(id0, CardProp.class); + set(CardProp.Original, new CardStateView(id0)); + } + + public PlayerView getOwner() { + return get(CardProp.Owner); + } + void updateOwner(Card c) { + set(CardProp.Owner, PlayerView.get(c.getOwner())); + } + + public PlayerView getController() { + return get(CardProp.Controller); + } + void updateController(Card c) { + set(CardProp.Owner, PlayerView.get(c.getController())); + } + + public ZoneType getZone() { + return get(CardProp.Zone); + } + void updateZone(Card c) { + set(CardProp.Zone, c.getZone() == null ? null : c.getZone().getZoneType()); + } + + public boolean isCloned() { + return get(CardProp.Cloned); + } + + public boolean isFaceDown() { + return get(CardProp.FaceDown); + } + + public boolean isFlipCard() { + return get(CardProp.FlipCard); + } + + public boolean isFlipped() { + return get(CardProp.Flipped); + } + + public boolean isSplitCard() { + return get(CardProp.SplitCard); + } + + public boolean isTransformed() { + return get(CardProp.Transformed); + } + + public String getSetCode() { + return get(CardProp.SetCode); + } + void updateSetCode(Card c) { + set(CardProp.SetCode, c.getCurSetCode()); + } + + public CardRarity getRarity() { + return get(CardProp.Rarity); + } + void updateRarity(Card c) { + set(CardProp.Rarity, c.getRarity()); + } + + public boolean isAttacking() { + return get(CardProp.Attacking); + } + void updateAttacking(Card c) { + set(CardProp.Attacking, c.getGame().getCombat().isAttacking(c)); + } + + public boolean isBlocking() { + return get(CardProp.Blocking); + } + void updateBlocking(Card c) { + set(CardProp.Blocking, c.getGame().getCombat().isBlocking(c)); + } + + public boolean isPhasedOut() { + return get(CardProp.PhasedOut); + } + void updatePhasedOut(Card c) { + set(CardProp.PhasedOut, c.isPhasedOut()); + } + + public boolean isFirstTurnControlled() { + return get(CardProp.Sickness); + } + public boolean hasSickness() { + return isFirstTurnControlled() && !getOriginal().hasHaste(); + } + public boolean isSick() { + return getZone() == ZoneType.Battlefield && hasSickness(); + } + void updateSickness(Card c) { + set(CardProp.Sickness, c.isInPlay() && c.isSick()); + } + + public boolean isTapped() { + return get(CardProp.Tapped); + } + void updateTapped(Card c) { + set(CardProp.Tapped, c.isTapped()); + } + + public boolean isToken() { + return get(CardProp.Token); + } + void updateToken(Card c) { + set(CardProp.Token, c.isToken()); + } + + public Map getCounters() { + return get(CardProp.Counters); + } + void updateCounters(Card c) { + set(CardProp.Counters, c.getCounters()); + } + + public int getDamage() { + return get(CardProp.Damage); + } + void updateDamage(Card c) { + set(CardProp.Damage, c.getDamage()); + } + + public int getAssignedDamage() { + return get(CardProp.AssignedDamage); + } + void updateAssignedDamage(Card c) { + set(CardProp.AssignedDamage, c.getTotalAssignedDamage()); + } + + public int getLethalDamage() { + return getOriginal().getToughness() - getDamage() - getAssignedDamage(); + } + + public int getShieldCount() { + return get(CardProp.ShieldCount); + } + void updateShieldCount(Card c) { + set(CardProp.ShieldCount, c.getShieldCount()); + } + + public String getChosenType() { + return get(CardProp.ChosenType); + } + void updateChosenType(Card c) { + set(CardProp.ChosenType, c.getChosenType()); + } + + public List getChosenColors() { + return get(CardProp.ChosenColors); + } + void updateChosenColors(Card c) { + set(CardProp.ChosenColors, c.getChosenColors()); + } + + public PlayerView getChosenPlayer() { + return get(CardProp.ChosenPlayer); + } + void updateChosenPlayer(Card c) { + set(CardProp.ChosenPlayer, c.getChosenPlayer()); + } + + public String getNamedCard() { + return get(CardProp.NamedCard); + } + void updateNamedCard(Card c) { + set(CardProp.NamedCard, c.getNamedCard()); + } + + public CardView getEquipping() { + return get(CardProp.Equipping); + } + void updateEquipping(Card c) { + set(CardProp.Equipping, CardView.get(c.getEquipping())); + } + + public Iterable getEquippedBy() { + return get(CardProp.EquippedBy); + } + void updateEquippedBy(Card c) { + set(CardProp.EquippedBy, CardView.getCollection(c.getEquippedBy())); + } + + public boolean isEquipped() { + return getEquippedBy() != null; + } + + public GameEntityView getEnchanting() { + return get(CardProp.Enchanting); + } + void updateEnchanting(Card c) { + set(CardProp.Owner, GameEntityView.get(c.getEnchanting())); + } + + public CardView getEnchantingCard() { + GameEntityView enchanting = getEnchanting(); + if (enchanting instanceof CardView) { + return (CardView) enchanting; + } + return null; + } + public PlayerView getEnchantingPlayer() { + GameEntityView enchanting = getEnchanting(); + if (enchanting instanceof PlayerView) { + return (PlayerView) enchanting; + } + return null; + } + + public Iterable getEnchantedBy() { + return get(CardProp.EnchantedBy); + } + void updateEnchantedBy(Card c) { + set(CardProp.EnchantedBy, CardView.getCollection(c.getEnchantedBy())); + } + + public boolean isEnchanted() { + return getEnchantedBy() != null; + } + + public CardView getFortifying() { + return get(CardProp.Fortifying); + } + void updateFortifying(Card c) { + set(CardProp.Fortifying, c.getFortifying()); + } + + public Iterable getFortifiedBy() { + return get(CardProp.FortifiedBy); + } + void updateFortifiedBy(Card c) { + set(CardProp.FortifiedBy, CardView.getCollection(c.getFortifiedBy())); + } + + public boolean isFortified() { + return getFortifiedBy() != null; + } + + public Iterable getGainControlTargets() { + return get(CardProp.GainControlTargets); + } + void updateGainControlTargets(Card c) { + set(CardProp.GainControlTargets, CardView.getCollection(c.getGainControlTargets())); + } + + public CardView getCloneOrigin() { + return get(CardProp.CloneOrigin); + } + void updateCloneOrigin(Card c) { + set(CardProp.CloneOrigin, CardView.get(c.getCloneOrigin())); + } + + public Iterable getImprinted() { + return get(CardProp.Imprinted); + } + void updateImprinted(Card c) { + set(CardProp.Imprinted, CardView.getCollection(c.getImprinted())); + } + + public Iterable getHauntedBy() { + return get(CardProp.HauntedBy); + } + void updateHauntedBy(Card c) { + set(CardProp.HauntedBy, CardView.getCollection(c.getHauntedBy())); + } + + public CardView getHaunting() { + return get(CardProp.Haunting); + } + void updateHaunting(Card c) { + set(CardProp.Haunting, CardView.get(c.getHaunting())); + } + + public Iterable getMustBlock() { + return get(CardProp.MustBlock); + } + void updateHaunting(CardView haunting) { + set(CardProp.MustBlock, haunting); + } + + public CardView getPairedWith() { + return get(CardProp.PairedWith); + } + void updatePairedWith(Card c) { + set(CardProp.PairedWith, CardView.get(c.getPairedWith())); + } + + public CardStateView getOriginal() { + return get(CardProp.Original); + } + + public CardStateView getAlternate() { + return get(CardProp.Alternate); + } + + public CardStateView getState(final boolean alternate0) { + return alternate0 ? getAlternate() : getOriginal(); + } + void updateState(Card c, boolean fromCurStateChange) { + boolean isDoubleFaced = c.isDoubleFaced(); + boolean isFaceDown = c.isFaceDown(); + boolean isFlipCard = c.isFlipCard(); + boolean isFlipped = c.getCurState() == CardCharacteristicName.Flipped; + boolean isSplitCard = c.isSplitCard(); + boolean isTransformed = c.getCurState() == CardCharacteristicName.Transformed; + boolean hasAltState = isDoubleFaced || isFlipCard || isSplitCard || (isFaceDown/* && mayShowCardFace*/); + + set(CardProp.Alternate, hasAltState ? new CardStateView(getId()) : null); + set(CardProp.Cloned, c.isCloned()); + set(CardProp.FaceDown, isFaceDown); + set(CardProp.SplitCard, isSplitCard); + set(CardProp.FlipCard, isFlipCard); + + if (fromCurStateChange) { + set(CardProp.Flipped, isFlipped); + set(CardProp.Transformed, isTransformed); + updateRarity(c); //rarity and set based on current state + updateSetCode(c); + } + + if (isSplitCard) { + final CardCharacteristicName orig, alt; + if (c.getCurState() == CardCharacteristicName.RightSplit) { + // If right half on stack, place it first + orig = CardCharacteristicName.RightSplit; + alt = CardCharacteristicName.LeftSplit; + } + else { + orig = CardCharacteristicName.LeftSplit; + alt = CardCharacteristicName.RightSplit; + } + updateState(c, getOriginal(), orig); + updateState(c, getAlternate(), alt); + return; + } + + final CardStateView origView = getOriginal(); + origView.updateName(c); + origView.updateColors(c); + origView.updateImageKey(c); + origView.updateType(c); + origView.updateManaCost(c); + origView.updatePower(c); + origView.updateToughness(c); + origView.updateLoyalty(c); + origView.updateText(c); + origView.updateChangedColorWords(c); + origView.updateChangedTypes(c); + origView.updateManaCost(c); + origView.updateKeywords(c); + origView.updateFoilIndex(c); + + if (hasAltState) { + if (isFlipCard && !isFlipped) { + updateState(c, getAlternate(), CardCharacteristicName.Flipped); + } + else if (isDoubleFaced && !isTransformed) { + updateState(c, getAlternate(), CardCharacteristicName.Transformed); + } + else { + updateState(c, getAlternate(), CardCharacteristicName.Original); + } + } + } + private void updateState(Card c, CardStateView view, CardCharacteristicName state) { + final CardCharacteristics chars = c.getState(state); + view.updateName(chars); + view.updateColors(chars); + view.updateImageKey(chars); + view.updateType(chars); + view.updateManaCost(chars); + view.updatePower(chars); + view.updateToughness(chars); + view.updateLoyalty(chars); + view.updateText(chars); + view.updateFoilIndex(chars); + } + + @Override + public String toString() { + if (getId() <= 0) { //if fake card, just return name + return getOriginal().getName(); + } + + /*if (!mayBeShown) { + return "(Unknown card)"; + }*/ + + if (StringUtils.isEmpty(getOriginal().getName())) { + CardStateView alternate = getAlternate(); + if (alternate != null) { + return "Face-down card (" + getAlternate().getName() + ")"; + } + return "(" + getId() + ")"; + } + return getOriginal().getName() + " (" + getId() + ")"; + } + + public String determineName(final CardStateView state) { + if (state == getOriginal()) { + return toString(); + } + return getAlternate().getName() + " (" + getId() + ")"; + } + + public class CardStateView extends TrackableObject { + public CardStateView(int id0) { + super(id0, CardStateProp.class); + } + + @Override + public String toString() { + return getCard().determineName(this); + } + + public CardView getCard() { + return CardView.this; + } + + public String getName() { + return get(CardStateProp.Name); + } + void updateName(Card c) { + set(CardStateProp.Name, c.getName()); + } + void updateName(CardCharacteristics c) { + set(CardStateProp.Name, c.getName()); + } + + public ColorSet getColors() { + return get(CardStateProp.Colors); + } + void updateColors(Card c) { + set(CardStateProp.Colors, c.determineColor()); + } + void updateColors(CardCharacteristics c) { + set(CardStateProp.Colors, c.determineColor()); + } + + public String getImageKey() { + return get(CardStateProp.ImageKey); + } + void updateImageKey(Card c) { + set(CardStateProp.ImageKey, c.getImageKey()); + } + void updateImageKey(CardCharacteristics c) { + set(CardStateProp.ImageKey, c.getImageKey()); + } + + public Set getType() { + return get(CardStateProp.Type); + } + void updateType(Card c) { + set(CardStateProp.Type, c.getType()); + } + void updateType(CardCharacteristics c) { + set(CardStateProp.Type, c.getType()); + } + + public ManaCost getManaCost() { + return get(CardStateProp.ManaCost); + } + void updateManaCost(Card c) { + set(CardStateProp.ManaCost, c.getManaCost()); + } + void updateManaCost(CardCharacteristics c) { + set(CardStateProp.ManaCost, c.getManaCost()); + } + + public int getPower() { + return get(CardStateProp.Power); + } + void updatePower(Card c) { + set(CardStateProp.Power, c.getNetAttack()); + } + void updatePower(CardCharacteristics c) { + set(CardStateProp.Power, c.getBaseAttack()); + } + + public int getToughness() { + return get(CardStateProp.Toughness); + } + void updateToughness(Card c) { + set(CardStateProp.Toughness, c.getNetDefense()); + } + void updateToughness(CardCharacteristics c) { + set(CardStateProp.Toughness, c.getBaseDefense()); + } + + public int getLoyalty() { + return get(CardStateProp.Loyalty); + } + void updateLoyalty(Card c) { + set(CardStateProp.Loyalty, c.getCurrentLoyalty()); + } + void updateLoyalty(CardCharacteristics c) { + set(CardStateProp.Loyalty, 0); // Q why is loyalty not a property of CardCharacteristic? A: because no alt states have a base loyalty (only candidate is Garruk Relentless). + } + + public String getText() { + return get(CardStateProp.Text); + } + void updateText(Card c) { + set(CardStateProp.Text, c.getText()); + } + void updateText(CardCharacteristics c) { + set(CardStateProp.Text, c.getOracleText()); + } + + public int getFoilIndex() { + return get(CardStateProp.FoilIndex); + } + void updateFoilIndex(Card c) { + set(CardStateProp.FoilIndex, c.getCharacteristics().getFoil()); + } + void updateFoilIndex(CardCharacteristics c) { + set(CardStateProp.FoilIndex, c.getFoil()); + } + + public Map getChangedColorWords() { + return get(CardStateProp.ChangedColorWords); + } + void updateChangedColorWords(Card c) { + set(CardStateProp.ChangedColorWords, c.getChangedTextColorWords()); + } + + public Map getChangedTypes() { + return get(CardStateProp.ChangedTypes); + } + void updateChangedTypes(Card c) { + set(CardStateProp.ChangedTypes, c.getChangedTextTypeWords()); + } + + public boolean hasDeathtouch() { + return get(CardStateProp.HasDeathtouch); + } + public boolean hasHaste() { + return get(CardStateProp.HasHaste); + } + public boolean hasInfect() { + return get(CardStateProp.HasInfect); + } + public boolean hasStorm() { + return get(CardStateProp.HasStorm); + } + public boolean hasTrample() { + return get(CardStateProp.HasTrample); + } + void updateKeywords(Card c) { + set(CardStateProp.HasDeathtouch, c.hasKeyword("Deathtouch")); + set(CardStateProp.HasHaste, c.hasKeyword("Haste")); + set(CardStateProp.HasInfect, c.hasKeyword("Infect")); + set(CardStateProp.HasStorm, c.hasKeyword("Storm")); + set(CardStateProp.HasTrample, c.hasKeyword("Trample")); + } + + public boolean isBasicLand() { + return isLand() && Iterables.any(getType(), Predicates.in(CardType.getBasicTypes())); + } + public boolean isCreature() { + return getType().contains("Creature"); + } + public boolean isLand() { + return getType().contains("Land"); + } + public boolean isPlane() { + return getType().contains("Plane"); + } + public boolean isPhenomenon() { + return getType().contains("Phenomenon"); + } + public boolean isPlaneswalker() { + return getType().contains("Planeswalker"); + } + } + + @Override + protected CardProp preventNextDamageProp() { + return CardProp.PreventNextDamage; + } +} diff --git a/forge-game/src/main/java/forge/game/combat/Combat.java b/forge-game/src/main/java/forge/game/combat/Combat.java index 34ba2b70a82..c29b80604fe 100644 --- a/forge-game/src/main/java/forge/game/combat/Combat.java +++ b/forge-game/src/main/java/forge/game/combat/Combat.java @@ -278,9 +278,9 @@ public class Combat { if (source.isAura()) { attacker = source.getEnchantingCard(); } else if (source.isEquipment()) { - attacker = source.getEquippingCard(); + attacker = source.getEquipping(); } else if (source.isFortification()) { - attacker = source.getFortifyingCard(); + attacker = source.getFortifying(); } // return the corresponding defender diff --git a/forge-game/src/main/java/forge/game/combat/CombatUtil.java b/forge-game/src/main/java/forge/game/combat/CombatUtil.java index 3a19a23f559..ddd6e4c1268 100644 --- a/forge-game/src/main/java/forge/game/combat/CombatUtil.java +++ b/forge-game/src/main/java/forge/game/combat/CombatUtil.java @@ -634,7 +634,7 @@ public class CombatUtil { final String parse = blocker.getKeyword().get(keywordPosition).toString(); if (parse.startsWith("CantBlockCardUID")) { final String[] k = parse.split("_", 2); - if (attacker.getUniqueNumber() == Integer.parseInt(k[1])) { + if (attacker.getId() == Integer.parseInt(k[1])) { return false; } } else { @@ -999,7 +999,7 @@ public class CombatUtil { // Rule 702.23b: If a creature has multiple instances of flanking, each triggers separately. for( int i = 0; i < flankingMagnitude; i++ ) { - String effect = String.format("AB$ Pump | Cost$ 0 | Defined$ CardUID_%d | NumAtt$ -1 | NumDef$ -1 | ", blocker.getUniqueNumber()); + String effect = String.format("AB$ Pump | Cost$ 0 | Defined$ CardUID_%d | NumAtt$ -1 | NumDef$ -1 | ", blocker.getId()); String desc = String.format("StackDescription$ Flanking (The blocking %s gets -1/-1 until end of turn)", blocker.getName()); SpellAbility ability = AbilityFactory.getAbility(effect + desc, attacker); @@ -1031,7 +1031,7 @@ public class CombatUtil { private static void executeRampageAbility(final Game game, final Card c, final int magnitude, final int numBlockers) { // numBlockers starts with 1 since it is for every creature beyond the first for (int i = 1; i < numBlockers; i++) { - String effect = "AB$ Pump | Cost$ 0 | " + c.getUniqueNumber() + " | NumAtt$ " + magnitude + " | NumDef$ " + magnitude + " | "; + String effect = "AB$ Pump | Cost$ 0 | " + c.getId() + " | NumAtt$ " + magnitude + " | NumDef$ " + magnitude + " | "; String desc = "StackDescription$ Rampage " + magnitude + " (Whenever CARDNAME becomes blocked, it gets +" + magnitude + "/+" + magnitude + " until end of turn for each creature blocking it beyond the first.)"; diff --git a/forge-game/src/main/java/forge/game/combat/CombatView.java b/forge-game/src/main/java/forge/game/combat/CombatView.java new file mode 100644 index 00000000000..050ac60a235 --- /dev/null +++ b/forge-game/src/main/java/forge/game/combat/CombatView.java @@ -0,0 +1,150 @@ +package forge.game.combat; + +import java.util.ArrayList; +import java.util.List; +import java.util.Map; +import java.util.Map.Entry; + +import com.google.common.collect.Iterables; +import com.google.common.collect.Lists; +import com.google.common.collect.Sets; + +import forge.game.GameEntityView; +import forge.game.card.CardView; +import forge.trackable.TrackableObject; +import forge.trackable.TrackableProperty.CombatProp; + + +public class CombatView extends TrackableObject { + public CombatView() { + super(-1, CombatProp.class); //ID not needed + } + private Map> getAttackersWithDefenders() { + return get(CombatProp.AttackersWithDefenders); + } + private Map> getAttackersWithBlockers() { + return get(CombatProp.AttackersWithBlockers); + } + private Map, GameEntityView> getBandsWithDefenders() { + return get(CombatProp.BandsWithDefenders); + } + private Map, Iterable> getBandsWithBlockers() { + return get(CombatProp.BandsWithBlockers); + } + private Map> getAttackersWithPlannedBlockers() { + return get(CombatProp.AttackersWithPlannedBlockers); + } + private Map, Iterable> getBandsWithPlannedBlockers() { + return get(CombatProp.BandsWithPlannedBlockers); + } + + public int getNumAttackers() { + return getAttackersWithDefenders().size(); + } + + public boolean isAttacking(final CardView card) { + return getAttackersWithDefenders().containsKey(card); + } + + public Iterable getAttackers() { + return getAttackersWithDefenders().keySet(); + } + + public Iterable> getDefenders() { + return Sets.newHashSet(getAttackersWithDefenders().values()); + } + + public GameEntityView getDefender(final CardView attacker) { + return getAttackersWithDefenders().get(attacker); + } + + public boolean isBlocking(final CardView card) { + for (final Iterable blockers : getAttackersWithBlockers().values()) { + if (blockers == null) { + continue; + } + if (Iterables.contains(blockers, card)) { + return true; + } + } + return false; + } + + /** + * @param attacker + * @return the blockers associated with an attacker, or {@code null} if the + * attacker is unblocked. + */ + public Iterable getBlockers(final CardView attacker) { + return getAttackersWithBlockers().get(attacker); + } + + /** + * @param attacker + * @return the blockers associated with an attacker, or {@code null} if the + * attacker is unblocked (planning stage, for targeting overlay). + */ + public Iterable getPlannedBlockers(final CardView attacker) { + return getAttackersWithPlannedBlockers().get(attacker); + } + + /** + * Get an {@link Iterable} of the blockers of the specified band, or + * {@code null} if that band is unblocked. + * + * @param attackingBand + * an {@link Iterable} representing an attacking band. + * @return an {@link Iterable} of {@link CardView} objects, or {@code null}. + */ + public Iterable getBlockers(final Iterable attackingBand) { + return getBandsWithBlockers().get(attackingBand); + } + + /** + * Get an {@link Iterable} of the blockers of the specified band, or + * {@code null} if that band is unblocked (planning stage, for targeting overlay). + * + * @param attackingBand + * an {@link Iterable} representing an attacking band. + * @return an {@link Iterable} of {@link CardView} objects, or {@code null}. + */ + public Iterable getPlannedBlockers(final Iterable attackingBand) { + return getBandsWithPlannedBlockers().get(attackingBand); + } + + public Iterable getAttackersOf(final GameEntityView defender) { + ArrayList views = new ArrayList(); + for (Entry> entry : getAttackersWithDefenders().entrySet()) { + if (entry.getValue().equals(defender)) { + views.add(entry.getKey()); + } + } + return views; + } + public Iterable> getAttackingBandsOf(final GameEntityView defender) { + ArrayList> views = new ArrayList>(); + for (Entry, GameEntityView> entry : getBandsWithDefenders().entrySet()) { + if (entry.getValue().equals(defender)) { + views.add(entry.getKey()); + } + } + return views; + } + + public void addAttackingBand(final Iterable attackingBand, final GameEntityView defender, final Iterable blockers, final Iterable plannedBlockers) { + final List attackingBandCopy = Lists.newArrayList(attackingBand), + blockersCopy, plannedBlockersCopy; + + blockersCopy = blockers == null ? null : Lists.newArrayList(blockers); + plannedBlockersCopy = plannedBlockers == null ? null : Lists.newArrayList(plannedBlockers); + + for (final CardView attacker : attackingBandCopy) { + this.getAttackersWithDefenders().put(attacker, defender); + this.getAttackersWithBlockers().put(attacker, blockersCopy); + this.getAttackersWithPlannedBlockers().put(attacker, plannedBlockersCopy); + } + this.getBandsWithDefenders().put(attackingBandCopy, defender); + this.getBandsWithBlockers().put(attackingBandCopy, blockersCopy); + this.getBandsWithPlannedBlockers().put(attackingBandCopy, plannedBlockersCopy); + } +} diff --git a/forge-game/src/main/java/forge/game/cost/CostUnattach.java b/forge-game/src/main/java/forge/game/cost/CostUnattach.java index a03fc5e30bf..7f00c0ff789 100644 --- a/forge-game/src/main/java/forge/game/cost/CostUnattach.java +++ b/forge-game/src/main/java/forge/game/cost/CostUnattach.java @@ -111,7 +111,7 @@ public class CostUnattach extends CostPartWithList { */ @Override protected Card doPayment(SpellAbility ability, Card targetCard) { - targetCard.unEquipCard(targetCard.getEquipping().get(0)); + targetCard.unEquipCard(targetCard.getEquipping()); return targetCard; } diff --git a/forge-game/src/main/java/forge/game/io/GameStateSerializer.java b/forge-game/src/main/java/forge/game/io/GameStateSerializer.java index c3444e97f96..6ec40a6226b 100644 --- a/forge-game/src/main/java/forge/game/io/GameStateSerializer.java +++ b/forge-game/src/main/java/forge/game/io/GameStateSerializer.java @@ -58,7 +58,7 @@ public class GameStateSerializer { public void write(Card card) { if (card == null) { return; } - int key = card.getUniqueNumber(); + int key = card.getId(); cards.put(key, card); write(key); //only write info for each card once at end of file } diff --git a/forge-game/src/main/java/forge/game/phase/PhaseHandler.java b/forge-game/src/main/java/forge/game/phase/PhaseHandler.java index 464df2610f5..f088b330f87 100644 --- a/forge-game/src/main/java/forge/game/phase/PhaseHandler.java +++ b/forge-game/src/main/java/forge/game/phase/PhaseHandler.java @@ -518,7 +518,7 @@ public class PhaseHandler implements java.io.Serializable, IGameStateObject { int exaltedMagnitude = card.getKeywordAmount("Exalted"); for (int i = 0; i < exaltedMagnitude; i++) { - String abScript = String.format("AB$ Pump | Cost$ 0 | Defined$ CardUID_%d | NumAtt$ +1 | NumDef$ +1 | StackDescription$ Exalted for attacker {c:CardUID_%d} (Whenever a creature you control attacks alone, that creature gets +1/+1 until end of turn).", attacker.getUniqueNumber(), attacker.getUniqueNumber()); + String abScript = String.format("AB$ Pump | Cost$ 0 | Defined$ CardUID_%d | NumAtt$ +1 | NumDef$ +1 | StackDescription$ Exalted for attacker {c:CardUID_%d} (Whenever a creature you control attacks alone, that creature gets +1/+1 until end of turn).", attacker.getId(), attacker.getId()); SpellAbility ability = AbilityFactory.getAbility(abScript, card); ability.setActivatingPlayer(card.getController()); ability.setDescription(ability.getStackDescription()); diff --git a/forge-game/src/main/java/forge/game/phase/Untap.java b/forge-game/src/main/java/forge/game/phase/Untap.java index 7a974fde48f..7fcf56df368 100644 --- a/forge-game/src/main/java/forge/game/phase/Untap.java +++ b/forge-game/src/main/java/forge/game/phase/Untap.java @@ -257,11 +257,11 @@ public class Untap extends Phase { continue; } } else if (c.isEquipment() && c.isEquipping()) { - if (list.contains(c.getEquippingCard())) { + if (list.contains(c.getEquipping())) { continue; } } else if (c.isFortification() && c.isFortifying()) { - if (list.contains(c.getFortifyingCard())) { + if (list.contains(c.getFortifying())) { continue; } } diff --git a/forge-game/src/main/java/forge/game/player/Player.java b/forge-game/src/main/java/forge/game/player/Player.java index bc6f59c48cc..2410625bcf4 100644 --- a/forge-game/src/main/java/forge/game/player/Player.java +++ b/forge-game/src/main/java/forge/game/player/Player.java @@ -71,68 +71,33 @@ import java.util.concurrent.ConcurrentSkipListMap; * @version $Id$ */ public class Player extends GameEntity implements Comparable, IIdentifiable { + public static final List ALL_ZONES = Collections.unmodifiableList(Arrays.asList(ZoneType.Battlefield, + ZoneType.Library, ZoneType.Graveyard, ZoneType.Hand, ZoneType.Exile, ZoneType.Command, ZoneType.Ante, + ZoneType.Sideboard, ZoneType.PlanarDeck, ZoneType.SchemeDeck)); + private final int id; private final Map commanderDamage = new HashMap(); - /** The poison counters. */ private int poisonCounters = 0; - - /** The life. */ private int life = 20; - - /** The life this player started the game with. */ private int startingLife = 20; - - /** The assigned damage. */ private final Map assignedDamage = new HashMap(); - - /** Number of spells cast this turn. */ private int spellsCastThisTurn = 0; - - /** The life lost this turn. */ - private int lifeLostThisTurn = 0; - - /** The life lost last turn. */ - private int lifeLostLastTurn = 0; - - /** The life Gained this turn. */ - private int lifeGainedThisTurn = 0; - - /** The num power surge lands. */ - private int numPowerSurgeLands; - - /** The number of times this player has searched his library. */ - private int numLibrarySearchedOwn = 0; - - /** The prowl. */ - private ArrayList prowl = new ArrayList(); - - /** The num lands played this turn. */ private int landsPlayedThisTurn = 0; - - /** The max hand size. */ + private int lifeLostThisTurn = 0; + private int lifeLostLastTurn = 0; + private int lifeGainedThisTurn = 0; + private int numPowerSurgeLands; + private int numLibrarySearchedOwn = 0; //The number of times this player has searched his library private int maxHandSize = 7; - - /** Starting hand size. */ private int startingHandSize = 7; - - /** The unlimited hand size. */ private boolean unlimitedHandSize = false; - - /** The last drawn card. */ private Card lastDrawnCard = null; - - /** The named card. */ private String namedCard = ""; - - /** The num drawn this turn. */ private int numDrawnThisTurn = 0; private int numDrawnThisDrawStep = 0; - - /** The num discarded this turn. */ private int numDiscardedThisTurn = 0; - private int numCardsInHandStartedThisTurnWith = 0; /** A list of tokens not in play, but on their way. @@ -140,57 +105,47 @@ public class Player extends GameEntity implements Comparable, IIdentifia * on tokens. */ private List inboundTokens = new ArrayList(); - /** The keywords. */ private Map changedKeywords = new ConcurrentSkipListMap(); - - /** The mana pool. */ private ManaPool manaPool = new ManaPool(this); - - /** The must attack entity. */ private GameEntity mustAttackEntity = null; - - /** The attackedWithCreatureThisTurn. */ private boolean attackedWithCreatureThisTurn = false; - private boolean activateLoyaltyAbilityThisTurn = false; - - /** The playerAttackCountThisTurn. */ private int attackersDeclaredThisTurn = 0; - /** The zones. */ private final Map zones = new EnumMap(ZoneType.class); private List currentPlanes = new ArrayList(); + private ArrayList prowl = new ArrayList(); private PlayerStatistics stats = new PlayerStatistics(); - protected PlayerController controller; - protected PlayerController controllerCreator = null; - + private PlayerController controller; + private PlayerController controllerCreator = null; private Player mindSlaveMaster = null; private int teamNumber = -1; - private Card activeScheme = null; - private Card commander = null; - - /** The Constant ALL_ZONES. */ - public static final List ALL_ZONES = Collections.unmodifiableList(Arrays.asList(ZoneType.Battlefield, - ZoneType.Library, ZoneType.Graveyard, ZoneType.Hand, ZoneType.Exile, ZoneType.Command, ZoneType.Ante, - ZoneType.Sideboard, ZoneType.PlanarDeck,ZoneType.SchemeDeck)); - - protected final Game game; - + private final Game game; private boolean triedToDrawFromEmptyLibrary = false; - private boolean isPlayingExtraTrun = false; - private List lostOwnership = new ArrayList(); private List gainedOwnership = new ArrayList(); - private int numManaConversion = 0; private final AchievementTracker achievementTracker = new AchievementTracker(); + private final PlayerView view; + + public Player(String name0, Game game0, final int id0) { + game = game0; + for (final ZoneType z : Player.ALL_ZONES) { + final PlayerZone toPut = z == ZoneType.Battlefield ? new PlayerZoneBattlefield(z, this) : new PlayerZone(z, this); + zones.put(z, toPut); + } + + setName(chooseName(name0)); + id = id0; + view = new PlayerView(id); + } public final AchievementTracker getAchievementTracker() { return achievementTracker; @@ -200,29 +155,6 @@ public class Player extends GameEntity implements Comparable, IIdentifia return stats.getOutcome(); } - /** - *

- * Constructor for Player. - *

- * - * @param myName - * a {@link java.lang.String} object. - * @param myLife - * a int. - * @param myPoisonCounters - * a int. - */ - public Player(String name, Game game0, final int id) { - game = game0; - for (final ZoneType z : Player.ALL_ZONES) { - final PlayerZone toPut = z == ZoneType.Battlefield ? new PlayerZoneBattlefield(z, this) : new PlayerZone(z, this); - this.zones.put(z, toPut); - } - - this.setName(chooseName(name)); - this.id = id; - } - private String chooseName(String originalName) { String nameCandidate = originalName; for (int i = 2; i <= 8; i++) { // several tries, not matter how many @@ -243,11 +175,11 @@ public class Player extends GameEntity implements Comparable, IIdentifia @Override public int getId() { - return this.id; + return id; } @Override - public Game getGame() { // I'll probably regret about this + public Game getGame() { return game; } @@ -255,17 +187,15 @@ public class Player extends GameEntity implements Comparable, IIdentifia return stats; } - public final void setTeam(int iTeam) { - teamNumber = iTeam; - } public final int getTeam() { return teamNumber; } + public final void setTeam(int iTeam) { + teamNumber = iTeam; + } public boolean isArchenemy() { - - //Only the archenemy has schemes. - return getZone(ZoneType.SchemeDeck).size() > 0; + return getZone(ZoneType.SchemeDeck).size() > 0; //Only the archenemy has schemes. } public void setSchemeInMotion() { @@ -288,7 +218,7 @@ public class Player extends GameEntity implements Comparable, IIdentifia activeScheme = getZone(ZoneType.SchemeDeck).get(0); // gameAction moveTo ? getZone(ZoneType.SchemeDeck).remove(activeScheme); - this.getZone(ZoneType.Command).add(activeScheme); + getZone(ZoneType.Command).add(activeScheme); game.getTriggerHandler().clearSuppression(TriggerType.ChangesZone); // Run triggers @@ -298,11 +228,7 @@ public class Player extends GameEntity implements Comparable, IIdentifia } /** - *

* getOpponent. Used by current-generation AI. - *

- * - * @return a {@link forge.game.player.Player} object. */ public final Player getOpponent() { for (Player p : game.getPlayers()) { @@ -314,10 +240,8 @@ public class Player extends GameEntity implements Comparable, IIdentifia } /** - * * returns all opponents. * Should keep player relations somewhere in the match structure - * @return */ public final List getOpponents() { List result = new ArrayList(); @@ -344,35 +268,28 @@ public class Player extends GameEntity implements Comparable, IIdentifia /** * Find the smallest life total amongst this player's opponents. - * - * @return the life total of the opponent with the least life. */ public final int getOpponentsSmallestLifeTotal() { - return Aggregates.min(this.getOpponents(), Accessors.FN_GET_LIFE_TOTAL); + return Aggregates.min(getOpponents(), Accessors.FN_GET_LIFE_TOTAL); } /** * Find the greatest life total amongst this player's opponents. - * - * @return the life total of the opponent with the most life. */ public final int getOpponentsGreatestLifeTotal() { - return Aggregates.max(this.getOpponents(), Accessors.FN_GET_LIFE_TOTAL); + return Aggregates.max(getOpponents(), Accessors.FN_GET_LIFE_TOTAL); } /** * Get the total number of poison counters amongst this player's opponents. - * - * @return the total number of poison counters amongst this player's opponents. */ public final int getOpponentsTotalPoisonCounters() { - return Aggregates.sum(this.getOpponents(), Accessors.FN_GET_POISON_COUNTERS); + return Aggregates.sum(getOpponents(), Accessors.FN_GET_POISON_COUNTERS); } /** * returns allied players. * Should keep player relations somewhere in the match structure - * @return */ public final List getAllies() { List result = new ArrayList(); @@ -387,7 +304,6 @@ public class Player extends GameEntity implements Comparable, IIdentifia /** * returns all other players. * Should keep player relations somewhere in the match structure - * @return */ public final List getAllOtherPlayers() { List result = new ArrayList(game.getPlayers()); @@ -398,10 +314,9 @@ public class Player extends GameEntity implements Comparable, IIdentifia /** * returns the weakest opponent (based on life totals). * Should keep player relations somewhere in the match structure - * @return */ public final Player getWeakestOpponent() { - List opponents = this.getOpponents(); + List opponents = getOpponents(); Player weakest = opponents.get(0); for (int i = 1; i < opponents.size(); i++) { if (weakest.getLife() > opponents.get(i).getLife()) { @@ -412,85 +327,37 @@ public class Player extends GameEntity implements Comparable, IIdentifia } public boolean isOpponentOf(Player other) { - return other != this && other != null && (other.teamNumber < 0 || other.teamNumber != this.teamNumber); + return other != this && other != null && (other.teamNumber < 0 || other.teamNumber != teamNumber); } - // //////////////////////// - // - // methods for manipulating life - // - // //////////////////////// - - /** - *

- * Setter for the field life. - *

- * - * @param newLife - * a int. - * @param source - * a {@link forge.game.card.Card} object. - * @return a boolean. - */ public final boolean setLife(final int newLife, final Card source) { boolean change = false; // rule 118.5 - if (this.life > newLife) { - change = (this.loseLife(this.life - newLife) > 0); - } else if (newLife > this.life) { - change = this.gainLife(newLife - this.life, source); - } else { - // life == newLife + if (life > newLife) { + change = (loseLife(life - newLife) > 0); + } + else if (newLife > life) { + change = gainLife(newLife - life, source); + } + else { // life == newLife change = false; } return change; } - /** - * Sets the starting life for a game. Should only be called from - * newGame()'s. - * - * @param startLife - * a int. - */ - public final void setStartingLife(final int startLife) { - this.startingLife = startLife; - this.life = startLife; - } - - /** - *

- * Getter for the field life. - *

- * - * @return a int. - */ - public final int getLife() { - return this.life; - } - - /** - *

- * Getter for the field startingLife. - *

- * - * @return a int. - */ public final int getStartingLife() { - return this.startingLife; + return startingLife; + } + public final void setStartingLife(final int startLife) { + //Should only be called from newGame(). + startingLife = startLife; + life = startLife; + } + + public final int getLife() { + return life; } - /** - *

- * gainLife. - *

- * - * @param toGain - * a int. - * @param source - * a {@link forge.game.card.Card} object. - * @return a boolean. - */ public final boolean gainLife(final int toGain, final Card source) { // Run any applicable replacement effects. final HashMap repParams = new HashMap(); @@ -503,16 +370,16 @@ public class Player extends GameEntity implements Comparable, IIdentifia } boolean newLifeSet = false; - if (!this.canGainLife()) { + if (!canGainLife()) { return false; } final int lifeGain = toGain; if (lifeGain > 0) { int oldLife = life; - this.life += lifeGain; + life += lifeGain; newLifeSet = true; - this.lifeGainedThisTurn += lifeGain; + lifeGainedThisTurn += lifeGain; // Run triggers final HashMap runParams = new HashMap(); @@ -521,56 +388,41 @@ public class Player extends GameEntity implements Comparable, IIdentifia game.getTriggerHandler().runTrigger(TriggerType.LifeGained, runParams, false); game.fireEvent(new GameEventPlayerLivesChanged(this, oldLife, life)); - } else { + } + else { System.out.println("Player - trying to gain negative or 0 life"); } - return newLifeSet; } - /** - *

- * canGainLife. - *

- * - * @return a boolean. - */ public final boolean canGainLife() { - if (this.hasKeyword("You can't gain life.") || this.hasKeyword("Your life total can't change.")) { + if (hasKeyword("You can't gain life.") || hasKeyword("Your life total can't change.")) { return false; } return true; } - /** - *

- * loseLife. - *

- * - * @param toLose - * a int. - * @return an int. - */ public final int loseLife(final int toLose) { int lifeLost = 0; - if (!this.canLoseLife()) { + if (!canLoseLife()) { return 0; } if (toLose > 0) { int oldLife = life; - this.life -= toLose; + life -= toLose; lifeLost = toLose; game.fireEvent(new GameEventPlayerLivesChanged(this, oldLife, life)); - } else if (toLose == 0) { + } + else if (toLose == 0) { // Rule 118.4 - // this is for players being able to pay 0 life - // nothing to do - } else { + // this is for players being able to pay 0 life nothing to do + } + else { System.out.println("Player - trying to lose negative life"); return 0; } - this.lifeLostThisTurn += toLose; + lifeLostThisTurn += toLose; // Run triggers final HashMap runParams = new HashMap(); @@ -581,110 +433,63 @@ public class Player extends GameEntity implements Comparable, IIdentifia return lifeLost; } - /** - *

- * canLoseLife. - *

- * - * @return a boolean. - */ public final boolean canLoseLife() { - if (this.hasKeyword("Your life total can't change.")) { + if (hasKeyword("Your life total can't change.")) { return false; } return true; } - /** - *

- * canPayLife. - *

- * - * @param lifePayment - * a int. - * @return a boolean. - */ public final boolean canPayLife(final int lifePayment) { - if (this.life < lifePayment) { + if (life < lifePayment) { return false; } - if ((lifePayment > 0) && this.hasKeyword("Your life total can't change.")) { + if ((lifePayment > 0) && hasKeyword("Your life total can't change.")) { return false; } return true; } - /** - *

- * payLife. - *

- * - * @param lifePayment - * a int. - * @param source - * a {@link forge.game.card.Card} object. - * @return a boolean. - */ public final boolean payLife(final int lifePayment, final Card source) { - if (!this.canPayLife(lifePayment)) { + if (!canPayLife(lifePayment)) { return false; } if (lifePayment <= 0) - return true; + return true; // rule 118.8 - if (this.life >= lifePayment) { - return (this.loseLife(lifePayment) > 0); + if (life >= lifePayment) { + return (loseLife(lifePayment) > 0); } - return false; } - // //////////////////////// - // - // methods for handling damage - // - // //////////////////////// - - // This function handles damage after replacement and prevention effects are - // applied - /** - *

- * addDamageAfterPrevention. - *

- * - * @param damage - * a int. - * @param source - * a {@link forge.game.card.Card} object. - * @param isCombat - * a boolean. - * @return whether or not damage was dealt - */ + // This function handles damage after replacement and prevention effects are applied @Override public final boolean addDamageAfterPrevention(final int amount, final Card source, final boolean isCombat) { if (amount <= 0) { return false; } //String additionalLog = ""; - source.addDealtDamageToPlayerThisTurn(this.getName(), amount); + source.addDealtDamageToPlayerThisTurn(getName(), amount); boolean infect = source.hasKeyword("Infect") - || this.hasKeyword("All damage is dealt to you as though its source had infect."); + || hasKeyword("All damage is dealt to you as though its source had infect."); if (infect) { - this.addPoisonCounters(amount, source); - } else { + addPoisonCounters(amount, source); + } + else { // Worship does not reduce the damage dealt but changes the effect // of the damage - if (this.hasKeyword("Damage that would reduce your life total to less than 1 reduces it to 1 instead.") - && this.life <= amount) { - this.loseLife(Math.min(amount, this.life - 1)); - } else { - // rule 118.2. Damage dealt to a player normally causes that - // player to lose that much life. - this.loseLife(amount); + if (hasKeyword("Damage that would reduce your life total to less than 1 reduces it to 1 instead.") + && life <= amount) { + loseLife(Math.min(amount, life - 1)); + } + else { + // rule 118.2. Damage dealt to a player normally causes that player to lose that much life. + loseLife(amount); } } @@ -697,15 +502,14 @@ public class Player extends GameEntity implements Comparable, IIdentifia } } - this.assignedDamage.put(source, amount); + assignedDamage.put(source, amount); if (source.hasKeyword("Lifelink")) { source.getController().gainLife(amount, source); } source.getDamageHistory().registerDamage(this); if (isCombat) { - final ArrayList types = source.getType(); - for (final String type : types) { + for (final String type : source.getType()) { source.getController().addProwlType(type); } } @@ -719,25 +523,10 @@ public class Player extends GameEntity implements Comparable, IIdentifia game.getTriggerHandler().runTrigger(TriggerType.DamageDone, runParams, false); game.fireEvent(new GameEventPlayerDamaged(this, source, amount, isCombat, infect)); - return true; } - // This should be also usable by the AI to forecast an effect (so it must - // not change the game state) - /** - *

- * staticDamagePrevention. - *

- * - * @param damage - * a int. - * @param source - * a {@link forge.game.card.Card} object. - * @param isCombat - * a boolean. - * @return a int. - */ + // This should be also usable by the AI to forecast an effect (so it must not change the game state) @Override public final int staticDamagePrevention(final int damage, final Card source, final boolean isCombat, final boolean isTest) { if (game.getStaticEffects().getGlobalRuleChange(GlobalRuleChange.noPrevention)) { @@ -748,7 +537,7 @@ public class Player extends GameEntity implements Comparable, IIdentifia return 0; } - if (this.hasProtectionFrom(source)) { + if (hasProtectionFrom(source)) { return 0; } @@ -781,34 +570,20 @@ public class Player extends GameEntity implements Comparable, IIdentifia if (restDamage > 0) { return restDamage; - } else { - return 0; } + return 0; } // This is usable by the AI to forecast an effect (so it must // not change the game state) // 2012/01/02: No longer used in calculating the finalized damage, but // retained for damageprediction. -Hellfish - /** - *

- * staticReplaceDamage. - *

- * - * @param damage - * a int. - * @param source - * a {@link forge.game.card.Card} object. - * @param isCombat - * a boolean. - * @return a int. - */ @Override public final int staticReplaceDamage(final int damage, final Card source, final boolean isCombat) { int restDamage = damage; - if (this.hasKeyword("Damage that would reduce your life total to less than 1 reduces it to 1 instead.")) { - restDamage = Math.min(restDamage, this.life - 1); + if (hasKeyword("Damage that would reduce your life total to less than 1 reduces it to 1 instead.")) { + restDamage = Math.min(restDamage, life - 1); } for (Card c : game.getCardsIn(ZoneType.Battlefield)) { @@ -845,7 +620,7 @@ public class Player extends GameEntity implements Comparable, IIdentifia restDamage *= 2; } } else if (c.getName().equals("Inquisitor's Flail")) { - if (isCombat && c.getEquippingCard() != null && c.getEquippingCard().equals(source)) { + if (isCombat && c.getEquipping() != null && c.getEquipping().equals(source)) { restDamage *= 2; } } else if (c.getName().equals("Ghosts of the Innocent")) { @@ -864,31 +639,17 @@ public class Player extends GameEntity implements Comparable, IIdentifia restDamage = 2; } } else if (c.getName().equals("Elderscale Wurm")) { - if (c.getController().equals(this) && this.getLife() - restDamage < 7) { - restDamage = this.getLife() - 7; + if (c.getController().equals(this) && getLife() - restDamage < 7) { + restDamage = getLife() - 7; if (restDamage < 0) { restDamage = 0; } } } } - return restDamage; } - /** - *

- * replaceDamage. - *

- * - * @param damage - * a int. - * @param source - * a {@link forge.game.card.Card} object. - * @param isCombat - * a boolean. - * @return a int. - */ @Override public final int replaceDamage(final int damage, final Card source, final boolean isCombat) { // Replacement effects @@ -902,23 +663,9 @@ public class Player extends GameEntity implements Comparable, IIdentifia if (game.getReplacementHandler().run(repParams) != ReplacementResult.NotReplaced) { return 0; } - return damage; } - /** - *

- * preventDamage. - *

- * - * @param damage - * a int. - * @param source - * a {@link forge.game.card.Card} object. - * @param isCombat - * a boolean. - * @return a int. - */ @Override public final int preventDamage(final int damage, final Card source, final boolean isCombat) { if (game.getStaticEffects().getGlobalRuleChange(GlobalRuleChange.noPrevention) @@ -929,8 +676,8 @@ public class Player extends GameEntity implements Comparable, IIdentifia int restDamage = damage; boolean DEBUGShieldsWithEffects = false; - while (!this.getPreventNextDamageWithEffect().isEmpty() && restDamage != 0) { - TreeMap> shieldMap = this.getPreventNextDamageWithEffect(); + while (!getPreventNextDamageWithEffect().isEmpty() && restDamage != 0) { + TreeMap> shieldMap = getPreventNextDamageWithEffect(); List preventionEffectSources = new ArrayList(shieldMap.keySet()); Card shieldSource = preventionEffectSources.get(0); if (preventionEffectSources.size() > 1) { @@ -945,7 +692,7 @@ public class Player extends GameEntity implements Comparable, IIdentifia choices.add(shieldDescription); choiceMap.put(shieldDescription, key); } - shieldSource = this.getController().chooseProtectionShield(this, choices, choiceMap); + shieldSource = getController().chooseProtectionShield(this, choices, choiceMap); } if (DEBUGShieldsWithEffects) { System.out.println("Prevention shield source: " + shieldSource); @@ -975,18 +722,18 @@ public class Player extends GameEntity implements Comparable, IIdentifia boolean apiIsEffect = (shieldSA.getApi() == ApiType.Effect); List cardsInCommand = null; if (apiIsEffect) { - cardsInCommand = this.getGame().getCardsIn(ZoneType.Command); + cardsInCommand = getGame().getCardsIn(ZoneType.Command); } - this.getController().playSpellAbilityNoStack(shieldSA, true); + getController().playSpellAbilityNoStack(shieldSA, true); if (apiIsEffect) { - List newCardsInCommand = this.getGame().getCardsIn(ZoneType.Command); + List newCardsInCommand = getGame().getCardsIn(ZoneType.Command); newCardsInCommand.removeAll(cardsInCommand); if (!newCardsInCommand.isEmpty()) { - newCardsInCommand.get(0).setSVar("PreventedDamage", "Number$" + Integer.toString(dmgToBePrevented)); + newCardsInCommand.get(0).setSVar("PreventedDamage", "Number$" + Integer.toString(dmgToBePrevented)); } } - this.subtractPreventNextDamageWithEffect(shieldSource, restDamage); + subtractPreventNextDamageWithEffect(shieldSource, restDamage); restDamage = restDamage - dmgToBePrevented; if (DEBUGShieldsWithEffects) { @@ -1008,38 +755,26 @@ public class Player extends GameEntity implements Comparable, IIdentifia return 0; } - restDamage = this.staticDamagePrevention(restDamage, source, isCombat, false); + restDamage = staticDamagePrevention(restDamage, source, isCombat, false); - if (restDamage >= this.getPreventNextDamage()) { - restDamage = restDamage - this.getPreventNextDamage(); - this.setPreventNextDamage(0); + if (restDamage >= getPreventNextDamage()) { + restDamage = restDamage - getPreventNextDamage(); + setPreventNextDamage(0); } else { - this.setPreventNextDamage(this.getPreventNextDamage() - restDamage); + setPreventNextDamage(getPreventNextDamage() - restDamage); restDamage = 0; } return restDamage; } - /** - *

- * Setter for the field assignedDamage. - *

- */ public final void clearAssignedDamage() { - this.assignedDamage.clear(); + assignedDamage.clear(); } - /** - *

- * Getter for the field assignedDamage. - *

- * - * @return a int. - */ public final int getAssignedDamage() { int num = 0; - for (final Integer value : this.assignedDamage.values()) { + for (final Integer value : assignedDamage.values()) { num += value; } return num; @@ -1049,21 +784,11 @@ public class Player extends GameEntity implements Comparable, IIdentifia return assignedDamage.keySet(); } - /** - *

- * Getter for the field assignedDamage. - *

- * - * @param type - * a string. - * - * @return a int. - */ public final int getAssignedDamage(final String type) { final Map valueMap = new HashMap(); - for (final Card c : this.assignedDamage.keySet()) { + for (final Card c : assignedDamage.keySet()) { if (c.isType(type)) { - valueMap.put(c, this.assignedDamage.get(c)); + valueMap.put(c, assignedDamage.get(c)); } } int num = 0; @@ -1075,42 +800,25 @@ public class Player extends GameEntity implements Comparable, IIdentifia /** * Get the total damage assigned to this player's opponents this turn. - * - * @return the total damage assigned to this player's opponents this turn. */ public final int getOpponentsAssignedDamage() { - return Aggregates.sum(this.getOpponents(), Accessors.FN_GET_ASSIGNED_DAMAGE); + return Aggregates.sum(getOpponents(), Accessors.FN_GET_ASSIGNED_DAMAGE); } /** * Get the greatest amount of damage assigned to a single opponent this turn. - * - * @return the greatest amount of damage assigned to a single opponent this turn. */ public final int getMaxOpponentAssignedDamage() { - return Aggregates.max(this.getOpponents(), Accessors.FN_GET_ASSIGNED_DAMAGE); + return Aggregates.max(getOpponents(), Accessors.FN_GET_ASSIGNED_DAMAGE); } - /** - *

- * addCombatDamage. - *

- * - * @param damage - * a int. - * @param source - * a {@link forge.game.card.Card} object. - */ public final boolean addCombatDamage(final int damage, final Card source) { int damageToDo = damage; - damageToDo = this.replaceDamage(damageToDo, source, true); - damageToDo = this.preventDamage(damageToDo, source, true); + damageToDo = replaceDamage(damageToDo, source, true); + damageToDo = preventDamage(damageToDo, source, true); - this.addDamageAfterPrevention(damageToDo, source, true); // damage - // prevention - // is already - // checked + addDamageAfterPrevention(damageToDo, source, true); // damage prevention is already checked if (damageToDo > 0) { GameActionUtil.executeCombatDamageToPlayerEffects(this, source, damageToDo); @@ -1119,56 +827,22 @@ public class Player extends GameEntity implements Comparable, IIdentifia return false; } - // //////////////////////// - // - // methods for handling Poison counters - // - // //////////////////////// - - /** - *

- * addPoisonCounters. - *

- * - * @param num - * a int. - * @param source - * the source - */ + public final int getPoisonCounters() { + return poisonCounters; + } + public final void setPoisonCounters(final int num, Card source) { + int oldPoison = poisonCounters; + poisonCounters = num; + game.fireEvent(new GameEventPlayerPoisoned(this, source, oldPoison, num)); + } public final void addPoisonCounters(final int num, final Card source) { - if (!this.hasKeyword("You can't get poison counters")) { + if (!hasKeyword("You can't get poison counters")) { setPoisonCounters(poisonCounters + num, source); } } - /** - *

- * Setter for the field poisonCounters. - *

- * - * @param num - * a int. - * @param source - */ - public final void setPoisonCounters(final int num, Card source) { - int oldPoison = poisonCounters; - this.poisonCounters = num; - game.fireEvent(new GameEventPlayerPoisoned(this, source, oldPoison, num)); - } - - /** - *

- * Getter for the field poisonCounters. - *

- * - * @return a int. - */ - public final int getPoisonCounters() { - return this.poisonCounters; - } - public final void addChangedKeywords(final String[] addKeywords, final String[] removeKeywords, final Long timestamp) { - this.addChangedKeywords(ImmutableList.copyOf(addKeywords), ImmutableList.copyOf(removeKeywords), timestamp); + addChangedKeywords(ImmutableList.copyOf(addKeywords), ImmutableList.copyOf(removeKeywords), timestamp); } public final void addChangedKeywords(final List addKeywords, final List removeKeywords, final Long timestamp) { @@ -1179,11 +853,11 @@ public class Player extends GameEntity implements Comparable, IIdentifia final KeywordsChange cks = changedKeywords.get(timestamp); kws.addAll(cks.getKeywords()); rkws.addAll(cks.getRemoveKeywords()); - this.changedKeywords.put(timestamp, new KeywordsChange(kws, rkws, cks.isRemoveAllKeywords())); + changedKeywords.put(timestamp, new KeywordsChange(kws, rkws, cks.isRemoveAllKeywords())); return; } - this.changedKeywords.put(timestamp, new KeywordsChange(addKeywords, removeKeywords, false)); + changedKeywords.put(timestamp, new KeywordsChange(addKeywords, removeKeywords, false)); game.fireEvent(new GameEventPlayerStatsChanged(this)); } @@ -1197,7 +871,7 @@ public class Player extends GameEntity implements Comparable, IIdentifia * @param keyword the keyword to add. */ public final void addKeyword(final String keyword) { - this.addChangedKeywords(ImmutableList.of(keyword), ImmutableList.of(), this.getGame().getNextTimestamp()); + addChangedKeywords(ImmutableList.of(keyword), ImmutableList.of(), getGame().getNextTimestamp()); } /** @@ -1206,7 +880,7 @@ public class Player extends GameEntity implements Comparable, IIdentifia * @param newKeyword the keyword with which to replace. */ private final void replaceAllKeywordInstances(final String oldKeyword, final String newKeyword) { - for (final KeywordsChange ck : this.changedKeywords.values()) { + for (final KeywordsChange ck : changedKeywords.values()) { if (ck.getKeywords().contains(oldKeyword)) { ck.getKeywords().remove(oldKeyword); ck.getKeywords().add(newKeyword); @@ -1220,50 +894,36 @@ public class Player extends GameEntity implements Comparable, IIdentifia * @param keyword the keyword to remove. */ public final void removeKeyword(final String keyword) { - for (final KeywordsChange ck : this.changedKeywords.values()) { + for (final KeywordsChange ck : changedKeywords.values()) { if (ck.getKeywords().contains(keyword)) { ck.getKeywords().remove(keyword); } } // Remove the empty changes - for (final Entry ck : ImmutableList.copyOf(this.changedKeywords.entrySet())) { + for (final Entry ck : ImmutableList.copyOf(changedKeywords.entrySet())) { if (ck.getValue().isEmpty()) { - this.changedKeywords.remove(ck.getKey()); + changedKeywords.remove(ck.getKey()); } } game.fireEvent(new GameEventPlayerStatsChanged(this)); } - /* - * (non-Javadoc) - * - * @see forge.GameEntity#hasKeyword(java.lang.String) - */ - /** - * Checks for keyword. - * - * @param keyword - * String - * @return boolean - */ @Override public final boolean hasKeyword(final String keyword) { - return this.getKeywords().contains(keyword); + return getKeywords().contains(keyword); } - /** - * @return this player's keywords. - */ public final List getKeywords() { final ArrayList keywords = Lists.newArrayList(); // see if keyword changes are in effect - for (final KeywordsChange ck : this.changedKeywords.values()) { + for (final KeywordsChange ck : changedKeywords.values()) { if (ck.isRemoveAllKeywords()) { keywords.clear(); - } else if (ck.getRemoveKeywords() != null) { + } + else if (ck.getRemoveKeywords() != null) { keywords.removeAll(ck.getRemoveKeywords()); } @@ -1271,36 +931,22 @@ public class Player extends GameEntity implements Comparable, IIdentifia keywords.addAll(ck.getKeywords()); } } - return keywords; } - /** - * Can target. - * - * @param sa - * the sa - * @return a boolean - */ @Override public final boolean canBeTargetedBy(final SpellAbility sa) { - if (this.hasKeyword("Shroud") || (!this.equals(sa.getActivatingPlayer()) && this.hasKeyword("Hexproof")) - || this.hasProtectionFrom(sa.getHostCard())) { + if (hasKeyword("Shroud") || (!equals(sa.getActivatingPlayer()) && hasKeyword("Hexproof")) + || hasProtectionFrom(sa.getHostCard())) { return false; } - return true; } - /* - * (non-Javadoc) - * - * @see forge.GameEntity#hasProtectionFrom(forge.Card) - */ @Override public boolean hasProtectionFrom(final Card source) { - if (this.getKeywords() != null) { - final List list = this.getKeywords(); + if (getKeywords() != null) { + final List list = getKeywords(); String kw = ""; for (int i = 0; i < list.size(); i++) { @@ -1329,82 +975,47 @@ public class Player extends GameEntity implements Comparable, IIdentifia return true; } } - } } return false; } - // ////////////////////////////// - // / - // / replaces Singletons.getModel().getGameAction().draw* methods - // / - // ////////////////////////////// - - /** - *

- * canDraw - *

- * . - * - * @return true if a player can draw a card, false otherwise - */ public final boolean canDraw() { - if (this.hasKeyword("You can't draw cards.")) { + if (hasKeyword("You can't draw cards.")) { return false; } - if (this.hasKeyword("You can't draw more than one card each turn.")) { - return this.numDrawnThisTurn < 1; + if (hasKeyword("You can't draw more than one card each turn.")) { + return numDrawnThisTurn < 1; } return true; } - /** - *

- * drawCard. - *

- * - * @return a List of cards actually drawn - */ public final List drawCard() { - return this.drawCards(1); + return drawCards(1); } public boolean canMulligan() { return !getZone(ZoneType.Hand).isEmpty(); } - /** - *

- * drawCards. - *

- * - * @param n - * a int. - * @return a List of cards actually drawn - */ public final List drawCards(final int n) { final List drawn = new ArrayList(); for (int i = 0; i < n; i++) { - if (!this.canDraw()) { + if (!canDraw()) { return drawn; } - drawn.addAll(this.doDraw()); + drawn.addAll(doDraw()); } return drawn; } /** - *

- * doDraw. - *

- * * @return a List of cards actually drawn */ private List doDraw() { final List drawn = new ArrayList(); - final PlayerZone library = this.getZone(ZoneType.Library); + final PlayerZone library = getZone(ZoneType.Library); // Replacement effects final HashMap repRunParams = new HashMap(); @@ -1416,14 +1027,13 @@ public class Player extends GameEntity implements Comparable, IIdentifia } if (!library.isEmpty()) { - Card c = library.get(0); c = game.getAction().moveToHand(c); drawn.add(c); - if (this.numDrawnThisTurn == 0) { + if (numDrawnThisTurn == 0) { boolean reveal = false; - final List cards = this.getCardsIn(ZoneType.Battlefield); + final List cards = getCardsIn(ZoneType.Battlefield); for (final Card card : cards) { if (card.hasKeyword("Reveal the first card you draw each turn") || (card.hasKeyword("Reveal the first card you draw on each of your turns") && game.getPhaseHandler().isPlayerTurn(this))) { @@ -1436,15 +1046,15 @@ public class Player extends GameEntity implements Comparable, IIdentifia } } - this.setLastDrawnCard(c); + setLastDrawnCard(c); c.setDrawnThisTurn(true); - this.numDrawnThisTurn++; + numDrawnThisTurn++; if (game.getPhaseHandler().is(PhaseType.DRAW)) { - this.numDrawnThisDrawStep++; + numDrawnThisDrawStep++; } // Miracle draws - if (this.numDrawnThisTurn == 1 + if (numDrawnThisTurn == 1 && game.getAge() != GameStage.Mulligan) { drawMiracle(c); } @@ -1452,25 +1062,21 @@ public class Player extends GameEntity implements Comparable, IIdentifia // Run triggers final HashMap runParams = new HashMap(); runParams.put("Card", c); - runParams.put("Number", this.numDrawnThisTurn); + runParams.put("Number", numDrawnThisTurn); runParams.put("Player", this); game.getTriggerHandler().runTrigger(TriggerType.Drawn, runParams, false); } - else // Lose by milling is always on. Give AI many cards it cannot play if you want it not to undertake actions - this.triedToDrawFromEmptyLibrary = true; - + else { // Lose by milling is always on. Give AI many cards it cannot play if you want it not to undertake actions + triedToDrawFromEmptyLibrary = true; + } return drawn; } /** * Returns PlayerZone corresponding to the given zone of game. - * - * @param zone - * the zone - * @return the zone */ public final PlayerZone getZone(final ZoneType zone) { - return this.zones.get(zone); + return zones.get(zone); } public final List getCardsIn(final ZoneType zoneType) { @@ -1478,12 +1084,7 @@ public class Player extends GameEntity implements Comparable, IIdentifia } /** - * gets a list of all cards in the requested zone. This function makes a - * List from Card[]. - * - * @param zone - * the zone - * @return a List with all the cards currently in requested zone + * gets a list of all cards in the requested zone. This function makes a List from Card[]. */ public final List getCardsIn(final ZoneType zoneType, boolean filterOutPhasedOut) { List result; @@ -1494,44 +1095,27 @@ public class Player extends GameEntity implements Comparable, IIdentifia result.add(c); } } - } else { - PlayerZone zone = this.getZone(zoneType); + } + else { + PlayerZone zone = getZone(zoneType); result = zone == null ? null : zone.getCards(filterOutPhasedOut); } return result; } - /** - * Gets the cards include phasing in. - * - * @param zone - * the zone - * @return the cards include phasing in - */ public final List getCardsIncludePhasingIn(final ZoneType zone) { - return this.getCardsIn(zone, false); + return getCardsIn(zone, false); } /** - * gets a list of first N cards in the requested zone. This function makes a - * List from Card[]. - * - * @param zone - * the zone - * @param n - * the n - * @return a List with all the cards currently in requested zone + * gets a list of first N cards in the requested zone. This function makes a List from Card[]. */ public final List getCardsIn(final ZoneType zone, final int n) { - return Lists.newArrayList(Iterables.limit(this.getCardsIn(zone), n)); + return Lists.newArrayList(Iterables.limit(getCardsIn(zone), n)); } /** * gets a list of all cards in a given player's requested zones. - * - * @param zones - * the zones - * @return a List with all the cards currently in requested zones */ public final List getCardsIn(final Iterable zones) { final List result = new ArrayList(); @@ -1551,29 +1135,23 @@ public class Player extends GameEntity implements Comparable, IIdentifia /** * gets a list of all cards with requested cardName in a given player's * requested zone. This function makes a List from Card[]. - * - * @param zone - * the zone - * @param cardName - * the card name - * @return a List with all the cards currently in that player's library */ public final List getCardsIn(final ZoneType zone, final String cardName) { - return CardLists.filter(this.getCardsIn(zone), CardPredicates.nameEquals(cardName)); + return CardLists.filter(getCardsIn(zone), CardPredicates.nameEquals(cardName)); } public List getCardsActivableInExternalZones(boolean includeCommandZone) { final List cl = new ArrayList(); - cl.addAll(this.getZone(ZoneType.Graveyard).getCardsPlayerCanActivate(this)); - cl.addAll(this.getZone(ZoneType.Exile).getCardsPlayerCanActivate(this)); - cl.addAll(this.getZone(ZoneType.Library).getCardsPlayerCanActivate(this)); + cl.addAll(getZone(ZoneType.Graveyard).getCardsPlayerCanActivate(this)); + cl.addAll(getZone(ZoneType.Exile).getCardsPlayerCanActivate(this)); + cl.addAll(getZone(ZoneType.Library).getCardsPlayerCanActivate(this)); if (includeCommandZone) { - cl.addAll(this.getZone(ZoneType.Command).getCardsPlayerCanActivate(this)); + cl.addAll(getZone(ZoneType.Command).getCardsPlayerCanActivate(this)); } //External activatables from all opponents - for (final Player opponent : this.getOpponents()) { + for (final Player opponent : getOpponents()) { cl.addAll(opponent.getZone(ZoneType.Exile).getCardsPlayerCanActivate(this)); cl.addAll(opponent.getZone(ZoneType.Graveyard).getCardsPlayerCanActivate(this)); cl.addAll(opponent.getZone(ZoneType.Library).getCardsPlayerCanActivate(this)); @@ -1581,33 +1159,21 @@ public class Player extends GameEntity implements Comparable, IIdentifia cl.addAll(opponent.getZone(ZoneType.Hand).getCardsPlayerCanActivate(this)); } } - cl.addAll(this.getGame().getCardsPlayerCanActivateInStack()); + cl.addAll(getGame().getCardsPlayerCanActivateInStack()); return cl; } - /** - * Gets the all cards. - * - * @return the all cards - */ public final List getAllCards() { - List allExcStack = this.getCardsIn(Player.ALL_ZONES); + List allExcStack = getCardsIn(Player.ALL_ZONES); allExcStack.addAll(getCardsIn(ZoneType.Stack)); allExcStack.addAll(inboundTokens); return allExcStack; } - /** - *

- * getDredge. - *

- * - * @return a {@link forge.CardList} object. - */ protected final List getDredge() { final List dredge = new ArrayList(); - int cntLibrary = this.getCardsIn(ZoneType.Library).size(); - for (final Card c : this.getCardsIn(ZoneType.Graveyard)) { + int cntLibrary = getCardsIn(ZoneType.Library).size(); + for (final Card c : getCardsIn(ZoneType.Graveyard)) { int nDr = getDredgeNumber(c); if (nDr > 0 && cntLibrary >= nDr) { dredge.add(c); @@ -1616,15 +1182,6 @@ public class Player extends GameEntity implements Comparable, IIdentifia return dredge; } - /** - *

- * getDredgeNumber. - *

- * - * @param c - * a {@link forge.game.card.Card} object. - * @return a int. - */ protected final int getDredgeNumber(final Card c) { for (String s : c.getKeyword()) { if (s.startsWith("Dredge")) { @@ -1632,58 +1189,21 @@ public class Player extends GameEntity implements Comparable, IIdentifia } } return 0; - // throw new RuntimeException("Input_Draw : getDredgeNumber() card doesn't have dredge - " + c.getName()); } - /** - *

- * resetNumDrawnThisTurn. - *

- */ public final void resetNumDrawnThisTurn() { - this.numDrawnThisTurn = 0; - this.numDrawnThisDrawStep = 0; + numDrawnThisTurn = 0; + numDrawnThisDrawStep = 0; } - /** - *

- * Getter for the field numDrawnThisTurn. - *

- * - * @return a int. - */ public final int getNumDrawnThisTurn() { - return this.numDrawnThisTurn; + return numDrawnThisTurn; } - /** - *

- * Getter for the field numDrawnThisTurnDrawStep. - *

- * - * @return a int. - */ public final int numDrawnThisDrawStep() { - return this.numDrawnThisDrawStep; + return numDrawnThisDrawStep; } - // ////////////////////////////// - // / - // / replaces Singletons.getModel().getGameAction().discard* methods - // / - // ////////////////////////////// - - /** - *

- * discard. - *

- * - * @param c - * a {@link forge.game.card.Card} object. - * @param sa - * a {@link forge.game.spellability.SpellAbility} object. - * @return the discarded {@link Card} in its new location. - */ public final Card discard(final Card c, final SpellAbility sa) { // TODO: This line should be moved inside CostPayment somehow /*if (sa != null) { @@ -1709,13 +1229,15 @@ public class Player extends GameEntity implements Comparable, IIdentifia if (discardToTopOfLibrary) { newCard = game.getAction().moveToLibrary(c, 0); // Play the Discard sound - } else if (discardMadness) { + } + else if (discardMadness) { newCard = game.getAction().exile(c); - } else { + } + else { newCard = game.getAction().moveToGraveyard(c); // Play the Discard sound } - this.numDiscardedThisTurn++; + numDiscardedThisTurn++; // Run triggers Card cause = null; if (sa != null) { @@ -1731,53 +1253,22 @@ public class Player extends GameEntity implements Comparable, IIdentifia return newCard; } - /** - *

- * Getter for the field numDiscardedThisTurn. - *

- * - * @return a int. - */ public final int getNumDiscardedThisTurn() { - return this.numDiscardedThisTurn; + return numDiscardedThisTurn; } - - /** - *

- * Getter for the field numDiscardedThisTurn. - *

- * - * @return a int. - */ public final void resetNumDiscardedThisTurn() { - this.numDiscardedThisTurn = 0; + numDiscardedThisTurn = 0; } - /** - * @return the numCardsInHandStartedThisTurnWith - */ - public int getNumCardsInHandStartedThisTurnWith() { - return numCardsInHandStartedThisTurnWith; - } + public int getNumCardsInHandStartedThisTurnWith() { + return numCardsInHandStartedThisTurnWith; + } + public void setNumCardsInHandStartedThisTurnWith(int num) { + numCardsInHandStartedThisTurnWith = num; + } - /** - * @param numCardsInHandStartedThisTurnWith the numCardsInHandStartedThisTurnWith to set - */ - public void setNumCardsInHandStartedThisTurnWith(int num) { - this.numCardsInHandStartedThisTurnWith = num; - } - - /** - *

- * mill. - *

- * - * @param n - * a int. - * @return the card list - */ public final List mill(final int n) { - return this.mill(n, ZoneType.Graveyard, false); + return mill(n, ZoneType.Graveyard, false); } /** @@ -1794,12 +1285,12 @@ public class Player extends GameEntity implements Comparable, IIdentifia * @return the card list */ public final List mill(final int n, final ZoneType zone, final boolean bottom) { - final List lib = new ArrayList(this.getCardsIn(ZoneType.Library)); + final List lib = new ArrayList(getCardsIn(ZoneType.Library)); final List milled = new ArrayList(); final int max = Math.min(n, lib.size()); - final ZoneType destination = this.getZone(zone).getZoneType(); + final ZoneType destination = getZone(zone).getZoneType(); for (int i = 0; i < max; i++) { if (bottom) { @@ -1819,7 +1310,7 @@ public class Player extends GameEntity implements Comparable, IIdentifia *

*/ public final void shuffle(final SpellAbility sa) { - final List list = Lists.newArrayList(this.getCardsIn(ZoneType.Library)); + final List list = Lists.newArrayList(getCardsIn(ZoneType.Library)); if (list.size() <= 1) { return; @@ -1846,7 +1337,7 @@ public class Player extends GameEntity implements Comparable, IIdentifia Collections.shuffle(list, random); Collections.shuffle(list, random); - this.getZone(ZoneType.Library).setCards(getController().cheatShuffle(list)); + getZone(ZoneType.Library).setCards(getController().cheatShuffle(list)); // Run triggers final HashMap runParams = new HashMap(); @@ -1874,9 +1365,9 @@ public class Player extends GameEntity implements Comparable, IIdentifia */ public final boolean playLand(final Card land, final boolean ignoreZoneAndTiming) { // Dakkon Blackblade Avatar will use a similar effect - if (this.canPlayLand(land, ignoreZoneAndTiming)) { + if (canPlayLand(land, ignoreZoneAndTiming)) { land.setController(this, 0); - game.getAction().moveTo(this.getZone(ZoneType.Battlefield), land); + game.getAction().moveTo(getZone(ZoneType.Battlefield), land); // play a sound game.fireEvent(new GameEventLandPlayed(this, land)); @@ -1912,7 +1403,7 @@ public class Player extends GameEntity implements Comparable, IIdentifia * @return a boolean. */ public final boolean canPlayLand(Card land, final boolean ignoreZoneAndTiming) { - if (!ignoreZoneAndTiming && !this.canCastSorcery()) { + if (!ignoreZoneAndTiming && !canCastSorcery()) { return false; } @@ -1941,19 +1432,19 @@ public class Player extends GameEntity implements Comparable, IIdentifia // **** Check for land play limit per turn **** // Dev Mode - if (this.getController().canPlayUnlimitedLands() || this.hasKeyword("You may play any number of additional lands on each of your turns.")) { + if (getController().canPlayUnlimitedLands() || hasKeyword("You may play any number of additional lands on each of your turns.")) { return true; } // check for adjusted max lands play per turn int adjMax = 1; - for (String keyword : this.getKeywords()) { + for (String keyword : getKeywords()) { if (keyword.startsWith("AdjustLandPlays")) { final String[] k = keyword.split(":"); adjMax += Integer.valueOf(k[1]); } } - if (this.landsPlayedThisTurn < adjMax) { + if (landsPlayedThisTurn < adjMax) { return true; } @@ -1966,7 +1457,7 @@ public class Player extends GameEntity implements Comparable, IIdentifia * @return the mana pool */ public final ManaPool getManaPool() { - return this.manaPool; + return manaPool; } // ///////////////////////////// @@ -1983,7 +1474,7 @@ public class Player extends GameEntity implements Comparable, IIdentifia * @return a int. */ public final int getNumPowerSurgeLands() { - return this.numPowerSurgeLands; + return numPowerSurgeLands; } /** @@ -1996,8 +1487,8 @@ public class Player extends GameEntity implements Comparable, IIdentifia * @return a int. */ public final int setNumPowerSurgeLands(final int n) { - this.numPowerSurgeLands = n; - return this.numPowerSurgeLands; + numPowerSurgeLands = n; + return numPowerSurgeLands; } /** @@ -2008,7 +1499,7 @@ public class Player extends GameEntity implements Comparable, IIdentifia * @return a {@link forge.game.card.Card} object. */ public final Card getLastDrawnCard() { - return this.lastDrawnCard; + return lastDrawnCard; } /** @@ -2021,8 +1512,8 @@ public class Player extends GameEntity implements Comparable, IIdentifia * @return a {@link forge.game.card.Card} object. */ private final Card setLastDrawnCard(final Card c) { - this.lastDrawnCard = c; - return this.lastDrawnCard; + lastDrawnCard = c; + return lastDrawnCard; } /** @@ -2033,7 +1524,7 @@ public class Player extends GameEntity implements Comparable, IIdentifia * @return a String. */ public final String getNamedCard() { - return this.namedCard; + return namedCard; } /** @@ -2047,7 +1538,7 @@ public class Player extends GameEntity implements Comparable, IIdentifia * @return a {@link forge.game.card.Card} object. */ public final void setNamedCard(final String s) { - this.namedCard = s; + namedCard = s; } /** *

@@ -2057,7 +1548,7 @@ public class Player extends GameEntity implements Comparable, IIdentifia * @return a int. */ public final int getTurn() { - return this.stats.getTurnsPlayed(); + return stats.getTurnsPlayed(); } /** @@ -2066,7 +1557,7 @@ public class Player extends GameEntity implements Comparable, IIdentifia *

*/ public final void incrementTurn() { - this.stats.nextTurn(); + stats.nextTurn(); } /** @@ -2077,7 +1568,7 @@ public class Player extends GameEntity implements Comparable, IIdentifia * @return a boolean. */ public final boolean getActivateLoyaltyAbilityThisTurn() { - return this.activateLoyaltyAbilityThisTurn; + return activateLoyaltyAbilityThisTurn; } /** @@ -2089,7 +1580,7 @@ public class Player extends GameEntity implements Comparable, IIdentifia * a boolean. */ public final void setActivateLoyaltyAbilityThisTurn(final boolean b) { - this.activateLoyaltyAbilityThisTurn = b; + activateLoyaltyAbilityThisTurn = b; } /** @@ -2100,7 +1591,7 @@ public class Player extends GameEntity implements Comparable, IIdentifia * @return a boolean. */ public final boolean getAttackedWithCreatureThisTurn() { - return this.attackedWithCreatureThisTurn; + return attackedWithCreatureThisTurn; } /** @@ -2112,7 +1603,7 @@ public class Player extends GameEntity implements Comparable, IIdentifia * a boolean. */ public final void setAttackedWithCreatureThisTurn(final boolean b) { - this.attackedWithCreatureThisTurn = b; + attackedWithCreatureThisTurn = b; } /** @@ -2123,7 +1614,7 @@ public class Player extends GameEntity implements Comparable, IIdentifia * @return a boolean. */ public final int getAttackersDeclaredThisTurn() { - return this.attackersDeclaredThisTurn; + return attackersDeclaredThisTurn; } /** @@ -2133,7 +1624,7 @@ public class Player extends GameEntity implements Comparable, IIdentifia * */ public final void incrementAttackersDeclaredThisTurn() { - this.attackersDeclaredThisTurn++; + attackersDeclaredThisTurn++; } /** @@ -2143,7 +1634,7 @@ public class Player extends GameEntity implements Comparable, IIdentifia * */ public final void resetAttackersDeclaredThisTurn() { - this.attackersDeclaredThisTurn = 0; + attackersDeclaredThisTurn = 0; } // Game win/loss @@ -2157,11 +1648,11 @@ public class Player extends GameEntity implements Comparable, IIdentifia * the source name */ public final void altWinBySpellEffect(final String sourceName) { - if (this.cantWin()) { + if (cantWin()) { System.out.println("Tried to win, but currently can't."); return; } - this.setOutcome(PlayerOutcome.altWin(sourceName)); + setOutcome(PlayerOutcome.altWin(sourceName)); } @@ -2178,7 +1669,7 @@ public class Player extends GameEntity implements Comparable, IIdentifia */ public final boolean loseConditionMet(final GameLossReason state, final String spellName) { if (state != GameLossReason.OpponentWon) { - if (this.cantLose()) { + if (cantLose()) { System.out.println("Tried to lose, but currently can't."); return false; } @@ -2212,11 +1703,11 @@ public class Player extends GameEntity implements Comparable, IIdentifia * @return a boolean. */ public final boolean cantLose() { - if (this.getOutcome() != null && this.getOutcome().lossState == GameLossReason.Conceded) { + if (getOutcome() != null && getOutcome().lossState == GameLossReason.Conceded) { return false; } - return (this.hasKeyword("You can't lose the game.") || Iterables.any(this.getOpponents(), Predicates.CANT_WIN)); + return (hasKeyword("You can't lose the game.") || Iterables.any(getOpponents(), Predicates.CANT_WIN)); } /** @@ -2227,7 +1718,7 @@ public class Player extends GameEntity implements Comparable, IIdentifia * @return a boolean. */ public final boolean cantLoseForZeroOrLessLife() { - return (this.hasKeyword("You don't lose the game for having 0 or less life.")); + return (hasKeyword("You don't lose the game for having 0 or less life.")); } /** @@ -2246,7 +1737,7 @@ public class Player extends GameEntity implements Comparable, IIdentifia } isAnyOppLoseProof |= p.hasKeyword("You can't lose the game."); } - return this.hasKeyword("You can't win the game.") || isAnyOppLoseProof; + return hasKeyword("You can't win the game.") || isAnyOppLoseProof; } /** @@ -2258,33 +1749,33 @@ public class Player extends GameEntity implements Comparable, IIdentifia */ public final boolean checkLoseCondition() { // Just in case player already lost - if (this.getOutcome() != null) { - return this.getOutcome().lossState != null; + if (getOutcome() != null) { + return getOutcome().lossState != null; } // Rule 704.5a - If a player has 0 or less life, he or she loses the game. - final boolean hasNoLife = this.getLife() <= 0; - if (hasNoLife && !this.cantLoseForZeroOrLessLife()) { - return this.loseConditionMet(GameLossReason.LifeReachedZero, null); + final boolean hasNoLife = getLife() <= 0; + if (hasNoLife && !cantLoseForZeroOrLessLife()) { + return loseConditionMet(GameLossReason.LifeReachedZero, null); } // Rule 704.5b - If a player attempted to draw a card from a library with no cards in it // since the last time state-based actions were checked, he or she loses the game. if (triedToDrawFromEmptyLibrary) { triedToDrawFromEmptyLibrary = false; // one-shot check - return this.loseConditionMet(GameLossReason.Milled, null); + return loseConditionMet(GameLossReason.Milled, null); } // Rule 704.5c - If a player has ten or more poison counters, he or she loses the game. - if (this.poisonCounters >= 10) { - return this.loseConditionMet(GameLossReason.Poisoned, null); + if (poisonCounters >= 10) { + return loseConditionMet(GameLossReason.Poisoned, null); } if (game.getRules().hasAppliedVariant(GameType.Commander)) { Map cmdDmg = getCommanderDamage(); for (Card c : cmdDmg.keySet()) { if (cmdDmg.get(c) >= 21) { - return this.loseConditionMet(GameLossReason.CommanderDamage, null); + return loseConditionMet(GameLossReason.CommanderDamage, null); } } } @@ -2293,17 +1784,17 @@ public class Player extends GameEntity implements Comparable, IIdentifia } public final boolean hasLost() { - return this.getOutcome() != null && this.getOutcome().lossState != null; + return getOutcome() != null && getOutcome().lossState != null; } public final boolean hasWon() { - if (this.cantWin()) { + if (cantWin()) { return false; } // in multiplayer game one player's win is replaced by all other's lose (rule 103.4h) // so if someone cannot lose, the game appears to continue - return this.getOutcome() != null && this.getOutcome().lossState == null; + return getOutcome() != null && getOutcome().lossState == null; } /** @@ -2314,7 +1805,7 @@ public class Player extends GameEntity implements Comparable, IIdentifia * @return a boolean. */ public final boolean hasMetalcraft() { - final List list = CardLists.filter(this.getCardsIn(ZoneType.Battlefield), CardPredicates.Presets.ARTIFACTS); + final List list = CardLists.filter(getCardsIn(ZoneType.Battlefield), CardPredicates.Presets.ARTIFACTS); return list.size() >= 3; } @@ -2326,7 +1817,7 @@ public class Player extends GameEntity implements Comparable, IIdentifia * @return a boolean. */ public final boolean hasThreshold() { - return this.getZone(ZoneType.Graveyard).size() >= 7; + return getZone(ZoneType.Graveyard).size() >= 7; } /** @@ -2337,7 +1828,7 @@ public class Player extends GameEntity implements Comparable, IIdentifia * @return a boolean. */ public final boolean hasHellbent() { - return this.getZone(ZoneType.Hand).isEmpty(); + return getZone(ZoneType.Hand).isEmpty(); } /** @@ -2348,7 +1839,7 @@ public class Player extends GameEntity implements Comparable, IIdentifia * @return a boolean. */ public final boolean hasLandfall() { - final List list = this.getZone(ZoneType.Battlefield).getCardsAddedThisTurn(null); + final List list = getZone(ZoneType.Battlefield).getCardsAddedThisTurn(null); return Iterables.any(list, CardPredicates.Presets.LANDS); } @@ -2360,7 +1851,7 @@ public class Player extends GameEntity implements Comparable, IIdentifia * @return a boolean. */ public final boolean hasBloodthirst() { - for (Player opp : this.getOpponents()) { + for (Player opp : getOpponents()) { if (opp.getAssignedDamage() > 0) { return true; } @@ -2377,7 +1868,7 @@ public class Player extends GameEntity implements Comparable, IIdentifia * @return a boolean. */ public boolean hasFerocious() { - final List list = this.getCreaturesInPlay(); + final List list = getCreaturesInPlay(); final List ferocious = CardLists.filter(list, new Predicate() { @Override public boolean apply(final Card c) { @@ -2396,7 +1887,7 @@ public class Player extends GameEntity implements Comparable, IIdentifia */ public final int getBloodthirstAmount() { int blood = 0; - for (Player opp : this.getOpponents()) { + for (Player opp : getOpponents()) { blood += opp.getAssignedDamage(); } return blood; @@ -2412,10 +1903,10 @@ public class Player extends GameEntity implements Comparable, IIdentifia * @return a boolean. */ public final boolean hasProwl(final String type) { - if (this.prowl.contains("AllCreatureTypes")) { + if (prowl.contains("AllCreatureTypes")) { return true; } - return this.prowl.contains(type); + return prowl.contains(type); } /** @@ -2425,42 +1916,42 @@ public class Player extends GameEntity implements Comparable, IIdentifia * the type */ public final void addProwlType(final String type) { - this.prowl.add(type); + prowl.add(type); } /** * Reset prowl. */ public final void resetProwl() { - this.prowl = new ArrayList(); + prowl = new ArrayList(); } public final void setLibrarySearched(final int l) { - this.numLibrarySearchedOwn = l; + numLibrarySearchedOwn = l; } public final int getLibrarySearched() { - return this.numLibrarySearchedOwn; + return numLibrarySearchedOwn; } public final void incLibrarySearched() { - this.numLibrarySearchedOwn++; + numLibrarySearchedOwn++; } public final void setNumManaConversion(final int l) { - this.numManaConversion = l; + numManaConversion = l; } public final boolean hasManaConversion() { - return this.numManaConversion < this.getAmountOfKeyword("You may spend mana as though" + return numManaConversion < getAmountOfKeyword("You may spend mana as though" + " it were mana of any color to cast a spell this turn."); } public final void incNumManaConversion() { - this.numManaConversion++; + numManaConversion++; } public final void decNumManaConversion() { - this.numManaConversion--; + numManaConversion--; } /* @@ -2473,11 +1964,11 @@ public class Player extends GameEntity implements Comparable, IIdentifia final String[] incR = restriction.split("\\."); if (incR[0].equals("Opponent")) { - if (this.equals(sourceController) || !this.isOpponentOf(sourceController)) { + if (equals(sourceController) || !isOpponentOf(sourceController)) { return false; } } else if (incR[0].equals("You")) { - if (!this.equals(sourceController)) { + if (!equals(sourceController)) { return false; } } else if (incR[0].equals("EnchantedController")) { @@ -2486,7 +1977,7 @@ public class Player extends GameEntity implements Comparable, IIdentifia return false; } final Card enchantedCard = (Card) enchanted; - if (!this.equals(enchantedCard.getController())) { + if (!equals(enchantedCard.getController())) { return false; } } else { @@ -2500,7 +1991,7 @@ public class Player extends GameEntity implements Comparable, IIdentifia final String[] exR = excR.split("\\+"); // Exclusive Restrictions // are ... for (int j = 0; j < exR.length; j++) { - if (!this.hasProperty(exR[j], sourceController, source)) { + if (!hasProperty(exR[j], sourceController, source)) { return false; } } @@ -2518,28 +2009,28 @@ public class Player extends GameEntity implements Comparable, IIdentifia @Override public final boolean hasProperty(final String property, final Player sourceController, final Card source) { if (property.equals("You")) { - if (!this.equals(sourceController)) { + if (!equals(sourceController)) { return false; } } else if (property.equals("Opponent")) { - if (this.equals(sourceController) || !this.isOpponentOf(sourceController)) { + if (equals(sourceController) || !isOpponentOf(sourceController)) { return false; } } else if (property.equals("Allies")) { - if (this.equals(sourceController) || this.isOpponentOf(sourceController)) { + if (equals(sourceController) || isOpponentOf(sourceController)) { return false; } } else if (property.equals("NonActive")) { - if (this.equals(game.getPhaseHandler().getPlayerTurn())) { + if (equals(game.getPhaseHandler().getPlayerTurn())) { return false; } } else if (property.equals("OpponentToActive")) { final Player active = game.getPhaseHandler().getPlayerTurn(); - if (this.equals(active) || !this.isOpponentOf(active)) { + if (equals(active) || !isOpponentOf(active)) { return false; } } else if (property.equals("Other")) { - if (this.equals(sourceController)) { + if (equals(sourceController)) { return false; } } else if (property.equals("wasDealtDamageBySourceThisGame")) { @@ -2551,27 +2042,27 @@ public class Player extends GameEntity implements Comparable, IIdentifia return false; } } else if (property.equals("attackedBySourceThisCombat")) { - if (game.getCombat() == null || !this.equals(game.getCombat().getDefenderPlayerByAttacker(source))) { + if (game.getCombat() == null || !equals(game.getCombat().getDefenderPlayerByAttacker(source))) { return false; } } else if (property.startsWith("wasDealtDamageThisTurn")) { - if (this.assignedDamage.isEmpty()) { + if (assignedDamage.isEmpty()) { return false; } } else if (property.startsWith("LostLifeThisTurn")) { - if (this.lifeLostThisTurn <= 0) { + if (lifeLostThisTurn <= 0) { return false; } } else if (property.startsWith("DeclaredAttackerThisTurn")) { - if (this.attackersDeclaredThisTurn <= 0) { + if (attackersDeclaredThisTurn <= 0) { return false; } } else if (property.startsWith("NoCardsInHandAtBeginningOfTurn")) { - if (this.numCardsInHandStartedThisTurnWith > 0) { + if (numCardsInHandStartedThisTurnWith > 0) { return false; } } else if (property.startsWith("CardsInHandAtBeginningOfTurn")) { - if (this.numCardsInHandStartedThisTurnWith <= 0) { + if (numCardsInHandStartedThisTurnWith <= 0) { return false; } } else if (property.equals("IsRemembered")) { @@ -2583,7 +2074,7 @@ public class Player extends GameEntity implements Comparable, IIdentifia return false; } } else if (property.startsWith("EnchantedBy")) { - if (!this.getEnchantedBy().contains(source)) { + if (!getEnchantedBy().contains(source)) { return false; } } else if (property.startsWith("Chosen")) { @@ -2592,17 +2083,17 @@ public class Player extends GameEntity implements Comparable, IIdentifia } } else if (property.startsWith("LifeEquals_")) { int life = AbilityUtils.calculateAmount(source, property.substring(11), null); - if (this.getLife() != life) { + if (getLife() != life) { return false; } } else if (property.equals("IsPoisoned")) { - if (this.getPoisonCounters() <= 0) { - return false; - } + if (getPoisonCounters() <= 0) { + return false; + } } else if (property.startsWith("withMore")) { final String cardType = property.split("sThan")[0].substring(8); final Player controller = "Active".equals(property.split("sThan")[1]) ? game.getPhaseHandler().getPlayerTurn() : sourceController; - final List oppList = CardLists.filter(this.getCardsIn(ZoneType.Battlefield), CardPredicates.isType(cardType)); + final List oppList = CardLists.filter(getCardsIn(ZoneType.Battlefield), CardPredicates.isType(cardType)); final List yourList = CardLists.filter(controller.getCardsIn(ZoneType.Battlefield), CardPredicates.isType(cardType)); if (oppList.size() <= yourList.size()) { return false; @@ -2611,7 +2102,7 @@ public class Player extends GameEntity implements Comparable, IIdentifia final String cardType = property.split("More")[1].split("sThan")[0]; final int amount = Integer.parseInt(property.substring(11, 12)); final Player controller = "Active".equals(property.split("sThan")[1]) ? game.getPhaseHandler().getPlayerTurn() : sourceController; - final List oppList = CardLists.filter(this.getCardsIn(ZoneType.Battlefield), CardPredicates.isType(cardType)); + final List oppList = CardLists.filter(getCardsIn(ZoneType.Battlefield), CardPredicates.isType(cardType)); final List yourList = CardLists.filter(controller.getCardsIn(ZoneType.Battlefield), CardPredicates.isType(cardType)); System.out.println(yourList.size()); if (oppList.size() < yourList.size() + amount) { @@ -2619,16 +2110,16 @@ public class Player extends GameEntity implements Comparable, IIdentifia } } else if (property.startsWith("hasMore")) { final Player controller = property.contains("Than") && "Active".equals(property.split("Than")[1]) ? game.getPhaseHandler().getPlayerTurn() : sourceController; - if (property.substring(7).startsWith("Life") && this.getLife() <= controller.getLife()) { + if (property.substring(7).startsWith("Life") && getLife() <= controller.getLife()) { return false; } else if (property.substring(7).startsWith("CardsInHand") - && this.getCardsIn(ZoneType.Hand).size() <= controller.getCardsIn(ZoneType.Hand).size()) { + && getCardsIn(ZoneType.Hand).size() <= controller.getCardsIn(ZoneType.Hand).size()) { return false; } } else if (property.startsWith("hasFewer")) { final Player controller = "Active".equals(property.split("Than")[1]) ? game.getPhaseHandler().getPlayerTurn() : sourceController; if (property.substring(8).startsWith("CreaturesInYard")) { - final List oppList = CardLists.filter(this.getCardsIn(ZoneType.Graveyard), Presets.CREATURES); + final List oppList = CardLists.filter(getCardsIn(ZoneType.Graveyard), Presets.CREATURES); final List yourList = CardLists.filter(controller.getCardsIn(ZoneType.Graveyard), Presets.CREATURES); if (oppList.size() >= yourList.size()) { return false; @@ -2636,13 +2127,13 @@ public class Player extends GameEntity implements Comparable, IIdentifia } } else if (property.startsWith("withMost")) { if (property.substring(8).equals("Life")) { - int highestLife = this.getLife(); // Negative base just in case a few Lich's are running around + int highestLife = getLife(); // Negative base just in case a few Lich's are running around for (final Player p : game.getPlayers()) { if (p.getLife() > highestLife) { highestLife = p.getLife(); } } - if (this.getLife() != highestLife) { + if (getLife() != highestLife) { return false; } } @@ -2655,7 +2146,7 @@ public class Player extends GameEntity implements Comparable, IIdentifia withLargestHand = p; } } - if (!this.equals(withLargestHand)) { + if (!equals(withLargestHand)) { return false; } } @@ -2687,7 +2178,7 @@ public class Player extends GameEntity implements Comparable, IIdentifia } } else if (property.startsWith("withLowest")) { if (property.substring(10).equals("Life")) { - int lowestLife = this.getLife(); + int lowestLife = getLife(); List lowestlifep = new ArrayList(); for (final Player p : game.getPlayers()) { if (p.getLife() == lowestLife) { @@ -2741,7 +2232,7 @@ public class Player extends GameEntity implements Comparable, IIdentifia * @param unlimitedHandSize0 the unlimitedHandSize to set */ public void setUnlimitedHandSize(boolean unlimited) { - this.unlimitedHandSize = unlimited; + unlimitedHandSize = unlimited; } /** @@ -2803,7 +2294,7 @@ public class Player extends GameEntity implements Comparable, IIdentifia * @return a int. */ public final int getLifeGainedThisTurn() { - return this.lifeGainedThisTurn; + return lifeGainedThisTurn; } /** @@ -2815,7 +2306,7 @@ public class Player extends GameEntity implements Comparable, IIdentifia * a int. */ public final void setLifeGainedThisTurn(final int n) { - this.lifeGainedThisTurn = n; + lifeGainedThisTurn = n; } /** @@ -2826,7 +2317,7 @@ public class Player extends GameEntity implements Comparable, IIdentifia * @return a int. */ public final int getLifeLostThisTurn() { - return this.lifeLostThisTurn; + return lifeLostThisTurn; } /** @@ -2838,7 +2329,7 @@ public class Player extends GameEntity implements Comparable, IIdentifia * a int. */ public final void setLifeLostThisTurn(final int n) { - this.lifeLostThisTurn = n; + lifeLostThisTurn = n; } /** @@ -2849,7 +2340,7 @@ public class Player extends GameEntity implements Comparable, IIdentifia * @return a int. */ public final int getLifeLostLastTurn() { - return this.lifeLostLastTurn; + return lifeLostLastTurn; } /** @@ -2861,7 +2352,7 @@ public class Player extends GameEntity implements Comparable, IIdentifia * a int. */ public final void setLifeLostLastTurn(final int n) { - this.lifeLostLastTurn = n; + lifeLostLastTurn = n; } /** @@ -2874,7 +2365,7 @@ public class Player extends GameEntity implements Comparable, IIdentifia * @since 1.1.01 */ public final void setMustAttackEntity(final GameEntity o) { - this.mustAttackEntity = o; + mustAttackEntity = o; } /** @@ -2885,7 +2376,7 @@ public class Player extends GameEntity implements Comparable, IIdentifia * @since 1.1.01 */ public final GameEntity getMustAttackEntity() { - return this.mustAttackEntity; + return mustAttackEntity; } // ////////////////////////////// @@ -2899,7 +2390,7 @@ public class Player extends GameEntity implements Comparable, IIdentifia public final boolean equals(final Object o) { if (o instanceof Player) { final Player p1 = (Player) o; - return p1.getName().equals(this.getName()); + return p1.getName().equals(getName()); } else { return false; } @@ -2910,7 +2401,7 @@ public class Player extends GameEntity implements Comparable, IIdentifia if (o == null) { return +1; } - int subtractedHash = o.hashCode() - this.hashCode(); + int subtractedHash = o.hashCode() - hashCode(); if (subtractedHash == 0) { return 0; } @@ -2921,7 +2412,7 @@ public class Player extends GameEntity implements Comparable, IIdentifia /** {@inheritDoc} */ @Override public int hashCode() { - return (41 * (41 + this.getName().hashCode())); + return (41 * (41 + getName().hashCode())); } public static class Predicates { @@ -2932,10 +2423,10 @@ public class Player extends GameEntity implements Comparable, IIdentifia } }; public static final Predicate CANT_WIN = new Predicate() { - @Override - public boolean apply(final Player p) { - return p.hasKeyword("You can't win the game."); - } + @Override + public boolean apply(final Player p) { + return p.hasKeyword("You can't win the game."); + } }; } @@ -2947,29 +2438,25 @@ public class Player extends GameEntity implements Comparable, IIdentifia } }; public static Function FN_GET_LIFE_TOTAL = new Function() { - @Override - public Integer apply(Player input) { - return input.getLife(); - } + @Override + public Integer apply(Player input) { + return input.getLife(); + } }; public static Function FN_GET_POISON_COUNTERS = new Function() { - @Override - public Integer apply(Player input) { - return input.getPoisonCounters(); - } + @Override + public Integer apply(Player input) { + return input.getPoisonCounters(); + } }; public static final Function FN_GET_ASSIGNED_DAMAGE = new Function() { - @Override - public Integer apply(Player input) { - return input.getAssignedDamage(); - } + @Override + public Integer apply(Player input) { + return input.getAssignedDamage(); + } }; } - /** - * TODO: Write javadoc for this method. - * @return - */ public final LobbyPlayer getLobbyPlayer() { return getController().getLobbyPlayer(); } @@ -3020,10 +2507,6 @@ public class Player extends GameEntity implements Comparable, IIdentifia /** * use to get a list of creatures in play for a given player. - * - * @param player - * the player to get creatures for - * @return a List containing all creatures a given player has in play */ public List getCreaturesInPlay() { return CardLists.filter(getCardsIn(ZoneType.Battlefield), Presets.CREATURES); @@ -3031,14 +2514,11 @@ public class Player extends GameEntity implements Comparable, IIdentifia /** * use to get a list of all lands a given player has on the battlefield. - * - * @param player - * the player whose lands we want to get - * @return a List containing all lands the given player has in play */ public List getLandsInPlay() { return CardLists.filter(getCardsIn(ZoneType.Battlefield), Presets.LANDS); } + public boolean isCardInPlay(final String cardName) { return getZone(ZoneType.Battlefield).contains(CardPredicates.nameEquals(cardName)); } @@ -3053,7 +2533,7 @@ public class Player extends GameEntity implements Comparable, IIdentifia public int getTokenDoublersMagnitude() { int tokenDoublers = 0; - for (String kw : this.getKeywords()) { + for (String kw : getKeywords()) { if (kw.equals("TokenDoubler")) { tokenDoublers++; } @@ -3063,7 +2543,7 @@ public class Player extends GameEntity implements Comparable, IIdentifia public final int getAmountOfKeyword(final String k) { int count = 0; - for (String kw : this.getKeywords()) { + for (String kw : getKeywords()) { if (kw.equals(k)) { count++; } @@ -3079,7 +2559,7 @@ public class Player extends GameEntity implements Comparable, IIdentifia resetPreventNextDamageWithEffect(); resetNumDrawnThisTurn(); resetNumDiscardedThisTurn(); - setNumCardsInHandStartedThisTurnWith(this.getCardsIn(ZoneType.Hand).size()); + setNumCardsInHandStartedThisTurnWith(getCardsIn(ZoneType.Hand).size()); setAttackedWithCreatureThisTurn(false); setActivateLoyaltyAbilityThisTurn(false); resetLandsPlayedThisTurn(); @@ -3092,18 +2572,7 @@ public class Player extends GameEntity implements Comparable, IIdentifia return now.isPlayerTurn(this) && now.getPhase().isMain() && game.getStack().isEmpty(); } - /** - *

- * couldCastSorcery. - * for conditions the stack must only have the sa being checked - *

- * - * @param player - * a {@link forge.game.player.Player} object. - * @param sa - * a {@link forge.game.player.SpellAbility} object. - * @return a boolean . - */ + //NOTE: for conditions the stack must only have the sa being checked public boolean couldCastSorcery(final SpellAbility sa) { final Card source = sa.getRootAbility().getHostCard(); boolean onlyThis = true; @@ -3136,8 +2605,6 @@ public class Player extends GameEntity implements Comparable, IIdentifia /** * Run a procedure using a different controller - * @param proc - * @param tempController */ public void runWithController(Runnable proc, PlayerController tempController) { PlayerController oldController = controller; @@ -3149,13 +2616,6 @@ public class Player extends GameEntity implements Comparable, IIdentifia } } - /** - *

- * skipCombat. - *

- * - * @return a boolean. - */ public boolean isSkippingCombat() { if (hasKeyword("Skip your next combat phase.")) { return true; @@ -3175,15 +2635,14 @@ public class Player extends GameEntity implements Comparable, IIdentifia } public int getStartingHandSize() { - return this.startingHandSize; + return startingHandSize; } public void setStartingHandSize(int shs) { - this.startingHandSize = shs; + startingHandSize = shs; } /** - * * Takes the top plane of the planar deck and put it face up in the command zone. * Then runs triggers. */ @@ -3194,11 +2653,9 @@ public class Player extends GameEntity implements Comparable, IIdentifia /** * Puts the planes in the argument and puts them face up in the command zone. * Then runs triggers. - * - * @param destinations The planes to planeswalk to. */ public void planeswalkTo(final List destinations) { - System.out.println(this.getName() + ": planeswalk to " + destinations.toString()); + System.out.println(getName() + ": planeswalk to " + destinations.toString()); currentPlanes.addAll(destinations); for (Card c : currentPlanes) { @@ -3219,7 +2676,6 @@ public class Player extends GameEntity implements Comparable, IIdentifia } /** - * * Puts my currently active planes, if any, at the bottom of my planar deck. */ public void leaveCurrentPlane() { @@ -3244,7 +2700,6 @@ public class Player extends GameEntity implements Comparable, IIdentifia } /** - * * Sets up the first plane of a round. */ public void initPlane() { @@ -3261,18 +2716,9 @@ public class Player extends GameEntity implements Comparable, IIdentifia break; } } - game.setActivePlanes(currentPlanes); } - /** - *

- * resetAttackedThisCombat. - *

- * - * @param player - * a {@link forge.game.player.Player} object. - */ public final void resetAttackedThisCombat() { // resets the status of attacked/blocked this phase List list = CardLists.filter(getCardsIn(ZoneType.Battlefield), Presets.CREATURES); @@ -3292,14 +2738,6 @@ public class Player extends GameEntity implements Comparable, IIdentifia } } - /** - *

- * drawMiracle. - *

- * - * @param card - * a {@link forge.game.card.Card} object. - */ public final void drawMiracle(final Card card) { // Whenever a card with miracle is the first card drawn in a turn, // you may cast it for it's miracle cost @@ -3325,11 +2763,9 @@ public class Player extends GameEntity implements Comparable, IIdentifia removeKeyword("Skip your next draw step."); return true; } - if (hasKeyword("Skip your draw step.")) { return true; } - return false; } @@ -3344,15 +2780,9 @@ public class Player extends GameEntity implements Comparable, IIdentifia private final class MiracleTrigger extends Ability { private final SpellAbility miracle; - /** - * TODO: Write javadoc for Constructor. - * @param sourceCard - * @param manaCost - * @param miracle - */ - private MiracleTrigger(Card sourceCard, ManaCost manaCost, SpellAbility miracle) { - super(sourceCard, manaCost); - this.miracle = miracle; + private MiracleTrigger(Card sourceCard0, ManaCost manaCost0, SpellAbility miracle0) { + super(sourceCard0, manaCost0); + miracle = miracle0; } @Override @@ -3371,40 +2801,23 @@ public class Player extends GameEntity implements Comparable, IIdentifia achievementTracker.mulliganTo = newHand; } - /** - * @return the commander - */ public Card getCommander() { return commander; } - - /** - * @param commander0 the commander to set - */ public void setCommander(Card commander0) { - this.commander = commander0; + commander = commander0; } - /** - * @return the commanderDamage - */ public Map getCommanderDamage() { return commanderDamage; } - /** - * @param b isPlayingExtraTurn to set - */ - public void setExtraTurn(boolean b) { - this.isPlayingExtraTrun = b; - } - - /** - * @return a boolean - */ public boolean isPlayingExtraTurn() { return isPlayingExtraTrun; } + public void setExtraTurn(boolean b) { + isPlayingExtraTrun = b; + } public void initVariantsZones(RegisteredPlayer registeredPlayer) { PlayerZone bf = getZone(ZoneType.Battlefield); @@ -3487,20 +2900,22 @@ public class Player extends GameEntity implements Comparable, IIdentifia // If gained then lost, just clear out of gained. Player oldOwner = card.getOwner(); - if (this.equals(oldOwner)) { + if (equals(oldOwner)) { return; } card.setOwner(this); - if (this.lostOwnership.contains(card)) { - this.lostOwnership.remove(card); - } else { - this.gainedOwnership.add(card); + if (lostOwnership.contains(card)) { + lostOwnership.remove(card); + } + else { + gainedOwnership.add(card); } if (oldOwner.gainedOwnership.contains(card)) { oldOwner.gainedOwnership.remove(card); - } else { + } + else { oldOwner.lostOwnership.add(card); } } @@ -3513,4 +2928,8 @@ public class Player extends GameEntity implements Comparable, IIdentifia return gainedOwnership; } + @Override + public PlayerView getView() { + return view; + } } diff --git a/forge-game/src/main/java/forge/game/player/PlayerView.java b/forge-game/src/main/java/forge/game/player/PlayerView.java new file mode 100644 index 00000000000..1f8914e43a0 --- /dev/null +++ b/forge-game/src/main/java/forge/game/player/PlayerView.java @@ -0,0 +1,207 @@ +package forge.game.player; + +import java.util.Map; + +import com.google.common.collect.Maps; + +import forge.LobbyPlayer; +import forge.card.MagicColor; +import forge.game.GameEntityView; +import forge.game.card.CardFactoryUtil; +import forge.game.card.CardView; +import forge.game.zone.PlayerZone; +import forge.game.zone.ZoneType; +import forge.trackable.TrackableCollection; +import forge.trackable.TrackableProperty.PlayerProp; + + +public class PlayerView extends GameEntityView { + public static PlayerView get(Player p) { + return p == null ? null : p.getView(); + } + + public static TrackableCollection getCollection(Iterable players) { + if (players == null) { + return null; + } + TrackableCollection collection = new TrackableCollection(); + for (Player p : players) { + collection.add(p.getView()); + } + return collection; + } + + public PlayerView(int id0) { + super(id0, PlayerProp.class); + + set(PlayerProp.Mana, Maps.newHashMapWithExpectedSize(MagicColor.NUMBER_OR_COLORS + 1)); + } + + public LobbyPlayer getLobbyPlayer() { + return get(PlayerProp.LobbyPlayer); + } + void updateLobbyPlayer(Player p) { + set(PlayerProp.LobbyPlayer, p.getLobbyPlayer()); + } + + public Iterable getOpponents() { + return get(PlayerProp.Opponents); + } + private TrackableCollection getOpponentCollection() { + return get(PlayerProp.Opponents); + } + + public boolean isOpponentOf(final PlayerView other) { + return getOpponentCollection().contains(other); + } + + public String getName() { + return getLobbyPlayer().getName(); + } + + @Override + public String toString() { + return getName(); + } + + public int getLife() { + return get(PlayerProp.Life); + } + void updateLife(Player p) { + set(PlayerProp.Life, p.getLife()); + } + + public int getPoisonCounters() { + return get(PlayerProp.PoisonCounters); + } + void updatePoisonCounters(Player p) { + set(PlayerProp.PoisonCounters, p.getPoisonCounters()); + } + + public int getMaxHandSize() { + return get(PlayerProp.MaxHandSize); + } + void updateMaxHandSize(Player p) { + set(PlayerProp.MaxHandSize, p.getMaxHandSize()); + } + + public boolean hasUnlimitedHandSize() { + return get(PlayerProp.HasUnlimitedHandSize); + } + void updateUnlimitedHandSize(Player p) { + set(PlayerProp.HasUnlimitedHandSize, p.isUnlimitedHandSize()); + } + + public int getNumDrawnThisTurn() { + return get(PlayerProp.NumDrawnThisTurn); + } + void updateNumDrawnThisTurn(Player p) { + set(PlayerProp.NumDrawnThisTurn, p.getNumDrawnThisTurn()); + } + + public Iterable getKeywords() { + return get(PlayerProp.Keywords); + } + void updateKeywords(Player p) { + set(PlayerProp.Keywords, p.getKeywords()); + } + + public String getCommanderInfo() { + return get(PlayerProp.CommanderInfo); + } + void updateCommanderInfo(Player p) { + set(PlayerProp.CommanderInfo, CardFactoryUtil.getCommanderInfo(p).trim().replace("\r\n", "; ")); + } + + public Iterable getAnte() { + return get(PlayerProp.Ante); + } + + public Iterable getBattlefield() { + return get(PlayerProp.Battlefield); + } + + public Iterable getCommand() { + return get(PlayerProp.Command); + } + + public Iterable getExile() { + return get(PlayerProp.Exile); + } + + public Iterable getFlashback() { + return get(PlayerProp.Flashback); + } + + public Iterable getGraveyard() { + return get(PlayerProp.Graveyard); + } + + public Iterable getHand() { + return get(PlayerProp.Hand); + } + + public Iterable getLibrary() { + return get(PlayerProp.Library); + } + + public Iterable getCards(final ZoneType zone) { + PlayerProp prop = getZoneProp(zone); + if (prop != null) { + return get(prop); + } + return null; + } + private PlayerProp getZoneProp(final ZoneType zone) { + switch (zone) { + case Ante: + return PlayerProp.Ante; + case Battlefield: + return PlayerProp.Battlefield; + case Command: + return PlayerProp.Command; + case Exile: + return PlayerProp.Exile; + case Graveyard: + return PlayerProp.Graveyard; + case Hand: + return PlayerProp.Hand; + case Library: + return PlayerProp.Library; + default: + return null; //other zones not represented + } + } + void updateZone(PlayerZone zone) { + PlayerProp prop = getZoneProp(zone.getZoneType()); + if (prop == null) { return; } + set(prop, CardView.getCollection(zone.getCards())); + } + + private Map getMana() { + return get(PlayerProp.Mana); + } + void updateMana(Player p) { + boolean changed = false; + Map mana = getMana(); + for (byte b : MagicColor.WUBRGC) { + int value = p.getManaPool().getAmountOfColor(b); + if (mana.put(b, value) != value) { + changed = true; + } + } + if (changed) { + flagAsChanged(PlayerProp.Mana); + } + } + + public int getMana(final byte color) { + Integer count = getMana().get(color); + return count != null ? count.intValue() : 0; + } + + @Override + protected PlayerProp preventNextDamageProp() { + return PlayerProp.PreventNextDamage; + } +} \ No newline at end of file diff --git a/forge-game/src/main/java/forge/game/replacement/ReplacementHandler.java b/forge-game/src/main/java/forge/game/replacement/ReplacementHandler.java index e68bc966240..2eefd5983ce 100644 --- a/forge-game/src/main/java/forge/game/replacement/ReplacementHandler.java +++ b/forge-game/src/main/java/forge/game/replacement/ReplacementHandler.java @@ -233,8 +233,8 @@ public class ReplacementHandler implements IGameStateObject { // Replaced mana type final Card repHost = replacementEffect.getHostCard(); String repType = repHost.getSVar(mapParams.get("ManaReplacement")); - if (repType.contains("Chosen") && !repHost.getChosenColor().isEmpty()) { - repType = repType.replace("Chosen", MagicColor.toShortString(repHost.getChosenColor().get(0))); + if (repType.contains("Chosen") && !repHost.getChosenColors().isEmpty()) { + repType = repType.replace("Chosen", MagicColor.toShortString(repHost.getChosenColors().get(0))); } manaAb.getManaPart().setManaReplaceType(repType); manaAb.getManaPart().produceMana(rep, player1, manaAb); diff --git a/forge-game/src/main/java/forge/game/spellability/AbilityManaPart.java b/forge-game/src/main/java/forge/game/spellability/AbilityManaPart.java index c44c21022ad..3cf309eb4e5 100644 --- a/forge-game/src/main/java/forge/game/spellability/AbilityManaPart.java +++ b/forge-game/src/main/java/forge/game/spellability/AbilityManaPart.java @@ -341,9 +341,9 @@ public class AbilityManaPart implements java.io.Serializable { */ public final String mana() { if (this.getOrigProduced().contains("Chosen")) { - if (this.getSourceCard() != null && !this.getSourceCard().getChosenColor().isEmpty()) { + if (this.getSourceCard() != null && !this.getSourceCard().getChosenColors().isEmpty()) { return MagicColor.toShortString(this.getSourceCard() - .getChosenColor().get(0)); + .getChosenColors().get(0)); } } return this.getOrigProduced(); @@ -473,7 +473,7 @@ public class AbilityManaPart implements java.io.Serializable { } if (this.getOrigProduced().contains("Chosen") && sourceCard != null ) { - List chosenCol = this.getSourceCard().getChosenColor(); + List chosenCol = this.getSourceCard().getChosenColors(); if ( !chosenCol.isEmpty() && MagicColor.toShortString(chosenCol.get(0)).contains(s)) { return true; } diff --git a/forge-game/src/main/java/forge/game/spellability/SpellAbility.java b/forge-game/src/main/java/forge/game/spellability/SpellAbility.java index 6b40307c58d..5b1122a84e9 100644 --- a/forge-game/src/main/java/forge/game/spellability/SpellAbility.java +++ b/forge-game/src/main/java/forge/game/spellability/SpellAbility.java @@ -55,15 +55,14 @@ import java.util.*; * @version $Id$ */ public abstract class SpellAbility extends CardTraitBase implements ISpellAbility, IIdentifiable { - private static int maxId = 0; private static int nextId() { return ++maxId; } public static class EmptySa extends SpellAbility { public EmptySa(Card sourceCard) { super(sourceCard, Cost.Zero); setActivatingPlayer(sourceCard.getController());} - public EmptySa(ApiType api, Card sourceCard) { super(sourceCard, Cost.Zero); setActivatingPlayer(sourceCard.getController()); this.api = api;} + public EmptySa(ApiType api0, Card sourceCard) { super(sourceCard, Cost.Zero); setActivatingPlayer(sourceCard.getController()); api = api0;} public EmptySa(Card sourceCard, Player activator) { super(sourceCard, Cost.Zero); setActivatingPlayer(activator);} - public EmptySa(ApiType api, Card sourceCard, Player activator) { super(sourceCard, Cost.Zero); setActivatingPlayer(activator); this.api = api;} + public EmptySa(ApiType api0, Card sourceCard, Player activator) { super(sourceCard, Cost.Zero); setActivatingPlayer(activator); api = api0;} @Override public void resolve() {} @Override public boolean canPlay() { return false; } } @@ -82,8 +81,6 @@ public abstract class SpellAbility extends CardTraitBase implements ISpellAbilit private Card grantorCard = null; // card which grants the ability (equipment or owner of static ability that gave this one) private List splicedCards = null; -// private List targetList; - // targetList doesn't appear to be used anymore private boolean basicSpell = true; private boolean trigger = false; @@ -131,6 +128,32 @@ public abstract class SpellAbility extends CardTraitBase implements ISpellAbilit private boolean isCopied = false; + private EnumSet optionalCosts = EnumSet.noneOf(OptionalCost.class); + private TargetRestrictions targetRestrictions = null; + private TargetChoices targetChosen = new TargetChoices(); + + private final SpellAbilityView view; + + public SpellAbility(final Card iSourceCard, Cost toPay) { + id = nextId(); + hostCard = iSourceCard; + payCosts = toPay; + view = new SpellAbilityView(this); + } + + @Override + public int getId() { + return id; + } + + @Override + public void setHostCard(final Card c) { + if (hostCard == c) { return; } + super.setHostCard(c); + view.updateHostCard(this); + view.updateDescription(this); //description can change if host card does + } + public final AbilityManaPart getManaPart() { return manaPart; } @@ -148,23 +171,23 @@ public abstract class SpellAbility extends CardTraitBase implements ISpellAbilit public final boolean isManaAbility() { // Check whether spell or ability first - if (this.isSpell()) { + if (isSpell()) { return false; } // without a target - if (this.usesTargeting()) { return false; } + if (usesTargeting()) { return false; } if (restrictions != null && restrictions.isPwAbility()) { return false; //Loyalty ability, not a mana ability. } - if (this.isWrapper() && ((WrappedAbility) this).getTrigger().getMode() != TriggerType.TapsForMana) { + if (isWrapper() && ((WrappedAbility) this).getTrigger().getMode() != TriggerType.TapsForMana) { return false; } return getManaPartRecursive() != null; } - protected final void setManaPart(AbilityManaPart manaPart) { - this.manaPart = manaPart; + protected final void setManaPart(AbilityManaPart manaPart0) { + manaPart = manaPart0; } public final String getSVar(final String name) { @@ -194,209 +217,67 @@ public abstract class SpellAbility extends CardTraitBase implements ISpellAbilit return sVars.keySet(); } - /** - *

- * Constructor for SpellAbility. - *

- * - * @param spellOrAbility - * a int. - * @param iSourceCard - * a {@link forge.game.card.Card} object. - */ - public SpellAbility(final Card iSourceCard, Cost toPay) { - this.id = nextId(); - this.hostCard = iSourceCard; - this.payCosts = toPay; - } - - @Override - public int getId() { - return id; - } - // Spell, and Ability, and other Ability objects override this method - /** - *

- * canPlay. - *

- * - * @return a boolean. - */ public abstract boolean canPlay(); - /** - *

- * isPossible. - *

- * - * @return a boolean. - */ public boolean isPossible() { return canPlay(); //by default, ability is only possible if it can be played } - /** - *

- * promptIfOnlyPossibleAbility. - *

- * - * @return a boolean. - */ public boolean promptIfOnlyPossibleAbility() { return false; //by default, don't prompt user if ability is only possible ability } // all Spell's and Abilities must override this method - /** - *

- * resolve. - *

- */ public abstract void resolve(); - /** - *

- * Getter for the field multiKickerManaCost. - *

- * - * @return a {@link java.lang.String} object. - */ public ManaCost getMultiKickerManaCost() { - return this.multiKickerManaCost; + return multiKickerManaCost; } - - /** - *

- * Setter for the field multiKickerManaCost. - *

- * - * @param cost - * a {@link java.lang.String} object. - */ public void setMultiKickerManaCost(final ManaCost cost) { - this.multiKickerManaCost = cost; + multiKickerManaCost = cost; } - - /** - *

- * Getter for the field activatingPlayer. - *

- * - * @return a {@link forge.game.player.Player} object. - */ public Player getActivatingPlayer() { - return this.activatingPlayer; + return activatingPlayer; } - - /** - *

- * Setter for the field activatingPlayer. - *

- * - * @param player - * a {@link forge.game.player.Player} object. - */ public void setActivatingPlayer(final Player player) { // trickle down activating player - this.activatingPlayer = player; - if (this.subAbility != null) { - this.subAbility.setActivatingPlayer(player); + activatingPlayer = player; + if (subAbility != null) { + subAbility.setActivatingPlayer(player); } } - /** - * @return the targetingPlayer - */ public Player getTargetingPlayer() { return targetingPlayer; } - - /** - * @param targetingPlayer the targetingPlayer to set - */ - public void setTargetingPlayer(Player targetingPlayer) { - this.targetingPlayer = targetingPlayer; + public void setTargetingPlayer(Player targetingPlayer0) { + targetingPlayer = targetingPlayer0; } - /** - *

- * isSpell. - *

- * - * @return a boolean. - */ public boolean isSpell() { return false; } public boolean isAbility() { return true; } - /** - *

- * setIsMorphUp. - *

- * - * @param b - * a boolean. - */ - public final void setIsMorphUp(final boolean b) { - this.morphup = b; - } - - /** - *

- * isMorphUp. - *

- * - * @return a boolean. - */ public boolean isMorphUp() { - return this.morphup; + return morphup; + } + public final void setIsMorphUp(final boolean b) { + morphup = b; } - /** - *

- * setIsCycling. - *

- * - * @param b - * a boolean. - */ - public final void setIsCycling(final boolean b) { - this.cycling = b; - } - - /** - *

- * isCycling. - *

- * - * @return a boolean. - */ public boolean isCycling() { - return this.cycling; + return cycling; + } + public final void setIsCycling(final boolean b) { + cycling = b; } - /** - *

- * Setter for the field originalHost. - *

- * - * @param c - * a {@link forge.game.card.Card} object. - */ - public void setOriginalHost(final Card c) { - this.grantorCard = c; - } - - /** - *

- * Getter for the field originalHost. - *

- * - * @return a {@link forge.game.card.Card} object. - */ public Card getOriginalHost() { - return this.grantorCard; + return grantorCard; + } + public void setOriginalHost(final Card c) { + grantorCard = c; } public String getParamOrDefault(String key, String defaultValue) { @@ -410,12 +291,8 @@ public abstract class SpellAbility extends CardTraitBase implements ISpellAbilit return mapParams.containsKey(key); } - /** - * TODO: Write javadoc for this method. - * @param mapParams - */ public void copyParamsToMap(Map mapParams) { - mapParams.putAll(this.mapParams); + mapParams.putAll(mapParams); } // If this is not null, then ability was made in a factory @@ -428,200 +305,79 @@ public abstract class SpellAbility extends CardTraitBase implements ISpellAbilit } public final boolean isCurse() { - return this.hasParam("IsCurse"); + return hasParam("IsCurse"); } // begin - Input methods - /** - *

- * Getter for the field payCosts. - *

- * - * @return a {@link forge.game.cost.Cost} object. - */ + public Cost getPayCosts() { - return this.payCosts; + return payCosts; } - - /** - *

- * Setter for the field payCosts. - *

- * - * @param abCost - * a {@link forge.game.cost.Cost} object. - */ public void setPayCosts(final Cost abCost) { - this.payCosts = abCost; + payCosts = abCost; } - /** - *

- * Setter for the field restrictions. - *

- * - * @param restrict - * a {@link forge.game.spellability.SpellAbilityRestriction} - * object. - */ - public void setRestrictions(final SpellAbilityRestriction restrict) { - this.restrictions = restrict; - } - - /** - *

- * Getter for the field restrictions. - *

- * - * @return a {@link forge.game.spellability.SpellAbilityRestriction} object. - */ public SpellAbilityRestriction getRestrictions() { - return this.restrictions; + return restrictions; + } + public void setRestrictions(final SpellAbilityRestriction restrict) { + restrictions = restrict; } /** - *

- * Shortcut to see how many activations there were. - *

- * - * @return the activations this turn + * Shortcut to see how many activations there were this turn. */ public int getActivationsThisTurn() { - return this.restrictions.getNumberTurnActivations(); + return restrictions.getNumberTurnActivations(); } - /** - *

- * Setter for the field conditions. - *

- * - * @param condition - * a {@link forge.game.spellability.SpellAbilityCondition} - * object. - * @since 1.0.15 - */ - public final void setConditions(final SpellAbilityCondition condition) { - this.conditions = condition; - } - - /** - *

- * Getter for the field conditions. - *

- * - * @return a {@link forge.game.spellability.SpellAbilityCondition} object. - * @since 1.0.15 - */ public SpellAbilityCondition getConditions() { - return this.conditions; + return conditions; + } + public final void setConditions(final SpellAbilityCondition condition) { + conditions = condition; } - /** - *

- * Getter for the field payingMana. - *

- * - * @return a {@link java.util.ArrayList} object. - */ public List getPayingMana() { - return this.payingMana; + return payingMana; } - public final void clearManaPaid() { payingMana.clear(); } - - /** - *

- * getPayingManaAbilities. - *

- * - * @return a {@link java.util.ArrayList} object. - */ + public List getPayingManaAbilities() { - return this.paidAbilities; + return paidAbilities; } // Combined PaidLists - /** - *

- * setPaidHash. - *

- * - * @param hash - * a {@link java.util.HashMap} object. - */ - public void setPaidHash(final HashMap> hash) { - this.paidLists = hash; - } - - /** - *

- * getPaidHash. - *

- * - * @return a {@link java.util.HashMap} object. - */ public HashMap> getPaidHash() { - return this.paidLists; + return paidLists; + } + public void setPaidHash(final HashMap> hash) { + paidLists = hash; } - /** - *

- * getPaidList. - *

- * - * @param str - * a {@link java.lang.String} object. - * @return a {@link forge.CardList} object. - */ public List getPaidList(final String str) { - return this.paidLists.get(str); + return paidLists.get(str); } - - /** - *

- * addCostToHashList. - *

- * - * @param c - * a {@link forge.game.card.Card} object. - * @param str - * a {@link java.lang.String} object. - */ public void addCostToHashList(final Card c, final String str) { - if (!this.paidLists.containsKey(str)) { - this.paidLists.put(str, new ArrayList()); + if (!paidLists.containsKey(str)) { + paidLists.put(str, new ArrayList()); } - - this.paidLists.get(str).add(c); + paidLists.get(str).add(c); } - - /** - *

- * resetPaidHash. - *

- */ public void resetPaidHash() { - this.paidLists = new HashMap>(); + paidLists = new HashMap>(); } - private EnumSet optionalCosts = EnumSet.noneOf(OptionalCost.class); - /** - * @return the optionalAdditionalCosts - */ public Iterable getOptionalCosts() { return optionalCosts; } - - /** - * @param cost the optionalAdditionalCost to add - */ public final void addOptionalCost(OptionalCost cost) { // Optional costs are added to swallow copies of original SAs, // Thus, to protect the original's set from changes, we make a copy right here. - this.optionalCosts = EnumSet.copyOf(optionalCosts); - this.optionalCosts.add(cost); + optionalCosts = EnumSet.copyOf(optionalCosts); + optionalCosts.add(cost); } public boolean isBuyBackAbility() { @@ -633,229 +389,98 @@ public abstract class SpellAbility extends CardTraitBase implements ISpellAbilit } public boolean isOptionalCostPaid(OptionalCost cost) { - SpellAbility saRoot = this.getRootAbility(); + SpellAbility saRoot = getRootAbility(); return saRoot.optionalCosts.contains(cost); } - /** - *

- * Getter for the field triggeringObjects. - *

- * - * @return a {@link java.util.HashMap} object. - * @since 1.0.15 - */ public HashMap getTriggeringObjects() { - return this.triggeringObjects; + return triggeringObjects; } - - /** - *

- * setAllTriggeringObjects. - *

- * - * @param triggeredObjects - * a {@link java.util.HashMap} object. - * @since 1.0.15 - */ - public void setAllTriggeringObjects(final HashMap triggeredObjects) { - this.triggeringObjects = triggeredObjects; + public void setTriggeringObjects(final HashMap triggeredObjects) { + triggeringObjects = triggeredObjects; } - - /** - *

- * setTriggeringObject. - *

- * - * @param type - * a {@link java.lang.String} object. - * @param o - * a {@link java.lang.Object} object. - * @since 1.0.15 - */ - public void setTriggeringObject(final String type, final Object o) { - this.triggeringObjects.put(type, o); - } - - /** - *

- * getTriggeringObject. - *

- * - * @param type - * a {@link java.lang.String} object. - * @return a {@link java.lang.Object} object. - * @since 1.0.15 - */ public Object getTriggeringObject(final String type) { - return this.triggeringObjects.get(type); + return triggeringObjects.get(type); + } + public void setTriggeringObject(final String type, final Object o) { + triggeringObjects.put(type, o); } - - /** - *

- * hasTriggeringObject. - *

- * - * @param type - * a {@link java.lang.String} object. - * @return a boolean. - * @since 1.0.15 - */ public boolean hasTriggeringObject(final String type) { - return this.triggeringObjects.containsKey(type); + return triggeringObjects.containsKey(type); } - - /** - *

- * resetTriggeringObjects. - *

- * - * @since 1.0.15 - */ public void resetTriggeringObjects() { - this.triggeringObjects = new HashMap(); + triggeringObjects = new HashMap(); } - public List getTriggerRemembered() { - return this.triggerRemembered; + return triggerRemembered; } - public void setTriggerRemembered(List list) { - this.triggerRemembered = list; + triggerRemembered = list; } - public void resetTriggerRemembered() { - this.triggerRemembered = new ArrayList(); + triggerRemembered = new ArrayList(); } - - /** - * Gets the replacing objects. - * - * @return the replacing objects - */ + public HashMap getReplacingObjects() { - return this.replacingObjects; + return replacingObjects; } - - /** - * Sets the replacing object. - * - * @param type - * the type - * @param o - * the o - */ - public void setReplacingObject(final String type, final Object o) { - this.replacingObjects.put(type, o); - } - - /** - * Gets the replacing object. - * - * @param type - * the type - * @return the replacing object - */ public Object getReplacingObject(final String type) { - final Object res = this.replacingObjects.get(type); + final Object res = replacingObjects.get(type); return res; } + public void setReplacingObject(final String type, final Object o) { + replacingObjects.put(type, o); + } - - /** - *

- * resetOnceResolved. - *

- */ public void resetOnceResolved() { - this.resetPaidHash(); - this.resetTargets(); - this.resetTriggeringObjects(); - this.resetTriggerRemembered(); - + resetPaidHash(); + resetTargets(); + resetTriggeringObjects(); + resetTriggerRemembered(); // Clear SVars for (final String store : Card.getStorableSVars()) { - final String value = this.hostCard.getSVar(store); + final String value = hostCard.getSVar(store); if (value.length() > 0) { - this.hostCard.setSVar(store, ""); + hostCard.setSVar(store, ""); } } } - /** - *

- * Setter for the field stackDescription. - *

- * - * @param s - * a {@link java.lang.String} object. - */ - public void setStackDescription(final String s) { - this.originalStackDescription = s; - this.stackDescription = this.originalStackDescription; - if (StringUtils.isEmpty(this.description) && StringUtils.isEmpty(this.hostCard.getText())) { - this.setDescription(s); - } - } - - /** - *

- * Getter for the field stackDescription. - *

- * - * @return a {@link java.lang.String} object. - */ public String getStackDescription() { - if (this.stackDescription.equals(this.getHostCard().getText().trim())) { - return this.getHostCard().getName() + " - " + this.getHostCard().getText(); + if (stackDescription.equals(getHostCard().getText().trim())) { + return getHostCard().getName() + " - " + getHostCard().getText(); + } + return stackDescription.replaceAll("CARDNAME", getHostCard().getName()); + } + public void setStackDescription(final String s) { + originalStackDescription = s; + stackDescription = originalStackDescription; + if (StringUtils.isEmpty(description) && StringUtils.isEmpty(hostCard.getText())) { + setDescription(s); } - - return this.stackDescription.replaceAll("CARDNAME", this.getHostCard().getName()); } // setDescription() includes mana cost and everything like // "G, tap: put target creature from your hand onto the battlefield" - /** - *

- * Setter for the field description. - *

- * - * @param s - * a {@link java.lang.String} object. - */ - public void setDescription(final String s) { - this.originalDescription = s; - this.description = this.originalDescription; - } - - /** - *

- * Getter for the field description. - *

- * - * @return a {@link java.lang.String} object. - */ public String getDescription() { - return this.description; + return description; + } + public void setDescription(final String s) { + originalDescription = s; + description = originalDescription; } /** {@inheritDoc} */ @Override public final String toString() { - if (this.isSuppressed()) { + if (isSuppressed()) { return ""; } - - return this.toUnsuppressedString(); + return toUnsuppressedString(); } - /** - * To unsuppressed string. - * - * @return the string - */ public String toUnsuppressedString() { final StringBuilder sb = new StringBuilder(); SpellAbility node = this; @@ -871,6 +496,17 @@ public abstract class SpellAbility extends CardTraitBase implements ISpellAbilit return sb.toString(); } + public AbilitySub getSubAbility() { + return subAbility; + } + public void setSubAbility(final AbilitySub subAbility0) { + if (subAbility == subAbility0) { return; } + subAbility = subAbility0; + if (subAbility != null) { + subAbility.setParent(this); + } + view.updateDescription(this); //description changes when sub-abilities change + } public void appendSubAbility(final AbilitySub toAdd) { SpellAbility tailend = this; while (tailend.getSubAbility() != null) { @@ -879,97 +515,31 @@ public abstract class SpellAbility extends CardTraitBase implements ISpellAbilit tailend.setSubAbility(toAdd); } - /** - *

- * Setter for the field subAbility. - *

- * - * @param subAbility - * a {@link forge.game.spellability.AbilitySub} object. - */ - public void setSubAbility(final AbilitySub subAbility) { - this.subAbility = subAbility; - if (subAbility != null) { - subAbility.setParent(this); - } - } - - /** - *

- * Getter for the field subAbility. - *

- * - * @return a {@link forge.game.spellability.AbilitySub} object. - */ - public AbilitySub getSubAbility() { - return this.subAbility; - } - - /** - *

- * isBasicAbility. - *

- * - * @return a boolean. - */ public boolean isBasicSpell() { - return this.basicSpell && !this.isFlashBackAbility() && !this.isBuyBackAbility(); + return basicSpell && !isFlashBackAbility() && !isBuyBackAbility(); + } + public void setBasicSpell(final boolean basicSpell0) { + basicSpell = basicSpell0; } - /** - *

- * Setter for the field setBasicSpell. - *

- * - * @param basicSpell - * a boolean. - */ - public void setBasicSpell(final boolean basicSpell) { - this.basicSpell = basicSpell; + public void setFlashBackAbility(final boolean flashBackAbility0) { + flashBackAbility = flashBackAbility0; } - - /** - *

- * Setter for the field flashBackAbility. - *

- * - * @param flashBackAbility - * a boolean. - */ - public void setFlashBackAbility(final boolean flashBackAbility) { - this.flashBackAbility = flashBackAbility; - } - - /** - *

- * isFlashBackAbility. - *

- * - * @return a boolean. - */ public boolean isFlashBackAbility() { - return this.flashBackAbility; + return flashBackAbility; } public boolean isOutlast() { return outlast; } - - public void setOutlast(boolean outlast) { - this.outlast = outlast; + public void setOutlast(boolean outlast0) { + outlast = outlast0; } - /** - *

- * copy. - *

- * - * @return a {@link forge.game.spellability.SpellAbility} object. - */ public SpellAbility copy() { SpellAbility clone = null; try { - clone = (SpellAbility) this.clone(); + clone = (SpellAbility) clone(); clone.id = nextId(); } catch (final CloneNotSupportedException e) { System.err.println(e); @@ -978,83 +548,56 @@ public abstract class SpellAbility extends CardTraitBase implements ISpellAbilit } public SpellAbility copyWithNoManaCost() { - final SpellAbility newSA = this.copy(); + final SpellAbility newSA = copy(); newSA.setPayCosts(newSA.getPayCosts().copyWithNoMana()); newSA.setDescription(newSA.getDescription() + " (without paying its mana cost)"); return newSA; } public SpellAbility copyWithDefinedCost(Cost abCost) { - final SpellAbility newSA = this.copy(); + final SpellAbility newSA = copy(); newSA.setPayCosts(abCost); return newSA; } - public void setTrigger(final boolean trigger) { - this.trigger = trigger; - } public boolean isTrigger() { - return this.trigger; + return trigger; + } + public void setTrigger(final boolean trigger0) { + trigger = trigger0; + } + + public boolean isOptionalTrigger() { + return optionalTrigger; } public void setOptionalTrigger(final boolean optrigger) { - this.optionalTrigger = optrigger; - } - public boolean isOptionalTrigger() { - return this.optionalTrigger; + optionalTrigger = optrigger; } - /** - *

- * setSourceTrigger. - *

- * - * @param id - * a int. - */ - public void setSourceTrigger(final int id) { - this.sourceTrigger = id; - } - - /** - *

- * getSourceTrigger. - *

- * - * @return a int. - */ public int getSourceTrigger() { - return this.sourceTrigger; + return sourceTrigger; + } + public void setSourceTrigger(final int id) { + sourceTrigger = id; } - public boolean isReplacementAbility() { return this.replacementAbility; } - public void setReplacementAbility(boolean replacement) { this.replacementAbility = replacement; } + public boolean isReplacementAbility() { + return replacementAbility; + } + public void setReplacementAbility(boolean replacement) { + replacementAbility = replacement; + } - /** - *

- * isMandatory. - *

- * - * @return a boolean. - */ public boolean isMandatory() { return false; } - /** - *

- * canTarget. - *

- * - * @param entity - * a GameEntity - * @return a boolean. - */ public final boolean canTarget(final GameObject entity) { - final TargetRestrictions tr = this.getTargetRestrictions(); + final TargetRestrictions tr = getTargetRestrictions(); // Restriction related to this ability if (tr != null) { - if (tr.isUniqueTargets() && this.getUniqueTargets().contains(entity)) + if (tr.isUniqueTargets() && getUniqueTargets().contains(entity)) return false; // If the cards must have a specific controller @@ -1076,7 +619,7 @@ public abstract class SpellAbility extends CardTraitBase implements ISpellAbilit } if (hasParam("TargetsWithSharedTypes") && entity instanceof Card) { final Card c = (Card) entity; - final SpellAbility parent = this.getParentTargetingCard(); + final SpellAbility parent = getParentTargetingCard(); final Card parentTargeted = parent != null ? parent.getTargetCard() : null; if (parentTargeted == null) { return false; @@ -1096,7 +639,7 @@ public abstract class SpellAbility extends CardTraitBase implements ISpellAbilit final String related = getParam("TargetsWithRelatedProperty"); final Card c = (Card) entity; Card parentTarget = null; - for (GameObject o : this.getUniqueTargets()) { + for (GameObject o : getUniqueTargets()) { if (o instanceof Card) { parentTarget = (Card) o; break; @@ -1121,7 +664,7 @@ public abstract class SpellAbility extends CardTraitBase implements ISpellAbilit } String[] validTgt = tr.getValidTgts(); - if (entity instanceof GameEntity && !((GameEntity) entity).isValid(validTgt, this.getActivatingPlayer(), this.getHostCard())) { + if (entity instanceof GameEntity && !((GameEntity) entity).isValid(validTgt, getActivatingPlayer(), getHostCard())) { return false; } } @@ -1131,144 +674,62 @@ public abstract class SpellAbility extends CardTraitBase implements ISpellAbilit } // is this a wrapping ability (used by trigger abilities) - /** - *

- * isWrapper. - *

- * - * @return a boolean. - * @since 1.0.15 - */ public boolean isWrapper() { return false; } - - /** - * Gets the checks if is delve. - * - * @return the isDelve - */ public final boolean isDelve() { - return this.delve; + return delve; } - - /** - * Sets the checks if is delve. - * - * @param isDelve0 - * the isDelve to set - */ public final void setDelve(final boolean isDelve0) { - this.delve = isDelve0; + delve = isDelve0; } - /** - * Adds the tapped for convoke. - * - * @param c - * the c - */ - public void addTappedForConvoke(final Card c) { - if (this.tappedForConvoke == null) { - this.tappedForConvoke = new ArrayList(); - } - - this.tappedForConvoke.add(c); - } - - /** - * Gets the tapped for convoke. - * - * @return the tapped for convoke - */ public List getTappedForConvoke() { - return this.tappedForConvoke; + return tappedForConvoke; + } + public void addTappedForConvoke(final Card c) { + if (tappedForConvoke == null) { + tappedForConvoke = new ArrayList(); + } + tappedForConvoke.add(c); } - - /** - * Clear tapped for convoke. - */ public void clearTappedForConvoke() { - if (this.tappedForConvoke != null) { - this.tappedForConvoke.clear(); + if (tappedForConvoke != null) { + tappedForConvoke.clear(); } } - /** - * Returns whether the SA is a patron offering. - */ public boolean isOffering() { - return this.offering; + return offering; } - - /** - * Sets the SA as a patron offering. - * - * @param c card sacrificed for a patron offering - */ public void setIsOffering(final boolean bOffering) { - this.offering = bOffering; + offering = bOffering; } - /** - * Sets the card sacrificed for a patron offering. - * - * @param c card sacrificed for a patron offering - */ + public Card getSacrificedAsOffering() { //for Patron offering + return sacrificedAsOffering; + } public void setSacrificedAsOffering(final Card c) { - this.sacrificedAsOffering = c; + sacrificedAsOffering = c; } - - /** - * Gets the card sacrificed for a patron offering. - * - * @return the card sacrificed for a patron offering - */ - public Card getSacrificedAsOffering() { - return this.sacrificedAsOffering; - } - - /** - * Clear the card sacrificed for a patron offering. - */ public void resetSacrificedAsOffering() { - this.sacrificedAsOffering = null; + sacrificedAsOffering = null; } - /** - * @return the splicedCards - */ public List getSplicedCards() { return splicedCards; } - - /** - * @param splicedCard the splicedCards to set - */ - public void setSplicedCards(List splicedCards) { - this.splicedCards = splicedCards; + public void setSplicedCards(List splicedCards0) { + splicedCards = splicedCards0; } - - /** - * @param splicedCard the splicedCard to add - */ public void addSplicedCards(Card splicedCard) { - if (this.splicedCards == null) { - this.splicedCards = new ArrayList(); + if (splicedCards == null) { + splicedCards = new ArrayList(); } - this.splicedCards.add(splicedCard); + splicedCards.add(splicedCard); } - /** - *

- * knownDetermineDefined. - *

- * - * @param defined - * a {@link java.lang.String} object. - * @return a {@link forge.CardList} object. - */ public List knownDetermineDefined(final String defined) { final List ret = new ArrayList(); final List list = AbilityUtils.getDefinedCards(getHostCard(), defined, this); @@ -1281,13 +742,6 @@ public abstract class SpellAbility extends CardTraitBase implements ISpellAbilit return ret; } - /** - *

- * findRootAbility. - *

- * - * @return a {@link forge.game.spellability.SpellAbility} object. - */ public SpellAbility getRootAbility() { SpellAbility parent = this; while (null != parent.getParent()) { @@ -1300,44 +754,26 @@ public abstract class SpellAbility extends CardTraitBase implements ISpellAbilit return null; } - /** - * TODO: Write javadoc for this method. - * @return - */ public boolean isUndoable() { - return this.undoable && this.payCosts.isUndoable() && this.getHostCard().isInPlay(); + return undoable && payCosts.isUndoable() && getHostCard().isInPlay(); } - /** - * TODO: Write javadoc for this method. - */ public boolean undo() { - if (isUndoable() && this.getActivatingPlayer().getManaPool().accountFor(this.getManaPart())) { - this.payCosts.refundPaidCost(hostCard); + if (isUndoable() && getActivatingPlayer().getManaPool().accountFor(getManaPart())) { + payCosts.refundPaidCost(hostCard); } return false; } - /** - * TODO: Write javadoc for this method. - * @param b - */ public void setUndoable(boolean b) { - this.undoable = b; + undoable = b; } - /** - * @return the isCopied - */ public boolean isCopied() { return isCopied; } - - /** - * @param isCopied0 the isCopied to set - */ public void setCopied(boolean isCopied0) { - this.isCopied = isCopied0; + isCopied = isCopied0; } /** @@ -1380,8 +816,8 @@ public abstract class SpellAbility extends CardTraitBase implements ISpellAbilit return basicLandAbility; } - public void setBasicLandAbility(boolean basicLandAbility) { - this.basicLandAbility = basicLandAbility; // TODO: Add 0 to parameter's name. + public void setBasicLandAbility(boolean basicLandAbility0) { + basicLandAbility = basicLandAbility0; } @Override @@ -1389,16 +825,12 @@ public abstract class SpellAbility extends CardTraitBase implements ISpellAbilit return sa.canTargetSpellAbility(this); } - /** The chosen target. */ - private TargetRestrictions targetRestricions = null; - private TargetChoices targetChosen = new TargetChoices(); - public boolean usesTargeting() { - return targetRestricions != null; + return targetRestrictions != null; } public TargetRestrictions getTargetRestrictions() { - return targetRestricions; + return targetRestrictions; } ///////////////////////////////////////////////////////////////////////////////////////////////////////////////// @@ -1408,7 +840,7 @@ public abstract class SpellAbility extends CardTraitBase implements ISpellAbilit ///////////////////////////////////////////////////////////////////////////////////////////////////////////////// public void setTargetRestrictions(final TargetRestrictions tgt) { - targetRestricions = tgt; + targetRestrictions = tgt; } /** @@ -1417,11 +849,11 @@ public abstract class SpellAbility extends CardTraitBase implements ISpellAbilit * @return the chosenTarget */ public TargetChoices getTargets() { - return this.targetChosen; + return targetChosen; } public void setTargets(TargetChoices targets) { - this.targetChosen = targets; + targetChosen = targets; } public void resetTargets() { @@ -1435,12 +867,12 @@ public abstract class SpellAbility extends CardTraitBase implements ISpellAbilit public void resetFirstTarget(GameObject c, SpellAbility originalSA) { SpellAbility sa = this; while (sa != null) { - if (sa.targetRestricions != null) { + if (sa.targetRestrictions != null) { sa.targetChosen = new TargetChoices(); sa.targetChosen.add(c); - if (!originalSA.targetRestricions.getDividedMap().isEmpty()) { - sa.targetRestricions.addDividedAllocation(c, - Iterables.getFirst(originalSA.targetRestricions.getDividedMap().values(), null)); + if (!originalSA.targetRestrictions.getDividedMap().isEmpty()) { + sa.targetRestrictions.addDividedAllocation(c, + Iterables.getFirst(originalSA.targetRestrictions.getDividedMap().values(), null)); } break; } @@ -1459,7 +891,7 @@ public abstract class SpellAbility extends CardTraitBase implements ISpellAbilit public final ArrayList getAllTargetChoices() { final ArrayList res = new ArrayList(); - SpellAbility sa = this.getRootAbility(); + SpellAbility sa = getRootAbility(); if (sa.getTargetRestrictions() != null) { res.add(sa.getTargets()); } @@ -1488,7 +920,7 @@ public abstract class SpellAbility extends CardTraitBase implements ISpellAbilit */ public void setTargetCard(final Card card) { if (card == null) { - System.out.println(this.getHostCard() + System.out.println(getHostCard() + " - SpellAbility.setTargetCard() called with null for target card."); return; } @@ -1498,12 +930,12 @@ public abstract class SpellAbility extends CardTraitBase implements ISpellAbilit final String desc; if (!card.isFaceDown()) { - desc = this.getHostCard().getName() + " - targeting " + card; + desc = getHostCard().getName() + " - targeting " + card; } else { - desc = this.getHostCard().getName() + " - targeting Morph(" + card.getUniqueNumber() + ")"; + desc = getHostCard().getName() + " - targeting Morph(" + card.getId() + ")"; } - this.setStackDescription(desc); + setStackDescription(desc); } /** @@ -1529,13 +961,13 @@ public abstract class SpellAbility extends CardTraitBase implements ISpellAbilit } // Lastly Search parent SAs that targets a card - SpellAbility parent = this.getParentTargetingCard(); + SpellAbility parent = getParentTargetingCard(); if (null != parent) { return parent.findTargetedCards(); } // Lastly Search parent SAs that targets an SA - parent = this.getParentTargetingSA(); + parent = getParentTargetingSA(); if (null != parent) { return parent.findTargetedCards(); } @@ -1548,7 +980,7 @@ public abstract class SpellAbility extends CardTraitBase implements ISpellAbilit } public SpellAbility getParentTargetingCard() { - SpellAbility parent = this.getParent(); + SpellAbility parent = getParent(); if (parent instanceof WrappedAbility) { parent = ((WrappedAbility) parent).getWrappedAbility(); } @@ -1566,7 +998,7 @@ public abstract class SpellAbility extends CardTraitBase implements ISpellAbilit } public SpellAbility getParentTargetingSA() { - SpellAbility parent = this.getParent(); + SpellAbility parent = getParent(); while (parent != null) { if (parent.targetChosen.isTargetingAnySpell()) return parent; @@ -1579,15 +1011,8 @@ public abstract class SpellAbility extends CardTraitBase implements ISpellAbilit return targetChosen.isTargetingAnyPlayer() ? this : getParentTargetingPlayer(); } - /** - *

- * findParentsTargetedPlayer. - *

- * - * @return a {@link forge.game.spellability.SpellAbility} object. - */ public SpellAbility getParentTargetingPlayer() { - SpellAbility parent = this.getParent(); + SpellAbility parent = getParent(); while (parent != null) { if (parent.getTargets().isTargetingAnyPlayer()) return parent; @@ -1596,16 +1021,9 @@ public abstract class SpellAbility extends CardTraitBase implements ISpellAbilit return null; } - /** - * Gets the unique targets. - * - * @param ability - * the ability - * @return the unique targets - */ public final List getUniqueTargets() { final List targets = new ArrayList(); - SpellAbility child = this.getParent(); + SpellAbility child = getParent(); while (child != null) { if (child.getTargetRestrictions() != null) { Iterables.addAll(targets, child.getTargets().getTargets()); @@ -1616,9 +1034,9 @@ public abstract class SpellAbility extends CardTraitBase implements ISpellAbilit } public boolean canTargetSpellAbility(final SpellAbility topSA) { - final TargetRestrictions tgt = this.getTargetRestrictions(); + final TargetRestrictions tgt = getTargetRestrictions(); - if (this.hasParam("TargetType") && !topSA.isValid(this.getParam("TargetType").split(","), this.getActivatingPlayer(), this.getHostCard())) { + if (hasParam("TargetType") && !topSA.isValid(getParam("TargetType").split(","), getActivatingPlayer(), getHostCard())) { return false; } @@ -1635,7 +1053,7 @@ public abstract class SpellAbility extends CardTraitBase implements ISpellAbilit boolean result = false; for (final GameObject o : matchTgt.getTargets()) { - if (o.isValid(splitTargetRestrictions.split(","), this.getActivatingPlayer(), this.getHostCard())) { + if (o.isValid(splitTargetRestrictions.split(","), getActivatingPlayer(), getHostCard())) { result = true; break; } @@ -1661,36 +1079,22 @@ public abstract class SpellAbility extends CardTraitBase implements ISpellAbilit } } - return topSA.getHostCard().isValid(tgt.getValidTgts(), this.getActivatingPlayer(), this.getHostCard()); + return topSA.getHostCard().isValid(tgt.getValidTgts(), getActivatingPlayer(), getHostCard()); } // Takes one argument like Permanent.Blue+withFlying - /** - *

- * isValid. - *

- * - * @param restriction - * a {@link java.lang.String} object. - * @param sourceController - * a {@link forge.game.player.Player} object. - * @param source - * a {@link forge.game.card.Card} object. - * @return a boolean. - */ @Override public final boolean isValid(final String restriction, final Player sourceController, final Card source) { - // Inclusive restrictions are Card types final String[] incR = restriction.split("\\.", 2); if (incR[0].equals("Spell")) { - if (!this.isSpell()) { + if (!isSpell()) { return false; } } else if (incR[0].equals("Triggered")) { - if (!this.isTrigger()) { + if (!isTrigger()) { return false; } } @@ -1707,28 +1111,15 @@ public abstract class SpellAbility extends CardTraitBase implements ISpellAbilit final String excR = incR[1]; final String[] exR = excR.split("\\+"); // Exclusive Restrictions are ... for (int j = 0; j < exR.length; j++) { - if (!this.hasProperty(exR[j], sourceController, source)) { + if (!hasProperty(exR[j], sourceController, source)) { return false; } } } return true; - } // isValid(String Restriction) + } // Takes arguments like Blue or withFlying - /** - *

- * hasProperty. - *

- * - * @param property - * a {@link java.lang.String} object. - * @param sourceController - * a {@link forge.game.player.Player} object. - * @param source - * a {@link forge.game.card.Card} object. - * @return a boolean. - */ @Override public boolean hasProperty(final String property, final Player sourceController, final Card source) { return true; @@ -1736,37 +1127,37 @@ public abstract class SpellAbility extends CardTraitBase implements ISpellAbilit // Methods enabling multiple instances of conspire public void addConspireInstance() { - this.conspireInstances++; + conspireInstances++; } public void subtractConspireInstance() { - this.conspireInstances--; + conspireInstances--; } public int getConspireInstances() { - return this.conspireInstances; + return conspireInstances; } // End of Conspire methods public boolean isCumulativeupkeep() { return cumulativeupkeep; } - public void setCumulativeupkeep(boolean cumulativeupkeep) { - this.cumulativeupkeep = cumulativeupkeep; + public void setCumulativeupkeep(boolean cumulativeupkeep0) { + cumulativeupkeep = cumulativeupkeep0; } // Return whether this spell tracks what color mana is spent to cast it for the sake of the effect public boolean tracksManaSpent() { - if (this.hostCard == null || this.hostCard.getRules() == null) { return false; } + if (hostCard == null || hostCard.getRules() == null) { return false; } - if (this.hostCard.hasKeyword("Sunburst")) { + if (hostCard.hasKeyword("Sunburst")) { return true; } - String text = this.hostCard.getRules().getOracleText(); - if (this.isSpell() && text.contains("was spent to cast")) { + String text = hostCard.getRules().getOracleText(); + if (isSpell() && text.contains("was spent to cast")) { return true; } - if (this.isAbility() && text.contains("mana spent to pay")) { + if (isAbility() && text.contains("mana spent to pay")) { return true; } return false; @@ -1774,11 +1165,11 @@ public abstract class SpellAbility extends CardTraitBase implements ISpellAbilit public void checkActivationResloveSubs() { if (hasParam("ActivationNumberSacrifice")) { - String comp = this.getParam("ActivationNumberSacrifice"); + String comp = getParam("ActivationNumberSacrifice"); int right = Integer.parseInt(comp.substring(2)); - int activationNum = this.getRestrictions().getNumberTurnActivations(); + int activationNum = getRestrictions().getNumberTurnActivations(); if (Expressions.compare(activationNum, comp, right)) { - SpellAbility deltrig = AbilityFactory.getAbility(hostCard.getSVar(this.getParam("ActivationResolveSub")), hostCard); + SpellAbility deltrig = AbilityFactory.getAbility(hostCard.getSVar(getParam("ActivationResolveSub")), hostCard); deltrig.setActivatingPlayer(activatingPlayer); AbilityUtils.resolve(deltrig); } @@ -1786,11 +1177,11 @@ public abstract class SpellAbility extends CardTraitBase implements ISpellAbilit } public void setTotalManaSpent(int totManaSpent) { - this.totalManaSpent = totManaSpent; + totalManaSpent = totManaSpent; } public int getTotalManaSpent() { - return this.totalManaSpent; + return totalManaSpent; } public List getChosenList() { @@ -1798,34 +1189,38 @@ public abstract class SpellAbility extends CardTraitBase implements ISpellAbilit } public void setChosenList(List choices) { - this.chosenList = choices; + chosenList = choices; } @Override public void changeText() { super.changeText(); - if (this.targetRestricions != null) { - this.targetRestricions.applyTargetTextChanges(this); + if (targetRestrictions != null) { + targetRestrictions.applyTargetTextChanges(this); } - if (this.getPayCosts() != null) { - this.getPayCosts().applyTextChangeEffects(this); + if (getPayCosts() != null) { + getPayCosts().applyTextChangeEffects(this); } - this.stackDescription = AbilityUtils.applyDescriptionTextChangeEffects(this.originalStackDescription, this); - this.description = AbilityUtils.applyDescriptionTextChangeEffects(this.originalDescription, this); + stackDescription = AbilityUtils.applyDescriptionTextChangeEffects(originalStackDescription, this); + description = AbilityUtils.applyDescriptionTextChangeEffects(originalDescription, this); - if (this.subAbility != null) { - this.subAbility.changeText(); + if (subAbility != null) { + subAbility.changeText(); } } @Override public void setIntrinsic(boolean i) { super.setIntrinsic(i); - if (this.subAbility != null) { - this.subAbility.setIntrinsic(i); + if (subAbility != null) { + subAbility.setIntrinsic(i); } } + + public SpellAbilityView getView() { + return view; + } } \ No newline at end of file diff --git a/forge-game/src/main/java/forge/game/spellability/SpellAbilityCondition.java b/forge-game/src/main/java/forge/game/spellability/SpellAbilityCondition.java index ebb241d9158..f9cff06bb4c 100644 --- a/forge-game/src/main/java/forge/game/spellability/SpellAbilityCondition.java +++ b/forge-game/src/main/java/forge/game/spellability/SpellAbilityCondition.java @@ -275,7 +275,7 @@ public class SpellAbilityCondition extends SpellAbilityVariables { } if (this.getColorToCheck() != null) { - if (!sa.getHostCard().getChosenColor().contains(this.getColorToCheck())) { + if (!sa.getHostCard().getChosenColors().contains(this.getColorToCheck())) { return false; } } diff --git a/forge-game/src/main/java/forge/game/spellability/SpellAbilityRestriction.java b/forge-game/src/main/java/forge/game/spellability/SpellAbilityRestriction.java index 8e986cd7b19..77475bb9727 100644 --- a/forge-game/src/main/java/forge/game/spellability/SpellAbilityRestriction.java +++ b/forge-game/src/main/java/forge/game/spellability/SpellAbilityRestriction.java @@ -302,7 +302,7 @@ public class SpellAbilityRestriction extends SpellAbilityVariables { } if (this.getColorToCheck() != null) { - if (!sa.getHostCard().getChosenColor().contains(this.getColorToCheck())) { + if (!sa.getHostCard().getChosenColors().contains(this.getColorToCheck())) { return false; } } diff --git a/forge-game/src/main/java/forge/game/spellability/SpellAbilityStackInstance.java b/forge-game/src/main/java/forge/game/spellability/SpellAbilityStackInstance.java index 4b23d96ad91..b0a4217ff76 100644 --- a/forge-game/src/main/java/forge/game/spellability/SpellAbilityStackInstance.java +++ b/forge-game/src/main/java/forge/game/spellability/SpellAbilityStackInstance.java @@ -51,10 +51,10 @@ public class SpellAbilityStackInstance implements IIdentifiable { // Coming off the Stack would work similarly, except it would just add the // full active SI instead of each of the parts - private int id; - private SpellAbility ability = null; + private final int id; + private final SpellAbility ability; - private SpellAbilityStackInstance subInstance = null; + private final SpellAbilityStackInstance subInstance; private Player activator; // When going to a SubAbility that SA has a Instance Choice object @@ -73,67 +73,58 @@ public class SpellAbilityStackInstance implements IIdentifiable { private int xManaPaid = 0; // Other Paid things - private HashMap> paidHash = new HashMap>(); + private final HashMap> paidHash; // Additional info // is Kicked, is Buyback // Triggers - private HashMap triggeringObjects = new HashMap(); - private List triggerRemembered = new ArrayList(); + private final HashMap triggeringObjects; + private final List triggerRemembered; private final HashMap storedSVars = new HashMap(); private final List zonesToOpen; private final Map playersWithValidTargets; - /** - *

- * Constructor for SpellAbility_StackInstance. - *

- * - * @param sa - * a {@link forge.game.spellability.SpellAbility} object. - */ + private final StackItemView view; + public SpellAbilityStackInstance(final SpellAbility sa) { // Base SA info - this.id = nextId(); - this.ability = sa; - this.stackDescription = this.ability.getStackDescription(); - this.activator = sa.getActivatingPlayer(); + id = nextId(); + ability = sa; + stackDescription = sa.getStackDescription(); + activator = sa.getActivatingPlayer(); // Payment info - this.paidHash = this.ability.getPaidHash(); - this.ability.resetPaidHash(); - this.splicedCards = sa.getSplicedCards(); + paidHash = ability.getPaidHash(); + ability.resetPaidHash(); + splicedCards = sa.getSplicedCards(); // TODO getXManaCostPaid should be on the SA, not the Card - this.xManaPaid = sa.getHostCard().getXManaCostPaid(); + xManaPaid = sa.getHostCard().getXManaCostPaid(); // Triggering info - this.triggeringObjects = sa.getTriggeringObjects(); - this.triggerRemembered = sa.getTriggerRemembered(); + triggeringObjects = sa.getTriggeringObjects(); + triggerRemembered = sa.getTriggerRemembered(); - final AbilitySub subAb = this.ability.getSubAbility(); - if (subAb != null) { - this.subInstance = new SpellAbilityStackInstance(subAb); - } + subInstance = ability.getSubAbility() == null ? null : new SpellAbilityStackInstance(ability.getSubAbility()); // Targeting info -- 29/06/11 Moved to after taking care of SubAbilities // because otherwise AF_DealDamage SubAbilities that use Defined$ // Targeted breaks (since it's parents target is reset) if (sa.usesTargeting()) { - this.tc = ability.getTargets(); - this.ability.resetTargets(); + tc = ability.getTargets(); + ability.resetTargets(); } - final Card source = this.ability.getHostCard(); + final Card source = ability.getHostCard(); // Store SVars and Clear for (final String store : Card.getStorableSVars()) { final String value = source.getSVar(store); if (value.length() > 0) { - this.storedSVars.put(store, value); + storedSVars.put(store, value); source.setSVar(store, ""); } } @@ -156,154 +147,107 @@ public class SpellAbilityStackInstance implements IIdentifiable { } } } + + view = new StackItemView(this); } @Override public int getId() { - return this.id; + return id; } - /** - *

- * getSpellAbility. - *

- * - * @return a {@link forge.game.spellability.SpellAbility} object. - */ - public final SpellAbility getSpellAbility() { - this.ability.resetTargets(); - this.ability.setTargets(tc); - this.ability.setActivatingPlayer(activator); - - // Saved sub-SA needs to be reset on the way out - if (this.subInstance != null) { - this.ability.setSubAbility((AbilitySub) this.subInstance.getSpellAbility()); - } - - // Set Cost specific things here - this.ability.resetPaidHash(); - this.ability.setPaidHash(this.paidHash); - this.ability.setSplicedCards(splicedCards); - this.ability.getHostCard().setXManaCostPaid(this.xManaPaid); - - // Triggered - this.ability.setAllTriggeringObjects(this.triggeringObjects); - this.ability.setTriggerRemembered(this.triggerRemembered); - - // Add SVars back in - final Card source = this.ability.getHostCard(); - for (final String store : this.storedSVars.keySet()) { - final String value = this.storedSVars.get(store); - if (value.length() > 0) { - source.setSVar(store, value); + //TODO: See if refresh actually needed for most places this is being called + // Perhaps lets move the refresh logic to a separate function called only when necessary + public final SpellAbility getSpellAbility(boolean refresh) { + if (refresh) { + ability.resetTargets(); + ability.setTargets(tc); + ability.setActivatingPlayer(activator); + + // Saved sub-SA needs to be reset on the way out + if (subInstance != null) { + ability.setSubAbility((AbilitySub) subInstance.getSpellAbility(true)); + } + + // Set Cost specific things here + ability.resetPaidHash(); + ability.setPaidHash(paidHash); + ability.setSplicedCards(splicedCards); + ability.getHostCard().setXManaCostPaid(xManaPaid); + + // Triggered + ability.setTriggeringObjects(triggeringObjects); + ability.setTriggerRemembered(triggerRemembered); + + // Add SVars back in + final Card source = ability.getHostCard(); + for (final String store : storedSVars.keySet()) { + final String value = storedSVars.get(store); + if (value.length() > 0) { + source.setSVar(store, value); + } } } - - return this.ability; + return ability; } // A bit of SA shared abilities to restrict conflicts - /** - *

- * Getter for the field stackDescription. - *

- * - * @return a {@link java.lang.String} object. - */ public final String getStackDescription() { - return this.stackDescription; + return stackDescription; } - /** - *

- * getHostCard. - *

- * - * @return a {@link forge.game.card.Card} object. - */ public final Card getSourceCard() { - return this.ability.getHostCard(); + return ability.getHostCard(); } - /** - *

- * isSpell. - *

- * - * @return a boolean. - */ public final boolean isSpell() { - return this.ability.isSpell(); + return ability.isSpell(); } - /** - *

- * isAbility. - *

- * - * @return a boolean. - */ public final boolean isAbility() { - return this.ability.isAbility(); + return ability.isAbility(); } - /** - *

- * isTrigger. - *

- * - * @return a boolean. - */ public final boolean isTrigger() { - return this.ability.isTrigger(); + return ability.isTrigger(); } - /** - *

- * isStateTrigger. - *

- * - * @param id - * a int. - * @return a boolean. - */ public final boolean isStateTrigger(final int id) { - return this.ability.getSourceTrigger() == id; + return ability.getSourceTrigger() == id; } - /** - * Checks if is optional trigger. - * - * @return true, if is optional trigger - */ public final boolean isOptionalTrigger() { - return this.ability.isOptionalTrigger(); + return ability.isOptionalTrigger(); } public final SpellAbilityStackInstance getSubInstance() { - return this.subInstance; + return subInstance; } public final TargetChoices getTargetChoices() { - return this.tc; + return tc; } public final List getZonesToOpen() { - return this.zonesToOpen; + return zonesToOpen; } public final Map getPlayersWithValidTargets() { - return this.playersWithValidTargets; + return playersWithValidTargets; } public void updateTarget(TargetChoices target) { if (target != null) { - this.tc = target; - this.ability.setTargets(tc); - this.stackDescription = this.ability.getStackDescription(); + tc = target; + ability.setTargets(tc); + stackDescription = ability.getStackDescription(); + view.updateTargetCards(this); + view.updateTargetPlayers(this); + view.updateText(this); + // Run BecomesTargetTrigger HashMap runParams = new HashMap(); - runParams.put("SourceSA", this.ability); + runParams.put("SourceSA", ability); HashSet distinctObjects = new HashSet(); for (final Object tgt : target.getTargets()) { if (distinctObjects.contains(tgt)) { @@ -315,7 +259,7 @@ public class SpellAbilityStackInstance implements IIdentifiable { ((Card) tgt).setBecameTargetThisTurn(true); } runParams.put("Target", tgt); - this.getSourceCard().getGame().getTriggerHandler().runTrigger(TriggerType.BecomesTarget, runParams, false); + getSourceCard().getGame().getTriggerHandler().runTrigger(TriggerType.BecomesTarget, runParams, false); } } } @@ -347,12 +291,18 @@ public class SpellAbilityStackInstance implements IIdentifiable { return activator; } - public void setActivator(Player activator) { - this.activator = activator; + public void setActivator(Player activator0) { + if (activator == activator0) { return; } + activator = activator0; + view.updateActivator(this); } @Override public String toString() { - return String.format("%s->%s", getSourceCard(), stackDescription); - } + return String.format("%s->%s", getSourceCard(), getStackDescription()); + } + + public StackItemView getView() { + return view; + } } diff --git a/forge-game/src/main/java/forge/game/spellability/SpellAbilityView.java b/forge-game/src/main/java/forge/game/spellability/SpellAbilityView.java new file mode 100644 index 00000000000..5070b019b4f --- /dev/null +++ b/forge-game/src/main/java/forge/game/spellability/SpellAbilityView.java @@ -0,0 +1,49 @@ +package forge.game.spellability; + +import forge.game.card.CardView; +import forge.trackable.TrackableObject; +import forge.trackable.TrackableProperty.SpellAbilityProp; + + +public class SpellAbilityView extends TrackableObject { + SpellAbilityView(SpellAbility sa) { + super(sa.getId(), SpellAbilityProp.class); + updateHostCard(sa); + updateDescription(sa); + updateCanPlay(sa); + updatePromptIfOnlyPossibleAbility(sa); + } + + @Override + public String toString() { + return this.getDescription(); + } + + public CardView getHostCard() { + return get(SpellAbilityProp.HostCard); + } + void updateHostCard(SpellAbility sa) { + set(SpellAbilityProp.HostCard, CardView.get(sa.getHostCard())); + } + + public String getDescription() { + return get(SpellAbilityProp.Description); + } + void updateDescription(SpellAbility sa) { + set(SpellAbilityProp.Description, sa.toUnsuppressedString()); + } + + public boolean canPlay() { + return get(SpellAbilityProp.CanPlay); + } + void updateCanPlay(SpellAbility sa) { + set(SpellAbilityProp.CanPlay, sa.canPlay()); + } + + public boolean promptIfOnlyPossibleAbility() { + return get(SpellAbilityProp.PromptIfOnlyPossibleAbility); + } + void updatePromptIfOnlyPossibleAbility(SpellAbility sa) { + set(SpellAbilityProp.PromptIfOnlyPossibleAbility, sa.promptIfOnlyPossibleAbility()); + } +} diff --git a/forge-game/src/main/java/forge/game/spellability/StackItemView.java b/forge-game/src/main/java/forge/game/spellability/StackItemView.java new file mode 100644 index 00000000000..df4ad14114f --- /dev/null +++ b/forge-game/src/main/java/forge/game/spellability/StackItemView.java @@ -0,0 +1,98 @@ +package forge.game.spellability; + +import forge.game.card.CardView; +import forge.game.player.PlayerView; +import forge.trackable.TrackableObject; +import forge.trackable.TrackableProperty.StackItemProp; + + +public class StackItemView extends TrackableObject { + public StackItemView(SpellAbilityStackInstance si) { + super(si.getId(), StackItemProp.class); + updateKey(si); + updateSourceTrigger(si); + updateText(si); + updateSourceCard(si); + updateActivator(si); + updateTargetCards(si); + updateTargetPlayers(si); + updateAbility(si); + updateOptionalTrigger(si); + updateSubInstance(si); + } + + public String getKey() { + return get(StackItemProp.Key); + } + void updateKey(SpellAbilityStackInstance si) { + set(StackItemProp.Key, si.getSpellAbility(false).toUnsuppressedString()); + } + + public int getSourceTrigger() { + return get(StackItemProp.SourceTrigger); + } + void updateSourceTrigger(SpellAbilityStackInstance si) { + set(StackItemProp.SourceTrigger, si.getSpellAbility(false).getSourceTrigger()); + } + + public String getText() { + return get(StackItemProp.Text); + } + void updateText(SpellAbilityStackInstance si) { + set(StackItemProp.Text, si.getStackDescription()); + } + + public CardView getSourceCard() { + return get(StackItemProp.SourceCard); + } + void updateSourceCard(SpellAbilityStackInstance si) { + set(StackItemProp.SourceCard, si.getSourceCard()); + } + + public PlayerView getActivator() { + return get(StackItemProp.Activator); + } + void updateActivator(SpellAbilityStackInstance si) { + set(StackItemProp.Activator, PlayerView.get(si.getActivator())); + } + + public Iterable getTargetCards() { + return get(StackItemProp.TargetCards); + } + void updateTargetCards(SpellAbilityStackInstance si) { + set(StackItemProp.TargetCards, CardView.getCollection(si.getTargetChoices().getTargetCards())); + } + + public Iterable getTargetPlayers() { + return get(StackItemProp.TargetPlayers); + } + void updateTargetPlayers(SpellAbilityStackInstance si) { + set(StackItemProp.TargetPlayers, PlayerView.getCollection(si.getTargetChoices().getTargetPlayers())); + } + + public boolean isAbility() { + return get(StackItemProp.Ability); + } + void updateAbility(SpellAbilityStackInstance si) { + set(StackItemProp.Ability, si.isAbility()); + } + + public boolean isOptionalTrigger() { + return get(StackItemProp.OptionalTrigger); + } + void updateOptionalTrigger(SpellAbilityStackInstance si) { + set(StackItemProp.OptionalTrigger, si.isOptionalTrigger()); + } + + public StackItemView getSubInstance() { + return get(StackItemProp.SubInstance); + } + void updateSubInstance(SpellAbilityStackInstance si) { + set(StackItemProp.SubInstance, si.getSubInstance() == null ? null : new StackItemView(si.getSubInstance())); + } + + @Override + public String toString() { + return getText(); + } +} diff --git a/forge-game/src/main/java/forge/game/staticability/StaticAbilityContinuous.java b/forge-game/src/main/java/forge/game/staticability/StaticAbilityContinuous.java index b1d7dfb555d..9fb77feb457 100644 --- a/forge-game/src/main/java/forge/game/staticability/StaticAbilityContinuous.java +++ b/forge-game/src/main/java/forge/game/staticability/StaticAbilityContinuous.java @@ -159,7 +159,7 @@ public class StaticAbilityContinuous { if (params.containsKey("AddKeyword")) { addKeywords = params.get("AddKeyword").split(" & "); - final List chosencolors = hostCard.getChosenColor(); + final List chosencolors = hostCard.getChosenColors(); for (final String color : chosencolors) { for (int w = 0; w < addKeywords.length; w++) { addKeywords[w] = addKeywords[w].replaceAll("ChosenColor", color.substring(0, 1).toUpperCase().concat(color.substring(1, color.length()))); @@ -170,7 +170,7 @@ public class StaticAbilityContinuous { addKeywords[w] = addKeywords[w].replaceAll("ChosenType", chosenType); } final String chosenName = hostCard.getNamedCard(); - final String hostCardUID = Integer.toString(hostCard.getUniqueNumber()); // Protection with "doesn't remove" effect + final String hostCardUID = Integer.toString(hostCard.getId()); // Protection with "doesn't remove" effect for (int w = 0; w < addKeywords.length; w++) { if (addKeywords[w].startsWith("Protection:")) { addKeywords[w] = addKeywords[w].replaceAll("ChosenName", "Card.named" + chosenName).replace("HostCardUID", hostCardUID); @@ -223,7 +223,7 @@ public class StaticAbilityContinuous { addTypes[0] = chosenType; se.setChosenType(chosenType); } else if (addTypes[0].equals("ImprintedCreatureType")) { - final ArrayList imprint = hostCard.getImprinted().get(0).getType(); + final Set imprint = hostCard.getImprinted().get(0).getType(); ArrayList imprinted = new ArrayList(); for (String t : imprint) { if (CardType.isACreatureType(t) || t.equals("AllCreatureTypes")) { @@ -262,7 +262,7 @@ public class StaticAbilityContinuous { if (params.containsKey("AddColor")) { final String colors = params.get("AddColor"); if (colors.equals("ChosenColor")) { - addColors = CardUtil.getShortColorsString(hostCard.getChosenColor()); + addColors = CardUtil.getShortColorsString(hostCard.getChosenColors()); } else { addColors = CardUtil.getShortColorsString(new ArrayList(Arrays.asList(colors.split( " & ")))); @@ -272,7 +272,7 @@ public class StaticAbilityContinuous { if (params.containsKey("SetColor")) { final String colors = params.get("SetColor"); if (colors.equals("ChosenColor")) { - addColors = CardUtil.getShortColorsString(hostCard.getChosenColor()); + addColors = CardUtil.getShortColorsString(hostCard.getChosenColors()); } else { addColors = CardUtil.getShortColorsString(new ArrayList(Arrays.asList( colors.split(" & ")))); @@ -381,8 +381,8 @@ public class StaticAbilityContinuous { if (changeColorWordsTo != null) { final byte color; if (changeColorWordsTo.equals("ChosenColor")) { - if (hostCard.getChosenColor().size() > 0) { - color = MagicColor.fromName(hostCard.getChosenColor().get(0)); + if (hostCard.getChosenColors().size() > 0) { + color = MagicColor.fromName(hostCard.getChosenColors().get(0)); } else { color = 0; } @@ -653,7 +653,7 @@ public class StaticAbilityContinuous { } else if (params.get("Affected").contains("EnchantedBy")) { affectedCards = Lists.newArrayList(hostCard.getEnchantingCard()); } else if (params.get("Affected").contains("EquippedBy")) { - affectedCards = Lists.newArrayList(hostCard.getEquippingCard()); + affectedCards = Lists.newArrayList(hostCard.getEquipping()); } else if (params.get("Affected").equals("EffectSource")) { affectedCards = new ArrayList(AbilityUtils.getDefinedCards(hostCard, params.get("Affected"), null)); return affectedCards; diff --git a/forge-game/src/main/java/forge/game/trigger/TriggerHandler.java b/forge-game/src/main/java/forge/game/trigger/TriggerHandler.java index cabc6969d24..8d947dcb3d8 100644 --- a/forge-game/src/main/java/forge/game/trigger/TriggerHandler.java +++ b/forge-game/src/main/java/forge/game/trigger/TriggerHandler.java @@ -190,7 +190,7 @@ public class TriggerHandler implements IGameStateObject { while(itr.hasNext()) { t = (Trigger)itr.next(); - if (c.getUniqueNumber() == t.getHostCard().getUniqueNumber() && t.isIntrinsic()) { + if (c.getId() == t.getHostCard().getId() && t.isIntrinsic()) { toBeRemoved.add(t); } } @@ -420,7 +420,7 @@ public class TriggerHandler implements IGameStateObject { Card host = regtrig.getHostCard(); Card trigCard = regtrig.getRunParams().containsKey("Card") ? (Card)regtrig.getRunParams().get("Card") : null; - if (trigCard != null && (host.getUniqueNumber() == trigCard.getUniqueNumber())) { + if (trigCard != null && (host.getId() == trigCard.getId())) { host = trigCard; } else { host = game.getCardState(regtrig.getHostCard()); @@ -445,7 +445,7 @@ public class TriggerHandler implements IGameStateObject { regtrig.setTriggeringObjects(sa); sa.setTriggerRemembered(regtrig.getTriggerRemembered()); if (regtrig.getStoredTriggeredObjects() != null) { - sa.setAllTriggeringObjects(regtrig.getStoredTriggeredObjects()); + sa.setTriggeringObjects(regtrig.getStoredTriggeredObjects()); } if (sa.getActivatingPlayer() == null) { // overriding delayed trigger should have set activator sa.setActivatingPlayer(host.getController()); diff --git a/forge-game/src/main/java/forge/game/trigger/TriggerSpellAbilityCast.java b/forge-game/src/main/java/forge/game/trigger/TriggerSpellAbilityCast.java index 4cea01fdf83..7d0c1ae6936 100644 --- a/forge-game/src/main/java/forge/game/trigger/TriggerSpellAbilityCast.java +++ b/forge-game/src/main/java/forge/game/trigger/TriggerSpellAbilityCast.java @@ -95,7 +95,7 @@ public class TriggerSpellAbilityCast extends Trigger { } if (this.mapParams.containsKey("ValidActivatingPlayer")) { - if (si == null || !matchesValid(si.getSpellAbility().getActivatingPlayer(), this.mapParams.get("ValidActivatingPlayer") + if (si == null || !matchesValid(si.getSpellAbility(true).getActivatingPlayer(), this.mapParams.get("ValidActivatingPlayer") .split(","), this.getHostCard())) { return false; } @@ -103,7 +103,7 @@ public class TriggerSpellAbilityCast extends Trigger { String compare = this.mapParams.get("ActivatorThisTurnCast"); List thisTurnCast = CardUtil.getThisTurnCast(this.mapParams.containsKey("ValidCard") ? this.mapParams.get("ValidCard") : "Card", this.getHostCard()); - thisTurnCast = CardLists.filterControlledBy(thisTurnCast, si.getSpellAbility().getActivatingPlayer()); + thisTurnCast = CardLists.filterControlledBy(thisTurnCast, si.getSpellAbility(true).getActivatingPlayer()); int left = thisTurnCast.size(); int right = Integer.parseInt(compare.substring(2)); if (!Expressions.compare(left, compare, right)) { @@ -121,7 +121,7 @@ public class TriggerSpellAbilityCast extends Trigger { if (this.mapParams.containsKey("TargetsValid")) { SpellAbility sa = spellAbility; if (si != null) { - sa = si.getSpellAbility(); + sa = si.getSpellAbility(true); } boolean validTgtFound = false; @@ -211,7 +211,7 @@ public class TriggerSpellAbilityCast extends Trigger { final SpellAbilityStackInstance si = sa.getHostCard().getGame().getStack().getInstanceFromSpellAbility(castSA); sa.setTriggeringObject("Card", castSA.getHostCard()); sa.setTriggeringObject("SpellAbility", castSA); - sa.setTriggeringObject("SpellAbilityTargetingCards", (si != null ? si.getSpellAbility() : castSA).getTargets().getTargetCards()); + sa.setTriggeringObject("SpellAbilityTargetingCards", (si != null ? si.getSpellAbility(true) : castSA).getTargets().getTargetCards()); sa.setTriggeringObject("Player", this.getRunParams().get("Player")); sa.setTriggeringObject("Activator", this.getRunParams().get("Activator")); sa.setTriggeringObject("CurrentStormCount", this.getRunParams().get("CurrentStormCount")); diff --git a/forge-game/src/main/java/forge/game/trigger/TriggerTapsForMana.java b/forge-game/src/main/java/forge/game/trigger/TriggerTapsForMana.java index 5842af0b621..aa2b943d5eb 100644 --- a/forge-game/src/main/java/forge/game/trigger/TriggerTapsForMana.java +++ b/forge-game/src/main/java/forge/game/trigger/TriggerTapsForMana.java @@ -93,7 +93,7 @@ public class TriggerTapsForMana extends Trigger { } String produced = (String) prod; if ("ChosenColor".equals(mapParams.get("Produced"))) { - List colors = this.getHostCard().getChosenColor(); + List colors = this.getHostCard().getChosenColors(); if (colors.isEmpty() || !produced.contains(MagicColor.toShortString(colors.get(0)))) { return false; } diff --git a/forge-game/src/main/java/forge/game/trigger/WrappedAbility.java b/forge-game/src/main/java/forge/game/trigger/WrappedAbility.java index 6bafe2536cd..f5ab983a735 100644 --- a/forge-game/src/main/java/forge/game/trigger/WrappedAbility.java +++ b/forge-game/src/main/java/forge/game/trigger/WrappedAbility.java @@ -31,7 +31,7 @@ public class WrappedAbility extends Ability implements ISpellAbility { boolean mandatory = false; public WrappedAbility(final Trigger regTrig, final SpellAbility sa0, final Player decider0) { - super(regTrig.getHostCard(), ManaCost.ZERO); + super(sa0.getHostCard(), ManaCost.ZERO); regtrig = regTrig; sa = sa0; decider = decider0; @@ -41,7 +41,6 @@ public class WrappedAbility extends Ability implements ISpellAbility { return sa; } - @Override public boolean isWrapper() { return true; @@ -109,8 +108,8 @@ public class WrappedAbility extends Ability implements ISpellAbility { } @Override - public void setAllTriggeringObjects(final HashMap triggeredObjects) { - sa.setAllTriggeringObjects(triggeredObjects); + public void setTriggeringObjects(final HashMap triggeredObjects) { + sa.setTriggeringObjects(triggeredObjects); } @Override @@ -178,11 +177,6 @@ public class WrappedAbility extends Ability implements ISpellAbility { return sa.getRestrictions(); } - @Override - public Card getHostCard() { - return sa.getHostCard(); - } - @Override public String getStackDescription() { final StringBuilder sb = new StringBuilder(regtrig.toString()); diff --git a/forge-game/src/main/java/forge/game/zone/MagicStack.java b/forge-game/src/main/java/forge/game/zone/MagicStack.java index c48f41524c7..42a62e064c7 100644 --- a/forge-game/src/main/java/forge/game/zone/MagicStack.java +++ b/forge-game/src/main/java/forge/game/zone/MagicStack.java @@ -191,7 +191,7 @@ public class MagicStack /* extends MyObservable */ implements Iterable(); SpellAbility s = sp; if (si != null) { - s = si.getSpellAbility(); + s = si.getSpellAbility(true); } runParams.put("SourceSA", s); HashSet distinctObjects = new HashSet(); @@ -780,13 +780,13 @@ public class MagicStack /* extends MyObservable */ implements Iterable> extends LinkedHashSet { //use linked hash set so order is maintained + public TrackableCollection() { + } + + @Override + public boolean add(T item) { + //TODO: Track change + return super.add(item); + } + + @Override + public boolean remove(Object item) { + //TODO: Track change + return super.remove(item); + } +} diff --git a/forge-game/src/main/java/forge/trackable/TrackableIndex.java b/forge-game/src/main/java/forge/trackable/TrackableIndex.java new file mode 100644 index 00000000000..c26d301d958 --- /dev/null +++ b/forge-game/src/main/java/forge/trackable/TrackableIndex.java @@ -0,0 +1,9 @@ +package forge.trackable; + +import java.util.HashMap; + +@SuppressWarnings("serial") +public class TrackableIndex> extends HashMap { + public TrackableIndex() { + } +} diff --git a/forge-game/src/main/java/forge/trackable/TrackableObject.java b/forge-game/src/main/java/forge/trackable/TrackableObject.java new file mode 100644 index 00000000000..09e44ea18b7 --- /dev/null +++ b/forge-game/src/main/java/forge/trackable/TrackableObject.java @@ -0,0 +1,48 @@ +package forge.trackable; + +import java.util.EnumMap; +import java.util.EnumSet; +import forge.game.IIdentifiable; + +//base class for objects that can be tracked and synced between game server and GUI +public abstract class TrackableObject> implements IIdentifiable { + private final int id; + private final EnumMap props; + private final EnumSet changedProps; + + protected TrackableObject(int id0, Class propEnum0) { + id = id0; + props = new EnumMap(propEnum0); + changedProps = EnumSet.noneOf(propEnum0); + } + + public int getId() { + return id; + } + + @Override + public int hashCode() { + return id; + } + + @SuppressWarnings("unchecked") + protected T get(E key) { + return (T)props.get(key); + } + + protected void set(E key, T value) { + if (value == null) { + if (props.remove(key) != null) { + changedProps.add(key); + } + } + else if (!value.equals(props.put(key, value))) { + changedProps.add(key); + } + } + + //use when updating collection type properties with using set + protected void flagAsChanged(E key) { + changedProps.add(key); + } +} diff --git a/forge-game/src/main/java/forge/trackable/TrackableProperty.java b/forge-game/src/main/java/forge/trackable/TrackableProperty.java new file mode 100644 index 00000000000..8bdd3cd7e9c --- /dev/null +++ b/forge-game/src/main/java/forge/trackable/TrackableProperty.java @@ -0,0 +1,118 @@ +package forge.trackable; + +public class TrackableProperty { + public enum CardProp { + Owner, + Controller, + Zone, + Cloned, + FaceDown, + FlipCard, + Flipped, + SplitCard, + Transformed, + SetCode, + Rarity, + Attacking, + Blocking, + PhasedOut, + Sickness, + Tapped, + Token, + Counters, + Damage, + AssignedDamage, + ShieldCount, + PreventNextDamage, + ChosenType, + ChosenColors, + ChosenPlayer, + NamedCard, + Equipping, + EquippedBy, + Enchanting, + EnchantedBy, + Fortifying, + FortifiedBy, + GainControlTargets, + CloneOrigin, + Imprinted, + HauntedBy, + Haunting, + MustBlock, + PairedWith, + Original, + Alternate + } + + public enum CardStateProp { + Name, + Colors, + ImageKey, + Type, + ManaCost, + Power, + Toughness, + Loyalty, + Text, + ChangedColorWords, + ChangedTypes, + HasDeathtouch, + HasHaste, + HasInfect, + HasStorm, + HasTrample, + FoilIndex + } + + public enum PlayerProp { + LobbyPlayer, + Opponents, + Life, + PoisonCounters, + MaxHandSize, + HasUnlimitedHandSize, + NumDrawnThisTurn, + PreventNextDamage, + Keywords, + CommanderInfo, + Ante, + Battlefield, + Command, + Exile, + Flashback, + Graveyard, + Hand, + Library, + Mana + } + + public enum SpellAbilityProp { + HostCard, + Description, + CanPlay, + PromptIfOnlyPossibleAbility + } + + public enum StackItemProp { + Key, + SourceTrigger, + Text, + SourceCard, + Activator, + TargetCards, + TargetPlayers, + SubInstance, + Ability, + OptionalTrigger + } + + public enum CombatProp { + AttackersWithDefenders, + AttackersWithBlockers, + BandsWithDefenders, + BandsWithBlockers, + AttackersWithPlannedBlockers, + BandsWithPlannedBlockers + } +} diff --git a/forge-gui-desktop/src/test/java/forge/gamesimulationtests/util/PlayerControllerForTests.java b/forge-gui-desktop/src/test/java/forge/gamesimulationtests/util/PlayerControllerForTests.java index b74c93d5ec6..6e5b420bd2c 100644 --- a/forge-gui-desktop/src/test/java/forge/gamesimulationtests/util/PlayerControllerForTests.java +++ b/forge-gui-desktop/src/test/java/forge/gamesimulationtests/util/PlayerControllerForTests.java @@ -575,7 +575,7 @@ public class PlayerControllerForTests extends PlayerController { @Override public CardShields chooseRegenerationShield(Card c) { - return Iterables.getFirst(c.getShield(), null); + return Iterables.getFirst(c.getShields(), null); } @Override diff --git a/forge-gui/src/main/java/forge/card/CardDetailUtil.java b/forge-gui/src/main/java/forge/card/CardDetailUtil.java index 07a986b376d..7c77fdcad4c 100644 --- a/forge-gui/src/main/java/forge/card/CardDetailUtil.java +++ b/forge-gui/src/main/java/forge/card/CardDetailUtil.java @@ -5,6 +5,7 @@ import java.util.Iterator; import java.util.List; import java.util.Map; import java.util.Map.Entry; +import java.util.Set; import org.apache.commons.lang3.StringUtils; @@ -167,7 +168,7 @@ public class CardDetailUtil { } public static String formatCardType(final CardStateView card) { - final List list = card.getType(); + final Set list = card.getType(); final StringBuilder sb = new StringBuilder(); final List superTypes = new ArrayList(); diff --git a/forge-gui/src/main/java/forge/match/input/InputBlock.java b/forge-gui/src/main/java/forge/match/input/InputBlock.java index cb84eb4bd9e..5225b9fefeb 100644 --- a/forge-gui/src/main/java/forge/match/input/InputBlock.java +++ b/forge-gui/src/main/java/forge/match/input/InputBlock.java @@ -82,7 +82,7 @@ public class InputBlock extends InputSyncronizedBase { showMessage("Select another attacker to declare blockers for."); } else { - String attackerName = currentAttacker.isFaceDown() ? "Morph" : currentAttacker.getName() + " (" + currentAttacker.getUniqueNumber() + ")"; + String attackerName = currentAttacker.isFaceDown() ? "Morph" : currentAttacker.getName() + " (" + currentAttacker.getId() + ")"; String message = "Select creatures to block " + attackerName + " or select another attacker to declare blockers for."; showMessage(message); } diff --git a/forge-gui/src/main/java/forge/player/HumanCostDecision.java b/forge-gui/src/main/java/forge/player/HumanCostDecision.java index bd0890db1a1..83801729cbf 100644 --- a/forge-gui/src/main/java/forge/player/HumanCostDecision.java +++ b/forge-gui/src/main/java/forge/player/HumanCostDecision.java @@ -327,7 +327,7 @@ public class HumanCostDecision extends CostDecisionMakerBase { for (SpellAbilityStackInstance si : game.getStack()) { final Card stC = si.getSourceCard(); - final SpellAbility stSA = si.getSpellAbility().getRootAbility(); + final SpellAbility stSA = si.getSpellAbility(true).getRootAbility(); if (stC.isValid(cost.getType().split(";"), ability.getActivatingPlayer(), source) && stSA.isSpell()) { saList.add(stSA); if (stC.isCopiedSpell()) { diff --git a/forge-gui/src/main/java/forge/player/PlayerControllerHuman.java b/forge-gui/src/main/java/forge/player/PlayerControllerHuman.java index 6428e9d5a7e..0c987c2d161 100644 --- a/forge-gui/src/main/java/forge/player/PlayerControllerHuman.java +++ b/forge-gui/src/main/java/forge/player/PlayerControllerHuman.java @@ -1275,10 +1275,14 @@ public class PlayerControllerHuman extends PlayerController { @Override public CardShields chooseRegenerationShield(Card c) { - if (c.getShield().size() < 2) { - return Iterables.getFirst(c.getShield(), null); + if (c.getShieldCount() < 2) { + return Iterables.getFirst(c.getShields(), null); } - return SGuiChoose.one(getGui(), "Choose a regeneration shield:", c.getShield()); + ArrayList shields = new ArrayList(); + for (CardShields shield : c.getShields()) { + shields.add(shield); + } + return SGuiChoose.one(getGui(), "Choose a regeneration shield:", shields); } @Override diff --git a/forge-gui/src/main/java/forge/player/TargetSelection.java b/forge-gui/src/main/java/forge/player/TargetSelection.java index 726abea0e71..1f0705d9b15 100644 --- a/forge-gui/src/main/java/forge/player/TargetSelection.java +++ b/forge-gui/src/main/java/forge/player/TargetSelection.java @@ -318,7 +318,7 @@ public class TargetSelection { final Game game = ability.getActivatingPlayer().getGame(); for (final SpellAbilityStackInstance si : game.getStack()) { - SpellAbility abilityOnStack = si.getSpellAbility(); + SpellAbility abilityOnStack = si.getSpellAbility(true); if (ability.equals(abilityOnStack)) { // By peeking at stack item, target is set to its SI state. So set it back before adding targets ability.resetTargets(); @@ -346,7 +346,7 @@ public class TargetSelection { return false; } if (madeChoice instanceof StackItemView) { - ability.getTargets().add(controller.getStackItem((StackItemView)madeChoice).getSpellAbility()); + ability.getTargets().add(controller.getStackItem((StackItemView)madeChoice).getSpellAbility(true)); } else // 'FINISH TARGETING' chosen bTargetingDone = true; } diff --git a/forge-gui/src/main/java/forge/view/CardView.java b/forge-gui/src/main/java/forge/view/CardView.java index 58d3c99bb33..12ce813bfb6 100644 --- a/forge-gui/src/main/java/forge/view/CardView.java +++ b/forge-gui/src/main/java/forge/view/CardView.java @@ -3,6 +3,7 @@ package forge.view; import java.util.Collections; import java.util.List; import java.util.Map; +import java.util.Set; import org.apache.commons.lang3.StringUtils; @@ -751,7 +752,7 @@ public class CardView extends GameEntityView { private String name; private ColorSet colors; private String imageKey; - private List type; + private Set type; private ManaCost manaCost; private int power, toughness, loyalty; private String text; @@ -768,7 +769,7 @@ public class CardView extends GameEntityView { this.name = ""; this.colors = ColorSet.getNullColor(); this.imageKey = ImageKeys.HIDDEN_CARD; - this.type = Collections.emptyList(); + this.type = Collections.emptySet(); this.manaCost = ManaCost.NO_COST; this.power = 0; this.toughness = 0; @@ -837,15 +838,15 @@ public class CardView extends GameEntityView { /** * @return the type */ - public List getType() { + public Set getType() { return type; } /** * @param type the type to set */ - public void setType(final List type) { - this.type = Collections.unmodifiableList(type); + public void setType(final Set type) { + this.type = type; } /** diff --git a/forge-gui/src/main/java/forge/view/LocalGameView.java b/forge-gui/src/main/java/forge/view/LocalGameView.java index 9805dd9ad42..76b1f1959ec 100644 --- a/forge-gui/src/main/java/forge/view/LocalGameView.java +++ b/forge-gui/src/main/java/forge/view/LocalGameView.java @@ -484,7 +484,7 @@ public abstract class LocalGameView implements IGameView { view.setAttacking(combat != null && combat.isAttacking(c)); view.setBlocking(combat != null && combat.isBlocking(c)); view.setChosenPlayer(getPlayerView(c.getChosenPlayer(), false)); - view.setEquipping(getCardView(Iterables.getFirst(c.getEquipping(), null), false)); + view.setEquipping(getCardView(c.getEquipping(), false)); view.setEquippedBy(getCardViews(c.getEquippedBy(), false)); view.setEnchantingCard(getCardView(c.getEnchantingCard(), false)); view.setEnchantingPlayer(getPlayerView(c.getEnchantingPlayer(), false)); diff --git a/forge-gui/src/main/java/forge/view/StackItemView.java b/forge-gui/src/main/java/forge/view/StackItemView.java index 80acb9f52b0..4e651278612 100644 --- a/forge-gui/src/main/java/forge/view/StackItemView.java +++ b/forge-gui/src/main/java/forge/view/StackItemView.java @@ -27,8 +27,8 @@ public class StackItemView implements IIdentifiable { public StackItemView(SpellAbilityStackInstance si, LocalGameView gameView) { id = si.getId(); - key = si.getSpellAbility().toUnsuppressedString(); - sourceTrigger = si.getSpellAbility().getSourceTrigger(); + key = si.getSpellAbility(false).toUnsuppressedString(); + sourceTrigger = si.getSpellAbility(false).getSourceTrigger(); text = si.getStackDescription(); source = gameView.getCardView(si.getSourceCard(), true); activatingPlayer = gameView.getPlayerView(si.getActivator(), false); diff --git a/forge-gui/src/main/java/forge/view/ViewUtil.java b/forge-gui/src/main/java/forge/view/ViewUtil.java index 421e247445f..599bfe7692b 100644 --- a/forge-gui/src/main/java/forge/view/ViewUtil.java +++ b/forge-gui/src/main/java/forge/view/ViewUtil.java @@ -1,6 +1,5 @@ package forge.view; -import java.util.Collections; import java.util.List; import com.google.common.base.Function; @@ -53,10 +52,10 @@ public final class ViewUtil { view.setCounters(c.getCounters()); view.setDamage(c.getDamage()); view.setAssignedDamage(c.getTotalAssignedDamage()); - view.setRegenerationShields(c.getShield().size()); + view.setRegenerationShields(c.getShieldCount()); view.setPreventNextDamage(c.getPreventNextDamageTotalShields()); view.setChosenType(c.getChosenType()); - view.setChosenColors(c.getChosenColor()); + view.setChosenColors(c.getChosenColors()); view.setNamedCard(c.getNamedCard()); if (c.isSplitCard()) { @@ -78,7 +77,7 @@ public final class ViewUtil { origView.setName(c.getName()); origView.setColors(c.determineColor()); origView.setImageKey(c.getImageKey() ); - origView.setType(Collections.unmodifiableList(c.getType())); + origView.setType(c.getType()); origView.setManaCost(c.getManaCost()); origView.setPower(c.getNetAttack()); origView.setToughness(c.getNetDefense()); @@ -119,7 +118,7 @@ public final class ViewUtil { view.setName(chars.getName()); view.setColors(chars.determineColor()); view.setImageKey(chars.getImageKey()); - view.setType(Collections.unmodifiableList(chars.getType())); + view.setType(chars.getType()); view.setManaCost(chars.getManaCost()); view.setPower(chars.getBaseAttack()); view.setToughness(chars.getBaseDefense());