// punch.js
(function () {
/* global adventurejs A */
/**
* @augments {adventurejs.Verb}
* @class punch
* @ajsnode game.dictionary.verbs.punch
* @ajsconstruct MyGame.createVerb({ "name": "punch", [...] });
* @ajsconstructedby adventurejs.Dictionary#createVerb
* @hideconstructor
* @ajsinstanceof Verb
* @ajsnavheading AltercationVerbs
* @summary Verb meaning punch an asset.
* @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">> punch dalton</span>
* You punch Sir Hillary Dalton with a great roundhouse sweep. His top hat goes flying and his cane clatters to the ground as he topples like a chopped birch sapling. Dame Dalton shrieks and steps toward Sir Dalton, trips on her fluttering crinolines and falls atop him, losing one delicate embroidered slipper in the process. You retrieve the slipper and secrete it away into a fold of your voluminous cloak for later inspection.
* </pre>
* <p>
* <strong>Punch</strong> requires that the
* {@link adventurejs.Tangible|Tangible}
* {@link adventurejs.Asset|Asset} to be punched has
* asset.dov.punch.enabled
* set to true. By default, no special results will occur.
* 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.punch = {
name: "punch",
prettyname: "punch",
past_tense: "punched",
synonyms: ["punch"],
gerund: "punching",
/**
* @ajsverbstructures
* @memberof punch
*/
accepts_structures: ["verb noun"],
/**
* @memberof punch
* @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,
},
},
// @todo what about "punch person on nose"?
// also possessive: "punch person's nose"
/**
* @memberof punch
* @ajsverbparams
* with_params: {},
*/
with_params: {},
doTry: function () {
var input = this.game.getInput();
var subject = input.getSubject();
var direct_object = input.getAsset(1);
var indirect_object = input.getAsset(2);
var indirect_preposition = input.getPreposition(2);
var results;
var msg = "";
// verb enabled?
if (!direct_object.isDOV("punch")) {
this.game.debug(
`D1382 | ${this.name}.js | ${direct_object.id}.dov.punch.enabled is false `
);
msg += `{We} can't punch ${direct_object.articlename}. `;
this.handleFailure(msg);
return null;
}
// verb state? skip
// single use direct object?
if (
direct_object.allowVerbOnce(this.name, "dov") &&
direct_object.didVerb(this.name, "dov")
) {
this.game.debug(
`D1982 | ${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")) {
// can verb act without an indirect object?
if (direct_object.allowVerbWithNothing(this.name, "dov")) {
return true;
}
} // verb 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);
}, // punch
};
})();