// untie.js
(function () {
/*global adventurejs A*/
"use strict";
/**
* @augments {adventurejs.Verb}
* @class untie
* @ajsnode game.dictionary.verbs.untie
* @ajsconstruct MyGame.createVerb({ "name": "untie", [...] });
* @ajsconstructedby adventurejs.Dictionary#createVerb
* @hideconstructor
* @ajsinstanceof Verb
* @ajsnavheading ManipulationVerbs
* @summary Verb meaning untie, as in "untie string from finger".
* @tutorial Scripting_VerbSubscriptions
* @tutorial Verbs_VerbAnatomy
* @tutorial Verbs_VerbProcess
* @tutorial Verbs_ModifyVerbs
* @tutorial Verbs_WriteVerbs
* @classdesc
* <pre class="display border outline">
* <span class="input">> untie shoelace</span>
* You untie your shoelace. Hung from the tree branch by your shoe
* as you are, this promptly results in you resuming your fall
* toward the ground. Yoink! Your parachute catches in the same branch
* and you're caught again, but thankfully only a couple of feet off
* the ground this time.
* </pre>
* <p>
* <strong>Untie</strong> a {@link adventurejs.Tangible|Tangible}
* {@link adventurejs.Asset|Asset}.
* Requires that the Asset has
* asset.dov.untie.enabled set to true.
* </p>
* tryUntieThis
* tryUntieThis[Preposition]That
* tryUntieThat[Preposition]This
* doUntieThis
* doUntieThis[Preposition]That
* doUntieThat[Preposition]This
* @ajsverbphases doBeforeTry, doAfterTry, doBeforeSuccess, doAfterSuccess
*/
A.Preverbs.untie = {
name: "untie",
synonyms: ["untie"],
past_tense: "untied",
prettyname: "untie",
/**
* @memberof untie
* @ajsverbphrase
* phrase1:
* {
* accepts_noun: true,
* requires_noun: true,
* noun_must_be:
* {
* known: true,
* tangible: true,
* present: true,
* visible: true,
* reachable: true,
* },
* },
*/
phrase1: {
accepts_noun: true,
requires_noun: true,
noun_must_be: {
known: true,
tangible: true,
present: true,
visible: true,
reachable: true,
},
},
/**
* @memberof untie
* @ajsverbphrase
* phrase2:
* {
* accepts_noun: true,
* requires_noun: true,
* noun_must_be:
* {
* known: true,
* tangible: true,
* present: true,
* visible: true,
* reachable: true,
* },
* },
*/
phrase2: {
accepts_noun: true,
requires_noun: true,
noun_must_be: {
known: true,
tangible: true,
present: true,
visible: true,
reachable: true,
},
},
/**
* @memberof untie
* @ajsverbparams
* with_params: {},
*/
with_params: {},
doTry: function () {
var input = this.game.getInput();
var player = this.game.getPlayer();
var direct_object = input.getAsset(1);
var indirect_object = input.getAsset(2);
var indirect_preposition = input.getPreposition(2);
var results;
var msg = "";
// example: untie rope (from thing)
// example: untie table (from rope)
// parsed sentence structure: verb
if (input.hasStructure("verb")) {
}
// parsed sentence structure: verb noun
if (input.hasStructure("verb noun")) {
} // verb noun
// can't tie to or tie with
if (!direct_object.isDOV(this.name) && !!direct_object.isIOV(this.name)) {
this.game.debug(
`F1482 | ${this.name}.js | ${direct_object.id}.dov.untie and .iov.untie are false `
);
msg += `${direct_object.Articlename} can't be untied. `;
this.handleFailure(msg);
return null;
}
// can't be untied, which might be true even if it's a rope
if (!direct_object.isDOV("untie")) {
this.game.debug(
`F1483 | ${this.name}.js | ${direct_object.id}.dov.untie.enabled is false `
);
msg += `$(We) can't untie ${direct_object.articlename}. `;
this.handleFailure(msg);
return null;
}
// if object is rope but not tied to anything
if (direct_object.dov.tie?.with_params.connections.length === 0) {
// rope isn't tied to anything
this.game.debug(
`F1484 | ${this.name}.js | ${direct_object.id}.dov.tie.with_params.connections.length is 0 `
);
msg += `${direct_object.Articlename} isn't tied to anything. `;
this.handleFailure(msg);
return null;
}
// if object can have rope tied to it but doesn't
if (
direct_object.isIOV("tie") &&
0 === direct_object.iov.tie.with_params.connections.length
) {
this.game.debug(
`F1485 | ${this.name}.js | ${direct_object.id}.iov.tie.with_params.connections.length is 0`
);
msg += `Nothing is tied to ${direct_object.articlename}. `;
this.handleFailure(msg);
return null;
}
// if object is rope but tied to multiple things
if (direct_object.dov.tie?.with_params.connections.length > 1) {
this.game.debug(
`F1486 | ${this.name}.js | ${direct_object.id}.dov.tie.with_params.connections.length > 1, soft prompt noun2 `
);
msg += `${direct_object.Articlename} is tied to
${this.game.getPrintableObjectList({
objects: direct_object.dov.tie.with_params.connections,
})}. Which thing would you like to untie it from? `;
// soft prompt for untiewith object
input.setSoftPrompt({ noun2: true, verb: "untie_from" });
this.handleFailure(msg);
return null;
}
// only tied to one thing so be nice and kick over to untiefrom
if (direct_object.dov.tie?.with_params.connections.length === 1) {
var tiedToObject = this.game.getAsset(
direct_object.dov.tie?.with_params.connections[0]
);
input.parsedNoun2 = new adventurejs.ParsedNoun(tiedToObject);
this.game.dictionary.doVerb(
"untie_from"
); /** @TODO consolidate untie_from */
return null;
}
if (input.hasStructure("verb noun preposition noun")) {
}
return true;
},
doSuccess: function () {
var input = this.game.getInput();
var player = this.game.getPlayer();
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;
var msg = "";
this.game.debug(`F1487 | ${this.name}.js | print doSuccess `);
// apply state changes
// @TODO break dov connection
// compose output
msg += `$(We) ${this.name}`;
msg += `${direct_preposition ? " " + direct_preposition : ""}`;
msg += `${direct_object ? " " + direct_object.articlename : ""}`;
msg += `${indirect_preposition ? " " + indirect_preposition : ""}`;
msg += `${indirect_object ? " " + indirect_object.articlename : ""}`;
msg += `. `;
// print output
this.handleSuccess(msg, direct_object);
return true;
},
};
})(); // untie