// jumpOn.js
(function () {
/*global adventurejs A*/
"use strict";
/**
* @augments {adventurejs.Verb}
* @class jumpOn
* @ajsnode game.dictionary.verbs.jumpOn
* @ajsconstruct MyGame.createVerb({ "name": "jumpOn", [...] });
* @ajsconstructedby adventurejs.Dictionary#createVerb
* @hideconstructor
* @ajsinstanceof Verb
* @ajsnavheading DeprecatedVerbs
* @summary Summary.
* @ajssynonyms hop on, jump on, jump onto
* @tutorial Scripting_VerbSubscriptions
* @tutorial Verbs_VerbAnatomy
* @tutorial Verbs_VerbProcess
* @tutorial Verbs_ModifyVerbs
* @tutorial Verbs_WriteVerbs
* @classdesc
* <pre class="display border outline">
* <span class="input">> jump on pedestal</span>
* You jump on to the floating crystal pedestal. It rises slowly
* into the air, carrying you toward the top of the tall fluted chamber.
* </pre>
* <p>
* <strong>Jump on</strong> requires that the
* {@link adventurejs.Tangible|Tangible}
* {@link adventurejs.Asset|Asset} has an <strong>on</strong>
* {@link adventurejs.Aspect|Aspect}.
* See
* <a href="/doc/Tangibles_Aspects.html">How to Use Aspects</a>
* to learn more.
* </p>
*/
A.Preverbs.jumpOn = {
name: "jumpOn",
prettyname: "jump on",
synonyms: [],
verb_prep_noun: ["hop on", "jump on"],
player_must_be: {
not_constrained: true,
not_on_floor: true,
not_nested_elsewhere: true,
},
phrase1: {
accepts_noun: true,
requires_noun: true,
noun_must_be: {
known: true,
tangible: true,
present: true,
visible: true,
reachable: true,
},
},
doTry: function () {
var input = this.game.getInput();
var direct_object = input.getAsset(1);
var player = this.game.getPlayer();
var nest_preposition = player.getNestPreposition();
var nest_parent_id = player.getNestId();
var nest_parent_object = player.getNestAsset();
// TODO:
// is object an exit? eg "jump on stage"
// for now just redirect to the exit
// this might need to be revisited
if (
direct_object instanceof adventurejs.Exit ||
direct_object instanceof adventurejs.Aperture
) {
this.game.dictionary.doVerb(direct_object.direction);
return null;
}
// player is already in/on target
if (
direct_object.id === nest_parent_id &&
("on" === nest_preposition ||
(direct_object.quirks.in_means_on && "in" === nest_preposition))
) {
// var msg = "$(We're) already "
// + nest_preposition
// + " "
// + direct_object.articlename
// + ". ";
var msg =
"$(We) jump up and down a bit " +
nest_preposition +
" " +
direct_object.articlename +
". ";
this.handleFailure(msg);
return null;
}
// player is nested some other way with target
// and needs to unnest first
if (
direct_object.id === nest_parent_id &&
((false === direct_object.quirks.in_means_on &&
"on" !== nest_preposition) ||
(direct_object.quirks.in_means_on &&
"on" !== nest_preposition &&
"in" !== nest_preposition))
) {
var msg =
"$(We) can't do that from $(our) position " +
player.getPostureGerund() +
" " +
nest_preposition +
" " +
nest_parent_object.articlename +
". ";
this.handleFailure(msg);
return null;
}
// player can't nest in/on object at all
if (
(false === direct_object.quirks.in_means_on &&
false === direct_object.can.jump_on) ||
(direct_object.quirks.in_mean._on &&
false === direct_object.can.jump_on &&
false === direct_object.can.jump_in)
) {
var msg = "$(We) can't get on " + direct_object.articlename + ". ";
this.handleFailure(msg);
return null;
}
return true;
},
doSuccess: function () {
var input = this.game.getInput();
var direct_object = input.getAsset(1);
var player = this.game.getPlayer();
var results;
// If direct_object is an exit/aperture, we already shunted to "enter".
/**
* We check default_aspect_for_go_on
* and default_posture_for_go_on for context.
*/
var posture = direct_object.default_posture_for_go_on;
var preposition = direct_object.default_aspect_for_go_on;
var msg = "";
if (direct_object.is.climbable) {
msg += "$(Our) start y is " + player.position.y + ". ";
}
msg +=
"$(We) jump up and " +
posture +
" " +
preposition +
" " +
direct_object.articlename +
". ";
// DO THE THING!
results = player.onNestThisToThat(direct_object, preposition);
if ("undefined" !== typeof results) return results;
player.posture = posture;
if (direct_object.is.climbable) {
player.position.y++;
msg += "$(Our) end y is " + player.position.y + ". ";
}
this.handleSuccess(msg, direct_object);
return true;
},
};
})(); // jumpOn