-
Notifications
You must be signed in to change notification settings - Fork 27
/
db_config.sql
99 lines (80 loc) · 2.75 KB
/
db_config.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
create database Game_server;
use Game_server;
create table Player_Profile (
PlayerID varchar(32),
firstName varchar(30),
lastName varchar(30),
Cash int default 0,
Gold int default 0,
primary key (PlayerID)
);
create table Login_Credentials (
PlayerID varchar(32),
password varchar(32),
primary key (PlayerID),
foreign key (PlayerID) references Player_Profile (PlayerID) on delete cascade on update cascade
);
create table Mini_Game (
GameID int,
No_of_rooms int,
primary key (GameID)
);
create table Players_in_Game (
PlayerID varchar(32),
GameID int,
RoomID int,
primary key (PlayerID,GameID,RoomID),
foreign key (PlayerID) references Player_Profile (PlayerID) on delete cascade on update cascade,
foreign key (GameID) references Mini_Game (GameID) on delete cascade on update cascade
);
create table Player_History (
PlayerID varchar(32),
GameID int,
RoomID int,
Cash int,
Gold int,
primary key (PlayerID,GameID,RoomID),
foreign key (PlayerID) references Player_Profile (PlayerID) on delete cascade on update cascade,
foreign key (GameID) references Mini_Game (GameID) on delete cascade on update cascade
);
create table Perks_Available (
PerkID int(1),
Name text,
Description text,
Price int(4),
primary key (PerkID)
);
create table Owned_Perk (
PlayerID varchar(32),
PerkID int(1),
Quantity int,
primary key (PlayerID,PerkID),
foreign key (PlayerID) references Player_Profile (PlayerID) on delete cascade on update cascade,
foreign key (PerkID) references Perks_Available (PerkID) on delete cascade on update cascade
);
insert into Mini_Game values(1,0);
insert into Mini_Game values(2,0);
insert into Perks_Available values(1,'2x Multiplier','Used to multiply both cash and gold obtained from a game!',4);
insert into Perks_Available values(2,'Head start!','Used to obtain a random headstart between 1 to 10 in Snakes \'n Ladders!',6);
delimiter $$
create procedure fullName(pid varchar(32))
begin
select concat(firstName,' ',lastName) as Name from Player_Profile where PlayerID = pid;
end $$
create procedure cashLeaderboard()
begin
select @rank:=@rank+1 as rank, firstName, lastName, Cash from Player_Profile p, (select @rank := 0) r order by Cash desc;
end $$
create procedure goldLeaderboard()
begin
select @rank:=@rank+1 as rank, firstName, lastName, Cash from Player_Profile p, (select @rank := 0) r order by Gold desc;
end $$
create procedure snakePlayerHistory(pid varchar(32))
begin
select @rank:=@rank+1 as rank, Cash, Gold from Player_History p, (select @rank:=0) r where PlayerID=pid and GameID=1 order by Cash desc;
end $$
create procedure c4PlayerHistory(pid varchar(32))
begin
select @rank:=@rank+1 as rank, Cash, Gold from Player_History p, (select @rank:=0) r where PlayerID=pid and GameID=2 order by Cash desc;
end $$
delimiter ;