// kneel.js
(function () {
/*global adventurejs A*/
"use strict";
/**
* @augments {adventurejs.Verb}
* @class kneel
* @ajsnode game.dictionary.verbs.kneel
* @ajsconstruct MyGame.createVerb({ "name": "kneel", [...] });
* @ajsconstructedby adventurejs.Dictionary#createVerb
* @hideconstructor
* @ajsinstanceof Verb
* @ajsnavheading PositionVerbs
* @summary Verb meaning kneel in place, or on 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">> kneel</span>
* You kneel on the floor.
* </pre>
* <p>
* If input without an object,
* <strong>kneel</strong> tries to put player into a kneeling
* position wherever they happen to be. If player is not nested in a
* {@link adventurejs.Tangible|Tangible}
* {@link adventurejs.Asset|Asset}, <strong>kneel</strong> uses
* the {@link adventurejs.Floor|Floor}. Requires that the
* Asset has an
* {@link adventurejs.Aspect|Aspect} with its
* aspect.player.can.kneel</a>
* property set to true.
* </p>
* @ajsverbreactions
* @ajsverbphases doBeforeTry, doAfterTry, doBeforeSuccess, doAfterSuccess
*/
A.Preverbs.kneel = {
name: "kneel",
prettyname: "kneel",
past_tense: "knelt",
//synonyms: ["kneel down"] /* @todo take direction / preposition */,
//verb_prep_noun: ["kneel down"],
/**
* @ajsverbstructures
* @memberof lie
*/
accepts_structures: [
"verb",
"verb noun",
"verb preposition",
"verb preposition noun",
],
player_must_be: {
not_constrained: true,
//not_on_floor: true,
//not_nested_elsewhere: true,
},
/**
* @memberof kneel
* @ajsverbphrase
* phrase1:
* {
* accepts_noun:true,
* noun_must_be:
* {
* known: true,
* tangible: true,
* present: true,
* visible: true,
* reachable: true,
* not_direction: true,
* not_in_inventory: true,
* },
* accepts_preposition: true,
* requires_preposition: true,
* // accepts_these_prepositions: ["on"],
* },
*/
phrase1: {
accepts_noun: true,
noun_must_be: {
known: true,
tangible: true,
present: true,
visible: true,
reachable: true,
not_direction: true,
not_in_inventory: true,
},
accepts_preposition: true,
requires_preposition: true,
},
/**
* @memberof kneel
* @ajsverbparams
* with_params: {},
*/
with_params: {},
in_can_mean_on: true,
doTry: function () {
var input = this.game.getInput();
var player = this.game.getPlayer();
var direct_object = input.getAsset(1);
var direct_preposition = input.getPreposition(1);
var nest_asset = player.getNestAsset();
var nest_preposition = player.getNestPreposition();
var msg = "";
var results;
// sentence structure: verb
if (input.hasStructure("verb")) {
// is player already kneeling?
if (player.is.kneeling) {
this.game.debug(
`F1326 | ${this.name}.js | ${player.id}.is.kneeling `,
);
msg += `$(We're) already kneeling! `;
this.handleFailure(msg);
return null;
}
if (nest_asset) {
direct_preposition = player.getNestOrPlacePreposition();
direct_object = nest_asset;
} else {
direct_preposition = "on";
direct_object = this.game.getCurrentRoomFloor();
}
input.setAsset(1, direct_object);
input.setPreposition(1, direct_preposition);
input.setStructure("verb preposition noun");
} // verb
// sentence structure: verb preposition
if (input.hasStructure("verb preposition")) {
if (direct_preposition === "down") {
if (player.is.kneeling) {
this.game.debug(
`F1088 | ${this.name}.js | ${player.id}.is.kneeling`,
);
msg += `$(We) shift weight from knee to knee. `;
this.handleFailure(msg);
return null;
}
// kneel down is still an option but we need a direct object
if (nest_asset) {
direct_object = nest_asset;
direct_preposition = nest_preposition;
} else {
// see if the room has its own floor
direct_object = this.game.getCurrentRoomFloor();
direct_preposition = "on";
}
if (direct_object) {
input.setAsset(1, direct_object);
input.setPreposition(1, direct_preposition);
input.setAssumed(1, true);
input.setStructure("verb preposition noun");
}
} else {
this.game.debug(
`F1021 | ${this.name}.js | no direct object received or inferred`,
);
msg += `$(We) try to kneel ${direct_preposition}, and fail. `;
this.handleFailure(msg);
return null;
}
} // verb preposition
// sentence structure: verb preposition noun
if (input.hasStructure("verb preposition noun")) {
// is player allowed to kneel here?
if (
!player.can.kneel ||
!direct_object.aspects[direct_preposition].player.can.kneel
) {
// nested in an object that can't be kneeled in
this.game.debug(
`F1327 | ${this.name}.js | player.can.kneel is false or ${direct_object.id}.aspects.${direct_preposition} }.player.can.kneel is false`,
);
msg += `$(We) can't kneel ${direct_preposition} ${direct_object.articlename}. `;
this.handleFailure(msg);
return null;
}
// can player reach it?
if (nest_asset && nest_asset.id !== direct_object.id) {
results = this.canPlayerGoThereFromNest(
direct_preposition,
direct_object,
);
if (results.failure) {
this.handleFailure(results.msg);
return null;
}
if (results.return) return true;
}
// player is nested some other way with target
// and needs to get up first
if (
nest_asset &&
nest_asset.id === direct_object.id &&
nest_preposition !== direct_preposition
) {
this.game.debug(
`F1614 | ${this.name}.js | player is otherwise nested ${nest_preposition} ${nest_asset.id} `,
);
msg += `$(We) can't do that from $(our) position ${player.getPostureGerund()} ${nest_preposition} ${
nest_asset.articlename
}. `;
this.handleFailure(msg);
return null;
}
if (player.is.kneeling) {
var already_on_it;
if (
nest_asset &&
nest_asset.id === direct_object.id &&
nest_preposition === direct_preposition
)
already_on_it = true;
if (!nest_asset && direct_object instanceof adventurejs.Floor)
already_on_it = true;
if (already_on_it) {
this.game.debug(
`F1613 | ${this.name}.js | ${player.id}.is.kneeling ${direct_preposition} ${direct_object.id} `,
);
msg += `$(We're) already kneeling ${direct_preposition} ${direct_object.articlename}. `;
this.handleFailure(msg);
return null;
}
}
} // verb preposition 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 player = this.game.getPlayer();
var nest_asset = player.getNestAsset();
var nest_preposition = player.getNestPreposition();
var do_nest, do_unnest;
var fromfloor;
var tofloor;
var results;
var msg = "";
// DO THE THING!
this.game.debug(`F1328 | ${this.name}.js | print doSuccess `);
tofloor = direct_object instanceof adventurejs.Floor;
fromfloor = !nest_asset || nest_asset instanceof adventurejs.Floor;
// floor to floor
if (fromfloor && tofloor) {
do_nest = true;
this.game.debug(`F1621 | ${this.name}.js | from floor to floor `);
msg += `$(We) ${
player.isOnFloor() ? "shift positions to" : ""
} kneel on the floor. `;
}
// floor to nest or change positions on nest
else if (
(fromfloor && !tofloor) ||
(nest_asset && nest_asset.id === direct_object.id)
) {
do_nest = fromfloor && !tofloor;
this.game.debug(
`F1622 | ${this.name}.js | from floor to asset or change position on asset `,
);
msg += `$(We) climb to a kneeling position ${direct_preposition} ${direct_object.articlename}. `;
}
// nest_asset to floor - unnest
else if (!fromfloor && tofloor) {
do_unnest = true;
this.game.debug(`F1623 | ${this.name}.js | from asset to floor `);
msg += `$(We) hop ${player.getPrettyUnnestPreposition()} ${
nest_asset.articlename
} and kneel ${direct_preposition} ${direct_object.articlename}. `;
}
// nest_asset to same nest_asset
else if (!fromfloor && !tofloor && direct_object.id === nest_asset.id) {
if (player.is.lying || player.is.sitting || player.is.standing) {
this.game.debug(`F1624 | ${this.name}.js | change posture on floor `);
msg += `$(We) kneel ${nest_preposition} ${direct_object.articlename}. `;
}
}
// nest_asset to other nest_asset
else if (!fromfloor && !tofloor && direct_object.id !== nest_asset.id) {
do_nest = true;
do_unnest = true;
this.game.debug(
`F1625 | ${this.name}.js | move from one asset to another `,
);
msg += `$(We) climb over to ${direct_object.articlename} and kneel ${direct_preposition} it. `;
}
if (do_unnest && nest_asset) {
results = player.onUnnestThisFromThat(nest_asset);
if ("undefined" !== typeof results) return results;
}
if (do_nest && direct_object) {
results = player.onNestThisToThat(direct_object, direct_preposition);
if ("undefined" !== typeof results) return results;
}
player.posture = "kneel";
// print output
this.handleSuccess(msg, direct_object);
return true;
},
}; // END p.preverbs.push
})();