forked from External/mage
new DamageTargetAndTargetEffect
This commit is contained in:
parent
06c51bd829
commit
7a6dfb7a2f
2 changed files with 71 additions and 61 deletions
|
|
@ -1,21 +1,14 @@
|
||||||
package mage.cards.a;
|
package mage.cards.a;
|
||||||
|
|
||||||
import mage.abilities.Ability;
|
import mage.abilities.effects.common.DamageTargetAndTargetEffect;
|
||||||
import mage.abilities.effects.OneShotEffect;
|
|
||||||
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.Outcome;
|
|
||||||
import mage.filter.common.FilterAnyTarget;
|
import mage.filter.common.FilterAnyTarget;
|
||||||
import mage.filter.common.FilterPermanentOrPlayer;
|
import mage.filter.common.FilterPermanentOrPlayer;
|
||||||
import mage.filter.predicate.other.AnotherTargetPredicate;
|
import mage.filter.predicate.other.AnotherTargetPredicate;
|
||||||
import mage.game.Game;
|
|
||||||
import mage.game.permanent.Permanent;
|
|
||||||
import mage.players.Player;
|
|
||||||
import mage.target.Target;
|
|
||||||
import mage.target.common.TargetPermanentOrPlayer;
|
import mage.target.common.TargetPermanentOrPlayer;
|
||||||
|
|
||||||
import java.io.ObjectStreamException;
|
|
||||||
import java.util.UUID;
|
import java.util.UUID;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
@ -34,8 +27,8 @@ public final class ArcTrail extends CardImpl {
|
||||||
public ArcTrail(UUID ownerId, CardSetInfo setInfo) {
|
public ArcTrail(UUID ownerId, CardSetInfo setInfo) {
|
||||||
super(ownerId, setInfo, new CardType[]{CardType.SORCERY}, "{1}{R}");
|
super(ownerId, setInfo, new CardType[]{CardType.SORCERY}, "{1}{R}");
|
||||||
|
|
||||||
// Arc Trail deals 2 damage to any target and 1 damage to another any target
|
// Arc Trail deals 2 damage to any target and 1 damage to another target
|
||||||
this.getSpellAbility().addEffect(ArcTrailEffect.getInstance());
|
this.getSpellAbility().addEffect(new DamageTargetAndTargetEffect(2, 1));
|
||||||
this.getSpellAbility().addTarget(new TargetPermanentOrPlayer(filter1).setTargetTag(1));
|
this.getSpellAbility().addTarget(new TargetPermanentOrPlayer(filter1).setTargetTag(1));
|
||||||
this.getSpellAbility().addTarget(new TargetPermanentOrPlayer(filter2).setTargetTag(2));
|
this.getSpellAbility().addTarget(new TargetPermanentOrPlayer(filter2).setTargetTag(2));
|
||||||
}
|
}
|
||||||
|
|
@ -50,54 +43,3 @@ public final class ArcTrail extends CardImpl {
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
class ArcTrailEffect extends OneShotEffect {
|
|
||||||
|
|
||||||
private static final ArcTrailEffect instance = new ArcTrailEffect();
|
|
||||||
|
|
||||||
private Object readResolve() throws ObjectStreamException {
|
|
||||||
return instance;
|
|
||||||
}
|
|
||||||
|
|
||||||
public static ArcTrailEffect getInstance() {
|
|
||||||
return instance;
|
|
||||||
}
|
|
||||||
|
|
||||||
private ArcTrailEffect() {
|
|
||||||
super(Outcome.Damage);
|
|
||||||
staticText = "{this} deals 2 damage to any target and 1 damage to another target";
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean apply(Game game, Ability source) {
|
|
||||||
|
|
||||||
boolean applied = false;
|
|
||||||
boolean twoDamageDone = false;
|
|
||||||
int damage = 2;
|
|
||||||
|
|
||||||
for (Target target : source.getTargets()) {
|
|
||||||
Permanent permanent = game.getPermanent(target.getFirstTarget());
|
|
||||||
|
|
||||||
if (twoDamageDone) {
|
|
||||||
damage = 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (permanent != null) {
|
|
||||||
applied |= (permanent.damage(damage, source.getSourceId(), source, game, false, true) > 0);
|
|
||||||
}
|
|
||||||
Player player = game.getPlayer(target.getFirstTarget());
|
|
||||||
if (player != null) {
|
|
||||||
applied |= (player.damage(damage, source.getSourceId(), source, game) > 0);
|
|
||||||
}
|
|
||||||
|
|
||||||
twoDamageDone = true;
|
|
||||||
}
|
|
||||||
return applied;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public ArcTrailEffect copy() {
|
|
||||||
return instance;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,68 @@
|
||||||
|
package mage.abilities.effects.common;
|
||||||
|
|
||||||
|
import mage.abilities.Ability;
|
||||||
|
import mage.abilities.Mode;
|
||||||
|
import mage.abilities.effects.OneShotEffect;
|
||||||
|
import mage.constants.Outcome;
|
||||||
|
import mage.game.Game;
|
||||||
|
import mage.game.permanent.Permanent;
|
||||||
|
import mage.players.Player;
|
||||||
|
|
||||||
|
import java.util.UUID;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author xenohedron
|
||||||
|
*/
|
||||||
|
public class DamageTargetAndTargetEffect extends OneShotEffect {
|
||||||
|
|
||||||
|
private final int firstAmount;
|
||||||
|
private final int secondAmount;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Deals simultaneous damage to two targets. Must set target tag 1 and 2
|
||||||
|
*/
|
||||||
|
public DamageTargetAndTargetEffect(int firstAmount, int secondAmount) {
|
||||||
|
super(Outcome.Damage);
|
||||||
|
this.firstAmount = firstAmount;
|
||||||
|
this.secondAmount = secondAmount;
|
||||||
|
}
|
||||||
|
|
||||||
|
protected DamageTargetAndTargetEffect(final DamageTargetAndTargetEffect effect) {
|
||||||
|
super(effect);
|
||||||
|
this.firstAmount = effect.firstAmount;
|
||||||
|
this.secondAmount = effect.secondAmount;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public DamageTargetAndTargetEffect copy() {
|
||||||
|
return new DamageTargetAndTargetEffect(this);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean apply(Game game, Ability source) {
|
||||||
|
source.getTargets().getByTag(1).getTargets().forEach(uuid -> damageTarget(uuid, firstAmount, source, game));
|
||||||
|
source.getTargets().getByTag(2).getTargets().forEach(uuid -> damageTarget(uuid, secondAmount, source, game));
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
private void damageTarget(UUID targetId, int amount, Ability source, Game game) {
|
||||||
|
Permanent permanent = game.getPermanent(targetId);
|
||||||
|
if (permanent != null) {
|
||||||
|
permanent.damage(amount, source.getSourceId(), source, game) ;
|
||||||
|
} else {
|
||||||
|
Player player = game.getPlayer(targetId);
|
||||||
|
if (player != null) {
|
||||||
|
player.damage(amount, source.getSourceId(), source, game);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String getText(Mode mode) {
|
||||||
|
if (staticText != null && !staticText.isEmpty()) {
|
||||||
|
return staticText;
|
||||||
|
}
|
||||||
|
return "{this} deals " + firstAmount + "damage to " + mode.getTargets().getByTag(1).getDescription() +
|
||||||
|
" and " + secondAmount + "damage to " + mode.getTargets().getByTag(2).getDescription();
|
||||||
|
}
|
||||||
|
}
|
||||||
Loading…
Add table
Add a link
Reference in a new issue