mirror of
https://github.com/correl/mage.git
synced 2024-11-15 11:09:30 +00:00
Added AttacksAllTriggeredAbility.
This commit is contained in:
parent
d80821fbe4
commit
dd9c620f8b
6 changed files with 144 additions and 132 deletions
|
@ -57,10 +57,12 @@ public class BehemothSledge extends CardImpl {
|
|||
this.subtype.add("Equipment");
|
||||
this.color.setGreen(true);
|
||||
this.color.setWhite(true);
|
||||
this.addAbility(new EquipAbility(Outcome.AddAbility, new GenericManaCost(3)));
|
||||
|
||||
this.addAbility(new SimpleStaticAbility(Zone.BATTLEFIELD, new BoostEquippedEffect(2, 2)));
|
||||
this.addAbility(new SimpleStaticAbility(Zone.BATTLEFIELD, new GainAbilityAttachedEffect(LifelinkAbility.getInstance(), AttachmentType.EQUIPMENT)));
|
||||
this.addAbility(new SimpleStaticAbility(Zone.BATTLEFIELD, new GainAbilityAttachedEffect(TrampleAbility.getInstance(), AttachmentType.EQUIPMENT)));
|
||||
this.addAbility(new SimpleStaticAbility(Zone.BATTLEFIELD, new BoostEquippedEffect(2, 2)));
|
||||
|
||||
this.addAbility(new EquipAbility(Outcome.AddAbility, new GenericManaCost(3)));
|
||||
}
|
||||
|
||||
protected BehemothSledge(BehemothSledge me) {
|
||||
|
|
|
@ -28,18 +28,13 @@
|
|||
package mage.sets.betrayersofkamigawa;
|
||||
|
||||
import java.util.UUID;
|
||||
|
||||
import mage.constants.CardType;
|
||||
import mage.constants.Rarity;
|
||||
import mage.MageInt;
|
||||
import mage.abilities.TriggeredAbilityImpl;
|
||||
import mage.abilities.common.AttacksAllTriggeredAbility;
|
||||
import mage.abilities.effects.common.GainLifeEffect;
|
||||
import mage.abilities.keyword.OfferingAbility;
|
||||
import mage.cards.CardImpl;
|
||||
import mage.constants.Zone;
|
||||
import mage.game.Game;
|
||||
import mage.game.events.GameEvent;
|
||||
|
||||
import mage.constants.CardType;
|
||||
import mage.constants.Rarity;
|
||||
|
||||
/**
|
||||
* @author LevelX2
|
||||
|
@ -59,7 +54,7 @@ public class PatronOfTheKitsune extends CardImpl {
|
|||
this.addAbility(new OfferingAbility("Fox"));
|
||||
|
||||
// Whenever a creature attacks, you may gain 1 life.
|
||||
this.addAbility(new PatronOfTheKitsuneTriggeredAbility());
|
||||
this.addAbility(new AttacksAllTriggeredAbility(new GainLifeEffect(1), true));
|
||||
}
|
||||
|
||||
public PatronOfTheKitsune(final PatronOfTheKitsune card) {
|
||||
|
@ -71,30 +66,3 @@ public class PatronOfTheKitsune extends CardImpl {
|
|||
return new PatronOfTheKitsune(this);
|
||||
}
|
||||
}
|
||||
|
||||
class PatronOfTheKitsuneTriggeredAbility extends TriggeredAbilityImpl {
|
||||
|
||||
public PatronOfTheKitsuneTriggeredAbility() {
|
||||
super(Zone.BATTLEFIELD, new GainLifeEffect(1), true);
|
||||
}
|
||||
|
||||
public PatronOfTheKitsuneTriggeredAbility(PatronOfTheKitsuneTriggeredAbility ability) {
|
||||
super(ability);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean checkTrigger(GameEvent event, Game game) {
|
||||
return event.getType().equals(GameEvent.EventType.ATTACKER_DECLARED);
|
||||
}
|
||||
|
||||
@Override
|
||||
public PatronOfTheKitsuneTriggeredAbility copy() {
|
||||
return new PatronOfTheKitsuneTriggeredAbility(this);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getRule() {
|
||||
return "Whenever a creature attacks, " + super.getRule();
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -27,24 +27,24 @@
|
|||
*/
|
||||
package mage.sets.darkascension;
|
||||
|
||||
import mage.constants.CardType;
|
||||
import mage.constants.Outcome;
|
||||
import mage.constants.Rarity;
|
||||
import java.util.UUID;
|
||||
import mage.MageObject;
|
||||
import mage.abilities.Ability;
|
||||
import mage.abilities.TriggeredAbilityImpl;
|
||||
import mage.abilities.common.AttacksAllTriggeredAbility;
|
||||
import mage.abilities.effects.OneShotEffect;
|
||||
import mage.cards.Card;
|
||||
import mage.cards.CardImpl;
|
||||
import mage.cards.Cards;
|
||||
import mage.cards.CardsImpl;
|
||||
import mage.constants.CardType;
|
||||
import mage.constants.Outcome;
|
||||
import mage.constants.Rarity;
|
||||
import mage.constants.SetTargetPointer;
|
||||
import mage.constants.Zone;
|
||||
import mage.filter.common.FilterCreaturePermanent;
|
||||
import mage.game.Game;
|
||||
import mage.game.events.GameEvent;
|
||||
import mage.game.permanent.Permanent;
|
||||
import mage.players.Player;
|
||||
import mage.target.targetpointer.FixedTarget;
|
||||
|
||||
import java.util.UUID;
|
||||
|
||||
/**
|
||||
*
|
||||
|
@ -59,7 +59,7 @@ public class LostInTheWoods extends CardImpl {
|
|||
this.color.setGreen(true);
|
||||
|
||||
// Whenever a creature attacks you or a planeswalker you control, reveal the top card of your library. If it's a Forest card, remove that creature from combat. Then put the revealed card on the bottom of your library.
|
||||
this.addAbility(new LostInTheWoodsTriggeredAbility());
|
||||
this.addAbility(new AttacksAllTriggeredAbility(new LostInTheWoodsEffect(), true, new FilterCreaturePermanent(), SetTargetPointer.CREATURE, true));
|
||||
}
|
||||
|
||||
public LostInTheWoods(final LostInTheWoods card) {
|
||||
|
@ -76,6 +76,7 @@ class LostInTheWoodsEffect extends OneShotEffect {
|
|||
|
||||
public LostInTheWoodsEffect() {
|
||||
super(Outcome.PreventDamage);
|
||||
staticText = "reveal the top card of your library. If it's a Forest card, remove that creature from combat. Then put the revealed card on the bottom of your library";
|
||||
}
|
||||
|
||||
public LostInTheWoodsEffect(final LostInTheWoodsEffect effect) {
|
||||
|
@ -84,16 +85,16 @@ class LostInTheWoodsEffect extends OneShotEffect {
|
|||
|
||||
@Override
|
||||
public boolean apply(Game game, Ability source) {
|
||||
Player player = game.getPlayer(source.getControllerId());
|
||||
if (player == null) {
|
||||
Player controller = game.getPlayer(source.getControllerId());
|
||||
MageObject sourceObject = game.getObject(source.getSourceId());
|
||||
if (sourceObject == null || controller == null) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (player.getLibrary().size() > 0) {
|
||||
Card card = player.getLibrary().getFromTop(game);
|
||||
if (controller.getLibrary().size() > 0) {
|
||||
Card card = controller.getLibrary().getFromTop(game);
|
||||
Cards cards = new CardsImpl();
|
||||
cards.add(card);
|
||||
player.revealCards("Lost in the Woods", cards, game);
|
||||
controller.revealCards(sourceObject.getLogName(), cards, game);
|
||||
|
||||
if (card != null) {
|
||||
if (card.getSubtype().contains("Forest")) {
|
||||
|
@ -102,11 +103,10 @@ class LostInTheWoodsEffect extends OneShotEffect {
|
|||
permanent.removeFromCombat(game);
|
||||
}
|
||||
}
|
||||
card.moveToZone(Zone.LIBRARY, source.getSourceId(), game, false);
|
||||
return true;
|
||||
controller.moveCardToLibraryWithInfo(card, source.getSourceId(), game, Zone.LIBRARY, false, true);
|
||||
}
|
||||
}
|
||||
return false;
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -115,40 +115,3 @@ class LostInTheWoodsEffect extends OneShotEffect {
|
|||
}
|
||||
|
||||
}
|
||||
|
||||
class LostInTheWoodsTriggeredAbility extends TriggeredAbilityImpl {
|
||||
|
||||
public LostInTheWoodsTriggeredAbility() {
|
||||
super(Zone.BATTLEFIELD, new LostInTheWoodsEffect(), false);
|
||||
}
|
||||
|
||||
public LostInTheWoodsTriggeredAbility(final LostInTheWoodsTriggeredAbility ability) {
|
||||
super(ability);
|
||||
}
|
||||
|
||||
@Override
|
||||
public LostInTheWoodsTriggeredAbility copy() {
|
||||
return new LostInTheWoodsTriggeredAbility(this);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean checkTrigger(GameEvent event, Game game) {
|
||||
if (event.getType() == GameEvent.EventType.ATTACKER_DECLARED) {
|
||||
if (event.getTargetId().equals(controllerId)) {
|
||||
this.getEffects().get(0).setTargetPointer(new FixedTarget(event.getSourceId()));
|
||||
return true;
|
||||
}
|
||||
Permanent permanent = game.getPermanent(event.getTargetId());
|
||||
if (permanent != null && permanent.getCardType().contains(CardType.PLANESWALKER) && permanent.getControllerId().equals(controllerId)) {
|
||||
this.getEffects().get(0).setTargetPointer(new FixedTarget(event.getSourceId()));
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getRule() {
|
||||
return "Whenever a creature attacks you or a planeswalker you control, reveal the top card of your library. If it's a Forest card, remove that creature from combat. Then put the revealed card on the bottom of your library.";
|
||||
}
|
||||
}
|
||||
|
|
|
@ -33,9 +33,11 @@ import mage.constants.CardType;
|
|||
import mage.constants.Rarity;
|
||||
import mage.MageInt;
|
||||
import mage.abilities.TriggeredAbilityImpl;
|
||||
import mage.abilities.common.AttacksAllTriggeredAbility;
|
||||
import mage.abilities.effects.common.DrawCardSourceControllerEffect;
|
||||
import mage.abilities.keyword.FlyingAbility;
|
||||
import mage.cards.CardImpl;
|
||||
import mage.constants.SetTargetPointer;
|
||||
import mage.constants.Zone;
|
||||
import mage.game.Game;
|
||||
import mage.game.events.GameEvent;
|
||||
|
@ -64,7 +66,7 @@ public class IsperiaSupremeJudge extends CardImpl {
|
|||
this.addAbility(FlyingAbility.getInstance());
|
||||
|
||||
// Whenever a creature attacks you or a planeswalker you control, you may draw a card.
|
||||
this.addAbility(new IsperiaSupremeJudgeTriggeredAbility());
|
||||
this.addAbility(new AttacksAllTriggeredAbility(new DrawCardSourceControllerEffect(1), true, true));
|
||||
}
|
||||
|
||||
public IsperiaSupremeJudge(final IsperiaSupremeJudge card) {
|
||||
|
@ -76,40 +78,3 @@ public class IsperiaSupremeJudge extends CardImpl {
|
|||
return new IsperiaSupremeJudge(this);
|
||||
}
|
||||
}
|
||||
|
||||
class IsperiaSupremeJudgeTriggeredAbility extends TriggeredAbilityImpl {
|
||||
|
||||
public IsperiaSupremeJudgeTriggeredAbility() {
|
||||
super(Zone.BATTLEFIELD, new DrawCardSourceControllerEffect(1), true);
|
||||
}
|
||||
|
||||
public IsperiaSupremeJudgeTriggeredAbility(final IsperiaSupremeJudgeTriggeredAbility ability) {
|
||||
super(ability);
|
||||
}
|
||||
|
||||
@Override
|
||||
public IsperiaSupremeJudgeTriggeredAbility copy() {
|
||||
return new IsperiaSupremeJudgeTriggeredAbility(this);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean checkTrigger(GameEvent event, Game game) {
|
||||
if (event.getType() == GameEvent.EventType.ATTACKER_DECLARED) {
|
||||
if (event.getTargetId().equals(controllerId)) {
|
||||
this.getEffects().get(0).setTargetPointer(new FixedTarget(event.getSourceId()));
|
||||
return true;
|
||||
}
|
||||
Permanent permanent = game.getPermanent(event.getTargetId());
|
||||
if (permanent != null && permanent.getCardType().contains(CardType.PLANESWALKER) && permanent.getControllerId().equals(controllerId)) {
|
||||
this.getEffects().get(0).setTargetPointer(new FixedTarget(event.getSourceId()));
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getRule() {
|
||||
return "Whenever a creature attacks you or a planeswalker you control, you may draw a card.";
|
||||
}
|
||||
}
|
114
Mage/src/mage/abilities/common/AttacksAllTriggeredAbility.java
Normal file
114
Mage/src/mage/abilities/common/AttacksAllTriggeredAbility.java
Normal file
|
@ -0,0 +1,114 @@
|
|||
/*
|
||||
* 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.CardType;
|
||||
import mage.constants.SetTargetPointer;
|
||||
import mage.constants.Zone;
|
||||
import mage.filter.common.FilterCreaturePermanent;
|
||||
import mage.game.Game;
|
||||
import mage.game.events.GameEvent;
|
||||
import mage.game.permanent.Permanent;
|
||||
import mage.target.targetpointer.FixedTarget;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author LevelX2
|
||||
*/
|
||||
|
||||
public class AttacksAllTriggeredAbility extends TriggeredAbilityImpl {
|
||||
|
||||
protected FilterCreaturePermanent filter;
|
||||
protected boolean attacksYouOrYourPlaneswalker;
|
||||
protected SetTargetPointer setTargetPointer;
|
||||
|
||||
public AttacksAllTriggeredAbility(Effect effect, boolean optional) {
|
||||
this(effect, optional, new FilterCreaturePermanent(), SetTargetPointer.NONE, false);
|
||||
}
|
||||
|
||||
public AttacksAllTriggeredAbility(Effect effect, boolean optional, boolean attacksYouOrYourPlaneswalker) {
|
||||
this(effect, optional, new FilterCreaturePermanent(), SetTargetPointer.NONE, attacksYouOrYourPlaneswalker);
|
||||
}
|
||||
|
||||
public AttacksAllTriggeredAbility(Effect effect, boolean optional, FilterCreaturePermanent filter, SetTargetPointer setTargetPointer, boolean attacksYouOrYourPlaneswalker) {
|
||||
super(Zone.BATTLEFIELD, effect, optional);
|
||||
this.filter = filter;
|
||||
this.attacksYouOrYourPlaneswalker = attacksYouOrYourPlaneswalker;
|
||||
this.setTargetPointer = setTargetPointer;
|
||||
}
|
||||
|
||||
public AttacksAllTriggeredAbility(final AttacksAllTriggeredAbility ability) {
|
||||
super(ability);
|
||||
this.filter = ability.filter.copy();
|
||||
this.attacksYouOrYourPlaneswalker = ability.attacksYouOrYourPlaneswalker;
|
||||
this.setTargetPointer = ability.setTargetPointer;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean checkTrigger(GameEvent event, Game game) {
|
||||
if (event.getType().equals(GameEvent.EventType.ATTACKER_DECLARED)) {
|
||||
Permanent permanent = game.getPermanent(event.getSourceId());
|
||||
if (filter.match(permanent, getSourceId(), getControllerId(), game)) {
|
||||
if (attacksYouOrYourPlaneswalker) {
|
||||
boolean check = false;
|
||||
if (event.getTargetId().equals(getControllerId())) {
|
||||
check = true;
|
||||
} else {
|
||||
Permanent planeswalker = game.getPermanent(event.getTargetId());
|
||||
if (planeswalker != null && planeswalker.getCardType().contains(CardType.PLANESWALKER) && planeswalker.getControllerId().equals(getControllerId())) {
|
||||
check = true;
|
||||
}
|
||||
}
|
||||
if (!check) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
if (SetTargetPointer.CREATURE.equals(setTargetPointer)) {
|
||||
for (Effect effect: getEffects()) {
|
||||
effect.setTargetPointer(new FixedTarget(permanent.getId()));
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public AttacksAllTriggeredAbility copy() {
|
||||
return new AttacksAllTriggeredAbility(this);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getRule() {
|
||||
return "Whenever a " + filter.getMessage() + " attacks" + (attacksYouOrYourPlaneswalker ? " you or a planeswalker you control":"") +", " + super.getRule();
|
||||
}
|
||||
|
||||
}
|
|
@ -40,7 +40,7 @@ import mage.game.Game;
|
|||
*/
|
||||
public class OwnerPredicate implements ObjectPlayerPredicate<ObjectPlayer<Card>> {
|
||||
|
||||
private TargetController targetOwner;
|
||||
private final TargetController targetOwner;
|
||||
|
||||
public OwnerPredicate(TargetController targetOwner) {
|
||||
this.targetOwner = targetOwner;
|
||||
|
|
Loading…
Reference in a new issue