// LiquidContainer.js
(function () {
/*global adventurejs A*/
"use strict";
/**
* @ajspath adventurejs.Atom.Asset.Matter.Tangible.Thing.Container.LiquidContainer
* @augments adventurejs.Container
* @class adventurejs.LiquidContainer
* @ajsconstruct MyGame.createAsset({ "class":"Tub", "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.
* @summary A base class for all kinds of containers which hold liquid.
* @ajssubstancecontainer in
* @ajstangiblecontainer in
* @classdesc <strong>LiquidContainer</strong> is a child class
* of {@link adventurejs.Container|Container} and the ancestor class for
* all types of containers that hold liquid (or other substances).
* It can be filled, emptied, poured from, drunk from. LiquidContainers
* can be set with a fixed maximum volume,
* and variable volume and substance. Substance volumes
* are set in mililiters by default. See the example below to create
* a new LiquidContainer.
* <pre class="display"><code class="language-javascript">MyGame.createAsset({
* class: "LiquidContainer",
* name: "dog dish",
* descriptions: { look: "That's Fido's water bowl! ", },
* in: {
* vessel: {
* volume: 500,
* maxvolume: 1000,
* substance_id: "water",
* }
* },
* });
* </code></pre>
* Before working with LiquidContainers, it's useful to understand
* the structure of nested {@link adventurejs.Asset|Assets}. All
* {@link adventurejs.Tangible|Tangible}
* Assets can have multiple
* {@link adventurejs.Aspect|Aspects}
* that correspond to in/on/under/behind/attached.
* Aspects allow players to put Tangible things
* in other Tangible things.
* {@link adventurejs.Substance|Substances} differ from Tangibles
* in that they are not singular, but rather exist in quantities
* that can be poured, filled,
* emptied, and divided. For example: water, milk, sand,
* dirt, and mercury are all Substances.
* In order for a Tangible to hold a
* Substance, Tangible.Aspect has nested in it a
* {@link adventurejs.Vessel|Vessel}.
* SubstanceLocations have their own set of properties and methods
* for dealing with Substances.
* <br><br>
* Most of the pouring and filling is handled
* automatically by internal methods, but this might make
* for a bit of confusion if you're custom coding
* SubstanceLocations at runtime. For example, here's how
* you would set a bowl filled with milk:
* <pre class="display"><code class="language-javascript">MyGame.world.my_bowl.aspects.in.vessel.substance_id = "milk";
* MyGame.world.my_bowl.aspects.in.vessel.volume = 500;
* </code></pre>
**/
class LiquidContainer extends adventurejs.Container {
constructor(name, game_name) {
super(name, game_name);
this.class = "LiquidContainer";
this.setDOVs(["fill", "empty", "pour", "drink"]);
this.setIOVs(["fill", "empty", "pour"]);
this.aspects.in = new adventurejs.Aspect("in", this.game_name).set({
parent_id: this.id,
});
this.aspects.in.vessel = new adventurejs.Vessel("in", game_name).set({
parent_id: this.id,
});
this.onPourLiquidOutOfMe = function LiquidContainer_onPourLiquidOutOfMe(
id
) {
console.log(this.name, "onPourLiquidOutOfMe", id);
};
this.doPourLiquidOutOfMe = {};
this.onPourLiquidIntoMe = function LiquidContainer_onPourLiquidIntoMe(
id
) {
console.log(this.name, "onPourLiquidIntoMe", id);
};
this.doPourLiquidIntoMe = {};
}
initialize(game) {
super.initialize(game);
return this;
}
}
adventurejs.LiquidContainer = LiquidContainer;
})();