Fixed that creatures forced to attack that have to pay a cost to attack lock the UI (not completed for all existing cards yet).

This commit is contained in:
LevelX2 2015-07-01 02:00:07 +02:00
parent 5f5513f4ed
commit 15fe85c5da
13 changed files with 326 additions and 301 deletions

View file

@ -25,20 +25,15 @@
* authors and should not be interpreted as representing official policies, either expressed
* or implied, of BetaSteward_at_googlemail.com.
*/
package mage.sets.championsofkamigawa;
import java.util.UUID;
import mage.constants.*;
import mage.abilities.Ability;
import mage.abilities.common.SimpleStaticAbility;
import mage.abilities.costs.mana.ManaCostsImpl;
import mage.abilities.effects.ReplacementEffectImpl;
import mage.abilities.effects.common.replacement.CantAttackYouUnlessPayManaAllEffect;
import mage.cards.CardImpl;
import mage.game.Game;
import mage.game.events.GameEvent;
import mage.players.Player;
/**
*
@ -46,16 +41,16 @@ import mage.players.Player;
*/
public class GhostlyPrison extends CardImpl {
public GhostlyPrison (UUID ownerId) {
public GhostlyPrison(UUID ownerId) {
super(ownerId, 10, "Ghostly Prison", Rarity.UNCOMMON, new CardType[]{CardType.ENCHANTMENT}, "{2}{W}");
this.expansionSetCode = "CHK";
// Creatures can't attack you unless their controller pays {2} for each creature he or she controls that's attacking you
this.addAbility(new SimpleStaticAbility(Zone.BATTLEFIELD, new GhostlyPrisonReplacementEffect()));
this.addAbility(new SimpleStaticAbility(Zone.BATTLEFIELD, new CantAttackYouUnlessPayManaAllEffect(new ManaCostsImpl("{2}"))));
}
public GhostlyPrison (final GhostlyPrison card) {
public GhostlyPrison(final GhostlyPrison card) {
super(card);
}
@ -65,58 +60,3 @@ public class GhostlyPrison extends CardImpl {
}
}
class GhostlyPrisonReplacementEffect extends ReplacementEffectImpl {
private static final String effectText = "Creatures can't attack you unless their controller pays {2} for each creature he or she controls that's attacking you";
GhostlyPrisonReplacementEffect ( ) {
super(Duration.WhileOnBattlefield, Outcome.Neutral);
staticText = effectText;
}
GhostlyPrisonReplacementEffect ( GhostlyPrisonReplacementEffect effect ) {
super(effect);
}
@Override
public boolean checksEventType(GameEvent event, Game game) {
return event.getType() == GameEvent.EventType.DECLARE_ATTACKER;
}
@Override
public boolean applies(GameEvent event, Ability source, Game game) {
if (event.getTargetId().equals(source.getControllerId()) ) {
Player attackedPlayer = game.getPlayer(event.getTargetId());
if (attackedPlayer != null) {
// only if a player is attacked. Attacking a planeswalker is free
return true;
}
}
return false;
}
@Override
public boolean replaceEvent(GameEvent event, Ability source, Game game) {
Player player = game.getPlayer(event.getPlayerId());
if ( player != null && event.getTargetId().equals(source.getControllerId())) {
ManaCostsImpl attackTax = new ManaCostsImpl("{2}");
if (attackTax.canPay(source, source.getSourceId(), event.getPlayerId(), game) &&
player.chooseUse(Outcome.Benefit, "Pay {2} to attack player?", source, game) ) {
if (attackTax.payOrRollback(source, game, this.getId(), event.getPlayerId())) {
return false;
}
}
return true;
}
return false;
}
@Override
public GhostlyPrisonReplacementEffect copy() {
return new GhostlyPrisonReplacementEffect(this);
}
}

View file

@ -31,9 +31,8 @@ import java.util.UUID;
import mage.MageInt;
import mage.abilities.Ability;
import mage.abilities.common.SimpleStaticAbility;
import mage.abilities.costs.common.ReturnToHandTargetPermanentCost;
import mage.abilities.costs.common.SacrificeTargetCost;
import mage.abilities.effects.ReplacementEffectImpl;
import mage.abilities.effects.PayCostToAttackBlockEffectImpl;
import mage.abilities.keyword.FlyingAbility;
import mage.cards.CardImpl;
import mage.constants.CardType;
@ -42,11 +41,8 @@ import mage.constants.Outcome;
import mage.constants.Rarity;
import mage.constants.Zone;
import mage.filter.common.FilterControlledLandPermanent;
import mage.filter.common.FilterControlledPermanent;
import mage.filter.predicate.mageobject.CardTypePredicate;
import mage.game.Game;
import mage.game.events.GameEvent;
import mage.players.Player;
import mage.target.common.TargetControlledPermanent;
/**
@ -64,9 +60,9 @@ public class ExaltedDragon extends CardImpl {
// Flying
this.addAbility(FlyingAbility.getInstance());
// Exalted Dragon can't attack unless you sacrifice a land.
this.addAbility(new SimpleStaticAbility(Zone.BATTLEFIELD, new ExaltedDragonReplacementEffect()));
this.addAbility(new SimpleStaticAbility(Zone.BATTLEFIELD, new ExaltedDragonCostToAttackBlockEffect()));
}
public ExaltedDragon(final ExaltedDragon card) {
@ -79,55 +75,26 @@ public class ExaltedDragon extends CardImpl {
}
}
class ExaltedDragonReplacementEffect extends ReplacementEffectImpl {
class ExaltedDragonCostToAttackBlockEffect extends PayCostToAttackBlockEffectImpl {
private static final FilterControlledPermanent filter = new FilterControlledLandPermanent();
ExaltedDragonReplacementEffect ( ) {
super(Duration.WhileOnBattlefield, Outcome.Neutral);
ExaltedDragonCostToAttackBlockEffect() {
super(Duration.WhileOnBattlefield, Outcome.Detriment, RestrictType.ATTACK,
new SacrificeTargetCost(new TargetControlledPermanent(new FilterControlledLandPermanent("a land"))));
staticText = "{this} can't attack unless you sacrifice a land <i>(This cost is paid as attackers are declared.)</i>";
}
ExaltedDragonReplacementEffect ( ExaltedDragonReplacementEffect effect ) {
ExaltedDragonCostToAttackBlockEffect(ExaltedDragonCostToAttackBlockEffect effect) {
super(effect);
}
@Override
public boolean apply(Game game, Ability source) {
throw new UnsupportedOperationException("Not supported.");
}
@Override
public boolean replaceEvent(GameEvent event, Ability source, Game game) {
Player player = game.getPlayer(event.getPlayerId());
if ( player != null ) {
SacrificeTargetCost attackCost = new SacrificeTargetCost(new TargetControlledPermanent(filter));
if ( attackCost.canPay(source, source.getSourceId(), event.getPlayerId(), game) &&
player.chooseUse(Outcome.Neutral, "Sacrifice a land?", source, game) )
{
if (attackCost.pay(source, game, source.getSourceId(), event.getPlayerId(), false) ) {
return false;
}
}
return true;
}
return false;
}
@Override
public boolean checksEventType(GameEvent event, Game game) {
return event.getType() == GameEvent.EventType.DECLARE_ATTACKER;
}
@Override
public boolean applies(GameEvent event, Ability source, Game game) {
return event.getSourceId().equals(source.getSourceId());
return source.getSourceId().equals(event.getSourceId());
}
@Override
public ExaltedDragonReplacementEffect copy() {
return new ExaltedDragonReplacementEffect(this);
public ExaltedDragonCostToAttackBlockEffect copy() {
return new ExaltedDragonCostToAttackBlockEffect(this);
}
}

View file

@ -30,8 +30,9 @@ package mage.sets.saviorsofkamigawa;
import java.util.UUID;
import mage.abilities.Ability;
import mage.abilities.common.SimpleStaticAbility;
import mage.abilities.costs.Cost;
import mage.abilities.costs.mana.GenericManaCost;
import mage.abilities.costs.mana.ManaCosts;
import mage.abilities.costs.mana.ManaCostsImpl;
import mage.abilities.effects.PayCostToAttackBlockEffectImpl;
import mage.abilities.effects.common.AttachEffect;
import mage.abilities.keyword.EnchantAbility;
@ -83,7 +84,7 @@ public class CowedByWisdom extends CardImpl {
class CowedByWisdomayCostToAttackBlockEffect extends PayCostToAttackBlockEffectImpl {
CowedByWisdomayCostToAttackBlockEffect() {
super(Duration.WhileOnBattlefield, Outcome.Detriment, RestrictType.ATTACK_AND_BLOCK, null);
super(Duration.WhileOnBattlefield, Outcome.Detriment, RestrictType.ATTACK_AND_BLOCK);
staticText = "Enchanted creature can't attack or block unless its controller pays {1} for each card in your hand";
}
@ -92,10 +93,12 @@ class CowedByWisdomayCostToAttackBlockEffect extends PayCostToAttackBlockEffectI
}
@Override
public Cost getCostToPay(GameEvent event, Ability source, Game game) {
public ManaCosts getManaCostToPay(GameEvent event, Ability source, Game game) {
Player controller = game.getPlayer(source.getControllerId());
if (controller != null && !controller.getHand().isEmpty()) {
return new GenericManaCost(controller.getHand().size());
ManaCosts manaCosts = new ManaCostsImpl();
manaCosts.add(new GenericManaCost(controller.getHand().size()));
return manaCosts;
}
return null;
}

View file

@ -28,19 +28,13 @@
package mage.sets.tempest;
import java.util.UUID;
import mage.abilities.Ability;
import mage.abilities.common.SimpleStaticAbility;
import mage.abilities.costs.mana.ManaCostsImpl;
import mage.abilities.effects.ReplacementEffectImpl;
import mage.abilities.effects.common.replacement.CantAttackYouUnlessPayManaAllEffect;
import mage.cards.CardImpl;
import mage.constants.CardType;
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.players.Player;
/**
*
@ -52,7 +46,8 @@ public class Propaganda extends CardImpl {
super(ownerId, 80, "Propaganda", Rarity.UNCOMMON, new CardType[]{CardType.ENCHANTMENT}, "{2}{U}");
this.expansionSetCode = "TMP";
this.addAbility(new SimpleStaticAbility(Zone.BATTLEFIELD, new PropagandaReplacementEffect()));
// Creatures can't attack you unless their controller pays {2} for each creature he or she controls that's attacking you.
this.addAbility(new SimpleStaticAbility(Zone.BATTLEFIELD, new CantAttackYouUnlessPayManaAllEffect(new ManaCostsImpl("{2}"))));
}
public Propaganda(final Propaganda card) {
@ -64,56 +59,3 @@ public class Propaganda extends CardImpl {
return new Propaganda(this);
}
}
class PropagandaReplacementEffect extends ReplacementEffectImpl {
private static final String effectText = "Creatures can't attack you unless their controller pays {2} for each creature he or she controls that's attacking you";
PropagandaReplacementEffect() {
super(Duration.WhileOnBattlefield, Outcome.Neutral);
staticText = effectText;
}
PropagandaReplacementEffect(PropagandaReplacementEffect effect) {
super(effect);
}
@Override
public boolean checksEventType(GameEvent event, Game game) {
return event.getType() == GameEvent.EventType.DECLARE_ATTACKER;
}
@Override
public boolean applies(GameEvent event, Ability source, Game game) {
if (event.getTargetId().equals(source.getControllerId())) {
Player attackedPlayer = game.getPlayer(event.getTargetId());
if (attackedPlayer != null) {
// only if a player is attacked. Attacking a planeswalker is free
return true;
}
}
return false;
}
@Override
public boolean replaceEvent(GameEvent event, Ability source, Game game) {
Player player = game.getPlayer(event.getPlayerId());
if (player != null) {
ManaCostsImpl attackTax = new ManaCostsImpl("{2}");
if (attackTax.canPay(source, source.getSourceId(), event.getPlayerId(), game)
&& player.chooseUse(Outcome.Neutral, "Pay {2} to attack player?", source, game)) {
if (attackTax.payOrRollback(source, game, source.getSourceId(), event.getPlayerId())) {
return false;
}
}
return true;
}
return false;
}
@Override
public PropagandaReplacementEffect copy() {
return new PropagandaReplacementEffect(this);
}
}

View file

@ -28,15 +28,19 @@
package mage.sets.tenthedition;
import java.util.UUID;
import mage.constants.*;
import mage.MageInt;
import mage.abilities.Ability;
import mage.abilities.common.SimpleStaticAbility;
import mage.abilities.costs.mana.ManaCostsImpl;
import mage.abilities.effects.ReplacementEffectImpl;
import mage.abilities.effects.common.replacement.CantAttackYouUnlessPayManaAllEffect;
import mage.abilities.keyword.FlyingAbility;
import mage.cards.CardImpl;
import mage.constants.CardType;
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.players.Player;
@ -53,12 +57,13 @@ public class WindbornMuse extends CardImpl {
this.subtype.add("Spirit");
this.power = new MageInt(2);
this.toughness = new MageInt(3);
// Flying
this.addAbility(FlyingAbility.getInstance());
// Creatures can't attack you unless their controller pays {2} for each creature he or she controls that's attacking you.
this.addAbility(new SimpleStaticAbility(Zone.BATTLEFIELD, new WindbornMuseReplacementEffect()));
this.addAbility(new SimpleStaticAbility(Zone.BATTLEFIELD, new CantAttackYouUnlessPayManaAllEffect(new ManaCostsImpl("{2}"))));
}
public WindbornMuse(final WindbornMuse card) {
@ -75,12 +80,12 @@ class WindbornMuseReplacementEffect extends ReplacementEffectImpl {
private static final String effectText = "Creatures can't attack you unless their controller pays {2} for each creature he or she controls that's attacking you";
WindbornMuseReplacementEffect ( ) {
WindbornMuseReplacementEffect() {
super(Duration.WhileOnBattlefield, Outcome.Benefit);
staticText = effectText;
}
WindbornMuseReplacementEffect ( WindbornMuseReplacementEffect effect ) {
WindbornMuseReplacementEffect(WindbornMuseReplacementEffect effect) {
super(effect);
}
@ -88,10 +93,10 @@ class WindbornMuseReplacementEffect extends ReplacementEffectImpl {
public boolean checksEventType(GameEvent event, Game game) {
return event.getType() == GameEvent.EventType.DECLARE_ATTACKER;
}
@Override
public boolean applies(GameEvent event, Ability source, Game game) {
if (event.getTargetId().equals(source.getControllerId()) ) {
if (event.getTargetId().equals(source.getControllerId())) {
Player attackedPlayer = game.getPlayer(event.getTargetId());
if (attackedPlayer != null) {
// only if a player is attacked. Attacking a planeswalker is free
@ -100,15 +105,14 @@ class WindbornMuseReplacementEffect extends ReplacementEffectImpl {
}
return false;
}
@Override
public boolean replaceEvent(GameEvent event, Ability source, Game game) {
Player player = game.getPlayer(event.getPlayerId());
if ( player != null && event.getTargetId().equals(source.getControllerId())) {
if (player != null && event.getTargetId().equals(source.getControllerId())) {
ManaCostsImpl attackTax = new ManaCostsImpl("{2}");
if ( attackTax.canPay(source, source.getSourceId(), event.getPlayerId(), game) &&
player.chooseUse(Outcome.Benefit, "Pay {2} to attack player?", source, game) )
{
if (attackTax.canPay(source, source.getSourceId(), event.getPlayerId(), game)
&& player.chooseUse(Outcome.Benefit, "Pay {2} to attack player?", source, game)) {
if (attackTax.payOrRollback(source, game, this.getId(), event.getPlayerId())) {
return false;
}
@ -124,4 +128,3 @@ class WindbornMuseReplacementEffect extends ReplacementEffectImpl {
}
}