Refactoring snow mana to allow tracking how much is spent (Ready for Review) (#7406)

* refactored mana methods to WUBRG order

* more WUBRG refactoring

* added new mana tracking object

* fixed code error

* fixed missing mana count

* fixed null pointer exception in tests

* fixed issue with equality

* more equality fixes

* some cosmetic changes to ManaTest

* added copy method to setToMana

* fixed some initialization issues

* fixed serialization issue

* [KHM] Implemented Search for Glory

* updated mana handling to track snow

* added tests for snow mana tracking

* updated implementation of setter methods

* updated paramater to use copy methods

* fixed snow mana test to ensure proper mana tapping

* replaced instances of getPayment with getUsedManaToPay

* updated tracking of snow mana

* reverted snow mana tracking removal

* finished reverting change
This commit is contained in:
Evan Kranzler 2021-01-21 18:13:51 -05:00 committed by GitHub
parent 5e4b5239d8
commit e5344b7a96
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
99 changed files with 1006 additions and 720 deletions

View file

@ -33,10 +33,10 @@ public enum AdamantCondition implements Condition {
if (coloredManaSymbol == null) {
return Arrays
.stream(ColoredManaSymbol.values())
.map(source.getManaCostsToPay().getPayment()::getColor)
.map(source.getManaCostsToPay().getUsedManaToPay()::getColor)
.anyMatch(i -> i > 2);
}
return source.getManaCostsToPay().getPayment().getColor(coloredManaSymbol) > 2;
return source.getManaCostsToPay().getUsedManaToPay().getColor(coloredManaSymbol) > 2;
}
ManaSpentToCastWatcher watcher = game.getState().getWatcher(ManaSpentToCastWatcher.class, source.getSourceId());
if (watcher == null) {

View file

@ -28,7 +28,7 @@ public class ManaWasSpentCondition implements Condition {
@Override
public boolean apply(Game game, Ability source) {
if (source.getAbilityType() == AbilityType.SPELL) {
return (source.getManaCostsToPay().getPayment().getColor(coloredManaSymbol) > 0);
return (source.getManaCostsToPay().getUsedManaToPay().getColor(coloredManaSymbol) > 0);
}
ManaSpentToCastWatcher watcher = game.getState().getWatcher(ManaSpentToCastWatcher.class, source.getSourceId());
if (watcher != null) {

View file

@ -73,6 +73,7 @@ public abstract class ManaCostImpl extends CostImpl implements ManaCost {
@Override
public void clearPaid() {
payment.clear();
usedManaToPay.clear();
super.clearPaid();
}
@ -100,33 +101,33 @@ public abstract class ManaCostImpl extends CostImpl implements ManaCost {
protected boolean assignColored(Ability ability, Game game, ManaPool pool, ColoredManaSymbol mana, Cost costToPay) {
// first check special mana
switch (mana) {
case B:
if (pool.pay(ManaType.BLACK, ability, sourceFilter, game, costToPay, usedManaToPay)) {
this.payment.increaseBlack();
case W:
if (pool.pay(ManaType.WHITE, ability, sourceFilter, game, costToPay, usedManaToPay)) {
this.payment.increaseWhite(1, pool.getLastPaymentWasSnow());
return true;
}
break;
case U:
if (pool.pay(ManaType.BLUE, ability, sourceFilter, game, costToPay, usedManaToPay)) {
this.payment.increaseBlue();
this.payment.increaseBlue(1, pool.getLastPaymentWasSnow());
return true;
}
break;
case W:
if (pool.pay(ManaType.WHITE, ability, sourceFilter, game, costToPay, usedManaToPay)) {
this.payment.increaseWhite();
return true;
}
break;
case G:
if (pool.pay(ManaType.GREEN, ability, sourceFilter, game, costToPay, usedManaToPay)) {
this.payment.increaseGreen();
case B:
if (pool.pay(ManaType.BLACK, ability, sourceFilter, game, costToPay, usedManaToPay)) {
this.payment.increaseBlack(1, pool.getLastPaymentWasSnow());
return true;
}
break;
case R:
if (pool.pay(ManaType.RED, ability, sourceFilter, game, costToPay, usedManaToPay)) {
this.payment.increaseRed();
this.payment.increaseRed(1, pool.getLastPaymentWasSnow());
return true;
}
break;
case G:
if (pool.pay(ManaType.GREEN, ability, sourceFilter, game, costToPay, usedManaToPay)) {
this.payment.increaseGreen(1, pool.getLastPaymentWasSnow());
return true;
}
break;
@ -138,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();
this.payment.increaseColorless(1, pool.getLastPaymentWasSnow());
}
break;
}
@ -151,38 +152,50 @@ public abstract class ManaCostImpl extends CostImpl implements ManaCost {
// filterMana can be null, uses for spells like "spend only black mana on X"
// {C}
if ((filterMana == null || filterMana.isColorless()) && pool.pay(ManaType.COLORLESS, ability, sourceFilter, game, costToPay, usedManaToPay)) {
this.payment.increaseColorless();
if ((filterMana == null || filterMana.isColorless()) && pool.pay(
ManaType.COLORLESS, ability, sourceFilter, game, costToPay, usedManaToPay
)) {
this.payment.increaseColorless(1, pool.getLastPaymentWasSnow());
continue;
}
// {B}
if ((filterMana == null || filterMana.isBlack()) && pool.pay(ManaType.BLACK, ability, sourceFilter, game, costToPay, usedManaToPay)) {
this.payment.increaseBlack();
if ((filterMana == null || filterMana.isBlack()) && pool.pay(
ManaType.BLACK, ability, sourceFilter, game, costToPay, usedManaToPay
)) {
this.payment.increaseBlack(1, pool.getLastPaymentWasSnow());
continue;
}
// {U}
if ((filterMana == null || filterMana.isBlue()) && pool.pay(ManaType.BLUE, ability, sourceFilter, game, costToPay, usedManaToPay)) {
this.payment.increaseBlue();
if ((filterMana == null || filterMana.isBlue()) && pool.pay(
ManaType.BLUE, ability, sourceFilter, game, costToPay, usedManaToPay
)) {
this.payment.increaseBlue(1, pool.getLastPaymentWasSnow());
continue;
}
// {W}
if ((filterMana == null || filterMana.isWhite()) && pool.pay(ManaType.WHITE, ability, sourceFilter, game, costToPay, usedManaToPay)) {
this.payment.increaseWhite();
if ((filterMana == null || filterMana.isWhite()) && pool.pay(
ManaType.WHITE, ability, sourceFilter, game, costToPay, usedManaToPay
)) {
this.payment.increaseWhite(1, pool.getLastPaymentWasSnow());
continue;
}
// {G}
if ((filterMana == null || filterMana.isGreen()) && pool.pay(ManaType.GREEN, ability, sourceFilter, game, costToPay, usedManaToPay)) {
this.payment.increaseGreen();
if ((filterMana == null || filterMana.isGreen()) && pool.pay(
ManaType.GREEN, ability, sourceFilter, game, costToPay, usedManaToPay
)) {
this.payment.increaseGreen(1, pool.getLastPaymentWasSnow());
continue;
}
// {R}
if ((filterMana == null || filterMana.isRed()) && pool.pay(ManaType.RED, ability, sourceFilter, game, costToPay, usedManaToPay)) {
this.payment.increaseRed();
if ((filterMana == null || filterMana.isRed()) && pool.pay(
ManaType.RED, ability, sourceFilter, game, costToPay, usedManaToPay
)) {
this.payment.increaseRed(1, pool.getLastPaymentWasSnow());
continue;
}

View file

@ -0,0 +1,49 @@
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;
/**
* @author TheElk801
*/
public enum SnowManaSpentValue implements DynamicValue {
instance;
@Override
public int calculate(Game game, Ability sourceAbility, Effect effect) {
if (sourceAbility.getAbilityType() == AbilityType.SPELL) {
return sourceAbility.getManaCostsToPay().getUsedManaToPay().getSnow();
}
ManaSpentToCastWatcher watcher = game.getState().getWatcher(
ManaSpentToCastWatcher.class, sourceAbility.getSourceId()
);
if (watcher == null) {
return 0;
}
Mana payment = watcher.getAndResetLastPayment();
if (payment == null) {
return 0;
}
return payment.getSnow();
}
@Override
public SnowManaSpentValue copy() {
return instance;
}
@Override
public String toString() {
return "1";
}
@Override
public String getMessage() {
return "{S} spent to cast this spell";
}
}

View file

@ -21,7 +21,7 @@ public enum SunburstCount implements DynamicValue {
if (!game.getStack().isEmpty()) {
StackObject spell = game.getStack().getFirst();
if (spell instanceof Spell && ((Spell) spell).getSourceId().equals(sourceAbility.getSourceId())) {
Mana mana = ((Spell) spell).getSpellAbility().getManaCostsToPay().getPayment();
Mana mana = ((Spell) spell).getSpellAbility().getManaCostsToPay().getUsedManaToPay();
if (mana.getBlack() > 0) {
count++;
}