Database Reference
In-Depth Information
id
:
'maze-1'
,
description
:
'a maze of twisty little passages...'
,
exits
:
{
n
:
'maze-2'
,
s
:
'maze-1'
,
e
:
'maze-3'
},
players
:
[
{
id
:
ObjectId
(
'...'
),
name
:
'grue'
},
{
id
:
ObjectId
(
'...'
),
name
:
'Tim'
}
],
inventory
:
[
{
qty
:
1
,
id
:
ObjectId
(
'...'
),
name
:
'scroll of cause fear'
}]
},
gold
:
523
,
armor
:
[
{
id
:
ObjectId
(
'...'
),
region
:
'head'
},
{
id
:
ObjectId
(
'...'
),
region
:
'body'
},
{
id
:
ObjectId
(
'...'
),
region
:
'feet'
}],
weapons
:
[ {
id
:
ObjectId
(
'...'
),
hand
:
'both'
} ],
inventory
:
[
{
qty
:
1
,
id
:
ObjectId
(
'...'
),
name
:
'backpack'
,
inventory
:
[
{
qty
:
4
,
id
:
ObjectId
(
'...'
),
name
:
'potion of healing'
},
{
qty
:
1
,
id
:
ObjectId
(
'...'
),
name
:
'scroll of magic mapping'
},
{
qty
:
2
,
id
:
ObjectId
(
'...'
),
name
:
'c-rations'
} ]},
{
qty
:
1
,
id
:
ObjectId
(
'...'
),
name
:
"wizard's hat"
,
bonus
:
3
},
{
qty
:
1
,
id
:
ObjectId
(
'...'
),
name
:
"wizard's robe"
,
bonus
:
0
},
{
qty
:
1
,
id
:
ObjectId
(
'...'
),
name
:
"old boots"
,
bonus
:
0
},
{
qty
:
1
,
id
:
ObjectId
(
'...'
),
name
:
"quarterstaff"
,
bonus
:
2
} ]
}
There are a few things to note about this document:
▪ Informationaboutthecharacter'slocationinthegameisencapsulatedunderthe
location
attribute. Note in particular that all of the information necessary to describe the room is
encapsulated within the character state document. This allows the game system to render
the room without making a second query to the database to get room information.
▪ The
armor
and
weapons
attributes contain little information about the actual items being
worn or carried. This information is actually stored under the
inventory
property. Since
the inventory information is stored in the same document, there is no need to replicate the
detailed information about each item into the
armor
and
weapons
properties.
▪ The
inventory
contains the item details necessary for rendering each item in the charac-
ter's possession, including any enchantments (
bonus
) and
quantity
. Once again, embed-
ding this data into the character record means we don't have to perform a separate query
to fetch item details necessary for display.