// wave.js
(function () {
/* global adventurejs A */
/**
* @augments {adventurejs.Verb}
* @class wave
* @ajsnode game.dictionary.verbs.wave
* @ajsconstruct MyGame.createVerb({ "name": "wave", [...] });
* @ajsconstructedby adventurejs.Dictionary#createVerb
* @hideconstructor
* @ajsinstanceof Verb
* @ajsnavheading GesticulationVerbs
* @summary Verb meaning wave, as in "wave at Queen" or "wave pennant".
* @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">> wave at dock</span>
* You wave at the people remaining on the dock. Poor bastards who couldn't afford the ticket. Oh well, sod 'em all. You don't give them another thought as you turn to find your cabin aboard the RMS Titanic.
* </pre>
* <p>
* <strong>Wave</strong> can be intransitive, or it can take a
* {@link adventurejs.Tangible|Tangible}
* {@link adventurejs.Asset|Asset} to be waved.
* Wave doesn't provide any special logic.
* Authors wanting to make use of it may need to use a method such
* as verb hooks. See
* <a href="/doc/Verbs_PhaseHooks.html">Verb Phases</a>
* to learn more.
* </p>
* @ajsverbreactions
* @ajsverbphases doBeforeTry, doAfterTry, doBeforeSuccess, doAfterSuccess
*/
A.Preverbs.wave = {
name: "wave",
past_tense: "waved",
synonyms: ["wave"],
gerund: "waving",
/**
* @ajsverbstructures
* @memberof wave
*/
accepts_structures: [
"verb",
"verb noun",
"verb preposition noun",
"verb noun preposition noun",
],
subject_must_be: {
not_constrained: true,
},
/**
* @memberof wave
* @ajsverbphrase
* phrase1:
* {
* accepts_noun: true,
* noun_must_be:
* {
* known: true,
* tangible: true,
* present: true,
* visible: true,
* },
* accepts_preposition: true,
* preposition_must_be: [ 'at', 'to' ],
* },
*/
phrase1: {
accepts_noun: true,
noun_must_be: {
known: true,
tangible: true,
present: true,
visible: true,
},
accepts_preposition: true,
preposition_must_be: ["with", "at", "to"],
},
/**
* @memberof wave
* @ajsverbphrase
* phrase2:
* {
* accepts_noun: true,
* noun_must_be:
* {
* known: true,
* tangible: true,
* present: true,
* visible: true,
* },
* accepts_preposition: true,
* requires_preposition: true,
* preposition_must_be: [ 'at', 'to' ],
* },
*/
phrase2: {
accepts_noun: true,
noun_must_be: {
known: true,
tangible: true,
present: true,
visible: true,
},
accepts_preposition: true,
requires_preposition: true,
preposition_must_be: ["at", "to", "with"],
},
/**
* @memberof wave
* @ajsverbparams
* with_params: {},
*/
with_params: {},
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 msg = "";
// sentence structure: verb noun
if (
input.hasStructure("verb noun") ||
input.hasStructure("verb noun preposition noun")
) {
// verb enabled?
if (!direct_object.isDOV(this.name)) {
this.game.debug(
`D1996 | ${this.name}.js | ${direct_object.id}.dov.${this.name}.enabled is false `
);
msg += `{We} can't ${this.name} ${direct_object.articlename}. `;
this.handleFailure(msg);
return null;
}
// is subject holding asset?
if (0 === this.game.parser.selectInHands(direct_object.id).length) {
this.game.debug(
`D1600 | ${this.name}.js | ${direct_object.id}.isWithin subject is false `
);
msg += `{We're} not holding ${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(
`D1997 | ${this.name}.js | ${direct_object.id}.dov.${this.name}.once and ${direct_object.id}.did.${this.name}.directly `
);
msg += `{We} can't ${this.name} ${direct_object.articlename} any more. `;
this.handleFailure(msg);
return false;
}
} // verb noun
// sentence structure: verb noun preposition noun or verb preposition noun
if (
input.hasStructure("verb noun preposition noun") ||
input.hasStructure("verb preposition noun")
) {
// "wave at x" is read with x as direct object
// but we infer that x is indirect object
if (!indirect_object) indirect_object = direct_object;
if (!indirect_preposition) indirect_preposition = direct_preposition;
if ("with" === indirect_preposition) {
// is subject holding asset?
if (!this.game.parser.selectInHands(indirect_object.id).length) {
this.game.debug(
`D2000 | ${this.name}.js | ${indirect_object.id}.$is("inhands") is false `
);
msg += `{We're} not holding ${indirect_object.articlename}. `;
this.handleFailure(msg);
return null;
}
}
// can indirect object be used?
if (!indirect_object.isIOV(this.name)) {
this.game.debug(
`D1998 | ${this.name}.js | ${indirect_object.id}.iov.${this.name} is unset `
);
msg += `{We} can't ${this.name} anything ${indirect_preposition} ${indirect_object.articlename}. `;
this.handleFailure(msg);
return false;
}
// single use indirect object?
if (
indirect_object.allowVerbOnce(this.name, "iov") &&
indirect_object.iDidVerb(this.name, "iov")
) {
this.game.debug(
`D1999 | ${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 += `{We've} already ${this.past_tense} ${indirect_preposition} ${indirect_object.articlename}. `;
this.handleFailure(msg);
return null;
}
}
// sentence structure: verb noun preposition noun
// ex: "wave x at y", "wave x with y"
if (input.hasStructure("verb noun preposition noun")) {
} // 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 results;
var msg = "";
// compose output
msg +=
`{We} ${this.agree()}` +
`${direct_preposition ? " " + direct_preposition : ""}` +
`${direct_object ? " " + direct_object.articlename : ""}` +
`${indirect_preposition ? " " + indirect_preposition : ""}` +
`${indirect_object ? " " + indirect_object.articlename : ""}` +
`! `;
// --------------------------------------------------
// print output
// --------------------------------------------------
return this.handleSuccess(msg);
},
};
})(); // wave