// onNestThisToThat.js
(function () {
/* global adventurejs A */
var p = adventurejs.Character.prototype;
/**
* Called when player asset is nested to another asset.
* Provides opportunities to override default behavior
* through the use of
* <a href="/doc/Scripting_VerbReactions.html">verb reactions</a>
* doNestThisToThat and doNestThatToThis.
* @memberOf adventurejs.Character
* @method adventurejs.Character#onNestThisToThat
* @param {Object} asset
* @param {String} preposition
* @returns {Boolean}
*/
p.onNestThisToThat = function Character_onNestThisToThat(asset, preposition) {
if (!asset) return;
if (!preposition) return;
this.game.log(
"L1431",
"log",
"high",
`[onNestThisToThat.js] nest ${this.id} ${preposition} ${asset.id}`,
"Character"
);
var results;
//if( asset instanceof adventurejs.Floor ) return;
// Verify with player that nothing prevents
// it from nesting in target asset.
results = this.doVerbAction({
action: "doNestThisToThat",
asset2: asset.name,
type: "VerbReaction",
});
if ("undefined" !== typeof results) return results;
// don't nest to floors
if (asset instanceof adventurejs.Floor) return;
// Verify with target asset that nothing
// prevents it from hosting player.
results = asset.onNestThatToThis(this, preposition);
if ("undefined" !== typeof results) return results;
this.nest = { [preposition]: asset.id };
this.posture = asset.aspects[preposition].nest.posture || this.posture;
if (this.isWithinYRange(asset)) {
// nothing
} else if (this.getY() > asset.getYTop()) {
this.setY(asset.getYTop());
} else if (this.getY() < asset.getYBottom()) {
this.setY(asset.getYBottom());
}
return;
};
})();