// release.js
(function () {
/*global adventurejs A*/
/**
* @augments {adventurejs.Verb}
* @class release
* @ajsnode game.dictionary.verbs.release
* @ajsconstruct MyGame.createVerb({ "name": "release", [...] });
* @ajsconstructedby adventurejs.Dictionary#createVerb
* @hideconstructor
* @ajsinstanceof Verb
* @ajsnavheading ManipulationVerbs
* @summary Verb meaning release or let go of, as in "let go of rope".
* @tutorial Scripting_VerbSubscriptions
* @tutorial Verbs_VerbAnatomy
* @tutorial Verbs_VerbProcess
* @tutorial Verbs_ModifyVerbs
* @tutorial Verbs_WriteVerbs
* @classdesc
* <pre class="display border outline">
* <span class="input">> let go of pride</span>
* You let go of your pride. With it, you feel a swell
* of emotion: loss, grief, regret. Joy. You sob and laugh
* with an intense, almost hysterical feeling of release,
* tinged with a hint of bitterness at all the time you've lost.
* </pre>
* <p>
* <strong>Let go of</strong> a
* {@link adventurejs.Tangible|Tangible}
* {@link adventurejs.Asset|Asset}.
* Operates in several ways. If player is hanging, as if from a rope,
* redirects to {@link go_off}. If player is holding but not nested,
* as if with an end of a rope, player lets go. If player is carrying
* Asset, player drops it.
* </p>
* @ajsverbreactions doRemoveThisFromThat, doRemoveThatFromThis, doMoveThisToThat, doMoveThatToThis
* @ajsverbphases doBeforeTry, doAfterTry, doBeforeSuccess, doAfterSuccess
*/
A.Preverbs.release = {
name: "release",
prettyname: "release",
synonyms: ["release"],
verb_prep_noun: ["let go"],
verb_prep_prep_noun: ["let go of"],
gerund: "releasing",
/**
* @ajsverbstructures
* @memberof release
*/
accepts_structures: ["verb", "verb noun"],
/**
* @memberof release
* @ajsverbphrase
* phrase1:
* {
* accepts_noun:true,
* noun_must_be:
* {
* tangible: true,
* known: true,
* present: true,
* visible: true,
* reachable: true,
* //in_inventory: true,
* // If we were carrying we'd limit to in_inventory
* // but "let go of" can also apply to things player
* // is holding on to.
* },
* },
*/
phrase1: {
accepts_noun: true,
noun_must_be: {
tangible: true,
known: true,
present: true,
visible: true,
reachable: true,
},
},
/**
* @memberof release
* @ajsverbparams
* with_params: {},
*/
with_params: {},
doTry: function () {
var input = this.game.getInput();
var verb_phrase = input.verb_phrase;
var direct_object = input.getAsset(1);
var player = this.game.getPlayer();
var nest_asset = player.getNestAsset();
var results;
var asset;
var msg = "";
if (verb_phrase === "let go" || verb_phrase === "let go of") {
//
}
if (input.hasStructure("verb")) {
// sentence structure: verb
if ("release" === input.input_verb) {
// we think of "release" as meaning drop
// and we don't accept it as intransitive
// in the way that we accept "let go" where
// context should make direct object clear
// prompt for a direct object
input.setSoftPrompt({
index: 1,
type: "noun",
noun1: true,
verb: input.input_verb,
verb_phrase: input.verb_phrase,
});
this.game.debug(
`D1355 | ${this.name}.js | no noun provided or inferrable, soft prompt noun1`
);
msg += `What did $(we) want to release? `;
this.handleFailure(msg);
return null;
}
// is player nested in something they can drop from?
if (
player.isNested() &&
nest_asset.hasQuirk("let_go_of_means_go_off")
) {
asset = nest_asset;
}
// is player holding one thing?
else if (1 === player.getVerbConnectionCount("hold", "to_dov")) {
asset = this.game.getAsset(
player.getVerbConnections("hold", "to_dov")[0]
);
}
if (!asset) {
this.game.debug(
`D1709 | ${this.name}.js | no noun supplied or inferred, soft prompt noun1 `
);
input.setSoftPrompt({
index: 1,
type: "noun",
noun1: true,
verb: this.name,
});
msg += "Let go of what? ";
this.handleFailure(msg);
return null;
}
direct_object = asset;
input.setAsset(1, asset);
input.setInferred(1);
input.setStructure("verb noun");
this.game.printInferred(`${asset.articlename}`);
} // verb
// sentence structure: verb noun
// example: let go of rope (holding)
if (input.hasStructure("verb noun")) {
// example: let go of branch (hanging from)
// might result in falling to ground
// might also result in tryTravel to lower room
// @TODO
// what if player is in space?
// or in rushing water?
// author can do these in doAfterSuccess
// is object takeable and in player inventory? do drop
if (direct_object.isWithin(player) && direct_object.isDOV("drop")) {
this.game.debug(
`D1710 | ${this.name}.js | infer 'drop ${direct_object.name}', doVerb drop`
);
return this.game.dictionary.doVerb("drop");
}
// is player nested in an object where letGo means goOff?
if (
player.isNested() &&
direct_object.id === nest_asset.id &&
direct_object.hasQuirk("let_go_of_means_go_off") &&
this.game.hasVerb("go")
) {
this.game.debug(
`D1711 | ${this.name}.js | infer 'go off', doVerb go`
);
if (player.isConnectedToAsset("hold", direct_object, "to_dov")) {
// break "held" connection
this.unsetVerbConnection(direct_object, player);
}
input.setVerb(1, "go");
input.setPreposition(1, "off");
input.setStructure("verb preposition noun");
return this.game.dictionary.doVerb("go");
}
// is player nested in an object where letGo means goDown?
if (
player.isNested() &&
direct_object.id === nest_asset.id &&
direct_object.hasQuirk("let_go_of_means_go_down")
) {
this.game.debug(
`D1712 | ${this.name}.js | infer 'go down', doVerb down`
);
results = this.game.tryTravel("down");
return results;
}
// not holding object
if (!player.isConnectedToAsset("hold", direct_object, "to_dov")) {
msg += `$(We're) not holding ${direct_object.articlename}. `;
this.handleFailure(msg);
return null;
}
} // verb noun
return true;
},
doSuccess: function () {
var input = this.game.getInput();
var verb_phrase = input.verb_phrase;
// if (input.did_tryTravel) return this.handleSuccess();
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 player = this.game.getPlayer();
var msg = "";
var results;
// apply state changes
if (player.isConnectedToAsset("hold", direct_object, "to_dov")) {
// break "held" connection
this.game.dictionary.verbs.hold.unsetVerbConnection(
direct_object,
player
);
}
// compose output
msg +=
`$(We) ${this.name}` +
`${direct_preposition ? " " + direct_preposition : ""}` +
`${direct_object ? " " + direct_object.articlename : ""}` +
`${indirect_preposition ? " " + indirect_preposition : ""}` +
`${indirect_object ? " " + indirect_object.articlename : ""}` +
`. `;
// print output
return this.handleSuccess(msg, direct_object);
},
};
})(); // release