Added treasure mana check (#7979)

* add treasure mana support to mana code

* [AFR] Implemented Hired Hexblade

* [AFR] Implemented Jaded Sell-Sword

* [AFR] Implemented Forsword Paladin

* added test

* fixed test failure

* another test fix

* completely reworked tracking mana sources
This commit is contained in:
Evan Kranzler 2021-07-06 19:43:32 -04:00 committed by GitHub
parent ddecfc388f
commit b4355b8f6e
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
21 changed files with 818 additions and 571 deletions

View file

@ -1,7 +1,6 @@
package mage.cards.b;
import mage.MageInt;
import mage.Mana;
import mage.abilities.Ability;
import mage.abilities.common.EntersBattlefieldTriggeredAbility;
import mage.abilities.effects.OneShotEffect;
@ -14,7 +13,7 @@ import mage.filter.FilterPermanent;
import mage.filter.predicate.Predicates;
import mage.game.Game;
import mage.target.TargetPermanent;
import mage.watchers.common.ManaSpentToCastWatcher;
import mage.watchers.common.ManaPaidSourceWatcher;
import java.util.UUID;
@ -47,7 +46,7 @@ public final class BergStrider extends CardImpl {
Ability ability = new EntersBattlefieldTriggeredAbility(new TapTargetEffect());
ability.addEffect(new BergStriderEffect());
ability.addTarget(new TargetPermanent(filter));
this.addAbility(ability);
this.addAbility(ability, new ManaPaidSourceWatcher());
}
private BergStrider(final BergStrider card) {
@ -79,15 +78,10 @@ class BergStriderEffect extends OneShotEffect {
@Override
public boolean apply(Game game, Ability source) {
ManaSpentToCastWatcher watcher = game.getState().getWatcher(ManaSpentToCastWatcher.class);
if (watcher == null) {
return false;
}
Mana payment = watcher.getAndResetLastPayment(source.getSourceId());
if (payment == null || payment.getSnow() < 1) {
return false;
}
if (ManaPaidSourceWatcher.getSnowPaid(source.getSourceId(), game) > 0) {
game.addEffect(new DontUntapInControllersNextUntapStepTargetEffect(), source);
return true;
}
return false;
}
}

View file

@ -18,6 +18,7 @@ import mage.game.permanent.Permanent;
import mage.players.Player;
import mage.target.TargetAmount;
import mage.target.common.TargetCreaturePermanentAmount;
import mage.watchers.common.ManaPaidSourceWatcher;
import java.util.UUID;
@ -33,6 +34,7 @@ public final class BlessingOfFrost extends CardImpl {
// Distribute X +1/+1 counters among any number of creatures you control, where X is the amount of {S} spent to cast this spell. Then draw a card for each creature you control with power 4 or greater.
this.getSpellAbility().addEffect(new BlessingOfFrostEffect());
this.getSpellAbility().addWatcher(new ManaPaidSourceWatcher());
}
private BlessingOfFrost(final BlessingOfFrost card) {
@ -75,7 +77,7 @@ class BlessingOfFrostEffect extends OneShotEffect {
if (player == null) {
return false;
}
int snow = source.getManaCostsToPay().getUsedManaToPay().getSnow();
int snow = ManaPaidSourceWatcher.getSnowPaid(source.getId(), game);
if (snow > 0) {
TargetAmount target = new TargetCreaturePermanentAmount(snow, StaticFilters.FILTER_CONTROLLED_CREATURE);
target.setNotTarget(true);

View file

@ -1,15 +1,13 @@
package mage.cards.b;
import java.util.UUID;
import mage.abilities.Ability;
import mage.abilities.Mode;
import mage.abilities.effects.OneShotEffect;
import mage.abilities.effects.common.DestroyAllEffect;
import mage.cards.Card;
import mage.constants.*;
import mage.cards.CardImpl;
import mage.cards.CardSetInfo;
import mage.constants.*;
import mage.filter.FilterCard;
import mage.filter.StaticFilters;
import mage.filter.predicate.Predicates;
@ -17,9 +15,11 @@ import mage.filter.predicate.mageobject.ManaValuePredicate;
import mage.game.Game;
import mage.players.Player;
import mage.target.common.TargetCardInYourGraveyard;
import mage.watchers.common.ManaPaidSourceWatcher;
import java.util.UUID;
/**
*
* @author weirddan455
*/
public final class BloodOnTheSnow extends CardImpl {
@ -45,6 +45,7 @@ public final class BloodOnTheSnow extends CardImpl {
"Then return a creature or planeswalker card with mana value X or less"
+ " from your graveyard to the battlefield, where X is the amount of {S} spent to cast this spell."
);
this.getSpellAbility().addWatcher(new ManaPaidSourceWatcher());
}
private BloodOnTheSnow(final BloodOnTheSnow card) {
@ -76,7 +77,7 @@ class BloodOnTheSnowEffect extends OneShotEffect {
public boolean apply(Game game, Ability source) {
Player controller = game.getPlayer(source.getControllerId());
if (controller != null) {
int snow = source.getManaCostsToPay().getUsedManaToPay().getSnow();
int snow = ManaPaidSourceWatcher.getSnowPaid(source.getId(), game);
FilterCard filter = new FilterCard("a creature or planeswalker card with mana value " + snow + " or less from your graveyard");
filter.add(Predicates.or(CardType.CREATURE.getPredicate(), CardType.PLANESWALKER.getPredicate()));
filter.add(new ManaValuePredicate(ComparisonType.FEWER_THAN, snow + 1));

View file

@ -16,6 +16,7 @@ import mage.game.events.EntersTheBattlefieldEvent;
import mage.game.events.GameEvent;
import mage.game.permanent.Permanent;
import mage.game.stack.Spell;
import mage.watchers.common.ManaPaidSourceWatcher;
import java.util.UUID;
@ -40,7 +41,7 @@ public final class BorealOutrider extends CardImpl {
), BorealOutriderCondition.instance, "Whenever you cast a creature spell, " +
"if {S} of any of that spell's colors was spent to cast it, that creature " +
"enters the battlefield with an additional +1/+1 counter on it."
));
), new ManaPaidSourceWatcher());
}
private BorealOutrider(final BorealOutrider card) {
@ -59,12 +60,7 @@ enum BorealOutriderCondition implements Condition {
@Override
public boolean apply(Game game, Ability source) {
Spell spell = (Spell) source.getEffects().get(0).getValue("spellCast");
return spell != null
&& spell
.getSpellAbility()
.getManaCostsToPay()
.getUsedManaToPay()
.checkSnow(spell.getColor(game));
return spell != null && ManaPaidSourceWatcher.checkSnowColor(spell, game);
}
}

View file

@ -0,0 +1,93 @@
package mage.cards.f;
import mage.MageInt;
import mage.abilities.Ability;
import mage.abilities.common.SimpleActivatedAbility;
import mage.abilities.costs.common.PayLifeCost;
import mage.abilities.costs.common.TapSourceCost;
import mage.abilities.costs.mana.ManaCostsImpl;
import mage.abilities.effects.OneShotEffect;
import mage.abilities.effects.common.CreateTokenEffect;
import mage.abilities.effects.common.continuous.BoostTargetEffect;
import mage.abilities.effects.common.continuous.GainAbilityTargetEffect;
import mage.abilities.keyword.DeathtouchAbility;
import mage.abilities.keyword.MenaceAbility;
import mage.cards.CardImpl;
import mage.cards.CardSetInfo;
import mage.constants.CardType;
import mage.constants.Duration;
import mage.constants.Outcome;
import mage.constants.SubType;
import mage.game.Game;
import mage.game.permanent.token.TreasureToken;
import mage.target.common.TargetCreaturePermanent;
import mage.watchers.common.ManaPaidSourceWatcher;
import java.util.UUID;
/**
* @author TheElk801
*/
public final class ForswornPaladin extends CardImpl {
public ForswornPaladin(UUID ownerId, CardSetInfo setInfo) {
super(ownerId, setInfo, new CardType[]{CardType.CREATURE}, "{B}");
this.subtype.add(SubType.HUMAN);
this.subtype.add(SubType.KNIGHT);
this.power = new MageInt(1);
this.toughness = new MageInt(1);
// Menace
this.addAbility(new MenaceAbility());
// {1}{B}, {T}, Pay 1 life: Create a Treasure token.
Ability ability = new SimpleActivatedAbility(new CreateTokenEffect(new TreasureToken()), new ManaCostsImpl<>("{1}{B}"));
ability.addCost(new TapSourceCost());
ability.addCost(new PayLifeCost(1));
this.addAbility(ability);
// {2}{B}: Target creature gets +2/+0 until end of turn. If mana from a Treasure was spent to activate this ability, that creature also gains deathtouch until end of turn.
ability = new SimpleActivatedAbility(
new BoostTargetEffect(2, 0), new ManaCostsImpl<>("{2}{B}")
);
ability.addEffect(new ForswornPaladinEffect());
ability.addTarget(new TargetCreaturePermanent());
this.addAbility(ability, new ManaPaidSourceWatcher());
}
private ForswornPaladin(final ForswornPaladin card) {
super(card);
}
@Override
public ForswornPaladin copy() {
return new ForswornPaladin(this);
}
}
class ForswornPaladinEffect extends OneShotEffect {
ForswornPaladinEffect() {
super(Outcome.Benefit);
staticText = "If mana from a Treasure was spent to activate this ability, " +
"that creature also gains deathtouch until end of turn.";
}
private ForswornPaladinEffect(final ForswornPaladinEffect effect) {
super(effect);
}
@Override
public ForswornPaladinEffect copy() {
return new ForswornPaladinEffect(this);
}
@Override
public boolean apply(Game game, Ability source) {
if (ManaPaidSourceWatcher.getTreasurePaid(source.getId(), game) > 0) {
game.addEffect(new GainAbilityTargetEffect(DeathtouchAbility.getInstance(), Duration.EndOfTurn), source);
}
return true;
}
}

View file

@ -9,6 +9,7 @@ import mage.constants.Outcome;
import mage.constants.SuperType;
import mage.game.Game;
import mage.players.Player;
import mage.watchers.common.ManaPaidSourceWatcher;
import java.util.UUID;
@ -24,6 +25,7 @@ public final class GravenLore extends CardImpl {
// Scry X, where is the amount of {S} spent to cast this spell, then draw three cards.
this.getSpellAbility().addEffect(new GravenLoreEffect());
this.getSpellAbility().addWatcher(new ManaPaidSourceWatcher());
}
private GravenLore(final GravenLore card) {
@ -58,7 +60,7 @@ class GravenLoreEffect extends OneShotEffect {
if (player == null) {
return false;
}
int snow = source.getManaCostsToPay().getUsedManaToPay().getSnow();
int snow = ManaPaidSourceWatcher.getSnowPaid(source.getId(), game);
if (snow > 0) {
player.scry(snow, source, game);
}

View file

@ -0,0 +1,49 @@
package mage.cards.h;
import mage.MageInt;
import mage.abilities.Ability;
import mage.abilities.common.EntersBattlefieldTriggeredAbility;
import mage.abilities.condition.common.TreasureSpentToCastCondition;
import mage.abilities.decorator.ConditionalInterveningIfTriggeredAbility;
import mage.abilities.effects.common.DrawCardSourceControllerEffect;
import mage.abilities.effects.common.LoseLifeSourceControllerEffect;
import mage.cards.CardImpl;
import mage.cards.CardSetInfo;
import mage.constants.CardType;
import mage.constants.SubType;
import mage.watchers.common.ManaPaidSourceWatcher;
import java.util.UUID;
/**
* @author TheElk801
*/
public final class HiredHexblade extends CardImpl {
public HiredHexblade(UUID ownerId, CardSetInfo setInfo) {
super(ownerId, setInfo, new CardType[]{CardType.CREATURE}, "{1}{B}");
this.subtype.add(SubType.ELF);
this.subtype.add(SubType.WARLOCK);
this.power = new MageInt(2);
this.toughness = new MageInt(2);
// When Hired Hexblade enters the battlefield, if mana from a Treasure was spent to cast it, you draw a card and you lose 1 life.
Ability ability = new ConditionalInterveningIfTriggeredAbility(
new EntersBattlefieldTriggeredAbility(new DrawCardSourceControllerEffect(1)),
TreasureSpentToCastCondition.instance, "When {this} enters the battlefield, " +
"if mana from a Treasure was spent to cast it, you draw a card and you lose 1 life."
);
ability.addEffect(new LoseLifeSourceControllerEffect(1));
this.addAbility(ability, new ManaPaidSourceWatcher());
}
private HiredHexblade(final HiredHexblade card) {
super(card);
}
@Override
public HiredHexblade copy() {
return new HiredHexblade(this);
}
}

View file

@ -0,0 +1,54 @@
package mage.cards.j;
import mage.MageInt;
import mage.abilities.Ability;
import mage.abilities.common.EntersBattlefieldTriggeredAbility;
import mage.abilities.condition.common.TreasureSpentToCastCondition;
import mage.abilities.decorator.ConditionalInterveningIfTriggeredAbility;
import mage.abilities.effects.common.continuous.GainAbilitySourceEffect;
import mage.abilities.keyword.FirstStrikeAbility;
import mage.abilities.keyword.HasteAbility;
import mage.cards.CardImpl;
import mage.cards.CardSetInfo;
import mage.constants.CardType;
import mage.constants.Duration;
import mage.constants.SubType;
import mage.watchers.common.ManaPaidSourceWatcher;
import java.util.UUID;
/**
* @author TheElk801
*/
public final class JadedSellSword extends CardImpl {
public JadedSellSword(UUID ownerId, CardSetInfo setInfo) {
super(ownerId, setInfo, new CardType[]{CardType.CREATURE}, "{3}{R}");
this.subtype.add(SubType.DRAGON);
this.subtype.add(SubType.WARRIOR);
this.power = new MageInt(4);
this.toughness = new MageInt(3);
// When Jaded Sell-Sword enters the battlefield, if mana from a Treasure was spent to cast it, it gains first strike and haste until end of turn.
Ability ability = new ConditionalInterveningIfTriggeredAbility(
new EntersBattlefieldTriggeredAbility(new GainAbilitySourceEffect(
FirstStrikeAbility.getInstance(), Duration.EndOfTurn
)), TreasureSpentToCastCondition.instance, "When {this} enters the battlefield, " +
"if mana from a Treasure was spent to cast it, it gains first strike and haste until end of turn."
);
ability.addEffect(new GainAbilitySourceEffect(
HasteAbility.getInstance(), Duration.EndOfTurn
));
this.addAbility(ability, new ManaPaidSourceWatcher());
}
private JadedSellSword(final JadedSellSword card) {
super(card);
}
@Override
public JadedSellSword copy() {
return new JadedSellSword(this);
}
}

View file

@ -13,6 +13,7 @@ import mage.filter.FilterCard;
import mage.filter.predicate.Predicate;
import mage.game.Game;
import mage.target.common.TargetCardInLibrary;
import mage.watchers.common.ManaPaidSourceWatcher;
import java.util.UUID;
@ -41,6 +42,7 @@ public final class SearchForGlory extends CardImpl {
this.getSpellAbility().addEffect(new GainLifeEffect(
SnowManaSpentValue.instance
).setText("You gain 1 life for each {S} spent to cast this spell"));
this.getSpellAbility().addWatcher(new ManaPaidSourceWatcher());
}
private SearchForGlory(final SearchForGlory card) {

View file

@ -13,6 +13,7 @@ import mage.constants.SuperType;
import mage.game.Game;
import mage.players.Player;
import mage.target.common.TargetCreatureOrPlaneswalker;
import mage.watchers.common.ManaPaidSourceWatcher;
import java.util.UUID;
@ -65,7 +66,7 @@ class TundraFumaroleEffect extends OneShotEffect {
if (player == null) {
return false;
}
int snow = source.getManaCostsToPay().getUsedManaToPay().getSnow();
int snow = ManaPaidSourceWatcher.getSnowPaid(source.getId(), game);
if (snow > 0) {
player.getManaPool().addMana(new Mana(ManaType.COLORLESS, snow), game, source, true);
}

View file

@ -83,6 +83,7 @@ public final class AdventuresInTheForgottenRealms extends ExpansionSet {
cards.add(new SetCardInfo("Flumph", 15, Rarity.RARE, mage.cards.f.Flumph.class));
cards.add(new SetCardInfo("Fly", 59, Rarity.UNCOMMON, mage.cards.f.Fly.class));
cards.add(new SetCardInfo("Forest", 278, Rarity.LAND, mage.cards.basiclands.Forest.class, NON_FULL_USE_VARIOUS));
cards.add(new SetCardInfo("Forsworn Paladin", 104, Rarity.RARE, mage.cards.f.ForswornPaladin.class));
cards.add(new SetCardInfo("Froghemoth", 184, Rarity.RARE, mage.cards.f.Froghemoth.class));
cards.add(new SetCardInfo("Gloom Stalker", 16, Rarity.COMMON, mage.cards.g.GloomStalker.class));
cards.add(new SetCardInfo("Gnoll Hunter", 185, Rarity.COMMON, mage.cards.g.GnollHunter.class));
@ -99,6 +100,7 @@ public final class AdventuresInTheForgottenRealms extends ExpansionSet {
cards.add(new SetCardInfo("Hama Pashar, Ruin Seeker", 224, Rarity.UNCOMMON, mage.cards.h.HamaPasharRuinSeeker.class));
cards.add(new SetCardInfo("Herald of Hadar", 108, Rarity.COMMON, mage.cards.h.HeraldOfHadar.class));
cards.add(new SetCardInfo("Hill Giant Herdgorger", 187, Rarity.COMMON, mage.cards.h.HillGiantHerdgorger.class));
cards.add(new SetCardInfo("Hired Hexblade", 109, Rarity.COMMON, mage.cards.h.HiredHexblade.class));
cards.add(new SetCardInfo("Hive of the Eye Tyrant", 258, Rarity.RARE, mage.cards.h.HiveOfTheEyeTyrant.class));
cards.add(new SetCardInfo("Hoarding Ogre", 146, Rarity.COMMON, mage.cards.h.HoardingOgre.class));
cards.add(new SetCardInfo("Hobgoblin Captain", 148, Rarity.COMMON, mage.cards.h.HobgoblinCaptain.class));
@ -110,6 +112,7 @@ public final class AdventuresInTheForgottenRealms extends ExpansionSet {
cards.add(new SetCardInfo("Intrepid Outlander", 191, Rarity.UNCOMMON, mage.cards.i.IntrepidOutlander.class));
cards.add(new SetCardInfo("Island", 266, Rarity.LAND, mage.cards.basiclands.Island.class, NON_FULL_USE_VARIOUS));
cards.add(new SetCardInfo("Iymrith, Desert Doom", 62, Rarity.MYTHIC, mage.cards.i.IymrithDesertDoom.class));
cards.add(new SetCardInfo("Jaded Sell-Sword", 152, Rarity.COMMON, mage.cards.j.JadedSellSword.class));
cards.add(new SetCardInfo("Kick in the Door", 153, Rarity.COMMON, mage.cards.k.KickInTheDoor.class));
cards.add(new SetCardInfo("Krydle of Baldur's Gate", 226, Rarity.UNCOMMON, mage.cards.k.KrydleOfBaldursGate.class));
cards.add(new SetCardInfo("Lightfoot Rogue", 111, Rarity.UNCOMMON, mage.cards.l.LightfootRogue.class));

View file

@ -1,6 +1,8 @@
package org.mage.test.cards.conditional;
import mage.abilities.keyword.FirstStrikeAbility;
import mage.abilities.keyword.HasteAbility;
import mage.constants.PhaseStep;
import mage.constants.Zone;
import org.junit.Test;
@ -86,4 +88,52 @@ public class ManaWasSpentToCastTest extends CardTestPlayerBase {
assertGraveyardCount(playerA, "Search for Glory", 1);
assertLife(playerA, 21);
}
@Test
public void testSnowMana3() {
addCard(Zone.BATTLEFIELD, playerA, "Snow-Covered Island");
addCard(Zone.BATTLEFIELD, playerA, "Island", 4);
addCard(Zone.BATTLEFIELD, playerB, "Silvercoat Lion");
addCard(Zone.HAND, playerA, "Berg Strider");
castSpell(1, PhaseStep.PRECOMBAT_MAIN, playerA, "Berg Strider");
setStopAt(2, PhaseStep.PRECOMBAT_MAIN);
execute();
assertAllCommandsUsed();
assertTapped("Silvercoat Lion", true);
}
@Test
public void testTreasureMana() {
addCard(Zone.BATTLEFIELD, playerA, "Mountain", 4);
addCard(Zone.HAND, playerA, "Jaded Sell-Sword");
addCard(Zone.HAND, playerA, "Strike It Rich", 1);
castSpell(1, PhaseStep.PRECOMBAT_MAIN, playerA, "Strike It Rich");
castSpell(1, PhaseStep.PRECOMBAT_MAIN, playerA, "Jaded Sell-Sword");
setStopAt(1, PhaseStep.END_TURN);
execute();
assertAllCommandsUsed();
assertAbility(playerA, "Jaded Sell-Sword", FirstStrikeAbility.getInstance(), true);
assertAbility(playerA, "Jaded Sell-Sword", HasteAbility.getInstance(), true);
}
@Test
public void testTreasureMana2() {
addCard(Zone.BATTLEFIELD, playerA, "Mountain", 4);
addCard(Zone.HAND, playerA, "Jaded Sell-Sword");
castSpell(1, PhaseStep.PRECOMBAT_MAIN, playerA, "Jaded Sell-Sword");
setStopAt(1, PhaseStep.END_TURN);
execute();
assertAllCommandsUsed();
assertAbility(playerA, "Jaded Sell-Sword", FirstStrikeAbility.getInstance(), false);
assertAbility(playerA, "Jaded Sell-Sword", HasteAbility.getInstance(), false);
}
}

View file

@ -334,7 +334,7 @@ public abstract class CardTestAPIImpl extends MageTestBase implements CardTestAP
for (Ability ability : abilities) {
Assert.assertTrue("No such ability=" + ability.toString() + ", player=" + player.getName() +
", cardName" + cardName, found.getAbilities().contains(ability));
", cardName=" + cardName, found.getAbilities().contains(ability));
}
}

View file

@ -113,25 +113,25 @@ public class ConditionalMana extends Mana implements Serializable, Emptiable {
return;
}
if (filter.isBlack()) {
black.clear();
black = 0;
}
if (filter.isBlue()) {
blue.clear();
blue = 0;
}
if (filter.isWhite()) {
white.clear();
white = 0;
}
if (filter.isGreen()) {
green.clear();
green = 0;
}
if (filter.isRed()) {
red.clear();
red = 0;
}
if (filter.isColorless()) {
colorless.clear();
colorless = 0;
}
if (filter.isGeneric()) {
generic.clear();
generic = 0;
}
}
@ -154,25 +154,25 @@ public class ConditionalMana extends Mana implements Serializable, Emptiable {
public void clear(ManaType manaType) {
switch (manaType) {
case BLACK:
black.clear();
black = 0;
break;
case BLUE:
blue.clear();
blue = 0;
break;
case GREEN:
green.clear();
green = 0;
break;
case RED:
red.clear();
red = 0;
break;
case WHITE:
white.clear();
white = 0;
break;
case GENERIC:
generic.clear();
generic = 0;
break;
case COLORLESS:
colorless.clear();
colorless = 0;
break;
}
}
@ -198,25 +198,25 @@ public class ConditionalMana extends Mana implements Serializable, Emptiable {
public void add(ManaType manaType, int amount) {
switch (manaType) {
case BLACK:
black.incrementAmount(amount, false);
black += amount;
break;
case BLUE:
blue.incrementAmount(amount, false);
blue += amount;
break;
case GREEN:
green.incrementAmount(amount, false);
green += amount;
break;
case RED:
red.incrementAmount(amount, false);
red += amount;
break;
case WHITE:
white.incrementAmount(amount, false);
white += amount;
break;
case COLORLESS:
colorless.incrementAmount(amount, false);
colorless += amount;
break;
case GENERIC:
generic.incrementAmount(amount, false);
generic += amount;
break;
}
}

File diff suppressed because it is too large Load diff

View file

@ -0,0 +1,22 @@
package mage.abilities.condition.common;
import mage.abilities.Ability;
import mage.abilities.condition.Condition;
import mage.constants.AbilityType;
import mage.game.Game;
import mage.watchers.common.ManaPaidSourceWatcher;
/**
* @author TheElk801
*/
public enum TreasureSpentToCastCondition implements Condition {
instance;
@Override
public boolean apply(Game game, Ability source) {
if (source.getAbilityType() == AbilityType.SPELL) {
return ManaPaidSourceWatcher.getTreasurePaid(source.getId(), game) > 0;
}
return ManaPaidSourceWatcher.getTreasurePaid(source.getSourceId(), game) > 0;
}
}

View file

@ -103,31 +103,31 @@ public abstract class ManaCostImpl extends CostImpl implements ManaCost {
switch (mana) {
case W:
if (pool.pay(ManaType.WHITE, ability, sourceFilter, game, costToPay, usedManaToPay)) {
this.payment.increaseWhite(1, pool.getLastPaymentWasSnow());
this.payment.increaseWhite();
return true;
}
break;
case U:
if (pool.pay(ManaType.BLUE, ability, sourceFilter, game, costToPay, usedManaToPay)) {
this.payment.increaseBlue(1, pool.getLastPaymentWasSnow());
this.payment.increaseBlue();
return true;
}
break;
case B:
if (pool.pay(ManaType.BLACK, ability, sourceFilter, game, costToPay, usedManaToPay)) {
this.payment.increaseBlack(1, pool.getLastPaymentWasSnow());
this.payment.increaseBlack();
return true;
}
break;
case R:
if (pool.pay(ManaType.RED, ability, sourceFilter, game, costToPay, usedManaToPay)) {
this.payment.increaseRed(1, pool.getLastPaymentWasSnow());
this.payment.increaseRed();
return true;
}
break;
case G:
if (pool.pay(ManaType.GREEN, ability, sourceFilter, game, costToPay, usedManaToPay)) {
this.payment.increaseGreen(1, pool.getLastPaymentWasSnow());
this.payment.increaseGreen();
return true;
}
break;
@ -139,7 +139,7 @@ public abstract class ManaCostImpl extends CostImpl implements ManaCost {
int conditionalCount = pool.getConditionalCount(ability, game, null, costToPay);
while (mana > payment.count() && (pool.count() > 0 || conditionalCount > 0)) {
if (pool.pay(ManaType.COLORLESS, ability, sourceFilter, game, costToPay, usedManaToPay)) {
this.payment.increaseColorless(1, pool.getLastPaymentWasSnow());
this.payment.increaseColorless();
}
break;
}
@ -155,7 +155,7 @@ public abstract class ManaCostImpl extends CostImpl implements ManaCost {
if ((filterMana == null || filterMana.isColorless()) && pool.pay(
ManaType.COLORLESS, ability, sourceFilter, game, costToPay, usedManaToPay
)) {
this.payment.increaseColorless(1, pool.getLastPaymentWasSnow());
this.payment.increaseColorless();
continue;
}
@ -163,7 +163,7 @@ public abstract class ManaCostImpl extends CostImpl implements ManaCost {
if ((filterMana == null || filterMana.isBlack()) && pool.pay(
ManaType.BLACK, ability, sourceFilter, game, costToPay, usedManaToPay
)) {
this.payment.increaseBlack(1, pool.getLastPaymentWasSnow());
this.payment.increaseBlack();
continue;
}
@ -171,7 +171,7 @@ public abstract class ManaCostImpl extends CostImpl implements ManaCost {
if ((filterMana == null || filterMana.isBlue()) && pool.pay(
ManaType.BLUE, ability, sourceFilter, game, costToPay, usedManaToPay
)) {
this.payment.increaseBlue(1, pool.getLastPaymentWasSnow());
this.payment.increaseBlue();
continue;
}
@ -179,7 +179,7 @@ public abstract class ManaCostImpl extends CostImpl implements ManaCost {
if ((filterMana == null || filterMana.isWhite()) && pool.pay(
ManaType.WHITE, ability, sourceFilter, game, costToPay, usedManaToPay
)) {
this.payment.increaseWhite(1, pool.getLastPaymentWasSnow());
this.payment.increaseWhite();
continue;
}
@ -187,7 +187,7 @@ public abstract class ManaCostImpl extends CostImpl implements ManaCost {
if ((filterMana == null || filterMana.isGreen()) && pool.pay(
ManaType.GREEN, ability, sourceFilter, game, costToPay, usedManaToPay
)) {
this.payment.increaseGreen(1, pool.getLastPaymentWasSnow());
this.payment.increaseGreen();
continue;
}
@ -195,7 +195,7 @@ public abstract class ManaCostImpl extends CostImpl implements ManaCost {
if ((filterMana == null || filterMana.isRed()) && pool.pay(
ManaType.RED, ability, sourceFilter, game, costToPay, usedManaToPay
)) {
this.payment.increaseRed(1, pool.getLastPaymentWasSnow());
this.payment.increaseRed();
continue;
}

View file

@ -1,12 +1,11 @@
package mage.abilities.dynamicvalue.common;
import mage.Mana;
import mage.abilities.Ability;
import mage.abilities.dynamicvalue.DynamicValue;
import mage.abilities.effects.Effect;
import mage.constants.AbilityType;
import mage.game.Game;
import mage.watchers.common.ManaSpentToCastWatcher;
import mage.watchers.common.ManaPaidSourceWatcher;
/**
* @author TheElk801
@ -17,17 +16,9 @@ public enum SnowManaSpentValue implements DynamicValue {
@Override
public int calculate(Game game, Ability sourceAbility, Effect effect) {
if (sourceAbility.getAbilityType() == AbilityType.SPELL) {
return sourceAbility.getManaCostsToPay().getUsedManaToPay().getSnow();
return ManaPaidSourceWatcher.getSnowPaid(sourceAbility.getId(), game);
}
ManaSpentToCastWatcher watcher = game.getState().getWatcher(ManaSpentToCastWatcher.class);
if (watcher == null) {
return 0;
}
Mana payment = watcher.getAndResetLastPayment(sourceAbility.getSourceId());
if (payment == null) {
return 0;
}
return payment.getSnow();
return ManaPaidSourceWatcher.getSnowPaid(sourceAbility.getSourceId(), game);
}
@Override

View file

@ -1,6 +1,8 @@
package mage.game.events;
import mage.MageObject;
import mage.abilities.Ability;
import mage.constants.ManaType;
import java.util.UUID;
@ -9,9 +11,28 @@ import java.util.UUID;
*/
public class ManaPaidEvent extends GameEvent {
public ManaPaidEvent(Ability abilityToPay, UUID manaSourceId, boolean manaFlag, UUID manaOriginalId) {
private final UUID sourcePaidId;
private final MageObject sourceObject;
private final ManaType manaType;
public ManaPaidEvent(Ability abilityToPay, UUID manaSourceId, boolean manaFlag, UUID manaOriginalId, MageObject sourceObject, ManaType manaType) {
super(GameEvent.EventType.MANA_PAID, abilityToPay.getId(), null, abilityToPay.getControllerId(), 0, manaFlag);
this.setSourceId(manaSourceId);
this.setData(manaOriginalId.toString());
this.sourcePaidId = abilityToPay.getSourceId();
this.sourceObject = sourceObject;
this.manaType = manaType;
}
public UUID getSourcePaidId() {
return sourcePaidId;
}
public MageObject getSourceObject() {
return sourceObject;
}
public ManaType getManaType() {
return manaType;
}
}

View file

@ -50,15 +50,12 @@ public class ManaPool implements Serializable {
}
}
private boolean lastPaymentWasSnow;
public ManaPool(UUID playerId) {
this.playerId = playerId;
autoPayment = true;
autoPaymentRestricted = true;
unlockedManaType = null;
forcedToPay = false;
lastPaymentWasSnow = false;
}
public ManaPool(final ManaPool pool) {
@ -74,7 +71,6 @@ public class ManaPool implements Serializable {
poolBookmark.add(item.copy());
}
this.doNotEmptyManaTypes.addAll(pool.doNotEmptyManaTypes);
this.lastPaymentWasSnow = pool.lastPaymentWasSnow;
this.manaBecomesColorless = pool.manaBecomesColorless;
}
@ -109,7 +105,6 @@ public class ManaPool implements Serializable {
* @return
*/
public boolean pay(ManaType manaType, Ability ability, Filter filter, Game game, Cost costToPay, Mana usedManaToPay) {
lastPaymentWasSnow = false;
if (!isAutoPayment() && manaType != unlockedManaType) {
// if manual payment and the needed mana type was not unlocked, nothing will be paid
return false;
@ -139,7 +134,6 @@ public class ManaPool implements Serializable {
lockManaType(); // pay only one mana if mana payment is set to manually
return true;
}
lastPaymentWasSnow = false;
for (ManaPoolItem mana : manaItems) {
if (filter != null) {
@ -164,11 +158,10 @@ public class ManaPool implements Serializable {
continue;
}
if (mana.get(usableManaType) > 0) {
GameEvent event = new ManaPaidEvent(ability, mana.getSourceId(), mana.getFlag(), mana.getOriginalId());
GameEvent event = new ManaPaidEvent(ability, mana.getSourceId(), mana.getFlag(), mana.getOriginalId(), mana.getSourceObject(), usableManaType);
game.fireEvent(event);
usedManaToPay.increase(usableManaType, mana.getSourceObject().isSnow());
usedManaToPay.increase(usableManaType);
mana.remove(usableManaType);
lastPaymentWasSnow |= mana.getSourceObject().isSnow();
if (mana.count() == 0) { // so no items with count 0 stay in list
manaItems.remove(mana);
}
@ -410,8 +403,8 @@ public class ManaPool implements Serializable {
for (ConditionalMana mana : getConditionalMana()) {
if (mana.get(manaInfo.manaType) > 0 && mana.apply(ability, game, mana.getManaProducerId(), costToPay)) {
mana.set(manaInfo.manaType, CardUtil.overflowDec(mana.get(manaInfo.manaType), 1));
usedManaToPay.increase(manaInfo.manaType, manaInfo.sourceObject.isSnow());
GameEvent event = new ManaPaidEvent(ability, mana.getManaProducerId(), mana.getFlag(), mana.getManaProducerOriginalId());
usedManaToPay.increase(manaInfo.manaType);
GameEvent event = new ManaPaidEvent(ability, mana.getManaProducerId(), mana.getFlag(), mana.getManaProducerOriginalId(), manaInfo.sourceObject, manaInfo.manaType);
game.fireEvent(event);
break;
}
@ -528,10 +521,6 @@ public class ManaPool implements Serializable {
}
}
public boolean getLastPaymentWasSnow() {
return lastPaymentWasSnow;
}
@Override
public String toString() {
return getMana().toString();

View file

@ -0,0 +1,123 @@
package mage.watchers.common;
import mage.MageObject;
import mage.ObjectColor;
import mage.constants.ManaType;
import mage.constants.SubType;
import mage.constants.WatcherScope;
import mage.constants.Zone;
import mage.game.Game;
import mage.game.events.GameEvent;
import mage.game.events.ManaPaidEvent;
import mage.game.events.ZoneChangeEvent;
import mage.game.stack.Spell;
import mage.watchers.Watcher;
import java.io.Serializable;
import java.util.HashMap;
import java.util.Map;
import java.util.UUID;
/**
* @author TheElk801
*/
public class ManaPaidSourceWatcher extends Watcher {
private static final class ManaPaidTracker implements Serializable {
private int whiteSnow = 0;
private int blueSnow = 0;
private int blackSnow = 0;
private int redSnow = 0;
private int greenSnow = 0;
private int colorlessSnow = 0;
private int treasure = 0;
private void increment(MageObject sourceObject, ManaType manaType, Game game) {
if (sourceObject.hasSubtype(SubType.TREASURE, game)) {
treasure++;
}
if (!sourceObject.isSnow()) {
return;
}
switch (manaType) {
case WHITE:
whiteSnow++;
break;
case BLUE:
blueSnow++;
break;
case BLACK:
blackSnow++;
break;
case RED:
redSnow++;
break;
case GREEN:
greenSnow++;
break;
case COLORLESS:
case GENERIC:
colorlessSnow++;
break;
}
}
private int getSnow() {
return whiteSnow + blueSnow + blackSnow + redSnow + greenSnow + colorlessSnow;
}
private boolean checkSnowColor(Spell spell, Game game) {
ObjectColor color = spell.getColor(game);
return color.isWhite() && whiteSnow > 0
|| color.isBlue() && blueSnow > 0
|| color.isBlack() && blackSnow > 0
|| color.isRed() && redSnow > 0
|| color.isGreen() && greenSnow > 0;
}
}
private static final ManaPaidTracker emptyTracker = new ManaPaidTracker();
private final Map<UUID, ManaPaidTracker> manaMap = new HashMap<>();
public ManaPaidSourceWatcher() {
super(WatcherScope.GAME);
}
@Override
public void watch(GameEvent event, Game game) {
switch (event.getType()) {
case ZONE_CHANGE:
if (((ZoneChangeEvent) event).getFromZone() == Zone.BATTLEFIELD) {
manaMap.remove(event.getSourceId());
}
return;
case MANA_PAID:
ManaPaidEvent manaEvent = (ManaPaidEvent) event;
manaMap.computeIfAbsent(manaEvent.getTargetId(), x -> new ManaPaidTracker())
.increment(manaEvent.getSourceObject(), manaEvent.getManaType(), game);
manaMap.computeIfAbsent(manaEvent.getSourcePaidId(), x -> new ManaPaidTracker())
.increment(manaEvent.getSourceObject(), manaEvent.getManaType(), game);
}
}
@Override
public void reset() {
super.reset();
manaMap.clear();
}
public static int getTreasurePaid(UUID sourceId, Game game) {
ManaPaidSourceWatcher watcher = game.getState().getWatcher(ManaPaidSourceWatcher.class);
return watcher == null ? 0 : watcher.manaMap.getOrDefault(sourceId, emptyTracker).treasure;
}
public static int getSnowPaid(UUID sourceId, Game game) {
ManaPaidSourceWatcher watcher = game.getState().getWatcher(ManaPaidSourceWatcher.class);
return watcher == null ? 0 : watcher.manaMap.getOrDefault(sourceId, emptyTracker).getSnow();
}
public static boolean checkSnowColor(Spell spell, Game game) {
ManaPaidSourceWatcher watcher = game.getState().getWatcher(ManaPaidSourceWatcher.class);
return watcher != null && watcher.manaMap.getOrDefault(spell.getSpellAbility().getId(), emptyTracker).checkSnowColor(spell, game);
}
}