From b71a5ed9b4164e0e0c0e940fec00e5ffbb873602 Mon Sep 17 00:00:00 2001 From: magenoxx Date: Wed, 26 Jan 2011 09:31:21 +0300 Subject: [PATCH] Updated targetImpl message with multi targets. Updated PreventDamageFromTargetEffect to work with multi targets. Soul Parry works. --- .../mage/sets/scarsofmirrodin/SoulParry.java | 1 + .../common/PreventDamageFromTargetEffect.java | 58 ++++++++++++------- Mage/src/mage/target/TargetImpl.java | 6 ++ 3 files changed, 45 insertions(+), 20 deletions(-) diff --git a/Mage.Sets/src/mage/sets/scarsofmirrodin/SoulParry.java b/Mage.Sets/src/mage/sets/scarsofmirrodin/SoulParry.java index af6c750bfe..bf705d6c8e 100644 --- a/Mage.Sets/src/mage/sets/scarsofmirrodin/SoulParry.java +++ b/Mage.Sets/src/mage/sets/scarsofmirrodin/SoulParry.java @@ -49,6 +49,7 @@ public class SoulParry extends CardImpl { this.expansionSetCode = "SOM"; this.color.setWhite(true); Target target = new TargetCreaturePermanent(1,2); + target.setTargetName("one or two creatures"); this.getSpellAbility().addEffect(new PreventDamageFromTargetEffect(Duration.EndOfTurn, true)); this.getSpellAbility().addTarget(target); } diff --git a/Mage/src/mage/abilities/effects/common/PreventDamageFromTargetEffect.java b/Mage/src/mage/abilities/effects/common/PreventDamageFromTargetEffect.java index f1e2215c11..661d0cee78 100644 --- a/Mage/src/mage/abilities/effects/common/PreventDamageFromTargetEffect.java +++ b/Mage/src/mage/abilities/effects/common/PreventDamageFromTargetEffect.java @@ -33,9 +33,11 @@ import mage.abilities.Ability; import mage.abilities.effects.PreventionEffectImpl; import mage.game.Game; import mage.game.events.GameEvent; +import mage.target.Target; + +import java.util.UUID; /** - * * @author nantuko */ public class PreventDamageFromTargetEffect extends PreventionEffectImpl { @@ -72,33 +74,49 @@ public class PreventDamageFromTargetEffect extends PreventionEffectImpl= this.amount) { - int damage = event.getAmount(); - event.setAmount(event.getAmount() - amount); - this.used = true; - game.fireEvent(GameEvent.getEvent(GameEvent.EventType.PREVENTED_DAMAGE, source.getFirstTarget(), source.getId(), source.getControllerId(), damage)); - } else { - int damage = event.getAmount(); - event.setAmount(0); - amount -= damage; - game.fireEvent(GameEvent.getEvent(GameEvent.EventType.PREVENTED_DAMAGE, source.getFirstTarget(), source.getId(), source.getControllerId(), damage)); + for (Target target : source.getTargets()) { + for (UUID chosen : target.getTargets()) { + if (event.getSourceId().equals(chosen)) { + preventDamage(event, source, chosen, game); } } } return false; } + private void preventDamage(GameEvent event, Ability source, UUID target, Game game) { + GameEvent preventEvent = new GameEvent(GameEvent.EventType.PREVENT_DAMAGE, target, source.getId(), source.getControllerId(), event.getAmount(), false); + if (!game.replaceEvent(preventEvent)) { + if (all) { + int damage = event.getAmount(); + event.setAmount(0); + game.fireEvent(GameEvent.getEvent(GameEvent.EventType.PREVENTED_DAMAGE, target, source.getId(), source.getControllerId(), damage)); + } else { + if (event.getAmount() >= this.amount) { + int damage = event.getAmount(); + event.setAmount(event.getAmount() - amount); + this.used = true; + game.fireEvent(GameEvent.getEvent(GameEvent.EventType.PREVENTED_DAMAGE, target, source.getId(), source.getControllerId(), damage)); + } else { + int damage = event.getAmount(); + event.setAmount(0); + amount -= damage; + game.fireEvent(GameEvent.getEvent(GameEvent.EventType.PREVENTED_DAMAGE, target, source.getId(), source.getControllerId(), damage)); + } + } + } + } + @Override public boolean applies(GameEvent event, Ability source, Game game) { - if (!this.used && super.applies(event, source, game) && event.getSourceId().equals(source.getFirstTarget())) { - return true; + if (!this.used && super.applies(event, source, game)) { + for (Target target : source.getTargets()) { + for (UUID chosen : target.getTargets()) { + if (event.getSourceId().equals(chosen)) { + return true; + } + } + } } return false; } diff --git a/Mage/src/mage/target/TargetImpl.java b/Mage/src/mage/target/TargetImpl.java index cef2eef9c2..794c755317 100644 --- a/Mage/src/mage/target/TargetImpl.java +++ b/Mage/src/mage/target/TargetImpl.java @@ -92,6 +92,12 @@ public abstract class TargetImpl> implements Target { @Override public String getMessage() { + if (maxNumberOfTargets > 1) { + StringBuilder sb = new StringBuilder(); + sb.append("Select ").append(targetName); + sb.append(" (").append(targets.size()).append("/").append(maxNumberOfTargets).append(")"); + return sb.toString(); + } return "Select a " + targetName; }