// unscrew.js
(function () {
/*global adventurejs A*/
"use strict";
/**
* @augments {adventurejs.Verb}
* @class unscrew
* @ajsnode game.dictionary.verbs.unscrew
* @ajsconstruct MyGame.createVerb({ "name": "unscrew", [...] });
* @ajsconstructedby adventurejs.Dictionary#createVerb
* @hideconstructor
* @ajsinstanceof Verb
* @ajsnavheading ManipulationVerbs
* @summary Verb meaning unscrew, as in "unscrew table leg".
* @tutorial Scripting_VerbSubscriptions
* @tutorial Verbs_VerbAnatomy
* @tutorial Verbs_VerbProcess
* @tutorial Verbs_ModifyVerbs
* @tutorial Verbs_WriteVerbs
* @classdesc
* <pre class="display border outline">
* <span class="input">> unscrew table leg</span>
* You unscrew the thick table leg. A bottle cap falls out of the
* screw hole and pings to the floor. You pick up the bottle cap.
* Red Devil Brewery. Could it be a clue?
* </pre>
* <p>
* <strong>Unscrew</strong> a {@link adventurejs.Tangible|Tangible}
* {@link adventurejs.Asset|Asset}.
* Requires that the Asset has
* asset.dov.unscrew.enabled set to true.
* </p>
* tryUnscrewThis
* tryUnscrewThis[Preposition]That
* tryUnscrewThat[Preposition]This
* doUnscrewThis
* doUnscrewThis[Preposition]That
* doUnscrewThat[Preposition]This
* @ajsverbphases doBeforeTry, doAfterTry, doBeforeSuccess, doAfterSuccess
*/
A.Preverbs.unscrew = {
name: "unscrew",
synonyms: ["unscrew"],
past_tense: "unscrewed",
prettyname: "unscrew",
unstate: "screwed",
/**
* @memberof unscrew
* @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 unscrew
* @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 msg = "";
var results;
// parsed sentence structure: verb
if (input.hasStructure("verb")) {
}
// parsed sentence structure: verb noun
if (input.hasStructure("verb noun")) {
} // verb noun
// if it's attached to something then we're unscrewing it from something
if ("attached" === direct_object.getPlacePreposition()) {
/** @TODO consolidate unscrew_from into screw */
this.game.debug(
`F1473 | ${this.name}.js | ${direct_object.id} is attached, infer unscrew_from `
);
this.game.dictionary.doVerb("unscrew_from");
return null;
}
// can't unscrew
if (!direct_object.isDOV("unscrew")) {
this.game.debug(
`F1474 | ${this.name}.js | ${direct_object.id}.dov.unscrew.enabled is false `
);
msg += `$(We) can't unscrew ${direct_object.articlename}. `;
this.handleFailure(msg);
return null;
}
// already unscrewed
if (!direct_object.is.screwed) {
this.game.debug(
`F1475 | ${this.name}.js | ${direct_object.id}.is.screwed is false `
);
msg += `${direct_object.Articlename} is already unscrewed. `;
this.handleFailure(msg);
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 msg = "";
var results;
this.game.debug(`F1476 | ${this.name}.js | print doSuccess `);
// apply state changes
this.setState(direct_object, false);
// 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 += `. `;
// we don't do anything more
// could be something like a pen that is traded for two new objects
// leaving it up to author to decide
// what happens to it, using doAfterSuccess
// print output
this.handleSuccess(msg, direct_object);
return true;
},
};
})(); // unscrew