123456789101112131415161718192021222324252627282930313233343536373839 |
- /// <reference path="../../AI.ts" />
- /// <reference path="../../Things/Person.ts" />
- module AIRules {
- export var standUp = new Rule({
- name: "Stand if down",
- firstPriority : AIRules.PRIORITY_ACTING_ON_SITUATION,
- priority : AIRules.PRIORITY_ACTING_ON_SITUATION,
- conditions : (runner : RulebookRunner<Person>) => {
- let person = runner.noun;
- return (person.stance != PersonStance.STANDING)
- },
- code : (runner : RulebookRunner<Person>) => {
- return new ActionStand(runner.noun);
- }
- });
- AI.combatRules.addRule(standUp);
- AI.rules.addRule(standUp);
- export var Hunt = AI.rules.createAndAddRule({
- name: "Follow based on grudge",
- firstPriority: AIRules.PRIORITY_ACTING_ON_SITUATION,
- priority: AIRules.PRIORITY_ACTING_ON_IDLE,
- code: (runner: RulebookRunner<Person>) => {
- let person = runner.noun;
- let hostiles = [...runner.noun.AI.hostileTargets].sort((a, b) => {
- return person.AI.getHostilityTo(b) - person.AI.getHostilityTo(a);
- });
- for (let i = 0; i < hostiles.length; i++) {
- if (ActionFollow.isCloseEnough(person, hostiles[i])) {
- return new ActionFollow(person, hostiles[i]);
- }
- }
- },
- conditions: (runner: RulebookRunner<Person>) => {
- return runner.noun.AI.hostileTargets.length > 0 && Math.random() < 0.5; // add randomness to allow escape
- }
- });
- }
|