// sit.js
(function () {
/*global adventurejs A*/
"use strict";
/**
* @augments {adventurejs.Verb}
* @class sit
* @ajsnode game.dictionary.verbs.sit
* @ajsconstruct MyGame.createVerb({ "name": "sit", [...] });
* @ajsconstructedby adventurejs.Dictionary#createVerb
* @hideconstructor
* @ajsinstanceof Verb
* @ajsnavheading PositionVerbs
* @summary Verb meaning sit, as in "sit on throne".
* @tutorial Scripting_VerbSubscriptions
* @tutorial Verbs_VerbAnatomy
* @tutorial Verbs_VerbProcess
* @tutorial Verbs_ModifyVerbs
* @tutorial Verbs_WriteVerbs
* @classdesc
* <pre class="display border outline">
* <span class="input">> sit</span>
* You sit on the floor.
* </pre>
* <p>
* If input without an object, <strong>Sit</strong> tries to
* put player into a sitting position wherever they happen to be.
* If player is not nested in a
* {@link adventurejs.Tangible|Tangible}
* {@link adventurejs.Asset|Asset}, <strong>Sit</strong> uses
* the {@link adventurejs.Floor|Floor}. Requires that the target
* Asset has an aspect with its
* aspect.player.can.sit
* property set to true.
* </p>
* @ajsverbreactions
* @ajsverbphases doBeforeTry, doAfterTry, doBeforeSuccess, doAfterSuccess
*/
A.Preverbs.sit = {
name: "sit",
prettyname: "sit",
past_tense: "sat",
synonyms: ["sit"],
//verb_prep_noun: ["sit down", "sit up"],
/**
* @ajsverbstructures
* @memberof sit
*/
accepts_structures: [
"verb",
"verb noun",
"verb preposition",
"verb preposition noun",
],
/**
* @memberof sit
* @ajsverbphrase
* phrase1:
* {
* accepts_noun:true,
* noun_must_be:
* {
* known: true,
* tangible: true,
* present: true,
* visible: true,
* reachable: true,
* not_direction: 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,
},
accepts_preposition: true,
accepts_preposition_without_noun: true,
requires_preposition: true,
},
/**
* @memberof sit
* @ajsverbparams
* with_params: {},
*/
with_params: {},
in_can_mean_on: true,
doTry: function () {
var input = this.game.getInput();
var player = this.game.getPlayer();
var nest_preposition = player.getNestPreposition();
var nest_asset = player.getNestAsset();
var direct_object = input.getAsset(1);
var direct_preposition = input.getPreposition(1);
var current_room = this.game.getCurrentRoom();
var msg = "";
var results;
// sentence structure: verb
if (input.hasStructure("verb")) {
// already sitting
if (player.is.sitting) {
this.game.debug(`F1019 | ${this.name}.js | ${player.id}.is.sitting`);
msg += `$(We're) already sitting! `;
this.handleFailure(msg);
return null;
}
direct_preposition = player.getNestOrPlacePreposition();
input.setPreposition(1, direct_preposition);
direct_object = player.getNestOrPlaceAsset();
input.setStructure("verb preposition noun");
} // verb
// sentence structure: verb preposition
if (input.hasStructure("verb preposition")) {
if (direct_preposition === "up") {
if (player.is.sitting) {
this.game.debug(`F1097 | ${this.name}.js | 'sit up'`);
msg += `$(We) sit up a bit straighter. `;
this.handleFailure(msg);
return null;
}
if (!player.is.lying) {
this.game.debug(`F1446 | ${this.name}.js | 'sit up'`);
msg += `$(We) can't sit up while $(we're) ${player.getPostureGerund()}. `;
this.handleFailure(msg);
return null;
}
} else if (direct_preposition === "down") {
if (player.is.sitting) {
this.game.debug(
`F1098 | ${this.name}.js | ${player.id}.is.sitting`
);
msg += `$(We) slouch down a bit lower. `;
this.handleFailure(msg);
return null;
}
} else {
this.game.debug(
`F1098 | ${this.name}.js | no direct object received or inferred`
);
msg += `$(We) try to sit ${direct_preposition}, and fail. `;
this.handleFailure(msg);
return null;
}
// sit 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");
}
} // verb preposition
// sentence structure: verb preposition noun
if (input.hasStructure("verb preposition noun")) {
// is player allowed to sit here?
if (
!player.can.sit ||
!direct_object.aspects[direct_preposition].player.can.sit
) {
this.game.debug(
`F1087 | ${this.name}.js | player.can.sit is false or ${direct_object.id}.aspects.${direct_preposition} }.player.can.sit is false`
);
msg += `$(We) can't sit ${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 unnest first
if (
nest_asset &&
nest_asset.id === direct_object.id &&
nest_preposition !== direct_preposition
) {
this.game.debug(
`F1022 | ${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 sitting [preposition] target
if (player.is.sitting) {
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(
`F1089 | ${this.name}.js | player.is.sitting ${direct_preposition} ${direct_object.id}`
);
msg += `$(We're) already sitting ${direct_preposition} ${direct_object.articlename}. `;
this.handleFailure(msg);
return null;
}
}
} // verb preposition noun
return true;
},
doSuccess: function () {
var input = this.game.getInput();
var player = this.game.getPlayer();
var nest_preposition = player.getNestPreposition();
var nest_asset = player.getNestAsset();
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 do_nest, do_unnest;
var fromfloor;
var tofloor;
var results;
var msg = "";
this.game.debug(`F1632 | ${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(`F1633 | ${this.name}.js | from floor to floor `);
msg += `$(We) sit ${player.is.lying ? "up" : "down"} 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(
`F1634 | ${this.name}.js | from floor to asset or change position on asset `
);
msg += `$(We) sit ${direct_preposition} ${direct_object.articlename}. `;
}
// nest_asset to floor - unnest
else if (!fromfloor && tofloor) {
do_unnest = true;
this.game.debug(`F1635 | ${this.name}.js | from asset to floor `);
msg += `$(We) hop ${player.getPrettyUnnestPreposition()} ${
nest_asset.articlename
} and sit ${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(`F1636 | ${this.name}.js | change posture on floor `);
msg += `$(We) sit down ${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(
`F1637 | ${this.name}.js | move from one asset to another `
);
msg += `$(We) climb over to ${direct_object.articlename} and sit down ${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 = "sit";
// print output
this.handleSuccess(msg, direct_object);
return true;
},
};
})(); // sit