[refactoring] merged dies triggered abilities for less duplicate code

This commit is contained in:
North 2012-07-22 17:07:06 +03:00
parent c0da929ba0
commit 0197c16cd7
22 changed files with 138 additions and 444 deletions

View file

@ -30,10 +30,14 @@ package mage.sets.avacynrestored;
import mage.Constants.CardType;
import mage.Constants.Rarity;
import mage.MageInt;
import mage.abilities.common.DiesAnotherCreatureTriggeredAbility;
import mage.abilities.common.DiesCreatureTriggeredAbility;
import mage.abilities.effects.common.DrawCardControllerEffect;
import mage.abilities.keyword.DeathtouchAbility;
import mage.cards.CardImpl;
import mage.filter.common.FilterCreaturePermanent;
import mage.filter.predicate.Predicates;
import mage.filter.predicate.permanent.AnotherPredicate;
import mage.filter.predicate.permanent.TokenPredicate;
import java.util.UUID;
@ -42,6 +46,13 @@ import java.util.UUID;
*/
public class HarvesterOfSouls extends CardImpl<HarvesterOfSouls> {
private static final FilterCreaturePermanent filter = new FilterCreaturePermanent("another nontoken creature");
static {
filter.add(Predicates.not(new TokenPredicate()));
filter.add(new AnotherPredicate());
}
public HarvesterOfSouls(UUID ownerId) {
super(ownerId, 107, "Harvester of Souls", Rarity.RARE, new CardType[]{CardType.CREATURE}, "{4}{B}{B}");
this.expansionSetCode = "AVR";
@ -54,7 +65,7 @@ public class HarvesterOfSouls extends CardImpl<HarvesterOfSouls> {
this.addAbility(DeathtouchAbility.getInstance());
// Whenever another nontoken creature dies, you may draw a card.
this.addAbility(new DiesAnotherCreatureTriggeredAbility(new DrawCardControllerEffect(1), true, true));
this.addAbility(new DiesCreatureTriggeredAbility(new DrawCardControllerEffect(1), true, filter));
}
public HarvesterOfSouls(final HarvesterOfSouls card) {

View file

@ -32,7 +32,7 @@ import mage.Constants.CardType;
import mage.Constants.Rarity;
import mage.MageInt;
import mage.abilities.common.DealsCombatDamageToAPlayerTriggeredAbility;
import mage.abilities.common.DiesAnotherCreatureTriggeredAbility;
import mage.abilities.common.DiesCreatureTriggeredAbility;
import mage.abilities.effects.common.counter.AddCountersSourceEffect;
import mage.cards.CardImpl;
import mage.counters.CounterType;
@ -55,7 +55,7 @@ public class HavengulVampire extends CardImpl<HavengulVampire> {
// Whenever Havengul Vampire deals combat damage to a player, put a +1/+1 counter on it.
this.addAbility(new DealsCombatDamageToAPlayerTriggeredAbility(new AddCountersSourceEffect(CounterType.P1P1.createInstance()), false));
// Whenever another creature dies, put a +1/+1 counter on Havengul Vampire.
this.addAbility(new DiesAnotherCreatureTriggeredAbility(new AddCountersSourceEffect(CounterType.P1P1.createInstance()), false));
this.addAbility(new DiesCreatureTriggeredAbility(new AddCountersSourceEffect(CounterType.P1P1.createInstance()), false, true));
}
public HavengulVampire(final HavengulVampire card) {

View file

@ -30,14 +30,17 @@ package mage.sets.darkascension;
import java.util.UUID;
import mage.Constants.CardType;
import mage.Constants.Rarity;
import mage.Constants.TargetController;
import mage.MageInt;
import mage.abilities.common.DiesAnotherCreatureYouControlTriggeredAbility;
import mage.abilities.common.DiesCreatureTriggeredAbility;
import mage.abilities.effects.common.CreateTokenEffect;
import mage.abilities.keyword.FlyingAbility;
import mage.cards.CardImpl;
import mage.filter.common.FilterCreaturePermanent;
import mage.filter.predicate.Predicates;
import mage.filter.predicate.mageobject.SubtypePredicate;
import mage.filter.predicate.permanent.AnotherPredicate;
import mage.filter.predicate.permanent.ControllerPredicate;
import mage.game.permanent.token.SpiritWhiteToken;
/**
@ -45,10 +48,12 @@ import mage.game.permanent.token.SpiritWhiteToken;
* @author intimidatingant
*/
public class RequiemAngel extends CardImpl<RequiemAngel> {
private static final FilterCreaturePermanent filter = new FilterCreaturePermanent("non-Spirit creature");
private static final FilterCreaturePermanent filter = new FilterCreaturePermanent("another non-Spirit creature you control");
static {
filter.add(Predicates.not(new SubtypePredicate("Spirit")));
filter.add(new AnotherPredicate());
filter.add(new ControllerPredicate(TargetController.YOU));
}
public RequiemAngel(UUID ownerId) {
@ -63,7 +68,7 @@ public class RequiemAngel extends CardImpl<RequiemAngel> {
this.addAbility(FlyingAbility.getInstance());
// Whenever another non-Spirit creature you control dies, put a 1/1 white Spirit creature token with flying onto the battlefield.
this.addAbility(new DiesAnotherCreatureYouControlTriggeredAbility(new CreateTokenEffect(new SpiritWhiteToken(), 1), false, filter));
this.addAbility(new DiesCreatureTriggeredAbility(new CreateTokenEffect(new SpiritWhiteToken(), 1), false, filter));
}
public RequiemAngel(final RequiemAngel card) {

View file

@ -33,7 +33,7 @@ import mage.Constants.Rarity;
import mage.Constants.Zone;
import mage.MageInt;
import mage.abilities.common.AttacksEachTurnStaticAbility;
import mage.abilities.common.CreatureDiesTriggeredAbility;
import mage.abilities.common.DiesCreatureTriggeredAbility;
import mage.abilities.common.SimpleStaticAbility;
import mage.abilities.effects.common.SkipUntapSourceEffect;
import mage.abilities.effects.common.UntapSourceEffect;
@ -58,7 +58,7 @@ public class GalvanicJuggernaut extends CardImpl<GalvanicJuggernaut> {
// Galvanic Juggernaut doesn't untap during your untap step.
this.addAbility(new SimpleStaticAbility(Zone.BATTLEFIELD, new SkipUntapSourceEffect()));
// Whenever another creature dies, untap Galvanic Juggernaut.
this.addAbility(new CreatureDiesTriggeredAbility(new UntapSourceEffect(), false, true));
this.addAbility(new DiesCreatureTriggeredAbility(new UntapSourceEffect(), false, true));
}
public GalvanicJuggernaut(final GalvanicJuggernaut card) {

View file

@ -31,7 +31,7 @@ import java.util.UUID;
import mage.Constants.CardType;
import mage.Constants.Rarity;
import mage.MageInt;
import mage.abilities.common.CreatureDiesTriggeredAbility;
import mage.abilities.common.DiesCreatureTriggeredAbility;
import mage.abilities.effects.common.counter.AddCountersSourceEffect;
import mage.abilities.keyword.HexproofAbility;
import mage.cards.CardImpl;
@ -54,7 +54,7 @@ public class Lumberknot extends CardImpl<Lumberknot> {
this.addAbility(HexproofAbility.getInstance());
// Whenever a creature dies, put a +1/+1 counter on Lumberknot.
this.addAbility(new CreatureDiesTriggeredAbility(new AddCountersSourceEffect(CounterType.P1P1.createInstance()), false));
this.addAbility(new DiesCreatureTriggeredAbility(new AddCountersSourceEffect(CounterType.P1P1.createInstance()), false));
}
public Lumberknot(final Lumberknot card) {

View file

@ -33,7 +33,7 @@ import mage.Constants.Outcome;
import mage.Constants.Rarity;
import mage.MageInt;
import mage.abilities.Ability;
import mage.abilities.common.CreatureDiesTriggeredAbility;
import mage.abilities.common.DiesCreatureTriggeredAbility;
import mage.abilities.effects.OneShotEffect;
import mage.abilities.keyword.FlyingAbility;
import mage.cards.CardImpl;
@ -57,7 +57,7 @@ public class MurderOfCrows extends CardImpl<MurderOfCrows> {
this.addAbility(FlyingAbility.getInstance());
// Whenever another creature dies, you may draw a card. If you do, discard a card.
this.addAbility(new CreatureDiesTriggeredAbility(new MurderOfCrowsEffect(), false, true));
this.addAbility(new DiesCreatureTriggeredAbility(new MurderOfCrowsEffect(), false, true));
}
public MurderOfCrows(final MurderOfCrows card) {

View file

@ -31,7 +31,7 @@ import java.util.UUID;
import mage.Constants.CardType;
import mage.Constants.Rarity;
import mage.MageInt;
import mage.abilities.common.CreatureDiesTriggeredAbility;
import mage.abilities.common.DiesCreatureTriggeredAbility;
import mage.abilities.effects.common.DamageTargetEffect;
import mage.cards.CardImpl;
import mage.target.TargetPlayer;
@ -53,7 +53,7 @@ public class RageThrower extends CardImpl<RageThrower> {
this.toughness = new MageInt(2);
// Whenever another creature dies, Rage Thrower deals 2 damage to target player.
CreatureDiesTriggeredAbility ability = new CreatureDiesTriggeredAbility(new DamageTargetEffect(2), false, true);
DiesCreatureTriggeredAbility ability = new DiesCreatureTriggeredAbility(new DamageTargetEffect(2), false, true);
ability.addTarget(new TargetPlayer());
this.addAbility(ability);
}

View file

@ -30,11 +30,15 @@ package mage.sets.innistrad;
import java.util.UUID;
import mage.Constants.CardType;
import mage.Constants.Rarity;
import mage.Constants.TargetController;
import mage.MageInt;
import mage.abilities.common.DiesAnotherCreatureYouControlTriggeredAbility;
import mage.abilities.common.DiesCreatureTriggeredAbility;
import mage.abilities.effects.common.counter.AddCountersSourceEffect;
import mage.cards.CardImpl;
import mage.counters.CounterType;
import mage.filter.common.FilterCreaturePermanent;
import mage.filter.predicate.permanent.AnotherPredicate;
import mage.filter.predicate.permanent.ControllerPredicate;
/**
*
@ -42,6 +46,13 @@ import mage.counters.CounterType;
*/
public class UnrulyMob extends CardImpl<UnrulyMob> {
private static final FilterCreaturePermanent filter = new FilterCreaturePermanent("another creature you control");
static {
filter.add(new AnotherPredicate());
filter.add(new ControllerPredicate(TargetController.YOU));
}
public UnrulyMob(UUID ownerId) {
super(ownerId, 39, "Unruly Mob", Rarity.COMMON, new CardType[]{CardType.CREATURE}, "{1}{W}");
this.expansionSetCode = "ISD";
@ -52,7 +63,7 @@ public class UnrulyMob extends CardImpl<UnrulyMob> {
this.toughness = new MageInt(1);
// Whenever another creature you control dies, put a +1/+1 counter on Unruly Mob.
this.addAbility(new DiesAnotherCreatureYouControlTriggeredAbility(new AddCountersSourceEffect(CounterType.P1P1.createInstance()), false));
this.addAbility(new DiesCreatureTriggeredAbility(new AddCountersSourceEffect(CounterType.P1P1.createInstance()), false, filter));
}
public UnrulyMob(final UnrulyMob card) {

View file

@ -31,7 +31,7 @@ import java.util.UUID;
import mage.Constants.CardType;
import mage.Constants.Rarity;
import mage.MageInt;
import mage.abilities.common.CreatureDiesTriggeredAbility;
import mage.abilities.common.DiesCreatureTriggeredAbility;
import mage.abilities.effects.common.counter.AddCountersSourceEffect;
import mage.abilities.keyword.ShroudAbility;
import mage.cards.CardImpl;
@ -54,7 +54,7 @@ public class AlgaeGharial extends CardImpl<AlgaeGharial> {
this.addAbility(ShroudAbility.getInstance());
// Whenever another creature dies, you may put a +1/+1 counter on Algae Gharial.
this.addAbility(new CreatureDiesTriggeredAbility(new AddCountersSourceEffect(CounterType.P1P1.createInstance()), true, true));
this.addAbility(new DiesCreatureTriggeredAbility(new AddCountersSourceEffect(CounterType.P1P1.createInstance()), true, true));
}
public AlgaeGharial(final AlgaeGharial card) {

View file

@ -31,7 +31,7 @@ import java.util.UUID;
import mage.Constants.CardType;
import mage.Constants.Rarity;
import mage.MageInt;
import mage.abilities.common.CreatureDiesTriggeredAbility;
import mage.abilities.common.DiesCreatureTriggeredAbility;
import mage.abilities.effects.common.GainLifeEffect;
import mage.cards.CardImpl;
@ -52,7 +52,7 @@ public class Deathgreeter extends CardImpl<Deathgreeter> {
this.toughness = new MageInt(1);
// Whenever another creature dies, you may gain 1 life.
this.addAbility(new CreatureDiesTriggeredAbility(new GainLifeEffect(1), true, true));
this.addAbility(new DiesCreatureTriggeredAbility(new GainLifeEffect(1), true, true));
}
public Deathgreeter(final Deathgreeter card) {

View file

@ -31,7 +31,7 @@ import java.util.UUID;
import mage.Constants.CardType;
import mage.Constants.Rarity;
import mage.MageInt;
import mage.abilities.common.CreatureDiesTriggeredAbility;
import mage.abilities.common.DiesCreatureTriggeredAbility;
import mage.abilities.effects.common.DamageTargetEffect;
import mage.cards.CardImpl;
import mage.target.TargetPlayer;
@ -52,7 +52,7 @@ public class HissingIguanar extends CardImpl<HissingIguanar> {
this.toughness = new MageInt(1);
// Whenever another creature dies, you may have Hissing Iguanar deal 1 damage to target player.
CreatureDiesTriggeredAbility ability = new CreatureDiesTriggeredAbility(new DamageTargetEffect(1), true, true);
DiesCreatureTriggeredAbility ability = new DiesCreatureTriggeredAbility(new DamageTargetEffect(1), true, true);
ability.addTarget(new TargetPlayer());
this.addAbility(ability);
}

View file

@ -31,7 +31,7 @@ import java.util.UUID;
import mage.Constants.CardType;
import mage.Constants.Rarity;
import mage.MageInt;
import mage.abilities.common.CreatureDiesTriggeredAbility;
import mage.abilities.common.DiesCreatureTriggeredAbility;
import mage.abilities.effects.common.counter.AddCountersSourceEffect;
import mage.abilities.keyword.FirstStrikeAbility;
import mage.cards.CardImpl;
@ -54,7 +54,7 @@ public class RockslideElemental extends CardImpl<RockslideElemental> {
this.addAbility(FirstStrikeAbility.getInstance());
// Whenever another creature dies, you may put a +1/+1 counter on Rockslide Elemental.
this.addAbility(new CreatureDiesTriggeredAbility(new AddCountersSourceEffect(CounterType.P1P1.createInstance()), true, true));
this.addAbility(new DiesCreatureTriggeredAbility(new AddCountersSourceEffect(CounterType.P1P1.createInstance()), true, true));
}
public RockslideElemental(final RockslideElemental card) {

View file

@ -31,7 +31,7 @@ import java.util.UUID;
import mage.Constants.CardType;
import mage.Constants.Rarity;
import mage.MageInt;
import mage.abilities.common.CreatureDiesTriggeredAbility;
import mage.abilities.common.DiesCreatureTriggeredAbility;
import mage.abilities.effects.common.counter.AddCountersSourceEffect;
import mage.abilities.keyword.FlyingAbility;
import mage.cards.CardImpl;
@ -54,7 +54,7 @@ public class ScavengerDrake extends CardImpl<ScavengerDrake> {
this.addAbility(FlyingAbility.getInstance());
// Whenever another creature dies, you may put a +1/+1 counter on Scavenger Drake.
this.addAbility(new CreatureDiesTriggeredAbility(new AddCountersSourceEffect(CounterType.P1P1.createInstance()), true, true));
this.addAbility(new DiesCreatureTriggeredAbility(new AddCountersSourceEffect(CounterType.P1P1.createInstance()), true, true));
}
public ScavengerDrake(final ScavengerDrake card) {

View file

@ -34,11 +34,12 @@ import mage.Constants.CardType;
import mage.Constants.Rarity;
import mage.MageInt;
import mage.abilities.Ability;
import mage.abilities.common.DiesThisOrAnotherControlledCreatureTriggeredAbility;
import mage.abilities.common.DiesThisOrAnotherCreatureTriggeredAbility;
import mage.abilities.effects.OneShotEffect;
import mage.abilities.keyword.FlyingAbility;
import mage.cards.CardImpl;
import mage.filter.common.FilterControlledPermanent;
import mage.filter.common.FilterCreaturePermanent;
import mage.filter.predicate.mageobject.CardTypePredicate;
import mage.filter.predicate.permanent.ControllerPredicate;
import mage.game.Game;
@ -53,6 +54,8 @@ import mage.target.common.TargetControlledPermanent;
*/
public class ButcherOfMalakir extends CardImpl<ButcherOfMalakir> {
private static final FilterCreaturePermanent filter = new FilterCreaturePermanent("creature you control");
public ButcherOfMalakir(UUID ownerId) {
super(ownerId, 53, "Butcher of Malakir", Rarity.RARE, new CardType[]{CardType.CREATURE}, "{5}{B}{B}");
this.expansionSetCode = "WWK";
@ -67,7 +70,7 @@ public class ButcherOfMalakir extends CardImpl<ButcherOfMalakir> {
this.addAbility(FlyingAbility.getInstance());
// Whenever Butcher of Malakir or another creature you control dies, each opponent sacrifices a creature.
this.addAbility(new DiesThisOrAnotherControlledCreatureTriggeredAbility(new ButcherOfMalakirEffect(), false));
this.addAbility(new DiesThisOrAnotherCreatureTriggeredAbility(new ButcherOfMalakirEffect(), false, filter));
}
public ButcherOfMalakir(final ButcherOfMalakir card) {
@ -79,7 +82,6 @@ public class ButcherOfMalakir extends CardImpl<ButcherOfMalakir> {
return new ButcherOfMalakir(this);
}
}
class ButcherOfMalakirEffect extends OneShotEffect<ButcherOfMalakirEffect> {
public ButcherOfMalakirEffect() {

View file

@ -33,7 +33,7 @@ import mage.Constants.Rarity;
import mage.Constants.Zone;
import mage.MageInt;
import mage.ObjectColor;
import mage.abilities.common.CreatureDiesTriggeredAbility;
import mage.abilities.common.DiesCreatureTriggeredAbility;
import mage.abilities.common.SimpleActivatedAbility;
import mage.abilities.costs.common.RemoveCountersSourceCost;
import mage.abilities.costs.common.SacrificeSourceCost;
@ -56,7 +56,7 @@ public class QuestForTheGravelord extends CardImpl<QuestForTheGravelord> {
this.color.setBlack(true);
// Whenever a creature dies, you may put a quest counter on Quest for the Gravelord.
this.addAbility(new CreatureDiesTriggeredAbility(new AddCountersSourceEffect(CounterType.QUEST.createInstance()), true));
this.addAbility(new DiesCreatureTriggeredAbility(new AddCountersSourceEffect(CounterType.QUEST.createInstance()), true));
// Remove three quest counters from Quest for the Gravelord and sacrifice it: Put a 5/5 black Zombie Giant creature token onto the battlefield.
SimpleActivatedAbility ability = new SimpleActivatedAbility(Zone.BATTLEFIELD,
new CreateTokenEffect(new ZombieToken()),

View file

@ -1,82 +0,0 @@
/*
* Copyright 2011 BetaSteward_at_googlemail.com. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modification, are
* permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice, this list of
* conditions and the following disclaimer.
*
* 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
* provided with the distribution.
*
* 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
* 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
* 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
* 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
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
* 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
* or implied, of BetaSteward_at_googlemail.com.
*/
package mage.abilities.common;
import mage.Constants.CardType;
import mage.Constants.Zone;
import mage.abilities.TriggeredAbilityImpl;
import mage.abilities.effects.Effect;
import mage.game.Game;
import mage.game.events.GameEvent;
import mage.game.events.ZoneChangeEvent;
import mage.game.permanent.Permanent;
/**
*
* @author North
*/
public class CreatureDiesTriggeredAbility extends TriggeredAbilityImpl<CreatureDiesTriggeredAbility> {
protected boolean another;
public CreatureDiesTriggeredAbility(Effect effect, boolean optional) {
this(effect, optional, false);
}
public CreatureDiesTriggeredAbility(Effect effect, boolean optional, boolean another) {
super(Zone.BATTLEFIELD, effect, optional);
this.another = another;
}
public CreatureDiesTriggeredAbility(final CreatureDiesTriggeredAbility ability) {
super(ability);
this.another = ability.another;
}
@Override
public CreatureDiesTriggeredAbility copy() {
return new CreatureDiesTriggeredAbility(this);
}
@Override
public boolean checkTrigger(GameEvent event, Game game) {
if (event.getType() == GameEvent.EventType.ZONE_CHANGE && ((ZoneChangeEvent)event).isDiesEvent()) {
Permanent permanent = (Permanent) game.getLastKnownInformation(event.getTargetId(), Zone.BATTLEFIELD);
if (permanent != null && permanent.getCardType().contains(CardType.CREATURE)
&& (!another || !permanent.getId().equals(this.getSourceId()))) {
return true;
}
}
return false;
}
@Override
public String getRule() {
return "Whenever " + (another ? "another" : "a") + " creature dies, " + super.getRule();
}
}

View file

@ -1,89 +0,0 @@
package mage.abilities.common;
import mage.Constants;
import mage.abilities.TriggeredAbilityImpl;
import mage.abilities.effects.Effect;
import mage.filter.common.FilterCreaturePermanent;
import mage.game.Game;
import mage.game.events.GameEvent;
import mage.game.events.ZoneChangeEvent;
import mage.game.permanent.Permanent;
import mage.game.permanent.PermanentToken;
import java.util.UUID;
/**
* noxx
*/
public class DiesAnotherCreatureTriggeredAbility extends TriggeredAbilityImpl<DiesAnotherCreatureTriggeredAbility> {
protected FilterCreaturePermanent filter;
protected boolean nontoken;
public DiesAnotherCreatureTriggeredAbility(Effect effect, boolean optional) {
this(effect, optional, new FilterCreaturePermanent());
}
public DiesAnotherCreatureTriggeredAbility(Effect effect, boolean optional, boolean nontoken) {
this(effect, optional, new FilterCreaturePermanent(), nontoken);
}
public DiesAnotherCreatureTriggeredAbility(Effect effect, boolean optional, FilterCreaturePermanent filter) {
this(effect, optional, filter, false);
}
public DiesAnotherCreatureTriggeredAbility(Effect effect, boolean optional, FilterCreaturePermanent filter, boolean nontoken) {
super(Constants.Zone.BATTLEFIELD, effect, optional);
this.filter = filter;
this.nontoken = nontoken;
}
public DiesAnotherCreatureTriggeredAbility(DiesAnotherCreatureTriggeredAbility ability) {
super(ability);
this.filter = ability.filter;
this.nontoken = ability.nontoken;
}
@Override
public DiesAnotherCreatureTriggeredAbility copy() {
return new DiesAnotherCreatureTriggeredAbility(this);
}
@Override
public boolean checkTrigger(GameEvent event, Game game) {
if (event.getType() == GameEvent.EventType.ZONE_CHANGE) {
ZoneChangeEvent zEvent = (ZoneChangeEvent) event;
UUID sourceId = getSourceId();
if (game.getPermanent(sourceId) == null) {
if (game.getLastKnownInformation(sourceId, Constants.Zone.BATTLEFIELD) == null) {
return false;
}
}
if (zEvent.getFromZone() == Constants.Zone.BATTLEFIELD && zEvent.getToZone() == Constants.Zone.GRAVEYARD) {
Permanent permanent = (Permanent) game.getLastKnownInformation(event.getTargetId(), Constants.Zone.BATTLEFIELD);
if (permanent != null) {
if (permanent.getId().equals(this.getSourceId())) {
return false;
}
if (nontoken && permanent instanceof PermanentToken) {
return false;
}
if (filter.match(permanent, game)) {
return true;
}
}
}
}
return false;
}
@Override
public String getRule() {
if (nontoken) {
return "Whenever another nontoken creature dies, " + super.getRule();
}
return "Whenever another creature dies, " + super.getRule();
}
}

View file

@ -1,114 +0,0 @@
/*
* Copyright 2010 BetaSteward_at_googlemail.com. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modification, are
* permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice, this list of
* conditions and the following disclaimer.
*
* 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
* provided with the distribution.
*
* 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
* 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
* 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
* 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
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
* 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
* or implied, of BetaSteward_at_googlemail.com.
*/
package mage.abilities.common;
import mage.Constants;
import mage.abilities.TriggeredAbilityImpl;
import mage.abilities.effects.Effect;
import mage.filter.common.FilterCreaturePermanent;
import mage.game.Game;
import mage.game.events.GameEvent;
import mage.game.events.ZoneChangeEvent;
import mage.game.permanent.Permanent;
import mage.game.permanent.PermanentToken;
import java.util.UUID;
/**
* @author noxx
*/
public class DiesAnotherCreatureYouControlTriggeredAbility extends TriggeredAbilityImpl<DiesAnotherCreatureYouControlTriggeredAbility> {
protected FilterCreaturePermanent filter;
protected boolean nontoken;
public DiesAnotherCreatureYouControlTriggeredAbility(Effect effect, boolean optional) {
this(effect, optional, new FilterCreaturePermanent());
}
public DiesAnotherCreatureYouControlTriggeredAbility(Effect effect, boolean optional, boolean nontoken) {
this(effect, optional, new FilterCreaturePermanent(), nontoken);
}
public DiesAnotherCreatureYouControlTriggeredAbility(Effect effect, boolean optional, FilterCreaturePermanent filter) {
this(effect, optional, filter, false);
}
public DiesAnotherCreatureYouControlTriggeredAbility(Effect effect, boolean optional, FilterCreaturePermanent filter, boolean nontoken) {
super(Constants.Zone.BATTLEFIELD, effect, optional);
this.filter = filter;
this.nontoken = nontoken;
}
public DiesAnotherCreatureYouControlTriggeredAbility(DiesAnotherCreatureYouControlTriggeredAbility ability) {
super(ability);
this.filter = ability.filter;
this.nontoken = ability.nontoken;
}
@Override
public DiesAnotherCreatureYouControlTriggeredAbility copy() {
return new DiesAnotherCreatureYouControlTriggeredAbility(this);
}
@Override
public boolean checkTrigger(GameEvent event, Game game) {
if (event.getType() == GameEvent.EventType.ZONE_CHANGE) {
UUID sourceId = getSourceId();
if (game.getPermanent(sourceId) == null) {
if (game.getLastKnownInformation(sourceId, Constants.Zone.BATTLEFIELD) == null) {
return false;
}
}
ZoneChangeEvent zEvent = (ZoneChangeEvent) event;
Permanent permanent = zEvent.getTarget();
if (nontoken && permanent instanceof PermanentToken) {
return false;
}
if (permanent != null && permanent.getCardType().contains(Constants.CardType.CREATURE) &&
zEvent.isDiesEvent() &&
permanent.getControllerId().equals(this.getControllerId()) && filter != null &&
filter.match(permanent, game)) {
return true;
}
}
return false;
}
@Override
public String getRule() {
if (nontoken) {
return "Whenever another nontoken creature you control dies, " + super.getRule();
}
return "Whenever another creature you control dies, " + super.getRule();
}
}

View file

@ -0,0 +1,69 @@
package mage.abilities.common;
import mage.Constants.Zone;
import mage.abilities.TriggeredAbilityImpl;
import mage.abilities.effects.Effect;
import mage.filter.common.FilterCreaturePermanent;
import mage.filter.predicate.permanent.AnotherPredicate;
import mage.game.Game;
import mage.game.events.GameEvent;
import mage.game.events.ZoneChangeEvent;
import mage.game.permanent.Permanent;
/**
* @author North
*/
public class DiesCreatureTriggeredAbility extends TriggeredAbilityImpl<DiesCreatureTriggeredAbility> {
protected FilterCreaturePermanent filter;
public DiesCreatureTriggeredAbility(Effect effect, boolean optional) {
this(effect, optional, new FilterCreaturePermanent("a creature"));
}
public DiesCreatureTriggeredAbility(Effect effect, boolean optional, boolean another) {
this(effect, optional, new FilterCreaturePermanent("another creature"));
filter.add(new AnotherPredicate());
}
public DiesCreatureTriggeredAbility(Effect effect, boolean optional, FilterCreaturePermanent filter) {
super(Zone.BATTLEFIELD, effect, optional);
this.filter = filter;
}
public DiesCreatureTriggeredAbility(DiesCreatureTriggeredAbility ability) {
super(ability);
this.filter = ability.filter;
}
@Override
public DiesCreatureTriggeredAbility copy() {
return new DiesCreatureTriggeredAbility(this);
}
@Override
public boolean checkTrigger(GameEvent event, Game game) {
if (event.getType() == GameEvent.EventType.ZONE_CHANGE) {
ZoneChangeEvent zEvent = (ZoneChangeEvent) event;
if (game.getPermanent(sourceId) == null) {
if (game.getLastKnownInformation(sourceId, Zone.BATTLEFIELD) == null) {
return false;
}
}
if (zEvent.getFromZone() == Zone.BATTLEFIELD && zEvent.getToZone() == Zone.GRAVEYARD) {
Permanent permanent = (Permanent) game.getLastKnownInformation(event.getTargetId(), Zone.BATTLEFIELD);
if (permanent != null && filter.match(permanent, sourceId, controllerId, game)) {
return true;
}
}
}
return false;
}
@Override
public String getRule() {
return "Whenever " + filter.getMessage() + " dies, " + super.getRule();
}
}

View file

@ -1,99 +0,0 @@
/*
* Copyright 2010 BetaSteward_at_googlemail.com. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modification, are
* permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice, this list of
* conditions and the following disclaimer.
*
* 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
* provided with the distribution.
*
* 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
* 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
* 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
* 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
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
* 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
* or implied, of BetaSteward_at_googlemail.com.
*/
package mage.abilities.common;
import mage.Constants;
import mage.abilities.TriggeredAbilityImpl;
import mage.abilities.effects.Effect;
import mage.game.Game;
import mage.game.events.GameEvent;
import mage.game.events.ZoneChangeEvent;
import mage.game.permanent.Permanent;
import java.util.UUID;
import mage.filter.common.FilterControlledCreaturePermanent;
/**
* @author jeff
*/
public class DiesThisOrAnotherControlledCreatureTriggeredAbility extends TriggeredAbilityImpl<DiesThisOrAnotherControlledCreatureTriggeredAbility> {
protected FilterControlledCreaturePermanent filter;
public DiesThisOrAnotherControlledCreatureTriggeredAbility(Effect effect, boolean optional) {
this(effect, optional, new FilterControlledCreaturePermanent());
}
public DiesThisOrAnotherControlledCreatureTriggeredAbility(Effect effect, boolean optional, FilterControlledCreaturePermanent filter) {
super(Constants.Zone.BATTLEFIELD, effect, optional);
this.filter = filter;
}
public DiesThisOrAnotherControlledCreatureTriggeredAbility(DiesThisOrAnotherControlledCreatureTriggeredAbility ability) {
super(ability);
this.filter = ability.filter;
}
@Override
public DiesThisOrAnotherControlledCreatureTriggeredAbility copy() {
return new DiesThisOrAnotherControlledCreatureTriggeredAbility(this);
}
@Override
public boolean checkTrigger(GameEvent event, Game game) {
if (event.getType() == GameEvent.EventType.ZONE_CHANGE) {
ZoneChangeEvent zEvent = (ZoneChangeEvent) event;
UUID sourceId = getSourceId();
if (game.getPermanent(sourceId) == null) {
if (game.getLastKnownInformation(sourceId, Constants.Zone.BATTLEFIELD) == null) {
return false;
}
}
if (zEvent.getFromZone() == Constants.Zone.BATTLEFIELD && zEvent.getToZone() == Constants.Zone.GRAVEYARD) {
Permanent permanent = (Permanent) game.getLastKnownInformation(event.getTargetId(), Constants.Zone.BATTLEFIELD);
if (permanent != null) {
if (permanent.getId().equals(this.getSourceId())) {
return true;
} else {
if (filter.match(permanent, game)) {
return true;
}
}
}
}
}
return false;
}
@Override
public String getRule() {
return "Whenever {this} or another creature you control dies, " + super.getRule();
}
}

View file

@ -27,7 +27,7 @@
*/
package mage.abilities.common;
import mage.Constants;
import mage.Constants.Zone;
import mage.abilities.TriggeredAbilityImpl;
import mage.abilities.effects.Effect;
import mage.filter.common.FilterCreaturePermanent;
@ -36,8 +36,6 @@ import mage.game.events.GameEvent;
import mage.game.events.ZoneChangeEvent;
import mage.game.permanent.Permanent;
import java.util.UUID;
/**
* @author noxx
*/
@ -50,7 +48,7 @@ public class DiesThisOrAnotherCreatureTriggeredAbility extends TriggeredAbilityI
}
public DiesThisOrAnotherCreatureTriggeredAbility(Effect effect, boolean optional, FilterCreaturePermanent filter) {
super(Constants.Zone.BATTLEFIELD, effect, optional);
super(Zone.BATTLEFIELD, effect, optional);
this.filter = filter;
}
@ -69,20 +67,19 @@ public class DiesThisOrAnotherCreatureTriggeredAbility extends TriggeredAbilityI
if (event.getType() == GameEvent.EventType.ZONE_CHANGE) {
ZoneChangeEvent zEvent = (ZoneChangeEvent) event;
UUID sourceId = getSourceId();
if (game.getPermanent(sourceId) == null) {
if (game.getLastKnownInformation(sourceId, Constants.Zone.BATTLEFIELD) == null) {
if (game.getLastKnownInformation(sourceId, Zone.BATTLEFIELD) == null) {
return false;
}
}
if (zEvent.getFromZone() == Constants.Zone.BATTLEFIELD && zEvent.getToZone() == Constants.Zone.GRAVEYARD) {
Permanent permanent = (Permanent) game.getLastKnownInformation(event.getTargetId(), Constants.Zone.BATTLEFIELD);
if (zEvent.getFromZone() == Zone.BATTLEFIELD && zEvent.getToZone() == Zone.GRAVEYARD) {
Permanent permanent = (Permanent) game.getLastKnownInformation(event.getTargetId(), Zone.BATTLEFIELD);
if (permanent != null) {
if (permanent.getId().equals(this.getSourceId())) {
return true;
} else {
if (filter.match(permanent, game)) {
if (filter.match(permanent, sourceId, controllerId, game)) {
return true;
}
}
@ -94,6 +91,6 @@ public class DiesThisOrAnotherCreatureTriggeredAbility extends TriggeredAbilityI
@Override
public String getRule() {
return "Whenever {this} or another creature dies, " + super.getRule();
return "Whenever {this} or another " + filter.getMessage() + " dies, " + super.getRule();
}
}
}

View file

@ -40,8 +40,6 @@ import mage.game.Game;
*/
public class DiesTriggeredAbility extends ZoneChangeTriggeredAbility<DiesTriggeredAbility> {
// boolean used = false;
public DiesTriggeredAbility(Effect effect, boolean optional) {
super(Zone.BATTLEFIELD, Zone.GRAVEYARD, effect, "When {this} dies, ", optional);
}
@ -67,19 +65,4 @@ public class DiesTriggeredAbility extends ZoneChangeTriggeredAbility<DiesTrigger
public DiesTriggeredAbility copy() {
return new DiesTriggeredAbility(this);
}
// @Override
// public boolean checkTrigger(GameEvent event, Game game) {
// return super.checkTrigger(event, game) && !used;
// }
// @Override
// public void trigger(Game game, UUID controllerId) {
// if ( !used ) {
// super.trigger(game, controllerId);
// used = true;
// }
// }
}