AI: improved stability and bug fixes (related to #13290):

- bug's reason: wrong usage of canTarget, add/addTarget, getOpponents, etc;
- fixed that it can target dead players in some use cases (close #13507);
- fixed that it wrongly choose targets in bad/good effects in some use cases;
- fixed that it can't find valid targets in some use cases;
- fixed game freezes and errors with some cards;
This commit is contained in:
Oleg Agafonov 2025-04-19 07:04:55 +04:00
parent b915c6590b
commit 3dc606501d
10 changed files with 219 additions and 204 deletions

View file

@ -36,7 +36,7 @@ public class AttackIfAbleTargetRandomOpponentSourceEffect extends OneShotEffect
if (controller == null) {
return false;
}
List<UUID> opponents = new ArrayList<>(game.getOpponents(controller.getId()));
List<UUID> opponents = new ArrayList<>(game.getOpponents(controller.getId(), true));
Player opponent = game.getPlayer(opponents.get(RandomUtil.nextInt(opponents.size())));
if (opponent != null) {
game.informPlayers(opponent.getLogName() + " was chosen at random.");

View file

@ -55,6 +55,9 @@ public interface Target extends Serializable {
boolean chooseTarget(Outcome outcome, UUID playerId, Ability source, Game game);
/**
* Add target from targeting methods like chooseTarget (will check and generate target events and effects)
*/
void addTarget(UUID id, Ability source, Game game);
void addTarget(UUID id, int amount, Ability source, Game game);
@ -90,6 +93,9 @@ public interface Target extends Serializable {
boolean choose(Outcome outcome, UUID playerId, UUID sourceId, Ability source, Game game);
/**
* Add target from non targeting methods like choose
*/
void add(UUID id, Game game);
void remove(UUID targetId);