Template ‐ FURNITURE - ThePix/QuestJS GitHub Wiki
Furniture is anything the player can sit, lie (generally referred to as "recline") or stand on.
The template need to be sent a dictionary, with one or more of "sit", "recline", "stand". This example allows the player (or any NPCs) to sit on it or lie on it.
createItem("settee", FURNITURE({sit:true, recline:true}), {
loc:"dining_room",
examine:"A comfy-looking settee.",
})
By default, USE with furniture defaults to reclining, then sitting if available. Use "useCmd" to modify; for example we might want our settee to default to sitting:
createItem("settee", FURNITURE({sit:true, recline:true, useCmd:"SitOn"}), {
loc:"dining_room",
...
Furniture does not record who is on it; it is done with the characters. The character's "posture" attribute notes his posture, while "postureFurniture" has the furniture he is on. Note that the latter may be undefined
if, say, the player is sitting on the floor. If the player is standing on the floor (i.e., the default state) posture will be undefined
.
Restrictions and reactions
Before furniture is used, its "testPostureOn" will be called; if successful "afterPostureOn" is called. This settee will give a comment if the player (or other character) sits or lies on it.
createItem("settee", FURNITURE({sit:true, recline:true}), {
loc:"dining_room",
examine:"A comfy-looking settee.",
afterPostureOn:function(options) {
if (options.posture === "sitting") {
msg("The chair makes a strange noise when {nv:char:sit} on it.", options)
}
else {
msg("The settee makes a strange noise when {nv:char:lie} on it.", options)
}
},
});
More here.
Other postures
If you want to add further postures, that should be possible, but you would probably be best creating your own template, and extending FURNITURE.
const EXTENDED_FURNITURE = function(options) {
const res = $.extend({}, FURNITURE(options))
if (options.sit) {
res.siton = function(isMultiple, char) {
return this.assumePosture(isMultiple, char, "sitting", 'sit');
};
}
return res
}
You would need to add to the language data (in code.js I suggest), as Quest will try to use lang.sit_on_successful.
lang.sit_on_successful = "{nv:char:sit:true} on {nm:item:the}.",
A Note About Posture
The posture of the player, and NPCs too, is in an attribute called "posture", and is a string set to one of "standing", "sitting" or "reclining". If the player is sitting or reclining on an item of furniture, then the attribute "postureFurniture" will contain the name of the item.