Pre-release
AdventureJS Docs Downloads
Score: 0 Moves: 0
// Floor.js
(function () {
  /*global adventurejs A*/

  /**
   * @ajspath adventurejs.Atom.Asset.Matter.Tangible.Floor
   * @class adventurejs.Floor
   * @augments adventurejs.Tangible
   * @ajsconstruct MyGame.createAsset({ "class":"Floor", "name":"foo" })
   * @ajsconstructedby adventurejs.Game#createAsset
   * @ajsnavheading RoomAssets
   * @param {String} name A name for the object, to be serialized and used as ID.
   * @param {String} game_name The name of the top level game object.
   * @summary Catches player input such as
   * <code class="property">pour water on floor</code>.
   * @classdesc
   * <p>
   * <strong>Floor</strong> is a special
   * {@link adventurejs.Asset|Asset}
   * that exists to catch player input that refers to the floor,
   * such as <code class="property">sit on floor</code> or
   *  <code class="property">pour water on floor</code> or
   *  <code class="property">empty bucket on floor</code>.
   * </p>
   * <p>There is already a {@link global_floor} already
   * available in all rooms, so it's not necessary to
   * create a Floor for each room, but you can if you want to,
   * perhaps in order to attach custom code to them. </p>
   * <h3 class="examples">Example:</h3>
   * <pre class="display"><code class="language-javascript">MyGame.createAsset({
   *   class:"Floor",
   *   name:"Candy Room floor",
   *   place: { in: "Candy Room" },
   *   descriptions: { look: "It appears to be made of red jelly beans. " },
   * });
   * </code></pre>
   **/
  class Floor extends adventurejs.Tangible {
    constructor(name, game_name) {
      super(name, game_name);
      this.class = "Floor";
      this.synonyms = ["ground"];
      this.setDOVs(["dig", "stomp"]);
      this.setIOVs(["dig"]);
      this.singlePluralPairs = [["floor", "floors"]];

      this.aspects.on = new adventurejs.Aspect("on", this.game_name).set({
        list_in_room: false,
        list_in_examine: true,

        player: {
          posture: "stand",
          preposition: "on",
          can: {
            enter: true,
            sit: true,
            crawl: true,
            kneel: true,
            lie: true,
            stand: true,
          },
        },
      });

      this.is.false_nest = true;
      this.is.deep_nest = true;
      this.is.listed_in_room = false;
      this.quirks.stand_means_get_off = true;
    }

    validate(game) {
      super.validate(game);

      /**
       * Global floor is a special case which exists to catch
       * floor interactions where authors haven't
       * made a custom floor. They don't need further validation.
       */
      if (this.is.global) {
        return true;
      }

      /**
       * TODO
       * What other validation does a floor need?
       */
    }
  }
  adventurejs.Floor = Floor;
})();