M_VIPProfitCFG.cpp 7.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261
  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 "M_VIPProfitCFG.h"
  10. #include "FileEncrypt.h"
  11. std::auto_ptr<M_VIPProfitCFG> M_VIPProfitCFG::msSingleton(nullptr);
  12. int M_VIPProfitCFG::GetCount()
  13. {
  14. return (int)mMapData.size();
  15. }
  16. const M_VIPProfitCFGData* M_VIPProfitCFG::GetData(int VipLv)
  17. {
  18. auto it = mMapData.find(VipLv);
  19. if (it != mMapData.end())
  20. {
  21. return &it->second;
  22. }
  23. return NULL;
  24. }
  25. boost::unordered_map<int, M_VIPProfitCFGData>& M_VIPProfitCFG::GetMapData()
  26. {
  27. return mMapData;
  28. }
  29. void M_VIPProfitCFG::Reload()
  30. {
  31. mMapData.clear();
  32. Load();
  33. }
  34. void M_VIPProfitCFG::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. M_VIPProfitCFGData data;
  67. data.mVipLv = element->IntAttribute("VipLv");
  68. data.mVipExp = element->IntAttribute("VipExp");
  69. data.mOnlineReward = element->IntAttribute("OnlineReward");
  70. data.mMaxGiftslimit = element->IntAttribute("MaxGiftslimit");
  71. {
  72. const char* GiftUnlock = element->Attribute("GiftUnlock");
  73. std::vector<std::string> vecGiftUnlock;
  74. boost::split(vecGiftUnlock, GiftUnlock, boost::is_any_of(","));
  75. for (unsigned int i = 0; i < vecGiftUnlock.size(); i++)
  76. {
  77. data.mGiftUnlock.push_back(vecGiftUnlock[i]);
  78. }
  79. }
  80. {
  81. const char* RoomUnlock = element->Attribute("RoomUnlock");
  82. std::vector<std::string> vecRoomUnlock;
  83. boost::split(vecRoomUnlock, RoomUnlock, boost::is_any_of(","));
  84. for (unsigned int i = 0; i < vecRoomUnlock.size(); i++)
  85. {
  86. data.mRoomUnlock.push_back(vecRoomUnlock[i]);
  87. }
  88. }
  89. {
  90. const char* FishItemUnlock = element->Attribute("FishItemUnlock");
  91. std::vector<std::string> vecFishItemUnlock;
  92. boost::split(vecFishItemUnlock, FishItemUnlock, boost::is_any_of(","));
  93. for (unsigned int i = 0; i < vecFishItemUnlock.size(); i++)
  94. {
  95. data.mFishItemUnlock.push_back(vecFishItemUnlock[i]);
  96. }
  97. }
  98. data.mVipName = element->IntAttribute("VipName");
  99. data.mGiveTicket = element->IntAttribute("GiveTicket");
  100. data.mAttendance = element->IntAttribute("Attendance");
  101. data.mDailyLottery = element->IntAttribute("DailyLottery");
  102. data.mBrokenGift = element->IntAttribute("BrokenGift");
  103. data.mBankruptcyRelief = element->IntAttribute("BankruptcyRelief");
  104. data.mTodayMaxGold = element->IntAttribute("TodayMaxGold");
  105. data.mPropGun = element->IntAttribute("PropGun");
  106. data.mPropGunName = element->Attribute("PropGunName");
  107. data.mPropGunNameImg = element->Attribute("PropGunNameImg");
  108. data.mPropGunIcon = element->Attribute("PropGunIcon");
  109. {
  110. const char* CanStar = element->Attribute("CanStar");
  111. std::vector<std::string> vecCanStar;
  112. boost::split(vecCanStar, CanStar, boost::is_any_of(","));
  113. int temp;
  114. for (unsigned int i = 0; i < vecCanStar.size(); i++)
  115. {
  116. if (tinyxml2::XMLUtil::ToInt(vecCanStar[i].c_str(), &temp))
  117. {
  118. data.mCanStar.push_back(temp);
  119. }
  120. }
  121. }
  122. {
  123. const char* StarFixed = element->Attribute("StarFixed");
  124. std::vector<std::string> vecStarFixed;
  125. boost::split(vecStarFixed, StarFixed, boost::is_any_of(","));
  126. int temp;
  127. for (unsigned int i = 0; i < vecStarFixed.size(); i++)
  128. {
  129. if (tinyxml2::XMLUtil::ToInt(vecStarFixed[i].c_str(), &temp))
  130. {
  131. data.mStarFixed.push_back(temp);
  132. }
  133. }
  134. }
  135. data.mBuyMaterialsGiftLimit = element->IntAttribute("BuyMaterialsGiftLimit");
  136. data.mBuyWeekLimit = element->IntAttribute("BuyWeekLimit");
  137. {
  138. const char* BagShopSort = element->Attribute("BagShopSort");
  139. std::vector<std::string> vecBagShopSort;
  140. boost::split(vecBagShopSort, BagShopSort, boost::is_any_of(","));
  141. int temp;
  142. for (unsigned int i = 0; i < vecBagShopSort.size(); i++)
  143. {
  144. if (tinyxml2::XMLUtil::ToInt(vecBagShopSort[i].c_str(), &temp))
  145. {
  146. data.mBagShopSort.push_back(temp);
  147. }
  148. }
  149. }
  150. {
  151. const char* GoldShopSort = element->Attribute("GoldShopSort");
  152. std::vector<std::string> vecGoldShopSort;
  153. boost::split(vecGoldShopSort, GoldShopSort, boost::is_any_of(","));
  154. int temp;
  155. for (unsigned int i = 0; i < vecGoldShopSort.size(); i++)
  156. {
  157. if (tinyxml2::XMLUtil::ToInt(vecGoldShopSort[i].c_str(), &temp))
  158. {
  159. data.mGoldShopSort.push_back(temp);
  160. }
  161. }
  162. }
  163. {
  164. const char* GemShopSort = element->Attribute("GemShopSort");
  165. std::vector<std::string> vecGemShopSort;
  166. boost::split(vecGemShopSort, GemShopSort, boost::is_any_of(","));
  167. int temp;
  168. for (unsigned int i = 0; i < vecGemShopSort.size(); i++)
  169. {
  170. if (tinyxml2::XMLUtil::ToInt(vecGemShopSort[i].c_str(), &temp))
  171. {
  172. data.mGemShopSort.push_back(temp);
  173. }
  174. }
  175. }
  176. data.mTurretAddRate = element->IntAttribute("TurretAddRate");
  177. data.mSquamaExchange = element->IntAttribute("SquamaExchange");
  178. data.mAirDropsNumber = element->IntAttribute("AirDropsNumber");
  179. data.mOnlineRewardMultiples = element->FloatAttribute("OnlineRewardMultiples");
  180. data.mGoldenTurtleTime = element->IntAttribute("GoldenTurtleTime");
  181. data.mRechargeGoldRewardEx = element->IntAttribute("RechargeGoldRewardEx");
  182. {
  183. const char* DisplayVipReward1 = element->Attribute("DisplayVipReward1");
  184. std::vector<std::string> vecDisplayVipReward1;
  185. boost::split(vecDisplayVipReward1, DisplayVipReward1, boost::is_any_of(","));
  186. int temp;
  187. for (unsigned int i = 0; i < vecDisplayVipReward1.size(); i++)
  188. {
  189. if (tinyxml2::XMLUtil::ToInt(vecDisplayVipReward1[i].c_str(), &temp))
  190. {
  191. data.mDisplayVipReward1.push_back(temp);
  192. }
  193. }
  194. }
  195. {
  196. const char* VipReward1 = element->Attribute("VipReward1");
  197. std::vector<std::string> vecVipReward1;
  198. boost::split(vecVipReward1, VipReward1, boost::is_any_of(","));
  199. int temp;
  200. for (unsigned int i = 0; i < vecVipReward1.size(); i++)
  201. {
  202. if (tinyxml2::XMLUtil::ToInt(vecVipReward1[i].c_str(), &temp))
  203. {
  204. data.mVipReward1.push_back(temp);
  205. }
  206. }
  207. }
  208. {
  209. const char* DisplayVipReward2 = element->Attribute("DisplayVipReward2");
  210. std::vector<std::string> vecDisplayVipReward2;
  211. boost::split(vecDisplayVipReward2, DisplayVipReward2, boost::is_any_of(","));
  212. int temp;
  213. for (unsigned int i = 0; i < vecDisplayVipReward2.size(); i++)
  214. {
  215. if (tinyxml2::XMLUtil::ToInt(vecDisplayVipReward2[i].c_str(), &temp))
  216. {
  217. data.mDisplayVipReward2.push_back(temp);
  218. }
  219. }
  220. }
  221. data.mArenaUp = element->IntAttribute("ArenaUp");
  222. data.mVipMoney = element->IntAttribute("VipMoney");
  223. {
  224. const char* VipReward2 = element->Attribute("VipReward2");
  225. std::vector<std::string> vecVipReward2;
  226. boost::split(vecVipReward2, VipReward2, boost::is_any_of(","));
  227. int temp;
  228. for (unsigned int i = 0; i < vecVipReward2.size(); i++)
  229. {
  230. if (tinyxml2::XMLUtil::ToInt(vecVipReward2[i].c_str(), &temp))
  231. {
  232. data.mVipReward2.push_back(temp);
  233. }
  234. }
  235. }
  236. data.mPersonalPoolRebate = element->IntAttribute("PersonalPoolRebate");
  237. if (mMapData.find(data.mVipLv) != mMapData.end())std::cout <<"data refind:" << data.mVipLv << std::endl;
  238. assert(mMapData.find(data.mVipLv) == mMapData.end());
  239. mMapData.insert(std::make_pair(data.mVipLv, data));
  240. element = element->NextSiblingElement();
  241. }
  242. }
  243. void M_VIPProfitCFG::Load()
  244. {
  245. Load("../Config/M_VIPProfitCFG.xml");
  246. }
  247. M_VIPProfitCFG* M_VIPProfitCFG::GetSingleton()
  248. {
  249. if (msSingleton.get() == nullptr)
  250. {
  251. msSingleton.reset(new M_VIPProfitCFG());
  252. }
  253. return msSingleton.get();
  254. }