1
1

ActionRest.ts 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. /// <reference path="../Action.ts" />
  2. /// <reference path="../Rule.ts" />
  3. /// <reference path="../Rulebook.ts" />
  4. /// <reference path="../Things/Person.ts" />
  5. class ActionRest extends Action {
  6. public static check = new Rulebook<ActionRest>("Check Rest");
  7. public static carry = new Rulebook<ActionRest>("Carry out Rest");
  8. public constructor (actor : Thing, ...nouns : Array<any>) {
  9. super(actor, ...nouns);
  10. this.requiresNoun = true;
  11. this.requiresVisibility = true;
  12. }
  13. public getCommandText () {
  14. return "rest on " + (<Thing> this.getNoun(0)).getPrintedName();
  15. }
  16. public static carryRest = ActionRest.carry.createAndAddRule({
  17. name : "Rest - Restful Moment",
  18. code : (runner : RulebookRunner<ActionRest>) => {
  19. let actor = runner.noun.actor;
  20. if (actor instanceof Person) {
  21. // TODO: Run the Rulebook responsible for healing on the person. Resting = 2x healing.
  22. let action = runner.noun;
  23. if (WorldState.isPlayer(actor)) {
  24. runner.noun.say.add("You decide to rest for a bit on ", Say.Mention(runner.noun.getNoun(0)), ".");
  25. } else {
  26. runner.noun.say.add(Say.Mention(action.actor), " rests on ", Say.Mention(action.getNoun(0)), ".");
  27. }
  28. }
  29. }
  30. });
  31. }
  32. Elements.HyperlinkHandler.HyperlinkingRulebook.addRule(new Rule(
  33. {
  34. name : "Hyperlink - Rest",
  35. firstPriority : Rule.PRIORITY_HIGHEST,
  36. code : (rulebook : RulebookRunner<Thing>) => {
  37. let thing = <Thing> rulebook.noun;
  38. if (thing instanceof RestingStuff && thing.isVisibleTo(WorldState.player)) {
  39. Elements.HyperlinkHandler.addAvailableAction("Rest", new ActionRest(WorldState.player, thing));
  40. }
  41. }
  42. }
  43. ));