Merge pull request #2865 from Card-Forge/counterAddedFirstTime

CounterAddedOnce add FirstTime
This commit is contained in:
Anthony Calosa
2023-04-08 20:03:56 +08:00
committed by GitHub
6 changed files with 41 additions and 16 deletions

View File

@@ -1132,6 +1132,20 @@ public class Game {
} }
return result; return result;
} }
public int getCounterAddedThisTurn(CounterType cType, Card card) {
int result = 0;
if (!countersAddedThisTurn.containsRow(cType)) {
return result;
}
for (List<Pair<Card, Integer>> l : countersAddedThisTurn.row(cType).values()) {
for (Pair<Card, Integer> p : l) {
if (p.getKey().equalsWithTimestamp(card)) {
result += p.getValue();
}
}
}
return result;
}
public void clearCounterAddedThisTurn() { public void clearCounterAddedThisTurn() {
countersAddedThisTurn.clear(); countersAddedThisTurn.clear();

View File

@@ -505,7 +505,6 @@ public class ChangeZoneEffect extends SpellAbilityEffect {
final boolean optional = sa.hasParam("Optional"); final boolean optional = sa.hasParam("Optional");
final boolean shuffle = sa.hasParam("Shuffle") && "True".equals(sa.getParam("Shuffle")); final boolean shuffle = sa.hasParam("Shuffle") && "True".equals(sa.getParam("Shuffle"));
final long ts = game.getNextTimestamp();
boolean combatChanged = false; boolean combatChanged = false;
Player chooser = player; Player chooser = player;
@@ -703,13 +702,6 @@ public class ChangeZoneEffect extends SpellAbilityEffect {
combatChanged = true; combatChanged = true;
} }
movedCard.setTimestamp(ts);
if (movedCard.isInPlay()) {
// need to also update LKI
List<Card> lki = movedCard.getZone().getCardsAddedThisTurn(null);
lki.get(lki.lastIndexOf(movedCard)).setTimestamp(ts);
}
if (sa.hasParam("AttachAfter") && movedCard.isAttachment()) { if (sa.hasParam("AttachAfter") && movedCard.isAttachment()) {
CardCollection list = AbilityUtils.getDefinedCards(hostCard, sa.getParam("AttachAfter"), sa); CardCollection list = AbilityUtils.getDefinedCards(hostCard, sa.getParam("AttachAfter"), sa);
if (list.isEmpty()) { if (list.isEmpty()) {
@@ -1284,7 +1276,6 @@ public class ChangeZoneEffect extends SpellAbilityEffect {
List<ZoneType> origin = HiddenOriginChoicesMap.get(player).origin; List<ZoneType> origin = HiddenOriginChoicesMap.get(player).origin;
ZoneType destination = HiddenOriginChoicesMap.get(player).destination; ZoneType destination = HiddenOriginChoicesMap.get(player).destination;
CardCollection movedCards = new CardCollection(); CardCollection movedCards = new CardCollection();
long ts = game.getNextTimestamp();
Player decider = ObjectUtils.firstNonNull(chooser, player); Player decider = ObjectUtils.firstNonNull(chooser, player);
for (final Card c : chosenCards) { for (final Card c : chosenCards) {
@@ -1391,13 +1382,6 @@ public class ChangeZoneEffect extends SpellAbilityEffect {
} }
movedCard = game.getAction().moveToPlay(c, c.getController(), sa, moveParams); movedCard = game.getAction().moveToPlay(c, c.getController(), sa, moveParams);
movedCard.setTimestamp(ts);
if (movedCard.isInPlay()) {
// need to also update LKI
List<Card> lki = movedCard.getZone().getCardsAddedThisTurn(null);
lki.get(lki.lastIndexOf(movedCard)).setTimestamp(ts);
}
if (sa.hasParam("AttachAfter") && movedCard.isAttachment() && movedCard.isInPlay()) { if (sa.hasParam("AttachAfter") && movedCard.isAttachment() && movedCard.isInPlay()) {
CardCollection list = AbilityUtils.getDefinedCards(source, sa.getParam("AttachAfter"), sa); CardCollection list = AbilityUtils.getDefinedCards(source, sa.getParam("AttachAfter"), sa);
if (list.isEmpty()) { if (list.isEmpty()) {

View File

@@ -1447,6 +1447,7 @@ public class Card extends GameEntity implements Comparable<Card>, IHasSVars {
final int toughnessBonusBefore = getToughnessBonusFromCounters(); final int toughnessBonusBefore = getToughnessBonusFromCounters();
final int loyaltyBefore = getCurrentLoyalty(); final int loyaltyBefore = getCurrentLoyalty();
int addedThisTurn = getGame().getCounterAddedThisTurn(counterType, this);
setCounters(counterType, newValue); setCounters(counterType, newValue);
getGame().addCounterAddedThisTurn(source, counterType, this, addAmount); getGame().addCounterAddedThisTurn(source, counterType, this, addAmount);
view.updateCounters(this); view.updateCounters(this);
@@ -1473,6 +1474,7 @@ public class Card extends GameEntity implements Comparable<Card>, IHasSVars {
} }
if (addAmount > 0) { if (addAmount > 0) {
runParams.put(AbilityKey.CounterAmount, addAmount); runParams.put(AbilityKey.CounterAmount, addAmount);
runParams.put(AbilityKey.FirstTime, addedThisTurn == 0);
getGame().getTriggerHandler().runTrigger( getGame().getTriggerHandler().runTrigger(
TriggerType.CounterAddedOnce, AbilityKey.newMap(runParams), false); TriggerType.CounterAddedOnce, AbilityKey.newMap(runParams), false);
} }

View File

@@ -55,6 +55,12 @@ public class TriggerCounterAddedOnce extends Trigger {
* @param runParams*/ * @param runParams*/
@Override @Override
public final boolean performTest(final Map<AbilityKey, Object> runParams) { public final boolean performTest(final Map<AbilityKey, Object> runParams) {
if (hasParam("FirstTime")) {
if (!(boolean) runParams.get(AbilityKey.FirstTime)) {
return false;
}
}
if (hasParam("CounterType")) { if (hasParam("CounterType")) {
final CounterType addedType = (CounterType) runParams.get(AbilityKey.CounterType); final CounterType addedType = (CounterType) runParams.get(AbilityKey.CounterType);
final String type = getParam("CounterType"); final String type = getParam("CounterType");

View File

@@ -0,0 +1,8 @@
Name:Axgard Artisan
ManaCost:1 R
Types:Creature Dwarf Artificer
PT:2/1
T:Mode$ CounterAddedOnce | ValidCard$ Card.Self | TriggerZones$ Battlefield | CounterType$ P1P1 | FirstTime$ True | Execute$ TrigToken | TriggerDescription$ Whenever one or more +1/+1 counters are put on CARDNAME for the first time each turn, create a Treasure token. (its an artifact with “{T}, Sacrifice this artifact: Add one mana of any color.”)
SVar:TrigToken:DB$ Token | TokenAmount$ 1 | TokenScript$ c_a_treasure_sac | TokenOwner$ You
DeckHints:Ability$Counters
Oracle:Whenever one or more +1/+1 counters are put on Axgard Artisan for the first time each turn, create a Treasure token. (its an artifact with “{T}, Sacrifice this artifact: Add one mana of any color.”)

View File

@@ -0,0 +1,11 @@
Name:Botanical Brawler
ManaCost:G W
Types:Creature Elemental Warrior
PT:0/0
K:Trample
K:etbCounter:P1P1:2
T:Mode$ CounterAddedOnce | ValidCard$ Card.Other+YouCtrl+inZoneBattlefield | TriggerZones$ Battlefield | CounterType$ P1P1 | FirstTime$ True | Execute$ TrigPutCounter | TriggerDescription$ Whenever one or more +1/+1 counters are put on another permanent you control, if its the first time +1/+1 counters have been put on that permanent this turn, put a +1/+1 counter on CARDNAME.
SVar:TrigPutCounter:DB$ PutCounter | CounterType$ P1P1 | CounterNum$ 1
DeckHas:Ability$Counters
DeckHints:Ability$Counters
Oracle:Trample\nBotanical Brawler enters the battlefield with two +1/+1 counters on it.\nWhenever one or more +1/+1 counters are put on another permanent you control, if its the first time +1/+1 counters have been put on that permanent this turn, put a +1/+1 counter on Botanical Brawler.