fix unwanted null check in FightTargetsEffect

This commit is contained in:
xenohedron 2024-01-06 15:05:14 -05:00
parent 784a0f564b
commit aa4d1654c7

View file

@ -3,12 +3,12 @@ package mage.abilities.effects.common;
import mage.abilities.Ability;
import mage.abilities.Mode;
import mage.abilities.effects.OneShotEffect;
import mage.cards.Card;
import mage.constants.Outcome;
import mage.game.Game;
import mage.game.permanent.Permanent;
import mage.target.Target;
import java.util.Objects;
import java.util.UUID;
/**
@ -34,38 +34,28 @@ public class FightTargetsEffect extends OneShotEffect {
@Override
public boolean apply(Game game, Ability source) {
Card card = game.getCard(source.getSourceId());
if (card != null) {
UUID target1Id = null;
UUID target2Id = null;
boolean secondTargetOptional = false;
// first target is in target pointer, second target is a normal target
if (source.getTargets().size() < 2) {
if (!source.getTargets().get(0).isLegal(source, game)) {
return false;
}
target1Id = getTargetPointer().getFirst(game, source);
target2Id = source.getTargets().getFirstTarget();
if (target1Id == target2Id) {
return false;
}
// two normal targets available, only if both targets are legal the effect will be applied
} else if (source.getTargets().get(0).isLegal(source, game) && source.getTargets().get(1).isLegal(source, game)) {
target1Id = source.getTargets().get(0).getFirstTarget();
target2Id = source.getTargets().get(1).getFirstTarget();
secondTargetOptional = source.getTargets().get(1).getMinNumberOfTargets() == 0;
}
Permanent creature1 = game.getPermanent(target1Id);
Permanent creature2 = game.getPermanent(target2Id);
// 20110930 - 701.10
if (creature1 != null && creature2 != null) {
if (creature1.isCreature(game) && creature2.isCreature(game)) {
return creature1.fight(creature2, source, game);
}
}
if (!game.isSimulation() && !secondTargetOptional) {
game.informPlayers(card.getName() + " has been fizzled.");
UUID target1Id = null;
UUID target2Id = null;
// first target is in target pointer, second target is a normal target
if (source.getTargets().size() < 2) {
if (!source.getTargets().get(0).isLegal(source, game)) {
return false;
}
target1Id = getTargetPointer().getFirst(game, source);
target2Id = source.getTargets().getFirstTarget();
// two normal targets available, only if both targets are legal the effect will be applied
} else if (source.getTargets().get(0).isLegal(source, game) && source.getTargets().get(1).isLegal(source, game)) {
target1Id = source.getTargets().get(0).getFirstTarget();
target2Id = source.getTargets().get(1).getFirstTarget();
}
if (Objects.equals(target1Id, target2Id)) {
return false;
}
Permanent creature1 = game.getPermanent(target1Id);
Permanent creature2 = game.getPermanent(target2Id);
// 20110930 - 701.10
if (creature1 != null && creature2 != null && creature1.isCreature(game) && creature2.isCreature(game)) {
return creature1.fight(creature2, source, game);
}
return false;