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

  /**
   * @ajspath adventurejs.Atom.Asset.Matter.Tangible.Thing.Key
   * @augments {adventurejs.Thing}
   * @class adventurejs.Key
   * @ajsconstruct MyGame.createAsset({ "class":"Key", "name":"foo", [...] })
   * @ajsconstructedby adventurejs.Game#createAsset
   * @ajsnavheading KeyClasses
   * @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 Keys unlock locks.
   * @tutorial CreateKey
   * @classdesc
   * <p>
   * <strong>Key</strong> is a subclass of
   * {@link adventurejs.Thing|Thing}
   * that can be used to unlock locked
   * {@link adventurejs.Asset|Assets}.
   * The interaction is determined by properties on both objects.
   * The Key will have a list of Asset
   * <a href="#id">IDs</a> it can unlock in its
   * <code class="property">asset.iov.unlock.with_assets</code>,
   * and the locked object will also have the Key ID listed in its
   * <code class="property">asset.dov.unlock.with_assets</code>.
   * (You can set just one or the other in your game file.
   * As long as one is set, the Key and Lock will be associated during
   * initialization.) The locked object will also have
   * asset.dov.lock.enabled set to true.
   * See the example below to create a key and a locked chest.
   * </p>
   * <pre class="display"><code class="language-javascript">MyGame.createAsset({
   *   class: "Key",
   *   name: "brass key",
   *   place: { in: "Treasure Room" },
   *   iov: { unlock: { with_assets: ['treasure chest'], }, },
   * });
   * MyGame.createAsset({
   *   class: "Chest",
   *   name: "treasure chest",
   *   place: { in: "Treasure Room" },
   *   is_locked: true,
   *   dov: { unlock: { with_assets: ['brass key'], }, },
   * });
   * </code></pre>
   **/
  class Key extends adventurejs.Thing {
    constructor(name, game_name) {
      super(name, game_name);
      this.class = "Key";

      this.setDOVs(["put", "give", "take", "drop", "throw", "tie"]);
      this.setIOVs(["lock", "unlock"]);

      this.descriptions.look = "It's a key.";
      this.singlePluralPairs = [["key", "keys"]];
      this.on_tie_to_this_take_this = true;
      this.on_tie_to_drag_behind_rope = true;
    }
  }
  adventurejs.Key = Key;
})();