typedef struct itemtypeinfo\r
{\r
ItemTypes::ItemType itemtype; //!< The ItemType enumeration value\r
- const char *name; //!< The Name of the type\r
+ string name; //!< The Name of the type\r
} itemtypeinfo;\r
\r
static const itemtypeinfo mItemTypeInfoTable[];\r
\r
}; // ItemTypes class\r
- }\r
+\r
+ class Modifiers\r
+ {\r
+ public:\r
+ //! Logical Modifer enumerator\r
+ enum Modifier\r
+ {\r
+ strength, defense, maxhp, hp, forestfights, playerfights, gold, bank\r
+ };\r
+\r
+ //! Get the name of a modifier\r
+ static string GetName(Modifier modifier);\r
+\r
+ //! Parse the name and return the modifier enumeration value\r
+ static Modifier Parse(const string &modifier);\r
+ private:\r
+ typedef struct modifierinfo\r
+ {\r
+ Modifiers::Modifier modifier; //!< The modifier enumeration value\r
+ string name; //!< The name of the modifier\r
+ } modifierinfo;\r
+ static const modifierinfo mModifierInfoTable[];\r
+ }; // Modifiers class\r
+ } \r
}\r
#endif
\ No newline at end of file
#include <GameServ/Types.h>\r
using GameServ::Types::ItemTypes;\r
+using GameServ::Types::Modifiers;\r
using GameServ::Types::Exceptions::TypeException;\r
\r
#include <string>\r
using boost::format;\r
using boost::str;\r
\r
-TypeException::TypeException(const string &ErrorMsg, const char *pFilename, int SourceLine)
-: GameServException(ErrorMsg, pFilename, SourceLine)
-{ }
-
-TypeException::TypeException(const string &ErrorMsg)
-: GameServException(ErrorMsg)
-{ }
-
-TypeException::TypeException(void)
-: GameServException("Type Exception occurred either do to conversion or improper type usage.", __FILE__, __LINE__)
-{ }
+TypeException::TypeException(const string &ErrorMsg, const char *pFilename, int SourceLine)\r
+: GameServException(ErrorMsg, pFilename, SourceLine)\r
+{ }\r
+\r
+TypeException::TypeException(const string &ErrorMsg)\r
+: GameServException(ErrorMsg)\r
+{ }\r
+ \r
+TypeException::TypeException(void)\r
+: GameServException("Type Exception occurred either do to conversion or improper type usage.", __FILE__, __LINE__)\r
+{ }\r
\r
const ItemTypes::itemtypeinfo ItemTypes::mItemTypeInfoTable[] =\r
{\r
{\r
if (mItemTypeInfoTable[i].itemtype == itemtype)\r
{\r
- return string(mItemTypeInfoTable[i].name);\r
+ return mItemTypeInfoTable[i].name;\r
}\r
}\r
\r
// This should never happen because an enumeration is passed, but in the case where a user\r
// may attempt an invalid integer cast, it provides protection\r
throw TypeException(str(format("No item type found for %1% enumeration value") % itemtype).c_str());\r
+}\r
+\r
+ItemTypes::ItemType ItemTypes::Parse(const string &itemtype)\r
+{\r
+ for (unsigned int i = 0; i < sizeof(mItemTypeInfoTable) / sizeof(itemtypeinfo); i++)\r
+ {\r
+ if (mItemTypeInfoTable[i].name == itemtype)\r
+ {\r
+ return mItemTypeInfoTable[i].itemtype;\r
+ }\r
+ }\r
+ return ItemTypes::NOTYPE;\r
+}\r
+\r
+const Modifiers::modifierinfo Modifiers::mModifierInfoTable[] =\r
+{\r
+ { strength, "Strength"}, { defense, "Defense" }, { maxhp, "MaxHP" }, { hp, "HP" }, { forestfights, "Forest Fights" },\r
+ { playerfights, "Player Fights" }, { gold, "Gold" }, { bank, "Bank" }\r
+};\r
+\r
+string Modifiers::GetName(Modifiers::Modifier modifier)\r
+{\r
+ for (unsigned int i = 0; i < sizeof(mModifierInfoTable) / sizeof(modifierinfo); i++)\r
+ {\r
+ if (mModifierInfoTable[i].modifier == modifier)\r
+ {\r
+ return mModifierInfoTable[i].name;\r
+ }\r
+ }\r
+\r
+ // This should never happen because an enumeration is passed, but in the case where a user\r
+ // may attempt an invalid integer cast, it provides protection\r
+ throw TypeException(str(format("No item type found for %1% enumeration value") % modifier).c_str());\r
+}\r
+\r
+Modifiers::Modifier Modifiers::Parse(const string &modifier)\r
+{\r
+ for (unsigned int i = 0; i < sizeof(mModifierInfoTable) / sizeof(modifierinfo); i++)\r
+ {\r
+ if (mModifierInfoTable[i].name == modifier)\r
+ {\r
+ return mModifierInfoTable[i].modifier;\r
+ }\r
+ }\r
+\r
+ throw TypeException(str(format("No modifier enumeration found for %1%") % modifier), __FILE__, __LINE__);\r
}
\ No newline at end of file
#include <GameServ/DataLayer/IDAOFactory.h>\r
using GameServ::DataLayer::IDAOFactory;\r
\r
-#include <boost/shared_ptr.hpp>\r
+#include <boost/smart_ptr/shared_ptr.hpp>\r
using boost::shared_ptr;\r
\r
namespace GameServ { namespace DataLayer\r
#include <GameServ/DataLayer/IArmorDAO.h>\r
using GameServ::DataLayer::DataAccessObjects::IArmorDAO;\r
\r
-#include <boost/shared_ptr.hpp>\r
+#include <boost/smart_ptr/shared_ptr.hpp>\r
using boost::shared_ptr;\r
\r
namespace GameServ { namespace DataLayer { namespace File\r
#include <string>\r
using std::string;\r
\r
+#include <GameServ/Types.h>\r
+using GameServ::Types::ItemTypes;\r
+\r
namespace GameServ { namespace DataLayer { namespace File {\r
class FileId\r
{\r
public:\r
static string CreatePlayerId(const string &Name);\r
static string GetNameFromPlayerId(const string &Id);\r
+\r
+ static string CreateItemId(ItemTypes::ItemType type, const string &Number);\r
+ static ItemTypes::ItemType GetItemTypeFromId(const string &Id);\r
+ static string GetItemNumberFromId(const string &Id);\r
private:\r
FileId();\r
~FileId();\r
using GameServ::GameLayer::GameObjects::PlayerGO;\r
using GameServ::DataLayer::DataAccessObjects::IPlayerDAO;\r
\r
-#include <boost/shared_ptr.hpp>\r
+#include <boost/smart_ptr/shared_ptr.hpp>\r
using boost::shared_ptr;\r
\r
#include <string>\r
#include <GameServ/DataLayer/IArmorDAO.h>\r
using GameServ::DataLayer::DataAccessObjects::IArmorDAO;\r
\r
-#include <boost/shared_ptr.hpp>\r
+#include <boost/smart_ptr/shared_ptr.hpp>\r
using boost::shared_ptr;\r
\r
namespace GameServ { namespace DataLayer \r
#include <GameServ/GameLayer/GameObjects/PlayerGO.h>\r
using GameServ::GameLayer::GameObjects::PlayerGO;\r
\r
-#include <boost/shared_ptr.hpp>\r
+#include <boost/smart_ptr/shared_ptr.hpp>\r
using boost::shared_ptr;\r
\r
#include <list>\r
using std::string;\r
using std::unary_function;\r
\r
-#include <boost/shared_ptr.hpp>\r
+#include <boost/smart_ptr/shared_ptr.hpp>\r
using boost::shared_ptr;\r
\r
namespace GameServ { namespace GameLayer { namespace GameObjects\r
using GameServ::GameLayer::GameObjects::GameObject;\r
#include <GameServ/Types.h>\r
using GameServ::Types::ItemTypes;\r
+using GameServ::Types::Modifiers;\r
\r
#include <string>\r
using std::string;\r
-#include <vector>\r
-using std::vector;\r
+#include <map>\r
+using std::map;\r
\r
namespace GameServ { namespace GameLayer { namespace GameObjects {\r
\r
{\r
public:\r
ItemGO();\r
- ItemGO(const string &name, const unsigned long int &price, const int &uses, const vector<string> &modifiers);\r
virtual ~ItemGO();\r
\r
//! Property get - Name\r
void Type(const ItemTypes::ItemType &value);\r
\r
//! Property get - Modifiers\r
- vector<string> Modifiers(void) const;\r
+ map<Modifiers::Modifier, int> Modifiers(void) const;\r
+\r
//! Property set - Modifiers\r
- void Modifiers(const vector<string> &value);\r
+ void Modifiers(const map<Modifiers::Modifier, int> &modifiers);\r
\r
virtual ItemGO *Clone(void) const;\r
\r
unsigned long int mPrice;\r
int mUses;\r
ItemTypes::ItemType mType;\r
- vector<string> mModifiers;\r
+ map<Modifiers::Modifier, int> mModifiers;\r
};\r
}}}\r
#endif
\ No newline at end of file
#include <GameServ/GameLayer/GameObjects/WeaponGO.h>\r
using GameServ::GameLayer::GameObjects::WeaponGO;\r
\r
-#include <boost/shared_ptr.hpp>\r
+#include <boost/smart_ptr/shared_ptr.hpp>\r
using boost::shared_ptr;\r
\r
#include <string>\r
#include <GameServ/DataLayer/IPlayerDAO.h>\r
using GameServ::DataLayer::DataAccessObjects::IPlayerDAO;\r
\r
-#include <boost/shared_ptr.hpp>\r
+#include <boost/smart_ptr/shared_ptr.hpp>\r
using boost::shared_ptr;\r
\r
#include <list>\r
PreprocessorDefinitions="WIN32;_DEBUG;_LIB;_CRT_SECURE_NO_WARNINGS ;_SCL_SECURE_NO_WARNINGS"\r
MinimalRebuild="true"\r
BasicRuntimeChecks="3"\r
- RuntimeLibrary="3"\r
+ RuntimeLibrary="1"\r
WarningLevel="3"\r
Detect64BitPortabilityProblems="false"\r
DebugInformationFormat="4"\r
using GameServ::DataLayer::Exceptions::DataLayerException;\r
using GameServ::DataLayer::File::FileDAOFactory;\r
\r
-#include <boost/shared_ptr.hpp>\r
+#include <boost/smart_ptr/shared_ptr.hpp>\r
#include <boost/format.hpp>\r
using boost::shared_ptr;\r
using boost::format;\r
#include <GameServ/DataLayer/File/FileId.h>\r
using GameServ::DataLayer::File::FileId;\r
\r
+#include <GameServ/Types.h>\r
+using GameServ::Types::ItemTypes;\r
+using GameServ::Types::Modifiers;\r
+\r
#include <boost/shared_ptr.hpp>\r
#include <boost/format.hpp>\r
#include <boost/algorithm/string.hpp>\r
{\r
assert(!line.empty());\r
shared_ptr<ArmorGO> spArmor;\r
+ map<Modifiers::Modifier, int> modifiers;\r
spArmor = shared_ptr<ArmorGO>(new ArmorGO());\r
- boost::char_separator<char> sep(" ", 0, boost::keep_empty_tokens);\r
+ boost::char_separator<char> sep("~", 0, boost::keep_empty_tokens);\r
tokenizer tokens(line, sep);\r
tokenizer::iterator tok_iter = tokens.begin();\r
-\r
-\r
+ if ((*tok_iter) != "2")\r
+ return shared_ptr<ArmorGO>();\r
+ tok_iter++;\r
+ spArmor->Id(FileId::CreateItemId(ItemTypes::Armor, (*tok_iter)));\r
+\r
+ tok_iter++;\r
+ spArmor->Name((*tok_iter));\r
+ tok_iter++;\r
+ spArmor->Price(lexical_cast<unsigned long int>((*tok_iter)));\r
+ tok_iter++;\r
+ spArmor->Uses(lexical_cast<int>((*tok_iter)));\r
+ tok_iter++;\r
+ modifiers[Modifiers::strength] = lexical_cast<int>((*tok_iter));\r
+ tok_iter++;\r
+ modifiers[Modifiers::defense] = lexical_cast<int>((*tok_iter));\r
+ tok_iter++;\r
+ modifiers[Modifiers::maxhp] = lexical_cast<int>((*tok_iter));\r
+ tok_iter++;\r
+ modifiers[Modifiers::hp] = lexical_cast<int>((*tok_iter));\r
+ tok_iter++;\r
+ modifiers[Modifiers::forestfights] = lexical_cast<int>((*tok_iter));\r
+ tok_iter++;\r
+ modifiers[Modifiers::playerfights] = lexical_cast<int>((*tok_iter));\r
+ tok_iter++;\r
+ modifiers[Modifiers::gold] = lexical_cast<int>((*tok_iter));\r
+ tok_iter++;\r
+ modifiers[Modifiers::bank] = lexical_cast<int>((*tok_iter));\r
+ spArmor->Modifiers(modifiers);\r
\r
return spArmor;\r
}\r
\r
void FileArmorDAO::LoadArmorCache(void)\r
{\r
+ ifstream infile;\r
+ infile.open(mFilename.c_str());\r
+\r
+ if (infile.fail())\r
+ {\r
+ throw DataLayerException(str(format("Unable to open %1% for reading") % mFilename), __FILE__, __LINE__);\r
+ }\r
+ string line;\r
+ while (getline(infile, line))\r
+ {\r
+ if (line.length() == 0)\r
+ {\r
+ continue;\r
+ }\r
+ if (line[0] == '#')\r
+ {\r
+ continue;\r
+ }\r
+ shared_ptr<ArmorGO> spArmor = CreateArmorFromLine(line);\r
+ if (spArmor != 0)\r
+ {\r
+ spArmorCache[spArmor->Id()] = spArmor;\r
+ }\r
+ }\r
+ infile.close();\r
}
\ No newline at end of file
using GameServ::DataLayer::File::FilePlayerDAO;\r
using GameServ::DataLayer::File::FileArmorDAO;\r
\r
-#include <boost/shared_ptr.hpp>\r
+#include <boost/smart_ptr/shared_ptr.hpp>\r
using boost::shared_ptr;\r
\r
FileDAOFactory::FileDAOFactory(void)\r
#include <string>\r
using std::string;\r
\r
+#include <GameServ/Types.h>\r
+using GameServ::Types::ItemTypes;\r
+\r
+#include <GameServ/GameServException.h>\r
+using GameServ::Exceptions::GameServException;\r
+\r
+#include <boost/format.hpp>\r
+#include <boost/algorithm/string.hpp>\r
+#include <boost/lexical_cast.hpp>\r
+using boost::str;\r
+using boost::format;\r
+using boost::lexical_cast;\r
+\r
FileId::FileId()\r
{\r
}\r
{\r
return Id;\r
}\r
+\r
+string FileId::CreateItemId(ItemTypes::ItemType type, const string &Number)\r
+{\r
+ string id = ItemTypes::GetName(type) + ":" + Number;\r
+ return id;\r
+}\r
+\r
+ItemTypes::ItemType FileId::GetItemTypeFromId(const string &Id)\r
+{\r
+ size_t colon = Id.find_first_of(":");\r
+ if (colon == string::npos)\r
+ throw GameServException(str(format("Invalid Item ID %1%") % Id), __FILE__, __LINE__);\r
+ \r
+ return ItemTypes::Parse(Id.substr(0, colon));\r
+}\r
+\r
+string FileId::GetItemNumberFromId(const string &Id)\r
+{\r
+ size_t colon = Id.find_first_of(":");\r
+ if (colon == string::npos)\r
+ throw GameServException(str(format("Invalid Item ID %1%") % Id), __FILE__, __LINE__);\r
+ return Id.substr(colon + 1);\r
+}
\ No newline at end of file
#include <GameServ/DataLayer/File/FileId.h>\r
using GameServ::DataLayer::File::FileId;\r
\r
-#include <boost/shared_ptr.hpp>\r
+#include <boost/smart_ptr/shared_ptr.hpp>\r
#include <boost/format.hpp>\r
#include <boost/algorithm/string.hpp>\r
#include <boost/lexical_cast.hpp>\r
#include <GameServ/GameLayer/GameObjects/ArmorGO.h>\r
using GameServ::GameLayer::GameObjects::ArmorGO;\r
\r
+#include <GameServ/Types.h>\r
+using GameServ::Types::Modifiers;\r
+using GameServ::Types::ItemTypes;\r
+\r
#include <string>\r
using std::string;\r
-#include <vector>\r
-using std::vector;\r
+#include <map>\r
+using std::map;\r
\r
#include <boost/format.hpp>\r
#include <boost/algorithm/string.hpp>\r
mPrice = price;\r
mUses = uses;\r
mModifiers.clear();\r
- mModifiers.push_back(str(format("STRENGTH + %d") % strength));\r
- mModifiers.push_back(str(format("DEFENSE + %d") % defense));\r
- mModifiers.push_back(str(format("MAXHP + %d") % maxhp));\r
+ mModifiers[Modifiers::strength] = strength;\r
+ mModifiers[Modifiers::defense] = defense;\r
+ mModifiers[Modifiers::maxhp] = maxhp;\r
}\r
\r
ArmorGO::~ArmorGO()\r
#include <string>\r
using std::string;\r
\r
-#include <boost/shared_ptr.hpp>\r
+#include <boost/smart_ptr/shared_ptr.hpp>\r
using boost::shared_ptr;\r
\r
GameObject::GameObject(void) : mId()\r
\r
#include <GameServ/Types.h>\r
using GameServ::Types::ItemTypes;\r
+using GameServ::Types::Modifiers;\r
\r
#include <string>\r
using std::string;\r
-#include <vector>\r
-using std::vector;\r
+#include <map>\r
+using std::map;\r
\r
-#include <boost/shared_ptr.hpp>\r
+#include <boost/smart_ptr/shared_ptr.hpp>\r
using boost::shared_ptr;\r
\r
ItemGO::ItemGO() : GameObject(), mName(""), mPrice(0), mUses(1), mType(ItemTypes::NOTYPE)\r
{\r
- mModifiers.resize(8);\r
-}\r
-\r
-ItemGO::ItemGO(const string &name, const unsigned long &price, const int &uses, const vector<string> &modifiers) : GameObject(),\r
-mName(name), mPrice(price), mUses(uses), mType(ItemTypes::NOTYPE)\r
-{\r
- mModifiers.clear();\r
- mModifiers.insert(mModifiers.begin(), modifiers.begin(), modifiers.end());\r
}\r
\r
ItemGO::~ItemGO()\r
mType = value;\r
}\r
\r
-vector<string> ItemGO::Modifiers(void) const\r
+map<Modifiers::Modifier, int> ItemGO::Modifiers(void) const\r
{\r
return mModifiers;\r
}\r
\r
-void ItemGO::Modifiers(const vector<string> &value)\r
+void ItemGO::Modifiers(const map<Modifiers::Modifier, int> &modifiers)\r
{\r
mModifiers.clear();\r
- mModifiers.insert(mModifiers.begin(), value.begin(), value.end());\r
+ mModifiers.insert(modifiers.begin(), modifiers.end());\r
}\r
\r
ItemGO *ItemGO::Clone(void) const\r
#include <GameServ/GameLayer/GameObjects/WeaponGO.h>\r
using GameServ::GameLayer::GameObjects::WeaponGO;\r
\r
-#include <boost/shared_ptr.hpp>\r
+#include <boost/smart_ptr/shared_ptr.hpp>\r
using boost::shared_ptr;\r
\r
#include <GameServ/GameServException.h>\r
#include <GameServ/GameLayer/GameObjects/WeaponGO.h>\r
using GameServ::GameLayer::GameObjects::WeaponGO;\r
\r
+#include <GameServ/Types.h>\r
+using GameServ::Types::Modifiers;\r
+\r
#include <string>\r
using std::string;\r
-#include <vector>\r
-using std::vector;\r
+#include <map>\r
+using std::map;\r
\r
#include <boost/format.hpp>\r
#include <boost/algorithm/string.hpp>\r
mPrice = price;\r
mUses = uses;\r
mModifiers.clear();\r
- mModifiers.push_back(str(format("STRENGTH + %d") % strength));\r
- mModifiers.push_back(str(format("DEFENSE + %d") % defense));\r
- mModifiers.push_back(str(format("MAXHP + %d") % maxhp));\r
+ mModifiers[Modifiers::strength] = strength;\r
+ mModifiers[Modifiers::defense] = defense;\r
+ mModifiers[Modifiers::maxhp] = maxhp;\r
}\r
\r
WeaponGO::~WeaponGO()\r
AdditionalIncludeDirectories="$(SolutionDir)/libgameservgldl/include;$(SolutionDir)/libgameservcore/include"\r
MinimalRebuild="true"\r
BasicRuntimeChecks="3"\r
- RuntimeLibrary="3"\r
+ RuntimeLibrary="1"\r
WarningLevel="3"\r
DebugInformationFormat="4"\r
/>\r