// lie.js
(function () {
/*global adventurejs A*/
/**
* @augments {adventurejs.Verb}
* @class lie
* @ajsnode game.dictionary.verbs.lie
* @ajsconstruct MyGame.createVerb({ "name": "lie", [...] });
* @ajsconstructedby adventurejs.Dictionary#createVerb
* @hideconstructor
* @ajsinstanceof Verb
* @ajsnavheading PositionVerbs
* @summary Verb meaning lie down 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">> lie down</span>
* You lie down, and let your mind drift. Though you would prefer they
* not, your thoughts turn to the mademoiselle of Mairie Ste Cloud,
* as they so often do. Perhaps you never will forget that
* fateful kiss beneath the statue of Santos Dumont, stolen at
* such great cost and never returned.
* </pre>
* <p>
* <strong>Lie</strong> or more likely <strong>lie down</strong>
* tries to put subject into a lying
* position wherever they happen to be. If subject is not nested in a
* {@link adventurejs.Tangible|Tangible}
* {@link adventurejs.Asset|Asset}, <strong>lie</strong> uses
* the {@link adventurejs.Floor|Floor}. Requires that the
* Asset has an {@link adventurejs.Aspect|Aspect} with its
* player.can.lie
* property set to true.
* </p>
* @ajsverbreactions
* @ajsverbphases doBeforeTry, doAfterTry, doBeforeSuccess, doAfterSuccess
*/
A.Preverbs.lie = {
name: "lie",
prettyname: "lie",
past_tense: "lay",
//synonyms: ["lie down"],
//verb_prep_noun: ["lie down"],
gerund: "laying",
/**
* @ajsverbstructures
* @memberof lie
*/
accepts_structures: [
"verb",
"verb noun",
"verb preposition",
"verb preposition noun",
],
subject_must_be: {
not_constrained: true,
//not_on_floor: true,
//not_nested_elsewhere: true,
},
/**
* @memberof lie
* @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 lie
* @ajsverbparams
* with_params: {},
*/
with_params: {},
in_can_mean_on: true,
doTry: function () {
var input = this.game.getInput();
var subject = input.getSubject();
var verb_phrase = input.verb_phrase;
var direct_object = input.getAsset(1);
var direct_preposition = input.getPreposition(1);
var nest_asset = subject.getNestAsset();
var nest_preposition = subject.getNestPreposition();
var target;
var msg = "";
var results;
//@todo add distinction for "lie to"
// or even contextual clue for just "lie"
// if subject has been conversing
// sentence structure: verb
if (input.hasStructure("verb")) {
// already lying
if (subject.is.lying) {
this.game.debug(`D1010 | ${this.name}.js | subject.is.lying`);
msg += "$(We're) already lying! ";
this.handleFailure(msg);
return null;
}
direct_preposition = subject.getNestOrPlacePreposition();
input.setPreposition(1, direct_preposition);
direct_object = subject.getNestOrPlaceAsset();
input.setStructure("verb preposition noun");
} // verb
// sentence structure: verb preposition
if (input.hasStructure("verb preposition")) {
if (direct_preposition === "down") {
if (subject.is.lying) {
this.game.debug(`D1153 | ${this.name}.js | ${subject.id}.is.lying`);
msg += `$(We) roll over fitfully. `;
this.handleFailure(msg);
return null;
}
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.setInferred(1, true);
input.setStructure("verb preposition noun");
this.game.printInferred(
`${direct_preposition} ${direct_object.articlename}`
);
}
} else {
this.game.debug(
`D1240 | ${this.name}.js | no direct object received or inferred`
);
msg += `$(We) try to ${this.name} ${direct_preposition}, and fail. `;
this.handleFailure(msg);
return null;
}
} // verb preposition
// sentence structure: verb preposition noun
if (input.hasStructure("verb preposition noun")) {
// is subject allowed to lie here?
if (
!subject.can.lie ||
!direct_object.aspects[direct_preposition].canCharacter("lie")
) {
// nested in an object that can't be stood in
this.game.debug(
`D1011 | ${this.name}.js | subject.can.lie is false or ${direct_object.id}.aspects.${direct_preposition}.nest.can.lie is false`
);
msg += `$(We) can't ${this.name} ${direct_preposition} ${direct_object.articlename}. `;
this.handleFailure(msg);
return null;
}
// can subject reach it?
if (nest_asset && nest_asset.id !== direct_object.id) {
results = this.canCharacterGoThereFromNest(
direct_preposition,
direct_object
);
if (results.failure) {
this.handleFailure(results.msg);
return null;
}
if (results.return) return true;
}
// subject 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(
`D1013 | ${this.name}.js | subject is otherwise nested ${nest_preposition} ${nest_asset.id}`
);
msg += `$(We) can't do that from $(our) position ${subject.getPostureGerund()} ${nest_preposition} ${
nest_asset.articlename
}. `;
this.handleFailure(msg);
return null;
}
// subject is already lying [preposition] target
if (subject.is.lying) {
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(
`D1090 | ${this.name}.js | ${subject.id}.is.lying ${direct_preposition} ${direct_object.id}`
);
msg += `$(We're) already lying ${direct_preposition} ${direct_object.articlename}. `;
this.handleFailure(msg);
return null;
}
}
} // verb preposition noun
target = direct_object;
if (target?.placePreventsNesting(subject)) {
this.game.debug(
`D1170 | ${this.name}.js | ${target.id}.is.deep_nest is false `
);
msg += `$(We) can't do that while ${target.articlename_is}
${target.getPrettyPlacePreposition()}
${target.getPlaceAsset().articlename}. `;
this.handleFailure(msg);
return null;
}
return true;
},
doSuccess: function () {
var input = this.game.getInput();
var subject = input.getSubject();
var verb_phrase = input.verb_phrase;
var direct_object = input.getAsset(1);
var direct_preposition = input.getPreposition(1);
var indirect_object = input.getAsset(2);
var nest_asset = subject.getNestAsset();
var nest_preposition = subject.getNestPreposition();
var do_nest, do_unnest;
var fromfloor;
var tofloor;
var results;
var msg = "";
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.log(
"L1360",
"log",
"high",
`${this.name}.js > from floor to floor `,
"verbs"
);
msg += `$(We) ${subject.isOnFloor() ? "shift positions to" : ""} ${
this.name
} 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.log(
"L1361",
"log",
"high",
`${this.name}.js > from floor to asset or change position on asset `,
"verbs"
);
msg += `${
fromfloor && subject.posture !== "stand"
? "$(We) rise from the floor and "
: "$(We) "
} ${this.name} ${direct_preposition} ${direct_object.articlename}. `;
}
// nest_asset to floor - unnest
else if (!fromfloor && tofloor) {
do_unnest = true;
this.game.log(
"L1362",
"log",
"high",
`${this.name}.js > from asset to floor `,
"verbs"
);
msg += `$(We) get ${subject.getPrettyUnnestPreposition()} ${
nest_asset.articlename
} and ${this.name} ${direct_preposition} ${
direct_object.articlename
}. `;
}
// nest_asset to same nest_asset
else if (!fromfloor && !tofloor && direct_object.id === nest_asset.id) {
if (subject.is.lying || subject.is.sitting || subject.is.kneeling) {
this.game.log(
"L1363",
"log",
"high",
`${this.name}.js > change posture on floor `,
"verbs"
);
msg += `$(We) ${this.agree()} ${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.log(
"L1364",
"log",
"high",
`${this.name}.js > move from one asset to another `,
"verbs"
);
msg += `$(We) move over to ${direct_object.articlename} and ${this.name} ${direct_preposition} it. `;
}
if (do_unnest && nest_asset) {
results = subject.onUnnestThisFromThat(nest_asset);
if ("undefined" !== typeof results) return results;
}
if (do_nest && direct_object) {
results = subject.onNestThisToThat(direct_object, direct_preposition);
if ("undefined" !== typeof results) return results;
}
subject.posture = this.name;
// print output
return this.handleSuccess(msg, direct_object);
},
}; // END p.preverbs.push
})();