* Hollow One - Fixed counting of discarded/cycled cards if returned to hand during a turn.

This commit is contained in:
LevelX2 2017-12-28 16:52:51 +01:00
parent 6d17199129
commit d808b15569
2 changed files with 28 additions and 14 deletions

View file

@ -35,17 +35,15 @@ import mage.abilities.common.SimpleStaticAbility;
import mage.abilities.costs.mana.ManaCostsImpl; import mage.abilities.costs.mana.ManaCostsImpl;
import mage.abilities.effects.common.cost.CostModificationEffectImpl; import mage.abilities.effects.common.cost.CostModificationEffectImpl;
import mage.abilities.keyword.CyclingAbility; import mage.abilities.keyword.CyclingAbility;
import mage.cards.Card;
import mage.cards.CardImpl; import mage.cards.CardImpl;
import mage.cards.CardSetInfo; import mage.cards.CardSetInfo;
import mage.constants.CardType; import mage.constants.CardType;
import mage.constants.SubType;
import mage.constants.CostModificationType; import mage.constants.CostModificationType;
import mage.constants.Duration; import mage.constants.Duration;
import mage.constants.Outcome; import mage.constants.Outcome;
import mage.constants.SubType;
import mage.constants.Zone; import mage.constants.Zone;
import mage.game.Game; import mage.game.Game;
import mage.players.Player;
import mage.util.CardUtil; import mage.util.CardUtil;
import mage.watchers.common.CardsCycledOrDiscardedThisTurnWatcher; import mage.watchers.common.CardsCycledOrDiscardedThisTurnWatcher;
@ -94,17 +92,9 @@ class HollowOneReductionEffect extends CostModificationEffectImpl {
@Override @Override
public boolean apply(Game game, Ability source, Ability abilityToModify) { public boolean apply(Game game, Ability source, Ability abilityToModify) {
Player controller = game.getPlayer(source.getControllerId());
CardsCycledOrDiscardedThisTurnWatcher watcher = (CardsCycledOrDiscardedThisTurnWatcher) game.getState().getWatchers().get(CardsCycledOrDiscardedThisTurnWatcher.class.getSimpleName()); CardsCycledOrDiscardedThisTurnWatcher watcher = (CardsCycledOrDiscardedThisTurnWatcher) game.getState().getWatchers().get(CardsCycledOrDiscardedThisTurnWatcher.class.getSimpleName());
int reductionAmount = 0; if (watcher != null) {
if (controller != null CardUtil.reduceCost(abilityToModify, watcher.getNumberOfCardsCycledOrDiscardedThisTurn(source.getControllerId()) * 2);
&& watcher != null) {
for (Card card : watcher.getCardsCycledOrDiscardedThisTurn(controller.getId()).getCards(game)) {
if (card.getOwnerId().equals(controller.getId())) {
reductionAmount++;
}
}
CardUtil.reduceCost(abilityToModify, reductionAmount * 2);
return true; return true;
} }
return false; return false;

View file

@ -28,9 +28,12 @@
package mage.watchers.common; package mage.watchers.common;
import java.util.HashMap; import java.util.HashMap;
import java.util.HashSet;
import java.util.Map; import java.util.Map;
import java.util.Map.Entry; import java.util.Map.Entry;
import java.util.Set;
import java.util.UUID; import java.util.UUID;
import mage.MageObjectReference;
import mage.cards.Card; import mage.cards.Card;
import mage.cards.Cards; import mage.cards.Cards;
import mage.cards.CardsImpl; import mage.cards.CardsImpl;
@ -47,6 +50,7 @@ import mage.watchers.Watcher;
public class CardsCycledOrDiscardedThisTurnWatcher extends Watcher { public class CardsCycledOrDiscardedThisTurnWatcher extends Watcher {
private final Map<UUID, Cards> cycledOrDiscardedCardsThisTurn = new HashMap<>(); private final Map<UUID, Cards> cycledOrDiscardedCardsThisTurn = new HashMap<>();
private final Map<UUID, Set<MageObjectReference>> numberOfCycledOrDiscardedCardsThisTurn = new HashMap<>();
public CardsCycledOrDiscardedThisTurnWatcher() { public CardsCycledOrDiscardedThisTurnWatcher() {
super(CardsCycledOrDiscardedThisTurnWatcher.class.getSimpleName(), WatcherScope.GAME); super(CardsCycledOrDiscardedThisTurnWatcher.class.getSimpleName(), WatcherScope.GAME);
@ -57,6 +61,12 @@ public class CardsCycledOrDiscardedThisTurnWatcher extends Watcher {
for (Entry<UUID, Cards> entry : watcher.cycledOrDiscardedCardsThisTurn.entrySet()) { for (Entry<UUID, Cards> entry : watcher.cycledOrDiscardedCardsThisTurn.entrySet()) {
cycledOrDiscardedCardsThisTurn.put(entry.getKey(), entry.getValue().copy()); cycledOrDiscardedCardsThisTurn.put(entry.getKey(), entry.getValue().copy());
} }
for (Entry<UUID, Set<MageObjectReference>> entry : watcher.numberOfCycledOrDiscardedCardsThisTurn.entrySet()) {
Set<MageObjectReference> cycledOrDiscardedCards = new HashSet<>();
cycledOrDiscardedCards.addAll(entry.getValue());
numberOfCycledOrDiscardedCardsThisTurn.put(entry.getKey(), cycledOrDiscardedCards);
}
numberOfCycledOrDiscardedCardsThisTurn.putAll(watcher.numberOfCycledOrDiscardedCardsThisTurn);
} }
@Override @Override
@ -69,6 +79,12 @@ public class CardsCycledOrDiscardedThisTurnWatcher extends Watcher {
Cards c = getCardsCycledOrDiscardedThisTurn(event.getPlayerId()); Cards c = getCardsCycledOrDiscardedThisTurn(event.getPlayerId());
c.add(card); c.add(card);
cycledOrDiscardedCardsThisTurn.put(event.getPlayerId(), c); cycledOrDiscardedCardsThisTurn.put(event.getPlayerId(), c);
Set<MageObjectReference> cycledOrDiscardedCards = numberOfCycledOrDiscardedCardsThisTurn.get(event.getPlayerId());
if (cycledOrDiscardedCards == null) {
cycledOrDiscardedCards = new HashSet<>();
numberOfCycledOrDiscardedCardsThisTurn.put(event.getPlayerId(), cycledOrDiscardedCards);
}
cycledOrDiscardedCards.add(new MageObjectReference(card, game));
} }
} }
} }
@ -77,10 +93,18 @@ public class CardsCycledOrDiscardedThisTurnWatcher extends Watcher {
return cycledOrDiscardedCardsThisTurn.getOrDefault(playerId, new CardsImpl()); return cycledOrDiscardedCardsThisTurn.getOrDefault(playerId, new CardsImpl());
} }
public int getNumberOfCardsCycledOrDiscardedThisTurn(UUID playerId) {
if (numberOfCycledOrDiscardedCardsThisTurn.containsKey(playerId)) {
return numberOfCycledOrDiscardedCardsThisTurn.get(playerId).size();
}
return 0;
}
@Override @Override
public void reset() { public void reset() {
super.reset(); super.reset();
cycledOrDiscardedCardsThisTurn.clear(); cycledOrDiscardedCardsThisTurn.clear();
numberOfCycledOrDiscardedCardsThisTurn.clear();
} }
@Override @Override