// stand.js
(function () {
/*global adventurejs A*/
"use strict";
/**
* @augments {adventurejs.Verb}
* @class stand
* @ajsnode game.dictionary.verbs.stand
* @ajsconstruct MyGame.createVerb({ "name": "stand", [...] });
* @ajsconstructedby adventurejs.Dictionary#createVerb
* @hideconstructor
* @ajsinstanceof Verb
* @ajsnavheading PositionVerbs
* @summary Verb meaning stand, as in "stand up" or "stand on trap door".
* @tutorial Scripting_VerbSubscriptions
* @tutorial Verbs_VerbAnatomy
* @tutorial Verbs_VerbProcess
* @tutorial Verbs_ModifyVerbs
* @tutorial Verbs_WriteVerbs
* @classdesc
* <pre class="display border outline">
* <span class="input">> stand in pentagram</span>
* You stand in the pentagram. Eldritch energies
* flicker and rise from the chalked symbol, protecting
* you or trapping you inside, you're not sure which.
* </pre>
* <p>
* <strong>Stand in</strong> requires that the
* {@link adventurejs.Tangible|Tangible}
* {@link adventurejs.Asset|Asset} has an <strong>in</strong>
* {@link adventurejs.Aspect|Aspect}
* and that its
* aspect.player.can.stand
* property is set to true.
* If player is already in the Asset, player will move to
* a standing position.
* See
* <a href="/doc/Tangibles_Aspects.html">How to Use Aspects</a>
* to learn more.
* </p>
* @ajsverbreactions
* @ajsverbphases doBeforeTry, doAfterTry, doBeforeSuccess, doAfterSuccess
*/
A.Preverbs.stand = {
name: "stand",
prettyname: "stand",
past_tense: "stood",
synonyms: ["stand"],
// verb_prep_noun: ["stand up", "get up", "stand down"],
/**
* @ajsverbstructures
* @memberof stand
*/
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 stand
* @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,
* },
*/
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,
accepts_preposition_without_noun: true,
requires_preposition: true,
},
/**
* @memberof stand
* @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 current_room = this.game.getCurrentRoom();
var msg = "";
var results;
// sentence structure: verb
if (input.hasStructure("verb")) {
// already standing
if (player.is.standing) {
this.game.debug(`F1099 | ${this.name}.js | ${player.id}.is.standing`);
msg += `$(We're) already standing! `;
this.handleFailure(msg);
return null;
}
if (nest_asset && !nest_asset.quirks.stand_means_get_off) {
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");
}
// sentence structure: verb preposition
if (input.hasStructure("verb preposition")) {
// player input "stand down"
if (direct_preposition === "down") {
this.game.debug(
`F1023 | ${this.name}.js | no response for idiom 'stand down'`
);
msg += `YES, SIR! `;
this.handleFailure(msg);
return null;
}
if (direct_preposition !== "up") {
this.game.debug(
`F1096 | ${this.name}.js | no response for idiom 'stand down'`
);
msg += `$(We) don't know how to stand ${direct_preposition}. `;
this.handleFailure(msg);
return null;
}
// already standing
if (player.is.standing) {
this.game.debug(`F1024 | ${this.name}.js | player.is.standing`);
msg += `$(We're) already standing! `;
this.handleFailure(msg);
return null;
}
} // verb preposition
// sentence structure: verb preposition
if (
input.hasStructure("verb") ||
input.hasStructure("verb preposition")
) {
// player input "stand" or "stand up"
if (
nest_asset &&
(nest_asset.quirks.stand_means_get_off ||
("get" === input.input_verb &&
nest_asset.quirks.get_up_means_get_off))
) {
// if quirks.stand_means_get_off, go straight to doSuccess
// return true;
direct_object = this.game.getCurrentRoomFloor();
direct_preposition = "on";
} else 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";
}
// we should now be able to assume a direct object
if (direct_object) {
input.setAsset(1, direct_object);
input.setPreposition(1, direct_preposition);
input.setAssumed(1, true);
input.setStructure("verb preposition noun");
}
} // verb || verb preposition
// sentence structure: verb preposition noun
if (input.hasStructure("verb preposition noun")) {
// is player allowed to stand here?
if (
!player.can.stand ||
!direct_object.aspects[direct_preposition].player.can.stand
) {
this.game.debug(
`F1025 | ${this.name}.js | player.can.stand is false or ${direct_object.id}.aspects.${direct_preposition} }.player.can.stand is false`
);
msg += `$(We) can't stand ${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;
this.game.dictionary.doVerb("go");
return null;
}
// if (results.return) return true;
}
// player is nested some other way with target
// and needs to unnest first
if (
nest_asset &&
nest_asset.id === direct_object.id &&
nest_preposition !== direct_preposition
) {
this.game.debug(
`F1028 | ${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;
}
// player is already standing [preposition] target
if (player.is.standing) {
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(
`F1029 | ${this.name}.js | player.is.standing ${direct_preposition} ${direct_object.id} `
);
msg += `$(We're) already standing ${direct_preposition} ${direct_object.articlename}. `;
this.handleFailure(msg);
return null;
}
}
}
return true;
},
doSuccess: function () {
var input = this.game.getInput();
var player = this.game.getPlayer();
var direct_object = input.getAsset(1);
var direct_preposition = input.getPreposition(1);
var indirect_object = input.getAsset(2);
var indirect_preposition = input.getPreposition(2);
var nest_asset = player.getNestAsset();
var nest_preposition = player.getNestPreposition();
var do_nest, do_unnest;
var fromfloor;
var tofloor;
var results;
var msg = "";
this.game.debug(`F1415 | ${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_unnest = true;
this.game.debug(`F1026 | ${this.name}.js | from floor to floor `);
msg += `$(We) clamber up to a standing position. `;
}
// floor to nest or change positions on nest
else if (
(fromfloor && !tofloor) ||
(nest_asset && nest_asset.id === direct_object.id)
) {
do_unnest = nest_asset && nest_asset.id !== direct_object.id;
do_nest = fromfloor && !tofloor;
this.game.debug(
`F1617 | ${this.name}.js | from floor to asset or change position on asset `
);
msg += `$(We) climb to a standing position ${direct_preposition} ${direct_object.articlename}. `;
}
// nest_asset to floor - unnest
else if (!fromfloor && tofloor) {
do_unnest = true;
this.game.debug(`F1618 | ${this.name}.js | from asset to floor `);
msg += `$(We) hop ${player.getPrettyUnnestPreposition()} ${
nest_asset.articlename
} and stand ${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.kneeling) {
this.game.debug(`F1619 | ${this.name}.js | change posture on floor `);
msg += `$(We) stand up ${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(
`F1620 | ${this.name}.js | move from one asset to another `
);
msg += `$(We) climb over to ${direct_object.articlename} and stand ${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 = "stand";
// print output
this.handleSuccess(msg, direct_object);
return true;
},
};
})(); // stand