mirror of
https://github.com/correl/mage.git
synced 2025-01-11 19:13:02 +00:00
Implemented Maddening Imp
This commit is contained in:
parent
6fc977c843
commit
3509bdfa56
1 changed files with 200 additions and 0 deletions
200
Mage.Sets/src/mage/cards/m/MaddeningImp.java
Normal file
200
Mage.Sets/src/mage/cards/m/MaddeningImp.java
Normal file
|
@ -0,0 +1,200 @@
|
|||
/*
|
||||
* 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.cards.m;
|
||||
|
||||
import java.util.HashSet;
|
||||
import java.util.Set;
|
||||
import java.util.UUID;
|
||||
import mage.MageInt;
|
||||
import mage.MageObjectReference;
|
||||
import mage.abilities.Ability;
|
||||
import mage.abilities.common.delayed.AtTheBeginOfNextEndStepDelayedTriggeredAbility;
|
||||
import mage.abilities.condition.Condition;
|
||||
import mage.abilities.condition.InvertCondition;
|
||||
import mage.abilities.condition.common.TargetAttackedThisTurnCondition;
|
||||
import mage.abilities.costs.common.TapSourceCost;
|
||||
import mage.abilities.decorator.ConditionalActivatedAbility;
|
||||
import mage.abilities.effects.OneShotEffect;
|
||||
import mage.abilities.effects.common.combat.AttacksIfAbleAllEffect;
|
||||
import mage.abilities.keyword.FlyingAbility;
|
||||
import mage.cards.CardImpl;
|
||||
import mage.cards.CardSetInfo;
|
||||
import mage.constants.*;
|
||||
import mage.filter.common.FilterCreaturePermanent;
|
||||
import mage.filter.predicate.Predicates;
|
||||
import mage.filter.predicate.mageobject.SubtypePredicate;
|
||||
import mage.filter.predicate.permanent.ControllerPredicate;
|
||||
import mage.game.Game;
|
||||
import mage.game.permanent.Permanent;
|
||||
import mage.players.Player;
|
||||
import mage.watchers.common.AttackedThisTurnWatcher;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author L_J
|
||||
*/
|
||||
public class MaddeningImp extends CardImpl {
|
||||
|
||||
private static final FilterCreaturePermanent filter = new FilterCreaturePermanent("non-Wall creatures");
|
||||
|
||||
static {
|
||||
filter.add(Predicates.not(new SubtypePredicate(SubType.WALL)));
|
||||
filter.add(new ControllerPredicate(TargetController.ACTIVE));
|
||||
filter.setMessage("non-Wall creatures the active player controls");
|
||||
}
|
||||
|
||||
public MaddeningImp(UUID ownerId, CardSetInfo setInfo) {
|
||||
super(ownerId, setInfo, new CardType[]{CardType.CREATURE}, "{2}{B}");
|
||||
this.subtype.add(SubType.IMP);
|
||||
this.power = new MageInt(1);
|
||||
this.toughness = new MageInt(1);
|
||||
|
||||
// Flying
|
||||
this.addAbility(FlyingAbility.getInstance());
|
||||
|
||||
// {T}: Non-Wall creatures the active player controls attack this turn if able. At the beginning of the next end step, destroy each of those creatures that didn't attack this turn. Activate this ability only during an opponent's turn and only before combat.
|
||||
Ability ability = new ConditionalActivatedAbility(Zone.BATTLEFIELD, new AttacksIfAbleAllEffect(filter, Duration.EndOfTurn),
|
||||
new TapSourceCost(), new MaddeningImpTurnCondition(),
|
||||
"{T}: Non-Wall creatures the active player controls attack this turn if able. "
|
||||
+ "At the beginning of the next end step, destroy each of those creatures that didn't attack this turn. "
|
||||
+ "Activate this ability only during an opponent's turn and only before combat.");
|
||||
ability.addEffect(new MaddeningImpCreateDelayedTriggeredAbilityEffect());
|
||||
this.addAbility(ability, new AttackedThisTurnWatcher());
|
||||
|
||||
}
|
||||
|
||||
public MaddeningImp(final MaddeningImp card) {
|
||||
super(card);
|
||||
}
|
||||
|
||||
@Override
|
||||
public MaddeningImp copy() {
|
||||
return new MaddeningImp(this);
|
||||
}
|
||||
}
|
||||
|
||||
class MaddeningImpTurnCondition implements Condition {
|
||||
|
||||
@Override
|
||||
public boolean apply(Game game, Ability source) {
|
||||
Player activePlayer = game.getPlayer(game.getActivePlayerId());
|
||||
return activePlayer != null && activePlayer.hasOpponent(source.getControllerId(), game) && game.getPhase().getStep().getType().getIndex() < 5;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "";
|
||||
}
|
||||
}
|
||||
|
||||
class MaddeningImpCreateDelayedTriggeredAbilityEffect extends OneShotEffect {
|
||||
|
||||
private static final FilterCreaturePermanent filter = new FilterCreaturePermanent();
|
||||
|
||||
static {
|
||||
filter.add(Predicates.not(new SubtypePredicate(SubType.WALL)));
|
||||
filter.add(new ControllerPredicate(TargetController.ACTIVE));
|
||||
}
|
||||
|
||||
public MaddeningImpCreateDelayedTriggeredAbilityEffect() {
|
||||
super(Outcome.DestroyPermanent);
|
||||
this.staticText = "At the beginning of the next end step, destroy each of those creatures that didn't attack this turn";
|
||||
}
|
||||
|
||||
public MaddeningImpCreateDelayedTriggeredAbilityEffect(final MaddeningImpCreateDelayedTriggeredAbilityEffect effect) {
|
||||
super(effect);
|
||||
}
|
||||
|
||||
@Override
|
||||
public MaddeningImpCreateDelayedTriggeredAbilityEffect copy() {
|
||||
return new MaddeningImpCreateDelayedTriggeredAbilityEffect(this);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean apply(Game game, Ability source) {
|
||||
Player player = game.getPlayer(game.getActivePlayerId());
|
||||
if (player != null) {
|
||||
Set<MageObjectReference> activeCreatures = new HashSet<>();
|
||||
for (Permanent creature : game.getBattlefield().getAllActivePermanents(filter, player.getId(), game)) {
|
||||
if (creature != null) {
|
||||
activeCreatures.add(new MageObjectReference(creature, game));
|
||||
}
|
||||
}
|
||||
AtTheBeginOfNextEndStepDelayedTriggeredAbility delayedAbility
|
||||
= new AtTheBeginOfNextEndStepDelayedTriggeredAbility(Zone.ALL, new MaddeningImpDelayedDestroyEffect(activeCreatures), TargetController.ANY, new InvertCondition(TargetAttackedThisTurnCondition.instance));
|
||||
delayedAbility.getDuration();
|
||||
game.addDelayedTriggeredAbility(delayedAbility, source);
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
class MaddeningImpDelayedDestroyEffect extends OneShotEffect {
|
||||
|
||||
private Set<MageObjectReference> activeCreatures;
|
||||
|
||||
MaddeningImpDelayedDestroyEffect(Set<MageObjectReference> activeCreatures) {
|
||||
super(Outcome.DestroyPermanent);
|
||||
this.activeCreatures = activeCreatures;
|
||||
this.staticText = "At the beginning of the next end step, destroy each of those creatures that didn't attack this turn";
|
||||
}
|
||||
|
||||
MaddeningImpDelayedDestroyEffect(final MaddeningImpDelayedDestroyEffect effect) {
|
||||
super(effect);
|
||||
this.activeCreatures = effect.activeCreatures;
|
||||
}
|
||||
|
||||
@Override
|
||||
public MaddeningImpDelayedDestroyEffect copy() {
|
||||
return new MaddeningImpDelayedDestroyEffect(this);
|
||||
}
|
||||
|
||||
public boolean apply(Game game, Ability source) {
|
||||
Player player = game.getPlayer(game.getActivePlayerId());
|
||||
if (player != null) {
|
||||
for (Permanent permanent : game.getBattlefield().getAllActivePermanents(player.getId())) {
|
||||
|
||||
MageObjectReference mor = new MageObjectReference(permanent, game);
|
||||
// Only affect permanents present when the ability resolved
|
||||
if (!activeCreatures.contains(mor)) {
|
||||
continue;
|
||||
}
|
||||
// Creatures that attacked are safe.
|
||||
AttackedThisTurnWatcher watcher = (AttackedThisTurnWatcher) game.getState().getWatchers().get(AttackedThisTurnWatcher.class.getSimpleName());
|
||||
if (watcher != null && watcher.getAttackedThisTurnCreatures().contains(mor)) {
|
||||
continue;
|
||||
}
|
||||
// Destroy the rest.
|
||||
permanent.destroy(source.getSourceId(), game, false);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
}
|
Loading…
Reference in a new issue