mirror of
https://github.com/Card-Forge/forge.git
synced 2025-11-19 12:18:00 +00:00
Card: store activations in Card
This commit is contained in:
committed by
Michael Kamensky
parent
8f0457f0fa
commit
8e5e8e1759
@@ -1255,7 +1255,7 @@ public class ComputerUtil {
|
||||
|
||||
// returns true if the AI should stop using the ability
|
||||
public static boolean preventRunAwayActivations(final SpellAbility sa) {
|
||||
int activations = sa.getRestrictions().getNumberTurnActivations();
|
||||
int activations = sa.getActivationsThisTurn();
|
||||
|
||||
if (sa.isTemporary()) {
|
||||
return MyRandom.getRandom().nextFloat() >= .95; // Abilities created by static abilities have no memory
|
||||
|
||||
@@ -20,7 +20,6 @@ import forge.game.phase.PhaseType;
|
||||
import forge.game.player.Player;
|
||||
import forge.game.player.PlayerActionConfirmMode;
|
||||
import forge.game.spellability.SpellAbility;
|
||||
import forge.game.spellability.SpellAbilityRestriction;
|
||||
import forge.game.spellability.TargetRestrictions;
|
||||
import forge.game.staticability.StaticAbility;
|
||||
import forge.game.zone.ZoneType;
|
||||
@@ -288,9 +287,8 @@ public class PumpAi extends PumpAiBase {
|
||||
}
|
||||
|
||||
if (sa.hasParam("ActivationNumberSacrifice")) {
|
||||
final SpellAbilityRestriction restrict = sa.getRestrictions();
|
||||
final int sacActivations = Integer.parseInt(sa.getParam("ActivationNumberSacrifice").substring(2));
|
||||
final int activations = restrict.getNumberTurnActivations();
|
||||
final int activations = sa.getActivationsThisTurn();
|
||||
// don't risk sacrificing a creature just to pump it
|
||||
if (activations >= sacActivations - 1) {
|
||||
return false;
|
||||
|
||||
@@ -324,12 +324,12 @@ public class GameCopier {
|
||||
if (c.isPlaneswalker()) {
|
||||
for (SpellAbility sa : c.getAllSpellAbilities()) {
|
||||
SpellAbilityRestriction restrict = sa.getRestrictions();
|
||||
if (sa.isPwAbility() && restrict.getNumberTurnActivations() > 0) {
|
||||
int active = sa.getActivationsThisTurn();
|
||||
if (sa.isPwAbility() && active > 0) {
|
||||
SpellAbility newSa = findSAInCard(sa, newCard);
|
||||
if (newSa != null) {
|
||||
for (int i = 0; i < restrict.getNumberTurnActivations(); i++) {
|
||||
newSa.getRestrictions().abilityActivated();
|
||||
newCard.addPlaneswalkerAbilityActivated();
|
||||
for (int i = 0; i < active; i++) {
|
||||
newCard.addAbilityActivated(newSa);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -269,6 +269,13 @@ public class Card extends GameEntity implements Comparable<Card> {
|
||||
|
||||
private int planeswalkerAbilityActivated = 0;
|
||||
|
||||
private final Map<SpellAbility, Integer> numberTurnActivations = Maps.newHashMap();
|
||||
private final Map<SpellAbility, Integer> numberGameActivations = Maps.newHashMap();
|
||||
|
||||
private final Table<SpellAbility, StaticAbility, Integer> numberTurnActivationsStatic = HashBasedTable.create();
|
||||
private final Table<SpellAbility, StaticAbility, Integer> numberGameActivationsStatic = HashBasedTable.create();
|
||||
|
||||
|
||||
// Enumeration for CMC request types
|
||||
public enum SplitCMCMode {
|
||||
CurrentSideCMC,
|
||||
@@ -6186,6 +6193,62 @@ public class Card extends GameEntity implements Comparable<Card> {
|
||||
return true;
|
||||
}
|
||||
|
||||
public void addAbilityActivated(SpellAbility ability) {
|
||||
SpellAbility original = ability.getOriginalAbility();
|
||||
if (original == null) {
|
||||
original = ability;
|
||||
}
|
||||
|
||||
int turnActivated = getAbilityActivatedThisTurn(ability);
|
||||
int gameActivated = getAbilityActivatedThisGame(ability);
|
||||
if (ability.getGrantorStatic() != null) {
|
||||
numberTurnActivationsStatic.put(original, ability.getGrantorStatic(), turnActivated + 1);
|
||||
numberGameActivationsStatic.put(original, ability.getGrantorStatic(), gameActivated + 1);
|
||||
} else {
|
||||
numberTurnActivations.put(original, turnActivated + 1);
|
||||
numberGameActivations.put(original, gameActivated + 1);
|
||||
}
|
||||
|
||||
if (ability.isPwAbility()) {
|
||||
addPlaneswalkerAbilityActivated();
|
||||
}
|
||||
}
|
||||
|
||||
public int getAbilityActivatedThisTurn(SpellAbility ability) {
|
||||
SpellAbility original = ability.getOriginalAbility();
|
||||
if (original == null) {
|
||||
original = ability;
|
||||
}
|
||||
|
||||
if (ability.getGrantorStatic() != null) {
|
||||
if (numberTurnActivationsStatic.contains(original, ability.getGrantorStatic())) {
|
||||
return numberTurnActivationsStatic.get(original, ability.getGrantorStatic());
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
return numberTurnActivations.containsKey(original) ? numberTurnActivations.get(original) : 0;
|
||||
}
|
||||
|
||||
public int getAbilityActivatedThisGame(SpellAbility ability) {
|
||||
SpellAbility original = ability.getOriginalAbility();
|
||||
if (original == null) {
|
||||
original = ability;
|
||||
}
|
||||
|
||||
if (ability.getGrantorStatic() != null) {
|
||||
if (numberGameActivationsStatic.contains(original, ability.getGrantorStatic())) {
|
||||
return numberGameActivationsStatic.get(original, ability.getGrantorStatic());
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
return numberGameActivations.containsKey(original) ? numberGameActivations.get(original) : 0;
|
||||
}
|
||||
|
||||
public void resetTurnActivations() {
|
||||
numberTurnActivations.clear();
|
||||
numberTurnActivationsStatic.clear();
|
||||
}
|
||||
|
||||
public int getPlaneswalkerAbilityActivated() {
|
||||
return planeswalkerAbilityActivated;
|
||||
}
|
||||
@@ -6196,8 +6259,7 @@ public class Card extends GameEntity implements Comparable<Card> {
|
||||
|
||||
public void resetActivationsPerTurn() {
|
||||
planeswalkerAbilityActivated = 0;
|
||||
for (final SpellAbility sa : this.getAllSpellAbilities()) {
|
||||
sa.getRestrictions().resetTurnActivations();
|
||||
}
|
||||
numberTurnActivations.clear();
|
||||
numberTurnActivationsStatic.clear();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -631,9 +631,6 @@ public class CardFactory {
|
||||
}
|
||||
if (from.getRestrictions() != null) {
|
||||
to.setRestrictions((SpellAbilityRestriction) from.getRestrictions().copy());
|
||||
if (!lki) {
|
||||
to.getRestrictions().resetTurnActivations();
|
||||
}
|
||||
}
|
||||
if (from.getConditions() != null) {
|
||||
to.setConditions((SpellAbilityCondition) from.getConditions().copy());
|
||||
@@ -919,10 +916,6 @@ public class CardFactory {
|
||||
if (sa.hasParam("SetColor") || sa.hasParam("Embalm") || sa.hasParam("Eternalize")) {
|
||||
state.removeIntrinsicKeyword("Devoid");
|
||||
}
|
||||
|
||||
for (SpellAbility ab : state.getSpellAbilities()) {
|
||||
ab.getRestrictions().resetTurnActivations();
|
||||
}
|
||||
}
|
||||
|
||||
// Dont copy the facedown state, make new one
|
||||
|
||||
@@ -83,6 +83,9 @@ public abstract class SpellAbility extends CardTraitBase implements ISpellAbilit
|
||||
private Player targetingPlayer = null;
|
||||
|
||||
private Card grantorCard = null; // card which grants the ability (equipment or owner of static ability that gave this one)
|
||||
private SpellAbility grantorOriginal = null;
|
||||
private StaticAbility grantorStatic = null;
|
||||
|
||||
private SpellAbility mayPlayOriginal = null;
|
||||
|
||||
private CardCollection splicedCards = null;
|
||||
@@ -463,8 +466,12 @@ public abstract class SpellAbility extends CardTraitBase implements ISpellAbilit
|
||||
* Shortcut to see how many activations there were this turn.
|
||||
*/
|
||||
public int getActivationsThisTurn() {
|
||||
return restrictions.getNumberTurnActivations();
|
||||
return getHostCard().getAbilityActivatedThisTurn(this);
|
||||
}
|
||||
public int getActivationsThisGame() {
|
||||
return getHostCard().getAbilityActivatedThisGame(this);
|
||||
}
|
||||
|
||||
|
||||
public SpellAbilityCondition getConditions() {
|
||||
return conditions;
|
||||
@@ -1701,7 +1708,7 @@ public abstract class SpellAbility extends CardTraitBase implements ISpellAbilit
|
||||
if (hasParam("ActivationNumberSacrifice")) {
|
||||
String comp = getParam("ActivationNumberSacrifice");
|
||||
int right = Integer.parseInt(comp.substring(2));
|
||||
int activationNum = getRestrictions().getNumberTurnActivations();
|
||||
int activationNum = getActivationsThisTurn();
|
||||
if (Expressions.compare(activationNum, comp, right)) {
|
||||
SpellAbility deltrig = AbilityFactory.getAbility(hostCard.getSVar(getParam("ActivationResolveSub")), hostCard);
|
||||
deltrig.setActivatingPlayer(activatingPlayer);
|
||||
@@ -1886,4 +1893,20 @@ public abstract class SpellAbility extends CardTraitBase implements ISpellAbilit
|
||||
public void setPreventMap(final CardDamageMap map) {
|
||||
preventMap = map;
|
||||
}
|
||||
|
||||
public SpellAbility getOriginalAbility() {
|
||||
return grantorOriginal;
|
||||
}
|
||||
|
||||
public void setOriginalAbility(final SpellAbility sa) {
|
||||
grantorOriginal = sa;
|
||||
}
|
||||
|
||||
public StaticAbility getGrantorStatic() {
|
||||
return grantorStatic;
|
||||
}
|
||||
|
||||
public void setGrantorStatic(final StaticAbility st) {
|
||||
grantorStatic = st;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -299,11 +299,11 @@ public class SpellAbilityCondition extends SpellAbilityVariables {
|
||||
return false;
|
||||
}
|
||||
|
||||
if ((this.getActivationLimit() != -1) && (this.getNumberTurnActivations() >= this.getActivationLimit())) {
|
||||
if ((this.getActivationLimit() != -1) && (sa.getActivationsThisTurn() >= this.getActivationLimit())) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if ((this.getGameActivationLimit() != -1) && (this.getNumberGameActivations() >= this.getGameActivationLimit())) {
|
||||
if ((this.getGameActivationLimit() != -1) && (sa.getActivationsThisGame() >= this.getGameActivationLimit())) {
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
@@ -572,7 +572,7 @@ public class SpellAbilityRestriction extends SpellAbilityVariables {
|
||||
int activationLimit = AbilityUtils.calculateAmount(c, limit, sa);
|
||||
this.setActivationLimit(activationLimit);
|
||||
|
||||
if ((this.getActivationLimit() != -1) && (this.getNumberTurnActivations() >= this.getActivationLimit())) {
|
||||
if ((this.getActivationLimit() != -1) && (sa.getActivationsThisTurn() >= this.getActivationLimit())) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
@@ -582,7 +582,7 @@ public class SpellAbilityRestriction extends SpellAbilityVariables {
|
||||
int gameActivationLimit = AbilityUtils.calculateAmount(c, limit, sa);
|
||||
this.setGameActivationLimit(gameActivationLimit);
|
||||
|
||||
if ((this.getGameActivationLimit() != -1) && (this.getNumberGameActivations() >= this.getGameActivationLimit())) {
|
||||
if ((this.getGameActivationLimit() != -1) && (sa.getActivationsThisGame() >= this.getGameActivationLimit())) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -66,8 +66,6 @@ public class SpellAbilityVariables implements Cloneable {
|
||||
this.playerTurn = sav.isPlayerTurn();
|
||||
this.activationLimit = sav.getActivationLimit();
|
||||
this.gameActivationLimit = sav.getGameActivationLimit();
|
||||
this.numberTurnActivations = sav.getNumberTurnActivations();
|
||||
this.numberGameActivations = sav.getNumberGameActivations();
|
||||
this.cardsInHand = sav.getCardsInHand();
|
||||
this.chosenColors = sav.getColorToCheck();
|
||||
this.threshold = sav.isThreshold();
|
||||
@@ -136,12 +134,6 @@ public class SpellAbilityVariables implements Cloneable {
|
||||
/** The gameLimitToCheck to check. */
|
||||
private String gameLimitToCheck = null;
|
||||
|
||||
/** The number turn activations. */
|
||||
private int numberTurnActivations = 0;
|
||||
|
||||
/** The number game activations. */
|
||||
private int numberGameActivations = 0;
|
||||
|
||||
/** The n cards in hand. */
|
||||
private int cardsInHand = -1;
|
||||
|
||||
@@ -382,47 +374,6 @@ public class SpellAbilityVariables implements Cloneable {
|
||||
this.gameActivationLimit = limit;
|
||||
}
|
||||
|
||||
/**
|
||||
* <p>
|
||||
* abilityActivated.
|
||||
* </p>
|
||||
*/
|
||||
public final void abilityActivated() {
|
||||
this.numberTurnActivations++;
|
||||
this.numberGameActivations++;
|
||||
}
|
||||
|
||||
/**
|
||||
* <p>
|
||||
* Getter for the field <code>numberTurnActivations</code>.
|
||||
* </p>
|
||||
*
|
||||
* @return a int.
|
||||
*/
|
||||
public final int getNumberTurnActivations() {
|
||||
return this.numberTurnActivations;
|
||||
}
|
||||
|
||||
/**
|
||||
* <p>
|
||||
* Getter for the field <code>numberTurnActivations</code>.
|
||||
* </p>
|
||||
*
|
||||
* @return a int.
|
||||
*/
|
||||
public final int getNumberGameActivations() {
|
||||
return this.numberGameActivations;
|
||||
}
|
||||
|
||||
/**
|
||||
* <p>
|
||||
* resetTurnActivations.
|
||||
* </p>
|
||||
*/
|
||||
public final void resetTurnActivations() {
|
||||
this.numberTurnActivations = 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* <p>
|
||||
* Setter for the field <code>phases</code>.
|
||||
|
||||
@@ -17,6 +17,7 @@
|
||||
*/
|
||||
package forge.game.staticability;
|
||||
|
||||
import com.google.common.collect.ImmutableList;
|
||||
import com.google.common.collect.Iterables;
|
||||
import com.google.common.collect.Lists;
|
||||
import forge.GameCommand;
|
||||
@@ -375,14 +376,12 @@ public final class StaticAbilityContinuous {
|
||||
|
||||
if (layer == StaticAbilityLayer.ABILITIES1 && params.containsKey("GainsAbilitiesOf")) {
|
||||
final String[] valids = params.get("GainsAbilitiesOf").split(",");
|
||||
List<ZoneType> validZones = new ArrayList<ZoneType>();
|
||||
List<ZoneType> validZones;
|
||||
final boolean loyaltyAB = params.containsKey("GainsLoyaltyAbilities");
|
||||
validZones.add(ZoneType.Battlefield);
|
||||
if (params.containsKey("GainsAbilitiesOfZones")) {
|
||||
validZones.clear();
|
||||
for (String s : params.get("GainsAbilitiesOfZones").split(",")) {
|
||||
validZones.add(ZoneType.smartValueOf(s));
|
||||
}
|
||||
validZones = ZoneType.listValueOf(params.get("GainsAbilitiesOfZones"));
|
||||
} else {
|
||||
validZones = ImmutableList.of(ZoneType.Battlefield);
|
||||
}
|
||||
|
||||
CardCollectionView cardsIGainedAbilitiesFrom = game.getCardsIn(validZones);
|
||||
@@ -403,6 +402,8 @@ public final class StaticAbilityContinuous {
|
||||
newSA.getRestrictions().setLimitToCheck(params.get("GainsAbilitiesLimitPerTurn"));
|
||||
}
|
||||
newSA.setOriginalHost(c);
|
||||
newSA.setOriginalAbility(sa); // need to be set to get the Once Per turn Clause correct
|
||||
newSA.setGrantorStatic(stAb);
|
||||
newSA.setIntrinsic(false);
|
||||
newSA.setTemporary(true);
|
||||
addFullAbs.add(newSA);
|
||||
|
||||
@@ -137,10 +137,7 @@ public class MagicStack /* extends MyObservable */ implements Iterable<SpellAbil
|
||||
|
||||
if (!ability.isCopied()) {
|
||||
// Copied abilities aren't activated, so they shouldn't change these values
|
||||
ability.getRestrictions().abilityActivated();
|
||||
if (ability.isPwAbility()) {
|
||||
source.addPlaneswalkerAbilityActivated();
|
||||
}
|
||||
source.addAbilityActivated(ability);
|
||||
ability.checkActivationResloveSubs();
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user