123456789101112131415161718192021222324252627282930313233343536373839404142434445464748 |
- /// <reference path="./Classes/Rulebook.ts" />
- /// <reference path="./Classes/Rule.ts" />
- /// <reference path="Classes/Things/Person.ts" />
- 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
- && (<RoomRandom> person.getRoom()).placed)));
- }
- let people = <Array<Person>> 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();
- }
- });
- }
|