Pre-release
Adventure.js Docs Downloads
Score: 0 Moves: 0
// onNestThatToThis.js
(function () {
  /*global adventurejs A*/
  "use strict";
  var p = adventurejs.Tangible.prototype;
  /**
   * Called when a player asset is nested to this.
   * Provides an opportunity to override default behavior
   * through the use of
   * <a href="/doc/Scripting_VerbReactions.html">verb reactions</a>
   * doNestThatToThis.
   * @memberOf adventurejs.Tangible
   * @method adventurejs.Tangible#onNestThatToThis
   * @param {Object} player
   * @returns {Boolean}
   */
  p.onNestThatToThis = function Tangible_onNestThatToThis(player) {
    this.game.log(
      "log",
      "high",
      this.name + " onNestThatToThis " + player.name + ".",
      "Behavior"
    );
    if (!player) return;
    var results;
    var msg = "";

    // Unless explicitly set otherwise,
    // typically can't nest player into objects
    // that are themselves contained.

    if (
      !this.is.deep_nest &&
      this.getPlaceAssetId() !== this.game.getPlayer().id &&
      !(this.getPlaceAsset() instanceof adventurejs.Room)
    ) {
      this.game.debug(
        `F1524 | onNestThatToThis.js | ${this.id}.can_deep_nest is false `
      );
      msg += `$(We) can't do that while ${this.articlename} is 
        ${this.game.dictionary.getStringLookup(
          "prepositions",
          this.getPlacePreposition()
        )}
        ${this.getPlaceAsset().articlename}. `;
      this.game.print(msg);
      return null;
    }

    // Simple vehicles go into player inventory.

    if (this.is.rideable && !this.isIn(player)) {
      // move this from its parent
      results = this.moveFrom(this.getPlaceAsset());
      if ("undefined" !== typeof results) return results;

      // move this into player inventory
      results = this.moveTo("in", player);
      if ("undefined" !== typeof results) return results;
    }

    // allow for author to add custom interactions per-object
    results = this.callAction("doNestThatToThis", player.name, {});
    if ("undefined" !== typeof results) return results;

    return;
  };
})();