// onNestThisToThat.js
(function () {
/*global adventurejs A*/
"use strict";
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} aspect
* @returns {Boolean}
*/
p.onNestThisToThat = function Character_onNestThisToThat(asset, aspect) {
this.game.log(
"log",
"high",
"Nest " + this.name + " to " + asset.name + ".",
"Behavior"
);
if (!asset) return;
if (!aspect) return;
var results;
//if( asset instanceof adventurejs.Floor ) return;
// Verify with player that nothing prevents
// it from nesting in target asset.
results = this.callAction("doNestThisToThat", asset.name, {});
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.callAction("onNestThatToThis", this.name, this);
if ("undefined" !== typeof results) return results;
this.nest = { [aspect]: asset.id };
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());
}
//this.game.updateDisplayRoom();
return;
};
})();