Some cleanup (#9056)

This commit is contained in:
tool4ever
2025-11-01 15:44:47 +01:00
committed by GitHub
parent 1445fc2621
commit 54b8094211
9 changed files with 39 additions and 54 deletions

View File

@@ -487,14 +487,14 @@ public class ComputerUtilMana {
String originalProduced = manaProduced.toString(); String originalProduced = manaProduced.toString();
if (originalProduced.isEmpty()) { if (originalProduced.isEmpty()) {
return manaProduced.toString(); return originalProduced;
} }
// Run triggers like Nissa // Run triggers like Nissa
final Map<AbilityKey, Object> runParams = AbilityKey.mapFromCard(hostCard); final Map<AbilityKey, Object> runParams = AbilityKey.mapFromCard(hostCard);
runParams.put(AbilityKey.Activator, ai); // assuming AI would only ever gives itself mana runParams.put(AbilityKey.Activator, ai); // assuming AI would only ever gives itself mana
runParams.put(AbilityKey.AbilityMana, saPayment); runParams.put(AbilityKey.AbilityMana, saPayment);
runParams.put(AbilityKey.Produced, manaProduced.toString()); runParams.put(AbilityKey.Produced, originalProduced);
for (Trigger tr : ai.getGame().getTriggerHandler().getActiveTrigger(TriggerType.TapsForMana, runParams)) { for (Trigger tr : ai.getGame().getTriggerHandler().getActiveTrigger(TriggerType.TapsForMana, runParams)) {
SpellAbility trSA = tr.ensureAbility(); SpellAbility trSA = tr.ensureAbility();
if (trSA == null) { if (trSA == null) {
@@ -1292,11 +1292,11 @@ public class ComputerUtilMana {
* @return ManaCost * @return ManaCost
*/ */
public static ManaCostBeingPaid calculateManaCost(final Cost cost, final SpellAbility sa, final boolean test, final int extraMana, final boolean effect) { public static ManaCostBeingPaid calculateManaCost(final Cost cost, final SpellAbility sa, final boolean test, final int extraMana, final boolean effect) {
Card card = sa.getHostCard(); Card host = sa.getHostCard();
Zone castFromBackup = null; Zone castFromBackup = null;
if (test && sa.isSpell() && !card.isInZone(ZoneType.Stack)) { if (test && sa.isSpell() && !host.isInZone(ZoneType.Stack)) {
castFromBackup = card.getCastFrom(); castFromBackup = host.getCastFrom();
card.setCastFrom(card.getZone() != null ? card.getZone() : null); host.setCastFrom(host.getZone() != null ? host.getZone() : null);
} }
Cost payCosts; Cost payCosts;
@@ -1319,7 +1319,7 @@ public class ComputerUtilMana {
final int multiplicator = Math.max(xCounter, 1); final int multiplicator = Math.max(xCounter, 1);
manaToAdd = extraMana * multiplicator; manaToAdd = extraMana * multiplicator;
} else { } else {
manaToAdd = AbilityUtils.calculateAmount(card, sa.getParamOrDefault("XAlternative", "X"), sa) * xCounter; manaToAdd = AbilityUtils.calculateAmount(host, sa.getParamOrDefault("XAlternative", "X"), sa) * xCounter;
} }
if (manaToAdd < 1 && payCosts != null && payCosts.getCostMana().getXMin() > 0) { if (manaToAdd < 1 && payCosts != null && payCosts.getCostMana().getXMin() > 0) {
@@ -1331,7 +1331,7 @@ public class ComputerUtilMana {
if (xColor == null) { if (xColor == null) {
xColor = "1"; xColor = "1";
} }
if (card.hasKeyword("Spend only colored mana on X. No more than one mana of each color may be spent this way.")) { if (host.hasKeyword("Spend only colored mana on X. No more than one mana of each color may be spent this way.")) {
xColor = "WUBRGX"; xColor = "WUBRGX";
} }
if (xCounter > 0) { if (xCounter > 0) {
@@ -1356,14 +1356,14 @@ public class ComputerUtilMana {
mCost = ManaCost.combine(mCost, mkCost); mCost = ManaCost.combine(mCost, mkCost);
ManaCostBeingPaid mcbp = new ManaCostBeingPaid(mCost); ManaCostBeingPaid mcbp = new ManaCostBeingPaid(mCost);
if (!canPayManaCost(mcbp, sa, sa.getActivatingPlayer(), true)) { if (!canPayManaCost(mcbp, sa, sa.getActivatingPlayer(), true)) {
sa.getHostCard().setSVar("NumTimes", "Number$" + i); host.setSVar("NumTimes", "Number$" + i);
break; break;
} }
} }
} }
if (test && sa.isSpell()) { if (test && sa.isSpell() && !host.isInZone(ZoneType.Stack)) {
sa.getHostCard().setCastFrom(castFromBackup); host.setCastFrom(castFromBackup);
} }
return manaCost; return manaCost;
@@ -1596,6 +1596,7 @@ public class ComputerUtilMana {
} }
// don't use abilities with dangerous drawbacks // don't use abilities with dangerous drawbacks
// TODO this has already been checked earlier
AbilitySub sub = m.getSubAbility(); AbilitySub sub = m.getSubAbility();
if (sub != null && !SpellApiToAi.Converter.get(sub).chkDrawbackWithSubs(ai, sub).willingToPlay()) { if (sub != null && !SpellApiToAi.Converter.get(sub).chkDrawbackWithSubs(ai, sub).willingToPlay()) {
continue; continue;

View File

@@ -411,15 +411,13 @@ public class AnimateAi extends SpellAbilityAi {
} }
if (logic.equals("ValuableAttackerOrBlocker")) { if (logic.equals("ValuableAttackerOrBlocker")) {
if (ph.inCombat()) { final Combat combat = ph.getCombat();
final Combat combat = ph.getCombat(); for (Card c : list) {
for (Card c : list) { Card animated = becomeAnimated(c, sa);
Card animated = becomeAnimated(c, sa); boolean isValuableAttacker = ph.is(PhaseType.COMBAT_BEGIN, ai) && ComputerUtilCard.doesSpecifiedCreatureAttackAI(ai, animated);
boolean isValuableAttacker = ph.is(PhaseType.MAIN1, ai) && ComputerUtilCard.doesSpecifiedCreatureAttackAI(ai, animated); boolean isValuableBlocker = combat != null && combat.getDefendingPlayers().contains(ai) && ComputerUtilCard.doesSpecifiedCreatureBlock(ai, animated);
boolean isValuableBlocker = combat != null && combat.getDefendingPlayers().contains(ai) && ComputerUtilCard.doesSpecifiedCreatureBlock(ai, animated); if (isValuableAttacker || isValuableBlocker)
if (isValuableAttacker || isValuableBlocker) return new AiAbilityDecision(100, AiPlayDecision.WillPlay);
return new AiAbilityDecision(100, AiPlayDecision.WillPlay);
}
} }
} }

View File

@@ -879,14 +879,12 @@ public final class GameActionUtil {
} else if (abMana.isComboMana()) { } else if (abMana.isComboMana()) {
// amount is already taken care of in resolve method for combination mana, just append baseMana // amount is already taken care of in resolve method for combination mana, just append baseMana
sb.append(baseMana); sb.append(baseMana);
} else if (StringUtils.isNumeric(baseMana)) {
sb.append(amount * Integer.parseInt(baseMana));
} else { } else {
if (StringUtils.isNumeric(baseMana)) { sb.append(baseMana);
sb.append(amount * Integer.parseInt(baseMana)); for (int i = 1; i < amount; i++) {
} else { sb.append(" ").append(baseMana);
sb.append(baseMana);
for (int i = 1; i < amount; i++) {
sb.append(" ").append(baseMana);
}
} }
} }
return sb.toString(); return sb.toString();

View File

@@ -3419,7 +3419,6 @@ public class AbilityUtils {
} }
public static int playerXProperty(final Player player, final String s, final Card source, CardTraitBase ctb) { public static int playerXProperty(final Player player, final String s, final Card source, CardTraitBase ctb) {
final String[] l = s.split("/"); final String[] l = s.split("/");
final String m = CardFactoryUtil.extractOperators(s); final String m = CardFactoryUtil.extractOperators(s);

View File

@@ -103,12 +103,10 @@ public class ManaReflectedEffect extends SpellAbilityEffect {
return "0"; return "0";
} else if (colors.size() == 1) { } else if (colors.size() == 1) {
baseMana = MagicColor.toShortString(colors.iterator().next()); baseMana = MagicColor.toShortString(colors.iterator().next());
} else if (colors.contains("colorless")) {
baseMana = MagicColor.toShortString(player.getController().chooseColorAllowColorless(Localizer.getInstance().getMessage("lblSelectManaProduce"), sa.getHostCard(), ColorSet.fromNames(colors)));
} else { } else {
if (colors.contains("colorless")) { baseMana = MagicColor.toShortString(player.getController().chooseColor(Localizer.getInstance().getMessage("lblSelectManaProduce"), sa, ColorSet.fromNames(colors)));
baseMana = MagicColor.toShortString(player.getController().chooseColorAllowColorless(Localizer.getInstance().getMessage("lblSelectManaProduce"), sa.getHostCard(), ColorSet.fromNames(colors)));
} else {
baseMana = MagicColor.toShortString(player.getController().chooseColor(Localizer.getInstance().getMessage("lblSelectManaProduce"), sa, ColorSet.fromNames(colors)));
}
} }
} else { } else {
colorMenu = ColorSet.fromMask(mask); colorMenu = ColorSet.fromMask(mask);
@@ -122,19 +120,16 @@ public class ManaReflectedEffect extends SpellAbilityEffect {
if (amount == 0) { if (amount == 0) {
sb.append("0"); sb.append("0");
} else if (StringUtils.isNumeric(baseMana)) {
// if baseMana is an integer(colorless), just multiply amount and baseMana
final int base = Integer.parseInt(baseMana);
sb.append(base * amount);
} else { } else {
if (StringUtils.isNumeric(baseMana)) { for (int i = 0; i < amount; i++) {
// if baseMana is an integer(colorless), just multiply amount if (i != 0) {
// and baseMana sb.append(" ");
final int base = Integer.parseInt(baseMana);
sb.append(base * amount);
} else {
for (int i = 0; i < amount; i++) {
if (i != 0) {
sb.append(" ");
}
sb.append(baseMana);
} }
sb.append(baseMana);
} }
} }
return sb.toString(); return sb.toString();

View File

@@ -192,10 +192,8 @@ public class AbilityManaPart implements java.io.Serializable {
} }
} }
// add the mana produced to the mana pool
manaPool.add(this.lastManaProduced); manaPool.add(this.lastManaProduced);
// Run triggers
final Map<AbilityKey, Object> runParams = AbilityKey.mapFromCard(source); final Map<AbilityKey, Object> runParams = AbilityKey.mapFromCard(source);
runParams.put(AbilityKey.Player, player); runParams.put(AbilityKey.Player, player);
runParams.put(AbilityKey.Produced, afterReplace); runParams.put(AbilityKey.Produced, afterReplace);
@@ -512,7 +510,7 @@ public class AbilityManaPart implements java.io.Serializable {
* @return a {@link java.lang.String} object. * @return a {@link java.lang.String} object.
*/ */
public final String mana(SpellAbility sa) { public final String mana(SpellAbility sa) {
if (isComboMana()) { // when asking combo, just go there if (isComboMana()) {
return getComboColors(sa); return getComboColors(sa);
} }
String produced = this.getOrigProduced(); String produced = this.getOrigProduced();

View File

@@ -58,10 +58,6 @@ public class TriggerHandler {
game = gameState; game = gameState;
} }
public final boolean hasDelayedTriggers() {
return !delayedTriggers.isEmpty();
}
public final void registerDelayedTrigger(final Trigger trig) { public final void registerDelayedTrigger(final Trigger trig) {
delayedTriggers.add(trig); delayedTriggers.add(trig);
} }

View File

@@ -2,7 +2,7 @@ Name:General Kreat, the Boltbringer
ManaCost:2 R ManaCost:2 R
Types:Legendary Creature Goblin Soldier Types:Legendary Creature Goblin Soldier
PT:2/2 PT:2/2
T:Mode$ AttackersDeclared | ValidAttackers$ Goblin.YouCtrl | Execute$ TrigToken | TriggerZones$ Battlefield | ActivationLimit$ 1 | TriggerDescription$ Whenever one or more Goblins you control attack, create a 1/1 red Goblin creature token that's tapped and attacking. T:Mode$ AttackersDeclared | ValidAttackers$ Goblin.YouCtrl | Execute$ TrigToken | TriggerZones$ Battlefield | TriggerDescription$ Whenever one or more Goblins you control attack, create a 1/1 red Goblin creature token that's tapped and attacking.
SVar:TrigToken:DB$ Token | TokenAmount$ 1 | TokenScript$ r_1_1_goblin | TokenOwner$ You | TokenTapped$ True | TokenAttacking$ True SVar:TrigToken:DB$ Token | TokenAmount$ 1 | TokenScript$ r_1_1_goblin | TokenOwner$ You | TokenTapped$ True | TokenAttacking$ True
T:Mode$ ChangesZone | ValidCard$ Creature.Other+YouCtrl | Destination$ Battlefield | TriggerZones$ Battlefield | Execute$ TrigDealDamage | TriggerDescription$ Whenever another creature you control enters, CARDNAME deals 1 damage to each opponent. T:Mode$ ChangesZone | ValidCard$ Creature.Other+YouCtrl | Destination$ Battlefield | TriggerZones$ Battlefield | Execute$ TrigDealDamage | TriggerDescription$ Whenever another creature you control enters, CARDNAME deals 1 damage to each opponent.
SVar:TrigDealDamage:DB$ DealDamage | Defined$ Player.Opponent | NumDmg$ 1 SVar:TrigDealDamage:DB$ DealDamage | Defined$ Player.Opponent | NumDmg$ 1

View File

@@ -1,7 +1,7 @@
Name:Synchronized Eviction Name:Synchronized Eviction
ManaCost:4 U ManaCost:4 U
Types:Instant Types:Instant
S:Mode$ ReduceCost | ValidCard$ Card.Self | Type$ Spell | Amount$ 2 | EffectZone$ All | CheckSVar$ X | SVarCompare$ GE2 | Description$ This spell costs {2} less to cast if you control two at least two creatures that share a creature type. S:Mode$ ReduceCost | ValidCard$ Card.Self | Type$ Spell | Amount$ 2 | EffectZone$ All | CheckSVar$ X | SVarCompare$ GE2 | Description$ This spell costs {2} less to cast if you control at least two creatures that share a creature type.
SVar:X:Count$MostProminentCreatureType Creature.YouCtrl SVar:X:Count$MostProminentCreatureType Creature.YouCtrl
A:SP$ ChangeZone | Origin$ Battlefield | Destination$ Library | ValidTgts$ Permanent.nonLand | TgtPrompt$ Select target nonland permanent | LibraryPosition$ 1 | SpellDescription$ Put target nonland permanent into its owner's library second from the top. A:SP$ ChangeZone | Origin$ Battlefield | Destination$ Library | ValidTgts$ Permanent.nonLand | TgtPrompt$ Select target nonland permanent | LibraryPosition$ 1 | SpellDescription$ Put target nonland permanent into its owner's library second from the top.
Oracle:This spell costs {2} less to cast if you control two at least two creatures that share a creature type.\nPut target nonland permanent into its owner's library second from the top. Oracle:This spell costs {2} less to cast if you control at least two creatures that share a creature type.\nPut target nonland permanent into its owner's library second from the top.