M_VIPProfitCFG.cpp 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307
  1. #include "stdafx.h"
  2. #include "tinyxml2/tinyxml2.h"
  3. #include "LuaCfgHelper.h"
  4. #include <iostream>
  5. #include <boost/algorithm/string.hpp>
  6. #include "M_VIPProfitCFG.h"
  7. std::auto_ptr<M_VIPProfitCFG> M_VIPProfitCFG::msSingleton(nullptr);
  8. int M_VIPProfitCFG::GetCount()
  9. {
  10. return (int)mMapData.size();
  11. }
  12. const M_VIPProfitCFGData* M_VIPProfitCFG::GetData(int VipLv)
  13. {
  14. auto it = mMapData.find(VipLv);
  15. if (it != mMapData.end())
  16. {
  17. return &it->second;
  18. }
  19. return NULL;
  20. }
  21. const std::map<int, M_VIPProfitCFGData>& M_VIPProfitCFG::GetMapData()
  22. {
  23. return mMapData;
  24. }
  25. void M_VIPProfitCFG::Load()
  26. {
  27. tinyxml2::XMLDocument xmlDoc;
  28. std::string content = FileUtils::getInstance()->getStringFromFile("Config/M_VIPProfitCFG.xml");
  29. auto result = xmlDoc.Parse(content.c_str(), content.length());
  30. if (result != tinyxml2::XML_SUCCESS)
  31. {
  32. CCLOGERROR("Result:%d", result);
  33. CCASSERT(false, "result != tinyxml2::XML_SUCCESS");
  34. return;
  35. }
  36. auto root = xmlDoc.RootElement();
  37. if (root == NULL)
  38. {
  39. CCASSERT(false, "root == NULL");
  40. return;
  41. }
  42. auto element = root->FirstChildElement("Data");
  43. while (element != NULL)
  44. {
  45. M_VIPProfitCFGData data;
  46. data.mVipLv = element->IntAttribute("VipLv");
  47. data.mVipExp = element->IntAttribute("VipExp");
  48. data.mOnlineReward = element->IntAttribute("OnlineReward");
  49. data.mMaxGiftslimit = element->IntAttribute("MaxGiftslimit");
  50. {
  51. const char* GiftUnlock = element->Attribute("GiftUnlock");
  52. std::vector<std::string> vecGiftUnlock;
  53. boost::split(vecGiftUnlock, GiftUnlock, boost::is_any_of(","));
  54. for (unsigned int i = 0; i < vecGiftUnlock.size(); i++)
  55. {
  56. data.mGiftUnlock.push_back(vecGiftUnlock[i]);
  57. }
  58. }
  59. {
  60. const char* RoomUnlock = element->Attribute("RoomUnlock");
  61. std::vector<std::string> vecRoomUnlock;
  62. boost::split(vecRoomUnlock, RoomUnlock, boost::is_any_of(","));
  63. for (unsigned int i = 0; i < vecRoomUnlock.size(); i++)
  64. {
  65. data.mRoomUnlock.push_back(vecRoomUnlock[i]);
  66. }
  67. }
  68. {
  69. const char* FishItemUnlock = element->Attribute("FishItemUnlock");
  70. std::vector<std::string> vecFishItemUnlock;
  71. boost::split(vecFishItemUnlock, FishItemUnlock, boost::is_any_of(","));
  72. for (unsigned int i = 0; i < vecFishItemUnlock.size(); i++)
  73. {
  74. data.mFishItemUnlock.push_back(vecFishItemUnlock[i]);
  75. }
  76. }
  77. data.mVipName = element->IntAttribute("VipName");
  78. data.mGiveTicket = element->IntAttribute("GiveTicket");
  79. data.mAttendance = element->IntAttribute("Attendance");
  80. data.mDailyLottery = element->IntAttribute("DailyLottery");
  81. data.mBrokenGift = element->IntAttribute("BrokenGift");
  82. data.mBankruptcyRelief = element->IntAttribute("BankruptcyRelief");
  83. data.mTodayMaxGold = element->IntAttribute("TodayMaxGold");
  84. data.mPropGun = element->IntAttribute("PropGun");
  85. data.mPropGunName = element->Attribute("PropGunName");
  86. data.mPropGunNameImg = element->Attribute("PropGunNameImg");
  87. data.mPropGunIcon = element->Attribute("PropGunIcon");
  88. {
  89. const char* CanStar = element->Attribute("CanStar");
  90. std::vector<std::string> vecCanStar;
  91. boost::split(vecCanStar, CanStar, boost::is_any_of(","));
  92. int temp;
  93. for (unsigned int i = 0; i < vecCanStar.size(); i++)
  94. {
  95. if (tinyxml2::XMLUtil::ToInt(vecCanStar[i].c_str(), &temp))
  96. {
  97. data.mCanStar.push_back(temp);
  98. }
  99. }
  100. }
  101. {
  102. const char* StarFixed = element->Attribute("StarFixed");
  103. std::vector<std::string> vecStarFixed;
  104. boost::split(vecStarFixed, StarFixed, boost::is_any_of(","));
  105. int temp;
  106. for (unsigned int i = 0; i < vecStarFixed.size(); i++)
  107. {
  108. if (tinyxml2::XMLUtil::ToInt(vecStarFixed[i].c_str(), &temp))
  109. {
  110. data.mStarFixed.push_back(temp);
  111. }
  112. }
  113. }
  114. data.mBuyMaterialsGiftLimit = element->IntAttribute("BuyMaterialsGiftLimit");
  115. data.mBuyWeekLimit = element->IntAttribute("BuyWeekLimit");
  116. {
  117. const char* BagShopSort = element->Attribute("BagShopSort");
  118. std::vector<std::string> vecBagShopSort;
  119. boost::split(vecBagShopSort, BagShopSort, boost::is_any_of(","));
  120. int temp;
  121. for (unsigned int i = 0; i < vecBagShopSort.size(); i++)
  122. {
  123. if (tinyxml2::XMLUtil::ToInt(vecBagShopSort[i].c_str(), &temp))
  124. {
  125. data.mBagShopSort.push_back(temp);
  126. }
  127. }
  128. }
  129. {
  130. const char* GoldShopSort = element->Attribute("GoldShopSort");
  131. std::vector<std::string> vecGoldShopSort;
  132. boost::split(vecGoldShopSort, GoldShopSort, boost::is_any_of(","));
  133. int temp;
  134. for (unsigned int i = 0; i < vecGoldShopSort.size(); i++)
  135. {
  136. if (tinyxml2::XMLUtil::ToInt(vecGoldShopSort[i].c_str(), &temp))
  137. {
  138. data.mGoldShopSort.push_back(temp);
  139. }
  140. }
  141. }
  142. {
  143. const char* GemShopSort = element->Attribute("GemShopSort");
  144. std::vector<std::string> vecGemShopSort;
  145. boost::split(vecGemShopSort, GemShopSort, boost::is_any_of(","));
  146. int temp;
  147. for (unsigned int i = 0; i < vecGemShopSort.size(); i++)
  148. {
  149. if (tinyxml2::XMLUtil::ToInt(vecGemShopSort[i].c_str(), &temp))
  150. {
  151. data.mGemShopSort.push_back(temp);
  152. }
  153. }
  154. }
  155. data.mTurretAddRate = element->IntAttribute("TurretAddRate");
  156. data.mSquamaExchange = element->IntAttribute("SquamaExchange");
  157. data.mAirDropsNumber = element->IntAttribute("AirDropsNumber");
  158. data.mOnlineRewardMultiples = element->FloatAttribute("OnlineRewardMultiples");
  159. data.mGoldenTurtleTime = element->IntAttribute("GoldenTurtleTime");
  160. data.mRechargeGoldRewardEx = element->IntAttribute("RechargeGoldRewardEx");
  161. {
  162. const char* DisplayVipReward1 = element->Attribute("DisplayVipReward1");
  163. std::vector<std::string> vecDisplayVipReward1;
  164. boost::split(vecDisplayVipReward1, DisplayVipReward1, boost::is_any_of(","));
  165. int temp;
  166. for (unsigned int i = 0; i < vecDisplayVipReward1.size(); i++)
  167. {
  168. if (tinyxml2::XMLUtil::ToInt(vecDisplayVipReward1[i].c_str(), &temp))
  169. {
  170. data.mDisplayVipReward1.push_back(temp);
  171. }
  172. }
  173. }
  174. {
  175. const char* VipReward1 = element->Attribute("VipReward1");
  176. std::vector<std::string> vecVipReward1;
  177. boost::split(vecVipReward1, VipReward1, boost::is_any_of(","));
  178. int temp;
  179. for (unsigned int i = 0; i < vecVipReward1.size(); i++)
  180. {
  181. if (tinyxml2::XMLUtil::ToInt(vecVipReward1[i].c_str(), &temp))
  182. {
  183. data.mVipReward1.push_back(temp);
  184. }
  185. }
  186. }
  187. {
  188. const char* DisplayVipReward2 = element->Attribute("DisplayVipReward2");
  189. std::vector<std::string> vecDisplayVipReward2;
  190. boost::split(vecDisplayVipReward2, DisplayVipReward2, boost::is_any_of(","));
  191. int temp;
  192. for (unsigned int i = 0; i < vecDisplayVipReward2.size(); i++)
  193. {
  194. if (tinyxml2::XMLUtil::ToInt(vecDisplayVipReward2[i].c_str(), &temp))
  195. {
  196. data.mDisplayVipReward2.push_back(temp);
  197. }
  198. }
  199. }
  200. data.mArenaUp = element->IntAttribute("ArenaUp");
  201. data.mVipMoney = element->IntAttribute("VipMoney");
  202. {
  203. const char* VipReward2 = element->Attribute("VipReward2");
  204. std::vector<std::string> vecVipReward2;
  205. boost::split(vecVipReward2, VipReward2, boost::is_any_of(","));
  206. int temp;
  207. for (unsigned int i = 0; i < vecVipReward2.size(); i++)
  208. {
  209. if (tinyxml2::XMLUtil::ToInt(vecVipReward2[i].c_str(), &temp))
  210. {
  211. data.mVipReward2.push_back(temp);
  212. }
  213. }
  214. }
  215. data.mPersonalPoolRebate = element->IntAttribute("PersonalPoolRebate");
  216. if (mMapData.find(data.mVipLv) != mMapData.end())std::cout <<"data refind:" << data.mVipLv << std::endl;
  217. CCASSERT(mMapData.find(data.mVipLv) == mMapData.end(), "data.mVipLv is exists");
  218. mMapData.insert(std::make_pair(data.mVipLv, data));
  219. element = element->NextSiblingElement();
  220. }
  221. CCLOG("M_VIPProfitCFG Loaded. Load Data:%u", mMapData.size());
  222. }
  223. void M_VIPProfitCFG::LoadLua()
  224. {
  225. LuaEngine::getInstance()->executeScriptFile("config/M_VIPProfitCFG");
  226. lua_State* L = LuaEngine::getInstance()->getLuaStack()->getLuaState();
  227. lua_getglobal(L, "M_VIPProfitCFG");
  228. CCASSERT(lua_istable(L, -1) == 1, "is not table");
  229. lua_pushstring(L, "datas");
  230. lua_gettable(L, -2);
  231. CCASSERT(lua_istable(L, -1) == 1, "is not table");
  232. lua_pushnil(L);
  233. while(lua_next(L, 2))
  234. {
  235. CCASSERT(lua_istable(L, -1) == 1, "is not table");
  236. M_VIPProfitCFGData data;
  237. LuaCfgHelper::readInt(L, "VipLv", data.mVipLv);
  238. LuaCfgHelper::readInt(L, "VipExp", data.mVipExp);
  239. LuaCfgHelper::readInt(L, "OnlineReward", data.mOnlineReward);
  240. LuaCfgHelper::readInt(L, "MaxGiftslimit", data.mMaxGiftslimit);
  241. LuaCfgHelper::readVectorString(L, "GiftUnlock", data.mGiftUnlock);
  242. LuaCfgHelper::readVectorString(L, "RoomUnlock", data.mRoomUnlock);
  243. LuaCfgHelper::readVectorString(L, "FishItemUnlock", data.mFishItemUnlock);
  244. LuaCfgHelper::readInt(L, "VipName", data.mVipName);
  245. LuaCfgHelper::readInt(L, "GiveTicket", data.mGiveTicket);
  246. LuaCfgHelper::readInt(L, "Attendance", data.mAttendance);
  247. LuaCfgHelper::readInt(L, "DailyLottery", data.mDailyLottery);
  248. LuaCfgHelper::readInt(L, "BrokenGift", data.mBrokenGift);
  249. LuaCfgHelper::readInt(L, "BankruptcyRelief", data.mBankruptcyRelief);
  250. LuaCfgHelper::readInt(L, "TodayMaxGold", data.mTodayMaxGold);
  251. LuaCfgHelper::readInt(L, "PropGun", data.mPropGun);
  252. LuaCfgHelper::readString(L, "PropGunName", data.mPropGunName);
  253. LuaCfgHelper::readString(L, "PropGunNameImg", data.mPropGunNameImg);
  254. LuaCfgHelper::readString(L, "PropGunIcon", data.mPropGunIcon);
  255. LuaCfgHelper::readVectorInt(L, "CanStar", data.mCanStar);
  256. LuaCfgHelper::readVectorInt(L, "StarFixed", data.mStarFixed);
  257. LuaCfgHelper::readInt(L, "BuyMaterialsGiftLimit", data.mBuyMaterialsGiftLimit);
  258. LuaCfgHelper::readInt(L, "BuyWeekLimit", data.mBuyWeekLimit);
  259. LuaCfgHelper::readVectorInt(L, "BagShopSort", data.mBagShopSort);
  260. LuaCfgHelper::readVectorInt(L, "GoldShopSort", data.mGoldShopSort);
  261. LuaCfgHelper::readVectorInt(L, "GemShopSort", data.mGemShopSort);
  262. LuaCfgHelper::readInt(L, "TurretAddRate", data.mTurretAddRate);
  263. LuaCfgHelper::readInt(L, "SquamaExchange", data.mSquamaExchange);
  264. LuaCfgHelper::readInt(L, "AirDropsNumber", data.mAirDropsNumber);
  265. LuaCfgHelper::readFloat(L, "OnlineRewardMultiples", data.mOnlineRewardMultiples);
  266. LuaCfgHelper::readInt(L, "GoldenTurtleTime", data.mGoldenTurtleTime);
  267. LuaCfgHelper::readInt(L, "RechargeGoldRewardEx", data.mRechargeGoldRewardEx);
  268. LuaCfgHelper::readVectorInt(L, "DisplayVipReward1", data.mDisplayVipReward1);
  269. LuaCfgHelper::readVectorInt(L, "VipReward1", data.mVipReward1);
  270. LuaCfgHelper::readVectorInt(L, "DisplayVipReward2", data.mDisplayVipReward2);
  271. LuaCfgHelper::readInt(L, "ArenaUp", data.mArenaUp);
  272. LuaCfgHelper::readInt(L, "VipMoney", data.mVipMoney);
  273. LuaCfgHelper::readVectorInt(L, "VipReward2", data.mVipReward2);
  274. LuaCfgHelper::readInt(L, "PersonalPoolRebate", data.mPersonalPoolRebate);
  275. if (mMapData.find(data.mVipLv) != mMapData.end())std::cout <<"data refind:" << data.mVipLv << std::endl;
  276. CCASSERT(mMapData.find(data.mVipLv) == mMapData.end(), "data.mVipLv is exists");
  277. mMapData.insert(std::make_pair(data.mVipLv, data));
  278. lua_pop(L, 1);
  279. }
  280. lua_settop(L, 0);
  281. CCLOG("M_VIPProfitCFG Loaded. Load Data:%u", mMapData.size());
  282. }
  283. void M_VIPProfitCFG::Reload()
  284. {
  285. mMapData.clear();
  286. Load();
  287. }
  288. M_VIPProfitCFG* M_VIPProfitCFG::GetSingleton()
  289. {
  290. if (msSingleton.get() == nullptr)
  291. {
  292. msSingleton.reset(new M_VIPProfitCFG());
  293. }
  294. return msSingleton.get();
  295. }
  296. void M_VIPProfitCFG::Release()
  297. {
  298. msSingleton.reset(nullptr);
  299. }