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) {
|
||||
|
||||
|
||||
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) {
|
||||
// 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;
|
||||
}
|
||||
|
||||
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 max = mapParams.containsKey("TargetMax") ? mapParams.get("TargetMax") : "1";
|
||||
|
||||
|
||||
// TgtPrompt now optional
|
||||
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");
|
||||
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
|
||||
// something
|
||||
@@ -264,7 +261,7 @@ public final class AbilityFactory {
|
||||
abTgt.setDifferentControllers(true);
|
||||
}
|
||||
if (mapParams.containsKey("DividedAsYouChoose")) {
|
||||
abTgt.calculateStillToDivide(mapParams.get("DividedAsYouChoose"), hostC, null);
|
||||
abTgt.calculateStillToDivide(mapParams.get("DividedAsYouChoose"), null, null);
|
||||
abTgt.setDividedAsYouChoose(true);
|
||||
}
|
||||
if (mapParams.containsKey("TargetsAtRandom")) {
|
||||
|
||||
@@ -189,13 +189,12 @@ public class CardFactory {
|
||||
//remove all costs
|
||||
copySA.setPayCosts(new Cost("", sa.isAbility()));
|
||||
if (definedTarget != null) {
|
||||
Target target = new Target(c, null, "");
|
||||
Target target = new Target(null, "");
|
||||
target.setDefinedTarget(definedTarget);
|
||||
copySA.setTarget(target);
|
||||
}
|
||||
else if (sa.getTarget() != null) {
|
||||
Target target = new Target(sa.getTarget());
|
||||
target.setSourceCard(c);
|
||||
copySA.setTarget(target);
|
||||
}
|
||||
copySA.setActivatingPlayer(controller);
|
||||
|
||||
@@ -132,7 +132,7 @@ public class CardFactoryCreatures {
|
||||
|
||||
private static void getCard_MasterOfTheWildHunt(final Card card) {
|
||||
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 {
|
||||
public MasterOfTheWildHuntAbility(final Card ca, final Cost co, final Target t) {
|
||||
super(ca, co, t);
|
||||
|
||||
@@ -79,10 +79,6 @@ public abstract class SpellAbility implements ISpellAbility, ITargetable {
|
||||
private boolean offering = false;
|
||||
private boolean morphup = false;
|
||||
|
||||
private Card targetCard;
|
||||
/** The chosen target. */
|
||||
private Target chosenTarget = null;
|
||||
|
||||
/** The pay costs. */
|
||||
private Cost payCosts = null;
|
||||
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>
|
||||
* Getter for the field <code>targetCard</code>.
|
||||
|
||||
@@ -22,6 +22,8 @@ import java.util.Arrays;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
|
||||
import org.apache.commons.lang.StringUtils;
|
||||
|
||||
import forge.Card;
|
||||
import forge.ITargetable;
|
||||
import forge.card.CardType;
|
||||
@@ -43,7 +45,7 @@ public class Target {
|
||||
// Targeting restrictions (Creature, Min/Maxm etc) which are true for this
|
||||
|
||||
// Target Choices (which is specific for the StackInstance)
|
||||
private Card srcCard;
|
||||
|
||||
// What this Object is restricted to targeting
|
||||
private boolean tgtValid = false;
|
||||
private String[] validTgts;
|
||||
@@ -94,7 +96,6 @@ public class Target {
|
||||
*/
|
||||
public Target(final Target target) {
|
||||
this.tgtValid = true;
|
||||
this.srcCard = target.getSourceCard();
|
||||
this.vtSelection = target.getVTSelection();
|
||||
this.validTgts = target.getValidTgts();
|
||||
this.minTargets = target.getMinTargets();
|
||||
@@ -129,8 +130,8 @@ public class Target {
|
||||
* @param valid
|
||||
* an array of {@link java.lang.String} objects.
|
||||
*/
|
||||
public Target(final Card src, final String select, final String[] valid) {
|
||||
this(src, select, valid, "1", "1");
|
||||
public Target(final String select, final String[] valid) {
|
||||
this(select, valid, "1", "1");
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -145,8 +146,8 @@ public class Target {
|
||||
* @param valid
|
||||
* a {@link java.lang.String} object.
|
||||
*/
|
||||
public Target(final Card src, final String select, final String valid) {
|
||||
this(src, select, valid.split(","), "1", "1");
|
||||
public Target(final String select, final String valid) {
|
||||
this(select, valid.split(","), "1", "1");
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -165,8 +166,7 @@ public class Target {
|
||||
* @param max
|
||||
* a {@link java.lang.String} object.
|
||||
*/
|
||||
public Target(final Card src, final String select, final String[] valid, final String min, final String max) {
|
||||
this.srcCard = src;
|
||||
public Target(final String select, final String[] valid, final String min, final String max) {
|
||||
this.tgtValid = true;
|
||||
this.vtSelection = select;
|
||||
this.validTgts = valid;
|
||||
@@ -175,29 +175,6 @@ public class Target {
|
||||
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>
|
||||
* 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)) {
|
||||
// Stack Zone targets are considered later
|
||||
return true;
|
||||
} else {
|
||||
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;
|
||||
}
|
||||
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)) {
|
||||
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 isAlreadyTargeted = this.getTargetCards().contains(c);
|
||||
if (isValidTarget && canTarget && !isAlreadyTargeted) {
|
||||
@@ -740,7 +719,7 @@ public class Target {
|
||||
}
|
||||
} else {
|
||||
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 isAlreadyTargeted = this.getTargetCards().contains(c);
|
||||
if (isValidTarget && canTarget && !isAlreadyTargeted) {
|
||||
@@ -972,8 +951,10 @@ public class Target {
|
||||
return;
|
||||
}
|
||||
|
||||
if (toDistribute.matches("[0-9][0-9]")) {
|
||||
if (StringUtils.isNumeric(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")) {
|
||||
this.setStillToDivide(source.getXManaCostPaid());
|
||||
} else {
|
||||
|
||||
@@ -147,9 +147,9 @@ public class TargetSelection {
|
||||
if (canTgtStack) {
|
||||
// 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
|
||||
Card activatingCard = tgt.getSourceCard();
|
||||
Card activatingCard = ability.getSourceCard();
|
||||
if (activatingCard.isInZone(ZoneType.Stack)) {
|
||||
choices.remove(tgt.getSourceCard());
|
||||
choices.remove(ability.getSourceCard());
|
||||
}
|
||||
}
|
||||
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))) {
|
||||
for(Card c : chainsList) {
|
||||
// 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);
|
||||
|
||||
if (getCardsIn(ZoneType.Hand).isEmpty()) {
|
||||
|
||||
Reference in New Issue
Block a user