Reworked some replacement effects.

This commit is contained in:
LevelX2 2015-03-14 09:48:20 +01:00
parent b4a0fd5920
commit 190f9dc0b3
10 changed files with 177 additions and 157 deletions

View file

@ -27,7 +27,7 @@
*/
package mage.sets.avacynrestored;
import mage.constants.*;
import java.util.UUID;
import mage.MageInt;
import mage.abilities.Ability;
import mage.abilities.common.SimpleStaticAbility;
@ -35,12 +35,19 @@ import mage.abilities.effects.ReplacementEffectImpl;
import mage.abilities.keyword.FirstStrikeAbility;
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.game.events.GameEvent.EventType;
import static mage.game.events.GameEvent.EventType.DAMAGE_CREATURE;
import static mage.game.events.GameEvent.EventType.DAMAGE_PLANESWALKER;
import static mage.game.events.GameEvent.EventType.DAMAGE_PLAYER;
import mage.game.permanent.Permanent;
import java.util.UUID;
/**
*
* @author noxx
@ -53,8 +60,6 @@ public class GiselaBladeOfGoldnight extends CardImpl {
this.supertype.add("Legendary");
this.subtype.add("Angel");
this.color.setRed(true);
this.color.setWhite(true);
this.power = new MageInt(5);
this.toughness = new MageInt(5);
@ -93,8 +98,35 @@ class GiselaBladeOfGoldnightDoubleDamageEffect extends ReplacementEffectImpl {
return new GiselaBladeOfGoldnightDoubleDamageEffect(this);
}
@Override
public boolean checksEventType(GameEvent event, Game game) {
return event.getType().equals(EventType.DAMAGE_CREATURE) ||
event.getType().equals(EventType.DAMAGE_PLANESWALKER) ||
event.getType().equals(EventType.DAMAGE_PLAYER);
}
@Override
public boolean applies(GameEvent event, Ability source, Game game) {
return true;
}
private void preventDamage(GameEvent event, Ability source, UUID target, Game game) {
int amount = (int)Math.ceil(event.getAmount() / 2.0);
GameEvent preventEvent = new GameEvent(GameEvent.EventType.PREVENT_DAMAGE, target, source.getSourceId(), source.getControllerId(), amount, false);
if (!game.replaceEvent(preventEvent)) {
event.setAmount(event.getAmount() - amount);
game.fireEvent(GameEvent.getEvent(GameEvent.EventType.PREVENTED_DAMAGE, target, source.getSourceId(), source.getControllerId(), amount));
}
}
@Override
public boolean apply(Game game, Ability source) {
return true;
}
@Override
public boolean replaceEvent(GameEvent event, Ability source, Game game) {
switch (event.getType()) {
case DAMAGE_PLAYER:
if (event.getTargetId().equals(source.getControllerId())) {
@ -116,25 +148,4 @@ class GiselaBladeOfGoldnightDoubleDamageEffect extends ReplacementEffectImpl {
}
return false;
}
private void preventDamage(GameEvent event, Ability source, UUID target, Game game) {
int amount = (int)Math.ceil(event.getAmount() / 2.0);
GameEvent preventEvent = new GameEvent(GameEvent.EventType.PREVENT_DAMAGE, target, source.getSourceId(), source.getControllerId(), amount, false);
if (!game.replaceEvent(preventEvent)) {
event.setAmount(event.getAmount() - amount);
game.fireEvent(GameEvent.getEvent(GameEvent.EventType.PREVENTED_DAMAGE, target, source.getSourceId(), source.getControllerId(), amount));
}
}
@Override
public boolean apply(Game game, Ability source) {
return true;
}
@Override
public boolean replaceEvent(GameEvent event, Ability source, Game game) {
return apply(game, source);
}
}

View file

@ -38,8 +38,6 @@ import mage.constants.Outcome;
import mage.constants.Rarity;
import mage.game.Game;
import mage.game.events.GameEvent;
import static mage.game.events.GameEvent.EventType.DAMAGE_CREATURE;
import static mage.game.events.GameEvent.EventType.DAMAGE_PLAYER;
import mage.target.TargetPermanent;
/**
@ -88,16 +86,15 @@ class FireServantEffect extends ReplacementEffectImpl {
return new FireServantEffect(this);
}
@Override
public boolean checksEventType(GameEvent event, Game game) {
return event.getType().equals(GameEvent.EventType.DAMAGE_CREATURE) ||
event.getType().equals(GameEvent.EventType.DAMAGE_PLAYER);
}
@Override
public boolean applies(GameEvent event, Ability source, Game game) {
switch (event.getType()) {
case DAMAGE_CREATURE:
case DAMAGE_PLAYER:
if (event.getSourceId().equals(this.getTargetPointer().getFirst(game, source))) {
event.setAmount(event.getAmount() * 2);
}
}
return false;
return event.getSourceId().equals(this.getTargetPointer().getFirst(game, source));
}
@Override
@ -107,7 +104,8 @@ class FireServantEffect extends ReplacementEffectImpl {
@Override
public boolean replaceEvent(GameEvent event, Ability source, Game game) {
return apply(game, source);
event.setAmount(event.getAmount() * 2);
return false;
}
}

View file

@ -41,9 +41,7 @@ import mage.constants.Rarity;
import mage.constants.Zone;
import mage.game.Game;
import mage.game.events.GameEvent;
import static mage.game.events.GameEvent.EventType.DAMAGE_PLAYER;
import mage.game.permanent.Permanent;
import mage.players.Player;
import mage.target.TargetPlayer;
/**
@ -96,16 +94,18 @@ class CurseOfBloodlettingEffect extends ReplacementEffectImpl {
return new CurseOfBloodlettingEffect(this);
}
@Override
public boolean checksEventType(GameEvent event, Game game) {
return event.getType().equals(GameEvent.EventType.DAMAGE_PLAYER);
}
@Override
public boolean applies(GameEvent event, Ability source, Game game) {
switch (event.getType()) {
case DAMAGE_PLAYER:
Permanent enchantment = game.getPermanent(source.getSourceId());
if (enchantment != null &&
enchantment.getAttachedTo() != null &&
event.getTargetId().equals(enchantment.getAttachedTo())) {
return true;
}
Permanent enchantment = game.getPermanent(source.getSourceId());
if (enchantment != null &&
enchantment.getAttachedTo() != null &&
event.getTargetId().equals(enchantment.getAttachedTo())) {
return true;
}
return false;
}

View file

@ -27,21 +27,24 @@
*/
package mage.sets.innistrad;
import mage.constants.*;
import java.util.UUID;
import mage.abilities.Ability;
import mage.abilities.common.SimpleStaticAbility;
import mage.abilities.costs.mana.GenericManaCost;
import mage.abilities.effects.ReplacementEffectImpl;
import mage.abilities.keyword.EquipAbility;
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.DamageCreatureEvent;
import mage.game.events.DamageEvent;
import mage.game.events.GameEvent;
import mage.game.permanent.Permanent;
import java.util.UUID;
/**
* @author nantuko
*/
@ -87,29 +90,31 @@ class InquisitorsFlailEffect extends ReplacementEffectImpl {
return new InquisitorsFlailEffect(this);
}
@Override
public boolean checksEventType(GameEvent event, Game game) {
return event.getType().equals(GameEvent.EventType.DAMAGE_CREATURE) ||
event.getType().equals(GameEvent.EventType.DAMAGE_PLANESWALKER) ||
event.getType().equals(GameEvent.EventType.DAMAGE_PLAYER);
}
@Override
public boolean applies(GameEvent event, Ability source, Game game) {
boolean isCombat = false;
switch (event.getType()) {
case DAMAGE_CREATURE:
case DAMAGE_PLAYER:
case DAMAGE_PLANESWALKER:
if (event instanceof DamageCreatureEvent) {
isCombat = ((DamageCreatureEvent) event).isCombatDamage();
} else if (event instanceof DamageEvent) {
isCombat = ((DamageEvent) event).isCombatDamage();
}
if (isCombat) {
Permanent equipment = game.getPermanent(source.getSourceId());
if (equipment != null && equipment.getAttachedTo() != null) {
UUID attachedTo = equipment.getAttachedTo();
if (event.getSourceId().equals(attachedTo)) {
event.setAmount(event.getAmount() * 2);
} else if (event.getTargetId().equals(attachedTo)) {
event.setAmount(event.getAmount() * 2);
}
}
if (event instanceof DamageCreatureEvent) {
isCombat = ((DamageCreatureEvent) event).isCombatDamage();
} else if (event instanceof DamageEvent) {
isCombat = ((DamageEvent) event).isCombatDamage();
}
if (isCombat) {
Permanent equipment = game.getPermanent(source.getSourceId());
if (equipment != null && equipment.getAttachedTo() != null) {
UUID attachedTo = equipment.getAttachedTo();
if (event.getSourceId().equals(attachedTo)) {
return true;
} else if (event.getTargetId().equals(attachedTo)) {
return true;
}
}
}
return false;
}
@ -121,7 +126,8 @@ class InquisitorsFlailEffect extends ReplacementEffectImpl {
@Override
public boolean replaceEvent(GameEvent event, Ability source, Game game) {
return apply(game, source);
event.setAmount(event.getAmount() * 2);
return false;
}
}

View file

@ -28,17 +28,18 @@
package mage.sets.innistrad;
import java.util.UUID;
import mage.abilities.Ability;
import mage.abilities.common.SimpleStaticAbility;
import mage.abilities.effects.ReplacementEffectImpl;
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.abilities.Ability;
import mage.abilities.common.SimpleStaticAbility;
import mage.abilities.effects.ReplacementEffectImpl;
import mage.cards.CardImpl;
import mage.game.Game;
import mage.game.events.GameEvent;
import mage.game.events.GameEvent.EventType;
import mage.game.stack.StackObject;
/**
@ -51,8 +52,6 @@ public class ParallelLives extends CardImpl {
super(ownerId, 199, "Parallel Lives", Rarity.RARE, new CardType[]{CardType.ENCHANTMENT}, "{3}{G}");
this.expansionSetCode = "ISD";
this.color.setGreen(true);
// If an effect would put one or more tokens onto the battlefield under your control, it puts twice that many of those tokens onto the battlefield instead.
this.addAbility(new SimpleStaticAbility(Zone.BATTLEFIELD, new ParallelLivesEffect()));
}
@ -83,16 +82,15 @@ class ParallelLivesEffect extends ReplacementEffectImpl {
return new ParallelLivesEffect(this);
}
@Override
public boolean checksEventType(GameEvent event, Game game) {
return event.getType().equals(EventType.CREATE_TOKEN);
}
@Override
public boolean applies(GameEvent event, Ability source, Game game) {
switch (event.getType()) {
case CREATE_TOKEN:
StackObject spell = game.getStack().getStackObject(event.getSourceId());
if (spell != null && spell.getControllerId().equals(source.getControllerId())) {
event.setAmount(event.getAmount() * 2);
}
}
return false;
StackObject spell = game.getStack().getStackObject(event.getSourceId());
return spell != null && spell.getControllerId().equals(source.getControllerId());
}
@Override
@ -102,7 +100,8 @@ class ParallelLivesEffect extends ReplacementEffectImpl {
@Override
public boolean replaceEvent(GameEvent event, Ability source, Game game) {
return apply(game, source);
event.setAmount(event.getAmount() * 2);
return false;
}
}

View file

@ -29,16 +29,16 @@
package mage.sets.magic2011;
import java.util.UUID;
import mage.constants.CardType;
import mage.constants.Duration;
import mage.constants.Outcome;
import mage.constants.Rarity;
import mage.constants.Zone;
import mage.MageInt;
import mage.abilities.Ability;
import mage.abilities.common.SimpleStaticAbility;
import mage.abilities.effects.ReplacementEffectImpl;
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.game.stack.StackObject;
@ -53,10 +53,11 @@ public class FireServant extends CardImpl {
super(ownerId, 137, "Fire Servant", Rarity.UNCOMMON, new CardType[]{CardType.CREATURE}, "{3}{R}{R}");
this.expansionSetCode = "M11";
this.subtype.add("Elemental");
this.color.setRed(true);
this.power = new MageInt(4);
this.toughness = new MageInt(3);
// If a red instant or sorcery spell you control would deal damage, it deals double that damage instead.
this.addAbility(new SimpleStaticAbility(Zone.BATTLEFIELD, new FireServantEffect()));
}
@ -87,19 +88,20 @@ class FireServantEffect extends ReplacementEffectImpl {
return new FireServantEffect(this);
}
@Override
public boolean checksEventType(GameEvent event, Game game) {
return event.getType().equals(GameEvent.EventType.DAMAGE_CREATURE) ||
event.getType().equals(GameEvent.EventType.DAMAGE_PLANESWALKER) ||
event.getType().equals(GameEvent.EventType.DAMAGE_PLAYER);
}
@Override
public boolean applies(GameEvent event, Ability source, Game game) {
switch (event.getType()) {
case DAMAGE_CREATURE:
case DAMAGE_PLAYER:
case DAMAGE_PLANESWALKER:
StackObject spell = game.getStack().getStackObject(event.getSourceId());
if (spell != null && spell.getControllerId().equals(source.getControllerId()) && spell.getColor().isRed() &&
(spell.getCardType().contains(CardType.INSTANT) || spell.getCardType().contains(CardType.SORCERY))) {
event.setAmount(event.getAmount() * 2);
}
}
return false;
StackObject spell = game.getStack().getStackObject(event.getSourceId());
return spell != null &&
spell.getControllerId().equals(source.getControllerId()) &&
spell.getColor().isRed() &&
(spell.getCardType().contains(CardType.INSTANT) || spell.getCardType().contains(CardType.SORCERY));
}
@Override
@ -109,7 +111,8 @@ class FireServantEffect extends ReplacementEffectImpl {
@Override
public boolean replaceEvent(GameEvent event, Ability source, Game game) {
return apply(game, source);
event.setAmount(event.getAmount() * 2);
return false;
}
}

View file

@ -28,16 +28,20 @@
package mage.sets.magic2013;
import java.util.UUID;
import mage.constants.*;
import mage.MageInt;
import mage.abilities.Ability;
import mage.abilities.common.SimpleStaticAbility;
import mage.abilities.effects.ReplacementEffectImpl;
import mage.abilities.keyword.LifelinkAbility;
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.game.events.GameEvent.EventType;
/**
*
@ -51,7 +55,6 @@ public class RhoxFaithmender extends CardImpl {
this.subtype.add("Rhino");
this.subtype.add("Monk");
this.color.setWhite(true);
this.power = new MageInt(1);
this.toughness = new MageInt(5);
@ -95,18 +98,18 @@ class RhoxFaithmenderEffect extends ReplacementEffectImpl {
@Override
public boolean replaceEvent(GameEvent event, Ability source, Game game) {
return apply(game, source);
event.setAmount(event.getAmount() * 2);
return false;
}
@Override
public boolean checksEventType(GameEvent event, Game game) {
return event.getType().equals(EventType.GAIN_LIFE);
}
@Override
public boolean applies(GameEvent event, Ability source, Game game) {
switch (event.getType()) {
case GAIN_LIFE:
if (event.getPlayerId().equals(source.getControllerId()) && (source.getControllerId() != null)) {
event.setAmount(event.getAmount() * 2);
}
}
return false;
return event.getPlayerId().equals(source.getControllerId()) && (source.getControllerId() != null);
}
}

View file

@ -28,15 +28,15 @@
package mage.sets.modernmasters;
import java.util.UUID;
import mage.abilities.Ability;
import mage.abilities.common.SimpleStaticAbility;
import mage.abilities.effects.ReplacementEffectImpl;
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.abilities.Ability;
import mage.abilities.common.SimpleStaticAbility;
import mage.abilities.effects.ReplacementEffectImpl;
import mage.cards.CardImpl;
import mage.game.Game;
import mage.game.events.GameEvent;
import mage.game.permanent.Permanent;
@ -52,8 +52,6 @@ public class DoublingSeason extends CardImpl {
super(ownerId, 141, "Doubling Season", Rarity.RARE, new CardType[]{CardType.ENCHANTMENT}, "{4}{G}");
this.expansionSetCode = "MMA";
this.color.setGreen(true);
// If an effect would put one or more tokens onto the battlefield under your control, it puts twice that many of those tokens onto the battlefield instead.
this.addAbility(new SimpleStaticAbility(Zone.BATTLEFIELD, new DoublingSeasonTokenEffect()));
// If an effect would place one or more counters on a permanent you control, it places twice that many of those counters on that permanent instead.

View file

@ -28,14 +28,18 @@
package mage.sets.shadowmoor;
import java.util.UUID;
import mage.constants.*;
import mage.abilities.Ability;
import mage.abilities.common.SimpleStaticAbility;
import mage.abilities.effects.ReplacementEffectImpl;
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.game.events.GameEvent.EventType;
/**
*
@ -48,8 +52,6 @@ public class BoonReflection extends CardImpl {
super(ownerId, 5, "Boon Reflection", Rarity.RARE, new CardType[]{CardType.ENCHANTMENT}, "{4}{W}");
this.expansionSetCode = "SHM";
this.color.setWhite(true);
// If you would gain life, you gain twice that much life instead.
this.addAbility(new SimpleStaticAbility(Zone.BATTLEFIELD, new BoonReflectionEffect()));
}
@ -87,17 +89,17 @@ class BoonReflectionEffect extends ReplacementEffectImpl {
@Override
public boolean replaceEvent(GameEvent event, Ability source, Game game) {
return apply(game, source);
event.setAmount(event.getAmount() * 2);
return false;
}
@Override
public boolean checksEventType(GameEvent event, Game game) {
return event.getType().equals(EventType.GAIN_LIFE);
}
@Override
public boolean applies(GameEvent event, Ability source, Game game) {
switch (event.getType()) {
case GAIN_LIFE:
if (event.getPlayerId().equals(source.getControllerId()) && (source.getControllerId() != null)) {
event.setAmount(event.getAmount() * 2);
}
}
return false;
return event.getPlayerId().equals(source.getControllerId()) && (source.getControllerId() != null);
}
}

View file

@ -28,10 +28,6 @@
package mage.sets.zendikar;
import java.util.UUID;
import mage.constants.CardType;
import mage.constants.Rarity;
import mage.constants.Zone;
import mage.abilities.Ability;
import mage.abilities.TriggeredAbilityImpl;
import mage.abilities.common.SimpleActivatedAbility;
@ -40,8 +36,11 @@ import mage.abilities.costs.common.SacrificeSourceCost;
import mage.abilities.effects.ReplacementEffectImpl;
import mage.abilities.effects.common.counter.AddCountersSourceEffect;
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.counters.CounterType;
import mage.game.Game;
import mage.game.events.GameEvent;
@ -59,8 +58,6 @@ public class QuestForPureFlame extends CardImpl {
super(ownerId, 144, "Quest for Pure Flame", Rarity.UNCOMMON, new CardType[]{CardType.ENCHANTMENT}, "{R}");
this.expansionSetCode = "ZEN";
this.color.setRed(true);
// Whenever a source you control deals damage to an opponent, you may put a quest counter on Quest for Pure Flame.
this.addAbility(new QuestForPureFlameTriggeredAbility());
@ -139,22 +136,24 @@ class QuestForPureFlameEffect extends ReplacementEffectImpl {
}
@Override
public boolean applies(GameEvent event, Ability source, Game game) {
if (event.getType().equals(GameEvent.EventType.DAMAGE_PLAYER)
|| event.getType().equals(GameEvent.EventType.DAMAGE_CREATURE)) {
Permanent permanent = game.getPermanent(event.getSourceId());
Player player = game.getPlayer(event.getSourceId());
StackObject spell = game.getStack().getStackObject(event.getSourceId());
public boolean checksEventType(GameEvent event, Game game) {
return event.getType().equals(GameEvent.EventType.DAMAGE_CREATURE) ||
event.getType().equals(GameEvent.EventType.DAMAGE_PLAYER);
}
if (permanent != null && permanent.getControllerId().equals(source.getControllerId())) {
event.setAmount(event.getAmount() * 2);
}
if (player != null && player.getId().equals(source.getControllerId())) {
event.setAmount(event.getAmount() * 2);
}
if (spell != null && spell.getControllerId().equals(source.getControllerId())) {
event.setAmount(event.getAmount() * 2);
}
@Override
public boolean applies(GameEvent event, Ability source, Game game) {
Permanent permanent = game.getPermanent(event.getSourceId());
if (permanent != null && permanent.getControllerId().equals(source.getControllerId())) {
return true;
}
Player player = game.getPlayer(event.getSourceId());
if (player != null && player.getId().equals(source.getControllerId())) {
return true;
}
StackObject spell = game.getStack().getStackObject(event.getSourceId());
if (spell != null && spell.getControllerId().equals(source.getControllerId())) {
return true;
}
return false;
}
@ -166,6 +165,7 @@ class QuestForPureFlameEffect extends ReplacementEffectImpl {
@Override
public boolean replaceEvent(GameEvent event, Ability source, Game game) {
return apply(game, source);
event.setAmount(event.getAmount() * 2);
return false;
}
}