mirror of
https://github.com/correl/mage.git
synced 2024-12-25 03:00:15 +00:00
Implemented Gideon's Sacrifice
This commit is contained in:
parent
8bdb0934d0
commit
7c5e4c0118
2 changed files with 182 additions and 0 deletions
181
Mage.Sets/src/mage/cards/g/GideonsSacrifice.java
Normal file
181
Mage.Sets/src/mage/cards/g/GideonsSacrifice.java
Normal file
|
@ -0,0 +1,181 @@
|
|||
package mage.cards.g;
|
||||
|
||||
import mage.MageObjectReference;
|
||||
import mage.abilities.Ability;
|
||||
import mage.abilities.effects.OneShotEffect;
|
||||
import mage.abilities.effects.ReplacementEffectImpl;
|
||||
import mage.cards.CardImpl;
|
||||
import mage.cards.CardSetInfo;
|
||||
import mage.constants.CardType;
|
||||
import mage.constants.Duration;
|
||||
import mage.constants.Outcome;
|
||||
import mage.filter.FilterPermanent;
|
||||
import mage.filter.common.FilterControlledPermanent;
|
||||
import mage.filter.predicate.Predicates;
|
||||
import mage.filter.predicate.mageobject.CardTypePredicate;
|
||||
import mage.game.Game;
|
||||
import mage.game.events.DamageEvent;
|
||||
import mage.game.events.GameEvent;
|
||||
import mage.game.permanent.Permanent;
|
||||
import mage.players.Player;
|
||||
import mage.target.Target;
|
||||
import mage.target.TargetPermanent;
|
||||
|
||||
import java.util.UUID;
|
||||
|
||||
/**
|
||||
* @author TheElk801
|
||||
*/
|
||||
public final class GideonsSacrifice extends CardImpl {
|
||||
|
||||
public GideonsSacrifice(UUID ownerId, CardSetInfo setInfo) {
|
||||
super(ownerId, setInfo, new CardType[]{CardType.INSTANT}, "{W}");
|
||||
|
||||
// Choose a creature or planeswalker you control. All damage that would be dealt this turn to you and permanents you control is dealt to the chosen permanent instead.
|
||||
this.getSpellAbility().addEffect(new GideonsSacrificeEffect());
|
||||
}
|
||||
|
||||
private GideonsSacrifice(final GideonsSacrifice card) {
|
||||
super(card);
|
||||
}
|
||||
|
||||
@Override
|
||||
public GideonsSacrifice copy() {
|
||||
return new GideonsSacrifice(this);
|
||||
}
|
||||
}
|
||||
|
||||
class GideonsSacrificeEffect extends OneShotEffect {
|
||||
|
||||
private static final FilterPermanent filter
|
||||
= new FilterControlledPermanent("creature or planeswalker you controls");
|
||||
|
||||
static {
|
||||
filter.add(Predicates.or(
|
||||
new CardTypePredicate(CardType.PLANESWALKER),
|
||||
new CardTypePredicate(CardType.CREATURE)
|
||||
));
|
||||
}
|
||||
|
||||
GideonsSacrificeEffect() {
|
||||
super(Outcome.Benefit);
|
||||
staticText = "Choose a creature or planeswalker you control. " +
|
||||
"All damage that would be dealt this turn to you " +
|
||||
"and permanents you control is dealt to the chosen permanent instead.";
|
||||
}
|
||||
|
||||
private GideonsSacrificeEffect(final GideonsSacrificeEffect effect) {
|
||||
super(effect);
|
||||
}
|
||||
|
||||
@Override
|
||||
public GideonsSacrificeEffect copy() {
|
||||
return new GideonsSacrificeEffect(this);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean apply(Game game, Ability source) {
|
||||
Player player = game.getPlayer(source.getControllerId());
|
||||
if (player == null) {
|
||||
return false;
|
||||
}
|
||||
Target target = new TargetPermanent(filter);
|
||||
target.setNotTarget(true);
|
||||
if (!player.choose(outcome, target, source.getSourceId(), game)) {
|
||||
return false;
|
||||
}
|
||||
game.addEffect(new GideonsSacrificeEffectReplacementEffect(
|
||||
new MageObjectReference(target.getFirstTarget(), game)
|
||||
), source);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
class GideonsSacrificeEffectReplacementEffect extends ReplacementEffectImpl {
|
||||
|
||||
private final MageObjectReference mor;
|
||||
|
||||
GideonsSacrificeEffectReplacementEffect(MageObjectReference mor) {
|
||||
super(Duration.EndOfTurn, Outcome.RedirectDamage);
|
||||
this.mor = mor;
|
||||
}
|
||||
|
||||
private GideonsSacrificeEffectReplacementEffect(final GideonsSacrificeEffectReplacementEffect effect) {
|
||||
super(effect);
|
||||
this.mor = effect.mor;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean checksEventType(GameEvent event, Game game) {
|
||||
switch (event.getType()) {
|
||||
case DAMAGE_CREATURE:
|
||||
case DAMAGE_PLAYER:
|
||||
case DAMAGE_PLANESWALKER:
|
||||
return true;
|
||||
default:
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean applies(GameEvent event, Ability source, Game game) {
|
||||
if (event.getType() == GameEvent.EventType.DAMAGE_PLAYER
|
||||
&& event.getPlayerId().equals(source.getControllerId())) {
|
||||
return true;
|
||||
}
|
||||
if (event.getType() == GameEvent.EventType.DAMAGE_CREATURE
|
||||
|| event.getType() == GameEvent.EventType.DAMAGE_PLANESWALKER) {
|
||||
Permanent targetPermanent = game.getPermanent(event.getTargetId());
|
||||
if (targetPermanent != null
|
||||
&& targetPermanent.isControlledBy(source.getControllerId())) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean replaceEvent(GameEvent event, Ability source, Game game) {
|
||||
DamageEvent damageEvent = (DamageEvent) event;
|
||||
|
||||
Permanent permanent = mor.getPermanent(game);
|
||||
|
||||
if (permanent == null) {
|
||||
return false;
|
||||
}
|
||||
|
||||
// Name of old target
|
||||
Permanent targetPermanent = game.getPermanent(event.getTargetId());
|
||||
StringBuilder message = new StringBuilder();
|
||||
message.append(permanent.getName()).append(": gets ");
|
||||
message.append(damageEvent.getAmount()).append(" damage redirected from ");
|
||||
if (targetPermanent != null) {
|
||||
message.append(targetPermanent.getName());
|
||||
} else {
|
||||
Player targetPlayer = game.getPlayer(event.getTargetId());
|
||||
if (targetPlayer != null) {
|
||||
message.append(targetPlayer.getLogName());
|
||||
} else {
|
||||
message.append("unknown");
|
||||
}
|
||||
|
||||
}
|
||||
game.informPlayers(message.toString());
|
||||
// Redirect damage
|
||||
permanent.damage(
|
||||
damageEvent.getAmount(), damageEvent.getSourceId(), game,
|
||||
damageEvent.isCombatDamage(), damageEvent.isPreventable(), event.getAppliedEffects()
|
||||
);
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean apply(Game game, Ability source) {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public GideonsSacrificeEffectReplacementEffect copy() {
|
||||
return new GideonsSacrificeEffectReplacementEffect(this);
|
||||
}
|
||||
}
|
|
@ -116,6 +116,7 @@ public final class WarOfTheSpark extends ExpansionSet {
|
|||
cards.add(new SetCardInfo("Gideon Blackblade", 13, Rarity.MYTHIC, mage.cards.g.GideonBlackblade.class));
|
||||
cards.add(new SetCardInfo("Gideon's Battle Cry", 267, Rarity.RARE, mage.cards.g.GideonsBattleCry.class));
|
||||
cards.add(new SetCardInfo("Gideon's Company", 268, Rarity.UNCOMMON, mage.cards.g.GideonsCompany.class));
|
||||
cards.add(new SetCardInfo("Gideon's Sacrifice", 14, Rarity.COMMON, mage.cards.g.GideonsSacrifice.class));
|
||||
cards.add(new SetCardInfo("Gideon's Triumph", 15, Rarity.UNCOMMON, mage.cards.g.GideonsTriumph.class));
|
||||
cards.add(new SetCardInfo("Gideon, the Oathsworn", 265, Rarity.MYTHIC, mage.cards.g.GideonTheOathsworn.class));
|
||||
cards.add(new SetCardInfo("Gleaming Overseer", 198, Rarity.UNCOMMON, mage.cards.g.GleamingOverseer.class));
|
||||
|
|
Loading…
Reference in a new issue