// lasso.js
(function () {
/* global adventurejs A */
/**
* @augments {adventurejs.Verb}
* @class lasso
* @ajsnode game.dictionary.verbs.lasso
* @ajsconstruct MyGame.createVerb({ "name": "lasso", [...] });
* @ajsconstructedby adventurejs.Dictionary#createVerb
* @hideconstructor
* @ajsinstanceof Verb
* @ajsnavheading ManipulationVerbs
* @summary Verb meaning lasso asset with rope.
* @tutorial Verbs_Subscriptions
* @tutorial AdvancedVerbs_VerbAnatomy
* @tutorial AdvancedVerbs_VerbProcess
* @tutorial AdvancedVerbs_ModifyVerbs
* @tutorial AdvancedVerbs_ModifyVerbs
* @classdesc
* <pre class="display border outline">
* <span class="ajs-player-input">> lasso crocagator with rope</span>
* You lasso the crocagator with the woven grass rope. The rope slips over the croc's long mouth. You pull, and the croc's mouth slams shut. The crocagator thrashes angrily and whips its jewel-tipped tail and pulls you off balance. You dig in and pull. Step by step, you drag the bellowing crocagator out of its watering hole. Soon its magic emerald will be yours.
* </pre>
* <p>
* <strong>Lasso</strong> a
* {@link adventurejs.Tangible|Tangible}
* {@link adventurejs.Asset|Asset} with a
* {@link adventurejs.Rope|Rope}.
* Asset to be lassoed must have
* <code>asset.dov.lasso.enabled</code> set to true.
* Lasso has several distinct <a href="#params">params</a>
* for controlling what happens to the rope after use.
* </p>
* @ajsverbreactions doTieThisToThat, doTieThatToThis, doRemoveThisFromThat, doRemoveThatFromThis, doMoveThisToThat, doMoveThatToThis
* @ajsverbphases doBeforeTry, doAfterTry, doBeforeSuccess, doAfterSuccess
*/
A.Preverbs.lasso = {
name: "lasso",
prettyname: "lasso",
past_tense: "lassoed",
synonyms: ["lasso", "rope"],
gerund: "lassoing",
subject_must_be: {
//not_on_floor: true,
not_constrained: true,
//not_under: true,
//not_behind: true,
},
/**
* @ajsverbstructures
* @memberof lasso
*/
accepts_structures: [
"verb noun", // lasso steer (with rope)
"verb noun preposition noun", // lasso steer with rope
],
/**
* @memberof lasso
* @ajsverbphrase
* phrase1:
* {
* accepts_noun:true,
* requires_noun: true,
* noun_must_be:
* {
* known: true,
* tangible: true,
* present: true,
* visible: true,
* },
* },
*/
phrase1: {
accepts_noun: true,
requires_noun: true,
noun_must_be: {
known: true,
tangible: true,
present: true,
visible: true,
},
},
/**
* @memberof lasso
* @ajsverbphrase
* phrase2:
* {
* accepts_noun:true,
* noun_must_be:
* {
* known: true,
* in_inventory: true,
* },
* accepts_preposition: true,
* requires_preposition: true,
* preposition_must_be: ["with"],
* },
*/
phrase2: {
accepts_noun: true,
noun_must_be: { known: true, in_inventory: true },
accepts_preposition: true,
requires_preposition: true,
preposition_must_be: ["with"],
},
/**
* @memberof lasso
* @ajsverbparams
* with_params: {
*
* // If true, using this asset to lasso another will
* // result in this asset being tied to the other;
* // and calling verb reactions
* // rope.doTieThisToThat and target.doTieThatToThis.
* on_lasso_set_tied: false,
*
* // If true, using this asset to lasso another will
* // result in this asset being attached to the other
* // and in calling these verb reactions:
* // - subject.doRemoveThatFromThis(lasso)
* // - lasso.doRemoveThisFromThat(subject)
* // - target.doMoveThatToThis(lasso)
* // - lasso.doMoveThisToThat(target)
* on_lasso_set_attached: false,
*
* // If true, using this asset as a lasso will
* // remove it from subject inventory.
* on_lasso_remove_from_player: false,
*
* // If true, using this asset as a lasso will
* // leave the subject holding it.
* on_lasso_set_held: false,
* },
*/
with_params: {
on_lasso_set_tied: false,
on_lasso_set_attached: false,
on_lasso_remove_from_player: false,
on_lasso_set_held: false,
},
doTry: function () {
var input = this.game.getInput();
var subject = input.getSubject();
var direct_object = input.getAsset(1);
var direct_preposition = input.getPreposition(1);
var indirect_object = input.getAsset(2);
var indirect_preposition = input.getPreposition(2);
var results, indirect_inferred;
var msg = "";
if (!direct_object.isDOV(this.name)) {
this.game.debug(
`D1330 | ${this.name}.js | ${direct_object.id}.dov.lasso is unset `
);
msg += `{We} can't lasso ${direct_object.articlename}. `;
this.handleFailure(msg);
return null;
}
// single use direct object?
if (
direct_object.allowVerbOnce(this.name, "dov") &&
direct_object.didVerb(this.name, "dov")
) {
this.game.debug(
`D2171 | ${this.name}.js | ${direct_object.id}.dov.${this.name}.once and ${direct_object.id}.did.${this.name}.directly `
);
msg += `${direct_object.Articlename} has already been ${this.past_tense}. `;
this.handleFailure(msg);
return false;
}
if (input.hasStructure("verb noun")) {
// indirect objects available?
if (
!direct_object.hasIndirectObjects(this.name) &&
!direct_object.allowVerbWithNothing(this.name, "dov")
) {
this.game.debug(
`D2172 | ${this.name}.js | ${direct_object.id}.dov.${this.name}.with_nothing is false `
);
msg += `{We} {don't} know of anything that can be used to ${this.name} ${direct_object.articlename}. `;
this.handleFailure(msg);
return false;
}
// infer indirect object?
results = this.tryToInferIndirectObject({
direct_object: direct_object,
context: subject,
handle_input: true,
});
if (results.prompt) {
// indirect object required?
if (direct_object.allowVerbWithNothing(this.name, "dov")) {
return true;
}
this.game.debug(`D2173 | ${this.name}.js | soft prompt for noun2 `);
msg += `What would {we} like to ${this.name} ${direct_object.articlename} with? `;
this.handleFailure(msg);
return false;
} else if (results.success) {
indirect_object = results.indirect_object;
indirect_preposition = "with";
indirect_inferred = true;
input.setAsset(2, indirect_object);
input.setPreposition(2, indirect_preposition);
input.setStructure("verb noun preposition noun");
this.game.printInferred(
`${indirect_preposition} ${indirect_object.articlename}`
);
}
} // verb noun
// sentence structure: verb noun preposition noun
if (input.hasStructure("verb noun preposition noun")) {
// indirect object already tied / attached?
if (
indirect_object.isAttached(direct_object) ||
indirect_object.isConnectedToAsset("tie", direct_object, "iov")
) {
let attached = indirect_object.isAttached(direct_object)
? "attached"
: "tied";
this.game.debug(
`D2179 | ${this.name}.js | ${indirect_object.id} is ${attached} to ${direct_object.id}`
);
msg += `${indirect_object.Articlename_is} already ${attached} to ${direct_object.articlename}. `;
this.handleFailure(msg);
return false;
}
// works with any indirect object?
if (direct_object.allowVerbWithAnything(this.name, "dov")) {
return true;
}
// indirect object not required?
// if (direct_object.allowVerbWithNothing(this.name, "dov")) {
// this.game.debug(
// ` | ${this.name}.js | ${direct_object.id}.dov.${this.name}.with_nothing `
// );
// msg += `{We} {don't} need ${indirect_object.articlename} to ${this.name} ${direct_object.articlename}. `;
// this.handleFailure(msg);
// return null;
// }
// can indirect object be used?
if (!indirect_object.isIOV(this.name)) {
this.game.debug(
`D1331 | ${this.name}.js | ${indirect_object.id}.iov.${this.name}.enabled is false `
);
msg += `{We} can't ${this.name} anything ${indirect_preposition} ${indirect_object.articlename}. `;
this.handleFailure(msg);
return null;
}
// single use indirect object?
if (
indirect_object.allowVerbOnce(this.name, "iov") &&
indirect_object.iDidVerb(this.name, "iov")
) {
this.game.debug(
`D2175 | ${this.name}.js | ${indirect_object.id}.iov.${
this.name
}.once and ${indirect_object.id}.did.${this.name}.indirectly is ${
indirect_object.did[this.name].indirectly
} `
);
msg += `${indirect_object.Articlename} has already been used to ${this.name} something. `;
this.handleFailure(msg);
return null;
}
// indirect object usable with direct object?
if (
!direct_object.allowVerbWithAsset({
verb: this.name,
asset: indirect_object,
ov: "dov",
})
) {
this.game.debug(
`D2174 | ${this.name}.js | ${direct_object.id}.dov.${this.name}.with_assets/with_classes does not include ${indirect_object.id} `
);
msg += `{We} can't use ${indirect_object.articlename} to ${this.name} ${direct_object.articlename}. `;
this.handleFailure(msg);
return null;
}
} // verb noun preposition noun
return true;
},
doSuccess: function () {
var input = this.game.getInput();
var subject = input.getSubject();
var direct_object = input.getAsset(1);
var direct_preposition = input.getPreposition(1);
var indirect_object = input.getAsset(2);
var indirect_preposition = input.getPreposition(2);
var msg = "";
var results;
var tied, attached, removed, held;
// remove from subject?
// @TODO is rope tied to subject?
if (
true ===
indirect_object.getVerbParam(
this.name,
"iov",
"on_lasso_remove_from_player"
) &&
subject.$has(indirect_object)
) {
// remove thing from subject
results = subject.onRemoveThatFromThis(indirect_object);
if ("undefined" !== typeof results) return results;
removed = true;
}
// set held?
// @TODO is rope tied to subject?
else if (
true ===
indirect_object.getVerbParam(this.name, "iov", "on_lasso_set_held")
) {
if (!indirect_object.isDOV("hold")) {
this.game.debug(
`D2178 | ${this.name}.js | ${indirect_object.id}.dov.hold is unset. ${indirect_object.id} won't be held by subject. `
);
} else {
if (subject.$has(indirect_object)) {
// remove thing from subject
results = subject.onRemoveThatFromThis(indirect_object);
if ("undefined" !== typeof results) return results;
}
let hold = this.game.dictionary.verbs.hold;
hold.setVerbConnection(indirect_object, subject);
held = true;
}
}
// tie rope to target?
if (indirect_object.getVerbParam(this.name, "iov", "on_lasso_set_tied")) {
if (!direct_object.isIOV("tie") || !indirect_object.isDOV("tie")) {
this.game.debug(
`D2176 | ${this.name}.js | ${indirect_object.id}.iov.${
this.name
}.with_params.on_lasso_set_tied is true but ${
!direct_object.isIOV("tie")
? direct_object.id + ".iov.tie is unset"
: ""
} ${
!indirect_object.isDOV("tie")
? indirect_object.id + ".dov.tie is unset"
: ""
}. ${direct_object.id} won't be tied to ${direct_object.id}. `
);
} else {
this.game.debug(
`Fxxx | ${this.name}.js | on_lasso_set_tied > move ${indirect_object.id} in ${direct_object.id}`
);
// call tie verb actions
results = indirect_object.onTieThisToThat(direct_object);
if ("undefined" !== typeof results) return results;
indirect_object.moveTo("on", direct_object);
console.warn("BUH?");
// direct_object.onMoveThatToThis(indirect_object, "in");
tied = true;
}
}
// attach rope to target?
if (
true ===
indirect_object.getVerbParam(this.name, "iov", "on_lasso_set_attached")
) {
if (!direct_object.hasAspectAt("attached")) {
this.game.debug(
`D2177 | ${this.name}.js | on_lasso_set_attached > ${
indirect_object.id
}.iov.${this.name}.with_params.on_lasso_set_attached is true but ${
direct_object.id + ".aspects.attached is unset"
}. ${indirect_object.id} won't be attached to ${direct_object.id}. `
);
} else {
this.game.debug(
`Fxxx | ${this.name}.js | move ${indirect_object.id} attached ${direct_object.id}`
);
indirect_object.moveTo("attached", direct_object);
attached = true;
}
}
// direct_object.can.support_swinging = true;
// indirect_object.is.supported = true;
// compose output
msg +=
`{We} ${this.agree()}` +
`${direct_preposition ? " " + direct_preposition : ""}` +
`${direct_object ? " " + direct_object.articlename : ""}` +
`${indirect_preposition ? " " + indirect_preposition : ""}` +
`${indirect_object ? " " + indirect_object.articlename : ""}` +
`. ` +
`${indirect_object.Articlename} ` +
`${
tied || attached
? (tied ? "ties " : "attaches ") + "tightly to "
: "settles over "
}` +
`${direct_object.articlename}` +
`${(tied || attached) && removed ? " and" : ""}` +
`${removed ? " slips from {our} hands" : ""}` +
`${held ? " leaving {us} holding the other end" : ""}` +
`. `;
// --------------------------------------------------
// print output
// --------------------------------------------------
return this.handleSuccess(msg);
},
}; // END p.preverbs.push
})();