ActionRest.ts 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. /// <reference path="../Action.ts" />
  2. /// <reference path="../Rule.ts" />
  3. /// <reference path="../Rulebook.ts" />
  4. /// <reference path="../Things/Person.ts" />
  5. import player = WorldState.player;
  6. class ActionRest extends Action {
  7. public static check = new Rulebook<ActionRest>("Check Rest");
  8. public static carry = new Rulebook<ActionRest>("Carry out Rest");
  9. private waiting = false;
  10. public constructor (actor : Thing, ...nouns : Array<any>) {
  11. super(actor, ...nouns);
  12. this.requiresNoun = true;
  13. this.requiresVisibility = true;
  14. }
  15. public getCommandText () {
  16. return "rest on " + (<Thing> this.getNoun(0)).getPrintedName();
  17. }
  18. public static carryRest = ActionRest.carry.createAndAddRule({
  19. name : "Rest - Restful Moment",
  20. code : async (runner : RulebookRunner<ActionRest>) => {
  21. let actor = runner.noun.actor;
  22. if (actor instanceof Person) {
  23. let bodyparts = <Array<Bodypart>> actor.getParts(Bodypart);
  24. bodyparts.forEach(bodypart => {
  25. bodypart.regenerate();
  26. });
  27. let action = runner.noun;
  28. if (WorldState.isPlayer(actor)) {
  29. if (action.waiting || (WorldState.player.getHealthOnScale() <= 9 && await Controls.askForConsent("Rest until fully healed?"))) {
  30. if (WorldState.player.getHealthOnScale() <= 9) {
  31. TurnSequence.repeatedAction = action;
  32. action.waiting = true;
  33. } else {
  34. action.waiting = false;
  35. }
  36. }
  37. if (action.waiting) {
  38. runner.noun.say.add("You keep resting on ", Say.Mention(runner.noun.getNoun(0)), ".");
  39. } else {
  40. runner.noun.say.add("You decide to rest on ", Say.Mention(runner.noun.getNoun(0)), ".");
  41. }
  42. } else {
  43. runner.noun.say.add(Say.Mention(action.actor), " rests on ", Say.Mention(action.getNoun(0)), ".");
  44. }
  45. }
  46. }
  47. });
  48. }
  49. Elements.HyperlinkHandler.HyperlinkingRulebook.addRule(new Rule(
  50. {
  51. name : "Hyperlink - Rest",
  52. firstPriority : Rule.PRIORITY_HIGHEST,
  53. code : (rulebook : RulebookRunner<Thing>) => {
  54. let thing = <Thing> rulebook.noun;
  55. if (thing instanceof RestingStuff && thing.isVisibleTo(WorldState.player)) {
  56. Elements.HyperlinkHandler.addAvailableAction("Rest", new ActionRest(WorldState.player, thing));
  57. }
  58. }
  59. }
  60. ));