[DST] Reimplement Turn the Tables using RedirectionEffect (#9196)

This commit is contained in:
sprangg 2022-07-02 17:30:00 +03:00 committed by GitHub
parent 6dd898a83c
commit 1e220d9f77
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -3,20 +3,20 @@ package mage.cards.t;
import java.util.UUID; import java.util.UUID;
import mage.abilities.Ability; import mage.abilities.Ability;
import mage.abilities.effects.PreventionEffectData; import mage.abilities.effects.RedirectionEffect;
import mage.abilities.effects.common.PreventDamageToControllerEffect;
import mage.cards.CardImpl; import mage.cards.CardImpl;
import mage.cards.CardSetInfo; import mage.cards.CardSetInfo;
import mage.constants.CardType; import mage.constants.CardType;
import mage.constants.Duration; import mage.constants.Duration;
import mage.game.Game; import mage.game.Game;
import mage.game.events.DamageEvent;
import mage.game.events.GameEvent; import mage.game.events.GameEvent;
import mage.game.permanent.Permanent;
import mage.target.common.TargetAttackingCreature; import mage.target.common.TargetAttackingCreature;
/** /**
* *
* @author LevelX2 * @author LevelX2
* @author sprangg
*/ */
public final class TurnTheTables extends CardImpl { public final class TurnTheTables extends CardImpl {
@ -38,10 +38,10 @@ public final class TurnTheTables extends CardImpl {
} }
} }
class TurnTheTablesEffect extends PreventDamageToControllerEffect { class TurnTheTablesEffect extends RedirectionEffect {
public TurnTheTablesEffect() { public TurnTheTablesEffect() {
super(Duration.EndOfTurn, true, false, Integer.MAX_VALUE); super(Duration.EndOfTurn, Integer.MAX_VALUE, UsageType.ACCORDING_DURATION);
staticText = "All combat damage that would be dealt to you this turn is dealt to target attacking creature instead"; staticText = "All combat damage that would be dealt to you this turn is dealt to target attacking creature instead";
} }
@ -55,16 +55,16 @@ class TurnTheTablesEffect extends PreventDamageToControllerEffect {
} }
@Override @Override
protected PreventionEffectData preventDamageAction(GameEvent event, Ability source, Game game) { public boolean applies(GameEvent event, Ability source, Game game) {
PreventionEffectData preventionEffectData = super.preventDamageAction(event, source, game); if (game.getPlayer(source.getControllerId()) == null || game.getPermanent(source.getFirstTarget()) == null) {
int damage = preventionEffectData.getPreventedDamage(); return false;
if (damage > 0) {
Permanent attackingCreature = game.getPermanent(getTargetPointer().getFirst(game, source));
if (attackingCreature != null) {
attackingCreature.damage(damage, source.getSourceId(), source, game, false, true);
}
} }
return preventionEffectData; DamageEvent damageEvent = (DamageEvent) event;
if (!damageEvent.isCombatDamage() || !source.getControllerId().equals(damageEvent.getTargetId())) {
return false;
}
this.redirectTarget = source.getTargets().get(0);
return true;
} }
} }