reworked methods for finding SpellAbility targets

This commit is contained in:
ArsenalNut
2012-12-03 08:09:00 +00:00
parent e91a7e6dfe
commit f9d3003d35
7 changed files with 149 additions and 134 deletions

View File

@@ -6,7 +6,7 @@ K:Equip 2
S:Mode$ Continuous | Affected$ Creature.EquippedBy | AddPower$ 2 | AddToughness$ 2 | AddKeyword$ Protection from red & Protection from white | Description$ Equipped creature gets +2/+2 and has protection from red and from white. S:Mode$ Continuous | Affected$ Creature.EquippedBy | AddPower$ 2 | AddToughness$ 2 | AddKeyword$ Protection from red & Protection from white | Description$ Equipped creature gets +2/+2 and has protection from red and from white.
T:Mode$ DamageDone | ValidSource$ Creature.EquippedBy | ValidTarget$ Player | CombatDamage$ True | Execute$ TrigDamage | TriggerZones$ Battlefield | TriggerDescription$ Whenever equipped creature deals combat damage to a player, CARDNAME deals damage to that player equal to the number of cards in his or her hand and you gain 1 life for each card in your hand. T:Mode$ DamageDone | ValidSource$ Creature.EquippedBy | ValidTarget$ Player | CombatDamage$ True | Execute$ TrigDamage | TriggerZones$ Battlefield | TriggerDescription$ Whenever equipped creature deals combat damage to a player, CARDNAME deals damage to that player equal to the number of cards in his or her hand and you gain 1 life for each card in your hand.
SVar:TrigDamage:AB$ DealDamage | Cost$ 0 | Defined$ TriggeredTarget | NumDmg$ X | References$ X | SubAbility$ DBGain SVar:TrigDamage:AB$ DealDamage | Cost$ 0 | Defined$ TriggeredTarget | NumDmg$ X | References$ X | SubAbility$ DBGain
SVar:X:TargetedPlayer$CardsInHand SVar:X:TriggeredTarget$CardsInHand
SVar:DBGain:DB$ GainLife | Defined$ You | LifeAmount$ Y | References$ Y SVar:DBGain:DB$ GainLife | Defined$ You | LifeAmount$ Y | References$ Y
SVar:Y:Count$CardsInYourHand SVar:Y:Count$CardsInYourHand
SVar:Rarity:Mythic SVar:Rarity:Mythic

View File

@@ -4,7 +4,7 @@ Types:Creature Human Shaman
Text:no text Text:no text
PT:1/1 PT:1/1
A:AB$ Pump | Cost$ 1 G T | ValidTgts$ Creature.YouCtrl | TgtPrompt$ Choose target creature you control | SubAbility$ TrackerFight | StackDescription$ None | SpellDescription$ Target creature you control fights another target creature. A:AB$ Pump | Cost$ 1 G T | ValidTgts$ Creature.YouCtrl | TgtPrompt$ Choose target creature you control | SubAbility$ TrackerFight | StackDescription$ None | SpellDescription$ Target creature you control fights another target creature.
SVar:TrackerFight:DB$ Fight | Defined$ Targeted | ValidTgts$ Creature | TargetUnique$ True | TgtPrompt$ Choose target creature to fight the first target SVar:TrackerFight:DB$ Fight | Defined$ ParentTarget | ValidTgts$ Creature | TargetUnique$ True | TgtPrompt$ Choose target creature to fight the first target
SVar:RemAIDeck:True SVar:RemAIDeck:True
SVar:Rarity:Rare SVar:Rarity:Rare
SVar:Picture:http://www.wizards.com/global/images/magic/general/ulvenwald_tracker.jpg SVar:Picture:http://www.wizards.com/global/images/magic/general/ulvenwald_tracker.jpg

View File

