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

  /**
   * @ajspath adventurejs.Atom.Asset.Matter.Tangible.Thing.Key.SingleUseLockpick
   * @augments adventurejs.Lockpick
   * @class adventurejs.SingleUseLockpick
   * @ajsconstruct MyGame.createAsset({ "class":"SingleUseLockpick", "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 A single use lockpick can be used to pick a lock. Once.
   * @tutorial CreateKey
   * @classdesc
   * <p>
   * <strong>SingleUseLockpick</strong> is a subclass of
   * {@link adventurejs.Lockpick|Lockpick}
   * that can be used to unlock locked
   * {@link adventurejs.Asset|Assets}.
   * The parent class Lockpick has
   * <code>quirks.pick_means_unlock</code>
   * set to true, which makes 'pick' equivalent to
   * <code class="property">unlock door with key</code>.
   * SingleUseLockpick uses
   * <code class="property">asset.iov.pick.then_destroy</code>,
   * to destroy the asset after one use.
   * The interaction is determined by properties on both objects.
   * The SingleUseLockpick will have a list of Asset
   * <a href="#id">IDs</a> it can pick in its
   * <code class="property">asset.iov.pick.with_assets</code>,
   * property, and the locked object will also have the
   * SingleUseLockpick ID listed in its
   * <code class="property">asset.dov.pick.with_assets</code>.
   * (You can set just one or the other in your game file.
   * As long as one is set, the SingleUseLockpick
   * 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 SingleUseLockpick and a locked chest.
   * </p>
   * <pre class="display"><code class="language-javascript">MyGame.createAsset({
   *   class: "SingleUseLockpick",
   *   name: "iron lockpick",
   *   place: { in: "Treasure Room" },
   *   iov: { pick: { with_assets: ['iron chest'], then_destroy: true, }, },
   * });
   * MyGame.createAsset({
   *   class: "Chest",
   *   name: "iron chest",
   *   place: { in: "Treasure Room" },
   *   is_locked: true,
   *   dov: { pick: { with_assets: ['iron lockpick'], }, },
   * });
   * </code></pre>
   **/
  class SingleUseLockpick extends adventurejs.Key {
    constructor(name, game_name) {
      super(name, game_name);
      this.class = "SingleUseLockpick";

      this.setIOV({ pick: { then_destroy: true } });
      this.setIOV({ unlock: { then_destroy: true } });
    }
  }
  adventurejs.SingleUseLockpick = SingleUseLockpick;
})();