// climb.js
(function () {
/*global adventurejs A*/
/**
* @augments {adventurejs.Verb}
* @class climb
* @ajsnode game.dictionary.verbs.climb
* @ajsconstruct MyGame.createVerb({ "name": "climb", [...] });
* @ajsconstructedby adventurejs.Dictionary#createVerb
* @hideconstructor
* @ajsinstanceof Verb
* @ajsnavheading LocomotionVerbs
* @summary Verb meaning climb, as in "climb tree"; or, travel in specified direction.
* @ajssynonyms climb onto, climb on, climb up
* @tutorial Scripting_VerbSubscriptions
* @tutorial Verbs_VerbAnatomy
* @tutorial Verbs_VerbProcess
* @tutorial Verbs_ModifyVerbs
* @tutorial Verbs_WriteVerbs
* @classdesc
* <pre class="display border outline">
* <span class="input">> climb tree</span>
* You climb a good way into the tree before your climbing
* is interrupted by an angry squirrel. Apparently you've
* put a foot into the knot in which it stores its nuts.
* </pre>
* <p>
* <strong>Climb</strong> can operate with or without
* a noun, inferring from context whether the action can succeed.
* </p>
* @ajsverbreactions doRemoveThisFromThat, doRemoveThatFromThis, doMoveThisToThat, doMoveThatToThis, doNestThatToThis, doNestThisToThat, doUnnestThatFromThis, doUnnestThisFromThat
* @ajsverbphases doBeforeTry, doAfterTry, doBeforeSuccess, doAfterSuccess
*/
A.Preverbs.climb = {
name: "climb",
prettyname: "climb",
past_tense: "climbed",
synonyms: ["climb"],
type: { locomotion: true, travel: true },
extends: { go: true },
gerund: "climbing",
default_direction: "up",
verb_prep_noun: [
// parse climb up / climb down as climb
// to prevent up/down being treated as nouns
//"climb down",
//"climb up",
],
/**
* @ajsadverbs
* @memberof climb
*/
accepts_adverbs: ["left", "right", "around", "back", "towards", "over"],
/**
* @ajsverbstructures
* @memberof climb
*/
accepts_structures: [
"verb", // climb
"verb noun", // climb thing, climb direction
"verb preposition", // climb up
"verb preposition noun", // climb on bed
"verb noun preposition noun", // climb cliff with pick
"verb preposition noun preposition noun", // climb from a to b
// "verb preposition noun preposition noun preposition noun",
],
player_must_be: {
not_on_floor: true,
not_constrained: true,
//not_under: true,
//not_behind: true,
},
/**
* @memberof climb
* @ajsverbphrase
* phrase1:
* {
* accepts_noun: true,
* accepts_preposition: true,
* accepts_direction: true,
* noun_must_be:
* {
* tangible: true,
* known: true,
* present: true,
* visible: true,
* reachable: true,
* not_player: true,
* },
* },
*/
phrase1: {
accepts_noun: true,
noun_must_be: {
tangible: true,
known: true,
present: true,
visible: true,
reachable: true,
not_player: true,
},
accepts_preposition: true,
accepts_preposition_without_noun: true,
accepts_direction: true,
},
/**
* @memberof climb
* @ajsverbphrase
* phrase2:
* {
* accepts_noun: true,
* accepts_preposition: true,
* noun_must_be:
* {
* tangible: true,
* known: true,
* present: true,
* visible: true,
* reachable: true,
* },
* },
*/
phrase2: {
accepts_noun: true,
noun_must_be: {
tangible: true,
known: true,
present: true,
visible: true,
reachable: true,
},
accepts_preposition: true,
accepts_these_prepositions: ["with", "to"],
},
/**
* @memberof climb
* @ajsverbparams
* with_params: {},
*/
with_params: {},
in_can_mean_on: true,
doTry: function () {
var input = this.game.getInput();
var direct_object = input.getAsset(1);
var direct_preposition = input.getPreposition(1);
var player = this.game.getPlayer();
var nest_asset = player.getNestAsset();
var msg = "";
// --------------------------------------------------
// sentence structure: verb
// ex: climb
// --------------------------------------------------
if (input.hasStructure("verb")) {
// if climb was entered without any preposition or object,
// assume up and try to get an object
if (nest_asset) {
// up or down?
let h = nest_asset.dimensions.height;
let y = nest_asset.position.y;
let py = player.position.y;
if (py >= y + h) input.setPreposition(1, "down");
else input.setPreposition(1, "up");
// update input
input.setAsset(1, nest_asset);
input.setStructure("verb preposition noun");
direct_object = input.getAsset(1);
direct_preposition = input.getPreposition(1);
this.game.printInferred(
`${direct_preposition} ${direct_object.articlename}`
);
} else {
// prompt for a direct object
input.setSoftPrompt({
index: 1,
type: "noun",
noun1: true,
});
this.game.debug(
`D1177 | ${this.name}.js | no noun provided or inferrable, soft prompt noun1`
);
msg += `What would $(we) like to climb? `;
this.handleFailure(msg);
return null;
}
} // verb
// --------------------------------------------------
// pass to go
// --------------------------------------------------
return this.game.dictionary.doVerb("go");
},
doSuccess: function () {
return this.handleSuccess();
},
}; // END p.preverbs.push
})();