From 811d4409ec550b4ca623c1b2afdc9da643a166ab Mon Sep 17 00:00:00 2001 From: LevelX2 Date: Sat, 14 Sep 2013 15:36:56 +0200 Subject: [PATCH] Refactored AttacksAttachedTriggeredAbility, added SacrificeSourceTriggeredAbility. --- .../src/mage/sets/alarareborn/MageSlayer.java | 4 +- .../sets/avacynrestored/MoonsilverSpear.java | 4 +- .../mage/sets/innistrad/TrepanationBlade.java | 4 +- .../sets/scarsofmirrodin/ArgentumArmor.java | 4 +- .../mage/sets/zendikar/ExplorersScope.java | 4 +- .../src/mage/sets/zendikar/GrapplingHook.java | 4 +- .../AttacksAttachedTriggeredAbility.java | 93 +++++++++++++++++++ .../AttacksEquippedTriggeredAbility.java | 43 --------- .../SacrificeSourceTriggeredAbility.java | 69 ++++++++++++++ 9 files changed, 174 insertions(+), 55 deletions(-) create mode 100644 Mage/src/mage/abilities/common/AttacksAttachedTriggeredAbility.java delete mode 100644 Mage/src/mage/abilities/common/AttacksEquippedTriggeredAbility.java create mode 100644 Mage/src/mage/abilities/common/SacrificeSourceTriggeredAbility.java diff --git a/Mage.Sets/src/mage/sets/alarareborn/MageSlayer.java b/Mage.Sets/src/mage/sets/alarareborn/MageSlayer.java index 9b0ce9cad5..0d8bba944a 100644 --- a/Mage.Sets/src/mage/sets/alarareborn/MageSlayer.java +++ b/Mage.Sets/src/mage/sets/alarareborn/MageSlayer.java @@ -29,7 +29,7 @@ package mage.sets.alarareborn; import java.util.UUID; import mage.abilities.Ability; -import mage.abilities.common.AttacksEquippedTriggeredAbility; +import mage.abilities.common.AttacksAttachedTriggeredAbility; import mage.abilities.costs.mana.GenericManaCost; import mage.abilities.effects.OneShotEffect; import mage.abilities.keyword.EquipAbility; @@ -56,7 +56,7 @@ public class MageSlayer extends CardImpl { this.color.setGreen(true); // Whenever equipped creature attacks, it deals damage equal to its power to defending player. - this.addAbility(new AttacksEquippedTriggeredAbility(new MageSlayerEffect(), false)); + this.addAbility(new AttacksAttachedTriggeredAbility(new MageSlayerEffect(), false)); // Equip {3} this.addAbility(new EquipAbility(Outcome.Benefit, new GenericManaCost(3), new TargetControlledCreaturePermanent())); diff --git a/Mage.Sets/src/mage/sets/avacynrestored/MoonsilverSpear.java b/Mage.Sets/src/mage/sets/avacynrestored/MoonsilverSpear.java index 4f3c282f32..e91d56a45d 100644 --- a/Mage.Sets/src/mage/sets/avacynrestored/MoonsilverSpear.java +++ b/Mage.Sets/src/mage/sets/avacynrestored/MoonsilverSpear.java @@ -30,7 +30,7 @@ package mage.sets.avacynrestored; import java.util.UUID; import mage.constants.*; -import mage.abilities.common.AttacksEquippedTriggeredAbility; +import mage.abilities.common.AttacksAttachedTriggeredAbility; import mage.abilities.common.SimpleStaticAbility; import mage.abilities.costs.mana.GenericManaCost; import mage.abilities.effects.common.CreateTokenEffect; @@ -54,7 +54,7 @@ public class MoonsilverSpear extends CardImpl { // Equipped creature has first strike. this.addAbility(new SimpleStaticAbility(Zone.BATTLEFIELD, new GainAbilityAttachedEffect(FirstStrikeAbility.getInstance(), AttachmentType.EQUIPMENT))); // Whenever equipped creature attacks, put a 4/4 white Angel creature token with flying onto the battlefield. - this.addAbility(new AttacksEquippedTriggeredAbility(new CreateTokenEffect(new AngelToken()))); + this.addAbility(new AttacksAttachedTriggeredAbility(new CreateTokenEffect(new AngelToken()))); // Equip {4} this.addAbility(new EquipAbility(Outcome.AddAbility, new GenericManaCost(4))); } diff --git a/Mage.Sets/src/mage/sets/innistrad/TrepanationBlade.java b/Mage.Sets/src/mage/sets/innistrad/TrepanationBlade.java index bdadbe564d..50a9e3ec4f 100644 --- a/Mage.Sets/src/mage/sets/innistrad/TrepanationBlade.java +++ b/Mage.Sets/src/mage/sets/innistrad/TrepanationBlade.java @@ -37,7 +37,7 @@ import mage.constants.SubLayer; import mage.constants.Zone; import mage.abilities.Ability; import mage.abilities.Mode; -import mage.abilities.common.AttacksEquippedTriggeredAbility; +import mage.abilities.common.AttacksAttachedTriggeredAbility; import mage.abilities.costs.mana.GenericManaCost; import mage.abilities.effects.ContinuousEffectImpl; import mage.abilities.effects.OneShotEffect; @@ -62,7 +62,7 @@ public class TrepanationBlade extends CardImpl { // Whenever equipped creature attacks, defending player reveals cards from the top of his or her library until he or she reveals a land card. // The creature gets +1/+0 until end of turn for each card revealed this way. That player puts the revealed cards into his or her graveyard. - Ability ability = new AttacksEquippedTriggeredAbility(new TrepanationBladeDiscardEffect()); + Ability ability = new AttacksAttachedTriggeredAbility(new TrepanationBladeDiscardEffect()); ability.addEffect(new TrepanationBladeBoostEffect()); this.addAbility(ability); // Equip {2} diff --git a/Mage.Sets/src/mage/sets/scarsofmirrodin/ArgentumArmor.java b/Mage.Sets/src/mage/sets/scarsofmirrodin/ArgentumArmor.java index 653c37ac2d..6be5ea9cd0 100644 --- a/Mage.Sets/src/mage/sets/scarsofmirrodin/ArgentumArmor.java +++ b/Mage.Sets/src/mage/sets/scarsofmirrodin/ArgentumArmor.java @@ -34,7 +34,7 @@ import mage.constants.CardType; import mage.constants.Rarity; import mage.constants.Zone; import mage.abilities.Ability; -import mage.abilities.common.AttacksEquippedTriggeredAbility; +import mage.abilities.common.AttacksAttachedTriggeredAbility; import mage.abilities.common.SimpleStaticAbility; import mage.abilities.costs.mana.GenericManaCost; import mage.abilities.effects.common.continious.BoostEquippedEffect; @@ -55,7 +55,7 @@ public class ArgentumArmor extends CardImpl { this.expansionSetCode = "SOM"; this.subtype.add("Equipment"); this.addAbility(new SimpleStaticAbility(Zone.BATTLEFIELD, new BoostEquippedEffect(6, 6))); - Ability ability = new AttacksEquippedTriggeredAbility(new DestroyTargetEffect()); + Ability ability = new AttacksAttachedTriggeredAbility(new DestroyTargetEffect()); ability.addTarget(new TargetPermanent()); this.addAbility(ability); this.addAbility(new EquipAbility(Outcome.AddAbility, new GenericManaCost(6))); diff --git a/Mage.Sets/src/mage/sets/zendikar/ExplorersScope.java b/Mage.Sets/src/mage/sets/zendikar/ExplorersScope.java index 59f729ab35..d23f8509c1 100644 --- a/Mage.Sets/src/mage/sets/zendikar/ExplorersScope.java +++ b/Mage.Sets/src/mage/sets/zendikar/ExplorersScope.java @@ -33,7 +33,7 @@ import mage.constants.Outcome; import mage.constants.Rarity; import mage.constants.Zone; import mage.abilities.Ability; -import mage.abilities.common.AttacksEquippedTriggeredAbility; +import mage.abilities.common.AttacksAttachedTriggeredAbility; import mage.abilities.costs.mana.GenericManaCost; import mage.abilities.effects.OneShotEffect; import mage.abilities.keyword.EquipAbility; @@ -56,7 +56,7 @@ public class ExplorersScope extends CardImpl { this.expansionSetCode = "ZEN"; this.subtype.add("Equipment"); - this.addAbility(new AttacksEquippedTriggeredAbility(new ExplorersScopeEffect())); + this.addAbility(new AttacksAttachedTriggeredAbility(new ExplorersScopeEffect())); this.addAbility(new EquipAbility(Outcome.AddAbility, new GenericManaCost(1))); } diff --git a/Mage.Sets/src/mage/sets/zendikar/GrapplingHook.java b/Mage.Sets/src/mage/sets/zendikar/GrapplingHook.java index 3e795c4063..90aa89417e 100644 --- a/Mage.Sets/src/mage/sets/zendikar/GrapplingHook.java +++ b/Mage.Sets/src/mage/sets/zendikar/GrapplingHook.java @@ -35,7 +35,7 @@ import mage.constants.Outcome; import mage.constants.Rarity; import mage.constants.Zone; import mage.abilities.Ability; -import mage.abilities.common.AttacksEquippedTriggeredAbility; +import mage.abilities.common.AttacksAttachedTriggeredAbility; import mage.abilities.common.SimpleStaticAbility; import mage.abilities.costs.mana.GenericManaCost; import mage.abilities.effects.RequirementEffect; @@ -61,7 +61,7 @@ public class GrapplingHook extends CardImpl { // Equipped creature has double strike. this.addAbility(new SimpleStaticAbility(Zone.BATTLEFIELD, new GainAbilityAttachedEffect(DoubleStrikeAbility.getInstance(), AttachmentType.EQUIPMENT))); // Whenever equipped creature attacks, you may have target creature block it this turn if able. - Ability ability = new AttacksEquippedTriggeredAbility(new GrapplingHookEffect(), true); + Ability ability = new AttacksAttachedTriggeredAbility(new GrapplingHookEffect(), true); ability.addTarget(new TargetCreaturePermanent()); this.addAbility(ability); // Equip {4} diff --git a/Mage/src/mage/abilities/common/AttacksAttachedTriggeredAbility.java b/Mage/src/mage/abilities/common/AttacksAttachedTriggeredAbility.java new file mode 100644 index 0000000000..83ea768593 --- /dev/null +++ b/Mage/src/mage/abilities/common/AttacksAttachedTriggeredAbility.java @@ -0,0 +1,93 @@ +/* + * 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.abilities.TriggeredAbilityImpl; +import mage.abilities.effects.Effect; +import mage.constants.AttachmentType; +import mage.constants.Zone; +import mage.game.Game; +import mage.game.events.GameEvent; +import mage.game.permanent.Permanent; + +/** + * "When enchanted/equipped creature attacks " triggered ability + * + * @author LevelX2 + */ + +public class AttacksAttachedTriggeredAbility extends TriggeredAbilityImpl { + + private AttachmentType attachmentType; + + public AttacksAttachedTriggeredAbility(Effect effect) { + this(effect, false); + } + + public AttacksAttachedTriggeredAbility(Effect effect, boolean optional) { + this(effect, AttachmentType.EQUIPMENT, optional); + } + + public AttacksAttachedTriggeredAbility(Effect effect, AttachmentType attachmentType, boolean optional) { + super(Zone.BATTLEFIELD, effect, optional); + this.attachmentType = attachmentType; + } + + public AttacksAttachedTriggeredAbility(final AttacksAttachedTriggeredAbility abiltity) { + super(abiltity); + this.attachmentType = abiltity.attachmentType; + } + + @Override + public AttacksAttachedTriggeredAbility copy() { + return new AttacksAttachedTriggeredAbility(this); + } + + @Override + public boolean checkTrigger(GameEvent event, Game game) { + Permanent equipment = game.getPermanent(this.sourceId); + if (equipment != null && equipment.getAttachedTo() != null + && event.getType() == GameEvent.EventType.ATTACKER_DECLARED + && event.getSourceId().equals(equipment.getAttachedTo())) { + return true; + } + return false; + } + + @Override + public String getRule() { + StringBuilder sb = new StringBuilder("Whenever "); + if (attachmentType.equals(AttachmentType.EQUIPMENT)) { + sb.append("equipped"); + } else { + sb.append("enchanted"); + } + return sb.append(" creature attacks, ").append(super.getRule()).toString(); + } +} diff --git a/Mage/src/mage/abilities/common/AttacksEquippedTriggeredAbility.java b/Mage/src/mage/abilities/common/AttacksEquippedTriggeredAbility.java deleted file mode 100644 index 99b9860645..0000000000 --- a/Mage/src/mage/abilities/common/AttacksEquippedTriggeredAbility.java +++ /dev/null @@ -1,43 +0,0 @@ -package mage.abilities.common; - -import mage.abilities.TriggeredAbilityImpl; -import mage.abilities.effects.Effect; -import mage.constants.Zone; -import mage.game.Game; -import mage.game.events.GameEvent; -import mage.game.permanent.Permanent; - -public class AttacksEquippedTriggeredAbility extends TriggeredAbilityImpl { - public AttacksEquippedTriggeredAbility(Effect effect) { - super(Zone.BATTLEFIELD, effect); - } - - public AttacksEquippedTriggeredAbility(Effect effect, boolean optional) { - super(Zone.BATTLEFIELD, effect, optional); - } - - public AttacksEquippedTriggeredAbility(final AttacksEquippedTriggeredAbility abiltity) { - super(abiltity); - } - - @Override - public AttacksEquippedTriggeredAbility copy() { - return new AttacksEquippedTriggeredAbility(this); - } - - @Override - public boolean checkTrigger(GameEvent event, Game game) { - Permanent equipment = game.getPermanent(this.sourceId); - if (equipment != null && equipment.getAttachedTo() != null - && event.getType() == GameEvent.EventType.ATTACKER_DECLARED - && event.getSourceId().equals(equipment.getAttachedTo())) { - return true; - } - return false; - } - - @Override - public String getRule() { - return "Whenever equipped creature attacks, " + super.getRule(); - } -} diff --git a/Mage/src/mage/abilities/common/SacrificeSourceTriggeredAbility.java b/Mage/src/mage/abilities/common/SacrificeSourceTriggeredAbility.java new file mode 100644 index 0000000000..db611cd743 --- /dev/null +++ b/Mage/src/mage/abilities/common/SacrificeSourceTriggeredAbility.java @@ -0,0 +1,69 @@ +/* + * 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.abilities.TriggeredAbilityImpl; +import mage.abilities.effects.Effect; +import mage.constants.Zone; +import mage.game.Game; +import mage.game.events.GameEvent; + +/** + * + * @author LevelX2 + */ + +public class SacrificeSourceTriggeredAbility extends TriggeredAbilityImpl { + + public SacrificeSourceTriggeredAbility(Effect effect, boolean optional) { + super(Zone.BATTLEFIELD, effect, optional); + } + + public SacrificeSourceTriggeredAbility(final SacrificeSourceTriggeredAbility ability) { + super(ability); + } + + @Override + public SacrificeSourceTriggeredAbility copy() { + return new SacrificeSourceTriggeredAbility(this); + } + + @Override + public boolean checkTrigger(GameEvent event, Game game) { + if (event.getType() == GameEvent.EventType.SACRIFICED_PERMANENT && event.getTargetId().equals(sourceId)) { + return true; + } + return false; + } + + @Override + public String getRule() { + return "When you sacrifice {this}, " + super.getRule(); + } +}