Răsfoiți Sursa

There we have it. Proper reactions.

Reddo 5 ani în urmă
părinte
comite
a45aadd082

+ 9 - 2
app/World/Classes/AI.ts

@@ -40,6 +40,9 @@ class AI {
     public extraCombatRules : Array<Rulebook<Thing>> = [];
     public static talktoRules = new Rulebook<Thing>("Default Talk To Rules");
     public extraTalktoRules : Array<Rulebook<Thing>> = [];
+    public static reacttoRules = new Rulebook<Thing>("Default React To Rules");
+    public extraReacttoRules : Array<Rulebook<Thing>> = [];
+    public reactingTo : Action;
 
     public storedReaction : Action;
 
@@ -169,9 +172,13 @@ class AI {
     }
 
     // TODO: Make this a rulebook. This happens every time an aggressive action is done.
-    public getPoked (action : Action) {
+    public async getPoked (action : Action) {
+        this.reactingTo = action;
         if (this.actor instanceof Person) {
-            AIRules.getPoked(this.actor, action);
+            //AIRules.getPoked(this.actor, action);
+            await AI.reacttoRules.execute({
+                noun : this.actor
+            }, ...this.extraReacttoRules);
         }
     }
 }

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

@@ -1,66 +1,5 @@
 /// <reference path="../AI.ts" />
 ///<reference path="../ContentPicker/ContentMarker.ts"/>
 module AIRules {
-    // Only one at a time
-    export var actionMin = new ContentMarker("That pissed me off a little", true);
-    export var actionMed = new ContentMarker("That pissed me off", true);
-    export var actionMax = new ContentMarker("That pissed me off HARD", true);
 
-    // Only one at a time
-    export var resultNotHostile = new ContentMarker("I'm not gonna do anything about it", true);
-    export var resultRetaliate = new ContentMarker("I'll hit you once so you can see how you like it", true);
-    export var resultHostile = new ContentMarker("I'll hit you until you drop dead.", true);
-
-    export function printGrudgeResult (aggressor : Thing, victim : Person, ...markers : Array<ContentMarker>) : Say {
-        let group = new ContentGroup();
-        let unit = new CombatPokeUnit();
-        group.addUnit(unit);
-        unit.setTarget(victim);
-        unit.setAggressor(aggressor);
-        unit.addMarker(...markers);
-
-        if (aggressor == WorldState.player) {
-            victim.AI.warnedTimes++;
-        }
-        return new Say(...CombatPokeDescription.getDescription(group));
-    }
-
-    // TODO: Make a rulebook called "ReactionTo", this is a rule that should be there with a condition of Action = ActingAggressively.
-    export function getPoked (person : Person, action : Action) {
-        if (person.AI.hostileTargets.includes(action.actor)) {
-            return; // Already hostile
-        }
-        person.AI.addHostility(action.actor, action.aggressivenessRating);
-        if (action.actor == WorldState.player) {
-            person.reputation -= action.aggressivenessRating;
-        }
-
-        let ai = person.AI;
-        let response : Say;
-        let gain = ai.grudgeRate * action.aggressivenessRating;
-        let actionLevel = actionMin;
-        let result = resultNotHostile;
-        if (ai.getHostilityTo(action.actor) > 100) {
-            result = resultHostile;
-        } else if (ai.retaliates && ai.getHostilityTo(action.actor) >= (ai.hostileThreshold / 2)) {
-            result = resultRetaliate;
-        }
-        if (gain >= (ai.hostileThreshold / 2)) {
-            actionLevel = actionMax;
-        } else if (gain >= (ai.hostileThreshold / 4)) {
-            actionLevel = actionMed;
-        }
-        response = printGrudgeResult(action.actor, person, actionLevel, result);
-
-        let nAct : Action;
-        if (result == resultRetaliate) {
-            nAct = new ActionAttack(person, action.actor);
-            nAct.finalSay = response.add(Say.PARAGRAPH_BREAK);
-            nAct.finalSayOnEnd = false;
-        } else {
-            nAct = new ActionWait(person);
-            nAct.finalSay = response.add(Say.PARAGRAPH_BREAK);
-        }
-        person.AI.storedReaction = nAct;
-    }
 }

+ 77 - 0
app/World/Classes/AI/Reaction/ReactToAggressive.ts

@@ -0,0 +1,77 @@
+/// <reference path="../../AI.ts" />
+///<reference path="../../ContentPicker/ContentMarker.ts"/>
+module AIRules {
+// Only one at a time
+    export var actionMin = new ContentMarker("That pissed me off a little", true);
+    export var actionMed = new ContentMarker("That pissed me off", true);
+    export var actionMax = new ContentMarker("That pissed me off HARD", true);
+
+    // Only one at a time
+    export var resultNotHostile = new ContentMarker("I'm not gonna do anything about it", true);
+    export var resultRetaliate = new ContentMarker("I'll hit you once so you can see how you like it", true);
+    export var resultHostile = new ContentMarker("I'll hit you until you drop dead.", true);
+
+    export function printGrudgeResult (aggressor : Thing, victim : Person, ...markers : Array<ContentMarker>) : Say {
+        let group = new ContentGroup();
+        let unit = new CombatPokeUnit();
+        group.addUnit(unit);
+        unit.setTarget(victim);
+        unit.setAggressor(aggressor);
+        unit.addMarker(...markers);
+
+        if (aggressor == WorldState.player) {
+            victim.AI.warnedTimes++;
+        }
+        return new Say(...CombatPokeDescription.getDescription(group));
+    }
+
+    export var actedUponAggressively = AI.reacttoRules.createAndAddRule({
+        name : "Reacting to Aggressive action",
+        code : (runner : RulebookRunner<Person>) => {
+            let person = runner.noun;
+            let pai = runner.noun.AI;
+            let action = pai.reactingTo;
+
+            if (person.AI.hostileTargets.includes(action.actor)) {
+                return; // Already hostile
+            }
+            person.AI.addHostility(action.actor, action.aggressivenessRating);
+            if (action.actor == WorldState.player) {
+                person.reputation -= action.aggressivenessRating;
+            }
+
+            let ai = person.AI;
+            let response : Say;
+            let gain = ai.grudgeRate * action.aggressivenessRating;
+            let actionLevel = actionMin;
+            let result = resultNotHostile;
+            if (ai.getHostilityTo(action.actor) > 100) {
+                result = resultHostile;
+            } else if (ai.retaliates && ai.getHostilityTo(action.actor) >= (ai.hostileThreshold / 2)) {
+                result = resultRetaliate;
+            }
+            if (gain >= (ai.hostileThreshold / 2)) {
+                actionLevel = actionMax;
+            } else if (gain >= (ai.hostileThreshold / 4)) {
+                actionLevel = actionMed;
+            }
+            response = printGrudgeResult(action.actor, person, actionLevel, result);
+
+            let nAct : Action;
+            if (result == resultRetaliate) {
+                nAct = new ActionAttack(person, action.actor);
+                nAct.finalSay = response.add(Say.PARAGRAPH_BREAK);
+                nAct.finalSayOnEnd = false;
+            } else {
+                nAct = new ActionWait(person);
+                nAct.finalSay = response.add(Say.PARAGRAPH_BREAK);
+            }
+            person.AI.storedReaction = nAct;
+        },
+        conditions : (runner : RulebookRunner<Person>) => {
+            let pai = runner.noun.AI;
+            let action = pai.reactingTo;
+            return action.actingAgressively;
+        }
+    })
+}

+ 2 - 2
app/World/Classes/Action.ts

@@ -213,11 +213,11 @@ Action.carry.addRule(
         name : "Check any Action - Angery",
         firstPriority : Rule.PRIORITY_LOWEST,
         priority: Rule.PRIORITY_LOWEST,
-        code : (rulebook : RulebookRunner<Action>) => {
+        code : async (rulebook : RulebookRunner<Action>) => {
             let action = <Action> rulebook.noun;
             let target = action.getNoun(0);
             let tai = (<Person> target).AI;
-            tai.getPoked(action);
+            await tai.getPoked(action);
         },
         conditions : (rulebook : RulebookRunner<Action>) => {
             let action = <Action> rulebook.noun;