-
Notifications
You must be signed in to change notification settings - Fork 8
Expand file tree
/
Copy pathGlobal_Check_For_Premium_Example.cpp
More file actions
140 lines (121 loc) · 3.07 KB
/
Copy pathGlobal_Check_For_Premium_Example.cpp
File metadata and controls
140 lines (121 loc) · 3.07 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
#include "chat.h"
#include "Config.h"
#include "math.h"
#include "player.h"
#include "RBAC.h"
#include "ScriptMgr.h"
#include "World.h"
/*
* Main command class.
*/
class PremCommand
{
public:
PremCommand(const char* _info) : info(_info) { }
void handleHelpCommand(ChatHandler* handler)
{
handler->PSendSysMessage(info);
}
virtual void handleCommand(ChatHandler* handler, Player* player) = 0;
private:
const char* info;
};
/*
* Sub command class(es).
*/
class DrinkCommand : public PremCommand
{
public:
DrinkCommand(const char* _info) : PremCommand(_info) { }
void handleCommand(ChatHandler* handler, Player* player)
{
uint8 drink = player->GetDrunkValue();
player->SetDrunkValue(drink + 5);
handler->PSendSysMessage("!Down the hatch!");
}
};
class DrunkCommand : public PremCommand
{
public:
DrunkCommand(const char* _info) : PremCommand(_info) { }
void handleCommand(ChatHandler* handler, Player* player)
{
player->SetDrunkValue(100);
handler->PSendSysMessage("!You drunk!");
}
};
class SoberCommand : public PremCommand
{
public:
SoberCommand(const char* _info) : PremCommand(_info) { }
void handleCommand(ChatHandler* handler, Player* player)
{
player->SetDrunkValue(1);
handler->PSendSysMessage("You're now sober..");
}
};
std::map<std::string, PremCommand*> command_map;
class Premium_Commands : public CommandScript
{
public:
Premium_Commands() : CommandScript("Premium_Commands")
{
// Setting up the commands.
if (command_map.empty())
{
command_map["drink"] = new DrinkCommand("Allows the player to increase +5 to drunk.");
command_map["drunk"] = new DrunkCommand("Allows the player become 100 drunk.");
command_map["sober"] = new SoberCommand("Allows the player to become sober.");
}
}
std::vector<ChatCommand> GetCommands() const
{
static std::vector<ChatCommand> commandTable =
{
{ "premium", rbac::RBAC_IN_GRANTED_LIST, true, &handlePremiumCommand, "Premium custom commands." },
};
return commandTable;
}
/*
* Main command handler. This will be executed, before any of the sub command handlers.
* It uses polymorphism to map the commands.
*/
static bool handlePremiumCommand(ChatHandler* handler, const char* args)
{
Player* player = handler->GetSession()->GetPlayer();
if (PREM::IsPlayerPremium(player))
return_type = true;
else
return false;
std::vector<char*> arguments = getArguments(args);
if (arguments.size() == 0)
return false;
std::string command = arguments[0];
arguments.erase(arguments.begin());
PremCommand* commandHandler = command_map[command];
if (commandHandler == NULL)
return false;
commandHandler->handleCommand(handler, player);
return true;
}
private:
/*
* Method to convert the argument string to a vector.
*/
static std::vector<char*> getArguments(const char* args)
{
std::vector<char*> arguments;
// Extracting the arguments and push them to the vector.
char* arg = strtok((char*)args, " ");
while (arg != NULL)
{
arguments.push_back(arg);
arg = strtok((char*)NULL, " ");
}
return arguments;
}
};
void AddSC_Premium_System()
{
new Premium_Commands;
}