package uulm.teamname.marvelous.gamelibrary.ai; import uulm.teamname.marvelous.gamelibrary.config.CharacterConfig; import uulm.teamname.marvelous.gamelibrary.config.PartyConfig; import uulm.teamname.marvelous.gamelibrary.config.ScenarioConfig; import uulm.teamname.marvelous.gamelibrary.entities.EntityType; import uulm.teamname.marvelous.gamelibrary.events.Event; import uulm.teamname.marvelous.gamelibrary.events.EventType; import uulm.teamname.marvelous.gamelibrary.gamelogic.GameInstance; import uulm.teamname.marvelous.gamelibrary.requests.Request; import java.util.ArrayList; import java.util.List; import java.util.Optional; /** Represents an AI player. */ public class AIClient { /** The {@link GameInstance} the AI is playing on. */ private final GameInstance game; /** The Player the AI is playing for. */ private final EntityType player; /** The actual {@link AI} instance. */ private final AI ai; /** Constructs a new {@link AIClient} playing the given player based on the given config values. */ public AIClient(EntityType player, PartyConfig partyConfig, CharacterConfig characterConfig, ScenarioConfig scenarioConfig) { this.game = new GameInstance(partyConfig, characterConfig, scenarioConfig); this.player = player; this.ai = new AI(game.state, player, partyConfig, characterConfig, scenarioConfig); } /** * Handles incoming {@link Event Events} and optionally returns a list of response {@link Request Requests}. * @param events The incoming events * @return Optionally resulting requests */ public Optional> handle(Event... events) { ArrayList result = new ArrayList<>(); game.applyEvents(events); boolean containsTurn = false; for(Event event: events) { if(event.type == EventType.TurnEvent) { containsTurn = true; break; } } //detect turn if(containsTurn && game.state.getActiveCharacter() != null && game.state.getActiveCharacter().type == player) { //let ai calculate requests result.addAll(this.ai.performTurn(game.state.getActiveCharacter())); } if(!result.isEmpty()) { return Optional.of(result); }else { return Optional.empty(); } } }