From 3b3f136d346cd961d0a124d7214c644fa4db1816 Mon Sep 17 00:00:00 2001 From: LevelX2 Date: Fri, 2 May 2014 16:45:26 +0200 Subject: [PATCH] Spells on the stack can now get counters. --- Mage.Common/src/mage/view/CardView.java | 1 - .../src/mage/view/StackAbilityView.java | 10 ++++--- Mage/src/mage/abilities/AbilityImpl.java | 4 +++ Mage/src/mage/constants/MageObjectType.java | 8 ++--- Mage/src/mage/game/stack/Spell.java | 29 ++++++++++++++----- Mage/src/mage/game/stack/SpellStack.java | 7 ++--- 6 files changed, 38 insertions(+), 21 deletions(-) diff --git a/Mage.Common/src/mage/view/CardView.java b/Mage.Common/src/mage/view/CardView.java index 267e2559252..d1e8b55cff9 100644 --- a/Mage.Common/src/mage/view/CardView.java +++ b/Mage.Common/src/mage/view/CardView.java @@ -41,7 +41,6 @@ import mage.cards.SplitCard; import mage.constants.CardType; import mage.constants.MageObjectType; import mage.constants.Rarity; -import mage.constants.SpellAbilityType; import mage.constants.Zone; import mage.counters.Counter; import mage.counters.CounterType; diff --git a/Mage.Common/src/mage/view/StackAbilityView.java b/Mage.Common/src/mage/view/StackAbilityView.java index 1ebe6c4bb66..deeacb9be92 100644 --- a/Mage.Common/src/mage/view/StackAbilityView.java +++ b/Mage.Common/src/mage/view/StackAbilityView.java @@ -47,7 +47,7 @@ import mage.target.targetpointer.TargetPointer; public class StackAbilityView extends CardView { private static final long serialVersionUID = 1L; - private CardView sourceCard; + private final CardView sourceCard; public StackAbilityView(Game game, StackAbility ability, String sourceName, CardView sourceCard) { this.id = ability.getId(); @@ -55,7 +55,7 @@ public class StackAbilityView extends CardView { this.sourceCard = sourceCard; this.sourceCard.setMageObjectType(mageObjectType); this.name = "Ability"; - this.rules = new ArrayList(); + this.rules = new ArrayList<>(); rules.add(ability.getRule(sourceName)); this.power = ability.getPower().toString(); this.toughness = ability.getToughness().toString(); @@ -65,17 +65,19 @@ public class StackAbilityView extends CardView { this.superTypes = ability.getSupertype(); this.color = ability.getColor(); this.manaCost = ability.getManaCost().getSymbols(); + this.counters = sourceCard.getCounters(); + updateTargets(game, ability); } private void updateTargets(Game game, StackAbility ability) { - List names = new ArrayList(); + List names = new ArrayList<>(); for(UUID modeId : ability.getModes().getSelectedModes()) { ability.getModes().setMode(ability.getModes().get(modeId)); if (ability.getTargets().size() > 0) { setTargets(ability.getTargets()); } else { - List targetList = new ArrayList(); + List targetList = new ArrayList<>(); for (Effect effect : ability.getEffects()) { TargetPointer targetPointer = effect.getTargetPointer(); if (targetPointer instanceof FixedTarget) { diff --git a/Mage/src/mage/abilities/AbilityImpl.java b/Mage/src/mage/abilities/AbilityImpl.java index 2a5d4ac3737..0dc5ed073fb 100644 --- a/Mage/src/mage/abilities/AbilityImpl.java +++ b/Mage/src/mage/abilities/AbilityImpl.java @@ -889,6 +889,10 @@ public abstract class AbilityImpl> implements Ability { return sb.toString(); } + public String getTargetDescription(Targets targets, Game game) { + return getTargetDescriptionForLog(targets, game); + } + protected String getTargetDescriptionForLog(Targets targets, Game game) { StringBuilder sb = new StringBuilder(); if (targets.size() > 0) { diff --git a/Mage/src/mage/constants/MageObjectType.java b/Mage/src/mage/constants/MageObjectType.java index 7afa5f33930..05fc18383f9 100644 --- a/Mage/src/mage/constants/MageObjectType.java +++ b/Mage/src/mage/constants/MageObjectType.java @@ -29,14 +29,14 @@ public enum MageObjectType { CARD ("Card", false, true), COPY_CARD ("Copy of a Card", false, true), TOKEN ("Token", true, true), - SPELL ("Spell", false, false), + SPELL ("Spell", false, true), PERMANENT ("Permanent", true, true), EMBLEM ("Emblem", false, false), COMMANDER ("Commander", false, false); - private String text; - private boolean permanent; - private boolean canHaveCounters; + private final String text; + private final boolean permanent; + private final boolean canHaveCounters; MageObjectType(String text, boolean permanent, boolean canHaveCounters) { diff --git a/Mage/src/mage/game/stack/Spell.java b/Mage/src/mage/game/stack/Spell.java index f3cc359e7c1..af56e853196 100644 --- a/Mage/src/mage/game/stack/Spell.java +++ b/Mage/src/mage/game/stack/Spell.java @@ -372,6 +372,7 @@ public class Spell> implements StackObject, Card { public boolean chooseNewTargets(Game game, UUID playerId, boolean forceChange, boolean onlyOneTarget) { Player player = game.getPlayer(playerId); if (player != null) { + StringBuilder newTargetDescription = new StringBuilder(); // Fused split spells or spells where "Splice on Arcane" was used can have more than one ability for (SpellAbility spellAbility : spellAbilities) { // Some spells can have more than one mode @@ -386,9 +387,11 @@ public class Spell> implements StackObject, Card { } } + newTargetDescription.append(getSpellAbility().getTargetDescription(mode.getTargets(), game)); } } + game.informPlayers(this.getName() + " is now " + newTargetDescription.toString()); return true; } return false; @@ -851,26 +854,38 @@ public class Spell> implements StackObject, Card { @Override public Counters getCounters() { - return null; + return card.getCounters(); } @Override - public void addCounters(String name, int amount, Game game) {} + public void addCounters(String name, int amount, Game game) { + card.addCounters(name, amount, game); + } @Override - public void addCounters(String name, int amount, Game game, ArrayList appliedEffects) {} + public void addCounters(String name, int amount, Game game, ArrayList appliedEffects) { + card.addCounters(name, amount, game, appliedEffects); + } @Override - public void addCounters(Counter counter, Game game) {} + public void addCounters(Counter counter, Game game) { + card.addCounters(counter, game); + } @Override - public void addCounters(Counter counter, Game game, ArrayList appliedEffects) {} + public void addCounters(Counter counter, Game game, ArrayList appliedEffects) { + card.addCounters(counter, game, appliedEffects); + } @Override - public void removeCounters(String name, int amount, Game game) {} + public void removeCounters(String name, int amount, Game game) { + card.removeCounters(name, amount, game); + } @Override - public void removeCounters(Counter counter, Game game) {} + public void removeCounters(Counter counter, Game game) { + card.removeCounters(counter, game); + } public Card getCard() { return card; diff --git a/Mage/src/mage/game/stack/SpellStack.java b/Mage/src/mage/game/stack/SpellStack.java index 65538aadd94..3e221ec5def 100644 --- a/Mage/src/mage/game/stack/SpellStack.java +++ b/Mage/src/mage/game/stack/SpellStack.java @@ -105,13 +105,10 @@ public class SpellStack extends ArrayDeque { public Spell getSpell(UUID id) { for (StackObject stackObject: this) { - if (stackObject.getId().equals(id)) { - if (stackObject instanceof Spell) { + if (stackObject instanceof Spell) { + if (stackObject.getId().equals(id) || stackObject.getSourceId().equals(id)) { return (Spell)stackObject; } - else { - return null; - } } } return null;