]> jfr.im git - irc/gameservirc.git/commitdiff
Changed all references of HP to Health
authorkainazzzo <redacted>
Wed, 16 Sep 2009 20:48:58 +0000 (20:48 +0000)
committerkainazzzo <redacted>
Wed, 16 Sep 2009 20:48:58 +0000 (20:48 +0000)
Moved the Use function from PlayerGO into ItemGO for different polymorphic uses of the different types of items. So far, they can only be used on players, but this opens up the possibility of using items on other items since Use() takes a shared_ptr<GameObject>

git-svn-id: https://svn.code.sf.net/p/gameservirc/code/trunk@524 bc333340-6410-0410-a689-9d09f3c113fa

13 files changed:
gameserv-2.0/libgameservcore/include/GameServ/Types.h
gameserv-2.0/libgameservcore/src/Types.cpp
gameserv-2.0/libgameservgldl/include/GameServ/GameLayer/GameObjects/ArmorGO.h
gameserv-2.0/libgameservgldl/include/GameServ/GameLayer/GameObjects/ItemGO.h
gameserv-2.0/libgameservgldl/include/GameServ/GameLayer/GameObjects/PlayerGO.h
gameserv-2.0/libgameservgldl/include/GameServ/GameLayer/GameObjects/PotionGO.h
gameserv-2.0/libgameservgldl/include/GameServ/GameLayer/GameObjects/WeaponGO.h
gameserv-2.0/libgameservgldl/src/DataLayer/File/FileItemDAO.cpp
gameserv-2.0/libgameservgldl/src/GameLayer/GameObjects/ArmorGO.cpp
gameserv-2.0/libgameservgldl/src/GameLayer/GameObjects/ItemGO.cpp
gameserv-2.0/libgameservgldl/src/GameLayer/GameObjects/PlayerGO.cpp
gameserv-2.0/libgameservgldl/src/GameLayer/GameObjects/PotionGO.cpp
gameserv-2.0/libgameservgldl/src/GameLayer/GameObjects/WeaponGO.cpp

index ce7efa2950c7bb822dc599fbd06899f077f6a55d..6e200fc278156d7509abc12225732485387241d4 100644 (file)
@@ -57,7 +57,7 @@ namespace GameServ
                        //! 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
index bf11953f3875519b8d144ff03cb0f9c1732335c9..e657b472e3537f36ab2674ca70156e967727a1b3 100644 (file)
@@ -60,7 +60,7 @@ ItemTypes::ItemType ItemTypes::Parse(const string &itemtype)
 \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
index 709b4b188303a19a25163aa0da612bf7b7e4da85..aaae64f26106282693dde63d97762977879afc88 100644 (file)
@@ -13,7 +13,7 @@ class ArmorGO : public ItemGO
 {\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
index 9370fcb316c714ec363f65238512128713557a02..a147a8992a08afc0336e77aa85408552894f845d 100644 (file)
@@ -46,6 +46,9 @@ namespace GameServ { namespace GameLayer { namespace GameObjects {
                //! 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
@@ -54,6 +57,9 @@ namespace GameServ { namespace GameLayer { namespace GameObjects {
                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
index 044607971d3664e01b8e313fce4c154d91624317..4f160cb9121251027096b79338dca39bf2ca30e7 100644 (file)
@@ -98,11 +98,6 @@ namespace GameServ { namespace GameLayer { namespace GameObjects
                //! 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
index ca52b31ab37e57c9aca328c3821f0ba18ae14e75..2361e1c76a088296f845a57e59844e570cca14fd 100644 (file)
@@ -13,7 +13,7 @@ class PotionGO : public ItemGO
 {\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
index b44cbff29bd46727297fa73bd9b26886aa43a1fe..fdd7bcadf83c61b0171a2c31f4a27ea211596756 100644 (file)
@@ -15,7 +15,7 @@ namespace GameServ { namespace GameLayer { namespace GameObjects {
        {\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
index aa0e2a2b1c5c5c69c6f2a40c45e9af73cd1c0560..ec2a0216be3f2915d99c4906cc9f6b9221a748b2 100644 (file)
@@ -169,14 +169,14 @@ shared_ptr<ItemGO> FileItemDAO::CreateItemFromLine(const string &line) const
                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
index 3a7e6bde3f66425a695ba3950993da9937326577..75905ab027f83d25e6276a2dec02bf0ad9a7f526 100644 (file)
@@ -21,7 +21,7 @@ ArmorGO::ArmorGO() : ItemGO()
        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
@@ -30,7 +30,7 @@ ItemGO()
        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
index b2309d26613032dfc4e99735c323cacdcd71ec12..8cb7be6d8f7d396bff23fa5ce96505a7c766b626 100644 (file)
@@ -1,5 +1,7 @@
 #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
@@ -12,6 +14,12 @@ using std::map;
 \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
@@ -51,6 +59,49 @@ void ItemGO::Uses(const int &value)
        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
index 28206fa8de16e5eb2a3377c5b0ac91e31b040027..601b56524c334583196dbee649a78f17d963665f 100644 (file)
@@ -194,16 +194,6 @@ void PlayerGO::Armor(shared_ptr<ArmorGO> spArmor)
        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
index a5eb1bb711a006687865bc8bdb349fc861e8d62c..e03c382c4023626d2a1205de57dd55adb08cb61b 100644 (file)
@@ -21,7 +21,7 @@ PotionGO::PotionGO() : ItemGO()
        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
@@ -30,7 +30,7 @@ ItemGO()
        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
index f4aff7abbbee9c10cd732f736de0a08cf0344317..1f6c1691504fabe49ff044092e56f887a295d56b 100644 (file)
@@ -21,7 +21,7 @@ WeaponGO::WeaponGO() : ItemGO()
        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
@@ -30,7 +30,7 @@ ItemGO()
        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