mirror of
https://github.com/correl/mage.git
synced 2024-12-25 03:00:15 +00:00
* Urborg Justice - Fixed that tokens going to graveyard were not counted.
This commit is contained in:
parent
11ba007fd3
commit
e090b26240
6 changed files with 168 additions and 177 deletions
|
@ -137,7 +137,7 @@ class BontuTheGlorifiedRestrictionEffect extends RestrictionEffect {
|
|||
CreaturesDiedWatcher watcher = (CreaturesDiedWatcher) game.getState().getWatchers().get(CreaturesDiedWatcher.class.getSimpleName());
|
||||
if (controller != null
|
||||
&& watcher != null) {
|
||||
return (watcher.getAmountOfCreaturesDiesThisTurn(controller.getId()) == 0);
|
||||
return (watcher.getAmountOfCreaturesDiedThisTurnByController(controller.getId()) == 0);
|
||||
}
|
||||
return true;
|
||||
} // do not apply to other creatures.
|
||||
|
|
|
@ -70,7 +70,7 @@ class FreshMeatDynamicValue implements DynamicValue {
|
|||
public int calculate(Game game, Ability sourceAbility, Effect effect) {
|
||||
CreaturesDiedWatcher watcher = (CreaturesDiedWatcher) game.getState().getWatchers().get(CreaturesDiedWatcher.class.getSimpleName());
|
||||
if (watcher != null) {
|
||||
return watcher.getAmountOfCreaturesDiesThisTurn(sourceAbility.getControllerId());
|
||||
return watcher.getAmountOfCreaturesDiedThisTurnByController(sourceAbility.getControllerId());
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
|
|
@ -111,7 +111,7 @@ enum KuonOgreAscendantCondition implements Condition {
|
|||
public boolean apply(Game game, Ability source) {
|
||||
CreaturesDiedWatcher watcher = (CreaturesDiedWatcher) game.getState().getWatchers().get(CreaturesDiedWatcher.class.getSimpleName());
|
||||
if (watcher != null) {
|
||||
return watcher.getAmountOfCreaturesDiesThisTurn() > 2;
|
||||
return watcher.getAmountOfCreaturesDiedThisTurn() > 2;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
|
|
@ -27,23 +27,19 @@
|
|||
*/
|
||||
package mage.cards.u;
|
||||
|
||||
import java.util.Set;
|
||||
import java.util.UUID;
|
||||
|
||||
import mage.MageObjectReference;
|
||||
import mage.abilities.Ability;
|
||||
import mage.abilities.dynamicvalue.DynamicValue;
|
||||
import mage.abilities.effects.Effect;
|
||||
import mage.abilities.effects.common.SacrificeEffect;
|
||||
import mage.cards.Card;
|
||||
import mage.cards.CardImpl;
|
||||
import mage.cards.CardSetInfo;
|
||||
import mage.constants.CardType;
|
||||
import mage.filter.common.FilterCreaturePermanent;
|
||||
import mage.game.Game;
|
||||
import mage.players.Player;
|
||||
import mage.target.common.TargetOpponent;
|
||||
import mage.watchers.common.CardsPutIntoGraveyardWatcher;
|
||||
import mage.watchers.common.CreaturesDiedWatcher;
|
||||
|
||||
/**
|
||||
*
|
||||
|
@ -55,7 +51,7 @@ public class UrborgJustice extends CardImpl {
|
|||
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.
|
||||
this.getSpellAbility().addWatcher(new CardsPutIntoGraveyardWatcher());
|
||||
this.getSpellAbility().addWatcher(new CreaturesDiedWatcher());
|
||||
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");
|
||||
|
||||
|
@ -92,21 +88,10 @@ class UrborgJusticeDynamicValue implements DynamicValue {
|
|||
|
||||
@Override
|
||||
public int calculate(Game game, Ability sourceAbility, Effect effect) {
|
||||
CardsPutIntoGraveyardWatcher watcher = (CardsPutIntoGraveyardWatcher) game.getState().getWatchers().get(CardsPutIntoGraveyardWatcher.class.getSimpleName());
|
||||
|
||||
int count = 0;
|
||||
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;
|
||||
CreaturesDiedWatcher watcher = (CreaturesDiedWatcher) game.getState().getWatchers().get(CreaturesDiedWatcher.class.getSimpleName());
|
||||
if (watcher != null) {
|
||||
return watcher.getAmountOfCreaturesDiedThisTurnByOwner(sourceAbility.getControllerId());
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -42,7 +42,7 @@ public class CreaturesDiedThisTurnCount implements DynamicValue {
|
|||
public int calculate(Game game, Ability sourceAbility, Effect effect) {
|
||||
CreaturesDiedWatcher watcher = (CreaturesDiedWatcher) game.getState().getWatchers().get(CreaturesDiedWatcher.class.getSimpleName());
|
||||
if (watcher != null) {
|
||||
return watcher.getAmountOfCreaturesDiesThisTurn();
|
||||
return watcher.getAmountOfCreaturesDiedThisTurn();
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
|
|
@ -29,8 +29,6 @@ package mage.watchers.common;
|
|||
|
||||
import java.util.HashMap;
|
||||
import java.util.UUID;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
import mage.constants.WatcherScope;
|
||||
import mage.game.Game;
|
||||
import mage.game.events.GameEvent;
|
||||
|
@ -43,6 +41,7 @@ import mage.watchers.Watcher;
|
|||
public class CreaturesDiedWatcher extends Watcher {
|
||||
|
||||
private final HashMap<UUID, Integer> amountOfCreaturesThatDiedByController = new HashMap<>();
|
||||
private final HashMap<UUID, Integer> amountOfCreaturesThatDiedByOwner = new HashMap<>();
|
||||
|
||||
public CreaturesDiedWatcher() {
|
||||
super(CreaturesDiedWatcher.class.getSimpleName(), WatcherScope.GAME);
|
||||
|
@ -51,6 +50,7 @@ public class CreaturesDiedWatcher extends Watcher {
|
|||
public CreaturesDiedWatcher(final CreaturesDiedWatcher watcher) {
|
||||
super(watcher);
|
||||
this.amountOfCreaturesThatDiedByController.putAll(watcher.amountOfCreaturesThatDiedByController);
|
||||
this.amountOfCreaturesThatDiedByOwner.putAll(watcher.amountOfCreaturesThatDiedByOwner);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -60,8 +60,10 @@ public class CreaturesDiedWatcher extends Watcher {
|
|||
if (zEvent.isDiesEvent()
|
||||
&& zEvent.getTarget() != null
|
||||
&& zEvent.getTarget().isCreature()) {
|
||||
int amount = getAmountOfCreaturesDiesThisTurn(zEvent.getTarget().getControllerId());
|
||||
int amount = getAmountOfCreaturesDiedThisTurnByController(zEvent.getTarget().getControllerId());
|
||||
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
|
||||
public void reset() {
|
||||
amountOfCreaturesThatDiedByController.clear();
|
||||
amountOfCreaturesThatDiedByOwner.clear();
|
||||
}
|
||||
|
||||
|
||||
public int getAmountOfCreaturesDiesThisTurn(UUID playerId) {
|
||||
public int getAmountOfCreaturesDiedThisTurnByController(UUID playerId) {
|
||||
return amountOfCreaturesThatDiedByController.getOrDefault(playerId, 0);
|
||||
}
|
||||
|
||||
public int getAmountOfCreaturesDiedThisTurnByOwner(UUID playerId) {
|
||||
return amountOfCreaturesThatDiedByOwner.getOrDefault(playerId, 0);
|
||||
}
|
||||
|
||||
@Override
|
||||
public CreaturesDiedWatcher copy() {
|
||||
return new CreaturesDiedWatcher(this);
|
||||
}
|
||||
|
||||
public int getAmountOfCreaturesDiesThisTurn() {
|
||||
public int getAmountOfCreaturesDiedThisTurn() {
|
||||
return amountOfCreaturesThatDiedByController.values().stream().mapToInt(x -> x).sum();
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue