mirror of
https://github.com/correl/mage.git
synced 2024-12-25 19:25:41 +00:00
Updated targetImpl message with multi targets. Updated PreventDamageFromTargetEffect to work with multi targets. Soul Parry works.
This commit is contained in:
parent
883d1b373f
commit
b71a5ed9b4
3 changed files with 45 additions and 20 deletions
|
@ -49,6 +49,7 @@ public class SoulParry extends CardImpl<SoulParry> {
|
|||
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);
|
||||
}
|
||||
|
|
|
@ -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<PreventDamageFromTargetEffect> {
|
||||
|
@ -72,33 +74,49 @@ public class PreventDamageFromTargetEffect extends PreventionEffectImpl<PreventD
|
|||
|
||||
@Override
|
||||
public boolean replaceEvent(GameEvent event, Ability source, Game game) {
|
||||
GameEvent preventEvent = new GameEvent(GameEvent.EventType.PREVENT_DAMAGE, source.getFirstTarget(), 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, source.getFirstTarget(), 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, 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;
|
||||
}
|
||||
|
|
|
@ -92,6 +92,12 @@ public abstract class TargetImpl<T extends TargetImpl<T>> 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;
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue