Pre-release
AdventureJS Docs Downloads
Score: 0 Moves: 0
// sleep.js

(function () {
  /* global adventurejs A */

  /**
   * @augments {adventurejs.Verb}
   * @class sleep
   * @ajsnode game.dictionary.verbs.sleep
   * @ajsconstruct MyGame.createVerb({ "name": "sleep", [...] });
   * @ajsconstructedby adventurejs.Dictionary#createVerb
   * @hideconstructor
   * @ajsinstanceof Verb
   * @ajsnavheading IntroversionVerbs
   * @summary Verb meaning sleep, as on a go to sleep.
   * @tutorial Scripting_VerbSubscriptions
   * @tutorial Verbs_VerbAnatomy
   * @tutorial Verbs_VerbProcess
   * @tutorial Verbs_ModifyVerbs
   * @tutorial Verbs_WriteVerbs
   * @classdesc
   * <pre class="display border outline">
   * <span class="ajs-player-input">&gt; sleep</span>
   * You catch a quick 40.
   * </pre>
   * @ajsverbphases doBeforeTry, doAfterTry, doBeforeSuccess, doAfterSuccess
   */
  A.Preverbs.sleep = {
    name: "sleep",
    prettyname: "sleep",
    past_tense: "slept",
    synonyms: ["sleep"],
    gerund: "skating",
    verb_prep_prep_noun: ["go to sleep"],

    subject_must_be: {},

    /**
     * @ajsadverbs
     * @memberof sleep
     */
    accepts_adverbs: [],

    /**
     * @ajsverbstructures
     * @memberof sleep
     */
    accepts_structures: [
      "verb", // sleep
      "verb preposition noun", // sleep in bed
    ],

    /**
     * @memberof sleep
     * @ajsverbphrase
     * phrase1:
     * {
     *   accepts_noun:true,
     *   noun_must_be:
     *   {
     *     known: true,
     *     tangible: true,
     *     present: true,
     *     visible: true,
     *     reachable: true,
     *   },
     *   accepts_preposition: true,
     *   requires_preposition: true,
     * },
     */
    phrase1: {
      accepts_noun: true,
      noun_must_be: {
        known: true,
        tangible: true,
        present: true,
        visible: true,
        reachable: true,
      },
      accepts_preposition: true,
      requires_preposition: true,
    },

    /**
     * @memberof sleep
     * @ajsverbparams
     * with_params: {},
     */
    with_params: {},

    doTry: function () {
      var input = this.game.getInput();
      var subject = input.getSubject();
      var direct_object = input.getAsset(1);
      var direct_preposition = input.getPreposition(1);
      var msg = "";

      if (input.hasStructure("verb")) {
        // this.game.debug(` | ${this.name}.js | sentence structure 'verb'`);
        // msg += this.game.settings.getUnparsedMessage(input.getInput());
        // this.handleFailure(msg);
        // return false;
      }

      if (input.hasStructure("verb preposition noun")) {
        let matchasset = subject.getNestOrPlaceAsset().id === direct_object.id;
        let matchaspect =
          subject.getNestOrPlacePreposition() === direct_preposition;
        if (matchasset && !matchaspect) {
          if (
            direct_preposition === "in" &&
            subject.getNestOrPlacePreposition() === "on" &&
            direct_object.hasQuirk("in_means_on")
          ) {
            matchaspect = true;
            direct_preposition = "on";
            input.setPreposition(1, "on");
          }
        }

        if (!matchasset || !matchaspect) {
          this.game.debug(
            `D1374 | ${this.name}.js | ${subject.id} is not ${direct_preposition} ${direct_object.id}`
          );
          msg += `{We're} not ${direct_preposition} ${direct_object.articlename}. `;
          this.handleFailure(msg);
          return false;
        }
      }
    },

    doSuccess: function () {
      var input = this.game.getInput();
      var subject = input.getSubject();
      var direct_object = input.getAsset(1);
      var direct_preposition = input.getPreposition(1);
      var msg = "";

      // compose output
      msg +=
        `{We} ${this.agree()}` +
        `${direct_preposition ? " " + direct_preposition : ""}` +
        `${direct_object ? " " + direct_object.articlename : ""}` +
        `. `;

      // --------------------------------------------------
      // print output
      // --------------------------------------------------
      return this.handleSuccess(msg, direct_object);
    },
  }; // END skate
})();