AIGrudge.ts 3.1 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>) {
  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. victim.AI.warnedTimes++;
  20. Elements.CurrentTurnHandler.printAsContent(new Say(...CombatPokeDescription.getDescription(group)));
  21. }
  22. export var Grudge = AI.rules.createAndAddRule({
  23. name : "Grudge",
  24. firstPriority : AIRules.PRIORITY_ACTING_ON_SITUATION,
  25. priority : AIRules.PRIORITY_ACTING_ON_SITUATION - 3,
  26. code : (runner : RulebookRunner<Person>) => {
  27. let person = runner.noun;
  28. for (let i = 0; i < TurnSequence.currentTurnActionsTargets.length; i++) {
  29. if (TurnSequence.currentTurnActionsTargets[i] == person) {
  30. let action = TurnSequence.currentTurnActions[i];
  31. if (action.actingAgressively) {
  32. person.AI.addHostility(action.actor, action.aggressivenessRating);
  33. if (action.actor == WorldState.player) {
  34. person.reputation -= action.aggressivenessRating;
  35. }
  36. let ai = person.AI;
  37. let gain = ai.grudgeRate * action.aggressivenessRating;
  38. let actionLevel = actionMin;
  39. let result = resultNotHostile;
  40. if (ai.getHostilityTo(action.actor) > 100) {
  41. result = resultHostile;
  42. } else if (ai.retaliates && ai.getHostilityTo(action.actor) >= (ai.hostileThreshold / 2)) {
  43. result = resultRetaliate;
  44. }
  45. if (gain >= (ai.hostileThreshold / 2)) {
  46. actionLevel = actionMax;
  47. } else if (gain >= (ai.hostileThreshold / 4)) {
  48. actionLevel = actionMed;
  49. }
  50. printGrudgeResult(action.actor, person, actionLevel, result);
  51. if (result == resultRetaliate) {
  52. return new ActionAttack(person, action.actor);
  53. }
  54. }
  55. }
  56. }
  57. }
  58. });
  59. }