// listRoomContents.js
(function () {
/*global adventurejs A*/
var p = adventurejs.Game.prototype;
/**
*
* @method adventurejs.Game#listCurrentRoomContents
* @memberOf adventurejs.Game
* @param {Object} room
* @returns {String}
*/
p.listRoomContents = function Game_listRoomContents(room) {
this.game.log("L1052", "log", 1, "Game.listRoomContents", "Game");
var roomContentsByID = A.clone.call(this.game, room.getAllContents()); // array of strings
var listableObjects = [];
var objectsWithListableContents = [];
var objectsTiedToOtherThings = [];
var output = "";
// exclude player from list
roomContentsByID.splice(roomContentsByID.indexOf(this.world._player), 1);
// exclude exits from list ?
// TODO needs to check against lighting and visibility
for (i = roomContentsByID.length - 1; i > -1; i--) {
object = this.game.getAsset(roomContentsByID[i]);
//console.log( object );
if (!object) {
this.game.log(
"L1053",
"warn",
"critical",
"listRoomContents found an undefined object in room " +
room.name +
".",
"Game"
);
continue;
}
if (object.is.hidden) {
continue;
}
object.setIs("known", true);
object.setIs("seen", true);
if (object.is.listed_in_room) {
listableObjects.push(object);
}
if (object.hasListableContents()) {
if (object.is.listed_in_room || object.is.unlisted_but_list_children) {
objectsWithListableContents.push(object);
}
}
} // for
// if the list is empty return
if (!listableObjects.length && !objectsWithListableContents.length) {
return false;
}
if (0 < listableObjects.length) {
output += "$(We) can see ";
}
for (var i = 0; i < listableObjects.length; i++) {
var object = listableObjects[i];
if (listableObjects.length > 1 && i === listableObjects.length - 1) {
output += " and ";
}
output += object.indefinite_article;
output += " ";
var name = A.getSAF.call(this, object.name);
/* @TODO
should check for descriptions.exits
before defaulting to name
2023.10.02 - is name a suitable field for getSAF?
*/
if (object.print_bold) name = "<strong>" + name + "</strong>";
if (object.print_italic) name = "<em>" + name + "</em>";
output += name;
if (object.getVerbConnectionCount("tie", "to_iov")) {
objectsTiedToOtherThings.push(object);
output +=
" (tied to " +
this.game.getPrintableObjectList({
objects: object.is.connected_by.tie.to_iov,
}) +
")";
}
if (i === listableObjects.length - 1) {
output += " here. ";
} else {
output += ", ";
}
}
if (objectsWithListableContents.length > 0) {
//console.warn("objectsWithListableContents",objectsWithListableContents);
for (var i = 0; i < objectsWithListableContents.length; i++) {
output += objectsWithListableContents[i].getPrintableListOfContents({
caller: "room",
});
}
}
return output;
};
})();