improve verify checks for target tag usage

This commit is contained in:
xenohedron 2025-11-11 00:20:32 -05:00
parent 646d34a90e
commit f2bf831e61
2 changed files with 17 additions and 21 deletions

View file

@ -40,8 +40,8 @@ public class DamageTargetAndTargetEffect extends OneShotEffect {
@Override @Override
public boolean apply(Game game, Ability source) { public boolean apply(Game game, Ability source) {
source.getTargets().getByTag(1).getTargets().forEach(uuid -> damageTarget(uuid, firstAmount, source, game)); source.getTargets().getTargetsByTag(1).forEach(uuid -> damageTarget(uuid, firstAmount, source, game));
source.getTargets().getByTag(2).getTargets().forEach(uuid -> damageTarget(uuid, secondAmount, source, game)); source.getTargets().getTargetsByTag(2).forEach(uuid -> damageTarget(uuid, secondAmount, source, game));
return true; return true;
} }
@ -59,6 +59,10 @@ public class DamageTargetAndTargetEffect extends OneShotEffect {
@Override @Override
public String getText(Mode mode) { public String getText(Mode mode) {
// verify check that target tags are properly setup
if (mode.getTargets().getByTag(1) == null || mode.getTargets().getByTag(2) == null) {
throw new IllegalArgumentException("Wrong code usage: need to add tags to targets");
}
if (staticText != null && !staticText.isEmpty()) { if (staticText != null && !staticText.isEmpty()) {
return staticText; return staticText;
} }

View file

@ -6,7 +6,6 @@ import mage.abilities.effects.OneShotEffect;
import mage.constants.Outcome; import mage.constants.Outcome;
import mage.game.Game; import mage.game.Game;
import mage.game.permanent.Permanent; import mage.game.permanent.Permanent;
import mage.target.Target;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;
@ -42,37 +41,26 @@ public class TargetsDamageTargetsEffect extends OneShotEffect {
@Override @Override
public boolean apply(Game game, Ability source) { public boolean apply(Game game, Ability source) {
if (source.getTargets().size() < 2) {
return false;
}
Target damageTarget = source.getTargets().getByTag(1);
Target additionalDamageTarget = source.getTargets().getByTag(2);
Target destTarget = source.getTargets().getByTag(3);
List<Permanent> damagingPermanents = new ArrayList<>(); List<Permanent> damagingPermanents = new ArrayList<>();
List<Permanent> receivingPermanents = new ArrayList<>(); List<Permanent> receivingPermanents = new ArrayList<>();
for (UUID id : damageTarget.getTargets()) { for (UUID id : source.getTargets().getTargetsByTag(1)) { // dealing damage
Permanent permanent = game.getPermanent(id); Permanent permanent = game.getPermanent(id);
if (permanent != null) { if (permanent != null) {
damagingPermanents.add(permanent); damagingPermanents.add(permanent);
} }
} }
if (additionalDamageTarget != null) { for (UUID id : source.getTargets().getTargetsByTag(2)) { // additional dealing damage, if applicable
for (UUID id : additionalDamageTarget.getTargets()) {
Permanent permanent = game.getPermanent(id); Permanent permanent = game.getPermanent(id);
if (permanent != null) { if (permanent != null) {
damagingPermanents.add(permanent); damagingPermanents.add(permanent);
} }
} }
} for (UUID id : source.getTargets().getTargetsByTag(3)) { // receiving damage
for (UUID id : destTarget.getTargets()) {
Permanent permanent = game.getPermanent(id); Permanent permanent = game.getPermanent(id);
if (permanent != null) { if (permanent != null) {
receivingPermanents.add(permanent); receivingPermanents.add(permanent);
} }
} }
if (receivingPermanents.isEmpty() || damagingPermanents.isEmpty()) { if (receivingPermanents.isEmpty() || damagingPermanents.isEmpty()) {
return false; return false;
} }
@ -86,6 +74,10 @@ public class TargetsDamageTargetsEffect extends OneShotEffect {
@Override @Override
public String getText(Mode mode) { public String getText(Mode mode) {
// verify check that target tags are properly setup
if (mode.getTargets().getByTag(1) == null || mode.getTargets().getByTag(3) == null) {
throw new IllegalArgumentException("Wrong code usage: need to add tags to targets");
}
if (staticText != null && !staticText.isEmpty()) { if (staticText != null && !staticText.isEmpty()) {
return staticText; return staticText;
} }