diff --git a/cardshifter-core/src/main/java/net/zomis/cardshifter/ecs/ai/AISystem.java b/cardshifter-core/src/main/java/net/zomis/cardshifter/ecs/ai/AISystem.java index aed0457b..b1a91631 100644 --- a/cardshifter-core/src/main/java/net/zomis/cardshifter/ecs/ai/AISystem.java +++ b/cardshifter-core/src/main/java/net/zomis/cardshifter/ecs/ai/AISystem.java @@ -84,5 +84,28 @@ public void startGame(ECSGame game) { game.getEvents().registerHandlerAfter(this, ActionPerformEvent.class, event -> this.aiPerform(event.getEntity().getGame())); game.getEvents().registerHandlerAfter(this, StartGameEvent.class, event -> this.aiPerform(event.getGame())); } + + /** + * Call all AIs in the game directly. Useful for when a new AI has been initialized while the game is running + * @param game Game to call AIs in + */ + public static void call(ECSGame game) { + Set ais = game.getEntitiesWithComponent(AIComponent.class); + ComponentRetriever ai = game.componentRetreiver(AIComponent.class); + + logger.info("AI entities " + ais); + for (Entity entity : ais) { + AIComponent aiComp = ai.get(entity); + ECSAction action = aiComp.getAI().getAction(entity); + if (action != null && !game.isGameOver()) { + logger.info(entity + " performs " + action); + action.perform(entity); + return; + } + else { + logger.info(entity + ": No actions available"); + } + } + } }