-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtables.sql
141 lines (126 loc) · 3.06 KB
/
tables.sql
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
-- The first two static tables
CREATE TABLE maps
(
name VARCHAR(30),
max_x INTEGER,
max_y INTEGER,
description VARCHAR,
PRIMARY KEY (name)
);
CREATE TABLE warp_points
(
from_map VARCHAR(30),
to_map VARCHAR(30),
from_point INTEGER[],
to_point INTEGER[],
PRIMARY KEY (from_map, to_map),
FOREIGN KEY (from_map)
REFERENCES maps (name),
FOREIGN KEY (to_map)
REFERENCES maps (name)
);
CREATE TABLE worth
(
name VARCHAR(20),
value INTEGER,
PRIMARY KEY (name)
);
-- Table of changing values
CREATE TABLE items
(
id INTEGER,
name VARCHAR(20),
x INTEGER, -- If both x and y are NULL
y INTEGER, -- then item must be on the ground in a room
map_name VARCHAR(30),
worth_type VARCHAR(20),
-- container_id INTEGER, -- If NULL then item is on ground
description VARCHAR,
PRIMARY KEY (id),
FOREIGN KEY (worth_type)
REFERENCES worth (name),
-- FOREIGN KEY (container_id)
-- REFERENCES containers (id),
FOREIGN KEY (map_name)
REFERENCES maps (name)
);
CREATE TABLE containers
(
id INTEGER,
name VARCHAR(20),
x INTEGER, -- If x, y are NULL then container is in a room
y INTEGER, -- Noting that rooms can also be 'containers'
map_name VARCHAR(30),
parent_container_id INTEGER,
description VARCHAR,
unlock_item_id INTEGER,
room_flag BOOLEAN,
PRIMARY KEY (id),
FOREIGN KEY (unlock_item_id)
REFERENCES items (id),
FOREIGN KEY (parent_container_id)
REFERENCES containers (id)
ON UPDATE SET NULL,
FOREIGN KEY (map_name)
REFERENCES maps (name)
);
-- Alter table is required because of FK overlaps
ALTER TABLE items
ADD container_id INTEGER;
ALTER TABLE items
ADD CONSTRAINT container_must_exist
FOREIGN KEY (container_id)
REFERENCES containers (id);
-- npcs are static and unchanging
CREATE TABLE npcs
(
name VARCHAR(20),
x INTEGER, -- If x, y are null then the npc is
y INTEGER, -- in a room.
map_name VARCHAR(20),
room_id INTEGER,
counter_value INTEGER,
description VARCHAR,
PRIMARY KEY (name),
FOREIGN KEY (room_id)
REFERENCES containers (id),
FOREIGN KEY (map_name)
REFERENCES maps (name)
);
CREATE TABLE npc_dialogue
(
npc_name VARCHAR(20),
counter INTEGER,
dialogue VARCHAR,
PRIMARY KEY (npc_name, counter),
FOREIGN KEY (npc_name)
REFERENCES npcs (name)
);
CREATE TABLE npc_conditionals
(
npc_name VARCHAR(20),
condition INTEGER,
action VARCHAR, --This is a python command such as protag.give(thing)
PRIMARY KEY (npc_name, action),
FOREIGN KEY (npc_name)
REFERENCES npcs (name)
);
-- Inventory tables
CREATE TABLE inventory
(
name VARCHAR(20),-- If NULL then Player's item
item_id INTEGER,
backpack BOOLEAN,
PRIMARY KEY (item_id),
FOREIGN KEY (item_id)
REFERENCES items (id),
FOREIGN KEY (name)
REFERENCES npcs(name)
);
CREATE TABLE help
(
name VARCHAR(10),
syntax VARCHAR(30),
description VARCHAR,
PRIMARY KEY (name)
);