new DamageTargetAndTargetEffect

This commit is contained in:
xenohedron 2025-11-09 23:25:37 -05:00
parent 06c51bd829
commit 7a6dfb7a2f
2 changed files with 71 additions and 61 deletions

View file

@ -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();
}
}