mirror of
https://github.com/Card-Forge/forge.git
synced 2025-11-17 03:08:02 +00:00
'Target' class no longer uses card in ctor and fields
This commit is contained in:
@@ -124,7 +124,7 @@ public final class AbilityFactory {
|
|||||||
public static final SpellAbility getAbility(AbilityRecordType type, ApiType api, Map<String, String> mapParams, Cost abCost, Card hostCard) {
|
public static final SpellAbility getAbility(AbilityRecordType type, ApiType api, Map<String, String> mapParams, Cost abCost, Card hostCard) {
|
||||||
|
|
||||||
|
|
||||||
Target abTgt = mapParams.containsKey("ValidTgts") ? readTarget(hostCard, mapParams) : null;
|
Target abTgt = mapParams.containsKey("ValidTgts") ? readTarget(mapParams) : null;
|
||||||
|
|
||||||
if (api == ApiType.CopySpellAbility || api == ApiType.Counter || api == ApiType.ChangeTargets) {
|
if (api == ApiType.CopySpellAbility || api == ApiType.Counter || api == ApiType.ChangeTargets) {
|
||||||
// Since all "CopySpell" ABs copy things on the Stack no need for it to be everywhere
|
// Since all "CopySpell" ABs copy things on the Stack no need for it to be everywhere
|
||||||
@@ -204,20 +204,17 @@ public final class AbilityFactory {
|
|||||||
return spellAbility;
|
return spellAbility;
|
||||||
}
|
}
|
||||||
|
|
||||||
private static final Target readTarget(Card hostC, Map<String, String> mapParams) {
|
private static final Target readTarget(Map<String, String> mapParams) {
|
||||||
final String min = mapParams.containsKey("TargetMin") ? mapParams.get("TargetMin") : "1";
|
final String min = mapParams.containsKey("TargetMin") ? mapParams.get("TargetMin") : "1";
|
||||||
final String max = mapParams.containsKey("TargetMax") ? mapParams.get("TargetMax") : "1";
|
final String max = mapParams.containsKey("TargetMax") ? mapParams.get("TargetMax") : "1";
|
||||||
|
|
||||||
|
|
||||||
// TgtPrompt now optional
|
// TgtPrompt now optional
|
||||||
final StringBuilder sb = new StringBuilder();
|
final StringBuilder sb = new StringBuilder();
|
||||||
if (hostC != null) {
|
|
||||||
sb.append(hostC + " - ");
|
|
||||||
}
|
|
||||||
final String prompt = mapParams.containsKey("TgtPrompt") ? mapParams.get("TgtPrompt") : "Select target " + mapParams.get("ValidTgts");
|
final String prompt = mapParams.containsKey("TgtPrompt") ? mapParams.get("TgtPrompt") : "Select target " + mapParams.get("ValidTgts");
|
||||||
sb.append(prompt);
|
sb.append(prompt);
|
||||||
|
|
||||||
Target abTgt = new Target(hostC, sb.toString(), mapParams.get("ValidTgts").split(","), min, max);
|
Target abTgt = new Target(prompt, mapParams.get("ValidTgts").split(","), min, max);
|
||||||
|
|
||||||
if (mapParams.containsKey("TgtZone")) { // if Targeting
|
if (mapParams.containsKey("TgtZone")) { // if Targeting
|
||||||
// something
|
// something
|
||||||
@@ -264,7 +261,7 @@ public final class AbilityFactory {
|
|||||||
abTgt.setDifferentControllers(true);
|
abTgt.setDifferentControllers(true);
|
||||||
}
|
}
|
||||||
if (mapParams.containsKey("DividedAsYouChoose")) {
|
if (mapParams.containsKey("DividedAsYouChoose")) {
|
||||||
abTgt.calculateStillToDivide(mapParams.get("DividedAsYouChoose"), hostC, null);
|
abTgt.calculateStillToDivide(mapParams.get("DividedAsYouChoose"), null, null);
|
||||||
abTgt.setDividedAsYouChoose(true);
|
abTgt.setDividedAsYouChoose(true);
|
||||||
}
|
}
|
||||||
if (mapParams.containsKey("TargetsAtRandom")) {
|
if (mapParams.containsKey("TargetsAtRandom")) {
|
||||||
|
|||||||
@@ -189,13 +189,12 @@ public class CardFactory {
|
|||||||
//remove all costs
|
//remove all costs
|
||||||
copySA.setPayCosts(new Cost("", sa.isAbility()));
|
copySA.setPayCosts(new Cost("", sa.isAbility()));
|
||||||
if (definedTarget != null) {
|
if (definedTarget != null) {
|
||||||
Target target = new Target(c, null, "");
|
Target target = new Target(null, "");
|
||||||
target.setDefinedTarget(definedTarget);
|
target.setDefinedTarget(definedTarget);
|
||||||
copySA.setTarget(target);
|
copySA.setTarget(target);
|
||||||
}
|
}
|
||||||
else if (sa.getTarget() != null) {
|
else if (sa.getTarget() != null) {
|
||||||
Target target = new Target(sa.getTarget());
|
Target target = new Target(sa.getTarget());
|
||||||
target.setSourceCard(c);
|
|
||||||
copySA.setTarget(target);
|
copySA.setTarget(target);
|
||||||
}
|
}
|
||||||
copySA.setActivatingPlayer(controller);
|
copySA.setActivatingPlayer(controller);
|
||||||
|
|||||||
@@ -132,7 +132,7 @@ public class CardFactoryCreatures {
|
|||||||
|
|
||||||
private static void getCard_MasterOfTheWildHunt(final Card card) {
|
private static void getCard_MasterOfTheWildHunt(final Card card) {
|
||||||
final Cost abCost = new Cost("T", true);
|
final Cost abCost = new Cost("T", true);
|
||||||
final Target abTgt = new Target(card, "Target a creature to Hunt", "Creature".split(","));
|
final Target abTgt = new Target("Target a creature to Hunt", new String[]{"Creature"});
|
||||||
class MasterOfTheWildHuntAbility extends AbilityActivated {
|
class MasterOfTheWildHuntAbility extends AbilityActivated {
|
||||||
public MasterOfTheWildHuntAbility(final Card ca, final Cost co, final Target t) {
|
public MasterOfTheWildHuntAbility(final Card ca, final Cost co, final Target t) {
|
||||||
super(ca, co, t);
|
super(ca, co, t);
|
||||||
|
|||||||
@@ -79,10 +79,6 @@ public abstract class SpellAbility implements ISpellAbility, ITargetable {
|
|||||||
private boolean offering = false;
|
private boolean offering = false;
|
||||||
private boolean morphup = false;
|
private boolean morphup = false;
|
||||||
|
|
||||||
private Card targetCard;
|
|
||||||
/** The chosen target. */
|
|
||||||
private Target chosenTarget = null;
|
|
||||||
|
|
||||||
/** The pay costs. */
|
/** The pay costs. */
|
||||||
private Cost payCosts = null;
|
private Cost payCosts = null;
|
||||||
private SpellAbilityRestriction restrictions = new SpellAbilityRestriction();
|
private SpellAbilityRestriction restrictions = new SpellAbilityRestriction();
|
||||||
@@ -1357,6 +1353,10 @@ public abstract class SpellAbility implements ISpellAbility, ITargetable {
|
|||||||
//
|
//
|
||||||
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
|
private Card targetCard;
|
||||||
|
/** The chosen target. */
|
||||||
|
private Target chosenTarget = null;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* <p>
|
* <p>
|
||||||
* Getter for the field <code>targetCard</code>.
|
* Getter for the field <code>targetCard</code>.
|
||||||
|
|||||||
@@ -22,6 +22,8 @@ import java.util.Arrays;
|
|||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
|
import org.apache.commons.lang.StringUtils;
|
||||||
|
|
||||||
import forge.Card;
|
import forge.Card;
|
||||||
import forge.ITargetable;
|
import forge.ITargetable;
|
||||||
import forge.card.CardType;
|
import forge.card.CardType;
|
||||||
@@ -43,7 +45,7 @@ public class Target {
|
|||||||
// Targeting restrictions (Creature, Min/Maxm etc) which are true for this
|
// Targeting restrictions (Creature, Min/Maxm etc) which are true for this
|
||||||
|
|
||||||
// Target Choices (which is specific for the StackInstance)
|
// Target Choices (which is specific for the StackInstance)
|
||||||
private Card srcCard;
|
|
||||||
// What this Object is restricted to targeting
|
// What this Object is restricted to targeting
|
||||||
private boolean tgtValid = false;
|
private boolean tgtValid = false;
|
||||||
private String[] validTgts;
|
private String[] validTgts;
|
||||||
@@ -94,7 +96,6 @@ public class Target {
|
|||||||
*/
|
*/
|
||||||
public Target(final Target target) {
|
public Target(final Target target) {
|
||||||
this.tgtValid = true;
|
this.tgtValid = true;
|
||||||
this.srcCard = target.getSourceCard();
|
|
||||||
this.vtSelection = target.getVTSelection();
|
this.vtSelection = target.getVTSelection();
|
||||||
this.validTgts = target.getValidTgts();
|
this.validTgts = target.getValidTgts();
|
||||||
this.minTargets = target.getMinTargets();
|
this.minTargets = target.getMinTargets();
|
||||||
@@ -129,8 +130,8 @@ public class Target {
|
|||||||
* @param valid
|
* @param valid
|
||||||
* an array of {@link java.lang.String} objects.
|
* an array of {@link java.lang.String} objects.
|
||||||
*/
|
*/
|
||||||
public Target(final Card src, final String select, final String[] valid) {
|
public Target(final String select, final String[] valid) {
|
||||||
this(src, select, valid, "1", "1");
|
this(select, valid, "1", "1");
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -145,8 +146,8 @@ public class Target {
|
|||||||
* @param valid
|
* @param valid
|
||||||
* a {@link java.lang.String} object.
|
* a {@link java.lang.String} object.
|
||||||
*/
|
*/
|
||||||
public Target(final Card src, final String select, final String valid) {
|
public Target(final String select, final String valid) {
|
||||||
this(src, select, valid.split(","), "1", "1");
|
this(select, valid.split(","), "1", "1");
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -165,8 +166,7 @@ public class Target {
|
|||||||
* @param max
|
* @param max
|
||||||
* a {@link java.lang.String} object.
|
* a {@link java.lang.String} object.
|
||||||
*/
|
*/
|
||||||
public Target(final Card src, final String select, final String[] valid, final String min, final String max) {
|
public Target(final String select, final String[] valid, final String min, final String max) {
|
||||||
this.srcCard = src;
|
|
||||||
this.tgtValid = true;
|
this.tgtValid = true;
|
||||||
this.vtSelection = select;
|
this.vtSelection = select;
|
||||||
this.validTgts = valid;
|
this.validTgts = valid;
|
||||||
@@ -175,29 +175,6 @@ public class Target {
|
|||||||
this.maxTargets = max;
|
this.maxTargets = max;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* <p>
|
|
||||||
* getSourceCard.
|
|
||||||
* </p>
|
|
||||||
*
|
|
||||||
* @return a Card object.
|
|
||||||
*/
|
|
||||||
public final Card getSourceCard() {
|
|
||||||
return this.srcCard;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* <p>
|
|
||||||
* setSourceCard.
|
|
||||||
* </p>
|
|
||||||
*
|
|
||||||
* @param source
|
|
||||||
* a Card object.
|
|
||||||
*/
|
|
||||||
public final void setSourceCard(final Card source) {
|
|
||||||
this.srcCard = source;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* <p>
|
* <p>
|
||||||
* getTargetChoices.
|
* getTargetChoices.
|
||||||
@@ -673,12 +650,13 @@ public class Target {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
final Card srcCard = sa.getSourceCard(); // should there be OrginalHost at any moment?
|
||||||
if (this.tgtZone.contains(ZoneType.Stack)) {
|
if (this.tgtZone.contains(ZoneType.Stack)) {
|
||||||
// Stack Zone targets are considered later
|
// Stack Zone targets are considered later
|
||||||
return true;
|
return true;
|
||||||
} else {
|
} else {
|
||||||
for (final Card c : game.getCardsIn(this.tgtZone)) {
|
for (final Card c : game.getCardsIn(this.tgtZone)) {
|
||||||
if (!c.isValid(this.validTgts, this.srcCard.getController(), this.srcCard)) {
|
if (!c.isValid(this.validTgts, srcCard.getController(), srcCard)) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
if (isTargeted && !c.canBeTargetedBy(sa)) {
|
if (isTargeted && !c.canBeTargetedBy(sa)) {
|
||||||
@@ -729,9 +707,10 @@ public class Target {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
final Card srcCard = sa.getSourceCard(); // should there be OrginalHost at any moment?
|
||||||
if (this.tgtZone.contains(ZoneType.Stack)) {
|
if (this.tgtZone.contains(ZoneType.Stack)) {
|
||||||
for (final Card c : game.getStackZone().getCards()) {
|
for (final Card c : game.getStackZone().getCards()) {
|
||||||
boolean isValidTarget = c.isValid(this.validTgts, this.srcCard.getController(), this.srcCard);
|
boolean isValidTarget = c.isValid(this.validTgts, srcCard.getController(), srcCard);
|
||||||
boolean canTarget = (!isTargeted || c.canBeTargetedBy(sa));
|
boolean canTarget = (!isTargeted || c.canBeTargetedBy(sa));
|
||||||
boolean isAlreadyTargeted = this.getTargetCards().contains(c);
|
boolean isAlreadyTargeted = this.getTargetCards().contains(c);
|
||||||
if (isValidTarget && canTarget && !isAlreadyTargeted) {
|
if (isValidTarget && canTarget && !isAlreadyTargeted) {
|
||||||
@@ -740,7 +719,7 @@ public class Target {
|
|||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
for (final Card c : game.getCardsIn(this.tgtZone)) {
|
for (final Card c : game.getCardsIn(this.tgtZone)) {
|
||||||
boolean isValidTarget = c.isValid(this.validTgts, this.srcCard.getController(), this.srcCard);
|
boolean isValidTarget = c.isValid(this.validTgts, srcCard.getController(), srcCard);
|
||||||
boolean canTarget = (!isTargeted || c.canBeTargetedBy(sa));
|
boolean canTarget = (!isTargeted || c.canBeTargetedBy(sa));
|
||||||
boolean isAlreadyTargeted = this.getTargetCards().contains(c);
|
boolean isAlreadyTargeted = this.getTargetCards().contains(c);
|
||||||
if (isValidTarget && canTarget && !isAlreadyTargeted) {
|
if (isValidTarget && canTarget && !isAlreadyTargeted) {
|
||||||
@@ -972,8 +951,10 @@ public class Target {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (toDistribute.matches("[0-9][0-9]")) {
|
if (StringUtils.isNumeric(toDistribute)) {
|
||||||
this.setStillToDivide(Integer.parseInt(toDistribute));
|
this.setStillToDivide(Integer.parseInt(toDistribute));
|
||||||
|
} else if ( source == null ) {
|
||||||
|
return; // such calls come from AbilityFactory.readTarget - at this moment we don't yet know X or any other variables
|
||||||
} else if (source.getSVar(toDistribute).equals("xPaid")) {
|
} else if (source.getSVar(toDistribute).equals("xPaid")) {
|
||||||
this.setStillToDivide(source.getXManaCostPaid());
|
this.setStillToDivide(source.getXManaCostPaid());
|
||||||
} else {
|
} else {
|
||||||
|
|||||||
@@ -147,9 +147,9 @@ public class TargetSelection {
|
|||||||
if (canTgtStack) {
|
if (canTgtStack) {
|
||||||
// Since getTargetableCards doesn't have additional checks if one of the Zones is stack
|
// Since getTargetableCards doesn't have additional checks if one of the Zones is stack
|
||||||
// Remove the activating card from targeting itself if its on the Stack
|
// Remove the activating card from targeting itself if its on the Stack
|
||||||
Card activatingCard = tgt.getSourceCard();
|
Card activatingCard = ability.getSourceCard();
|
||||||
if (activatingCard.isInZone(ZoneType.Stack)) {
|
if (activatingCard.isInZone(ZoneType.Stack)) {
|
||||||
choices.remove(tgt.getSourceCard());
|
choices.remove(ability.getSourceCard());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
List<ITargetable> targetedObjects = this.ability.getUniqueTargets();
|
List<ITargetable> targetedObjects = this.ability.getUniqueTargets();
|
||||||
|
|||||||
@@ -1302,7 +1302,7 @@ public class Player extends GameEntity implements Comparable<Player> {
|
|||||||
if (chainsList != null && (numDrawnThisDrawStep > 0 || !game.getPhaseHandler().is(PhaseType.DRAW))) {
|
if (chainsList != null && (numDrawnThisDrawStep > 0 || !game.getPhaseHandler().is(PhaseType.DRAW))) {
|
||||||
for(Card c : chainsList) {
|
for(Card c : chainsList) {
|
||||||
// I have to target this player - don't know how to do it.
|
// I have to target this player - don't know how to do it.
|
||||||
Target target = new Target(c, null, "");
|
Target target = new Target(null, "");
|
||||||
target.addTarget(this);
|
target.addTarget(this);
|
||||||
|
|
||||||
if (getCardsIn(ZoneType.Hand).isEmpty()) {
|
if (getCardsIn(ZoneType.Hand).isEmpty()) {
|
||||||
|
|||||||
Reference in New Issue
Block a user