// printPlayerInventory.js
(function () {
/*global adventurejs A*/
var p = adventurejs.Game.prototype;
/**
*
* @method adventurejs.Game#printPlayerInventory
* @memberOf adventurejs.Game
*/
p.printPlayerInventory = function Game_printPlayerInventory() {
//this.print( this.world[this.world._player].getPrintableListOfContentsAt("in") );
var player = this.game.getPlayer();
var nest_preposition = player.getNestPreposition();
var nest_parent_id = player.getNestId();
var nest_parent_object = player.getNestAsset();
var output = "";
var carried = [];
var openCarried = [];
var worn = [];
var riding = [];
var holding = [];
var carriedtied = [];
var holdingtied = [];
var handsempty = true;
var contents = player.aspects.in.contents;
var holding = player.getVerbConnections("hold", "to_dov");
if (0 === contents.length) {
output += "$(We're) not carrying anything. ";
}
for (var i = 0; i < contents.length; i++) {
// list worn, ridden, and carried objects separately
// worn
if (this.game.getAsset(contents[i]).is.worn) {
worn.push(contents[i]);
}
// ridden
else if (
this.game.getAsset(contents[i]).isDOV("ride") &&
contents[i] === nest_parent_id
) {
riding.push(contents[i]);
}
// carried
else {
carried.push(contents[i]);
}
}
// it shouldn't be possible to ride more than one thing
// but we're gonna cover the bases
if (0 < riding.length) {
for (var i = 0; i < riding.length; i++) {
var object = this.game.getAsset(riding[i]);
output +=
"$(We're) " +
player.getPostureGerund() +
" " +
nest_preposition +
" " +
object.articlename +
". ";
}
}
if (0 < carried.length) {
handsempty = false;
output += "$(We're) carrying ";
for (var i = 0; i < carried.length; i++) {
var object = this.game.getAsset(carried[i]);
if (
object.hasAspectAt("in") &&
object.aspects.in.contents.length > 0 &&
false === object.is.closed
) {
openCarried.push(object.id);
}
if (object.getVerbConnectionCount("tie", "to_iov")) {
carriedtied.push(object.id);
}
}
output += this.game.getPrintableObjectList({ objects: carried });
output += ". ";
}
if (0 < carriedtied.length) {
for (var i = 0; i < carriedtied.length; i++) {
var object = this.game.getAsset(carriedtied[i]);
output += object.Articlename + " $(we're) carrying is tied to ";
output += this.game.getPrintableObjectList({
objects: object.is.connected_by.tie.to_dov,
article: "definite",
});
output += ". ";
}
}
if (0 < holding.length) {
for (var i = 0; i < holding.length; i++) {
var object = this.game.getAsset(holding[i]);
if (object.getVerbConnectionCount("tie", "to_iov") > 0) {
holdingtied.push(object.id);
}
}
handsempty = false;
output += "$(We're) holding ";
output += this.game.getPrintableObjectList({
objects: holding,
});
output += ". ";
}
if (0 < holdingtied.length) {
for (var i = 0; i < holdingtied.length; i++) {
var object = this.game.getAsset(holdingtied[i]);
output += object.Articlename + " $(we're) holding is tied to ";
output += this.game.getPrintableObjectList({
objects: object.is.connected_by.tie.to_iov,
article: "definite",
});
output += ". ";
}
}
if (handsempty) {
output += "$(Our) hands are empty. ";
}
if (openCarried.length > 0) {
for (var i = 0; i < openCarried.length; i++) {
var object = this.game.getAsset(openCarried[i]);
output += object.Articlename + " $(we're) carrying contains ";
output += this.game.getPrintableObjectList({
objects: object.aspects.in.contents,
});
output += ". ";
}
}
if (worn.length > 0) {
output += "$(We're) wearing ";
for (var i = 0; i < worn.length; i++) {
var object = this.game.getAsset(worn[i]);
object.setIs("known", true);
object.setIs("seen", true);
if (worn.length > 1 && i === worn.length - 1) {
output += " and ";
}
output += object.indefinite_article;
output += " ";
output += object.name;
if (object.is.closed) {
output += ", which is closed";
}
if (
object.isDOV("close") &&
object.hasAspectAt("in") &&
object.aspects.in.contents.length > 0
) {
output += ", which contains ";
output += this.game.getPrintableObjectList({
objects: object.aspects.in.contents,
});
}
if (i === worn.length - 1) {
output += ". ";
}
if (i !== worn.length - 1 && worn.length > 2) {
output += ", ";
}
}
}
//"In the x you see..."
//"You're wearing..."
//"In the x you see..."
this.print(output);
return;
};
})();