///
///
///
module EveryTurn {
export var EveryTurn = new Rulebook("Every Turn");
export var RunAIRule = EveryTurn.createAndAddRule({
name : "Run NPC AI Rule",
code : async function () {
function isAIAvailable (person : Person) {
return (person != WorldState.player
&& ((person.getRoom() instanceof RoomRandom
&& ( person.getRoom()).placed)));
}
let people = > Thing.InsideRoomRelation.getAnyRightType(Person).filter(isAIAvailable);
for (let i = 0; i < people.length; i++) {
let person = people[i];
if (person.getHealthOnScale() > 0) {
let action = await people[i].AI.execute();
let visible = people[i].isVisibleTo(WorldState.player);
if (action != undefined) {
let printValue: Say = await action.execute();
if (
(
visible ||
person.isVisibleTo(WorldState.player)
) && printValue != undefined) {
Elements.CurrentTurnHandler.printAsContent(printValue);
}
}
}
}
}
});
export var incrementTurnCounterRule = EveryTurn.createAndAddRule({
firstPriority: Rule.PRIORITY_LOWEST,
priority: Rule.PRIORITY_LOWEST,
name: "Increment Turn Counter",
code: function () {
WorldState.incrementWorldTurn();
}
});
}