//! Logical Modifer enumerator\r
enum Modifier\r
{\r
- strength, defense, maxhp, hp, forestfights, playerfights, gold, bank\r
+ strength, defense, maxhealth, health, forestfights, playerfights, gold, bank\r
};\r
\r
//! Get the name of a modifier\r
\r
const Modifiers::modifierinfo Modifiers::mModifierInfoTable[] =\r
{\r
- { strength, "Strength"}, { defense, "Defense" }, { maxhp, "MaxHP" }, { hp, "HP" }, { forestfights, "Forest Fights" },\r
+ { strength, "Strength"}, { defense, "Defense" }, { maxhealth, "MaxHealth" }, { health, "Health" }, { forestfights, "Forest Fights" },\r
{ playerfights, "Player Fights" }, { gold, "Gold" }, { bank, "Bank" }\r
};\r
\r
{\r
public:\r
ArmorGO();\r
- ArmorGO(const string &name, const int &price, const int &uses, const int &strength, const int &defense, const int &maxhp);\r
+ ArmorGO(const string &name, const int &price, const int &uses, const int &strength, const int &defense, const int &maxhealth);\r
virtual ~ArmorGO();\r
\r
private:\r
//! Property set - Modifiers\r
void Modifiers(const map<Modifiers::Modifier, int> &modifiers);\r
\r
+ //! Use item on a player.\r
+ void Use(shared_ptr<GameObject> spPlayer);\r
+\r
virtual ItemGO *Clone(void) const;\r
\r
protected:\r
int mUses;\r
ItemTypes::ItemType mType;\r
map<Modifiers::Modifier, int> mModifiers;\r
+\r
+ //! Base class standard modifier applier. Simply adds the modified stat to the correct stat\r
+ virtual void ApplyModifier(shared_ptr<GameObject> spObject, const Modifiers::Modifier &modifier, const int &num);\r
};\r
}}}\r
#endif
\ No newline at end of file
//! Property set - Armor\r
void Armor(shared_ptr<ArmorGO> spArmor);\r
\r
- //! Use an Item\r
- void Use(shared_ptr<ItemGO> spItem);\r
- //! Undo the effects of an item\r
- void Undo(shared_ptr<ItemGO> spItem);\r
-\r
//! Property set - Password\r
void Password(const string &value);\r
//! Property get - Password\r
{\r
public:\r
PotionGO();\r
- PotionGO(const string &name, const int &price, const int &uses, const int &strength, const int &defense, const int &maxhp);\r
+ PotionGO(const string &name, const int &price, const int &uses, const int &strength, const int &defense, const int &maxhealth);\r
virtual ~PotionGO();\r
\r
private:\r
{\r
public:\r
WeaponGO();\r
- WeaponGO(const string &name, const int &price, const int &uses, const int &strength, const int &defense, const int &maxhp);\r
+ WeaponGO(const string &name, const int &price, const int &uses, const int &strength, const int &defense, const int &maxhealth);\r
virtual ~WeaponGO();\r
\r
private:\r
throw DataLayerException(str(format("Corrupt %1% file. Missing information on line %2%") %\r
mFilename % line), __FILE__, __LINE__);\r
}\r
- modifiers[Modifiers::maxhp] = lexical_cast<int>((*tok_iter));\r
+ modifiers[Modifiers::maxhealth] = lexical_cast<int>((*tok_iter));\r
tok_iter++;\r
if (tok_iter == tokens.end())\r
{\r
throw DataLayerException(str(format("Corrupt %1% file. Missing information on line %2%") %\r
mFilename % line), __FILE__, __LINE__);\r
}\r
- modifiers[Modifiers::hp] = lexical_cast<int>((*tok_iter));\r
+ modifiers[Modifiers::health] = lexical_cast<int>((*tok_iter));\r
tok_iter++;\r
if (tok_iter == tokens.end())\r
{\r
mType = ItemTypes::Armor;\r
}\r
\r
-ArmorGO::ArmorGO(const string &name, const int &price, const int &uses, const int &strength, const int &defense, const int &maxhp) :\r
+ArmorGO::ArmorGO(const string &name, const int &price, const int &uses, const int &strength, const int &defense, const int &maxhealth) :\r
ItemGO()\r
{\r
mName = name;\r
mModifiers.clear();\r
mModifiers[Modifiers::strength] = strength;\r
mModifiers[Modifiers::defense] = defense;\r
- mModifiers[Modifiers::maxhp] = maxhp;\r
+ mModifiers[Modifiers::maxhealth] = maxhealth;\r
mType = ItemTypes::Armor;\r
}\r
\r
#include <GameServ/GameLayer/GameObjects/ItemGO.h>\r
using GameServ::GameLayer::GameObjects::ItemGO;\r
+#include <GameServ/GameLayer/GameObjects/PlayerGO.h>\r
+using GameServ::GameLayer::GameObjects::PlayerGO;\r
\r
#include <GameServ/Types.h>\r
using GameServ::Types::ItemTypes;\r
\r
#include <boost/smart_ptr/shared_ptr.hpp>\r
using boost::shared_ptr;\r
+using boost::shared_static_cast;\r
+\r
+#include <boost/algorithm/string.hpp>\r
+#include <boost/format.hpp>\r
+using boost::str;\r
+using boost::format;\r
\r
ItemGO::ItemGO() : GameObject(), mName(""), mPrice(0), mUses(1), mType(ItemTypes::NOTYPE)\r
{\r
mUses = value;\r
}\r
\r
+void ItemGO::Use(shared_ptr<GameObject> spPlayer)\r
+{\r
+ map<Modifiers::Modifier, int>::const_iterator iter;\r
+ for (iter = mModifiers.begin(); iter != mModifiers.end(); iter++)\r
+ {\r
+ ApplyModifier(spPlayer, iter->first, iter->second);\r
+ }\r
+}\r
+\r
+void ItemGO::ApplyModifier(shared_ptr<GameObject> spObject, const Modifiers::Modifier &modifier, const int &num)\r
+{\r
+ shared_ptr<PlayerGO> spPlayer = shared_static_cast<PlayerGO>(spObject);\r
+ switch (modifier)\r
+ {\r
+ case Modifiers::strength:\r
+ spPlayer->Strength(spPlayer->Strength() + num);\r
+ break;\r
+ case Modifiers::defense:\r
+ spPlayer->Defense(spPlayer->Defense() + num);\r
+ break;\r
+ case Modifiers::health:\r
+ spPlayer->Health(spPlayer->Health() + num);\r
+ break;\r
+ case Modifiers::maxhealth:\r
+ spPlayer->MaxHealth(spPlayer->MaxHealth() + num);\r
+ break;\r
+ case Modifiers::gold:\r
+ spPlayer->Gold(spPlayer->Gold() + num);\r
+ break;\r
+ case Modifiers::bank:\r
+ spPlayer->Bank(spPlayer->Bank() + num);\r
+ break;\r
+ case Modifiers::forestfights:\r
+ spPlayer->ForestFights(spPlayer->ForestFights() + num);\r
+ break;\r
+ case Modifiers::playerfights:\r
+ spPlayer->PlayerFights(spPlayer->PlayerFights() + num);\r
+ break;\r
+ default:\r
+ throw GameServException(str(format("Invalid modifier %1%") % modifier), __FILE__, __LINE__);\r
+ }\r
+}\r
+\r
ItemTypes::ItemType ItemGO::Type(void) const\r
{\r
return mType;\r
mArmor = spArmor;\r
}\r
\r
-void PlayerGO::Use(shared_ptr<ItemGO> spItem)\r
-{\r
- throw GameServException("Undefined function.", __FILE__, __LINE__);\r
-}\r
-\r
-void PlayerGO::Undo(shared_ptr<ItemGO> spItem)\r
-{\r
- throw GameServException("Undefined function.", __FILE__, __LINE__);\r
-}\r
-\r
void PlayerGO::Password(const string &value)\r
{\r
mPassword = value;\r
mType = ItemTypes::Potion;\r
}\r
\r
-PotionGO::PotionGO(const string &name, const int &price, const int &uses, const int &strength, const int &defense, const int &maxhp) :\r
+PotionGO::PotionGO(const string &name, const int &price, const int &uses, const int &strength, const int &defense, const int &maxhealth) :\r
ItemGO()\r
{\r
mName = name;\r
mModifiers.clear();\r
mModifiers[Modifiers::strength] = strength;\r
mModifiers[Modifiers::defense] = defense;\r
- mModifiers[Modifiers::maxhp] = maxhp;\r
+ mModifiers[Modifiers::maxhealth] = maxhealth;\r
mType = ItemTypes::Potion;\r
}\r
\r
mType = ItemTypes::Weapon;\r
}\r
\r
-WeaponGO::WeaponGO(const string &name, const int &price, const int &uses, const int &strength, const int &defense, const int &maxhp) :\r
+WeaponGO::WeaponGO(const string &name, const int &price, const int &uses, const int &strength, const int &defense, const int &maxhealth) :\r
ItemGO()\r
{\r
mName = name;\r
mModifiers.clear();\r
mModifiers[Modifiers::strength] = strength;\r
mModifiers[Modifiers::defense] = defense;\r
- mModifiers[Modifiers::maxhp] = maxhp;\r
+ mModifiers[Modifiers::maxhealth] = maxhealth;\r
mType = ItemTypes::Weapon;\r
}\r
\r