// 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 DestructionVerbs
* @summary Verb meaning punch an asset.
* @tutorial Scripting_VerbSubscriptions
* @tutorial Verbs_VerbAnatomy
* @tutorial Verbs_VerbProcess
* @tutorial Verbs_ModifyVerbs
* @tutorial Verbs_WriteVerbs
* @classdesc
* <pre class="display border outline">
* <span class="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/Scripting_VerbPhases.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 verb_phrase = input.verb_phrase;
var direct_object = input.getAsset(1);
var indirect_object = input.getAsset(2);
var indirect_preposition = input.getPreposition(2);
var player = this.game.getPlayer();
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 verb_phrase = input.verb_phrase;
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 results;
var msg = "";
// 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);
}, // punch
};
})();