Fish_TurretLevelCFG.cpp 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207
  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_TurretLevelCFG.h"
  10. #include "FileEncrypt.h"
  11. std::auto_ptr<Fish_TurretLevelCFG> Fish_TurretLevelCFG::msSingleton(nullptr);
  12. int Fish_TurretLevelCFG::GetCount()
  13. {
  14. return (int)mMapData.size();
  15. }
  16. const Fish_TurretLevelCFGData* Fish_TurretLevelCFG::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_TurretLevelCFGData>& Fish_TurretLevelCFG::GetMapData()
  26. {
  27. return mMapData;
  28. }
  29. void Fish_TurretLevelCFG::Reload()
  30. {
  31. mMapData.clear();
  32. Load();
  33. }
  34. void Fish_TurretLevelCFG::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_TurretLevelCFGData data;
  67. data.mID = element->IntAttribute("ID");
  68. data.mOpenRate = element->IntAttribute("OpenRate");
  69. data.mAwardGold = element->IntAttribute("AwardGold");
  70. data.mOneTickUp = element->IntAttribute("OneTickUp");
  71. data.mShotsBuff = element->IntAttribute("ShotsBuff");
  72. data.mLevelUpIcon = element->Attribute("LevelUpIcon");
  73. data.mUpType = element->IntAttribute("UpType");
  74. data.mUpRate = element->IntAttribute("UpRate");
  75. data.mNeedLucky = element->IntAttribute("NeedLucky");
  76. {
  77. const char* NeedItems = element->Attribute("NeedItems");
  78. std::vector<std::string> vecNeedItems;
  79. boost::split(vecNeedItems, NeedItems, boost::is_any_of(","));
  80. int temp;
  81. for (unsigned int i = 0; i < vecNeedItems.size(); i++)
  82. {
  83. if (tinyxml2::XMLUtil::ToInt(vecNeedItems[i].c_str(), &temp))
  84. {
  85. data.mNeedItems.push_back(temp);
  86. }
  87. }
  88. }
  89. {
  90. const char* NeedCount = element->Attribute("NeedCount");
  91. std::vector<std::string> vecNeedCount;
  92. boost::split(vecNeedCount, NeedCount, boost::is_any_of(","));
  93. int temp;
  94. for (unsigned int i = 0; i < vecNeedCount.size(); i++)
  95. {
  96. if (tinyxml2::XMLUtil::ToInt(vecNeedCount[i].c_str(), &temp))
  97. {
  98. data.mNeedCount.push_back(temp);
  99. }
  100. }
  101. }
  102. {
  103. const char* ExtraUpgrade = element->Attribute("ExtraUpgrade");
  104. std::vector<std::string> vecExtraUpgrade;
  105. boost::split(vecExtraUpgrade, ExtraUpgrade, boost::is_any_of(","));
  106. int temp;
  107. for (unsigned int i = 0; i < vecExtraUpgrade.size(); i++)
  108. {
  109. if (tinyxml2::XMLUtil::ToInt(vecExtraUpgrade[i].c_str(), &temp))
  110. {
  111. data.mExtraUpgrade.push_back(temp);
  112. }
  113. }
  114. }
  115. data.mDropAttenuates = element->IntAttribute("DropAttenuates");
  116. {
  117. const char* DailyQuestGroup = element->Attribute("DailyQuestGroup");
  118. std::vector<std::string> vecDailyQuestGroup;
  119. boost::split(vecDailyQuestGroup, DailyQuestGroup, boost::is_any_of(","));
  120. int temp;
  121. for (unsigned int i = 0; i < vecDailyQuestGroup.size(); i++)
  122. {
  123. if (tinyxml2::XMLUtil::ToInt(vecDailyQuestGroup[i].c_str(), &temp))
  124. {
  125. data.mDailyQuestGroup.push_back(temp);
  126. }
  127. }
  128. }
  129. data.mDropLimit = element->IntAttribute("DropLimit");
  130. {
  131. const char* TaskItems = element->Attribute("TaskItems");
  132. std::vector<std::string> vecTaskItems;
  133. boost::split(vecTaskItems, TaskItems, boost::is_any_of(","));
  134. int temp;
  135. for (unsigned int i = 0; i < vecTaskItems.size(); i++)
  136. {
  137. if (tinyxml2::XMLUtil::ToInt(vecTaskItems[i].c_str(), &temp))
  138. {
  139. data.mTaskItems.push_back(temp);
  140. }
  141. }
  142. }
  143. {
  144. const char* QuantityOfArticles = element->Attribute("QuantityOfArticles");
  145. std::vector<std::string> vecQuantityOfArticles;
  146. boost::split(vecQuantityOfArticles, QuantityOfArticles, boost::is_any_of(","));
  147. int temp;
  148. for (unsigned int i = 0; i < vecQuantityOfArticles.size(); i++)
  149. {
  150. if (tinyxml2::XMLUtil::ToInt(vecQuantityOfArticles[i].c_str(), &temp))
  151. {
  152. data.mQuantityOfArticles.push_back(temp);
  153. }
  154. }
  155. }
  156. data.mTaskDisplay = element->IntAttribute("TaskDisplay");
  157. {
  158. const char* UnlockDisplayID = element->Attribute("UnlockDisplayID");
  159. std::vector<std::string> vecUnlockDisplayID;
  160. boost::split(vecUnlockDisplayID, UnlockDisplayID, boost::is_any_of(","));
  161. int temp;
  162. for (unsigned int i = 0; i < vecUnlockDisplayID.size(); i++)
  163. {
  164. if (tinyxml2::XMLUtil::ToInt(vecUnlockDisplayID[i].c_str(), &temp))
  165. {
  166. data.mUnlockDisplayID.push_back(temp);
  167. }
  168. }
  169. }
  170. {
  171. const char* UnlockDisplayMasks = element->Attribute("UnlockDisplayMasks");
  172. std::vector<std::string> vecUnlockDisplayMasks;
  173. boost::split(vecUnlockDisplayMasks, UnlockDisplayMasks, boost::is_any_of(","));
  174. int temp;
  175. for (unsigned int i = 0; i < vecUnlockDisplayMasks.size(); i++)
  176. {
  177. if (tinyxml2::XMLUtil::ToInt(vecUnlockDisplayMasks[i].c_str(), &temp))
  178. {
  179. data.mUnlockDisplayMasks.push_back(temp);
  180. }
  181. }
  182. }
  183. if (mMapData.find(data.mID) != mMapData.end())std::cout <<"data refind:" << data.mID << std::endl;
  184. assert(mMapData.find(data.mID) == mMapData.end());
  185. mMapData.insert(std::make_pair(data.mID, data));
  186. element = element->NextSiblingElement();
  187. }
  188. }
  189. void Fish_TurretLevelCFG::Load()
  190. {
  191. Load("../Config/Fish_TurretLevelCFG.xml");
  192. }
  193. Fish_TurretLevelCFG* Fish_TurretLevelCFG::GetSingleton()
  194. {
  195. if (msSingleton.get() == nullptr)
  196. {
  197. msSingleton.reset(new Fish_TurretLevelCFG());
  198. }
  199. return msSingleton.get();
  200. }