mirror of
https://github.com/correl/mage.git
synced 2024-11-28 11:09:54 +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))) {
|
||||
int costX;
|
||||
if (card instanceof Permanent) {
|
||||
// permanent on battlefield
|
||||
costX = ManacostVariableValue.ETB.calculate(game, card.getSpellAbility(), null);
|
||||
// permanent on battlefield (can show x icon multiple turns, so use end_game source)
|
||||
costX = ManacostVariableValue.END_GAME.calculate(game, card.getSpellAbility(), null);
|
||||
} 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);
|
||||
}
|
||||
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)
|
||||
// cost x
|
||||
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));
|
||||
}
|
||||
}
|
||||
|
|
|
@ -146,7 +146,7 @@ class GlimpseTheCosmosReplacementEffect extends ReplacementEffectImpl {
|
|||
if (watcher == null) {
|
||||
return false;
|
||||
}
|
||||
Mana payment = watcher.getAndResetLastPayment(source.getSourceId());
|
||||
Mana payment = watcher.getLastManaPayment(source.getSourceId());
|
||||
if (payment != null
|
||||
&& payment.getBlue() == 1 // must be blue mana
|
||||
&& payment.count() == 1) { // must be just one
|
||||
|
|
|
@ -72,7 +72,7 @@ class RadiantEpicureEffect extends OneShotEffect {
|
|||
if (player == null || watcher == null) {
|
||||
return false;
|
||||
}
|
||||
Mana payment = watcher.getAndResetLastPayment(source.getSourceId());
|
||||
Mana payment = watcher.getLastManaPayment(source.getSourceId());
|
||||
if (payment == null) {
|
||||
return false;
|
||||
}
|
||||
|
|
|
@ -42,7 +42,7 @@ public enum AdamantCondition implements Condition {
|
|||
if (watcher == null) {
|
||||
return false;
|
||||
}
|
||||
Mana payment = watcher.getAndResetLastPayment(source.getSourceId());
|
||||
Mana payment = watcher.getLastManaPayment(source.getSourceId());
|
||||
if (payment == null) {
|
||||
return false;
|
||||
}
|
||||
|
|
|
@ -32,7 +32,7 @@ public class ManaWasSpentCondition implements Condition {
|
|||
}
|
||||
ManaSpentToCastWatcher watcher = game.getState().getWatcher(ManaSpentToCastWatcher.class);
|
||||
if (watcher != null) {
|
||||
Mana payment = watcher.getAndResetLastPayment(source.getSourceId());
|
||||
Mana payment = watcher.getLastManaPayment(source.getSourceId());
|
||||
if (payment != null) {
|
||||
return payment.getColor(coloredManaSymbol) > 0;
|
||||
}
|
||||
|
|
|
@ -8,8 +8,10 @@ import mage.watchers.common.ManaSpentToCastWatcher;
|
|||
|
||||
public enum ManacostVariableValue implements DynamicValue {
|
||||
|
||||
REGULAR, // if you need X on cast/activate (in stack)
|
||||
ETB; // if you need X after ETB (in battlefield)
|
||||
REGULAR, // if you need X on cast/activate (in stack) - reset each turn
|
||||
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
|
||||
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);
|
||||
if (watcher != null) {
|
||||
return watcher.getAndResetLastXValue(sourceAbility);
|
||||
if (this == END_GAME) {
|
||||
return watcher.getLastXValue(sourceAbility, true);
|
||||
} else {
|
||||
return watcher.getLastXValue(sourceAbility, false);
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
|
|
@ -17,6 +17,8 @@ import java.util.UUID;
|
|||
/**
|
||||
* Watcher saves the mana that was spent to cast a spell
|
||||
* automatically added in each game
|
||||
* <p>
|
||||
* Resets each turn
|
||||
*
|
||||
* @author LevelX2
|
||||
*/
|
||||
|
@ -24,6 +26,7 @@ public class ManaSpentToCastWatcher extends Watcher {
|
|||
|
||||
private final Map<UUID, Mana> manaMap = 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() {
|
||||
super(WatcherScope.GAME);
|
||||
|
@ -38,24 +41,34 @@ public class ManaSpentToCastWatcher extends Watcher {
|
|||
if (spell != null) {
|
||||
manaMap.put(spell.getSourceId(), spell.getSpellAbility().getManaCostsToPay().getUsedManaToPay());
|
||||
xValueMap.put(spell.getSourceId(), spell.getSpellAbility().getManaCostsToPay().getX());
|
||||
xValueMapLong.put(spell.getSourceId(), spell.getSpellAbility().getManaCostsToPay().getX());
|
||||
}
|
||||
return;
|
||||
case ZONE_CHANGE:
|
||||
if (((ZoneChangeEvent) event).getFromZone() == Zone.BATTLEFIELD) {
|
||||
manaMap.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);
|
||||
}
|
||||
|
||||
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
|
||||
return xValueMap.get(source.getSourceId());
|
||||
return xSource.get(source.getSourceId());
|
||||
} else {
|
||||
// put to battlefield without cast (example: copied spell must keep announced X)
|
||||
return source.getManaCostsToPay().getX();
|
||||
|
@ -67,5 +80,6 @@ public class ManaSpentToCastWatcher extends Watcher {
|
|||
super.reset();
|
||||
manaMap.clear();
|
||||
xValueMap.clear();
|
||||
// xValueMapLong.clear(); // must keep until game end, so don't clear between turns
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue