* Added DealsDamageAttachedTriggeredAbility and used in some cards.

This commit is contained in:
LevelX2 2015-05-25 15:49:51 +02:00
parent 0847d3f820
commit d3b41c076d
10 changed files with 214 additions and 246 deletions

View file

@ -29,11 +29,12 @@ package mage.sets.invasion;
import java.util.UUID;
import mage.abilities.Ability;
import mage.abilities.TriggeredAbilityImpl;
import mage.abilities.common.DealsDamageAttachedTriggeredAbility;
import mage.abilities.common.SimpleStaticAbility;
import mage.abilities.dynamicvalue.common.NumericSetToEffectValues;
import mage.abilities.effects.Effect;
import mage.abilities.effects.OneShotEffect;
import mage.abilities.effects.common.AttachEffect;
import mage.abilities.effects.common.GainLifeEffect;
import mage.abilities.effects.common.continuous.BoostEnchantedEffect;
import mage.abilities.effects.common.continuous.GainAbilityAttachedEffect;
import mage.abilities.keyword.EnchantAbility;
@ -45,10 +46,6 @@ import mage.constants.Duration;
import mage.constants.Outcome;
import mage.constants.Rarity;
import mage.constants.Zone;
import mage.game.Game;
import mage.game.events.GameEvent;
import mage.game.permanent.Permanent;
import mage.players.Player;
import mage.target.TargetPermanent;
import mage.target.common.TargetCreaturePermanent;
@ -63,7 +60,6 @@ public class ArmadilloCloak extends CardImpl {
this.expansionSetCode = "INV";
this.subtype.add("Aura");
// Enchant creature
TargetPermanent auraTarget = new TargetCreaturePermanent();
this.getSpellAbility().addTarget(auraTarget);
@ -72,11 +68,14 @@ public class ArmadilloCloak extends CardImpl {
this.addAbility(ability);
// Enchanted creature gets +2/+2 and has trample.
this.addAbility(new SimpleStaticAbility(Zone.BATTLEFIELD, new BoostEnchantedEffect(2, 2, Duration.WhileOnBattlefield)));
this.addAbility(new SimpleStaticAbility(Zone.BATTLEFIELD, new GainAbilityAttachedEffect(TrampleAbility.getInstance(), AttachmentType.AURA)));
ability = new SimpleStaticAbility(Zone.BATTLEFIELD, new BoostEnchantedEffect(2, 2, Duration.WhileOnBattlefield));
Effect effect = new GainAbilityAttachedEffect(TrampleAbility.getInstance(), AttachmentType.AURA);
effect.setText("and has trample");
ability.addEffect(effect);
this.addAbility(ability);
// Whenever enchanted creature deals damage, you gain that much life.
this.addAbility(new ArmadilloCloakTriggeredAbility());
this.addAbility(new DealsDamageAttachedTriggeredAbility(Zone.BATTLEFIELD, new GainLifeEffect(new NumericSetToEffectValues("that much", "damage")), false));
}
@ -89,74 +88,3 @@ public class ArmadilloCloak extends CardImpl {
return new ArmadilloCloak(this);
}
}
class ArmadilloCloakTriggeredAbility extends TriggeredAbilityImpl {
public ArmadilloCloakTriggeredAbility() {
super(Zone.BATTLEFIELD, new ArmadilloCloakEffect(), false);
}
public ArmadilloCloakTriggeredAbility(final ArmadilloCloakTriggeredAbility ability) {
super(ability);
}
@Override
public ArmadilloCloakTriggeredAbility copy() {
return new ArmadilloCloakTriggeredAbility(this);
}
@Override
public boolean checkTrigger(GameEvent event, Game game) {
if (event.getType().equals(GameEvent.EventType.DAMAGED_CREATURE)
|| event.getType().equals(GameEvent.EventType.DAMAGED_PLAYER)
|| event.getType().equals(GameEvent.EventType.DAMAGED_PLANESWALKER)) {
Permanent enchantment = game.getPermanent(this.getSourceId());
if (enchantment == null || enchantment.getAttachedTo() == null) {
return false;
}
Permanent enchanted = game.getPermanent(enchantment.getAttachedTo());
if (enchanted != null && event.getSourceId().equals(enchanted.getId())) {
for (Effect effect : this.getEffects()) {
effect.setValue("damage", event.getAmount());
}
return true;
}
}
return false;
}
@Override
public String getRule() {
return "Whenever enchanted creature deals damage, " + super.getRule();
}
}
class ArmadilloCloakEffect extends OneShotEffect {
public ArmadilloCloakEffect() {
super(Outcome.GainLife);
this.staticText = "you gain that much life";
}
public ArmadilloCloakEffect(final ArmadilloCloakEffect effect) {
super(effect);
}
@Override
public ArmadilloCloakEffect copy() {
return new ArmadilloCloakEffect(this);
}
@Override
public boolean apply(Game game, Ability source) {
int amount = (Integer) getValue("damage");
if (amount > 0) {
Player controller = game.getPlayer(source.getControllerId());
if (controller != null) {
controller.gainLife(amount, game);
return true;
}
}
return false;
}
}

View file

@ -29,20 +29,16 @@ package mage.sets.seventhedition;
import java.util.UUID;
import mage.abilities.Ability;
import mage.abilities.TriggeredAbilityImpl;
import mage.abilities.effects.Effect;
import mage.abilities.effects.OneShotEffect;
import mage.abilities.common.DealsDamageAttachedTriggeredAbility;
import mage.abilities.dynamicvalue.common.NumericSetToEffectValues;
import mage.abilities.effects.common.AttachEffect;
import mage.abilities.effects.common.GainLifeEffect;
import mage.abilities.keyword.EnchantAbility;
import mage.cards.CardImpl;
import mage.constants.CardType;
import mage.constants.Outcome;
import mage.constants.Rarity;
import mage.constants.Zone;
import mage.game.Game;
import mage.game.events.GameEvent;
import mage.game.permanent.Permanent;
import mage.players.Player;
import mage.target.TargetPermanent;
import mage.target.common.TargetCreaturePermanent;
@ -57,7 +53,6 @@ public class SpiritLink extends CardImpl {
this.expansionSetCode = "7ED";
this.subtype.add("Aura");
// Enchant creature
TargetPermanent auraTarget = new TargetCreaturePermanent();
this.getSpellAbility().addTarget(auraTarget);
@ -66,7 +61,7 @@ public class SpiritLink extends CardImpl {
this.addAbility(ability);
// Whenever enchanted creature deals damage, you gain that much life.
this.addAbility(new SpiritLinkTriggeredAbility());
this.addAbility(new DealsDamageAttachedTriggeredAbility(Zone.BATTLEFIELD, new GainLifeEffect(new NumericSetToEffectValues("that much", "damage")), false));
}
public SpiritLink(final SpiritLink card) {
@ -78,74 +73,3 @@ public class SpiritLink extends CardImpl {
return new SpiritLink(this);
}
}
class SpiritLinkTriggeredAbility extends TriggeredAbilityImpl {
public SpiritLinkTriggeredAbility() {
super(Zone.BATTLEFIELD, new SpiritLinkEffect(), false);
}
public SpiritLinkTriggeredAbility(final SpiritLinkTriggeredAbility ability) {
super(ability);
}
@Override
public SpiritLinkTriggeredAbility copy() {
return new SpiritLinkTriggeredAbility(this);
}
@Override
public boolean checkTrigger(GameEvent event, Game game) {
if (event.getType().equals(GameEvent.EventType.DAMAGED_CREATURE)
|| event.getType().equals(GameEvent.EventType.DAMAGED_PLAYER)
|| event.getType().equals(GameEvent.EventType.DAMAGED_PLANESWALKER)) {
Permanent enchantment = game.getPermanent(this.getSourceId());
if (enchantment == null || enchantment.getAttachedTo() == null) {
return false;
}
Permanent enchanted = game.getPermanent(enchantment.getAttachedTo());
if (enchanted != null && event.getSourceId().equals(enchanted.getId())) {
for (Effect effect : this.getEffects()) {
effect.setValue("damage", event.getAmount());
}
return true;
}
}
return false;
}
@Override
public String getRule() {
return "Whenever enchanted creature deals damage, " + super.getRule();
}
}
class SpiritLinkEffect extends OneShotEffect {
public SpiritLinkEffect() {
super(Outcome.GainLife);
this.staticText = "you gain that much life";
}
public SpiritLinkEffect(final SpiritLinkEffect effect) {
super(effect);
}
@Override
public SpiritLinkEffect copy() {
return new SpiritLinkEffect(this);
}
@Override
public boolean apply(Game game, Ability source) {
int amount = (Integer) getValue("damage");
if (amount > 0) {
Player controller = game.getPlayer(source.getControllerId());
if (controller != null) {
controller.gainLife(amount, game);
return true;
}
}
return false;
}
}

View file

@ -32,19 +32,15 @@ import mage.cards.CardImpl;
import mage.constants.CardType;
import mage.constants.Rarity;
import mage.abilities.Ability;
import mage.abilities.TriggeredAbilityImpl;
import mage.abilities.effects.Effect;
import mage.abilities.effects.OneShotEffect;
import mage.abilities.common.DealsDamageAttachedTriggeredAbility;
import mage.abilities.common.PutIntoGraveFromBattlefieldSourceTriggeredAbility;
import mage.abilities.dynamicvalue.common.NumericSetToEffectValues;
import mage.abilities.effects.common.AttachEffect;
import mage.abilities.effects.common.GainLifeEffect;
import mage.abilities.effects.common.ReturnToHandSourceEffect;
import mage.abilities.keyword.EnchantAbility;
import mage.constants.Outcome;
import mage.constants.Zone;
import mage.game.Game;
import mage.game.events.GameEvent;
import mage.game.permanent.Permanent;
import mage.players.Player;
import mage.target.TargetPermanent;
import mage.target.common.TargetControlledCreaturePermanent;
/**
@ -58,7 +54,6 @@ public class SpiritLoop extends CardImpl {
this.expansionSetCode = "TSP";
this.subtype.add("Aura");
// Enchant creature you control
TargetPermanent auraTarget = new TargetControlledCreaturePermanent();
this.getSpellAbility().addTarget(auraTarget);
@ -67,7 +62,7 @@ public class SpiritLoop extends CardImpl {
this.addAbility(ability);
// Whenever enchanted creature deals damage, you gain that much life.
this.addAbility(new SpiritLoopTriggeredAbility());
this.addAbility(new DealsDamageAttachedTriggeredAbility(Zone.BATTLEFIELD, new GainLifeEffect(new NumericSetToEffectValues("that much", "damage")), false));
// When Spirit Loop is put into a graveyard from the battlefield, return Spirit Loop to its owner's hand.
this.addAbility(new PutIntoGraveFromBattlefieldSourceTriggeredAbility(new ReturnToHandSourceEffect()));
@ -82,75 +77,4 @@ public class SpiritLoop extends CardImpl {
public SpiritLoop copy() {
return new SpiritLoop(this);
}
}
class SpiritLoopTriggeredAbility extends TriggeredAbilityImpl {
public SpiritLoopTriggeredAbility() {
super(Zone.BATTLEFIELD, new SpiritLoopEffect(), false);
}
public SpiritLoopTriggeredAbility(final SpiritLoopTriggeredAbility ability) {
super(ability);
}
@Override
public SpiritLoopTriggeredAbility copy() {
return new SpiritLoopTriggeredAbility(this);
}
@Override
public boolean checkTrigger(GameEvent event, Game game) {
if (event.getType().equals(GameEvent.EventType.DAMAGED_CREATURE)
|| event.getType().equals(GameEvent.EventType.DAMAGED_PLAYER)
|| event.getType().equals(GameEvent.EventType.DAMAGED_PLANESWALKER)) {
Permanent enchantment = game.getPermanent(this.getSourceId());
if (enchantment == null || enchantment.getAttachedTo() == null) {
return false;
}
Permanent enchanted = game.getPermanent(enchantment.getAttachedTo());
if (enchanted != null && event.getSourceId().equals(enchanted.getId())) {
for (Effect effect : this.getEffects()) {
effect.setValue("damage", event.getAmount());
}
return true;
}
}
return false;
}
@Override
public String getRule() {
return "Whenever enchanted creature deals damage, " + super.getRule();
}
}
class SpiritLoopEffect extends OneShotEffect {
public SpiritLoopEffect() {
super(Outcome.GainLife);
this.staticText = "you gain that much life";
}
public SpiritLoopEffect(final SpiritLoopEffect effect) {
super(effect);
}
@Override
public SpiritLoopEffect copy() {
return new SpiritLoopEffect(this);
}
@Override
public boolean apply(Game game, Ability source) {
int amount = (Integer) getValue("damage");
if (amount > 0) {
Player controller = game.getPlayer(source.getControllerId());
if (controller != null) {
controller.gainLife(amount, game);
return true;
}
}
return false;
}
}