]>
jfr.im git - irc/gameservirc.git/blob - 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
;
10 #include <GameServ/GameServException.h>
11 using GameServ::Exceptions::GameServException
;
13 #include <GameServ/Types.h>
14 using GameServ::Types::ObjectTypes
;
16 #include <boost/smart_ptr/shared_ptr.hpp>
17 using boost::shared_ptr
;
18 using boost::shared_static_cast
;
20 #include <boost/algorithm/string.hpp>
21 #include <boost/format.hpp>
25 #include <boost/date_time/posix_time/posix_time.hpp>
26 using boost::posix_time::ptime
;
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("")
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("")
50 string
PlayerGO::Name(void) const
55 void PlayerGO::Name(const string
&value
)
57 assert(!value
.empty());
61 int PlayerGO::Level(void) const
66 void PlayerGO::Level(const int &value
)
72 unsigned long int PlayerGO::Experience(void) const
77 void PlayerGO::Experience(const unsigned long int &value
)
82 unsigned long int PlayerGO::Gold(void) const
87 void PlayerGO::Gold(const unsigned long int &value
)
92 unsigned long int PlayerGO::Bank(void) const
97 void PlayerGO::Bank(const unsigned long int &value
)
102 int PlayerGO::Health(void) const
107 void PlayerGO::Health(const int &value
)
113 int PlayerGO::MaxHealth(void) const
118 void PlayerGO::MaxHealth(const int &value
)
124 int PlayerGO::Strength(void) const
129 void PlayerGO::Strength(const int &value
)
135 int PlayerGO::Defense(void) const
140 void PlayerGO::Defense(const int &value
)
146 int PlayerGO::ForestFights(void) const
148 return mForestFights
;
151 void PlayerGO::ForestFights(const int &value
)
154 mForestFights
= value
;
157 int PlayerGO::PlayerFights(void) const
159 return mPlayerFights
;
162 void PlayerGO::PlayerFights(const int &value
)
165 mPlayerFights
= value
;
168 bool PlayerGO::Alive(void) const
173 void PlayerGO::Alive(const bool &value
)
178 bool PlayerGO::FoughtMaster(void) const
180 return mFoughtMaster
;
183 void PlayerGO::FoughtMaster(const bool &value
)
185 mFoughtMaster
= value
;
188 shared_ptr
<WeaponGO
> PlayerGO::Weapon(void) const
193 void PlayerGO::Weapon(shared_ptr
<WeaponGO
> spWeapon
)
198 shared_ptr
<ArmorGO
> PlayerGO::Armor(void) const
203 void PlayerGO::Armor(shared_ptr
<ArmorGO
> spArmor
)
208 void PlayerGO::Password(const string
&value
)
213 string
PlayerGO::Password(void) const
218 void PlayerGO::LastLogin(const ptime
&value
)
223 ptime
PlayerGO::LastLogin(void) const
228 void PlayerGO::Inventory(const vector
< shared_ptr
<ItemGO
> > &items
)
231 mItems
.insert(mItems
.begin(), items
.begin(), items
.end());
234 vector
< shared_ptr
<ItemGO
> > PlayerGO::Inventory(void) const
239 void PlayerGO::AddItemToInventory(shared_ptr
<ItemGO
> spItem
)
241 mItems
.push_back(spItem
);
244 shared_ptr
<ItemGO
> PlayerGO::CloneItemAsProperType(shared_ptr
<ItemGO
> spItem
) const
246 switch (spItem
->Type())
248 case ItemTypes::Armor
:
249 return shared_ptr
<ArmorGO
>(new ArmorGO(*(ArmorGO
*)spItem
->Clone()));
251 case ItemTypes::Weapon
:
252 return shared_ptr
<WeaponGO
>(new WeaponGO(*(WeaponGO
*)spItem
->Clone()));
254 case ItemTypes::Potion
:
255 return shared_ptr
<PotionGO
>(new PotionGO(*(PotionGO
*)spItem
->Clone()));
258 throw GameServException(str(format("Unsupported item type added to Player inventory: %1%") %
259 ItemTypes::GetName(spItem
->Type())), __FILE__
, __LINE__
);
262 void PlayerGO::RemoveItemFromInventory(shared_ptr
<ItemGO
> spItem
)
264 vector
< shared_ptr
<ItemGO
> >::iterator iter
;
265 iter
= find(mItems
.begin(), mItems
.end(), spItem
);
266 if (iter
!= mItems
.end())
273 bool PlayerGO::operator !=(const PlayerGO
&right
) const
275 return !(*this == right
);
278 bool PlayerGO::operator ==(const PlayerGO
&right
) const
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
;
290 PlayerGO
*PlayerGO::Clone(void) const
292 return new PlayerGO(*this);
295 ObjectTypes::ObjectType
PlayerGO::ObjectType(void) const
297 return ObjectTypes::Player
;