// locations.js
// OK 09 2023
(function () {
/*global adventurejs A*/
"use strict";
/**
* @augments {adventurejs.Verb}
* @class locations
* @ajsnode game.dictionary.verbs.locations
* @ajsconstruct MyGame.createVerb({ "name": "locations", [...] });
* @ajsconstructedby adventurejs.Dictionary#createVerb
* @hideconstructor
* @ajsinstanceof Verb
* @ajsnavheading UtilityVerbs
* @summary Verb meaning print a list of available locations.
* @tutorial Scripting_VerbSubscriptions
* @tutorial Verbs_VerbAnatomy
* @tutorial Verbs_VerbProcess
* @tutorial Verbs_ModifyVerbs
* @tutorial Verbs_WriteVerbs
* @classdesc
* <pre class="display border outline">
* <span class="input">> locations</span>
* Places you've visited include the
* Leavening Room, the Pity Palace, the Kate Cafe,
* the Umbrella Garden, the Toeholds of the Foothills,
* and the remembered bank of the River Mnemnesia.
* </pre>
* <p>
* <strong>Locations</strong> prints a list of Rooms that
* the player has visited.
* </p>
*/
A.Preverbs.locations = {
name: "locations",
synonyms: ["locations"],
/**
* @ajsverbstructures
* @memberof locations
*/
accepts_structures: ["verb"],
do: function () {
var input = this.game.getInput();
var rooms = [];
for (var i = 0; i < this.game.room_lookup.length; i++) {
var room = this.game.room_lookup[i];
//this.game.print( room );
room = this.game.world[room];
if (room.is.known) {
rooms.push(room);
}
}
if (0 === rooms.length) {
// unlikely
var msg = "$(We) haven't been anywhere. ";
this.handleFailure(msg);
return true;
}
if (0 < rooms.length) {
var msg = "Places $(we've) visited include ";
for (var i = 0; i < rooms.length; i++) {
var room = rooms[i];
if (i > 0 && i < rooms.length - 1) {
msg += ", ";
}
if (rooms.length > 1 && i === rooms.length - 1) {
msg += " and ";
}
msg += room.use_definite_article_in_lists
? room.definite_article + " "
: "";
msg += room.name;
}
msg += ". ";
if (msg) this.game.print(msg, input.output_class);
return true;
}
return true;
},
};
})();