]> jfr.im git - irc/gameservirc.git/blob - gameserv-2.0/libgameservgldl/src/GameLayer/GameObjects/PlayerGO.cpp
Finished out the LevelGO class for now
[irc/gameservirc.git] / gameserv-2.0 / libgameservgldl / src / GameLayer / GameObjects / PlayerGO.cpp
1 #include <GameServ/GameLayer/GameObjects/PlayerGO.h>
2 using GameServ::GameLayer::GameObjects::PlayerGO;
3 #include <GameServ/GameLayer/GameObjects/ArmorGO.h>
4 using GameServ::GameLayer::GameObjects::ArmorGO;
5 #include <GameServ/GameLayer/GameObjects/WeaponGO.h>
6 using GameServ::GameLayer::GameObjects::WeaponGO;
7 #include <GameServ/GameLayer/GameObjects/PotionGO.h>
8 using GameServ::GameLayer::GameObjects::PotionGO;
9
10 #include <GameServ/GameServException.h>
11 using GameServ::Exceptions::GameServException;
12
13 #include <GameServ/Types.h>
14 using GameServ::Types::ObjectTypes;
15
16 #include <boost/smart_ptr/shared_ptr.hpp>
17 using boost::shared_ptr;
18 using boost::shared_static_cast;
19
20 #include <boost/algorithm/string.hpp>
21 #include <boost/format.hpp>
22 using boost::str;
23 using boost::format;
24
25 #include <boost/date_time/posix_time/posix_time.hpp>
26 using boost::posix_time::ptime;
27
28 #include <vector>
29 using std::vector;
30 #include <string>
31 using std::string;
32 #include <algorithm>
33 using std::find;
34 using std::sort;
35
36 PlayerGO::PlayerGO() : GameObject(), mName(""), mLevel(1), mExperience(0), mGold(0), mHealth(0), mMaxHealth(0), mStrength(1),
37 mDefense(1), mForestFights(0), mPlayerFights(0), mPassword("")
38 {
39 }
40
41 PlayerGO::PlayerGO(const string &Id) : GameObject(Id), mName(""), mLevel(1), mExperience(0), mGold(0), mHealth(0), mMaxHealth(0), mStrength(1),
42 mDefense(1), mForestFights(0), mPlayerFights(0), mPassword("")
43 {
44 }
45
46 PlayerGO::~PlayerGO()
47 {
48 }
49
50 string PlayerGO::Name(void) const
51 {
52 return mName;
53 }
54
55 void PlayerGO::Name(const string &value)
56 {
57 assert(!value.empty());
58 mName = value;
59 }
60
61 int PlayerGO::Level(void) const
62 {
63 return mLevel;
64 }
65
66 void PlayerGO::Level(const int &value)
67 {
68 assert(value > 0);
69 mLevel = value;
70 }
71
72 unsigned long int PlayerGO::Experience(void) const
73 {
74 return mLevel;
75 }
76
77 void PlayerGO::Experience(const unsigned long int &value)
78 {
79 mExperience = value;
80 }
81
82 unsigned long int PlayerGO::Gold(void) const
83 {
84 return mGold;
85 }
86
87 void PlayerGO::Gold(const unsigned long int &value)
88 {
89 mGold = value;
90 }
91
92 unsigned long int PlayerGO::Bank(void) const
93 {
94 return mBank;
95 }
96
97 void PlayerGO::Bank(const unsigned long int &value)
98 {
99 mBank = value;
100 }
101
102 int PlayerGO::Health(void) const
103 {
104 return mHealth;
105 }
106
107 void PlayerGO::Health(const int &value)
108 {
109 assert(value >= 0);
110 mHealth = value;
111 }
112
113 int PlayerGO::MaxHealth(void) const
114 {
115 return mMaxHealth;
116 }
117
118 void PlayerGO::MaxHealth(const int &value)
119 {
120 assert (value >= 0);
121 mMaxHealth = value;
122 }
123
124 int PlayerGO::Strength(void) const
125 {
126 return mStrength;
127 }
128
129 void PlayerGO::Strength(const int &value)
130 {
131 assert (value > 0);
132 mStrength = value;
133 }
134
135 int PlayerGO::Defense(void) const
136 {
137 return mDefense;
138 }
139
140 void PlayerGO::Defense(const int &value)
141 {
142 assert(value > 0);
143 mDefense = value;
144 }
145
146 int PlayerGO::ForestFights(void) const
147 {
148 return mForestFights;
149 }
150
151 void PlayerGO::ForestFights(const int &value)
152 {
153 assert (value >= 0);
154 mForestFights = value;
155 }
156
157 int PlayerGO::PlayerFights(void) const
158 {
159 return mPlayerFights;
160 }
161
162 void PlayerGO::PlayerFights(const int &value)
163 {
164 assert (value >= 0);
165 mPlayerFights = value;
166 }
167
168 bool PlayerGO::Alive(void) const
169 {
170 return mAlive;
171 }
172
173 void PlayerGO::Alive(const bool &value)
174 {
175 mAlive = value;
176 }
177
178 bool PlayerGO::FoughtMaster(void) const
179 {
180 return mFoughtMaster;
181 }
182
183 void PlayerGO::FoughtMaster(const bool &value)
184 {
185 mFoughtMaster = value;
186 }
187
188 shared_ptr<WeaponGO> PlayerGO::Weapon(void) const
189 {
190 return mWeapon;
191 }
192
193 void PlayerGO::Weapon(shared_ptr<WeaponGO> spWeapon)
194 {
195 mWeapon = spWeapon;
196 }
197
198 shared_ptr<ArmorGO> PlayerGO::Armor(void) const
199 {
200 return mArmor;
201 }
202
203 void PlayerGO::Armor(shared_ptr<ArmorGO> spArmor)
204 {
205 mArmor = spArmor;
206 }
207
208 void PlayerGO::Password(const string &value)
209 {
210 mPassword = value;
211 }
212
213 string PlayerGO::Password(void) const
214 {
215 return mPassword;
216 }
217
218 void PlayerGO::LastLogin(const ptime &value)
219 {
220 mLastLogin = value;
221 }
222
223 ptime PlayerGO::LastLogin(void) const
224 {
225 return mLastLogin;
226 }
227
228 void PlayerGO::Inventory(const vector< shared_ptr<ItemGO> > &items)
229 {
230 mItems.clear();
231 mItems.insert(mItems.begin(), items.begin(), items.end());
232 }
233
234 vector< shared_ptr<ItemGO> > PlayerGO::Inventory(void) const
235 {
236 return mItems;
237 }
238
239 void PlayerGO::AddItemToInventory(shared_ptr<ItemGO> spItem)
240 {
241 mItems.push_back(spItem);
242 }
243
244 shared_ptr<ItemGO> PlayerGO::CloneItemAsProperType(shared_ptr<ItemGO> spItem) const
245 {
246 switch (spItem->Type())
247 {
248 case ItemTypes::Armor:
249 return shared_ptr<ArmorGO>(new ArmorGO(*(ArmorGO *)spItem->Clone()));
250 break;
251 case ItemTypes::Weapon:
252 return shared_ptr<WeaponGO>(new WeaponGO(*(WeaponGO *)spItem->Clone()));
253 break;
254 case ItemTypes::Potion:
255 return shared_ptr<PotionGO>(new PotionGO(*(PotionGO *)spItem->Clone()));
256 break;
257 default:
258 throw GameServException(str(format("Unsupported item type added to Player inventory: %1%") %
259 ItemTypes::GetName(spItem->Type())), __FILE__, __LINE__);
260 }
261 }
262 void PlayerGO::RemoveItemFromInventory(shared_ptr<ItemGO> spItem)
263 {
264 vector< shared_ptr<ItemGO> >::iterator iter;
265 iter = find(mItems.begin(), mItems.end(), spItem);
266 if (iter != mItems.end())
267 {
268 mItems.erase(iter);
269 }
270 }
271
272
273 bool PlayerGO::operator !=(const PlayerGO &right) const
274 {
275 return !(*this == right);
276 }
277
278 bool PlayerGO::operator ==(const PlayerGO &right) const
279 {
280 return GameObject::operator == (right) &&
281 mName == right.mName && right.mArmor == mArmor &&
282 right.mDefense == mDefense && right.mExperience == mExperience &&
283 right.mForestFights == mForestFights && right.mGold == mGold &&
284 right.mHealth == mHealth && right.mMaxHealth == mMaxHealth &&
285 right.mLevel == mLevel && right.mPassword == mPassword &&
286 right.mPlayerFights == mPlayerFights &&
287 right.mStrength == mStrength && right.mWeapon == mWeapon;
288 }
289
290 PlayerGO *PlayerGO::Clone(void) const
291 {
292 return new PlayerGO(*this);
293 }
294
295 ObjectTypes::ObjectType PlayerGO::ObjectType(void) const
296 {
297 return ObjectTypes::Player;
298 }