Răsfoiți Sursa

We getting combat now bois

Reddo 5 ani în urmă
părinte
comite
efbaa6a59f
2 a modificat fișierele cu 35 adăugiri și 1 ștergeri
  1. 14 1
      app/World/Classes/AI.ts
  2. 21 0
      app/World/Classes/AI/AIGrudge.ts

+ 14 - 1
app/World/Classes/AI.ts

@@ -16,6 +16,8 @@ class AI {
     public wandersOn : Region;
     public wanderChance = 50;
     public picksShinies = true;
+    public hostileTo : Array<Thing> = [];
+    public grudgeRate = 50;
 
     public constructor (options : AIOptions) {
         for (let key in options) {
@@ -29,7 +31,18 @@ class AI {
      */
     public async execute () : Promise<Action> {
         let promise : Promise<Action>;
-        if (promise != undefined) {
+        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);

+ 21 - 0
app/World/Classes/AI/AIGrudge.ts

@@ -0,0 +1,21 @@
+/// <reference path="../AI.ts" />
+module AIRules {
+    export var Grudge = AI.rules.createAndAddRule({
+        name : "Grudge",
+        firstPriority : AIRules.PRIORITY_ACTING_ON_SITUATION,
+        conditions : (runner : RulebookRunner<Person>) => {
+            let person = runner.noun;
+            return person.AI.hostileTo.length > 0 && (Math.random() * 100) <= person.AI.grudgeRate;
+        },
+        code : (runner : RulebookRunner<Person>) => {
+            let person = runner.noun;
+            let hostileTo = person.AI.hostileTo;
+
+            for (let i = 0; i < hostileTo.length; i++) {
+                if (ActionFollow.isCloseEnough(person, hostileTo[i])) {
+                    return new ActionFollow(person, hostileTo[i]);
+                }
+            }
+        }
+    });
+}