1
1

ReactToAggressive.ts 3.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  1. /// <reference path="../../AI.ts" />
  2. ///<reference path="../../ContentPicker/ContentMarker.ts"/>
  3. module AIRules {
  4. // Only one at a time
  5. export var actionMin = new ContentMarker("That pissed me off a little", true);
  6. export var actionMed = new ContentMarker("That pissed me off", true);
  7. export var actionMax = new ContentMarker("That pissed me off HARD", true);
  8. // Only one at a time
  9. export var resultNotHostile = new ContentMarker("I'm not gonna do anything about it", true);
  10. export var resultRetaliate = new ContentMarker("I'll hit you once so you can see how you like it", true);
  11. export var resultHostile = new ContentMarker("I'll hit you until you drop dead.", true);
  12. export function printGrudgeResult (aggressor : Thing, victim : Person, ...markers : Array<ContentMarker>) : Say {
  13. let group = new ContentGroup();
  14. let unit = new CombatPokeUnit();
  15. group.addUnit(unit);
  16. unit.setTarget(victim);
  17. unit.setAggressor(aggressor);
  18. unit.addMarker(...markers);
  19. if (aggressor == WorldState.player) {
  20. victim.AI.warnedTimes++;
  21. }
  22. return new Say(...CombatPokeDescription.getDescription(group));
  23. }
  24. export var actedUponAggressively = AI.reacttoRules.createAndAddRule({
  25. name : "Reacting to Aggressive action",
  26. code : (runner : RulebookRunner<Person>) => {
  27. let person = runner.noun;
  28. let pai = runner.noun.AI;
  29. let action = pai.reactingTo;
  30. person.AI.addHostility(action.actor, action.aggressivenessRating);
  31. person.reputation -= action.aggressivenessRating;
  32. if (person.AI.hostileTargets.includes(action.actor)) {
  33. return; // Already hostile
  34. }
  35. if (action.actor == WorldState.player) {
  36. person.reputation -= action.aggressivenessRating;
  37. }
  38. let ai = person.AI;
  39. let response : Say;
  40. let gain = ai.grudgeRate * action.aggressivenessRating;
  41. let actionLevel = actionMin;
  42. let result = resultNotHostile;
  43. if (ai.getHostilityTo(action.actor) > 100) {
  44. result = resultHostile;
  45. } else if (ai.retaliates && ai.getHostilityTo(action.actor) >= (ai.hostileThreshold / 2)) {
  46. result = resultRetaliate;
  47. }
  48. if (gain >= (ai.hostileThreshold / 2)) {
  49. actionLevel = actionMax;
  50. } else if (gain >= (ai.hostileThreshold / 4)) {
  51. actionLevel = actionMed;
  52. }
  53. response = printGrudgeResult(action.actor, person, actionLevel, result);
  54. let nAct : Action;
  55. if (result == resultRetaliate) {
  56. nAct = new ActionAttack(person, action.actor);
  57. nAct.finalSay = response.add(Say.PARAGRAPH_BREAK);
  58. nAct.finalSayOnEnd = false;
  59. } else {
  60. nAct = new ActionWait(person);
  61. nAct.finalSay = response.add(Say.PARAGRAPH_BREAK);
  62. }
  63. person.AI.storedReaction = nAct;
  64. },
  65. conditions : (runner : RulebookRunner<Person>) => {
  66. let pai = runner.noun.AI;
  67. let action = pai.reactingTo;
  68. return action.actingAgressively;
  69. }
  70. })
  71. }