mirror of
https://github.com/correl/mage.git
synced 2024-12-25 11:11:16 +00:00
* Hollow One - Fixed counting of discarded/cycled cards if returned to hand during a turn.
This commit is contained in:
parent
6d17199129
commit
d808b15569
2 changed files with 28 additions and 14 deletions
|
@ -35,17 +35,15 @@ import mage.abilities.common.SimpleStaticAbility;
|
|||
import mage.abilities.costs.mana.ManaCostsImpl;
|
||||
import mage.abilities.effects.common.cost.CostModificationEffectImpl;
|
||||
import mage.abilities.keyword.CyclingAbility;
|
||||
import mage.cards.Card;
|
||||
import mage.cards.CardImpl;
|
||||
import mage.cards.CardSetInfo;
|
||||
import mage.constants.CardType;
|
||||
import mage.constants.SubType;
|
||||
import mage.constants.CostModificationType;
|
||||
import mage.constants.Duration;
|
||||
import mage.constants.Outcome;
|
||||
import mage.constants.SubType;
|
||||
import mage.constants.Zone;
|
||||
import mage.game.Game;
|
||||
import mage.players.Player;
|
||||
import mage.util.CardUtil;
|
||||
import mage.watchers.common.CardsCycledOrDiscardedThisTurnWatcher;
|
||||
|
||||
|
@ -94,17 +92,9 @@ class HollowOneReductionEffect extends CostModificationEffectImpl {
|
|||
|
||||
@Override
|
||||
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());
|
||||
int reductionAmount = 0;
|
||||
if (controller != null
|
||||
&& watcher != null) {
|
||||
for (Card card : watcher.getCardsCycledOrDiscardedThisTurn(controller.getId()).getCards(game)) {
|
||||
if (card.getOwnerId().equals(controller.getId())) {
|
||||
reductionAmount++;
|
||||
}
|
||||
}
|
||||
CardUtil.reduceCost(abilityToModify, reductionAmount * 2);
|
||||
if (watcher != null) {
|
||||
CardUtil.reduceCost(abilityToModify, watcher.getNumberOfCardsCycledOrDiscardedThisTurn(source.getControllerId()) * 2);
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
|
|
|
@ -28,9 +28,12 @@
|
|||
package mage.watchers.common;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.HashSet;
|
||||
import java.util.Map;
|
||||
import java.util.Map.Entry;
|
||||
import java.util.Set;
|
||||
import java.util.UUID;
|
||||
import mage.MageObjectReference;
|
||||
import mage.cards.Card;
|
||||
import mage.cards.Cards;
|
||||
import mage.cards.CardsImpl;
|
||||
|
@ -47,6 +50,7 @@ import mage.watchers.Watcher;
|
|||
public class CardsCycledOrDiscardedThisTurnWatcher extends Watcher {
|
||||
|
||||
private final Map<UUID, Cards> cycledOrDiscardedCardsThisTurn = new HashMap<>();
|
||||
private final Map<UUID, Set<MageObjectReference>> numberOfCycledOrDiscardedCardsThisTurn = new HashMap<>();
|
||||
|
||||
public CardsCycledOrDiscardedThisTurnWatcher() {
|
||||
super(CardsCycledOrDiscardedThisTurnWatcher.class.getSimpleName(), WatcherScope.GAME);
|
||||
|
@ -57,11 +61,17 @@ public class CardsCycledOrDiscardedThisTurnWatcher extends Watcher {
|
|||
for (Entry<UUID, Cards> entry : watcher.cycledOrDiscardedCardsThisTurn.entrySet()) {
|
||||
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
|
||||
public void watch(GameEvent event, Game game) {
|
||||
if (event.getType() == GameEvent.EventType.DISCARDED_CARD
|
||||
if (event.getType() == GameEvent.EventType.DISCARDED_CARD
|
||||
|| event.getType() == GameEvent.EventType.CYCLED_CARD
|
||||
&& event.getPlayerId() != null) {
|
||||
Card card = game.getCard(event.getTargetId());
|
||||
|
@ -69,6 +79,12 @@ public class CardsCycledOrDiscardedThisTurnWatcher extends Watcher {
|
|||
Cards c = getCardsCycledOrDiscardedThisTurn(event.getPlayerId());
|
||||
c.add(card);
|
||||
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());
|
||||
}
|
||||
|
||||
public int getNumberOfCardsCycledOrDiscardedThisTurn(UUID playerId) {
|
||||
if (numberOfCycledOrDiscardedCardsThisTurn.containsKey(playerId)) {
|
||||
return numberOfCycledOrDiscardedCardsThisTurn.get(playerId).size();
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void reset() {
|
||||
super.reset();
|
||||
cycledOrDiscardedCardsThisTurn.clear();
|
||||
numberOfCycledOrDiscardedCardsThisTurn.clear();
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
Loading…
Reference in a new issue