Database Reference
In-Depth Information
Item Schema
Likewise, the item schema should include all details about all items globally in the game:
{
_id
:
ObjectId
(
'...'
),
name
:
'backpack'
,
bonus
:
null
null
,
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'
} ]},
weight
:
12
,
price
:
160
,
...
}
Note that this document contains more or less the same information as stored in the
invent-
ory
attribute of
character
documents, as well as additional data that may only be needed
sporadically in the case of gameplay such as
weight
and
price
.
Location Schema
Finally, the
location
schema specifies the state of the world in the game:
{
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'
} ],
}
Here, note that
location
stores exactly the same information as is stored in the
location
attribute of the
character
document. We'll use
location
as the system of record when the
game requires interaction between multiple characters or between characters and noninvent-
ory items.