Prechádzať zdrojové kódy

Resting Stuff and Resting Action

Reddo 5 rokov pred
rodič
commit
c61031f015

+ 48 - 0
app/World/Classes/Action/ActionRest.ts

@@ -0,0 +1,48 @@
+/// <reference path="../Action.ts" />
+/// <reference path="../Rule.ts" />
+/// <reference path="../Rulebook.ts" />
+/// <reference path="../Things/Person.ts" />
+class ActionRest extends Action {
+    public static check = new Rulebook<ActionRest>("Check Rest");
+    public static carry = new Rulebook<ActionRest>("Carry out Rest");
+
+    public constructor (actor : Thing, ...nouns : Array<any>) {
+        super(actor, ...nouns);
+        this.requiresNoun = true;
+        this.requiresVisibility = true;
+    }
+
+    public getCommandText () {
+        return "rest on " + (<Thing> this.getNoun(0)).getPrintedName();
+    }
+
+    public static carryRest = ActionRest.carry.createAndAddRule({
+        name : "Rest - Restful Moment",
+        code : (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 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)), ".");
+                } else {
+                    runner.noun.say.add(Say.Mention(action.actor), " rests on ", Say.Mention(action.getNoun(0)), ".");
+                }
+            }
+        }
+    });
+}
+
+Elements.HyperlinkHandler.HyperlinkingRulebook.addRule(new Rule(
+    {
+        name : "Hyperlink - Rest",
+        firstPriority : Rule.PRIORITY_HIGHEST,
+        code : (rulebook : RulebookRunner<Thing>) => {
+            let thing = <Thing> rulebook.noun;
+
+            if (thing instanceof RestingStuff && thing.isVisibleTo(WorldState.player)) {
+                Elements.HyperlinkHandler.addAvailableAction("Rest", new ActionRest(WorldState.player, thing));
+            }
+        }
+    }
+));

+ 7 - 0
app/World/Classes/Things/RestingStuff.ts

@@ -0,0 +1,7 @@
+/// <reference path="../Thing.ts" />
+class RestingStuff extends Thing {
+    constructor (name : string, description : Say | string) {
+        super({name : name, description : description});
+        this.fixedInPlace = true;
+    }
+}