-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathedit_parser.cpp
More file actions
141 lines (120 loc) · 4.66 KB
/
edit_parser.cpp
File metadata and controls
141 lines (120 loc) · 4.66 KB
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
#include "edit_parser.h"
#include "game_server.h"
#include <iostream>
#include "common.h"
#include "database.h"
using namespace std;
bool EditParser::handleeditInput(Player *p, string command)
{
//
// /setdesc <roomname> "description"
// /setreq <itemname> <roomname>
// /setreqmove <roomname> <itemname> <newroomname>
// /setchance <roomname> <%chance> <newroomname>
// REGEX PATTERNS & MORE
string input = command;
regex setdescPattern ("/setdesc (.+) (\"([^\"]*)\")");
regex setreqPattern ("/setreq (.+) (.+)");
regex setreqmovePattern ("/setreqmove (.+) (.+) (.+)");
regex setchancePattern ("/setchance (.+) ([0-99]%) (.+)");
smatch m;
//ADD CAN PLAYER EDIT
if(input == "help")
{
// HELP
server->printToUser(p, "Available editing commands: \n \n");
server->printToUser(p, "To set/change room description - /setdesc <roomname> \"description\"");
server->printToUser(p, "To require an item to enter a room - /setreq <itemname> <roomname>");
server->printToUser(p, "To requre an item to stay in room otherwise moved - /setreqmove <roomname> <itemname> <newroomname>");
server->printToUser(p, "To set a chance teleportation - /setchance <roomname> <chance%> <newroomname> \n \n");
return false;
}
if(regex_match(command, m, setdescPattern)){
{
server->printToUser(p, m[1]);
server->printToUser(p, m[3]);
if(db->findRoomByName(m[1]) != NULL)
{
db->findRoomByName(m[1])->setDesc(m[3]);
}
else
{
server->printToUser(p, "Room not found");
}
}
if(regex_match(command, m, setreqPattern))
{
if(db->findItemByName(m[1]) == NULL)
{
server->printToUser(p, "Item not found");
}
else
{
if(db->findRoomByName(m[2]) == NULL)
{
server->printToUser(p, "Room not found");
}
else
{
db->findRoomByName(m[2])->setReq(m[1]);
}
}
}
if(regex_match(command, m, setreqmovePattern))
{
if(db->findRoomByName(m[1]) == NULL)
{
server->printToUser(p, "First Room Parameter not found");
}
else
{
if(db->findItemByName(m[2]) == NULL)
{
server->printToUser(p, "Item not found");
}
else
{
if(db->findRoomByName(m[3]) == NULL)
{
server->printToUser(p, "Room not found");
}
else
{
//setreqMove(oldroom, itemname, newroom)
//server->printToUser(p, "Item: " + itemname + " requirement was set to " + roomname + " and will teleport you to " + newroomname);
server->printToUser(p, "WIP");
}
}
}
}
if(regex_match(command, m, setchancePattern))
{
if(db->findRoomByName(m[1]) == NULL)
{
server->printToUser(p, "Room not found");
}
else
{
double chance = stod(m[2]);
if(chance < 0 && chance > 100)
{
server->printToUser(p, "Chance not within parameters");
}
else
{
if(db->findRoomByName(m[3]) == NULL)
{
server->printToUser(p, "Room not found");
}
else
{
//setChance(roomname, chance, newroomname)
server->printToUser(p, "WIP");
//server->printToUser(p, ("In the room " + roomname + " There is now a " + chance + " % that a player will be teleported to " + newroomname + " if entered");
}
}
}
}
}
return false;
}