Pre-release
Adventure.js Docs Downloads
Score: 0 Moves: 0
// Door.js
(function () {
  /*global adventurejs A*/
  "use strict";

  /**
   * @ajspath adventurejs.Atom.Asset.Matter.Tangible.Thing.Aperture.Door
   * @augments adventurejs.Aperture
   * @class adventurejs.Door
   * @ajsconstruct MyGame.createAsset({ "class":"Door", "name":"foo", [...] })
   * @ajsconstructedby adventurejs.Game#createAsset
   * @ajsnavheading DoorExitClasses
   * @param {String} game_name The name of the top level game object.
   * @param {String} name A name for the object, to be serialized and used as ID.
   * @summary Shut the door!
   * @tutorial CreateExit
   * @classdesc
   * <p>
   * <strong>Door</strong> is a subclass of
   * {@link adventurejs.Aperture|Aperture}. Doors can be opened,
   * closed, locked and unlocked. By itself, a Door doesn't
   * move a player from {@link adventurejs.Room|Room} to room -
   * a Door must be linked with an
   * {@link adventurejs.Exit|Exit} in order to allow travel.
   * Doors are singular, meaning they only exist in one Room.
   * To allow two-way travel between Rooms, you must have two
   * Doors, each with its <a href="#linked_asset">linked_asset</a>
   * property set to the other Door. Following is an example
   * with two Doors + Exits.
   * </p>
   * <h3 class="example">Example:</h3>
   * <pre class="display"><code class="language-javascript">MyGame.createAsset({
   *   "class":"Exit",
   *   "direction":"east",
   *   "place":{ in: "Sunset" },
   *   "destination":"Sunrise",
   *   "aperture":"bright door"
   * });
   * MyGame.createAsset({
   *   "class":"Door",
   *   "name":"bright door",
   *   "direction":"east",
   *   "place":{ in: "Sunset" },
   *   "linked_asset":"dim door"
   * });
   * MyGame.createAsset({
   *   "class":"Exit",
   *   "direction":"west",
   *   "place":{ in: "Sunrise" },
   *   "destination":"Sunset",
   *   "aperture":"dim door"
   * });
   * MyGame.createAsset({
   *   "class":"Door",
   *   "name":"dim door",
   *   "place":{ in: "Sunrise" },
   *   "direction":"west",
   *   "linked_asset":"bright door"
   * });
   * </code></pre>
   * <p>
   * To make a pair of linked Doors that are locked and unlocked
   * with a particular {@link adventurejs.Key|Key},
   * we need to create a Key and list it in the Doors'
   * <code class="property">asset.dov.unlock.with_assets</code>
   * as in the example below.
   * </p>
   * <h3 class="example">Example:</h3>
   * <pre class="display"><code class="language-javascript"><span class="new">MyGame.createAsset({
   *   class: "Key",
   *   name: "day key",
   *   iov: { unlock: { with_assets: ['bright door','dim door'], }, },
   * });</span>
   * MyGame.createAsset({
   *   class: "Exit",
   *   direction: "east",
   *   place: { in: "Sunset" },
   *   destination: "Sunrise",
   *   aperture: "bright door"
   * });
   * MyGame.createAsset({
   *   class: "Door",
   *   name: "bright door",
   *   direction: "east",
   *   place: { in: "Sunset" },
   *   linked_asset :"dim door",
   * <span class="new">  dov: { unlock: { with_assets: ['day key'], }, },
   *   is: { closed: true, locked: true },
   * });
   * MyGame.createAsset({
   *   class:"Exit",
   *   direction:"west",
   *   place:{ in: "Sunrise" },
   *   destination: "Sunset",
   *   aperture: "dim door"
   * });
   * MyGame.createAsset({
   *   class: "Door",
   *   name: "dim door",
   *   place: { in: "Sunrise" },
   *   direction: "west",
   *   linked_asset: "bright door",
   * <span class="new">  dov: { unlock: { with_assets: ['day key'], }, },
   *   is: { closed: true, locked: true },</span>
   * });
   * </code></pre>
   **/
  class Door extends adventurejs.Aperture {
    constructor(name, game_name) {
      super(name, game_name);
      this.class = "Door";

      this.noun = "door";
      this.plural = "doors";
      this.singlePluralPairs = [["door", "doors"]];

      this.setDOVs(["open", "close"]);
      this.setDOV({
        open: {
          with_nothing: true,
          automatically_after_use: true,
        },
      });
      this.setDOV({
        close: {
          with_nothing: true,
          automatically_after_use: true,
        },
      });
      this.setDOV({
        lock: {
          with_nothing: false,
          automatically_after_use: true,
        },
      });
      this.setDOV({
        unlock: {
          with_nothing: false,
          automatically_after_use: true,
        },
      });

      // this.exit = ""; // a door will be associated with an exit direction
    }
  }
  adventurejs.Door = Door;
})();