mirror of
https://github.com/Card-Forge/forge.git
synced 2025-11-18 19:58:00 +00:00
add an AF_ChooseCard. It's pretty specific right now, but can be generalized/tweaked for when/how the needs arise
This commit is contained in:
@@ -358,10 +358,8 @@ public class Card extends GameEntity implements Comparable<Card> {
|
|||||||
|
|
||||||
private long timestamp = -1; // permanents on the battlefield
|
private long timestamp = -1; // permanents on the battlefield
|
||||||
|
|
||||||
private ArrayList<CardPowerToughness> newPT = new ArrayList<CardPowerToughness>(); // stack
|
//stack of set power/toughness
|
||||||
// of
|
private ArrayList<CardPowerToughness> newPT = new ArrayList<CardPowerToughness>();
|
||||||
// set
|
|
||||||
// power/toughness
|
|
||||||
private int baseLoyalty = 0;
|
private int baseLoyalty = 0;
|
||||||
private String baseAttackString = null;
|
private String baseAttackString = null;
|
||||||
private String baseDefenseString = null;
|
private String baseDefenseString = null;
|
||||||
@@ -405,6 +403,7 @@ public class Card extends GameEntity implements Comparable<Card> {
|
|||||||
private String namedCard = "";
|
private String namedCard = "";
|
||||||
private int chosenNumber;
|
private int chosenNumber;
|
||||||
private Player chosenPlayer;
|
private Player chosenPlayer;
|
||||||
|
private ArrayList<Card> chosenCard = new ArrayList<Card>();
|
||||||
|
|
||||||
private Card cloneOrigin = null;
|
private Card cloneOrigin = null;
|
||||||
private final ArrayList<Card> clones = new ArrayList<Card>();
|
private final ArrayList<Card> clones = new ArrayList<Card>();
|
||||||
@@ -2116,6 +2115,29 @@ public class Card extends GameEntity implements Comparable<Card> {
|
|||||||
this.chosenColor = s;
|
this.chosenColor = s;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* <p>
|
||||||
|
* Getter for the field <code>chosenCard</code>.
|
||||||
|
* </p>
|
||||||
|
*
|
||||||
|
* @return an ArrayList<Card> object.
|
||||||
|
*/
|
||||||
|
public final ArrayList<Card> getChosenCard() {
|
||||||
|
return this.chosenCard;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* <p>
|
||||||
|
* Setter for the field <code>chosenCard</code>.
|
||||||
|
* </p>
|
||||||
|
*
|
||||||
|
* @param c
|
||||||
|
* an ArrayList<String> object.
|
||||||
|
*/
|
||||||
|
public final void setChosenCard(final ArrayList<Card> c) {
|
||||||
|
this.chosenCard = c;
|
||||||
|
}
|
||||||
|
|
||||||
// used for cards like Meddling Mage...
|
// used for cards like Meddling Mage...
|
||||||
/**
|
/**
|
||||||
* <p>
|
* <p>
|
||||||
@@ -4032,9 +4054,8 @@ public class Card extends GameEntity implements Comparable<Card> {
|
|||||||
* </p>
|
* </p>
|
||||||
*/
|
*/
|
||||||
public final void unEquipAllCards() {
|
public final void unEquipAllCards() {
|
||||||
while (this.equippedBy.size() > 0) { // while there exists equipment,
|
//while there exists equipment, unequip the first one
|
||||||
// unequip
|
while (this.equippedBy.size() > 0) {
|
||||||
// the first one
|
|
||||||
this.equippedBy.get(0).unEquipCard(this);
|
this.equippedBy.get(0).unEquipCard(this);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -5351,9 +5372,8 @@ public class Card extends GameEntity implements Comparable<Card> {
|
|||||||
public final void clearAllKeywords() {
|
public final void clearAllKeywords() {
|
||||||
this.getCharacteristics().getIntrinsicKeyword().clear();
|
this.getCharacteristics().getIntrinsicKeyword().clear();
|
||||||
this.extrinsicKeyword.clear();
|
this.extrinsicKeyword.clear();
|
||||||
this.hiddenExtrinsicKeyword.clear(); // Hidden keywords won't be
|
//Hidden keywords won't be displayed on the card
|
||||||
// displayed on
|
this.hiddenExtrinsicKeyword.clear();
|
||||||
// the card
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -6505,9 +6525,8 @@ public class Card extends GameEntity implements Comparable<Card> {
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
final String[] incR = restriction.split("\\.", 2); // Inclusive
|
//Inclusive restrictions are Card types
|
||||||
// restrictions are
|
final String[] incR = restriction.split("\\.", 2);
|
||||||
// Card types
|
|
||||||
|
|
||||||
if (incR[0].equals("Spell") && !this.isSpell()) {
|
if (incR[0].equals("Spell") && !this.isSpell()) {
|
||||||
return false;
|
return false;
|
||||||
@@ -6566,6 +6585,10 @@ public class Card extends GameEntity implements Comparable<Card> {
|
|||||||
if (!this.getName().equals(source.getNamedCard())) {
|
if (!this.getName().equals(source.getNamedCard())) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
} else if (property.equals("ChosenCard")) {
|
||||||
|
if (!source.getChosenCard().contains(this)) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
// ... Card colors
|
// ... Card colors
|
||||||
else if (property.contains("White") || property.contains("Blue") || property.contains("Black")
|
else if (property.contains("White") || property.contains("Blue") || property.contains("Black")
|
||||||
@@ -7932,11 +7955,8 @@ public class Card extends GameEntity implements Comparable<Card> {
|
|||||||
*/
|
*/
|
||||||
public final void addDamage(final Map<Card, Integer> sourcesMap) {
|
public final void addDamage(final Map<Card, Integer> sourcesMap) {
|
||||||
for (final Entry<Card, Integer> entry : sourcesMap.entrySet()) {
|
for (final Entry<Card, Integer> entry : sourcesMap.entrySet()) {
|
||||||
this.addDamageAfterPrevention(entry.getValue(), entry.getKey(), true); // damage
|
//damage prevention is already checked!
|
||||||
// prevention
|
this.addDamageAfterPrevention(entry.getValue(), entry.getKey(), true);
|
||||||
// is
|
|
||||||
// already
|
|
||||||
// checked!
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -8447,9 +8467,8 @@ public class Card extends GameEntity implements Comparable<Card> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!this.isInZone(Constant.Zone.Battlefield)) { // keywords don't work
|
//keywords don't work outside battlefield
|
||||||
// outside the
|
if (!this.isInZone(Constant.Zone.Battlefield)) {
|
||||||
// battlefield
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -430,6 +430,16 @@ public class AbilityFactory {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
else if (this.api.equals("ChooseCard")) {
|
||||||
|
if (this.isAb) {
|
||||||
|
spellAbility = AbilityFactoryChoose.createAbilityChooseCard(this);
|
||||||
|
} else if (this.isSp) {
|
||||||
|
spellAbility = AbilityFactoryChoose.createSpellChooseCard(this);
|
||||||
|
} else if (this.isDb) {
|
||||||
|
spellAbility = AbilityFactoryChoose.createDrawbackChooseCard(this);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
else if (this.api.equals("ChooseColor")) {
|
else if (this.api.equals("ChooseColor")) {
|
||||||
if (this.isAb) {
|
if (this.isAb) {
|
||||||
spellAbility = AbilityFactoryChoose.createAbilityChooseColor(this);
|
spellAbility = AbilityFactoryChoose.createAbilityChooseColor(this);
|
||||||
@@ -517,9 +527,8 @@ public class AbilityFactory {
|
|||||||
else if (this.api.equals("Counter")) {
|
else if (this.api.equals("Counter")) {
|
||||||
final AbilityFactoryCounterMagic c = new AbilityFactoryCounterMagic(this);
|
final AbilityFactoryCounterMagic c = new AbilityFactoryCounterMagic(this);
|
||||||
|
|
||||||
if (this.isTargeted) { // Since all "Counter" ABs Counter things on
|
//Since all "Counter" ABs Counter things on the Stack no need for it to be everywhere
|
||||||
// the
|
if (this.isTargeted) {
|
||||||
// Stack no need for it to be everywhere
|
|
||||||
this.abTgt.setZone(Zone.Stack);
|
this.abTgt.setZone(Zone.Stack);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -32,7 +32,7 @@ import forge.item.CardPrinted;
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* <p>
|
* <p>
|
||||||
* AbilityFactory_Choose class.
|
* AbilityFactoryChoose class.
|
||||||
* </p>
|
* </p>
|
||||||
*
|
*
|
||||||
* @author Forge
|
* @author Forge
|
||||||
@@ -1156,7 +1156,17 @@ public final class AbilityFactoryChoose {
|
|||||||
card.setChosenPlayer(chosen);
|
card.setChosenPlayer(chosen);
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
// TODO - not implemented
|
if (params.containsKey("AILogic")) {
|
||||||
|
if (params.get("AILogic").equals("Curse")) {
|
||||||
|
card.setChosenPlayer(AllZone.getHumanPlayer());
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
card.setChosenPlayer(AllZone.getComputerPlayer());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
card.setChosenPlayer(AllZone.getComputerPlayer());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -1435,5 +1445,245 @@ public final class AbilityFactoryChoose {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// *************************************************************************
|
||||||
|
// *************************** ChooseCard **********************************
|
||||||
|
// *************************************************************************
|
||||||
|
|
||||||
} // end class AbilityFactory_Choose
|
/**
|
||||||
|
* <p>
|
||||||
|
* createAbilityChooseCard.
|
||||||
|
* </p>
|
||||||
|
*
|
||||||
|
* @param af
|
||||||
|
* a {@link forge.card.abilityFactory.AbilityFactory} object.
|
||||||
|
* @return a {@link forge.card.spellability.SpellAbility} object.
|
||||||
|
*/
|
||||||
|
public static SpellAbility createAbilityChooseCard(final AbilityFactory af) {
|
||||||
|
final SpellAbility abChooseCard = new AbilityActivated(af.getHostCard(), af.getAbCost(), af.getAbTgt()) {
|
||||||
|
private static final long serialVersionUID = 2399435577106102311L;
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String getStackDescription() {
|
||||||
|
return chooseCardStackDescription(af, this);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean canPlayAI() {
|
||||||
|
return chooseCardCanPlayAI(af, this);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void resolve() {
|
||||||
|
chooseCardResolve(af, this);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean doTrigger(final boolean mandatory) {
|
||||||
|
return chooseCardTriggerAI(af, this, mandatory);
|
||||||
|
}
|
||||||
|
|
||||||
|
};
|
||||||
|
return abChooseCard;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* <p>
|
||||||
|
* createSpellChooseCard.
|
||||||
|
* </p>
|
||||||
|
*
|
||||||
|
* @param af
|
||||||
|
* a {@link forge.card.abilityFactory.AbilityFactory} object.
|
||||||
|
* @return a {@link forge.card.spellability.SpellAbility} object.
|
||||||
|
* @since 1.1.7
|
||||||
|
*/
|
||||||
|
public static SpellAbility createSpellChooseCard(final AbilityFactory af) {
|
||||||
|
final SpellAbility spChooseCard = new Spell(af.getHostCard(), af.getAbCost(), af.getAbTgt()) {
|
||||||
|
private static final long serialVersionUID = 1425536663625668893L;
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String getStackDescription() {
|
||||||
|
return chooseCardStackDescription(af, this);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean canPlayAI() {
|
||||||
|
return chooseCardCanPlayAI(af, this);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void resolve() {
|
||||||
|
chooseCardResolve(af, this);
|
||||||
|
}
|
||||||
|
|
||||||
|
};
|
||||||
|
return spChooseCard;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* <p>
|
||||||
|
* createDrawbackChooseCard.
|
||||||
|
* </p>
|
||||||
|
*
|
||||||
|
* @param af
|
||||||
|
* a {@link forge.card.abilityFactory.AbilityFactory} object.
|
||||||
|
* @return a {@link forge.card.spellability.SpellAbility} object.
|
||||||
|
*/
|
||||||
|
public static SpellAbility createDrawbackChooseCard(final AbilityFactory af) {
|
||||||
|
final SpellAbility dbChooseCard = new AbilitySub(af.getHostCard(), af.getAbTgt()) {
|
||||||
|
private static final long serialVersionUID = -3255569671897226555L;
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String getStackDescription() {
|
||||||
|
return chooseCardStackDescription(af, this);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void resolve() {
|
||||||
|
chooseCardResolve(af, this);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean chkAIDrawback() {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean doTrigger(final boolean mandatory) {
|
||||||
|
return chooseCardTriggerAI(af, this, mandatory);
|
||||||
|
}
|
||||||
|
|
||||||
|
};
|
||||||
|
return dbChooseCard;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* <p>
|
||||||
|
* chooseCardStackDescription.
|
||||||
|
* </p>
|
||||||
|
*
|
||||||
|
* @param af
|
||||||
|
* a {@link forge.card.abilityFactory.AbilityFactory} object.
|
||||||
|
* @param sa
|
||||||
|
* a {@link forge.card.spellability.SpellAbility} object.
|
||||||
|
* @return a {@link java.lang.String} object.
|
||||||
|
*/
|
||||||
|
private static String chooseCardStackDescription(final AbilityFactory af, final SpellAbility sa) {
|
||||||
|
StringBuilder sb = new StringBuilder();
|
||||||
|
|
||||||
|
if (sa instanceof AbilitySub) {
|
||||||
|
sb.append(" ");
|
||||||
|
} else {
|
||||||
|
sb.append(sa.getSourceCard()).append(" - ");
|
||||||
|
}
|
||||||
|
|
||||||
|
ArrayList<Player> tgtPlayers;
|
||||||
|
|
||||||
|
Target tgt = af.getAbTgt();
|
||||||
|
if (tgt != null) {
|
||||||
|
tgtPlayers = tgt.getTargetPlayers();
|
||||||
|
} else {
|
||||||
|
tgtPlayers = AbilityFactory.getDefinedPlayers(sa.getSourceCard(), af.getMapParams().get("Defined"), sa);
|
||||||
|
}
|
||||||
|
|
||||||
|
for (Player p : tgtPlayers) {
|
||||||
|
sb.append(p).append(" ");
|
||||||
|
}
|
||||||
|
sb.append("chooses a card.");
|
||||||
|
|
||||||
|
AbilitySub abSub = sa.getSubAbility();
|
||||||
|
if (abSub != null) {
|
||||||
|
sb.append(abSub.getStackDescription());
|
||||||
|
}
|
||||||
|
|
||||||
|
return sb.toString();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* <p>
|
||||||
|
* chooseCardCanPlayAI.
|
||||||
|
* </p>
|
||||||
|
*
|
||||||
|
* @param af
|
||||||
|
* a {@link forge.card.abilityFactory.AbilityFactory} object.
|
||||||
|
* @param sa
|
||||||
|
* a {@link forge.card.spellability.SpellAbility} object.
|
||||||
|
* @return a boolean.
|
||||||
|
*/
|
||||||
|
private static boolean chooseCardCanPlayAI(final AbilityFactory af, final SpellAbility sa) {
|
||||||
|
return chooseCardTriggerAI(af, sa, false);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* <p>
|
||||||
|
* chooseCardTriggerAI.
|
||||||
|
* </p>
|
||||||
|
*
|
||||||
|
* @param af
|
||||||
|
* a {@link forge.card.abilityFactory.AbilityFactory} object.
|
||||||
|
* @param sa
|
||||||
|
* a {@link forge.card.spellability.SpellAbility} object.
|
||||||
|
* @param mandatory
|
||||||
|
* a boolean.
|
||||||
|
* @return a boolean.
|
||||||
|
*/
|
||||||
|
private static boolean chooseCardTriggerAI(final AbilityFactory af, final SpellAbility sa, final boolean mandatory) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* <p>
|
||||||
|
* chooseCardResolve.
|
||||||
|
* </p>
|
||||||
|
*
|
||||||
|
* @param af
|
||||||
|
* a {@link forge.card.abilityFactory.AbilityFactory} object.
|
||||||
|
* @param sa
|
||||||
|
* a {@link forge.card.spellability.SpellAbility} object.
|
||||||
|
*/
|
||||||
|
private static void chooseCardResolve(final AbilityFactory af, final SpellAbility sa) {
|
||||||
|
HashMap<String, String> params = af.getMapParams();
|
||||||
|
Card host = af.getHostCard();
|
||||||
|
|
||||||
|
ArrayList<Player> tgtPlayers;
|
||||||
|
|
||||||
|
Target tgt = af.getAbTgt();
|
||||||
|
if (tgt != null) {
|
||||||
|
tgtPlayers = tgt.getTargetPlayers();
|
||||||
|
} else {
|
||||||
|
tgtPlayers = AbilityFactory.getDefinedPlayers(sa.getSourceCard(), params.get("Defined"), sa);
|
||||||
|
}
|
||||||
|
|
||||||
|
CardList choices = AllZoneUtil.getCardsIn(Zone.Battlefield);
|
||||||
|
if (params.containsKey("Choices")) {
|
||||||
|
choices = choices.getValidCards(params.get("Choices"), host.getController(), host);
|
||||||
|
}
|
||||||
|
|
||||||
|
for (Player p : tgtPlayers) {
|
||||||
|
if (tgt == null || p.canBeTargetedBy(sa)) {
|
||||||
|
ArrayList<Card> chosen = new ArrayList<Card>();
|
||||||
|
if (sa.getActivatingPlayer().isHuman()) {
|
||||||
|
CardList land = AllZoneUtil.getLandsInPlay();
|
||||||
|
final ArrayList<String> basic = CardUtil.getBasicTypes();
|
||||||
|
|
||||||
|
for (final String type : basic) {
|
||||||
|
final CardList cl = land.getType(type);
|
||||||
|
if (cl.size() > 0) {
|
||||||
|
String prompt = "Choose a" + (type.equals("Island") ? "n " : " ") + type;
|
||||||
|
Object o = GuiUtils.getChoice(prompt, cl.toArray());
|
||||||
|
if (null != o) {
|
||||||
|
Card c = (Card) o;
|
||||||
|
chosen.add(c);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
} else {
|
||||||
|
// TODO - not implemented
|
||||||
|
}
|
||||||
|
host.setChosenCard(chosen);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
} // end class AbilityFactoryChoose
|
||||||
|
|||||||
Reference in New Issue
Block a user