From 7e14d5ca58dfe924e1748d42f1fc3f7ae427e837 Mon Sep 17 00:00:00 2001 From: Maxmtg Date: Thu, 11 Apr 2013 21:18:01 +0000 Subject: [PATCH] cleanup for Card class, removed unreferenced methods and variables, inlined once-referenced, moved ai-related closer to AI --- src/main/java/forge/Card.java | 489 +----------------- .../forge/card/ability/ai/ChangeZoneAi.java | 2 - .../forge/card/ability/ai/RepeatEachAi.java | 2 +- .../card/ability/effects/AttachEffect.java | 2 - .../ability/effects/ChangeZoneEffect.java | 6 - .../cardfactory/CardFactoryCreatures.java | 2 +- .../card/cardfactory/CardFactoryUtil.java | 1 - src/main/java/forge/game/GameAction.java | 3 +- .../java/forge/game/ai/ComputerUtilCard.java | 2 +- .../java/forge/game/ai/ComputerUtilMana.java | 35 +- .../game/zone/PlayerZoneBattlefield.java | 5 +- .../java/forge/view/arcane/CardPanel.java | 44 +- 12 files changed, 76 insertions(+), 517 deletions(-) diff --git a/src/main/java/forge/Card.java b/src/main/java/forge/Card.java index 83c389367a1..44bae53b649 100644 --- a/src/main/java/forge/Card.java +++ b/src/main/java/forge/Card.java @@ -30,6 +30,8 @@ import java.util.Map.Entry; import java.util.Set; import java.util.TreeMap; +import org.apache.commons.lang3.StringUtils; + import com.esotericsoftware.minlog.Log; import com.google.common.collect.ImmutableList; import com.google.common.collect.Iterables; @@ -47,7 +49,6 @@ import forge.card.mana.ManaCostBeingPaid; import forge.card.replacement.ReplaceMoved; import forge.card.replacement.ReplacementEffect; import forge.card.replacement.ReplacementResult; -import forge.card.spellability.AbilityManaPart; import forge.card.spellability.AbilityTriggered; import forge.card.spellability.SpellAbility; import forge.card.spellability.SpellPermanent; @@ -135,11 +136,9 @@ public class Card extends GameEntity implements Comparable { private boolean token = false; private boolean copiedToken = false; private boolean copiedSpell = false; - private boolean spellWithChoices = false; private ArrayList mustBlockCards = null; - private boolean canMorph = false; private boolean canCounter = true; private boolean evoked = false; @@ -212,10 +211,6 @@ public class Card extends GameEntity implements Comparable { private final List gainControlReleaseCommands = new ArrayList(); private final List zcTriggers = new ArrayList(); - private final List equipCommandList = new ArrayList(); - private final List unEquipCommandList = new ArrayList(); - private final List enchantCommandList = new ArrayList(); - private final List unEnchantCommandList = new ArrayList(); private final List untapCommandList = new ArrayList(); private final List changeControllerCommandList = new ArrayList(); @@ -1176,20 +1171,17 @@ public class Card extends GameEntity implements Comparable { } public final int getTotalCountersToAdd(final CounterType counterType, final int baseAmount, final boolean applyMultiplier) { - if (!this.canReceiveCounters(counterType)) { - return 0; + if (this.canReceiveCounters(counterType)) { + final int multiplier = applyMultiplier ? this.getController().getCounterDoublersMagnitude(counterType) : 1; + return multiplier * baseAmount; } - final int multiplier = applyMultiplier ? this.getController().getCounterDoublersMagnitude(counterType) : 1; - - return multiplier * baseAmount; + return 0; } public final void addCounter(final CounterType counterType, final int n, final boolean applyMultiplier) { - if (!this.canReceiveCounters(counterType)) { + final int addAmount = getTotalCountersToAdd(counterType, n, applyMultiplier); + if ( addAmount == 0 ) return; - } - final int multiplier = applyMultiplier ? this.getController().getCounterDoublersMagnitude(counterType) : 1; - final int addAmount = (multiplier * n); Integer oldValue = this.counters.get(counterType); int newValue = addAmount + (oldValue == null ? 0 : oldValue.intValue()); @@ -1330,19 +1322,6 @@ public class Card extends GameEntity implements Comparable { return !this.counters.isEmpty(); } - /** - * - * getNumberOfCounters. - * - * @return int - */ - public final int getNumberOfCounters() { - int number = 0; - for (final Integer i : this.counters.values()) { - number += i.intValue(); - } - return number; - } // get all counters from a card @@ -1452,24 +1431,12 @@ public class Card extends GameEntity implements Comparable { */ public final int sumAllCounters() { int count = 0; - int num = 0; - for (final Object value2 : this.counters.values()) { - num = (Integer) value2; - count += num; + for (final Integer value2 : this.counters.values()) { + count += value2.intValue(); } return count; } - /** - *

- * getNetPTCounters. - *

- * - * @return a int. - */ - public final int getNetPTCounters() { - return this.getCounters(CounterType.P1P1) - this.getCounters(CounterType.M1M1); - } /** *

@@ -2526,53 +2493,6 @@ public class Card extends GameEntity implements Comparable { return Collections.unmodifiableList(this.getCharacteristics().getManaAbility()); } - // Returns basic mana abilities plus "reflected mana" abilities - /** - *

- * getAIPlayableMana. - *

- * - * @return a {@link java.util.ArrayList} object. - */ - public final ArrayList getAIPlayableMana() { - final ArrayList res = new ArrayList(); - for (final SpellAbility a : this.getManaAbility()) { - - // if a mana ability has a mana cost the AI will miscalculate - // if there is a parent ability the AI can't use it - final Cost cost = a.getPayCosts(); - if (!cost.hasNoManaCost() - || (a.getApi() != ApiType.Mana && a.getApi() != ApiType.ManaReflected)) { - continue; - } - - AbilityManaPart am = a.getManaPart(); - if (am.isBasic() && !res.contains(a)) { - res.add(a); - } - - } - - return res; - - } - - /** - *

- * getBasicMana. - *

- * - * @return a {@link java.util.ArrayList} object. - */ - public final List getBasicMana() { - final List res = new ArrayList(); - for (final SpellAbility a : this.getManaAbility()) { - if (a.getManaPart().isBasic() && !res.contains(a)) { - res.add(a); - } - } - return res; - } /** *

@@ -2877,29 +2797,6 @@ public class Card extends GameEntity implements Comparable { return this.copiedSpell; } - /** - *

- * setSpellWithChoices. - *

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

- * hasChoices. - *

- * - * @return a boolean. - */ - public final boolean hasChoices() { - return this.spellWithChoices; - } - /** *

* isFaceDown. @@ -2934,28 +2831,6 @@ public class Card extends GameEntity implements Comparable { return this.canCounter; } - /** - *

- * setCanMorph. - *

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

- * getCanMorph. - *

- * - * @return a boolean. - */ - public final boolean getCanMorph() { - return this.canMorph; - } /** *

@@ -3022,26 +2897,7 @@ public class Card extends GameEntity implements Comparable { this.addTrigger(c, ZCTrigger.ENTERFIELD); } - /** - *

- * removeComesIntoPlayCommand. - *

- * - * @param c - * a {@link forge.Command} object. - */ - public final void removeComesIntoPlayCommand(final Command c) { - this.removeTrigger(c, ZCTrigger.ENTERFIELD); - } - /** - *

- * comesIntoPlay. - *

- */ - public final void comesIntoPlay() { - this.executeTrigger(ZCTrigger.ENTERFIELD); - } /** *

@@ -3055,26 +2911,6 @@ public class Card extends GameEntity implements Comparable { this.addTrigger(c, ZCTrigger.DESTROY); } - /** - *

- * removeDestroyCommand. - *

- * - * @param c - * a {@link forge.Command} object. - */ - public final void removeDestroyCommand(final Command c) { - this.removeTrigger(c, ZCTrigger.DESTROY); - } - - /** - *

- * destroy. - *

- */ - public final void destroy() { - this.executeTrigger(ZCTrigger.DESTROY); - } /** *

@@ -3088,161 +2924,6 @@ public class Card extends GameEntity implements Comparable { this.addTrigger(c, ZCTrigger.LEAVEFIELD); } - /** - *

- * removeLeavesPlayCommand. - *

- * - * @param c - * a {@link forge.Command} object. - */ - public final void removeLeavesPlayCommand(final Command c) { - this.removeTrigger(c, ZCTrigger.LEAVEFIELD); - } - - /** - *

- * leavesPlay. - *

- */ - public final void leavesPlay() { - this.executeTrigger(ZCTrigger.LEAVEFIELD); - } - - /** - *

- * addEquipCommand. - *

- * - * @param c - * a {@link forge.Command} object. - */ - public final void addEquipCommand(final Command c) { - this.equipCommandList.add(c); - } - - /** - *

- * removeEquipCommand. - *

- * - * @param c - * a {@link forge.Command} object. - */ - public final void removeEquipCommand(final Command c) { - this.equipCommandList.remove(c); - } - - /** - *

- * equip. - *

- */ - public final void equip() { - for (final Command var : this.equipCommandList) { - var.execute(); - } - } - - /** - *

- * addUnEquipCommand. - *

- * - * @param c - * a {@link forge.Command} object. - */ - public final void addUnEquipCommand(final Command c) { - this.unEquipCommandList.add(c); - } - - /** - *

- * removeUnEquipCommand. - *

- * - * @param c - * a {@link forge.Command} object. - */ - public final void removeUnEquipCommand(final Command c) { - this.unEquipCommandList.remove(c); - } - - /** - *

- * unEquip. - *

- */ - public final void unEquip() { - for (final Command var : this.unEquipCommandList) { - var.execute(); - } - } - - /** - *

- * addEnchantCommand. - *

- * - * @param c - * a {@link forge.Command} object. - */ - public final void addEnchantCommand(final Command c) { - this.enchantCommandList.add(c); - } - - /** - *

- * clearEnchantCommand. - *

- */ - public final void clearEnchantCommand() { - this.enchantCommandList.clear(); - } - - /** - *

- * enchant. - *

- */ - public final void enchant() { - for (final Command var : this.enchantCommandList) { - var.execute(); - } - } - - /** - *

- * addUnEnchantCommand. - *

- * - * @param c - * a {@link forge.Command} object. - */ - public final void addUnEnchantCommand(final Command c) { - this.unEnchantCommandList.add(c); - } - - /** - *

- * clearUnEnchantCommand. - *

- */ - public final void clearUnEnchantCommand() { - this.unEnchantCommandList.clear(); - } - - /** - *

- * unEnchant. - *

- */ - public final void unEnchant() { - for (final Command var : this.unEnchantCommandList) { - var.execute(); - } - } - /** *

* addUntapCommand. @@ -3420,7 +3101,7 @@ public class Card extends GameEntity implements Comparable { * @return a {@link forge.Card} object. */ public final Card getEquippingCard() { - if (this.equipping.size() == 0) { + if (this.equipping.isEmpty()) { return null; } return this.equipping.get(0); @@ -3544,7 +3225,6 @@ public class Card extends GameEntity implements Comparable { } this.addEquipping(c); c.addEquippedBy(this); - this.equip(); // Play the Equip sound Singletons.getModel().getGame().getEvents().post(new CardEquippedEvent()); @@ -3565,7 +3245,6 @@ public class Card extends GameEntity implements Comparable { */ public final void unEquipCard(final Card c) // equipment.unEquipCard(equippedCard); { - this.unEquip(); this.equipping.remove(c); c.removeEquippedBy(this); @@ -3735,7 +3414,6 @@ public class Card extends GameEntity implements Comparable { } this.addEnchanting(entity); entity.addEnchantedBy(this); - this.enchant(); // run trigger final HashMap runParams = new HashMap(); runParams.put("AttachSource", this); @@ -3753,7 +3431,6 @@ public class Card extends GameEntity implements Comparable { */ public final void unEnchantEntity(final GameEntity gameEntity) { if ((this.enchanting != null) && this.enchanting.equals(gameEntity)) { - this.unEnchant(); this.enchanting = null; gameEntity.removeEnchantedBy(this); } @@ -3782,17 +3459,6 @@ public class Card extends GameEntity implements Comparable { this.getCharacteristics().getType().add(a); } - /** - *

- * removeType. - *

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

@@ -3846,27 +3512,6 @@ public class Card extends GameEntity implements Comparable { return new ArrayList(this.getCharacteristics().getType()); } - /** - * - * TODO Write javadoc for this method. - * - * @param types - * a ArrayList - */ - public final void setChangedCardTypes(final ArrayList types) { - this.changedCardTypes = types; - } - - /** - * - * TODO Write javadoc for this method. - * - * @return ArrayList - */ - public final ArrayList getChangedCardTypes() { - return this.changedCardTypes; - } - /** * * TODO Write javadoc for this method. @@ -3946,20 +3591,6 @@ public class Card extends GameEntity implements Comparable { } } - /** - *

- * clearAllTypes. - *

- * - * @return a {@link java.util.ArrayList} object. - */ - public final ArrayList clearAllTypes() { - final ArrayList originalTypes = new ArrayList(); - originalTypes.addAll(this.getCharacteristics().getType()); - this.getCharacteristics().getType().clear(); - return originalTypes; - } - // values that are printed on card /** *

@@ -4081,27 +3712,6 @@ public class Card extends GameEntity implements Comparable { this.baseDefenseString = s; } - /** - * - * TODO Write javadoc for this method. - * - * @param pt - * ArrayList - */ - public final void setNewPT(final ArrayList pt) { - this.newPT = pt; - } - - /** - * - * TODO Write javadoc for this method. - * - * @return ArrayList - */ - public final ArrayList getNewPT() { - return this.newPT; - } - /** * * TODO Write javadoc for this method. @@ -4728,15 +4338,6 @@ public class Card extends GameEntity implements Comparable { return this.getCharacteristics().getIntrinsicKeyword(); } - /** - *

- * clearIntrinsicKeyword. - *

- */ - public final void clearIntrinsicKeyword() { - this.getCharacteristics().getIntrinsicKeyword().clear(); - } - /** *

* Setter for the field intrinsicKeyword. @@ -4749,17 +4350,6 @@ public class Card extends GameEntity implements Comparable { this.getCharacteristics().setIntrinsicKeyword(new ArrayList(a)); } - /** - *

- * clearAllKeywords. - *

- */ - public final void clearAllKeywords() { - this.getCharacteristics().getIntrinsicKeyword().clear(); - this.extrinsicKeyword.clear(); - // Hidden keywords won't be displayed on the card - this.hiddenExtrinsicKeyword.clear(); - } /** *

@@ -4891,17 +4481,6 @@ public class Card extends GameEntity implements Comparable { } } - /** - *

- * getExtrinsicKeywordSize. - *

- * - * @return a int. - */ - public int getExtrinsicKeywordSize() { - return this.extrinsicKeyword.size(); - } - // Hidden Keywords will be returned without the indicator HIDDEN /** @@ -4978,7 +4557,7 @@ public class Card extends GameEntity implements Comparable { * a {@link java.lang.String} object. */ public final void addStaticAbilityString(final String s) { - if (s.trim().length() != 0) { + if (StringUtils.isNotBlank(s)) { this.getCharacteristics().getStaticAbilityStrings().add(s); } } @@ -5016,27 +4595,6 @@ public class Card extends GameEntity implements Comparable { } } - /** - * Adds the static ability. - * - * @param s - * the s - * - * @param state - * a {@link forge.CardCharacteristicName} object. - * - * @return a {@link forge.card.staticability.StaticAbility} object. - */ - public final StaticAbility addStaticAbility(final String s, final CardCharacteristicName state) { - - if (s.trim().length() == 0) { - return null; - } - final StaticAbility stAb = new StaticAbility(s, this); - CardCharacteristics stateCharacteristics = this.getState(state); - stateCharacteristics.getStaticAbilities().add(stAb); - return stAb; - } public final boolean isPermanent() { return !(this.isInstant() || this.isSorcery() || this.isImmutable()); @@ -5070,9 +4628,9 @@ public class Card extends GameEntity implements Comparable { private boolean typeContains(final String s) { - final Iterator it = this.getType().iterator(); + final Iterator it = this.getType().iterator(); while (it.hasNext()) { - if (it.next().toString().startsWith(s)) { + if (it.next().startsWith(s)) { return true; } } @@ -5539,25 +5097,6 @@ public class Card extends GameEntity implements Comparable { return false; } - /** - *

- * hasAnyKeyword. - *

- * - * @param keywords - * a {@link java.util.ArrayList} object. - * @return a boolean. - */ - public final boolean hasAnyKeyword(final ArrayList keywords) { - for (int i = 0; i < keywords.size(); i++) { - if (this.hasKeyword(keywords.get(i))) { - return true; - } - } - - return false; - } - // This counts the number of instances of a keyword a card has /** *

diff --git a/src/main/java/forge/card/ability/ai/ChangeZoneAi.java b/src/main/java/forge/card/ability/ai/ChangeZoneAi.java index 24638acd72b..ad4e05dfb87 100644 --- a/src/main/java/forge/card/ability/ai/ChangeZoneAi.java +++ b/src/main/java/forge/card/ability/ai/ChangeZoneAi.java @@ -1277,8 +1277,6 @@ public class ChangeZoneAi extends SpellAbilityAi { // to unenchant it, then clear out the commands final GameEntity oldEnchanted = c.getEnchanting(); c.removeEnchanting(oldEnchanted); - c.clearEnchantCommand(); - c.clearUnEnchantCommand(); } c.enchantEntity(attachedTo); } else { // When it should enter the battlefield attached to an illegal permanent it fails diff --git a/src/main/java/forge/card/ability/ai/RepeatEachAi.java b/src/main/java/forge/card/ability/ai/RepeatEachAi.java index 578482c3703..7cd24bd987d 100644 --- a/src/main/java/forge/card/ability/ai/RepeatEachAi.java +++ b/src/main/java/forge/card/ability/ai/RepeatEachAi.java @@ -48,7 +48,7 @@ public class RepeatEachAi extends SpellAbilityAi { perms = CardLists.filter(CardLists.getTargetableCards(perms, sa), new Predicate() { @Override public boolean apply(final Card c) { - return (c.sumAllCounters() > 0); + return c.hasCounters(); } }); if (perms.isEmpty()) { diff --git a/src/main/java/forge/card/ability/effects/AttachEffect.java b/src/main/java/forge/card/ability/effects/AttachEffect.java index 50f008f5efb..61ba96f6a91 100644 --- a/src/main/java/forge/card/ability/effects/AttachEffect.java +++ b/src/main/java/forge/card/ability/effects/AttachEffect.java @@ -127,8 +127,6 @@ public class AttachEffect extends SpellAbilityEffect { final GameEntity oldEnchanted = card.getEnchanting(); oldEnchanted.removeEnchantedBy(card); card.removeEnchanting(oldEnchanted); - card.clearEnchantCommand(); - card.clearUnEnchantCommand(); card.clearTriggers(); // not sure if cleartriggers is needed? } diff --git a/src/main/java/forge/card/ability/effects/ChangeZoneEffect.java b/src/main/java/forge/card/ability/effects/ChangeZoneEffect.java index 5a15b9b0c81..9c05ac43e4d 100644 --- a/src/main/java/forge/card/ability/effects/ChangeZoneEffect.java +++ b/src/main/java/forge/card/ability/effects/ChangeZoneEffect.java @@ -488,8 +488,6 @@ public class ChangeZoneEffect extends SpellAbilityEffect { // to unenchant it, then clear out the commands final GameEntity oldEnchanted = tgtC.getEnchanting(); tgtC.removeEnchanting(oldEnchanted); - tgtC.clearEnchantCommand(); - tgtC.clearUnEnchantCommand(); } tgtC.enchantEntity(attachedTo); } else { //Equipment @@ -780,8 +778,6 @@ public class ChangeZoneEffect extends SpellAbilityEffect { // to unenchant it, then clear out the commands final GameEntity oldEnchanted = c.getEnchanting(); c.removeEnchanting(oldEnchanted); - c.clearEnchantCommand(); - c.clearUnEnchantCommand(); } c.enchantEntity(attachedTo); } else { //Equipment @@ -819,8 +815,6 @@ public class ChangeZoneEffect extends SpellAbilityEffect { // to unenchant it, then clear out the commands final GameEntity oldEnchanted = c.getEnchanting(); c.removeEnchanting(oldEnchanted); - c.clearEnchantCommand(); - c.clearUnEnchantCommand(); } c.enchantEntity(attachedTo); } diff --git a/src/main/java/forge/card/cardfactory/CardFactoryCreatures.java b/src/main/java/forge/card/cardfactory/CardFactoryCreatures.java index f3404f35de6..5a33e1bdaa3 100644 --- a/src/main/java/forge/card/cardfactory/CardFactoryCreatures.java +++ b/src/main/java/forge/card/cardfactory/CardFactoryCreatures.java @@ -359,7 +359,7 @@ public class CardFactoryCreatures { @Override public void resolve() { int n = card.sumAllCounters(); - for (int i = 0; i < card.sumAllCounters(); i++) { + for (int i = 0; i < n; i++) { for(Card tok : this.makeToken()) { Singletons.getModel().getGame().getAction().moveToPlay(tok); } diff --git a/src/main/java/forge/card/cardfactory/CardFactoryUtil.java b/src/main/java/forge/card/cardfactory/CardFactoryUtil.java index d5198d5d643..bc8bf2ed3f6 100644 --- a/src/main/java/forge/card/cardfactory/CardFactoryUtil.java +++ b/src/main/java/forge/card/cardfactory/CardFactoryUtil.java @@ -3344,7 +3344,6 @@ public class CardFactoryUtil { if (n != -1) { final String parse = card.getKeyword().get(n).toString(); - card.setCanMorph(true); Map sVars = card.getSVars(); final String[] k = parse.split(":"); diff --git a/src/main/java/forge/game/GameAction.java b/src/main/java/forge/game/GameAction.java index 9c9329e3cd0..037c3eb5d6e 100644 --- a/src/main/java/forge/game/GameAction.java +++ b/src/main/java/forge/game/GameAction.java @@ -52,6 +52,7 @@ import forge.card.spellability.Target; import forge.card.staticability.StaticAbility; import forge.card.trigger.Trigger; import forge.card.trigger.TriggerType; +import forge.card.trigger.ZCTrigger; import forge.game.ai.ComputerUtil; import forge.game.ai.ComputerUtilCost; import forge.game.event.CardDestroyedEvent; @@ -1345,7 +1346,7 @@ public class GameAction { final Card newCard = this.moveToGraveyard(c); // Destroy needs to be called with Last Known Information - c.destroy(); + c.executeTrigger(ZCTrigger.DESTROY); // System.out.println("Card " + c.getName() + // " is getting sent to GY, and this turn it got damaged by: "); diff --git a/src/main/java/forge/game/ai/ComputerUtilCard.java b/src/main/java/forge/game/ai/ComputerUtilCard.java index fb037c5fb2d..7183e9a996e 100644 --- a/src/main/java/forge/game/ai/ComputerUtilCard.java +++ b/src/main/java/forge/game/ai/ComputerUtilCard.java @@ -882,7 +882,7 @@ public class ComputerUtilCard { List list = CardLists.filter(player.getCardsIn(ZoneType.Battlefield), new Predicate() { @Override public boolean apply(final Card c) { - for (final SpellAbility am : c.getAIPlayableMana()) { + for (final SpellAbility am : ComputerUtilMana.getAIPlayableMana(c)) { am.setActivatingPlayer(player); if (am.canPlay()) { return true; diff --git a/src/main/java/forge/game/ai/ComputerUtilMana.java b/src/main/java/forge/game/ai/ComputerUtilMana.java index bf8effe3422..b813e34f46d 100644 --- a/src/main/java/forge/game/ai/ComputerUtilMana.java +++ b/src/main/java/forge/game/ai/ComputerUtilMana.java @@ -477,7 +477,7 @@ public class ComputerUtilMana { @Override public boolean apply(final Card c) { if (checkPlayable) { - for (final SpellAbility am : c.getAIPlayableMana()) { + for (final SpellAbility am : getAIPlayableMana(c)) { am.setActivatingPlayer(ai); if (am.canPlay()) { return true; @@ -518,7 +518,7 @@ public class ComputerUtilMana { int usableManaAbilities = 0; boolean needsLimitedResources = false; boolean producesAnyColor = false; - final ArrayList manaAbilities = card.getAIPlayableMana(); + final ArrayList manaAbilities = getAIPlayableMana(card); for (final SpellAbility m : manaAbilities) { @@ -605,7 +605,7 @@ public class ComputerUtilMana { // Loop over all mana sources for (int i = 0; i < manaSources.size(); i++) { final Card sourceCard = manaSources.get(i); - final ArrayList manaAbilities = sourceCard.getAIPlayableMana(); + final ArrayList manaAbilities = getAIPlayableMana(sourceCard); // Loop over all mana abilities for a source for (final SpellAbility m : manaAbilities) { @@ -781,4 +781,33 @@ public class ComputerUtilMana { return choiceString.toString(); } + // Returns basic mana abilities plus "reflected mana" abilities + /** + *

+ * getAIPlayableMana. + *

+ * + * @return a {@link java.util.ArrayList} object. + */ + public static final ArrayList getAIPlayableMana(Card c) { + final ArrayList res = new ArrayList(); + for (final SpellAbility a : c.getManaAbility()) { + + // if a mana ability has a mana cost the AI will miscalculate + // if there is a parent ability the AI can't use it + final Cost cost = a.getPayCosts(); + if (!cost.hasNoManaCost() + || (a.getApi() != ApiType.Mana && a.getApi() != ApiType.ManaReflected)) { + continue; + } + + AbilityManaPart am = a.getManaPart(); + if (am.isBasic() && !res.contains(a)) { + res.add(a); + } + + } + return res; + } + } diff --git a/src/main/java/forge/game/zone/PlayerZoneBattlefield.java b/src/main/java/forge/game/zone/PlayerZoneBattlefield.java index 979ba80f1b7..23ce7ef4d91 100644 --- a/src/main/java/forge/game/zone/PlayerZoneBattlefield.java +++ b/src/main/java/forge/game/zone/PlayerZoneBattlefield.java @@ -34,6 +34,7 @@ import forge.card.mana.ManaCost; import forge.card.spellability.Ability; import forge.card.spellability.SpellAbility; import forge.card.staticability.StaticAbility; +import forge.card.trigger.ZCTrigger; import forge.game.GameActionUtil; import forge.game.player.Player; @@ -116,7 +117,7 @@ public class PlayerZoneBattlefield extends PlayerZone { if (this.trigger) { c.setSickness(true); // summoning sickness - c.comesIntoPlay(); + c.executeTrigger(ZCTrigger.ENTERFIELD); if (c.isLand()) { @@ -214,7 +215,7 @@ public class PlayerZoneBattlefield extends PlayerZone { }*/ if (this.leavesTrigger) { - c.leavesPlay(); + c.executeTrigger(ZCTrigger.LEAVEFIELD); } if (Singletons.getModel().getGame().getStaticEffects().getCardToEffectsList().containsKey(c.getName())) { diff --git a/src/main/java/forge/view/arcane/CardPanel.java b/src/main/java/forge/view/arcane/CardPanel.java index 8e049bd4ac3..d7540b3fc77 100644 --- a/src/main/java/forge/view/arcane/CardPanel.java +++ b/src/main/java/forge/view/arcane/CardPanel.java @@ -391,39 +391,39 @@ public class CardPanel extends JPanel implements CardContainer { return; } - final int counters = this.getCard().getNumberOfCounters(); - - if (counters == 1) { - CardFaceSymbols.drawSymbol("counters1", g, this.cardXOffset - 15, (this.cardYOffset + this.cardHeight) - - (this.cardHeight / 3) - 40); - } else if (counters == 2) { - CardFaceSymbols.drawSymbol("counters2", g, this.cardXOffset - 15, (this.cardYOffset + this.cardHeight) - - (this.cardHeight / 3) - 40); - } else if (counters == 3) { - CardFaceSymbols.drawSymbol("counters3", g, this.cardXOffset - 15, (this.cardYOffset + this.cardHeight) - - (this.cardHeight / 3) - 40); - } else if (counters > 3) { - CardFaceSymbols.drawSymbol("countersMulti", g, this.cardXOffset - 15, (this.cardYOffset + this.cardHeight) - - (this.cardHeight / 3) - 40); + int number = 0; + for (final Integer i : this.getCard().getCounters().values()) { + number += i.intValue(); } + final int counters = number; + final int yCounters = (this.cardYOffset + this.cardHeight) - (this.cardHeight / 3) - 40; + + if (counters == 1) { + CardFaceSymbols.drawSymbol("counters1", g, this.cardXOffset - 15, yCounters); + } else if (counters == 2) { + CardFaceSymbols.drawSymbol("counters2", g, this.cardXOffset - 15, yCounters); + } else if (counters == 3) { + CardFaceSymbols.drawSymbol("counters3", g, this.cardXOffset - 15, yCounters); + } else if (counters > 3) { + CardFaceSymbols.drawSymbol("countersMulti", g, this.cardXOffset - 15, yCounters); + } + + final int xSymbols = (this.cardXOffset + (this.cardWidth / 4)) - 16; + final int ySymbols = (this.cardYOffset + this.cardHeight) - (this.cardHeight / 8) - 16; // int yOff = (cardHeight/4) + 2; if (this.getCard().isAttacking()) { - CardFaceSymbols.drawSymbol("attack", g, (this.cardXOffset + (this.cardWidth / 4)) - 16, - (this.cardYOffset + this.cardHeight) - (this.cardHeight / 8) - 16); + CardFaceSymbols.drawSymbol("attack", g, xSymbols, ySymbols); } else if (this.getCard().isBlocking()) { - CardFaceSymbols.drawSymbol("defend", g, (this.cardXOffset + (this.cardWidth / 4)) - 16, - (this.cardYOffset + this.cardHeight) - (this.cardHeight / 8) - 16); + CardFaceSymbols.drawSymbol("defend", g, xSymbols, ySymbols); } if (this.getCard().isSick() && this.getCard().isInPlay()) { - CardFaceSymbols.drawSymbol("summonsick", g, (this.cardXOffset + (this.cardWidth / 2)) - 16, - (this.cardYOffset + this.cardHeight) - (this.cardHeight / 8) - 16); + CardFaceSymbols.drawSymbol("summonsick", g, xSymbols, ySymbols); } if (this.getCard().isPhasedOut()) { - CardFaceSymbols.drawSymbol("phasing", g, (this.cardXOffset + (this.cardWidth / 2)) - 16, - (this.cardYOffset + this.cardHeight) - (this.cardHeight / 8) - 16); + CardFaceSymbols.drawSymbol("phasing", g, xSymbols, ySymbols); } if (this.getCard().isUsedToPay()) {