Fish_TurretLevelCFG.cpp 7.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235
  1. #include "stdafx.h"
  2. #include "tinyxml2/tinyxml2.h"
  3. #include "LuaCfgHelper.h"
  4. #include <iostream>
  5. #include <boost/algorithm/string.hpp>
  6. #include "Fish_TurretLevelCFG.h"
  7. std::auto_ptr<Fish_TurretLevelCFG> Fish_TurretLevelCFG::msSingleton(nullptr);
  8. int Fish_TurretLevelCFG::GetCount()
  9. {
  10. return (int)mMapData.size();
  11. }
  12. const Fish_TurretLevelCFGData* Fish_TurretLevelCFG::GetData(int ID)
  13. {
  14. auto it = mMapData.find(ID);
  15. if (it != mMapData.end())
  16. {
  17. return &it->second;
  18. }
  19. return NULL;
  20. }
  21. const std::map<int, Fish_TurretLevelCFGData>& Fish_TurretLevelCFG::GetMapData()
  22. {
  23. return mMapData;
  24. }
  25. void Fish_TurretLevelCFG::Load()
  26. {
  27. tinyxml2::XMLDocument xmlDoc;
  28. std::string content = FileUtils::getInstance()->getStringFromFile("Config/Fish_TurretLevelCFG.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. Fish_TurretLevelCFGData data;
  46. data.mID = element->IntAttribute("ID");
  47. data.mOpenRate = element->IntAttribute("OpenRate");
  48. data.mAwardGold = element->IntAttribute("AwardGold");
  49. data.mOneTickUp = element->IntAttribute("OneTickUp");
  50. data.mShotsBuff = element->IntAttribute("ShotsBuff");
  51. data.mLevelUpIcon = element->Attribute("LevelUpIcon");
  52. data.mUpType = element->IntAttribute("UpType");
  53. data.mUpRate = element->IntAttribute("UpRate");
  54. data.mNeedLucky = element->IntAttribute("NeedLucky");
  55. {
  56. const char* NeedItems = element->Attribute("NeedItems");
  57. std::vector<std::string> vecNeedItems;
  58. boost::split(vecNeedItems, NeedItems, boost::is_any_of(","));
  59. int temp;
  60. for (unsigned int i = 0; i < vecNeedItems.size(); i++)
  61. {
  62. if (tinyxml2::XMLUtil::ToInt(vecNeedItems[i].c_str(), &temp))
  63. {
  64. data.mNeedItems.push_back(temp);
  65. }
  66. }
  67. }
  68. {
  69. const char* NeedCount = element->Attribute("NeedCount");
  70. std::vector<std::string> vecNeedCount;
  71. boost::split(vecNeedCount, NeedCount, boost::is_any_of(","));
  72. int temp;
  73. for (unsigned int i = 0; i < vecNeedCount.size(); i++)
  74. {
  75. if (tinyxml2::XMLUtil::ToInt(vecNeedCount[i].c_str(), &temp))
  76. {
  77. data.mNeedCount.push_back(temp);
  78. }
  79. }
  80. }
  81. {
  82. const char* ExtraUpgrade = element->Attribute("ExtraUpgrade");
  83. std::vector<std::string> vecExtraUpgrade;
  84. boost::split(vecExtraUpgrade, ExtraUpgrade, boost::is_any_of(","));
  85. int temp;
  86. for (unsigned int i = 0; i < vecExtraUpgrade.size(); i++)
  87. {
  88. if (tinyxml2::XMLUtil::ToInt(vecExtraUpgrade[i].c_str(), &temp))
  89. {
  90. data.mExtraUpgrade.push_back(temp);
  91. }
  92. }
  93. }
  94. data.mDropAttenuates = element->IntAttribute("DropAttenuates");
  95. {
  96. const char* DailyQuestGroup = element->Attribute("DailyQuestGroup");
  97. std::vector<std::string> vecDailyQuestGroup;
  98. boost::split(vecDailyQuestGroup, DailyQuestGroup, boost::is_any_of(","));
  99. int temp;
  100. for (unsigned int i = 0; i < vecDailyQuestGroup.size(); i++)
  101. {
  102. if (tinyxml2::XMLUtil::ToInt(vecDailyQuestGroup[i].c_str(), &temp))
  103. {
  104. data.mDailyQuestGroup.push_back(temp);
  105. }
  106. }
  107. }
  108. data.mDropLimit = element->IntAttribute("DropLimit");
  109. {
  110. const char* TaskItems = element->Attribute("TaskItems");
  111. std::vector<std::string> vecTaskItems;
  112. boost::split(vecTaskItems, TaskItems, boost::is_any_of(","));
  113. int temp;
  114. for (unsigned int i = 0; i < vecTaskItems.size(); i++)
  115. {
  116. if (tinyxml2::XMLUtil::ToInt(vecTaskItems[i].c_str(), &temp))
  117. {
  118. data.mTaskItems.push_back(temp);
  119. }
  120. }
  121. }
  122. {
  123. const char* QuantityOfArticles = element->Attribute("QuantityOfArticles");
  124. std::vector<std::string> vecQuantityOfArticles;
  125. boost::split(vecQuantityOfArticles, QuantityOfArticles, boost::is_any_of(","));
  126. int temp;
  127. for (unsigned int i = 0; i < vecQuantityOfArticles.size(); i++)
  128. {
  129. if (tinyxml2::XMLUtil::ToInt(vecQuantityOfArticles[i].c_str(), &temp))
  130. {
  131. data.mQuantityOfArticles.push_back(temp);
  132. }
  133. }
  134. }
  135. data.mTaskDisplay = element->IntAttribute("TaskDisplay");
  136. {
  137. const char* UnlockDisplayID = element->Attribute("UnlockDisplayID");
  138. std::vector<std::string> vecUnlockDisplayID;
  139. boost::split(vecUnlockDisplayID, UnlockDisplayID, boost::is_any_of(","));
  140. int temp;
  141. for (unsigned int i = 0; i < vecUnlockDisplayID.size(); i++)
  142. {
  143. if (tinyxml2::XMLUtil::ToInt(vecUnlockDisplayID[i].c_str(), &temp))
  144. {
  145. data.mUnlockDisplayID.push_back(temp);
  146. }
  147. }
  148. }
  149. {
  150. const char* UnlockDisplayMasks = element->Attribute("UnlockDisplayMasks");
  151. std::vector<std::string> vecUnlockDisplayMasks;
  152. boost::split(vecUnlockDisplayMasks, UnlockDisplayMasks, boost::is_any_of(","));
  153. int temp;
  154. for (unsigned int i = 0; i < vecUnlockDisplayMasks.size(); i++)
  155. {
  156. if (tinyxml2::XMLUtil::ToInt(vecUnlockDisplayMasks[i].c_str(), &temp))
  157. {
  158. data.mUnlockDisplayMasks.push_back(temp);
  159. }
  160. }
  161. }
  162. if (mMapData.find(data.mID) != mMapData.end())std::cout <<"data refind:" << data.mID << std::endl;
  163. CCASSERT(mMapData.find(data.mID) == mMapData.end(), "data.mID is exists");
  164. mMapData.insert(std::make_pair(data.mID, data));
  165. element = element->NextSiblingElement();
  166. }
  167. CCLOG("Fish_TurretLevelCFG Loaded. Load Data:%u", mMapData.size());
  168. }
  169. void Fish_TurretLevelCFG::LoadLua()
  170. {
  171. LuaEngine::getInstance()->executeScriptFile("config/Fish_TurretLevelCFG");
  172. lua_State* L = LuaEngine::getInstance()->getLuaStack()->getLuaState();
  173. lua_getglobal(L, "Fish_TurretLevelCFG");
  174. CCASSERT(lua_istable(L, -1) == 1, "is not table");
  175. lua_pushstring(L, "datas");
  176. lua_gettable(L, -2);
  177. CCASSERT(lua_istable(L, -1) == 1, "is not table");
  178. lua_pushnil(L);
  179. while(lua_next(L, 2))
  180. {
  181. CCASSERT(lua_istable(L, -1) == 1, "is not table");
  182. Fish_TurretLevelCFGData data;
  183. LuaCfgHelper::readInt(L, "ID", data.mID);
  184. LuaCfgHelper::readInt(L, "OpenRate", data.mOpenRate);
  185. LuaCfgHelper::readInt(L, "AwardGold", data.mAwardGold);
  186. LuaCfgHelper::readInt(L, "OneTickUp", data.mOneTickUp);
  187. LuaCfgHelper::readInt(L, "ShotsBuff", data.mShotsBuff);
  188. LuaCfgHelper::readString(L, "LevelUpIcon", data.mLevelUpIcon);
  189. LuaCfgHelper::readInt(L, "UpType", data.mUpType);
  190. LuaCfgHelper::readInt(L, "UpRate", data.mUpRate);
  191. LuaCfgHelper::readInt(L, "NeedLucky", data.mNeedLucky);
  192. LuaCfgHelper::readVectorInt(L, "NeedItems", data.mNeedItems);
  193. LuaCfgHelper::readVectorInt(L, "NeedCount", data.mNeedCount);
  194. LuaCfgHelper::readVectorInt(L, "ExtraUpgrade", data.mExtraUpgrade);
  195. LuaCfgHelper::readInt(L, "DropAttenuates", data.mDropAttenuates);
  196. LuaCfgHelper::readVectorInt(L, "DailyQuestGroup", data.mDailyQuestGroup);
  197. LuaCfgHelper::readInt(L, "DropLimit", data.mDropLimit);
  198. LuaCfgHelper::readVectorInt(L, "TaskItems", data.mTaskItems);
  199. LuaCfgHelper::readVectorInt(L, "QuantityOfArticles", data.mQuantityOfArticles);
  200. LuaCfgHelper::readInt(L, "TaskDisplay", data.mTaskDisplay);
  201. LuaCfgHelper::readVectorInt(L, "UnlockDisplayID", data.mUnlockDisplayID);
  202. LuaCfgHelper::readVectorInt(L, "UnlockDisplayMasks", data.mUnlockDisplayMasks);
  203. if (mMapData.find(data.mID) != mMapData.end())std::cout <<"data refind:" << data.mID << std::endl;
  204. CCASSERT(mMapData.find(data.mID) == mMapData.end(), "data.mID is exists");
  205. mMapData.insert(std::make_pair(data.mID, data));
  206. lua_pop(L, 1);
  207. }
  208. lua_settop(L, 0);
  209. CCLOG("Fish_TurretLevelCFG Loaded. Load Data:%u", mMapData.size());
  210. }
  211. void Fish_TurretLevelCFG::Reload()
  212. {
  213. mMapData.clear();
  214. Load();
  215. }
  216. Fish_TurretLevelCFG* Fish_TurretLevelCFG::GetSingleton()
  217. {
  218. if (msSingleton.get() == nullptr)
  219. {
  220. msSingleton.reset(new Fish_TurretLevelCFG());
  221. }
  222. return msSingleton.get();
  223. }
  224. void Fish_TurretLevelCFG::Release()
  225. {
  226. msSingleton.reset(nullptr);
  227. }