Fish_IntermediateExchange.cpp 6.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236
  1. #include "stdafx.h"
  2. #include <cassert>
  3. #include <fstream>
  4. #include <iostream>
  5. #include <iostream>
  6. #include <boost/smart_ptr.hpp>
  7. #include <boost/algorithm/string.hpp>
  8. #include "tinyxml2.h"
  9. #include "Fish_IntermediateExchange.h"
  10. #include "FileEncrypt.h"
  11. std::auto_ptr<Fish_IntermediateExchange> Fish_IntermediateExchange::msSingleton(nullptr);
  12. int Fish_IntermediateExchange::GetCount()
  13. {
  14. return (int)mMapData.size();
  15. }
  16. const Fish_IntermediateExchangeData* Fish_IntermediateExchange::GetData(int ID)
  17. {
  18. auto it = mMapData.find(ID);
  19. if (it != mMapData.end())
  20. {
  21. return &it->second;
  22. }
  23. return NULL;
  24. }
  25. boost::unordered_map<int, Fish_IntermediateExchangeData>& Fish_IntermediateExchange::GetMapData()
  26. {
  27. return mMapData;
  28. }
  29. void Fish_IntermediateExchange::Reload()
  30. {
  31. mMapData.clear();
  32. Load();
  33. }
  34. void Fish_IntermediateExchange::Load(const std::string& path)
  35. {
  36. std::ifstream readStream(path, std::ios::binary);
  37. if (!readStream.is_open())
  38. {
  39. assert(false);
  40. return;
  41. }
  42. readStream.seekg(0, std::ios::end);
  43. int fileSize = readStream.tellg();
  44. boost::shared_array<char> buffer(new char[fileSize+1]);
  45. buffer.get()[fileSize] = '\0';
  46. readStream.seekg(0, std::ios::beg);
  47. readStream.read(buffer.get(), fileSize);
  48. readStream.close();
  49. FileEncrypt::decryptBuffer( buffer, fileSize );
  50. tinyxml2::XMLDocument xmlDoc;
  51. auto result = xmlDoc.Parse(buffer.get(), fileSize);
  52. if (result != tinyxml2::XML_SUCCESS)
  53. {
  54. assert(false);
  55. return;
  56. }
  57. auto root = xmlDoc.RootElement();
  58. if (root == NULL)
  59. {
  60. assert(false);
  61. return;
  62. }
  63. auto element = root->FirstChildElement("Data");
  64. while (element != NULL)
  65. {
  66. Fish_IntermediateExchangeData data;
  67. data.mID = element->IntAttribute("ID");
  68. data.mname = element->Attribute("name");
  69. {
  70. const char* itemId = element->Attribute("itemId");
  71. std::vector<std::string> vecitemId;
  72. boost::split(vecitemId, itemId, boost::is_any_of(","));
  73. int temp;
  74. for (unsigned int i = 0; i < vecitemId.size(); i++)
  75. {
  76. if (tinyxml2::XMLUtil::ToInt(vecitemId[i].c_str(), &temp))
  77. {
  78. data.mitemId.push_back(temp);
  79. }
  80. }
  81. }
  82. {
  83. const char* itemcount = element->Attribute("itemcount");
  84. std::vector<std::string> vecitemcount;
  85. boost::split(vecitemcount, itemcount, boost::is_any_of(","));
  86. int temp;
  87. for (unsigned int i = 0; i < vecitemcount.size(); i++)
  88. {
  89. if (tinyxml2::XMLUtil::ToInt(vecitemcount[i].c_str(), &temp))
  90. {
  91. data.mitemcount.push_back(temp);
  92. }
  93. }
  94. }
  95. {
  96. const char* fixedReward = element->Attribute("fixedReward");
  97. std::vector<std::string> vecfixedReward;
  98. boost::split(vecfixedReward, fixedReward, boost::is_any_of(","));
  99. int temp;
  100. for (unsigned int i = 0; i < vecfixedReward.size(); i++)
  101. {
  102. if (tinyxml2::XMLUtil::ToInt(vecfixedReward[i].c_str(), &temp))
  103. {
  104. data.mfixedReward.push_back(temp);
  105. }
  106. }
  107. }
  108. {
  109. const char* probabilityReward = element->Attribute("probabilityReward");
  110. std::vector<std::string> vecprobabilityReward;
  111. boost::split(vecprobabilityReward, probabilityReward, boost::is_any_of(","));
  112. int temp;
  113. for (unsigned int i = 0; i < vecprobabilityReward.size(); i++)
  114. {
  115. if (tinyxml2::XMLUtil::ToInt(vecprobabilityReward[i].c_str(), &temp))
  116. {
  117. data.mprobabilityReward.push_back(temp);
  118. }
  119. }
  120. }
  121. {
  122. const char* primaryFubao = element->Attribute("primaryFubao");
  123. std::vector<std::string> vecprimaryFubao;
  124. boost::split(vecprimaryFubao, primaryFubao, boost::is_any_of(","));
  125. int temp;
  126. for (unsigned int i = 0; i < vecprimaryFubao.size(); i++)
  127. {
  128. if (tinyxml2::XMLUtil::ToInt(vecprimaryFubao[i].c_str(), &temp))
  129. {
  130. data.mprimaryFubao.push_back(temp);
  131. }
  132. }
  133. }
  134. {
  135. const char* NewGiftIntegral = element->Attribute("NewGiftIntegral");
  136. std::vector<std::string> vecNewGiftIntegral;
  137. boost::split(vecNewGiftIntegral, NewGiftIntegral, boost::is_any_of(","));
  138. int temp;
  139. for (unsigned int i = 0; i < vecNewGiftIntegral.size(); i++)
  140. {
  141. if (tinyxml2::XMLUtil::ToInt(vecNewGiftIntegral[i].c_str(), &temp))
  142. {
  143. data.mNewGiftIntegral.push_back(temp);
  144. }
  145. }
  146. }
  147. {
  148. const char* NewIntegral = element->Attribute("NewIntegral");
  149. std::vector<std::string> vecNewIntegral;
  150. boost::split(vecNewIntegral, NewIntegral, boost::is_any_of(","));
  151. int temp;
  152. for (unsigned int i = 0; i < vecNewIntegral.size(); i++)
  153. {
  154. if (tinyxml2::XMLUtil::ToInt(vecNewIntegral[i].c_str(), &temp))
  155. {
  156. data.mNewIntegral.push_back(temp);
  157. }
  158. }
  159. }
  160. {
  161. const char* GiftIntegral = element->Attribute("GiftIntegral");
  162. std::vector<std::string> vecGiftIntegral;
  163. boost::split(vecGiftIntegral, GiftIntegral, boost::is_any_of(","));
  164. int temp;
  165. for (unsigned int i = 0; i < vecGiftIntegral.size(); i++)
  166. {
  167. if (tinyxml2::XMLUtil::ToInt(vecGiftIntegral[i].c_str(), &temp))
  168. {
  169. data.mGiftIntegral.push_back(temp);
  170. }
  171. }
  172. }
  173. {
  174. const char* ComIntegral = element->Attribute("ComIntegral");
  175. std::vector<std::string> vecComIntegral;
  176. boost::split(vecComIntegral, ComIntegral, boost::is_any_of(","));
  177. int temp;
  178. for (unsigned int i = 0; i < vecComIntegral.size(); i++)
  179. {
  180. if (tinyxml2::XMLUtil::ToInt(vecComIntegral[i].c_str(), &temp))
  181. {
  182. data.mComIntegral.push_back(temp);
  183. }
  184. }
  185. }
  186. {
  187. const char* NorIntegral = element->Attribute("NorIntegral");
  188. std::vector<std::string> vecNorIntegral;
  189. boost::split(vecNorIntegral, NorIntegral, boost::is_any_of(","));
  190. int temp;
  191. for (unsigned int i = 0; i < vecNorIntegral.size(); i++)
  192. {
  193. if (tinyxml2::XMLUtil::ToInt(vecNorIntegral[i].c_str(), &temp))
  194. {
  195. data.mNorIntegral.push_back(temp);
  196. }
  197. }
  198. }
  199. {
  200. const char* OnListWeight = element->Attribute("OnListWeight");
  201. std::vector<std::string> vecOnListWeight;
  202. boost::split(vecOnListWeight, OnListWeight, boost::is_any_of(","));
  203. int temp;
  204. for (unsigned int i = 0; i < vecOnListWeight.size(); i++)
  205. {
  206. if (tinyxml2::XMLUtil::ToInt(vecOnListWeight[i].c_str(), &temp))
  207. {
  208. data.mOnListWeight.push_back(temp);
  209. }
  210. }
  211. }
  212. if (mMapData.find(data.mID) != mMapData.end())std::cout <<"data refind:" << data.mID << std::endl;
  213. assert(mMapData.find(data.mID) == mMapData.end());
  214. mMapData.insert(std::make_pair(data.mID, data));
  215. element = element->NextSiblingElement();
  216. }
  217. }
  218. void Fish_IntermediateExchange::Load()
  219. {
  220. Load("../Config/Fish_IntermediateExchange.xml");
  221. }
  222. Fish_IntermediateExchange* Fish_IntermediateExchange::GetSingleton()
  223. {
  224. if (msSingleton.get() == nullptr)
  225. {
  226. msSingleton.reset(new Fish_IntermediateExchange());
  227. }
  228. return msSingleton.get();
  229. }