Parcourir la source

Repeated actions... this is awful

Reddo il y a 5 ans
Parent
commit
d7bdd8b3aa
3 fichiers modifiés avec 48 ajouts et 4 suppressions
  1. 15 1
      app/Controls/Controls.ts
  2. 24 3
      app/World/Classes/Action/ActionRest.ts
  3. 9 0
      app/World/TurnSequence.ts

+ 15 - 1
app/Controls/Controls.ts

@@ -62,9 +62,23 @@ module Controls {
         return [choices[chosen], chosen];
     }
 
-    export async function askForConsent () : Promise<boolean> {
+    export async function askForConsent (question? : string | Say) : Promise<boolean> {
+        let elements;
+        if (question != undefined) {
+            if (typeof question == "string") {
+                question = new Say(question);
+            }
+            elements = await Elements.CurrentTurnHandler.getSayElementsAsContent(question);
+            Elements.CurrentTurnHandler.print(...elements);
+        }
+
         let choices = ["Yes", "No"];
         let choice = await giveChoices(false, ...choices);
+
+        if (elements != undefined) {
+            Elements.CurrentTurnHandler.unprint(...elements);
+        }
+
         return choice[1] == 0;
     }
 }

+ 24 - 3
app/World/Classes/Action/ActionRest.ts

@@ -2,10 +2,14 @@
 /// <reference path="../Rule.ts" />
 /// <reference path="../Rulebook.ts" />
 /// <reference path="../Things/Person.ts" />
+import player = WorldState.player;
+
 class ActionRest extends Action {
     public static check = new Rulebook<ActionRest>("Check Rest");
     public static carry = new Rulebook<ActionRest>("Carry out Rest");
 
+    private waiting = false;
+
     public constructor (actor : Thing, ...nouns : Array<any>) {
         super(actor, ...nouns);
         this.requiresNoun = true;
@@ -18,13 +22,30 @@ class ActionRest extends Action {
 
     public static carryRest = ActionRest.carry.createAndAddRule({
         name : "Rest - Restful Moment",
-        code : (runner : RulebookRunner<ActionRest>) => {
+        code : async (runner : RulebookRunner<ActionRest>) => {
             let actor = runner.noun.actor;
             if (actor instanceof Person) {
-                // TODO: Run the Rulebook responsible for healing on the person. Resting = 2x healing.
+                let bodyparts = <Array<Bodypart>> actor.getParts(Bodypart);
+
+                bodyparts.forEach(bodypart => {
+                    bodypart.regenerate();
+                });
                 let action = runner.noun;
                 if (WorldState.isPlayer(actor)) {
-                    runner.noun.say.add("You decide to rest for a bit on ", Say.Mention(runner.noun.getNoun(0)), ".");
+                    if (action.waiting || (WorldState.player.getHealthOnScale() <= 9 && await Controls.askForConsent("Rest until fully healed?"))) {
+                        if (WorldState.player.getHealthOnScale() <= 9) {
+                            TurnSequence.repeatedAction = action;
+                            action.waiting = true;
+                        } else {
+                            action.waiting = false;
+                        }
+                    }
+
+                    if (action.waiting) {
+                        runner.noun.say.add("You keep resting on ", Say.Mention(runner.noun.getNoun(0)), ".");
+                    } else {
+                        runner.noun.say.add("You decide to rest on ", Say.Mention(runner.noun.getNoun(0)), ".");
+                    }
                 } else {
                     runner.noun.say.add(Say.Mention(action.actor), " rests on ", Say.Mention(action.getNoun(0)), ".");
                 }

+ 9 - 0
app/World/TurnSequence.ts

@@ -11,6 +11,8 @@ module TurnSequence {
     export let currentTurnActionsTargets : Array<any> = [];
     export let currentTurnActionsActors : Array<Thing> = [];
 
+    export let repeatedAction : Action;
+
     export function clearActions () {
         console.debug(Rulebook.getIndentation() + "Clearing Turn Sequence Actions");
         currentTurnActions = [];
@@ -42,6 +44,13 @@ module TurnSequence {
                 Elements.CurrentTurnHandler.printAsContent(new Say(new SayBold("Time taken for turn: "), (t1 - t0), " milliseconds."));
             }
         }
+        if (repeatedAction != undefined) {
+            setTimeout(() => {
+                let action = TurnSequence.repeatedAction;
+                TurnSequence.repeatedAction = undefined;
+                TurnSequence.execute(action);
+            }, 1);
+        }
     }
 
     /**