* Urborg Justice - Fixed that tokens going to graveyard were not counted.

This commit is contained in:
LevelX2 2017-05-18 23:42:32 +02:00
parent 11ba007fd3
commit e090b26240
6 changed files with 168 additions and 177 deletions

View file

@ -137,7 +137,7 @@ class BontuTheGlorifiedRestrictionEffect extends RestrictionEffect {
CreaturesDiedWatcher watcher = (CreaturesDiedWatcher) game.getState().getWatchers().get(CreaturesDiedWatcher.class.getSimpleName()); CreaturesDiedWatcher watcher = (CreaturesDiedWatcher) game.getState().getWatchers().get(CreaturesDiedWatcher.class.getSimpleName());
if (controller != null if (controller != null
&& watcher != null) { && watcher != null) {
return (watcher.getAmountOfCreaturesDiesThisTurn(controller.getId()) == 0); return (watcher.getAmountOfCreaturesDiedThisTurnByController(controller.getId()) == 0);
} }
return true; return true;
} // do not apply to other creatures. } // do not apply to other creatures.

View file

@ -70,7 +70,7 @@ class FreshMeatDynamicValue implements DynamicValue {
public int calculate(Game game, Ability sourceAbility, Effect effect) { public int calculate(Game game, Ability sourceAbility, Effect effect) {
CreaturesDiedWatcher watcher = (CreaturesDiedWatcher) game.getState().getWatchers().get(CreaturesDiedWatcher.class.getSimpleName()); CreaturesDiedWatcher watcher = (CreaturesDiedWatcher) game.getState().getWatchers().get(CreaturesDiedWatcher.class.getSimpleName());
if (watcher != null) { if (watcher != null) {
return watcher.getAmountOfCreaturesDiesThisTurn(sourceAbility.getControllerId()); return watcher.getAmountOfCreaturesDiedThisTurnByController(sourceAbility.getControllerId());
} }
return 0; return 0;
} }

View file

@ -111,7 +111,7 @@ enum KuonOgreAscendantCondition implements Condition {
public boolean apply(Game game, Ability source) { public boolean apply(Game game, Ability source) {
CreaturesDiedWatcher watcher = (CreaturesDiedWatcher) game.getState().getWatchers().get(CreaturesDiedWatcher.class.getSimpleName()); CreaturesDiedWatcher watcher = (CreaturesDiedWatcher) game.getState().getWatchers().get(CreaturesDiedWatcher.class.getSimpleName());
if (watcher != null) { if (watcher != null) {
return watcher.getAmountOfCreaturesDiesThisTurn() > 2; return watcher.getAmountOfCreaturesDiedThisTurn() > 2;
} }
return false; return false;
} }

View file

@ -27,23 +27,19 @@
*/ */
package mage.cards.u; package mage.cards.u;
import java.util.Set;
import java.util.UUID; import java.util.UUID;
import mage.MageObjectReference;
import mage.abilities.Ability; import mage.abilities.Ability;
import mage.abilities.dynamicvalue.DynamicValue; import mage.abilities.dynamicvalue.DynamicValue;
import mage.abilities.effects.Effect; import mage.abilities.effects.Effect;
import mage.abilities.effects.common.SacrificeEffect; import mage.abilities.effects.common.SacrificeEffect;
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.filter.common.FilterCreaturePermanent; import mage.filter.common.FilterCreaturePermanent;
import mage.game.Game; import mage.game.Game;
import mage.players.Player;
import mage.target.common.TargetOpponent; import mage.target.common.TargetOpponent;
import mage.watchers.common.CardsPutIntoGraveyardWatcher; import mage.watchers.common.CreaturesDiedWatcher;
/** /**
* *
@ -52,10 +48,10 @@ import mage.watchers.common.CardsPutIntoGraveyardWatcher;
public class UrborgJustice extends CardImpl { public class UrborgJustice extends CardImpl {
public UrborgJustice(UUID ownerId, CardSetInfo setInfo) { public UrborgJustice(UUID ownerId, CardSetInfo setInfo) {
super(ownerId,setInfo,new CardType[]{CardType.INSTANT},"{B}{B}"); super(ownerId, setInfo, new CardType[]{CardType.INSTANT}, "{B}{B}");
// Target opponent sacrifices a creature for each creature put into your graveyard from the battlefield this turn. // Target opponent sacrifices a creature for each creature put into your graveyard from the battlefield this turn.
this.getSpellAbility().addWatcher(new CardsPutIntoGraveyardWatcher()); this.getSpellAbility().addWatcher(new CreaturesDiedWatcher());
SacrificeEffect sacrificeEffect = new SacrificeEffect(new FilterCreaturePermanent(), new UrborgJusticeDynamicValue(), ""); SacrificeEffect sacrificeEffect = new SacrificeEffect(new FilterCreaturePermanent(), new UrborgJusticeDynamicValue(), "");
sacrificeEffect.setText("Target opponent sacrifices a creature for each creature put into your graveyard from the battlefield this turn"); sacrificeEffect.setText("Target opponent sacrifices a creature for each creature put into your graveyard from the battlefield this turn");
@ -92,21 +88,10 @@ class UrborgJusticeDynamicValue implements DynamicValue {
@Override @Override
public int calculate(Game game, Ability sourceAbility, Effect effect) { public int calculate(Game game, Ability sourceAbility, Effect effect) {
CardsPutIntoGraveyardWatcher watcher = (CardsPutIntoGraveyardWatcher) game.getState().getWatchers().get(CardsPutIntoGraveyardWatcher.class.getSimpleName()); CreaturesDiedWatcher watcher = (CreaturesDiedWatcher) game.getState().getWatchers().get(CreaturesDiedWatcher.class.getSimpleName());
if (watcher != null) {
int count = 0; return watcher.getAmountOfCreaturesDiedThisTurnByOwner(sourceAbility.getControllerId());
Player controller = game.getPlayer(sourceAbility.getControllerId());
if (controller != null && watcher != null) {
Set<MageObjectReference> cardsInGraveyard = watcher.getCardsPutToGraveyardFromBattlefield();
for (MageObjectReference mor : cardsInGraveyard) {
if (game.getState().getZoneChangeCounter(mor.getSourceId()) == mor.getZoneChangeCounter()) {
Card card = game.getCard(mor.getSourceId());
if (card != null && card.getOwnerId().equals(sourceAbility.getControllerId()) && card.isCreature()) {
count++;
}
}
}
} }
return count; return 0;
} }
} }

View file

@ -42,7 +42,7 @@ public class CreaturesDiedThisTurnCount implements DynamicValue {
public int calculate(Game game, Ability sourceAbility, Effect effect) { public int calculate(Game game, Ability sourceAbility, Effect effect) {
CreaturesDiedWatcher watcher = (CreaturesDiedWatcher) game.getState().getWatchers().get(CreaturesDiedWatcher.class.getSimpleName()); CreaturesDiedWatcher watcher = (CreaturesDiedWatcher) game.getState().getWatchers().get(CreaturesDiedWatcher.class.getSimpleName());
if (watcher != null) { if (watcher != null) {
return watcher.getAmountOfCreaturesDiesThisTurn(); return watcher.getAmountOfCreaturesDiedThisTurn();
} }
return 0; return 0;
} }

View file

@ -29,8 +29,6 @@ package mage.watchers.common;
import java.util.HashMap; import java.util.HashMap;
import java.util.UUID; import java.util.UUID;
import java.util.stream.Collectors;
import mage.constants.WatcherScope; import mage.constants.WatcherScope;
import mage.game.Game; import mage.game.Game;
import mage.game.events.GameEvent; import mage.game.events.GameEvent;
@ -43,6 +41,7 @@ import mage.watchers.Watcher;
public class CreaturesDiedWatcher extends Watcher { public class CreaturesDiedWatcher extends Watcher {
private final HashMap<UUID, Integer> amountOfCreaturesThatDiedByController = new HashMap<>(); private final HashMap<UUID, Integer> amountOfCreaturesThatDiedByController = new HashMap<>();
private final HashMap<UUID, Integer> amountOfCreaturesThatDiedByOwner = new HashMap<>();
public CreaturesDiedWatcher() { public CreaturesDiedWatcher() {
super(CreaturesDiedWatcher.class.getSimpleName(), WatcherScope.GAME); super(CreaturesDiedWatcher.class.getSimpleName(), WatcherScope.GAME);
@ -51,6 +50,7 @@ public class CreaturesDiedWatcher extends Watcher {
public CreaturesDiedWatcher(final CreaturesDiedWatcher watcher) { public CreaturesDiedWatcher(final CreaturesDiedWatcher watcher) {
super(watcher); super(watcher);
this.amountOfCreaturesThatDiedByController.putAll(watcher.amountOfCreaturesThatDiedByController); this.amountOfCreaturesThatDiedByController.putAll(watcher.amountOfCreaturesThatDiedByController);
this.amountOfCreaturesThatDiedByOwner.putAll(watcher.amountOfCreaturesThatDiedByOwner);
} }
@Override @Override
@ -60,8 +60,10 @@ public class CreaturesDiedWatcher extends Watcher {
if (zEvent.isDiesEvent() if (zEvent.isDiesEvent()
&& zEvent.getTarget() != null && zEvent.getTarget() != null
&& zEvent.getTarget().isCreature()) { && zEvent.getTarget().isCreature()) {
int amount = getAmountOfCreaturesDiesThisTurn(zEvent.getTarget().getControllerId()); int amount = getAmountOfCreaturesDiedThisTurnByController(zEvent.getTarget().getControllerId());
amountOfCreaturesThatDiedByController.put(zEvent.getTarget().getControllerId(), amount + 1); amountOfCreaturesThatDiedByController.put(zEvent.getTarget().getControllerId(), amount + 1);
amount = getAmountOfCreaturesDiedThisTurnByOwner(zEvent.getTarget().getOwnerId());
amountOfCreaturesThatDiedByOwner.put(zEvent.getTarget().getOwnerId(), amount + 1);
} }
} }
} }
@ -69,19 +71,23 @@ public class CreaturesDiedWatcher extends Watcher {
@Override @Override
public void reset() { public void reset() {
amountOfCreaturesThatDiedByController.clear(); amountOfCreaturesThatDiedByController.clear();
amountOfCreaturesThatDiedByOwner.clear();
} }
public int getAmountOfCreaturesDiedThisTurnByController(UUID playerId) {
public int getAmountOfCreaturesDiesThisTurn(UUID playerId) {
return amountOfCreaturesThatDiedByController.getOrDefault(playerId, 0); return amountOfCreaturesThatDiedByController.getOrDefault(playerId, 0);
} }
public int getAmountOfCreaturesDiedThisTurnByOwner(UUID playerId) {
return amountOfCreaturesThatDiedByOwner.getOrDefault(playerId, 0);
}
@Override @Override
public CreaturesDiedWatcher copy() { public CreaturesDiedWatcher copy() {
return new CreaturesDiedWatcher(this); return new CreaturesDiedWatcher(this);
} }
public int getAmountOfCreaturesDiesThisTurn() { public int getAmountOfCreaturesDiedThisTurn() {
return amountOfCreaturesThatDiedByController.values().stream().mapToInt(x -> x).sum(); return amountOfCreaturesThatDiedByController.values().stream().mapToInt(x -> x).sum();
} }
} }