1234567891011121314151617181920212223242526272829303132333435363738394041424344454647 |
- /// <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))
- && (person.lastActionTurn < WorldState.getCurrentTurn()));
- }
- 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) action = new ActionWait(person);
- 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();
- }
- });
- }
|