]> jfr.im git - irc/gameservirc.git/commitdiff
Changed Types::Range to use int instead of unsigned int so negative numbers can be...
authorkainazzzo <redacted>
Fri, 18 Sep 2009 02:27:57 +0000 (02:27 +0000)
committerkainazzzo <redacted>
Fri, 18 Sep 2009 02:27:57 +0000 (02:27 +0000)
Implemented Potions in FileItemDAO so that one is complete now!

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

gameserv-2.0/data/players.dat
gameserv-2.0/libgameservcore/include/GameServ/Types.h
gameserv-2.0/libgameservcore/src/Types.cpp
gameserv-2.0/libgameservgldl/src/DataLayer/File/FileItemDAO.cpp
gameserv-2.0/testdriver/main.cpp

index 3b526342dbe6d3ff05ede11fb86febc73f9a4864..abaee08942fb14d0d55857b3a5937cef460a4ef7 100644 (file)
@@ -1 +1,2 @@
-Kain 1 1 100 0 10 10 10 10 100 3 2 test 100000000 1 3001 3001 -1 1 -1 3002 -1
\ No newline at end of file
+Kain 1 1 100 0 10 10 10 10 100 3 0 test 19730303T094640 1 3001 3001 -1 1 -1 3002 -1 6001 1 6002 1 6003 1\r
+Kainazzzo 1 1 100 0 10 10 10 10 100 3 0 test 19730303T094640 1 3001 3001 -1 1 -1 3002 -1 6001 1 6002 1 6003 1\r
index 72611a7623e34675cd95ade74a16981ca3ab00e7..83e6bd99e8e5d7a6cc57586301d5a3356a18ac41 100644 (file)
@@ -78,27 +78,27 @@ namespace GameServ
                {\r
                public:\r
                        Range();\r
-                       Range(const unsigned int &high, const unsigned int &low);\r
+                       Range(const int &high, const int &low);\r
                        ~Range();\r
 \r
                        //! Generate a random number within the range\r
-                       unsigned int Random();\r
+                       int Random();\r
 \r
                        //! Property get - High\r
-                       unsigned int High(void) const;\r
+                       int High(void) const;\r
                        \r
                        //! Property set - High\r
-                       void High(const unsigned int &value);\r
+                       void High(const int &value);\r
 \r
                        //! Property get - Low\r
-                       unsigned int Low(void) const;\r
+                       int Low(void) const;\r
 \r
                        //! Property set - Low\r
-                       void Low(const unsigned int &value);\r
+                       void Low(const int &value);\r
                        \r
                private:\r
-                       unsigned int mHigh;\r
-                       unsigned int mLow;\r
+                       int mHigh;\r
+                       int mLow;\r
                };\r
        } \r
 }\r
index f61558117c2d16b145c294525eeebf03071e6461..d99923fc7814fb14a6507871a07f5229a2ae8ee4 100644 (file)
@@ -119,7 +119,7 @@ Range::Range()
        mLow = 0;\r
 }\r
 \r
