/// /// /// /// interface AIOptions { actor : Thing, wanderer? : boolean, wandersOn? : Region, picksShinies? : boolean } class AI { public actor : Thing; public wanderer = true; public wandersOn : Region; public wanderChance = 50; public picksShinies = true; public hostileTo : Array = []; public anger = 0; public grudgeRate = 10; public constructor (options : AIOptions) { for (let key in options) { this[key] = options[key]; } } /** * Executing an AI returns an Action. DOESN'T execute the action, just finds it! * @returns {Promise} */ public async execute () : Promise { let promise : Promise; let inCombat = false; if (this.hostileTo.length > 0) { for (let i = this.hostileTo.length - 1; i >= 0; i--) { if (this.actor.getRoom() == this.hostileTo[i].getRoom()) { inCombat = true; break; } } } if (inCombat) { promise = AI.combatRules.execute({ noun : this.actor }, ...this.extraCombatRules); } else { promise = AI.rules.execute({ noun : this.actor }, ...this.extraRules); } let result : Action = await promise; return result; } public addRulesBook (...books : Array>) { this.extraRules.push(...books) arrayUnique(this.extraRules); } public addCombatRulesBook (...books : Array>) { this.extraCombatRules.push(...books) arrayUnique(this.extraCombatRules); } public static rules = new Rulebook("Default AI Rules"); public extraRules : Array> = []; public static combatRules = new Rulebook("Default AI Combat Rules"); public extraCombatRules : Array> = []; } module AIRules { /** * This is or behavioral rules regarding something that is happening RIGHT NOW. * i.e. Rule for what a monster does when the player has just insulted them, or for when the player triggers an alarm, etc. * @type {number} */ export var PRIORITY_ACTING_ON_SITUATION = 5; /** * This is for behavioral rules about what the NPC SEES. * i.e. Is there a shiny on the ground for me to take? Do I see the player and if so how do I feel about it? * @type {number} */ export var PRIORITY_ACTING_ON_PLACE = 3; /** * This is for rules for when the NPC has nothing better to do. * i.e. Standard guarding routes, etc. * @type {number} */ export var PRIORITY_ACTING_ON_IDLE = 1; }