@@ -6315,13 +6315,11 @@ public class Card extends GameEntity implements Comparable<Card> {
} }
} else if (property.equals("TargetedPlayerCtrl")) { } else if (property.equals("TargetedPlayerCtrl")) {
for (final SpellAbility sa : source.getCharacteristics().getSpellAbility()) { for (final SpellAbility sa : source.getCharacteristics().getSpellAbility()) {
final SpellAbility parent = sa.getParentTargetingPlayer(); final SpellAbility saTargeting = sa.getSATargetingPlayer();
if (parent.getTarget() != null) { if (saTargeting != null) {
for (final Object o : parent.getTarget().getTargetPlayers()) { for (final Player p : saTargeting.getTarget().getTargetPlayers()) {
if (o instanceof Player) { if (!this.getController().equals(p)) {
if (!this.getController().equals(o)) { return false;
return false;
}
} }
} }
} }
@@ -6365,13 +6363,11 @@ public class Card extends GameEntity implements Comparable<Card> {
} }
} else if (property.equals("TargetedPlayerOwn")) { } else if (property.equals("TargetedPlayerOwn")) {
for (final SpellAbility sa : source.getCharacteristics().getSpellAbility()) { for (final SpellAbility sa : source.getCharacteristics().getSpellAbility()) {
final SpellAbility parent = sa.getParentTargetingPlayer(); final SpellAbility saTargeting = sa.getSATargetingPlayer();
if (parent.getTarget() != null) { if (saTargeting != null) {
for (final Object o : parent.getTarget().getTargetPlayers()) { for (final Player p : saTargeting.getTarget().getTargetPlayers()) {
if (o instanceof Player) { if (!this.getOwner().equals(p)) {
if (!this.getOwner().equals(o)) { return false;
return false;
}
} }
} }
} }

View File

@@ -588,25 +588,21 @@ public class AbilityFactory {
// Player attribute counting // Player attribute counting
if (calcX[0].startsWith("TargetedPlayer")) { if (calcX[0].startsWith("TargetedPlayer")) {
final ArrayList<Player> players = new ArrayList<Player>(); final ArrayList<Player> players = new ArrayList<Player>();
final SpellAbility saTargeting = (ability.getTarget() == null) ? ability.getParentTargetingPlayer() : ability; final SpellAbility saTargeting = ability.getSATargetingPlayer();
if (saTargeting.getTarget() != null) { if (null != saTargeting) {
players.addAll(saTargeting.getTarget().getTargetPlayers()); players.addAll(saTargeting.getTarget().getTargetPlayers());
} else {
players.addAll(AbilityFactory.getDefinedPlayers(card, saTargeting.getParam("Defined"), saTargeting));
} }
return CardFactoryUtil.playerXCount(players, calcX[1], card) * multiplier; return CardFactoryUtil.playerXCount(players, calcX[1], card) * multiplier;
} }
if (calcX[0].startsWith("TargetedObjects")) { if (calcX[0].startsWith("TargetedObjects")) {
final ArrayList<Object> objects = new ArrayList<Object>(); final ArrayList<Object> objects = new ArrayList<Object>();
final SpellAbility saTargeting = (ability.getTarget() == null) ? ability.getParentTargetingPlayer() : ability; // Make list of all targeted objects starting with the root SpellAbility
if (saTargeting.getTarget() != null) { SpellAbility loopSA = ability.getRootAbility();
SpellAbility loopSA = saTargeting; while (loopSA != null) {
while (loopSA != null) { if (loopSA.getTarget() != null) {
objects.addAll(saTargeting.getTarget().getTargets()); objects.addAll(loopSA.getTarget().getTargets());
loopSA = loopSA.getSubAbility();
} }
} else { loopSA = loopSA.getSubAbility();
objects.addAll(AbilityFactory.getDefinedObjects(card, saTargeting.getParam("Defined"), saTargeting));
} }
return CardFactoryUtil.objectXCount(objects, calcX[1], card) * multiplier; return CardFactoryUtil.objectXCount(objects, calcX[1], card) * multiplier;
} }
@@ -630,9 +626,9 @@ public class AbilityFactory {
} }
return CardFactoryUtil.playerXCount(players, calcX[1], card) * multiplier; return CardFactoryUtil.playerXCount(players, calcX[1], card) * multiplier;
} }
if (calcX[0].startsWith("TriggeredPlayer")) { if (calcX[0].startsWith("TriggeredPlayer") || calcX[0].startsWith("TriggeredTarget")) {
final SpellAbility root = ability.getRootAbility(); final SpellAbility root = ability.getRootAbility();
Object o = root.getTriggeringObject("Player"); Object o = root.getTriggeringObject(calcX[0].substring(9));
final ArrayList<Player> players = new ArrayList<Player>(); final ArrayList<Player> players = new ArrayList<Player>();
if (o instanceof Player) { if (o instanceof Player) {
players.add((Player) o); players.add((Player) o);
@@ -664,38 +660,7 @@ public class AbilityFactory {
} else if (calcX[0].startsWith("Revealed")) { } else if (calcX[0].startsWith("Revealed")) {
list = ability.getRootAbility().getPaidList("Revealed"); list = ability.getRootAbility().getPaidList("Revealed");
} else if (calcX[0].startsWith("Targeted")) { } else if (calcX[0].startsWith("Targeted")) {
final Target t = ability.getTarget(); list = ability.findTargetedCards();
if (null != t) {
final ArrayList<Object> all = t.getTargets();
list = new ArrayList<Card>();
if (!all.isEmpty() && (all.get(0) instanceof SpellAbility)) {
final SpellAbility saTargeting = ability.getParentTargetingSA();
// possible NPE on next line
final ArrayList<SpellAbility> sas = saTargeting.getTarget().getTargetSAs();
for (final SpellAbility sa : sas) {
list.add(sa.getSourceCard());
}
} else {
final SpellAbility saTargeting = ability.getParentTargetingCard();
if (null != saTargeting.getTarget()) {
list.addAll(saTargeting.getTarget().getTargetCards());
}
}
} else {
final SpellAbility parent = ability.getParentTargetingCard();
if (parent.getTarget() != null) {
final ArrayList<Object> all = parent.getTarget().getTargets();
if (!all.isEmpty() && (all.get(0) instanceof SpellAbility)) {
list = new ArrayList<Card>();
final ArrayList<SpellAbility> sas = parent.getTarget().getTargetSAs();
for (final SpellAbility sa : sas) {
list.add(sa.getSourceCard());
}
} else {
list = new ArrayList<Card>(parent.getTarget().getTargetCards());
}
}
}
} else if (calcX[0].startsWith("Triggered")) { } else if (calcX[0].startsWith("Triggered")) {
final SpellAbility root = ability.getRootAbility(); final SpellAbility root = ability.getRootAbility();
list = new ArrayList<Card>(); list = new ArrayList<Card>();
@@ -824,8 +789,14 @@ public class AbilityFactory {
} }
else if (defined.equals("Targeted")) { else if (defined.equals("Targeted")) {
final SpellAbility saTargeting = sa.getSATargetingCard();
if (saTargeting != null) {
cards.addAll(saTargeting.getTarget().getTargetCards());
}
} else if (defined.equals("ParentTarget")) {
final SpellAbility parent = sa.getParentTargetingCard(); final SpellAbility parent = sa.getParentTargetingCard();
if (parent.getTarget() != null && parent.getTarget().getTargetCards() != null) { if (parent != null) {
cards.addAll(parent.getTarget().getTargetCards()); cards.addAll(parent.getTarget().getTargetCards());
} }
@@ -949,9 +920,9 @@ public class AbilityFactory {
final String defined = (def == null) ? "You" : def; final String defined = (def == null) ? "You" : def;
if (defined.equals("Targeted")) { if (defined.equals("Targeted")) {
final SpellAbility parent = sa.getParentTargetingPlayer(); final SpellAbility saTargeting = sa.getSATargetingPlayer();
if (parent.getTarget() != null) { if (saTargeting != null) {
players.addAll(parent.getTarget().getTargetPlayers()); players.addAll(saTargeting.getTarget().getTargetPlayers());
} }
} else if (defined.equals("TargetedController")) { } else if (defined.equals("TargetedController")) {
final ArrayList<Card> list = AbilityFactory.getDefinedCards(card, "Targeted", sa); final ArrayList<Card> list = AbilityFactory.getDefinedCards(card, "Targeted", sa);
@@ -1161,9 +1132,9 @@ public class AbilityFactory {
if (defined.equals("Self")) { if (defined.equals("Self")) {
s = sa; s = sa;
} else if (defined.equals("Targeted")) { } else if (defined.equals("Targeted")) {
final SpellAbility parent = sa.getParentTargetingSA(); final SpellAbility saTargeting = sa.getSATargetingSA();
if (parent.getTarget() != null) { if (saTargeting != null) {
sas.addAll(parent.getTarget().getTargetSAs()); sas.addAll(saTargeting.getTarget().getTargetSAs());
} }
} else if (defined.startsWith("Triggered")) { } else if (defined.startsWith("Triggered")) {
final SpellAbility root = sa.getRootAbility(); final SpellAbility root = sa.getRootAbility();
@@ -1516,13 +1487,9 @@ public class AbilityFactory {
} else if (type.startsWith("Targeted")) { } else if (type.startsWith("Targeted")) {
source = null; source = null;
final SpellAbility parent = sa.getParentTargetingCard(); ArrayList<Card> tgts = sa.findTargetedCards();
if (parent.getTarget() != null) { if (!tgts.isEmpty()) {
if (!parent.getTarget().getTargetCards().isEmpty()) { source = tgts.get(0);
source = parent.getTarget().getTargetCards().get(0);
} else if (!parent.getTarget().getTargetSAs().isEmpty()) {
source = parent.getTarget().getTargetSAs().get(0).getSourceCard();
}
} }
if (source == null) { if (source == null) {
return new ArrayList<Card>(); return new ArrayList<Card>();

View File

@@ -49,40 +49,7 @@ public class StoreSVarEffect extends SpellEffect {
value = CardFactoryUtil.xCount(source, "SVar$" + expr); value = CardFactoryUtil.xCount(source, "SVar$" + expr);
} }
else if (type.equals("Targeted")) { else if (type.equals("Targeted")) {
List<Card> list = new ArrayList<Card>(); value = CardFactoryUtil.handlePaid(sa.findTargetedCards(), expr, source);
final Target t = sa.getTarget();
if (null != t) {
final ArrayList<Object> all = t.getTargets();
list = new ArrayList<Card>();
if (!all.isEmpty() && (all.get(0) instanceof SpellAbility)) {
final SpellAbility saTargeting = sa.getParentTargetingSA();
// possible NPE on next line
final ArrayList<SpellAbility> sas = saTargeting.getTarget().getTargetSAs();
for (final SpellAbility tgtsa : sas) {
list.add(tgtsa.getSourceCard());
}
} else {
final SpellAbility saTargeting = sa.getParentTargetingCard();
if (null != saTargeting.getTarget()) {
list.addAll(saTargeting.getTarget().getTargetCards());
}
}
} else {
final SpellAbility parent = sa.getParentTargetingCard();
if (parent.getTarget() != null) {
final ArrayList<Object> all = parent.getTarget().getTargets();
if (!all.isEmpty() && (all.get(0) instanceof SpellAbility)) {
list = new ArrayList<Card>();
final ArrayList<SpellAbility> sas = parent.getTarget().getTargetSAs();
for (final SpellAbility tgtsa : sas) {
list.add(tgtsa.getSourceCard());
}
} else {
list = new ArrayList<Card>(parent.getTarget().getTargetCards());
}
}
}
value = CardFactoryUtil.handlePaid(list, expr, source);
} }
//TODO For other types call a different function //TODO For other types call a different function

View File

@@ -2165,12 +2165,10 @@ public class CardFactoryUtil {
// Count$TargetedLifeTotal (targeted player's life total) // Count$TargetedLifeTotal (targeted player's life total)
if (sq[0].contains("TargetedLifeTotal")) { if (sq[0].contains("TargetedLifeTotal")) {
for (final SpellAbility sa : c.getCharacteristics().getSpellAbility()) { for (final SpellAbility sa : c.getCharacteristics().getSpellAbility()) {
final SpellAbility parent = sa.getParentTargetingPlayer(); final SpellAbility saTargeting = sa.getSATargetingPlayer();
if (parent.getTarget() != null) { if (saTargeting != null) {
for (final Object tgtP : parent.getTarget().getTargetPlayers()) { for (final Player tgtP : saTargeting.getTarget().getTargetPlayers()) {
if (tgtP instanceof Player) { return CardFactoryUtil.doXMath(tgtP.getLife(), m, c);
return CardFactoryUtil.doXMath(((Player) tgtP).getLife(), m, c);
}
} }
} }
} }
@@ -2608,14 +2606,10 @@ public class CardFactoryUtil {
// Count$InTargetedHand (targeted player's cards in hand) // Count$InTargetedHand (targeted player's cards in hand)
if (sq[0].contains("InTargetedHand")) { if (sq[0].contains("InTargetedHand")) {
for (final SpellAbility sa : c.getCharacteristics().getSpellAbility()) { for (final SpellAbility sa : c.getCharacteristics().getSpellAbility()) {
final SpellAbility parent = sa.getParentTargetingPlayer(); final SpellAbility saTargeting = sa.getSATargetingPlayer();
if (parent != null) { if (saTargeting != null) {
if (parent.getTarget() != null) { for (final Player tgtP : saTargeting.getTarget().getTargetPlayers()) {
for (final Object tgtP : parent.getTarget().getTargetPlayers()) { someCards.addAll(tgtP.getCardsIn(ZoneType.Hand));
if (tgtP instanceof Player) {
someCards.addAll(((Player) tgtP).getCardsIn(ZoneType.Hand));
}
}
} }
} }
} }

View File

@@ -1695,36 +1695,110 @@ public abstract class SpellAbility implements ISpellAbility {
/** /**
* <p> * <p>
* findParentsTargetedCard. * findTargetCards.
* </p>
*
* @return a {@link forge.card.spellability.SpellAbility} object.
*/
public ArrayList<Card> findTargetedCards() {
ArrayList<Card> list = new ArrayList<Card>();
Target tgt = this.getTarget();
// First search for targeted cards associated with current ability
if (tgt != null && tgt.getTargetCards() != null && !tgt.getTargetCards().isEmpty()) {
return tgt.getTargetCards();
}
// Next search for source cards of targeted SAs associated with current ability
else if (tgt != null && tgt.getTargetSAs() != null && !tgt.getTargetSAs().isEmpty()) {
for (final SpellAbility ability : tgt.getTargetSAs()) {
list.add(ability.getSourceCard());
}
return list;
}
// Lastly Search parent SAs for target cards
else {
// Check for a parent that targets a card
SpellAbility parent = this.getParentTargetingCard();
if (null != parent) {
return parent.getTarget().getTargetCards();
}
// Check for a parent that targets an SA
parent = this.getParentTargetingSA();
if (null != parent) {
for (final SpellAbility ability : parent.getTarget().getTargetSAs()) {
list.add(ability.getSourceCard());
}
}
}
return list;
}
/**
* <p>
* getSATargetingCard.
* </p>
*
* @return a {@link forge.card.spellability.SpellAbility} object.
*/
public SpellAbility getSATargetingCard() {
Target tgt = this.getTarget();
if (tgt != null && tgt.getTargetCards() != null && !tgt.getTargetCards().isEmpty()) {
return this;
}
else {
return this.getParentTargetingCard();
}
}
/**
* <p>
* getParentTargetingCard.
* </p> * </p>
* *
* @return a {@link forge.card.spellability.SpellAbility} object. * @return a {@link forge.card.spellability.SpellAbility} object.
*/ */
public SpellAbility getParentTargetingCard() { public SpellAbility getParentTargetingCard() {
SpellAbility parent = this; SpellAbility parent = this.getParent();
while (parent.getParent() != null) {
while (parent != null) {
Target tgt = parent.getTarget(); Target tgt = parent.getTarget();
if (tgt != null && tgt.getTargetCards() != null && !tgt.getTargetCards().isEmpty()) { if (tgt != null && tgt.getTargetCards() != null && !tgt.getTargetCards().isEmpty()) {
break; break;
} }
parent = parent.getParent(); parent = parent.getParent();
} }
return parent; return parent;
} }
/** /**
* <p> * <p>
* findParentsTargetedSpellAbility. * getSATargetingSA.
* </p>
*
* @return a {@link forge.card.spellability.SpellAbility} object.
*/
public SpellAbility getSATargetingSA() {
Target tgt = this.getTarget();
if (tgt != null && tgt.getTargetSAs() != null && !tgt.getTargetSAs().isEmpty()) {
return this;
}
else {
return this.getParentTargetingSA();
}
}
/**
* <p>
* getParentTargetingSA.
* </p> * </p>
* *
* @return a {@link forge.card.spellability.SpellAbility} object. * @return a {@link forge.card.spellability.SpellAbility} object.
*/ */
public SpellAbility getParentTargetingSA() { public SpellAbility getParentTargetingSA() {
SpellAbility parent = this; SpellAbility parent = this.getParent();
while (parent.getParent() != null) {
while (parent != null) {
Target tgt = parent.getTarget(); Target tgt = parent.getTarget();
if (tgt != null && tgt.getTargetSAs() != null && !tgt.getTargetSAs().isEmpty()) { if (tgt != null && tgt.getTargetSAs() != null && !tgt.getTargetSAs().isEmpty()) {
@@ -1736,6 +1810,23 @@ public abstract class SpellAbility implements ISpellAbility {
return parent; return parent;
} }
/**
* <p>
* getSATargetingPlayer.
* </p>
*
* @return a {@link forge.card.spellability.SpellAbility} object.
*/
public SpellAbility getSATargetingPlayer() {
Target tgt = this.getTarget();
if (tgt != null && tgt.getTargetPlayers() != null && !tgt.getTargetPlayers().isEmpty()) {
return this;
}
else {
return this.getParentTargetingPlayer();
}
}
/** /**
* <p> * <p>
* findParentsTargetedPlayer. * findParentsTargetedPlayer.
@@ -1744,8 +1835,8 @@ public abstract class SpellAbility implements ISpellAbility {
* @return a {@link forge.card.spellability.SpellAbility} object. * @return a {@link forge.card.spellability.SpellAbility} object.
*/ */
public SpellAbility getParentTargetingPlayer() { public SpellAbility getParentTargetingPlayer() {
SpellAbility parent = this; SpellAbility parent = this.getParent();
while (parent.getParent() != null) { while (parent != null) {
Target tgt = parent.getTarget(); Target tgt = parent.getTarget();
if (tgt != null && tgt.getTargetPlayers() != null && !tgt.getTargetPlayers().isEmpty()) { if (tgt != null && tgt.getTargetPlayers() != null && !tgt.getTargetPlayers().isEmpty()) {