mirror of
https://github.com/correl/mage.git
synced 2025-03-16 01:06:34 -09:00
[KHM] fixed Invasion of the Giants not correctly counting spells for its third chapter (fixes #7664)
This commit is contained in:
parent
2775d6e74a
commit
7484b520e5
1 changed files with 40 additions and 6 deletions
|
@ -16,11 +16,15 @@ import mage.cards.CardSetInfo;
|
||||||
import mage.constants.*;
|
import mage.constants.*;
|
||||||
import mage.filter.FilterCard;
|
import mage.filter.FilterCard;
|
||||||
import mage.game.Game;
|
import mage.game.Game;
|
||||||
|
import mage.game.events.GameEvent;
|
||||||
|
import mage.game.stack.Spell;
|
||||||
import mage.target.common.TargetCardInHand;
|
import mage.target.common.TargetCardInHand;
|
||||||
import mage.target.common.TargetOpponentOrPlaneswalker;
|
import mage.target.common.TargetOpponentOrPlaneswalker;
|
||||||
import mage.util.CardUtil;
|
import mage.util.CardUtil;
|
||||||
import mage.watchers.common.CastSpellLastTurnWatcher;
|
import mage.watchers.Watcher;
|
||||||
|
|
||||||
|
import java.util.HashMap;
|
||||||
|
import java.util.Map;
|
||||||
import java.util.UUID;
|
import java.util.UUID;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -64,7 +68,7 @@ public final class InvasionOfTheGiants extends CardImpl {
|
||||||
// III — The next Giant spell you cast this turns costs {2} less to cast.
|
// III — The next Giant spell you cast this turns costs {2} less to cast.
|
||||||
sagaAbility.addChapterEffect(this, SagaChapter.CHAPTER_III, new InvasionOfTheGiantsEffect());
|
sagaAbility.addChapterEffect(this, SagaChapter.CHAPTER_III, new InvasionOfTheGiantsEffect());
|
||||||
|
|
||||||
this.addAbility(sagaAbility);
|
this.addAbility(sagaAbility, new InvasionOfTheGiantsWatcher());
|
||||||
}
|
}
|
||||||
|
|
||||||
private InvasionOfTheGiants(final InvasionOfTheGiants card) {
|
private InvasionOfTheGiants(final InvasionOfTheGiants card) {
|
||||||
|
@ -94,9 +98,9 @@ class InvasionOfTheGiantsEffect extends CostModificationEffectImpl {
|
||||||
@Override
|
@Override
|
||||||
public void init(Ability source, Game game) {
|
public void init(Ability source, Game game) {
|
||||||
super.init(source, game);
|
super.init(source, game);
|
||||||
CastSpellLastTurnWatcher watcher = game.getState().getWatcher(CastSpellLastTurnWatcher.class);
|
InvasionOfTheGiantsWatcher watcher = game.getState().getWatcher(InvasionOfTheGiantsWatcher.class);
|
||||||
if (watcher != null) {
|
if (watcher != null) {
|
||||||
spellsCast = watcher.getAmountOfSpellsPlayerCastOnCurrentTurn(source.getControllerId());
|
spellsCast = watcher.getCount(source.getControllerId());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -108,11 +112,11 @@ class InvasionOfTheGiantsEffect extends CostModificationEffectImpl {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean applies(Ability abilityToModify, Ability source, Game game) {
|
public boolean applies(Ability abilityToModify, Ability source, Game game) {
|
||||||
CastSpellLastTurnWatcher watcher = game.getState().getWatcher(CastSpellLastTurnWatcher.class);
|
InvasionOfTheGiantsWatcher watcher = game.getState().getWatcher(InvasionOfTheGiantsWatcher.class);
|
||||||
if (watcher == null) {
|
if (watcher == null) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
if (watcher.getAmountOfSpellsPlayerCastOnCurrentTurn(source.getControllerId()) > spellsCast) {
|
if (watcher.getCount(source.getControllerId()) > spellsCast) {
|
||||||
discard(); // only one use
|
discard(); // only one use
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
@ -129,3 +133,33 @@ class InvasionOfTheGiantsEffect extends CostModificationEffectImpl {
|
||||||
return new InvasionOfTheGiantsEffect(this);
|
return new InvasionOfTheGiantsEffect(this);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
class InvasionOfTheGiantsWatcher extends Watcher {
|
||||||
|
|
||||||
|
private final Map<UUID, Integer> playerMap = new HashMap<>();
|
||||||
|
|
||||||
|
InvasionOfTheGiantsWatcher() {
|
||||||
|
super(WatcherScope.GAME);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void watch(GameEvent event, Game game) {
|
||||||
|
if (event.getType() != GameEvent.EventType.SPELL_CAST) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
Spell spell = game.getSpell(event.getSourceId());
|
||||||
|
if (spell != null && spell.hasSubtype(SubType.GIANT, game)) {
|
||||||
|
playerMap.compute(event.getPlayerId(), (u, i) -> i == null ? 1 : Integer.sum(i, 1));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void reset() {
|
||||||
|
super.reset();
|
||||||
|
playerMap.clear();
|
||||||
|
}
|
||||||
|
|
||||||
|
int getCount(UUID playerId) {
|
||||||
|
return playerMap.getOrDefault(playerId, 0);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue