1
1

ReactToAggressive.ts 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. /// <reference path="../../AI.ts" />
  2. module AIRules {
  3. export function printGrudgeResult (atom : ContentAtomAnnoy) : Say {
  4. return ContentMoleculeAnnoy.getSay(new ContentMolecule(atom));
  5. }
  6. export var actedUponAggressively = AI.reacttoRules.createAndAddRule({
  7. name : "Reacting to Aggressive action",
  8. code : (runner : RulebookRunner<Person>) => {
  9. let person = runner.noun;
  10. let pai = runner.noun.AI;
  11. let action = pai.reactingTo;
  12. person.AI.addHostility(action.actor, action.aggressivenessRating);
  13. person.reputation -= action.aggressivenessRating;
  14. if (person.AI.hostileTargets.includes(action.actor)) {
  15. return; // Already hostile
  16. }
  17. if (action.actor == WorldState.player) {
  18. person.reputation -= action.aggressivenessRating;
  19. }
  20. let ai = person.AI;
  21. let response : Say;
  22. let gain = ai.grudgeRate * action.aggressivenessRating;
  23. let actionLevel = ContentAtomAnnoy.TYPE_LOW;
  24. let result = ContentAtomAnnoy.RESULT_FRIENDLY;
  25. if (ai.getHostilityTo(action.actor) > 100) {
  26. result = ContentAtomAnnoy.RESULT_HOSTILE;
  27. } else if (ai.retaliates && ai.getHostilityTo(action.actor) >= (ai.hostileThreshold / 2)) {
  28. result = ContentAtomAnnoy.RESULT_PISSED;
  29. }
  30. if (gain >= (ai.hostileThreshold / 2)) {
  31. actionLevel = ContentAtomAnnoy.TYPE_HIGH;
  32. } else if (gain >= (ai.hostileThreshold / 4)) {
  33. actionLevel = ContentAtomAnnoy.TYPE_MEDIUM;
  34. }
  35. response = printGrudgeResult(new ContentAtomAnnoy(action.actor, person, [actionLevel, result]));
  36. let nAct : Action;
  37. if (result != ContentAtomAnnoy.RESULT_FRIENDLY) {
  38. nAct = new ActionAttack(person, action.actor);
  39. nAct.finalSay = response.add(Say.PARAGRAPH_BREAK);
  40. nAct.finalSayOnEnd = false;
  41. person.AI.storedReaction = nAct;
  42. } else {
  43. // nAct = new ActionWait(person);
  44. // nAct.finalSay = response.add(Say.PARAGRAPH_BREAK);
  45. // Stop waiting when hit?
  46. }
  47. },
  48. conditions : (runner : RulebookRunner<Person>) => {
  49. let pai = runner.noun.AI;
  50. let action = pai.reactingTo;
  51. return action.actingAgressively;
  52. }
  53. })
  54. }