Skip to content

Commit

Permalink
* Muldrotha, the Gravetide - Fixed a problem that the cast usage was …
Browse files Browse the repository at this point in the history
…checked by player instead by source (fixes #4969).
  • Loading branch information
LevelX2 committed May 27, 2018
1 parent 27ced16 commit 496609e
Showing 1 changed file with 14 additions and 10 deletions.
24 changes: 14 additions & 10 deletions Mage.Sets/src/mage/cards/m/MuldrothaTheGravetide.java
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
import java.util.UUID;
import mage.MageInt;
import mage.MageObject;
import mage.MageObjectReference;
import mage.abilities.Ability;
import mage.abilities.common.SimpleStaticAbility;
import mage.abilities.effects.AsThoughEffectImpl;
Expand Down Expand Up @@ -118,7 +119,8 @@ public boolean applies(UUID objectId, Ability source, UUID affectedControllerId,
if (mageObject != null && watcher != null) {
for (CardType cardType : mageObject.getCardType()) {
if (cardType.isPermanentType()) {
if (!watcher.permanentTypePlayedFromGraveyard(affectedControllerId, cardType)) {
MageObjectReference mor = new MageObjectReference(source.getSourceObject(game), game);
if (!watcher.permanentTypePlayedFromGraveyard(mor, cardType)) {
return true;
}
}
Expand All @@ -136,10 +138,12 @@ public boolean applies(UUID objectId, Ability source, UUID affectedControllerId,
*/
class MuldrothaTheGravetideWatcher extends Watcher {

// final HashMap<MageObjectReference, Set<CardType>> playerPlayedPermanentTypes = new HashMap<>(); // source that played permanent types from graveyard
final HashMap<UUID, Set<CardType>> playerPlayedPermanentTypes = new HashMap<>(); // player that played permanent types from graveyard
final HashMap<MageObjectReference, Set<CardType>> sourcePlayedPermanentTypes = new HashMap<>(); // source that played permanent types from graveyard
// final HashMap<UUID, Set<CardType>> playerPlayedPermanentTypes = new HashMap<>(); // player that played permanent types from graveyard
// 4/27/2018 If multiple effects allow you to play a card from your graveyard, such as those of Gisa and Geralf and Karador,
// Ghost Chieftain, you must announce which permission you’re using as you begin to play the card.
// 4/27/2018: If you play a card from your graveyard and then have a new Muldrotha come under your control in the same turn,
// you may play another card of that type from your graveyard that turn.
private Zone fromZone;

public MuldrothaTheGravetideWatcher() {
Expand All @@ -148,7 +152,7 @@ public MuldrothaTheGravetideWatcher() {

public MuldrothaTheGravetideWatcher(final MuldrothaTheGravetideWatcher watcher) {
super(watcher);
playerPlayedPermanentTypes.putAll(watcher.playerPlayedPermanentTypes);
sourcePlayedPermanentTypes.putAll(watcher.sourcePlayedPermanentTypes);
}

@Override
Expand All @@ -174,18 +178,18 @@ public void watch(GameEvent event, Game game) {
}

private void addPermanentTypes(GameEvent event, Card mageObject, Game game) {
if (mageObject != null) {
if (mageObject != null && event.getAdditionalReference() != null) {
UUID playerId = null;
if (mageObject instanceof Spell) {
playerId = ((Spell) mageObject).getControllerId();
} else if (mageObject instanceof Permanent) {
playerId = ((Permanent) mageObject).getControllerId();
}
if (playerId != null) {
Set<CardType> permanentTypes = playerPlayedPermanentTypes.get(playerId);
Set<CardType> permanentTypes = sourcePlayedPermanentTypes.get(event.getAdditionalReference());
if (permanentTypes == null) {
permanentTypes = EnumSet.noneOf(CardType.class);
playerPlayedPermanentTypes.put(playerId, permanentTypes);
sourcePlayedPermanentTypes.put(event.getAdditionalReference(), permanentTypes);
}
Set<CardType> typesNotCast = EnumSet.noneOf(CardType.class);
for (CardType cardType : mageObject.getCardType()) {
Expand Down Expand Up @@ -226,12 +230,12 @@ private void addPermanentTypes(GameEvent event, Card mageObject, Game game) {

@Override
public void reset() {
playerPlayedPermanentTypes.clear();
sourcePlayedPermanentTypes.clear();
super.reset();
}

public boolean permanentTypePlayedFromGraveyard(UUID playerId, CardType cardType) {
Set<CardType> permanentTypes = playerPlayedPermanentTypes.get(playerId);
public boolean permanentTypePlayedFromGraveyard(MageObjectReference sourceMor, CardType cardType) {
Set<CardType> permanentTypes = sourcePlayedPermanentTypes.get(sourceMor);
if (permanentTypes != null) {
return permanentTypes.contains(cardType);
}
Expand Down

0 comments on commit 496609e

Please sign in to comment.