mirror of
https://github.com/magefree/mage.git
synced 2025-12-26 13:32:06 -08:00
fixed issue with Kruphix, God of Horizons and Horizon Stone causing endless replacement effect loop
This commit is contained in:
parent
51c9121f5e
commit
2ffa719278
7 changed files with 137 additions and 75 deletions
|
|
@ -17,7 +17,7 @@ import java.util.UUID;
|
|||
/**
|
||||
* @author nantuko
|
||||
*/
|
||||
public class ConditionalMana extends Mana implements Serializable {
|
||||
public class ConditionalMana extends Mana implements Serializable, Emptiable {
|
||||
|
||||
/**
|
||||
* Conditions that should be met (all or any depending on comparison scope)
|
||||
|
|
|
|||
15
Mage/src/main/java/mage/Emptiable.java
Normal file
15
Mage/src/main/java/mage/Emptiable.java
Normal file
|
|
@ -0,0 +1,15 @@
|
|||
package mage;
|
||||
|
||||
import mage.constants.ManaType;
|
||||
|
||||
/**
|
||||
* @author TheElk801
|
||||
*/
|
||||
public interface Emptiable {
|
||||
|
||||
public void add(ManaType manaType, int amount);
|
||||
|
||||
public void clear(ManaType manaType);
|
||||
|
||||
public int get(final ManaType manaType);
|
||||
}
|
||||
|
|
@ -1,6 +1,7 @@
|
|||
package mage.players;
|
||||
|
||||
import mage.ConditionalMana;
|
||||
import mage.Emptiable;
|
||||
import mage.MageObject;
|
||||
import mage.Mana;
|
||||
import mage.abilities.Ability;
|
||||
|
|
@ -37,6 +38,7 @@ public class ManaPool implements Serializable {
|
|||
private final List<ManaPoolItem> poolBookmark = new ArrayList<>(); // mana pool bookmark for rollback purposes
|
||||
|
||||
private final Set<ManaType> doNotEmptyManaTypes = new HashSet<>();
|
||||
private boolean manaBecomesColorless = false;
|
||||
|
||||
private static final class ConditionalManaInfo {
|
||||
private final ManaType manaType;
|
||||
|
|
@ -73,6 +75,7 @@ public class ManaPool implements Serializable {
|
|||
}
|
||||
this.doNotEmptyManaTypes.addAll(pool.doNotEmptyManaTypes);
|
||||
this.lastPaymentWasSnow = pool.lastPaymentWasSnow;
|
||||
this.manaBecomesColorless = pool.manaBecomesColorless;
|
||||
}
|
||||
|
||||
public int getRed() {
|
||||
|
|
@ -229,12 +232,21 @@ public class ManaPool implements Serializable {
|
|||
|
||||
public void clearEmptyManaPoolRules() {
|
||||
doNotEmptyManaTypes.clear();
|
||||
this.manaBecomesColorless = false;
|
||||
}
|
||||
|
||||
public void addDoNotEmptyManaType(ManaType manaType) {
|
||||
doNotEmptyManaTypes.add(manaType);
|
||||
}
|
||||
|
||||
public void setManaBecomesColorless(boolean manaBecomesColorless) {
|
||||
this.manaBecomesColorless = manaBecomesColorless;
|
||||
}
|
||||
|
||||
public boolean isManaBecomesColorless() {
|
||||
return manaBecomesColorless;
|
||||
}
|
||||
|
||||
public void init() {
|
||||
manaItems.clear();
|
||||
}
|
||||
|
|
@ -246,35 +258,15 @@ public class ManaPool implements Serializable {
|
|||
ManaPoolItem item = it.next();
|
||||
ConditionalMana conditionalItem = item.getConditionalMana();
|
||||
for (ManaType manaType : ManaType.values()) {
|
||||
if (!doNotEmptyManaTypes.contains(manaType)) {
|
||||
if (item.get(manaType) > 0) {
|
||||
if (item.getDuration() != Duration.EndOfTurn
|
||||
|| game.getPhase().getType() == TurnPhase.END) {
|
||||
if (game.replaceEvent(new GameEvent(GameEvent.EventType.EMPTY_MANA_POOL, playerId, null, playerId))) {
|
||||
int amount = item.get(manaType);
|
||||
item.clear(manaType);
|
||||
item.add(ManaType.COLORLESS, amount);
|
||||
} else {
|
||||
total += item.get(manaType);
|
||||
item.clear(manaType);
|
||||
}
|
||||
}
|
||||
}
|
||||
if (conditionalItem != null) {
|
||||
if (conditionalItem.get(manaType) > 0) {
|
||||
if (item.getDuration() != Duration.EndOfTurn
|
||||
|| game.getPhase().getType() == TurnPhase.END) {
|
||||
if (game.replaceEvent(new GameEvent(GameEvent.EventType.EMPTY_MANA_POOL, playerId, null, playerId))) {
|
||||
int amount = conditionalItem.get(manaType);
|
||||
conditionalItem.clear(manaType);
|
||||
conditionalItem.add(ManaType.COLORLESS, amount);
|
||||
} else {
|
||||
total += conditionalItem.get(manaType);
|
||||
conditionalItem.clear(manaType);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
if (doNotEmptyManaTypes.contains(manaType)) {
|
||||
continue;
|
||||
}
|
||||
if (item.get(manaType) > 0) {
|
||||
total += emptyItem(item, item, game, manaType);
|
||||
}
|
||||
if (conditionalItem != null
|
||||
&& conditionalItem.get(manaType) > 0) {
|
||||
total += emptyItem(item, conditionalItem, game, manaType);
|
||||
}
|
||||
}
|
||||
if (item.count() == 0) {
|
||||
|
|
@ -284,6 +276,22 @@ public class ManaPool implements Serializable {
|
|||
return total;
|
||||
}
|
||||
|
||||
private int emptyItem(ManaPoolItem item, Emptiable toEmpty, Game game, ManaType manaType) {
|
||||
if (item.getDuration() == Duration.EndOfTurn
|
||||
&& game.getPhase().getType() != TurnPhase.END) {
|
||||
return 0;
|
||||
}
|
||||
if (!manaBecomesColorless) {
|
||||
int amount = toEmpty.get(manaType);
|
||||
toEmpty.clear(manaType);
|
||||
return amount;
|
||||
}
|
||||
int amount = toEmpty.get(manaType);
|
||||
toEmpty.clear(manaType);
|
||||
toEmpty.add(ManaType.COLORLESS, amount);
|
||||
return 0;
|
||||
}
|
||||
|
||||
public Mana getMana() {
|
||||
Mana m = new Mana();
|
||||
for (ManaPoolItem item : manaItems) {
|
||||
|
|
|
|||
|
|
@ -5,6 +5,7 @@ import java.util.UUID;
|
|||
import mage.ConditionalMana;
|
||||
import mage.MageObject;
|
||||
import mage.Mana;
|
||||
import mage.Emptiable;
|
||||
import mage.constants.Duration;
|
||||
import mage.constants.ManaType;
|
||||
|
||||
|
|
@ -12,7 +13,7 @@ import mage.constants.ManaType;
|
|||
*
|
||||
* @author BetaSteward_at_googlemail.com
|
||||
*/
|
||||
public class ManaPoolItem implements Serializable {
|
||||
public class ManaPoolItem implements Serializable, Emptiable {
|
||||
|
||||
private int red = 0;
|
||||
private int green = 0;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue