// exit.js
// OK 09 2023
(function () {
/*global adventurejs A*/
"use strict";
/**
* @augments {adventurejs.Verb}
* @class exit
* @ajsnode game.dictionary.verbs.exit
* @ajsconstruct MyGame.createVerb({ "name": "exit", [...] });
* @ajsconstructedby adventurejs.Dictionary#createVerb
* @hideconstructor
* @ajsinstanceof Verb
* @ajsnavheading DirectionVerbs
* @summary Verb meaning exit an asset, or travel out.
* @ajssynonyms exit, leave, out
* @tutorial Scripting_VerbSubscriptions
* @tutorial Verbs_VerbAnatomy
* @tutorial Verbs_VerbProcess
* @tutorial Verbs_ModifyVerbs
* @tutorial Verbs_WriteVerbs
* @classdesc
* <pre class="display border outline">
* <span class="input">> exit</span>
* You exit through the revolving door and wind up right back
* where you started, in the path of your pursuers' guns.
* </pre>
* <p>
* Direction verb: <strong>exit</strong> whatever player is in.
* To learn about {@link adventurejs.Exit|Exits},
* see <a href="/doc/GetStarted_CreateAnExit.html">Create an Exit</a>.
* </p>
* @ajsverbphases doBeforeTry, doAfterTry, doBeforeSuccess, doAfterSuccess
*/
A.Preverbs.exit = {
name: "exit",
past_tense: "exited",
is_direction: true,
synonyms: ["exit", "leave", "out"],
//verb_prep_noun: [ "go out", "get out" ],
type: { direction: true },
/**
* @ajsverbstructures
* @memberof exit
*/
accepts_structures: ["verb", "verb noun"],
/**
* @memberof exit
* @ajsverbphrase
* phrase1:
* {
* accepts_noun:true,
* noun_must_be:
* {
* player_parent: true,
* },
* },
*/
phrase1: {
accepts_noun: true,
noun_must_be: {
player_parent: true,
},
},
/**
* @memberof exit
* @ajsverbparams
* with_params: {},
*/
with_params: {},
doTry: function () {
var input = this.game.getInput();
var player = this.game.getPlayer();
var currentRoom = this.game.getCurrentRoom();
var nest_asset = player.getNestAsset();
var nest_preposition = player.getNestPreposition();
var unnest_preposition = player.getUnnestPreposition();
var direct_object = input.getAsset(1);
var msg = "";
if (direct_object) {
if (nest_asset) {
if (nest_asset.id === direct_object.id) {
this.game.debug(
`F1277 | ${this.name}.js | infer go ${unnest_preposition}`
);
input.setPreposition(1, unnest_preposition);
input.setStructure("verb preposition noun");
this.game.dictionary.doVerb("go");
return null;
}
if (nest_asset.id !== direct_object.id) {
this.game.debug(
`F1220 | ${this.name}.js | player is ${nest_preposition} ${nest_asset.id}, not ${direct_object.id}`
);
msg += `$(We) can't exit
${direct_object.articlename}
from $(our) position
${nest_preposition}
${nest_asset.articlename}. `;
this.handleFailure(msg);
return null;
}
}
if (!nest_asset) {
if (direct_object.id === currentRoom.id) {
this.game.debug(`F1276 | ${this.name}.js | tryTravel exit`);
this.game.tryTravel(this.name);
return null;
}
}
}
if (!direct_object) {
if (nest_asset) {
input.setAsset(1, nest_asset);
input.setPreposition(1, unnest_preposition);
input.setStructure("verb preposition noun");
this.game.debug(
`F1278 | ${this.name}.js | infer go ${unnest_preposition}`
);
this.game.dictionary.doVerb("go");
return null;
} else {
this.game.tryTravel(this.name);
return null;
}
}
return true;
},
doSuccess: function () {
return true;
},
};
})();