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

  /**
   * @ajspath adventurejs.Atom.Asset.Matter.Tangible.Thing.Platform
   * @augments adventurejs.Thing
   * @class adventurejs.Platform
   * @ajsconstruct MyGame.createAsset({ "class":"Platform", "name":"foo", [...] })
   * @ajsconstructedby adventurejs.Game#createAsset
   * @ajsnavheading MiscAssetClasses
   * @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.
   * @ajstangiblecontainer on
   * @summary Useful for dividing a Room into distinct areas.
   * @todo Expand this - clarify features and add examples
   * @classdesc
   * <p>
   * <strong>Platform</strong> is a subclass of
   * {@link adventurejs.Thing|Thing} that can be used to
   * create distinct areas in a Room. Platform acts like a
   * floor and allows players to go on it, climb on it,
   * walk on it, sit on it, swing to/from it, etc.
   * </p>
   * <h3 class="examples">Example:</h3>
   * <p>
   * The example below shows two Platforms with their
   * <code>things_player_can_swing_to_from_this</code>
   * properties set to each other, with the idea that a
   * player could swing on a vine from one to the other.
   * Their <code>player_can_exit</code> property is set to false
   * so that a player can't just step off either platform.
   * </p>
   * <pre class="display"><code class="language-javascript">MyGame.createAsset({
   *   class: "Platform",
   *   name: "east side of the chasm",
   *   place: { in: "Deep Chasm" },
   *   description: "The east side of the deep chasm. ",
   *   things_player_can_swing_to_from_this: "west side of the chasm",
   * });
   * MyGame.createAsset({
   *   class: "Platform",
   *   name: "west side of the chasm",
   *   place: { in: "Deep Chasm" },
   *   description: "The west side of the deep chasm.",
   *   things_player_can_swing_to_from_this: "east side of the chasm",
   * });
   * </code></pre>
   **/
  class Platform extends adventurejs.Thing {
    constructor(name, game_name) {
      super(name, game_name);
      this.class = "Platform";

      this.is.listed_in_room = false;
      this.is.unlisted_but_list_children = true;

      this.is.climbable = true;

      this.quirks.go_on_means_climb = true;
      this.is.unleavable = true;

      this.can.float_over = true;
      this.can.jump_from = true;
      this.can.jump_to = true;
      this.can.run_over = true;
      this.quirks.step_on_means_stand_on = true;
      this.can.swing_from = true;
      this.can.swing_to = true;
      this.can.swing_over = false;
      this.can.swing_across = false;
      this.can.walk_over = false;

      this.default_aspect = "on";

      this.aspects.on = new adventurejs.Aspect("on", this.game_name).set({
        parent_id: this.id,
        list_in_room: true,
        list_in_examine: true,
        player: {
          can: {
            enter: true,
            crawl: true,
            exit: false,
            jump: true,
            kneel: true,
            lie: true,
            sit: true,
            stand: true,
          },
        },
      });

      // TODO
      // special handling for unnesting
    }
  }
  adventurejs.Platform = Platform;
})();