1
1

AIGrudge.ts 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  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. // TODO: Make a rulebook called "ReactionTo", this is a rule that should be there with a condition of Action = ActingAggressively.
  25. export function getPoked (person : Person, action : Action) {
  26. if (person.AI.hostileTargets.includes(action.actor)) {
  27. return; // Already hostile
  28. }
  29. person.AI.addHostility(action.actor, action.aggressivenessRating);
  30. if (action.actor == WorldState.player) {
  31. person.reputation -= action.aggressivenessRating;
  32. }
  33. let ai = person.AI;
  34. let response : Say;
  35. let gain = ai.grudgeRate * action.aggressivenessRating;
  36. let actionLevel = actionMin;
  37. let result = resultNotHostile;
  38. if (ai.getHostilityTo(action.actor) > 100) {
  39. result = resultHostile;
  40. } else if (ai.retaliates && ai.getHostilityTo(action.actor) >= (ai.hostileThreshold / 2)) {
  41. result = resultRetaliate;
  42. }
  43. if (gain >= (ai.hostileThreshold / 2)) {
  44. actionLevel = actionMax;
  45. } else if (gain >= (ai.hostileThreshold / 4)) {
  46. actionLevel = actionMed;
  47. }
  48. response = printGrudgeResult(action.actor, person, actionLevel, result);
  49. let nAct : Action;
  50. if (result == resultRetaliate) {
  51. nAct = new ActionAttack(person, action.actor);
  52. nAct.finalSay = response.add(Say.PARAGRAPH_BREAK);
  53. nAct.finalSayOnEnd = false;
  54. } else {
  55. nAct = new ActionWait(person);
  56. nAct.finalSay = response.add(Say.PARAGRAPH_BREAK);
  57. }
  58. person.AI.storedReaction = nAct;
  59. }
  60. }