mirror of
https://github.com/correl/mage.git
synced 2024-12-25 03:00:15 +00:00
Renamed mage.util.SpellTargetAddress to mage.util.TargetAddress and made it handle non-Spell Cards.
This commit is contained in:
parent
8e92291b9d
commit
feb35dda81
3 changed files with 51 additions and 27 deletions
|
@ -55,7 +55,7 @@ import mage.target.Target;
|
||||||
import mage.filter.predicate.mageobject.FromSetPredicate;
|
import mage.filter.predicate.mageobject.FromSetPredicate;
|
||||||
import mage.players.Player;
|
import mage.players.Player;
|
||||||
import mage.target.TargetPermanent;
|
import mage.target.TargetPermanent;
|
||||||
import mage.util.SpellTargetAddress;
|
import mage.util.TargetAddress;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author duncancmt
|
* @author duncancmt
|
||||||
|
@ -128,7 +128,7 @@ class InkTreaderNephilimTriggeredAbility extends TriggeredAbilityImpl {
|
||||||
if (spell != null) {
|
if (spell != null) {
|
||||||
boolean allTargetsInkTreaderNephilim = true;
|
boolean allTargetsInkTreaderNephilim = true;
|
||||||
boolean atLeastOneTargetsInkTreaderNephilim = false;
|
boolean atLeastOneTargetsInkTreaderNephilim = false;
|
||||||
for (SpellTargetAddress addr : SpellTargetAddress.walk(spell)) {
|
for (TargetAddress addr : TargetAddress.walk(spell)) {
|
||||||
Target targetInstance = addr.getTarget(spell);
|
Target targetInstance = addr.getTarget(spell);
|
||||||
for (UUID target : targetInstance.getTargets()) {
|
for (UUID target : targetInstance.getTargets()) {
|
||||||
allTargetsInkTreaderNephilim &= target.equals(sourceId);
|
allTargetsInkTreaderNephilim &= target.equals(sourceId);
|
||||||
|
@ -183,12 +183,12 @@ class InkTreaderNephilimEffect extends OneShotEffect {
|
||||||
continue; // copy only for other creatures
|
continue; // copy only for other creatures
|
||||||
}
|
}
|
||||||
boolean legal = true;
|
boolean legal = true;
|
||||||
for (SpellTargetAddress addr : SpellTargetAddress.walk(copy)) {
|
for (TargetAddress addr : TargetAddress.walk(copy)) {
|
||||||
Target targetInstance = addr.getTarget(copy);
|
Target targetInstance = addr.getTarget(copy);
|
||||||
legal &= targetInstance.canTarget(permanent.getId(), addr.getSpellAbility(copy), game);
|
legal &= targetInstance.canTarget(permanent.getId(), addr.getSpellAbility(copy), game);
|
||||||
}
|
}
|
||||||
if (legal) {
|
if (legal) {
|
||||||
for (SpellTargetAddress addr : SpellTargetAddress.walk(copy)) {
|
for (TargetAddress addr : TargetAddress.walk(copy)) {
|
||||||
Target targetInstance = addr.getTarget(copy);
|
Target targetInstance = addr.getTarget(copy);
|
||||||
int numTargets = targetInstance.getNumberOfTargets();
|
int numTargets = targetInstance.getNumberOfTargets();
|
||||||
targetInstance.clearChosen();
|
targetInstance.clearChosen();
|
||||||
|
|
|
@ -57,7 +57,7 @@ import mage.target.Target;
|
||||||
import java.util.UUID;
|
import java.util.UUID;
|
||||||
import mage.filter.predicate.mageobject.FromSetPredicate;
|
import mage.filter.predicate.mageobject.FromSetPredicate;
|
||||||
import mage.target.TargetPermanent;
|
import mage.target.TargetPermanent;
|
||||||
import mage.util.SpellTargetAddress;
|
import mage.util.TargetAddress;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author nantuko
|
* @author nantuko
|
||||||
|
@ -127,7 +127,7 @@ class PrecursorGolemCopyTriggeredAbility extends TriggeredAbilityImpl {
|
||||||
if (spell != null &&
|
if (spell != null &&
|
||||||
(spell.getCardType().contains(CardType.INSTANT) || spell.getCardType().contains(CardType.SORCERY))) {
|
(spell.getCardType().contains(CardType.INSTANT) || spell.getCardType().contains(CardType.SORCERY))) {
|
||||||
UUID targetGolem = null;
|
UUID targetGolem = null;
|
||||||
for (SpellTargetAddress addr : SpellTargetAddress.walk(spell)) {
|
for (TargetAddress addr : TargetAddress.walk(spell)) {
|
||||||
Target targetInstance = addr.getTarget(spell);
|
Target targetInstance = addr.getTarget(spell);
|
||||||
for (UUID target : targetInstance.getTargets()) {
|
for (UUID target : targetInstance.getTargets()) {
|
||||||
Permanent permanent = game.getPermanent(target);
|
Permanent permanent = game.getPermanent(target);
|
||||||
|
@ -186,7 +186,7 @@ class PrecursorGolemCopySpellEffect extends OneShotEffect {
|
||||||
continue; // copy only for other golems
|
continue; // copy only for other golems
|
||||||
}
|
}
|
||||||
boolean legal = true;
|
boolean legal = true;
|
||||||
for (SpellTargetAddress addr : SpellTargetAddress.walk(spell)) {
|
for (TargetAddress addr : TargetAddress.walk(spell)) {
|
||||||
Target target = addr.getTarget(spell);
|
Target target = addr.getTarget(spell);
|
||||||
if (!target.canTarget(permanent.getId(), game)) {
|
if (!target.canTarget(permanent.getId(), game)) {
|
||||||
legal = false;
|
legal = false;
|
||||||
|
@ -196,7 +196,7 @@ class PrecursorGolemCopySpellEffect extends OneShotEffect {
|
||||||
if (legal) {
|
if (legal) {
|
||||||
Spell copy = spell.copySpell();
|
Spell copy = spell.copySpell();
|
||||||
copy.setCopiedSpell(true);
|
copy.setCopiedSpell(true);
|
||||||
for (SpellTargetAddress addr : SpellTargetAddress.walk(copy)) {
|
for (TargetAddress addr : TargetAddress.walk(copy)) {
|
||||||
Target target = addr.getTarget(copy);
|
Target target = addr.getTarget(copy);
|
||||||
target.clearChosen();
|
target.clearChosen();
|
||||||
target.add(permanent.getId(), game);
|
target.add(permanent.getId(), game);
|
||||||
|
|
|
@ -32,6 +32,7 @@ import java.util.UUID;
|
||||||
import mage.abilities.Mode;
|
import mage.abilities.Mode;
|
||||||
import mage.abilities.Modes;
|
import mage.abilities.Modes;
|
||||||
import mage.abilities.SpellAbility;
|
import mage.abilities.SpellAbility;
|
||||||
|
import mage.cards.Card;
|
||||||
import mage.game.stack.Spell;
|
import mage.game.stack.Spell;
|
||||||
import mage.target.Target;
|
import mage.target.Target;
|
||||||
|
|
||||||
|
@ -39,30 +40,30 @@ import mage.target.Target;
|
||||||
/**
|
/**
|
||||||
* @author duncancmt
|
* @author duncancmt
|
||||||
*/
|
*/
|
||||||
public class SpellTargetAddress {
|
public class TargetAddress {
|
||||||
protected int spellAbilityIndex;
|
protected int spellAbilityIndex;
|
||||||
protected UUID mode;
|
protected UUID mode;
|
||||||
protected int targetIndex;
|
protected int targetIndex;
|
||||||
|
|
||||||
public SpellTargetAddress(int spellAbilityIndex, UUID mode, int targetIndex) {
|
public TargetAddress(int spellAbilityIndex, UUID mode, int targetIndex) {
|
||||||
this.spellAbilityIndex = spellAbilityIndex;
|
this.spellAbilityIndex = spellAbilityIndex;
|
||||||
this.mode = mode;
|
this.mode = mode;
|
||||||
this.targetIndex = targetIndex;
|
this.targetIndex = targetIndex;
|
||||||
}
|
}
|
||||||
|
|
||||||
protected static class SpellTargetAddressIterable implements Iterable<SpellTargetAddress> {
|
protected static class TargetAddressIterable implements Iterable<TargetAddress> {
|
||||||
protected final Spell spell;
|
protected final Card card;
|
||||||
|
|
||||||
public SpellTargetAddressIterable(Spell spell) {
|
public TargetAddressIterable(Card card) {
|
||||||
this.spell = spell;
|
this.card = card;
|
||||||
}
|
}
|
||||||
|
|
||||||
public Iterator<SpellTargetAddress> iterator() {
|
public Iterator<TargetAddress> iterator() {
|
||||||
return new SpellTargetAddressIterator(spell);
|
return new TargetAddressIterator(card);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
protected static class SpellTargetAddressIterator implements Iterator<SpellTargetAddress> {
|
protected static class TargetAddressIterator implements Iterator<TargetAddress> {
|
||||||
protected Iterator<SpellAbility> spellAbilityIterator;
|
protected Iterator<SpellAbility> spellAbilityIterator;
|
||||||
protected Integer lastSpellAbilityIndex = null;
|
protected Integer lastSpellAbilityIndex = null;
|
||||||
protected Iterator<UUID> modeIterator = null;
|
protected Iterator<UUID> modeIterator = null;
|
||||||
|
@ -71,17 +72,25 @@ public class SpellTargetAddress {
|
||||||
protected Iterator<Target> targetIterator = null;
|
protected Iterator<Target> targetIterator = null;
|
||||||
protected Integer lastTargetIndex = null;
|
protected Integer lastTargetIndex = null;
|
||||||
|
|
||||||
public SpellTargetAddressIterator(Spell spell) {
|
public TargetAddressIterator(Spell spell) {
|
||||||
this.spellAbilityIterator = spell.getSpellAbilities().iterator();
|
this.spellAbilityIterator = spell.getSpellAbilities().iterator();
|
||||||
calcNext();
|
calcNext();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public TargetAddressIterator(Card card) {
|
||||||
|
this.lastSpellAbilityIndex = 0;
|
||||||
|
this.spellAbilityIterator = null;
|
||||||
|
this.modes = card.getSpellAbility().getModes();
|
||||||
|
this.modeIterator = this.modes.getSelectedModes().iterator();
|
||||||
|
calcNext();
|
||||||
|
}
|
||||||
|
|
||||||
public boolean hasNext() {
|
public boolean hasNext() {
|
||||||
return lastTargetIndex != null;
|
return lastTargetIndex != null;
|
||||||
}
|
}
|
||||||
|
|
||||||
public SpellTargetAddress next() {
|
public TargetAddress next() {
|
||||||
SpellTargetAddress ret = new SpellTargetAddress(lastSpellAbilityIndex,
|
TargetAddress ret = new TargetAddress(lastSpellAbilityIndex,
|
||||||
lastMode,
|
lastMode,
|
||||||
lastTargetIndex);
|
lastTargetIndex);
|
||||||
calcNext();
|
calcNext();
|
||||||
|
@ -96,7 +105,7 @@ public class SpellTargetAddress {
|
||||||
protected void calcNext() {
|
protected void calcNext() {
|
||||||
if (targetIterator == null) {
|
if (targetIterator == null) {
|
||||||
if (modeIterator == null) {
|
if (modeIterator == null) {
|
||||||
if (spellAbilityIterator.hasNext()) {
|
if (spellAbilityIterator != null && spellAbilityIterator.hasNext()) {
|
||||||
if (lastSpellAbilityIndex == null) {
|
if (lastSpellAbilityIndex == null) {
|
||||||
lastSpellAbilityIndex = 0;
|
lastSpellAbilityIndex = 0;
|
||||||
} else {
|
} else {
|
||||||
|
@ -137,19 +146,34 @@ public class SpellTargetAddress {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public static Iterable<SpellTargetAddress> walk(Spell spell) {
|
public static Iterable<TargetAddress> walk(Card card) {
|
||||||
return new SpellTargetAddressIterable(spell);
|
return new TargetAddressIterable(card);
|
||||||
}
|
}
|
||||||
|
|
||||||
public Target getTarget(Spell spell) {
|
public Target getTarget(Spell spell) {
|
||||||
return spell.getSpellAbilities().get(spellAbilityIndex).getModes().get(mode).getTargets().get(targetIndex);
|
return getMode(spell).getTargets().get(targetIndex);
|
||||||
|
}
|
||||||
|
|
||||||
|
public Target getTarget(Card card) {
|
||||||
|
return getMode(card).getTargets().get(targetIndex);
|
||||||
}
|
}
|
||||||
|
|
||||||
public Mode getMode(Spell spell) {
|
public Mode getMode(Spell spell) {
|
||||||
return spell.getSpellAbilities().get(spellAbilityIndex).getModes().get(mode);
|
return getSpellAbility(spell).getModes().get(mode);
|
||||||
|
}
|
||||||
|
|
||||||
|
public Mode getMode(Card card) {
|
||||||
|
return getSpellAbility(card).getModes().get(mode);
|
||||||
}
|
}
|
||||||
|
|
||||||
public SpellAbility getSpellAbility(Spell spell) {
|
public SpellAbility getSpellAbility(Spell spell) {
|
||||||
return spell.getSpellAbilities().get(spellAbilityIndex);
|
return spell.getSpellAbilities().get(spellAbilityIndex);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public SpellAbility getSpellAbility(Card card) {
|
||||||
|
if (spellAbilityIndex > 0) {
|
||||||
|
throw new IndexOutOfBoundsException("SpellAbility index " + spellAbilityIndex + " is out of bounds.");
|
||||||
|
}
|
||||||
|
return card.getSpellAbility();
|
||||||
|
}
|
||||||
}
|
}
|
Loading…
Reference in a new issue