// modifyVerb.js
(function () {
/* global adventurejs A */
var p = adventurejs.Dictionary.prototype;
/**
* <strong>modifyVerb</strong> enables an author to revise the properties
* of an existing verb. For example, let's say you want to revise the
* verb "plug" so that it works in the dark - meaning that players
* it can operate on assets the player can't see. You might copy the
* <code>plug.phrase1</code> and in your game file, call modifyVerb with
* line <code>visible: true</code> removed. Use game.modifyVerb() as a shortcut.
* <pre class="display"><code class="language-javascript">MyGame.modifyVerb({
* name: "plug",
* phrase1:{
* accepts_noun: true,
* requires_noun: true,
* accepts_preposition: true,
* noun_must_be:
* {
* known: true,
* tangible: true,
* present: true,
* <span class="strikethrough">visible: true,</span>
* reachable: true,
* },
* },
* });</code></pre>
* @memberOf adventurejs.Dictionary
* @method adventurejs.Dictionary#modifyVerb
* @param {Object} modifyVerb
* @returns {object}
*/
p.modifyVerb = function (modifyVerb) {
if ("object" !== typeof modifyVerb) {
var msg =
"Dictionary.modifyVerb takes an object, but received " +
typeof modifyVerb +
": " +
modifyVerb;
this.game.log("L1323", "warn", "critical", msg, "dictionary");
return false;
}
if ("undefined" === typeof modifyVerb.name) {
var msg =
"Dictionary.modifyVerb received an object without a name: " +
JSON.stringify(modifyVerb);
this.game.log("L1324", "warn", "critical", msg, "dictionary");
return false;
}
if ("undefined" === typeof this.verbs[modifyVerb.name]) {
var msg =
"Dictionary.modifyVerb received a verb name that doesn't exist: " +
modifyVerb.name;
this.game.log("L1325", "warn", "critical", msg, "Verb");
return false;
}
var verb = this.verbs[modifyVerb.name];
// add new synonyms, if any, to verb lookup
// does not allow removal of existing words
if (modifyVerb.synonyms) {
this.game.dictionary.verb_lookup[verb.name].synonyms =
this.game.dictionary.verb_lookup[verb.name].synonyms.concat(
modifyVerb.synonyms
);
}
verb.set(modifyVerb); // copy incoming props to existing verb
verb.initialize();
if (false !== verb) {
this.game.log(
"L1326",
"log",
"medium",
"modifyVerb successfully patched verb " + verb.name + ".",
"dictionary"
);
}
return verb;
};
})();