Fix NPE for ChangeZone Attach

This commit is contained in:
tool4EvEr
2021-10-15 21:12:45 +02:00
parent ad1c08c0d8
commit 99c5cf87d2
10 changed files with 15 additions and 44 deletions

View File

@@ -699,9 +699,9 @@ public class AiAttackController {
final boolean bAssault = doAssault(ai);
// TODO: detect Lightmine Field by presence of a card with a specific trigger
final boolean lightmineField = ComputerUtilCard.isPresentOnBattlefield(ai.getGame(), "Lightmine Field");
final boolean lightmineField = ai.getGame().isCardInPlay("Lightmine Field");
// TODO: detect Season of the Witch by presence of a card with a specific trigger
final boolean seasonOfTheWitch = ComputerUtilCard.isPresentOnBattlefield(ai.getGame(), "Season of the Witch");
final boolean seasonOfTheWitch = ai.getGame().isCardInPlay("Season of the Witch");
// Determine who will be attacked
GameEntity defender = chooseDefender(combat, bAssault);

View File

@@ -1834,10 +1834,6 @@ public class ComputerUtilCard {
return false;
}
public static boolean isPresentOnBattlefield(final Game game, final String cardName) {
return Iterables.any(game.getCardsIn(ZoneType.Battlefield), CardPredicates.nameEquals(cardName));
}
public static int getMaxSAEnergyCostOnBattlefield(final Player ai) {
// returns the maximum energy cost of an ability that permanents on the battlefield under AI's control have
CardCollectionView otb = ai.getCardsIn(ZoneType.Battlefield);

View File

@@ -459,8 +459,7 @@ public class AttachAi extends SpellAbilityAi {
* the mandatory
* @return the player
*/
private static Player attachToPlayerAIPreferences(final Player aiPlayer, final SpellAbility sa,
final boolean mandatory) {
public static Player attachToPlayerAIPreferences(final Player aiPlayer, final SpellAbility sa, final boolean mandatory) {
List<Player> targetable = new ArrayList<>();
for (final Player player : aiPlayer.getGame().getPlayers()) {
if (sa.canTarget(player)) {

View File

@@ -54,7 +54,6 @@ import forge.game.spellability.SpellAbility;
import forge.game.spellability.TargetRestrictions;
import forge.game.staticability.StaticAbilityMustTarget;
import forge.game.zone.ZoneType;
import forge.util.Aggregates;
import forge.util.MyRandom;
public class ChangeZoneAi extends SpellAbilityAi {
@@ -1733,7 +1732,7 @@ public class ChangeZoneAi extends SpellAbilityAi {
@Override
public Player chooseSinglePlayer(Player ai, SpellAbility sa, Iterable<Player> options, Map<String, Object> params) {
// Called when attaching Aura to player
return Aggregates.random(options);
return AttachAi.attachToPlayerAIPreferences(ai, sa, true);
}
private boolean doSacAndReturnFromGraveLogic(final Player ai, final SpellAbility sa) {

View File

@@ -90,12 +90,12 @@ public class CharmAi extends SpellAbilityAi {
if (AiPlayDecision.WillPlay == aic.canPlaySa(sub)) {
chosenList.add(sub);
if (chosenList.size() == num) {
return chosenList; // maximum choices reached
return chosenList; // maximum choices reached
}
}
}
if (isTrigger && chosenList.size() < min) {
// Second pass using doTrigger(false) to fulfil minimum choice
// Second pass using doTrigger(false) to fulfill minimum choice
choices.removeAll(chosenList);
for (AbilitySub sub : choices) {
sub.setActivatingPlayer(ai);