1
1

ReactToAggressive.ts 3.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  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. if (person.AI.hostileTargets.includes(action.actor)) {
  31. return; // Already hostile
  32. }
  33. person.AI.addHostility(action.actor, action.aggressivenessRating);
  34. if (action.actor == WorldState.player) {
  35. person.reputation -= action.aggressivenessRating;
  36. }
  37. let ai = person.AI;
  38. let response : Say;
  39. let gain = ai.grudgeRate * action.aggressivenessRating;
  40. let actionLevel = actionMin;
  41. let result = resultNotHostile;
  42. if (ai.getHostilityTo(action.actor) > 100) {
  43. result = resultHostile;
  44. } else if (ai.retaliates && ai.getHostilityTo(action.actor) >= (ai.hostileThreshold / 2)) {
  45. result = resultRetaliate;
  46. }
  47. if (gain >= (ai.hostileThreshold / 2)) {
  48. actionLevel = actionMax;
  49. } else if (gain >= (ai.hostileThreshold / 4)) {
  50. actionLevel = actionMed;
  51. }
  52. response = printGrudgeResult(action.actor, person, actionLevel, result);
  53. let nAct : Action;
  54. if (result == resultRetaliate) {
  55. nAct = new ActionAttack(person, action.actor);
  56. nAct.finalSay = response.add(Say.PARAGRAPH_BREAK);
  57. nAct.finalSayOnEnd = false;
  58. } else {
  59. nAct = new ActionWait(person);
  60. nAct.finalSay = response.add(Say.PARAGRAPH_BREAK);
  61. }
  62. person.AI.storedReaction = nAct;
  63. },
  64. conditions : (runner : RulebookRunner<Person>) => {
  65. let pai = runner.noun.AI;
  66. let action = pai.reactingTo;
  67. return action.actingAgressively;
  68. }
  69. })
  70. }