-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgame.h
executable file
·158 lines (132 loc) · 5.24 KB
/
game.h
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
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
#include <string.h>
#include <vector>
#include <dlfcn.h>
#include "irc.h"
using namespace std;
enum { WEP_MELEE, WEP_RANGED, WEP_AMMO };
// Stores the ID and how many the player has of it
struct MessageStruct
{
string Speaker;
string Host;
vector <string> StrSub;
bool Public;
};
struct ItemIDStruct
{
unsigned int ID;
short Amount;
};
// Actually holds the item info
struct ItemStruct
{
string Name, Description;
short Type;
int Power, Strength, Requires;
bool Use;
};
// Player
struct PlayerStruct
{
string Name, Nick, Password, Host;
int Level, Exp, Health, Gold, Race, Class;
char Gender; // M = male, F = female
short Equip[3], Current;
vector <ItemIDStruct> Item;
};
// Races
struct RaceStruct
{
string Name; // Name of the race
float Burn, Critical, Energy, Freeze, Immunity, Magic, Money, Poison, Shock; // Stats
bool OperOnly; // Locked races
};
// Classes
struct ClassStruct
{
string Name; // Name of the race
float Endurance, ExpRate, Luck, Magic, Speed, Stealth, Strength, Wit; // Stats
bool OperOnly; // Locked classes
};
// The help struct
struct HelpStruct
{
string Name;
vector <string> Output;
};
class GameClass
{
public:
GameClass();
void MainLoop();
void TrackUser(string OldNick, string NewNick);
void UserQuit(string Nick);
bool SaveToMySQL();
bool LoadFromMySQL();
void SaveToDatabase();
bool LoadFromDatabase();
bool LoadHelp();
// Get various things
string GetRaceFromName(string &Name);
string GetNameFromNick(string &Nick);
int GetIDFromNick(string &Name);
int GetItemIDFromItemName(string &Name);
int DoesPlayerHaveItem(int PlayerID, int ItemID);
void SetChannel(string &Channel_) { Channel = Channel_; };
string GetChannel() { return Channel; }
// Relating to the current message
void SetCurrMessage(string &speaker, string &host, vector <string> &StrSub, bool Public);
string GetCurrSpeaker() { return CurrMessage.Speaker; }
string GetCurrHost() { return CurrMessage.Host; }
string GetCurrMessage(int Word) { return CurrMessage.StrSub[Word]; }
unsigned int GetCurrMessageSize() { return CurrMessage.StrSub.size(); }
bool GetCurrPublic() { return CurrMessage.Public; }
// Get/set things relating to the player
unsigned int GetPlayerSize() { return Player.size(); }
PlayerStruct GetPlayer(int ID) { return Player[ID]; }
void SetPlayerNick(int ID, string Nick) { Player[ID].Nick = Nick; }
void SetPlayerHost(int ID, string Host) { Player[ID].Host = Host; }
unsigned int FindPlayerByName(string Name) { Name = ConvertToLower(Name); for (unsigned int i = 0; i < Player.size(); ++i) { if (ConvertToLower(Player[i].Name) == Name) return i; } return -1; }
unsigned int FindPlayerByNick(string Nick) { Nick = ConvertToLower(Nick); for (unsigned int i = 0; i < Player.size(); ++i) { if (ConvertToLower(Player[i].Nick) == Nick) return i; } return -1; }
void AddPlayer(PlayerStruct &NewPlayer) { Player.push_back(NewPlayer); };
void DeletePlayer(int ID) { Player.erase(Player.begin()+ID); }
bool IsLoggedIn(int ID, string Nick, string Host) { if (ConvertToLower(Player[ID].Nick) == ConvertToLower(Nick) && Player[ID].Host == Host) return true; else return false; }
// Get/set things relating to the race
unsigned int GetRaceSize() { return Race.size(); }
RaceStruct GetRace(int ID) { return Race[ID]; }
unsigned int FindRaceByName(string Name) { Name = ConvertToLower(Name); for (unsigned int i = 0; i < Race.size(); ++i) { if (ConvertToLower(Race[i].Name) == Name) return i; } return -1; }
// Get/set things relating to the class
unsigned int GetClassSize() { return Class.size(); }
ClassStruct GetClass(int ID) { return Class[ID]; }
unsigned int FindClassByName(string Name) { Name = ConvertToLower(Name); for (unsigned int i = 0; i < Class.size(); ++i) { if (ConvertToLower(Class[i].Name) == Name) return i; } return -1; }
void Help(string Command, string &Recipient, bool Incorrect); // Sends the user help about a command
private:
void UseItem(int Player, int Item);
void Equip(string &Type, string &Item, string &Speaker, string &Host);
void SetUse(string &Type, string &Speaker, string &Host);
bool CheckLevelUp(int Player);
void ShowStats(string Name, string Recipient);
void List(string Stat, string Recipient);
void Attack(string &PlayerNick, string &Victim, string &Recpient, string &Host);
void LogIn(string &PlayerName, string &PlayerNick, string &Password, string &Host);
void LogOut(string &PlayerNick, string &Host);
void Ghost(string &PlayerName, string &Password, string &Speaker);
/**********************
******* Variables *****
**********************/
string Channel;
MessageStruct CurrMessage;
vector <PlayerStruct> Player;
vector <RaceStruct> Race;
vector <ClassStruct> Class;
vector <ItemStruct> Item;
vector <HelpStruct> HelpObj;
};
extern GameClass Game;
#define ERROR_BADLOGIN "Sorry, you don't appear to be logged in."
#define ERROR_BADHOST "Sorry, but your username and host don't match. Use either the \'ghost\' command or \'login\' again."
#define ERROR_NOTANITEM "Sorry, that is not a valid item."
#define ERROR_DONOTHAVE "Sorry, but you do not have that item."
#define ERROR_WRONGTYPE "Sorry, but that item cannot be equiped to that slot."
#define ERROR_ALREADYEQUIP "That item is already equiped to that slot!"
#define ERROR_INVALIDTYPE "That weapon type does not exist."