// punch.js
(function () {
/*global adventurejs A*/
"use strict";
/**
* @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. No special logic is provided with the verb.
* 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"],
/**
* @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 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(
`F1382 | ${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.DOVallowOnce(this.name) &&
direct_object.DOVdidDo(this.name)
) {
this.game.debug(
`F1982 | ${this.name}.js | ${direct_object.id}.dov.${this.name}.once and ${direct_object.id}.dov.${this.name}.did_do `
);
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.DOVallowWithNothing(this.name)) {
return true;
}
} // verb noun
return true;
},
doSuccess: function () {
var input = this.game.getInput();
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 = "";
this.game.debug(`F1383 | ${this.name}.js | print doSuccess `);
// 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 += `. `;
// print output
this.handleSuccess(msg, direct_object);
return true;
}, // punch
};
})();