Fish_RoomCFG.cpp 6.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210
  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_RoomCFG.h"
  10. #include "FileEncrypt.h"
  11. std::auto_ptr<Fish_RoomCFG> Fish_RoomCFG::msSingleton(nullptr);
  12. int Fish_RoomCFG::GetCount()
  13. {
  14. return (int)mMapData.size();
  15. }
  16. const Fish_RoomCFGData* Fish_RoomCFG::GetData(int RoomID)
  17. {
  18. auto it = mMapData.find(RoomID);
  19. if (it != mMapData.end())
  20. {
  21. return &it->second;
  22. }
  23. return NULL;
  24. }
  25. boost::unordered_map<int, Fish_RoomCFGData>& Fish_RoomCFG::GetMapData()
  26. {
  27. return mMapData;
  28. }
  29. void Fish_RoomCFG::Reload()
  30. {
  31. mMapData.clear();
  32. Load();
  33. }
  34. void Fish_RoomCFG::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_RoomCFGData data;
  67. data.mRoomID = element->IntAttribute("RoomID");
  68. data.mRoomType = element->IntAttribute("RoomType");
  69. data.mRoomName = element->Attribute("RoomName");
  70. data.mRoomImage = element->Attribute("RoomImage");
  71. data.mArmatureName = element->Attribute("ArmatureName");
  72. data.mArmaturePath = element->Attribute("ArmaturePath");
  73. data.mOutFishConfig = element->Attribute("OutFishConfig");
  74. data.mLargetFishConfig = element->Attribute("LargetFishConfig");
  75. data.mBOSSID = element->IntAttribute("BOSSID");
  76. data.mNormalOutFishTime = element->IntAttribute("NormalOutFishTime");
  77. data.mSpecialBoss = element->IntAttribute("SpecialBoss");
  78. data.mBossGroup = element->IntAttribute("BossGroup");
  79. data.mGoldCondition = element->IntAttribute("GoldCondition");
  80. data.mVipCondition = element->IntAttribute("VipCondition");
  81. data.mOrder = element->IntAttribute("Order");
  82. data.mTicketCondition = element->IntAttribute("TicketCondition");
  83. data.mLockBagLv = element->IntAttribute("LockBagLv");
  84. data.mLevelCondition = element->IntAttribute("LevelCondition");
  85. data.mRobotMinGold = element->IntAttribute("RobotMinGold");
  86. data.mRobotMaxGold = element->IntAttribute("RobotMaxGold");
  87. data.mMinRate = element->IntAttribute("MinRate");
  88. data.mMaxRate = element->IntAttribute("MaxRate");
  89. data.mSkillTurret = element->IntAttribute("SkillTurret");
  90. {
  91. const char* RateList = element->Attribute("RateList");
  92. std::vector<std::string> vecRateList;
  93. boost::split(vecRateList, RateList, boost::is_any_of(","));
  94. int temp;
  95. for (unsigned int i = 0; i < vecRateList.size(); i++)
  96. {
  97. if (tinyxml2::XMLUtil::ToInt(vecRateList[i].c_str(), &temp))
  98. {
  99. data.mRateList.push_back(temp);
  100. }
  101. }
  102. }
  103. data.mTableCount = element->IntAttribute("TableCount");
  104. data.mTimeCheck = element->Attribute("TimeCheck");
  105. data.mRedPackage = element->IntAttribute("RedPackage");
  106. {
  107. const char* RedQuantity = element->Attribute("RedQuantity");
  108. std::vector<std::string> vecRedQuantity;
  109. boost::split(vecRedQuantity, RedQuantity, boost::is_any_of(","));
  110. int temp;
  111. for (unsigned int i = 0; i < vecRedQuantity.size(); i++)
  112. {
  113. if (tinyxml2::XMLUtil::ToInt(vecRedQuantity[i].c_str(), &temp))
  114. {
  115. data.mRedQuantity.push_back(temp);
  116. }
  117. }
  118. }
  119. data.mIsShow = element->BoolAttribute("IsShow");
  120. data.mIsOpen = element->BoolAttribute("IsOpen");
  121. data.mPowerParam = element->IntAttribute("PowerParam");
  122. data.mBuyPowerCost = element->IntAttribute("BuyPowerCost");
  123. data.mMissileRate = element->IntAttribute("MissileRate");
  124. data.mMissileCost = element->IntAttribute("MissileCost");
  125. data.mOpenProtect = element->BoolAttribute("OpenProtect");
  126. data.mExpGet = element->BoolAttribute("ExpGet");
  127. data.mChangeTable = element->BoolAttribute("ChangeTable");
  128. data.mWarnLeaveLv = element->IntAttribute("WarnLeaveLv");
  129. data.mNoEnterLv = element->IntAttribute("NoEnterLv");
  130. data.mWinRateAverage = element->IntAttribute("WinRateAverage");
  131. data.mWinRateMax = element->IntAttribute("WinRateMax");
  132. data.mWinRateMin = element->IntAttribute("WinRateMin");
  133. data.mWinRateCtrValue = element->IntAttribute("WinRateCtrValue");
  134. {
  135. const char* SceneIds = element->Attribute("SceneIds");
  136. std::vector<std::string> vecSceneIds;
  137. boost::split(vecSceneIds, SceneIds, boost::is_any_of(","));
  138. int temp;
  139. for (unsigned int i = 0; i < vecSceneIds.size(); i++)
  140. {
  141. if (tinyxml2::XMLUtil::ToInt(vecSceneIds[i].c_str(), &temp))
  142. {
  143. data.mSceneIds.push_back(temp);
  144. }
  145. }
  146. }
  147. {
  148. const char* OpenTime = element->Attribute("OpenTime");
  149. std::vector<std::string> vecOpenTime;
  150. boost::split(vecOpenTime, OpenTime, boost::is_any_of(","));
  151. int temp;
  152. for (unsigned int i = 0; i < vecOpenTime.size(); i++)
  153. {
  154. if (tinyxml2::XMLUtil::ToInt(vecOpenTime[i].c_str(), &temp))
  155. {
  156. data.mOpenTime.push_back(temp);
  157. }
  158. }
  159. }
  160. {
  161. const char* FreeLockId = element->Attribute("FreeLockId");
  162. std::vector<std::string> vecFreeLockId;
  163. boost::split(vecFreeLockId, FreeLockId, boost::is_any_of(","));
  164. int temp;
  165. for (unsigned int i = 0; i < vecFreeLockId.size(); i++)
  166. {
  167. if (tinyxml2::XMLUtil::ToInt(vecFreeLockId[i].c_str(), &temp))
  168. {
  169. data.mFreeLockId.push_back(temp);
  170. }
  171. }
  172. }
  173. {
  174. const char* FreeViolentId = element->Attribute("FreeViolentId");
  175. std::vector<std::string> vecFreeViolentId;
  176. boost::split(vecFreeViolentId, FreeViolentId, boost::is_any_of(","));
  177. int temp;
  178. for (unsigned int i = 0; i < vecFreeViolentId.size(); i++)
  179. {
  180. if (tinyxml2::XMLUtil::ToInt(vecFreeViolentId[i].c_str(), &temp))
  181. {
  182. data.mFreeViolentId.push_back(temp);
  183. }
  184. }
  185. }
  186. if (mMapData.find(data.mRoomID) != mMapData.end())std::cout <<"data refind:" << data.mRoomID << std::endl;
  187. assert(mMapData.find(data.mRoomID) == mMapData.end());
  188. mMapData.insert(std::make_pair(data.mRoomID, data));
  189. element = element->NextSiblingElement();
  190. }
  191. }
  192. void Fish_RoomCFG::Load()
  193. {
  194. Load("../Config/Fish_RoomCFG.xml");
  195. }
  196. Fish_RoomCFG* Fish_RoomCFG::GetSingleton()
  197. {
  198. if (msSingleton.get() == nullptr)
  199. {
  200. msSingleton.reset(new Fish_RoomCFG());
  201. }
  202. return msSingleton.get();
  203. }