// erase.js
(function () {
/*global adventurejs A*/
"use strict";
/**
* @augments {adventurejs.Verb}
* @class erase
* @ajsnode game.dictionary.verbs.erase
* @ajsconstruct MyGame.createVerb({ "name": "erase", [...] });
* @ajsconstructedby adventurejs.Dictionary#createVerb
* @hideconstructor
* @ajsinstanceof Verb
* @ajsnavheading CompositionVerbs
* @summary Verb meaning erase asset.
* @todo Everything. Copied this from write_on and haven't modified yet. Need erase_noun1_with_noun2.
* @tutorial Scripting_VerbSubscriptions
* @tutorial Verbs_VerbAnatomy
* @tutorial Verbs_VerbProcess
* @tutorial Verbs_ModifyVerbs
* @tutorial Verbs_WriteVerbs
* @classdesc
* <pre class="display border outline">
* <span class="input">> erase paper</span>
* You erase the sheet of paper.
* </pre>
* <p>
* <strong>Erase</strong> erases a
* {@link adventurejs.Tangible|Tangible}
* {@link adventurejs.Asset|Asset}
* of anything written on it.
* Requires that the Asset to be erased has
* asset.dov.erase.enabled
* set to true and that player is holding an
* {@link adventurejs.Eraser|Eraser} Asset
* (aka a Tangible Asset with its
* asset.iov.erase.enabled set to true).
* </p>
* @ajsverbphases doBeforeTry, doAfterTry, doBeforeSuccess, doAfterSuccess
*/
A.Preverbs.erase = {
name: "erase",
prettyname: "erase",
past_tense: "erased",
synonyms: ["erase"],
verb_noun_prep_noun: ["erase with"],
/**
* @memberof erase
* @ajsverbphrase
* phrase1:
* {
* accepts_noun: true,
* requires_noun: true,
* noun_must_be:
* {
* tangible: true,
* present: true,
* known: true,
* visible: true,
* reachable: true,
* },
* },
*/
phrase1: {
accepts_noun: true,
requires_noun: true,
noun_must_be: {
tangible: true,
present: true,
known: true,
visible: true,
reachable: true,
},
},
/**
* @memberof erase
* @ajsverbphrase
* phrase2:
* {
* accepts_noun: true,
* noun_must_be:
* {
* known: true,
* in_inventory: true,
* },
* accepts_preposition: true,
* accepts_these_prepositions: ["with"],
* },
*/
phrase2: {
accepts_noun: true,
noun_must_be: {
known: true,
in_inventory: true,
},
accepts_preposition: true,
accepts_these_prepositions: ["with"],
},
/**
* @memberof erase
* @ajsverbparams
* with_params: {},
*/
with_params: {},
doTry: function () {
var input = this.game.getInput();
var player = this.game.getPlayer();
var direct_object = input.getAsset(1);
var indirect_object = input.getAsset(2);
var indirect_preposition = input.getPreposition(2);
var results;
var msg = "";
var allow = true;
// parsed sentence structure: verb
if (input.hasStructure("verb")) {
}
// parsed sentence structure: verb noun
if (input.hasStructure("verb noun")) {
} // verb noun
if (!direct_object.isDOV("erase")) {
this.game.debug(
`F1516 | ${this.name}.js | ${direct_object.id}.dov.erase.enabled is false `,
);
msg += `${direct_object.Articlename} can't be erased. `;
this.handleFailure(msg);
return false;
}
if (input.hasStructure("verb noun")) {
// no asset needed
if (direct_object.DOVallowWithNothing(this.name)) {
return true;
}
results = this.tryToInferIndirectObject(direct_object, true);
if (results.prompt) {
this.game.debug(`F1755 | ${this.name}.js | soft prompt for noun2 `);
msg += `What would $(we) like to ${this.name} ${direct_object.articlename} with? `;
this.handleFailure(msg);
return false;
} else if (results.success) {
indirect_object = results.indirect_object;
indirect_preposition = "with";
}
} // verb noun
if (input.hasStructure("verb noun preposition noun")) {
if (direct_object.DOVallowWithNothing(this.name)) {
// it doesn't need a tool
this.game.debug(
`F1515 | ${this.name}.js | ${direct_object.id}.dov.erase.with_nothing `,
);
msg += `$(We) can't ${this.name} ${direct_object.articlename} ${indirect_preposition} ${indirect_object.articlename}. `;
this.handleFailure(msg);
return true;
}
if (!indirect_object.isIOV("erase")) {
this.game.debug(
`F1519 | ${this.name}.js | ${indirect_object.id}.iov.erase.enabled is false `,
);
msg += `${indirect_object.Articlename} can't be used as an eraser. `;
this.handleFailure(msg);
return null;
}
if (!direct_object.DOVAllowWithAsset(this.name, indirect_object)) {
this.game.debug(
`F1517 | ${this.name}.js | neither ${direct_object.id} nor ${indirect_object.id} lists the other in .assets_this_can_${this.name}, .assets_that_can_${this.name}_this, .classes_this_can_${this.name}, .classes_that_can_${this.name}_this `,
);
msg += `$(We) can't ${this.name} ${direct_object.articlename} with ${indirect_object.Articlename}. `;
this.handleFailure(msg);
return null;
}
} // verb noun preposition noun
return true;
},
doSuccess: function () {
var input = this.game.getInput();
var direct_object = input.getAsset(1);
var indirect_object = input.getAsset(2);
var player = this.game.getPlayer();
var msg = "";
var results;
this.game.debug(`F1514 | ${this.name}.js | print doSuccess `);
// parsed sentence structure: verb
if (input.hasStructure("verb")) {
}
// parsed sentence structure: verb noun
if (input.hasStructure("verb noun")) {
} // verb noun
// parsed sentence structure: verb noun preposition noun
if (input.hasStructure("verb noun preposition noun")) {
}
// apply state changes
direct_object.set({ written_strings: [] });
// compose output
msg += `$(We) erase ${direct_object.articlename} with
${
indirect_object
? indirect_object.articlename
: "the flat of $(our) hand"
}. `;
// print output
this.handleSuccess(msg, direct_object);
return true;
},
};
})(); // erase