// Nest.js
(function () {
/* global adventurejs A */
/**
* @ajspath adventurejs.Atom.Nest
* @augments adventurejs.Atom
* @class adventurejs.Nest
* @ajsnavheading BaseClasses
* @param {String} game_name Name of top level game instance that is scoped to window.
* @param {String} name Instance name.
* @summary A container for properties pertaining to room/player interactions.
* @classdesc
* <p>
* <strong>Nest</strong> is a special class
* that adds the ability for
* {@link adventurejs.Room|Rooms} and other
* {@link adventurejs.Asset|Asset} types
* {@link adventurejs.Character|Characters} inside
* {@link adventurejs.Aspect|Aspects}.
* The Nest stores a group of properties that determine
* how a character can interact with its container.
**/
class Nest extends adventurejs.Atom {
constructor(name = "nest", game_name, context_id) {
// Call the constructor of the super class
super(name, game_name, context_id);
this.class = "Nest";
this.preposition = name;
this.id = `${context_id}|${name}|nest`;
this.posture = "stand";
this.initial_position = { x: 0, y: 0, z: 0 };
this.can = {
// locomotion
bounce: false,
climb: false,
crawl: false,
drive: false,
float: false,
fly: false,
get: false,
go: false,
hide: false,
hop: false,
hover: false,
jump: false,
peddle: false,
ride: false,
run: false,
skate: false,
slither: false,
swim: false,
walk: false,
// travel
enter: false,
exit: false,
exit_from_height: true,
scale: false,
traverse: true,
// posture
cling: false,
hang: false,
kneel: false,
lie: false,
sit: false,
stand: false,
// sensory
hear: true,
see: true,
feel: true,
smell: true,
talk: true,
taste: true,
/**
* When player is nested within an aspect of an asset, other assets may not
* be reachable. <strong>reach</strong> enforces reachability of one asset
* from another. For example, if player is on a ladder, things on the ground
* might not be reachable. But, a player seated on a chair at a desk should
* be able to reach the desk and anything on it. Use this property to
* explicitly make some things reachable from other things. For example:
* <br/><br/>
* <pre class="display"><code class="language-javascript">MyGame.createAsset({
* class: "Chair",
* name: "chair",
* descriptions: { look: "A office chair. " },
* aspects:
* {
* on: { nest: { can: { reach: [ 'desk' ] } } }
* }
* });
* </code></pre>
* @var {Array} adventurejs.Nest!can!reach
* @default []
*/
reach: [],
reach_from_top: [],
reach_from_bottom: [],
};
return this;
}
get asset() {
return this.game.getAsset(this.asset_id);
}
get aspect() {
return this.game.getAsset(this.asset_id).aspects[this.preposition];
}
canSubjectReachAssetFromNest(asset) {
// was question asked without a valid object?
if ("string" === typeof asset) asset = this.game.getAsset(asset);
if (!asset) return false;
const input = this.game.getInput();
const subject = input.getSubject();
let bool = false;
bool =
this.can.reach.includes(asset.id) ||
this.can.reach.includes(asset.name);
if (bool) return bool;
if (this.preposition === "on") {
// if player on top
// bool = this.can.reach_from_top.includes(asset.id);
// if (bool) return bool;
// if player on bottom
// bool = this.can.reach_from_bottom.includes(asset.id);
// if (bool) return bool;
}
return bool;
}
}
adventurejs.Nest = Nest;
})();