// onMoveThisToThat.js
(function () {
/* global AdventureJS A */
var p = AdventureJS.Assets.Entity.prototype;
/**
* Called when this asset is added to another asset.
* Provides opportunities to override default behavior
* through the use of
* <a href="/doc/Verbs_ReactionHooks.html">verb reactions</a>
* doMoveThisToThat and doMoveThatToThis.
* @memberOf AdventureJS.Assets.Entity
* @method AdventureJS.Assets.Entity#onMoveThisToThat
* @param {Object} asset
* @param {String} aspect
* @returns {*}
*/
p.onMoveThisToThat = p.moveTo = function Entity_onMoveThisToThat(
aspect,
asset,
quantity = 1
) {
if ("string" === typeof asset) asset = this.game.getAsset(asset);
if (!asset) return false;
this.game.log(
"L1544",
"log",
"high",
`[onMoveThisToThat.js] move ${this.id} ${aspect} ${asset.id}`,
"Entity"
);
aspect = aspect || asset.default_aspect;
if (!aspect) return false;
if (!asset.hasAspectAt(aspect)) return false;
var results;
let destroyed = this.is.destroyed;
// check asset to be placed for verb hook
results = this.doVerbAction({
action: "doMoveThisToThat",
target: asset,
type: "VerbReaction",
});
if ("undefined" !== typeof results) return results;
if (!destroyed && this.is.destroyed) return;
// check receiving asset for verb hook
results = asset.onMoveThatToThis(aspect, this);
if ("undefined" !== typeof results) return results;
if (!destroyed && this.is.destroyed) return;
if (this.stack) {
const compatible = this.stack.findCompatibleStack(aspect, asset);
// @TODO consider fixed?
if (compatible) {
// merge includes a param to clear donor and
// we don't want to clear in this case because
// this stack's quantity may still be referred
// to in the verb output
compatible.stack.merge(this, false);
this.game.destroyAsset(this.id);
}
}
// reset this's position
this.position = { x: 0, y: 0, z: 0 };
// set this's new location to that
this.setPlace(aspect, asset.id);
}; // onMoveThisToThat.js
})();