* 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

@ -1,146 +1,146 @@
/* /*
* Copyright 2010 BetaSteward_at_googlemail.com. All rights reserved. * Copyright 2010 BetaSteward_at_googlemail.com. All rights reserved.
* *
* Redistribution and use in source and binary forms, with or without modification, are * Redistribution and use in source and binary forms, with or without modification, are
* permitted provided that the following conditions are met: * permitted provided that the following conditions are met:
* *
* 1. Redistributions of source code must retain the above copyright notice, this list of * 1. Redistributions of source code must retain the above copyright notice, this list of
* conditions and the following disclaimer. * conditions and the following disclaimer.
* *
* 2. Redistributions in binary form must reproduce the above copyright notice, this list * 2. Redistributions in binary form must reproduce the above copyright notice, this list
* of conditions and the following disclaimer in the documentation and/or other materials * of conditions and the following disclaimer in the documentation and/or other materials
* provided with the distribution. * provided with the distribution.
* *
* THIS SOFTWARE IS PROVIDED BY BetaSteward_at_googlemail.com ``AS IS'' AND ANY EXPRESS OR IMPLIED * THIS SOFTWARE IS PROVIDED BY BetaSteward_at_googlemail.com ``AS IS'' AND ANY EXPRESS OR IMPLIED
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
* FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL BetaSteward_at_googlemail.com OR * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL BetaSteward_at_googlemail.com OR
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
* ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
* *
* The views and conclusions contained in the software and documentation are those of the * The views and conclusions contained in the software and documentation are those of the
* authors and should not be interpreted as representing official policies, either expressed * authors and should not be interpreted as representing official policies, either expressed
* or implied, of BetaSteward_at_googlemail.com. * or implied, of BetaSteward_at_googlemail.com.
*/ */
package mage.cards.b; package mage.cards.b;
import java.util.UUID; import java.util.UUID;
import mage.MageInt; import mage.MageInt;
import mage.abilities.Ability; import mage.abilities.Ability;
import mage.abilities.common.SimpleActivatedAbility; import mage.abilities.common.SimpleActivatedAbility;
import mage.abilities.common.SimpleStaticAbility; import mage.abilities.common.SimpleStaticAbility;
import mage.abilities.costs.common.SacrificeTargetCost; import mage.abilities.costs.common.SacrificeTargetCost;
import mage.abilities.costs.mana.ManaCostsImpl; import mage.abilities.costs.mana.ManaCostsImpl;
import mage.abilities.effects.Effect; import mage.abilities.effects.Effect;
import mage.abilities.effects.RestrictionEffect; import mage.abilities.effects.RestrictionEffect;
import mage.abilities.effects.common.GainLifeEffect; import mage.abilities.effects.common.GainLifeEffect;
import mage.abilities.effects.common.LoseLifeOpponentsEffect; import mage.abilities.effects.common.LoseLifeOpponentsEffect;
import mage.abilities.effects.keyword.ScryEffect; import mage.abilities.effects.keyword.ScryEffect;
import mage.abilities.keyword.IndestructibleAbility; import mage.abilities.keyword.IndestructibleAbility;
import mage.abilities.keyword.MenaceAbility; import mage.abilities.keyword.MenaceAbility;
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.Duration; import mage.constants.Duration;
import mage.constants.SuperType; import mage.constants.SuperType;
import mage.constants.Zone; import mage.constants.Zone;
import mage.filter.common.FilterControlledCreaturePermanent; import mage.filter.common.FilterControlledCreaturePermanent;
import mage.filter.predicate.permanent.AnotherPredicate; import mage.filter.predicate.permanent.AnotherPredicate;
import mage.game.Game; import mage.game.Game;
import mage.game.permanent.Permanent; import mage.game.permanent.Permanent;
import mage.players.Player; import mage.players.Player;
import mage.target.common.TargetControlledPermanent; import mage.target.common.TargetControlledPermanent;
import mage.watchers.common.CreaturesDiedWatcher; import mage.watchers.common.CreaturesDiedWatcher;
/** /**
* *
* @author jeffwadsworth * @author jeffwadsworth
*/ */
public class BontuTheGlorified extends CardImpl { public class BontuTheGlorified extends CardImpl {
private static final FilterControlledCreaturePermanent filter = new FilterControlledCreaturePermanent("another creature"); private static final FilterControlledCreaturePermanent filter = new FilterControlledCreaturePermanent("another creature");
static { static {
filter.add(new AnotherPredicate()); filter.add(new AnotherPredicate());
} }
public BontuTheGlorified(UUID ownerId, CardSetInfo setInfo) { public BontuTheGlorified(UUID ownerId, CardSetInfo setInfo) {
super(ownerId, setInfo, new CardType[]{CardType.CREATURE}, "{2}{B}"); super(ownerId, setInfo, new CardType[]{CardType.CREATURE}, "{2}{B}");
addSuperType(SuperType.LEGENDARY); addSuperType(SuperType.LEGENDARY);
this.subtype.add("God"); this.subtype.add("God");
this.power = new MageInt(4); this.power = new MageInt(4);
this.toughness = new MageInt(6); this.toughness = new MageInt(6);
//Menace //Menace
this.addAbility(new MenaceAbility()); this.addAbility(new MenaceAbility());
//Indestructible //Indestructible
this.addAbility(IndestructibleAbility.getInstance()); this.addAbility(IndestructibleAbility.getInstance());
//Bontu the Glorified can't attack or block unless a creature died under your control this turn. //Bontu the Glorified can't attack or block unless a creature died under your control this turn.
this.addAbility(new SimpleStaticAbility(Zone.BATTLEFIELD, new BontuTheGlorifiedRestrictionEffect()), new CreaturesDiedWatcher()); this.addAbility(new SimpleStaticAbility(Zone.BATTLEFIELD, new BontuTheGlorifiedRestrictionEffect()), new CreaturesDiedWatcher());
//{1}{B}, Sacrifice another creature: Scry 1. Each opponent loses 1 life and you gain 1 life. //{1}{B}, Sacrifice another creature: Scry 1. Each opponent loses 1 life and you gain 1 life.
Ability ability = new SimpleActivatedAbility(Zone.BATTLEFIELD, new ScryEffect(1), new ManaCostsImpl("{1}{B}")); Ability ability = new SimpleActivatedAbility(Zone.BATTLEFIELD, new ScryEffect(1), new ManaCostsImpl("{1}{B}"));
ability.addEffect(new LoseLifeOpponentsEffect(1)); ability.addEffect(new LoseLifeOpponentsEffect(1));
Effect effect = new GainLifeEffect(1); Effect effect = new GainLifeEffect(1);
effect.setText("and you gain 1 life"); effect.setText("and you gain 1 life");
ability.addEffect(effect); ability.addEffect(effect);
ability.addCost(new SacrificeTargetCost(new TargetControlledPermanent(filter))); ability.addCost(new SacrificeTargetCost(new TargetControlledPermanent(filter)));
this.addAbility(ability); this.addAbility(ability);
} }
public BontuTheGlorified(final BontuTheGlorified card) { public BontuTheGlorified(final BontuTheGlorified card) {
super(card); super(card);
} }
@Override @Override
public BontuTheGlorified copy() { public BontuTheGlorified copy() {
return new BontuTheGlorified(this); return new BontuTheGlorified(this);
} }
} }
class BontuTheGlorifiedRestrictionEffect extends RestrictionEffect { class BontuTheGlorifiedRestrictionEffect extends RestrictionEffect {
public BontuTheGlorifiedRestrictionEffect() { public BontuTheGlorifiedRestrictionEffect() {
super(Duration.WhileOnBattlefield); super(Duration.WhileOnBattlefield);
staticText = "{this} can't attack or block unless a creature died under your control this turn"; staticText = "{this} can't attack or block unless a creature died under your control this turn";
} }
public BontuTheGlorifiedRestrictionEffect(final BontuTheGlorifiedRestrictionEffect effect) { public BontuTheGlorifiedRestrictionEffect(final BontuTheGlorifiedRestrictionEffect effect) {
super(effect); super(effect);
} }
@Override @Override
public BontuTheGlorifiedRestrictionEffect copy() { public BontuTheGlorifiedRestrictionEffect copy() {
return new BontuTheGlorifiedRestrictionEffect(this); return new BontuTheGlorifiedRestrictionEffect(this);
} }
@Override @Override
public boolean canAttack(Game game) { public boolean canAttack(Game game) {
return false; return false;
} }
@Override @Override
public boolean canBlock(Permanent attacker, Permanent blocker, Ability source, Game game) { public boolean canBlock(Permanent attacker, Permanent blocker, Ability source, Game game) {
return false; return false;
} }
@Override @Override
public boolean applies(Permanent permanent, Ability source, Game game) { public boolean applies(Permanent permanent, Ability source, Game game) {
if (permanent.getId().equals(source.getSourceId())) { if (permanent.getId().equals(source.getSourceId())) {
Player controller = game.getPlayer(source.getControllerId()); Player controller = game.getPlayer(source.getControllerId());
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.
return false; return false;
} }
} }

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();
} }
} }