-Range::Range(const unsigned int &high, const unsigned int &low)\r
+Range::Range(const int &high, const int &low)\r
 {\r
        mHigh = high;\r
        mLow = low;\r
@@ -129,32 +129,32 @@ Range::~Range()
 {\r
 }\r
 \r
-void Range::High(const unsigned int &value)\r
+void Range::High(const int &value)\r
 {\r
-       if (mHigh > mLow)\r
+       if (mHigh >= mLow)\r
                mHigh = value;\r
 }\r
 \r
-unsigned int Range::High(void) const\r
+int Range::High(void) const\r
 {\r
        return mHigh;\r
 }\r
 \r
-void Range::Low(const unsigned int &value)\r
+void Range::Low(const int &value)\r
 {\r
-       if (mLow < mHigh)\r
+       if (mLow <= mHigh)\r
                mLow = value;\r
 }\r
 \r
-unsigned int Range::Low(void) const\r
+int Range::Low(void) const\r
 {\r
        return mLow;\r
 }\r
 \r
-unsigned int Range::Random()\r
+int Range::Random()\r
 {\r
-       static base_generator_type generator(static_cast<unsigned int>(std::time(0)));\r
+       static base_generator_type generator(static_cast<int>(std::time(0)));\r
        boost::uniform_int<> uni_dist(mHigh, mLow);\r
        boost::variate_generator<base_generator_type&, boost::uniform_int<> > uni(generator, uni_dist);\r
-       return static_cast<unsigned int>(uni());\r
+       return static_cast<int>(uni());\r
 }
\ No newline at end of file
index 60d5802533a5bd7f1c9808cd4a526d12f92c876a..71e7037aec4d6d9fb18d415f13474a820c1953f5 100644 (file)
@@ -87,7 +87,172 @@ shared_ptr<ItemGO> FileItemDAO::GetById(const string &Id) const
 }\r
 shared_ptr<ItemGO> FileItemDAO::CreatePotionFromLine(const string &line) const\r
 {\r
+       assert(!line.empty());\r
        shared_ptr<PotionGO> spPotion = shared_ptr<PotionGO>(new PotionGO());\r
+       map<Modifiers::Modifier, Range> modifiers;\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
+       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
+       spPotion->Id(FileId::CreateItemId((*tok_iter)));\r
+\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
+\r
+       spPotion->Name((*tok_iter));\r
+\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
+       spPotion->Price(lexical_cast<unsigned long int>((*tok_iter)));\r
+\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
+       spPotion->Uses(lexical_cast<int>((*tok_iter)));\r
+\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
+       int low = 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
+       int high = lexical_cast<int>((*tok_iter));\r
+       modifiers[Modifiers::strength] = Range(high, low);\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
+       low = 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
+       high = lexical_cast<int>((*tok_iter));\r
+       modifiers[Modifiers::defense] = Range(high, low);\r
+\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
+       low = 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
+       high = lexical_cast<int>((*tok_iter));\r
+       modifiers[Modifiers::maxhealth] = Range(high, low);\r
+\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
+       low = 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
+       high = lexical_cast<int>((*tok_iter));\r
+       modifiers[Modifiers::health] = Range(high, low);\r
+\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
+       low = 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
+       high = lexical_cast<int>((*tok_iter));\r
+       modifiers[Modifiers::forestfights] = Range(high, low);\r
+\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
+       low = 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
+       high = lexical_cast<int>((*tok_iter));\r
+       modifiers[Modifiers::playerfights] = Range(high, low);\r
+\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
+       low = 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
+       high = lexical_cast<int>((*tok_iter));\r
+       modifiers[Modifiers::gold] = Range(high, low);\r
+\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
+       low = 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
+       high = lexical_cast<int>((*tok_iter));\r
+       modifiers[Modifiers::bank] = Range(high, low);\r
 \r
        return spPotion;\r
 }\r
index 3f8bb933c0d4a8092a2fbce1ca9eb45959f0cf41..7cd45a1b798c4826c57d872ee5016222150e29ec 100644 (file)
@@ -15,22 +15,22 @@ int main()
 {\r
        try\r
        {\r
-       /*      PlayerGL pgl;\r
-               shared_ptr<PlayerGO> spPlayer = pgl.GetById("Kain");\r
-               cout << spPlayer->Name() << endl;\r
-               spPlayer->Name("Kainazzzo");\r
-               pgl.Insert(spPlayer);*/\r
+               //PlayerGL pgl;\r
+               //shared_ptr<PlayerGO> spPlayer = pgl.GetById("Kain");\r
+               //cout << spPlayer->Name() << endl;\r
+               //spPlayer->Name("Kainazzzo");\r
+               //pgl.Insert(spPlayer);\r
 \r
                \r
-               map <unsigned int, unsigned int> frequencies;\r
+               map <int, int> frequencies;\r
                int x;\r
-               for (x = 0; x < 1000000; x++)\r
+               for (x = 0; x < 10000; x++)\r
                {\r
-                       Range testrange(1, 100);\r
-                       unsigned int randnum = testrange.Random();\r
+                       Range testrange(-100, 100);\r
+                       int randnum = testrange.Random();\r
                        frequencies[randnum]++;\r
                }\r
-               map<unsigned int, unsigned int>::const_iterator iter;\r
+               map<int, int>::const_iterator iter;\r
                for (iter = frequencies.begin(); iter != frequencies.end(); iter++)\r
                {\r
                        cout << iter->first << ": ";\r