mirror of
https://github.com/correl/mage.git
synced 2024-11-25 03:00:11 +00:00
* GUI: fixed that announced X card icon info shows X=0 on next turns (example: Engineered Explosives, #8046);
This commit is contained in:
parent
debf310697
commit
cdf6fbb5d8
8 changed files with 35 additions and 15 deletions
|
@ -459,10 +459,10 @@ public class CardView extends SimpleCardView {
|
||||||
&& (cardZone.match(Zone.BATTLEFIELD) || cardZone.match(Zone.STACK))) {
|
&& (cardZone.match(Zone.BATTLEFIELD) || cardZone.match(Zone.STACK))) {
|
||||||
int costX;
|
int costX;
|
||||||
if (card instanceof Permanent) {
|
if (card instanceof Permanent) {
|
||||||
// permanent on battlefield
|
// permanent on battlefield (can show x icon multiple turns, so use end_game source)
|
||||||
costX = ManacostVariableValue.ETB.calculate(game, card.getSpellAbility(), null);
|
costX = ManacostVariableValue.END_GAME.calculate(game, card.getSpellAbility(), null);
|
||||||
} else {
|
} else {
|
||||||
// other like Stack
|
// other like Stack (can show x icon on stack only, so use normal source)
|
||||||
costX = ManacostVariableValue.REGULAR.calculate(game, card.getSpellAbility(), null);
|
costX = ManacostVariableValue.REGULAR.calculate(game, card.getSpellAbility(), null);
|
||||||
}
|
}
|
||||||
this.cardIcons.add(new VariableCostCardIcon(costX));
|
this.cardIcons.add(new VariableCostCardIcon(costX));
|
||||||
|
|
|
@ -79,7 +79,7 @@ public class StackAbilityView extends CardView {
|
||||||
// card icons (warning, it must be synced in gui dialogs with replaced card, see comments at the start of the file)
|
// card icons (warning, it must be synced in gui dialogs with replaced card, see comments at the start of the file)
|
||||||
// cost x
|
// cost x
|
||||||
if (ability.getManaCostsToPay().containsX()) {
|
if (ability.getManaCostsToPay().containsX()) {
|
||||||
int costX = ManacostVariableValue.REGULAR.calculate(game, ability, null);
|
int costX = ManacostVariableValue.END_GAME.calculate(game, ability, null);
|
||||||
this.cardIcons.add(new VariableCostCardIcon(costX));
|
this.cardIcons.add(new VariableCostCardIcon(costX));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -146,7 +146,7 @@ class GlimpseTheCosmosReplacementEffect extends ReplacementEffectImpl {
|
||||||
if (watcher == null) {
|
if (watcher == null) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
Mana payment = watcher.getAndResetLastPayment(source.getSourceId());
|
Mana payment = watcher.getLastManaPayment(source.getSourceId());
|
||||||
if (payment != null
|
if (payment != null
|
||||||
&& payment.getBlue() == 1 // must be blue mana
|
&& payment.getBlue() == 1 // must be blue mana
|
||||||
&& payment.count() == 1) { // must be just one
|
&& payment.count() == 1) { // must be just one
|
||||||
|
|
|
@ -72,7 +72,7 @@ class RadiantEpicureEffect extends OneShotEffect {
|
||||||
if (player == null || watcher == null) {
|
if (player == null || watcher == null) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
Mana payment = watcher.getAndResetLastPayment(source.getSourceId());
|
Mana payment = watcher.getLastManaPayment(source.getSourceId());
|
||||||
if (payment == null) {
|
if (payment == null) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
|
@ -42,7 +42,7 @@ public enum AdamantCondition implements Condition {
|
||||||
if (watcher == null) {
|
if (watcher == null) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
Mana payment = watcher.getAndResetLastPayment(source.getSourceId());
|
Mana payment = watcher.getLastManaPayment(source.getSourceId());
|
||||||
if (payment == null) {
|
if (payment == null) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
|
@ -32,7 +32,7 @@ public class ManaWasSpentCondition implements Condition {
|
||||||
}
|
}
|
||||||
ManaSpentToCastWatcher watcher = game.getState().getWatcher(ManaSpentToCastWatcher.class);
|
ManaSpentToCastWatcher watcher = game.getState().getWatcher(ManaSpentToCastWatcher.class);
|
||||||
if (watcher != null) {
|
if (watcher != null) {
|
||||||
Mana payment = watcher.getAndResetLastPayment(source.getSourceId());
|
Mana payment = watcher.getLastManaPayment(source.getSourceId());
|
||||||
if (payment != null) {
|
if (payment != null) {
|
||||||
return payment.getColor(coloredManaSymbol) > 0;
|
return payment.getColor(coloredManaSymbol) > 0;
|
||||||
}
|
}
|
||||||
|
|
|
@ -8,8 +8,10 @@ import mage.watchers.common.ManaSpentToCastWatcher;
|
||||||
|
|
||||||
public enum ManacostVariableValue implements DynamicValue {
|
public enum ManacostVariableValue implements DynamicValue {
|
||||||
|
|
||||||
REGULAR, // if you need X on cast/activate (in stack)
|
REGULAR, // if you need X on cast/activate (in stack) - reset each turn
|
||||||
ETB; // if you need X after ETB (in battlefield)
|
ETB, // if you need X after ETB (in battlefield) - reset each turn
|
||||||
|
END_GAME; // if you need X until end game - keep data forever
|
||||||
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public int calculate(Game game, Ability sourceAbility, Effect effect) {
|
public int calculate(Game game, Ability sourceAbility, Effect effect) {
|
||||||
|
@ -18,7 +20,11 @@ public enum ManacostVariableValue implements DynamicValue {
|
||||||
}
|
}
|
||||||
ManaSpentToCastWatcher watcher = game.getState().getWatcher(ManaSpentToCastWatcher.class);
|
ManaSpentToCastWatcher watcher = game.getState().getWatcher(ManaSpentToCastWatcher.class);
|
||||||
if (watcher != null) {
|
if (watcher != null) {
|
||||||
return watcher.getAndResetLastXValue(sourceAbility);
|
if (this == END_GAME) {
|
||||||
|
return watcher.getLastXValue(sourceAbility, true);
|
||||||
|
} else {
|
||||||
|
return watcher.getLastXValue(sourceAbility, false);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
|
@ -17,6 +17,8 @@ import java.util.UUID;
|
||||||
/**
|
/**
|
||||||
* Watcher saves the mana that was spent to cast a spell
|
* Watcher saves the mana that was spent to cast a spell
|
||||||
* automatically added in each game
|
* automatically added in each game
|
||||||
|
* <p>
|
||||||
|
* Resets each turn
|
||||||
*
|
*
|
||||||
* @author LevelX2
|
* @author LevelX2
|
||||||
*/
|
*/
|
||||||
|
@ -24,6 +26,7 @@ public class ManaSpentToCastWatcher extends Watcher {
|
||||||
|
|
||||||
private final Map<UUID, Mana> manaMap = new HashMap<>();
|
private final Map<UUID, Mana> manaMap = new HashMap<>();
|
||||||
private final Map<UUID, Integer> xValueMap = new HashMap<>();
|
private final Map<UUID, Integer> xValueMap = new HashMap<>();
|
||||||
|
private final Map<UUID, Integer> xValueMapLong = new HashMap<>(); // do not reset, keep until game end
|
||||||
|
|
||||||
public ManaSpentToCastWatcher() {
|
public ManaSpentToCastWatcher() {
|
||||||
super(WatcherScope.GAME);
|
super(WatcherScope.GAME);
|
||||||
|
@ -38,24 +41,34 @@ public class ManaSpentToCastWatcher extends Watcher {
|
||||||
if (spell != null) {
|
if (spell != null) {
|
||||||
manaMap.put(spell.getSourceId(), spell.getSpellAbility().getManaCostsToPay().getUsedManaToPay());
|
manaMap.put(spell.getSourceId(), spell.getSpellAbility().getManaCostsToPay().getUsedManaToPay());
|
||||||
xValueMap.put(spell.getSourceId(), spell.getSpellAbility().getManaCostsToPay().getX());
|
xValueMap.put(spell.getSourceId(), spell.getSpellAbility().getManaCostsToPay().getX());
|
||||||
|
xValueMapLong.put(spell.getSourceId(), spell.getSpellAbility().getManaCostsToPay().getX());
|
||||||
}
|
}
|
||||||
return;
|
return;
|
||||||
case ZONE_CHANGE:
|
case ZONE_CHANGE:
|
||||||
if (((ZoneChangeEvent) event).getFromZone() == Zone.BATTLEFIELD) {
|
if (((ZoneChangeEvent) event).getFromZone() == Zone.BATTLEFIELD) {
|
||||||
manaMap.remove(event.getSourceId());
|
manaMap.remove(event.getSourceId());
|
||||||
xValueMap.remove(event.getSourceId());
|
xValueMap.remove(event.getSourceId());
|
||||||
|
xValueMapLong.remove(event.getSourceId());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public Mana getAndResetLastPayment(UUID sourceId) {
|
public Mana getLastManaPayment(UUID sourceId) {
|
||||||
return manaMap.getOrDefault(sourceId, null);
|
return manaMap.getOrDefault(sourceId, null);
|
||||||
}
|
}
|
||||||
|
|
||||||
public int getAndResetLastXValue(Ability source) {
|
/**
|
||||||
if (xValueMap.containsKey(source.getSourceId())) {
|
* Return X value for casted spell or permanents
|
||||||
|
*
|
||||||
|
* @param source
|
||||||
|
* @param useLongSource - use X value that keeps until end of game (for info only)
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
public int getLastXValue(Ability source, boolean useLongSource) {
|
||||||
|
Map<UUID, Integer> xSource = useLongSource ? this.xValueMapLong : this.xValueMap;
|
||||||
|
if (xSource.containsKey(source.getSourceId())) {
|
||||||
// cast normal way
|
// cast normal way
|
||||||
return xValueMap.get(source.getSourceId());
|
return xSource.get(source.getSourceId());
|
||||||
} else {
|
} else {
|
||||||
// put to battlefield without cast (example: copied spell must keep announced X)
|
// put to battlefield without cast (example: copied spell must keep announced X)
|
||||||
return source.getManaCostsToPay().getX();
|
return source.getManaCostsToPay().getX();
|
||||||
|
@ -67,5 +80,6 @@ public class ManaSpentToCastWatcher extends Watcher {
|
||||||
super.reset();
|
super.reset();
|
||||||
manaMap.clear();
|
manaMap.clear();
|
||||||
xValueMap.clear();
|
xValueMap.clear();
|
||||||
|
// xValueMapLong.clear(); // must keep until game end, so don't clear between turns
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue