Fish_FishCFG.cpp 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283
  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_FishCFG.h"
  7. std::auto_ptr<Fish_FishCFG> Fish_FishCFG::msSingleton(nullptr);
  8. int Fish_FishCFG::GetCount()
  9. {
  10. return (int)mMapData.size();
  11. }
  12. const Fish_FishCFGData* Fish_FishCFG::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_FishCFGData>& Fish_FishCFG::GetMapData()
  22. {
  23. return mMapData;
  24. }
  25. void Fish_FishCFG::Load()
  26. {
  27. tinyxml2::XMLDocument xmlDoc;
  28. std::string content = FileUtils::getInstance()->getStringFromFile("Config/Fish_FishCFG.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_FishCFGData data;
  46. data.mID = element->IntAttribute("ID");
  47. data.mFishName = element->Attribute("FishName");
  48. data.mModelID = element->IntAttribute("ModelID");
  49. data.mScore = element->IntAttribute("Score");
  50. data.mFishPoints = element->IntAttribute("FishPoints");
  51. {
  52. const char* Dimensity = element->Attribute("Dimensity");
  53. std::vector<std::string> vecDimensity;
  54. boost::split(vecDimensity, Dimensity, boost::is_any_of(","));
  55. int temp;
  56. for (unsigned int i = 0; i < vecDimensity.size(); i++)
  57. {
  58. if (tinyxml2::XMLUtil::ToInt(vecDimensity[i].c_str(), &temp))
  59. {
  60. data.mDimensity.push_back(temp);
  61. }
  62. }
  63. }
  64. data.mType = element->IntAttribute("Type");
  65. data.mDropGem = element->IntAttribute("DropGem");
  66. data.mShowRadius = element->IntAttribute("ShowRadius");
  67. data.mLayer = element->IntAttribute("Layer");
  68. data.mCanNetHit = element->BoolAttribute("CanNetHit");
  69. {
  70. const char* ServerDieParam = element->Attribute("ServerDieParam");
  71. std::vector<std::string> vecServerDieParam;
  72. boost::split(vecServerDieParam, ServerDieParam, boost::is_any_of(","));
  73. int temp;
  74. for (unsigned int i = 0; i < vecServerDieParam.size(); i++)
  75. {
  76. if (tinyxml2::XMLUtil::ToInt(vecServerDieParam[i].c_str(), &temp))
  77. {
  78. data.mServerDieParam.push_back(temp);
  79. }
  80. }
  81. }
  82. {
  83. const char* DieEffectParam = element->Attribute("DieEffectParam");
  84. std::vector<std::string> vecDieEffectParam;
  85. boost::split(vecDieEffectParam, DieEffectParam, boost::is_any_of(","));
  86. float temp;
  87. for (unsigned int i = 0; i < vecDieEffectParam.size(); i++)
  88. {
  89. if (tinyxml2::XMLUtil::ToFloat(vecDieEffectParam[i].c_str(), &temp))
  90. {
  91. data.mDieEffectParam.push_back(temp);
  92. }
  93. }
  94. }
  95. data.mDieEffect = element->IntAttribute("DieEffect");
  96. data.mShockScreen = element->BoolAttribute("ShockScreen");
  97. data.mDropGold = element->IntAttribute("DropGold");
  98. data.mEffectType = element->IntAttribute("EffectType");
  99. data.mGoldPlate = element->IntAttribute("GoldPlate");
  100. data.mScreenPlate = element->IntAttribute("ScreenPlate");
  101. {
  102. const char* DieSoundID = element->Attribute("DieSoundID");
  103. std::vector<std::string> vecDieSoundID;
  104. boost::split(vecDieSoundID, DieSoundID, boost::is_any_of(","));
  105. int temp;
  106. for (unsigned int i = 0; i < vecDieSoundID.size(); i++)
  107. {
  108. if (tinyxml2::XMLUtil::ToInt(vecDieSoundID[i].c_str(), &temp))
  109. {
  110. data.mDieSoundID.push_back(temp);
  111. }
  112. }
  113. }
  114. data.mShowBook = element->BoolAttribute("ShowBook");
  115. data.mBookIcon = element->Attribute("BookIcon");
  116. data.mBookScale = element->FloatAttribute("BookScale");
  117. data.mBookName = element->Attribute("BookName");
  118. data.mBookInfo = element->Attribute("BookInfo");
  119. data.mIsBOSS = element->BoolAttribute("IsBOSS");
  120. data.mIsFrozen = element->BoolAttribute("IsFrozen");
  121. data.mIsLottery = element->BoolAttribute("IsLottery");
  122. data.mShowStar = element->BoolAttribute("ShowStar");
  123. data.mRadius = element->FloatAttribute("Radius");
  124. data.mDisplayItem = element->IntAttribute("DisplayItem");
  125. {
  126. const char* ItemBubble = element->Attribute("ItemBubble");
  127. std::vector<std::string> vecItemBubble;
  128. boost::split(vecItemBubble, ItemBubble, boost::is_any_of(","));
  129. int temp;
  130. for (unsigned int i = 0; i < vecItemBubble.size(); i++)
  131. {
  132. if (tinyxml2::XMLUtil::ToInt(vecItemBubble[i].c_str(), &temp))
  133. {
  134. data.mItemBubble.push_back(temp);
  135. }
  136. }
  137. }
  138. {
  139. const char* ChatBubble = element->Attribute("ChatBubble");
  140. std::vector<std::string> vecChatBubble;
  141. boost::split(vecChatBubble, ChatBubble, boost::is_any_of(","));
  142. int temp;
  143. for (unsigned int i = 0; i < vecChatBubble.size(); i++)
  144. {
  145. if (tinyxml2::XMLUtil::ToInt(vecChatBubble[i].c_str(), &temp))
  146. {
  147. data.mChatBubble.push_back(temp);
  148. }
  149. }
  150. }
  151. {
  152. const char* ChatOffset = element->Attribute("ChatOffset");
  153. std::vector<std::string> vecChatOffset;
  154. boost::split(vecChatOffset, ChatOffset, boost::is_any_of(","));
  155. int temp;
  156. for (unsigned int i = 0; i < vecChatOffset.size(); i++)
  157. {
  158. if (tinyxml2::XMLUtil::ToInt(vecChatOffset[i].c_str(), &temp))
  159. {
  160. data.mChatOffset.push_back(temp);
  161. }
  162. }
  163. }
  164. data.mItemBubbleScale = element->FloatAttribute("ItemBubbleScale");
  165. data.mCanBomb = element->BoolAttribute("CanBomb");
  166. data.mShowIndex = element->IntAttribute("ShowIndex");
  167. data.mShowType = element->IntAttribute("ShowType");
  168. data.mShowScore = element->Attribute("ShowScore");
  169. data.mBombRange = element->IntAttribute("BombRange");
  170. data.mCanHitByBulletHead = element->Attribute("CanHitByBulletHead");
  171. data.mScoreType = element->IntAttribute("ScoreType");
  172. {
  173. const char* TimesRange = element->Attribute("TimesRange");
  174. std::vector<std::string> vecTimesRange;
  175. boost::split(vecTimesRange, TimesRange, boost::is_any_of(","));
  176. int temp;
  177. for (unsigned int i = 0; i < vecTimesRange.size(); i++)
  178. {
  179. if (tinyxml2::XMLUtil::ToInt(vecTimesRange[i].c_str(), &temp))
  180. {
  181. data.mTimesRange.push_back(temp);
  182. }
  183. }
  184. }
  185. data.mKillAndSendScore = element->IntAttribute("KillAndSendScore");
  186. if (mMapData.find(data.mID) != mMapData.end())std::cout <<"data refind:" << data.mID << std::endl;
  187. CCASSERT(mMapData.find(data.mID) == mMapData.end(), "data.mID is exists");
  188. mMapData.insert(std::make_pair(data.mID, data));
  189. element = element->NextSiblingElement();
  190. }
  191. CCLOG("Fish_FishCFG Loaded. Load Data:%u", mMapData.size());
  192. }
  193. void Fish_FishCFG::LoadLua()
  194. {
  195. LuaEngine::getInstance()->executeScriptFile("config/Fish_FishCFG");
  196. lua_State* L = LuaEngine::getInstance()->getLuaStack()->getLuaState();
  197. lua_getglobal(L, "Fish_FishCFG");
  198. CCASSERT(lua_istable(L, -1) == 1, "is not table");
  199. lua_pushstring(L, "datas");
  200. lua_gettable(L, -2);
  201. CCASSERT(lua_istable(L, -1) == 1, "is not table");
  202. lua_pushnil(L);
  203. while(lua_next(L, 2))
  204. {
  205. CCASSERT(lua_istable(L, -1) == 1, "is not table");
  206. Fish_FishCFGData data;
  207. LuaCfgHelper::readInt(L, "ID", data.mID);
  208. LuaCfgHelper::readString(L, "FishName", data.mFishName);
  209. LuaCfgHelper::readInt(L, "ModelID", data.mModelID);
  210. LuaCfgHelper::readInt(L, "Score", data.mScore);
  211. LuaCfgHelper::readInt(L, "FishPoints", data.mFishPoints);
  212. LuaCfgHelper::readVectorInt(L, "Dimensity", data.mDimensity);
  213. LuaCfgHelper::readInt(L, "Type", data.mType);
  214. LuaCfgHelper::readInt(L, "DropGem", data.mDropGem);
  215. LuaCfgHelper::readInt(L, "ShowRadius", data.mShowRadius);
  216. LuaCfgHelper::readInt(L, "Layer", data.mLayer);
  217. LuaCfgHelper::readBool(L, "CanNetHit", data.mCanNetHit);
  218. LuaCfgHelper::readVectorInt(L, "ServerDieParam", data.mServerDieParam);
  219. LuaCfgHelper::readVectorFloat(L, "DieEffectParam", data.mDieEffectParam);
  220. LuaCfgHelper::readInt(L, "DieEffect", data.mDieEffect);
  221. LuaCfgHelper::readBool(L, "ShockScreen", data.mShockScreen);
  222. LuaCfgHelper::readInt(L, "DropGold", data.mDropGold);
  223. LuaCfgHelper::readInt(L, "EffectType", data.mEffectType);
  224. LuaCfgHelper::readInt(L, "GoldPlate", data.mGoldPlate);
  225. LuaCfgHelper::readInt(L, "ScreenPlate", data.mScreenPlate);
  226. LuaCfgHelper::readVectorInt(L, "DieSoundID", data.mDieSoundID);
  227. LuaCfgHelper::readBool(L, "ShowBook", data.mShowBook);
  228. LuaCfgHelper::readString(L, "BookIcon", data.mBookIcon);
  229. LuaCfgHelper::readFloat(L, "BookScale", data.mBookScale);
  230. LuaCfgHelper::readString(L, "BookName", data.mBookName);
  231. LuaCfgHelper::readString(L, "BookInfo", data.mBookInfo);
  232. LuaCfgHelper::readBool(L, "IsBOSS", data.mIsBOSS);
  233. LuaCfgHelper::readBool(L, "IsFrozen", data.mIsFrozen);
  234. LuaCfgHelper::readBool(L, "IsLottery", data.mIsLottery);
  235. LuaCfgHelper::readBool(L, "ShowStar", data.mShowStar);
  236. LuaCfgHelper::readFloat(L, "Radius", data.mRadius);
  237. LuaCfgHelper::readInt(L, "DisplayItem", data.mDisplayItem);
  238. LuaCfgHelper::readVectorInt(L, "ItemBubble", data.mItemBubble);
  239. LuaCfgHelper::readVectorInt(L, "ChatBubble", data.mChatBubble);
  240. LuaCfgHelper::readVectorInt(L, "ChatOffset", data.mChatOffset);
  241. LuaCfgHelper::readFloat(L, "ItemBubbleScale", data.mItemBubbleScale);
  242. LuaCfgHelper::readBool(L, "CanBomb", data.mCanBomb);
  243. LuaCfgHelper::readInt(L, "ShowIndex", data.mShowIndex);
  244. LuaCfgHelper::readInt(L, "ShowType", data.mShowType);
  245. LuaCfgHelper::readString(L, "ShowScore", data.mShowScore);
  246. LuaCfgHelper::readInt(L, "BombRange", data.mBombRange);
  247. LuaCfgHelper::readString(L, "CanHitByBulletHead", data.mCanHitByBulletHead);
  248. LuaCfgHelper::readInt(L, "ScoreType", data.mScoreType);
  249. LuaCfgHelper::readVectorInt(L, "TimesRange", data.mTimesRange);
  250. LuaCfgHelper::readInt(L, "KillAndSendScore", data.mKillAndSendScore);
  251. if (mMapData.find(data.mID) != mMapData.end())std::cout <<"data refind:" << data.mID << std::endl;
  252. CCASSERT(mMapData.find(data.mID) == mMapData.end(), "data.mID is exists");
  253. mMapData.insert(std::make_pair(data.mID, data));
  254. lua_pop(L, 1);
  255. }
  256. lua_settop(L, 0);
  257. CCLOG("Fish_FishCFG Loaded. Load Data:%u", mMapData.size());
  258. }
  259. void Fish_FishCFG::Reload()
  260. {
  261. mMapData.clear();
  262. Load();
  263. }
  264. Fish_FishCFG* Fish_FishCFG::GetSingleton()
  265. {
  266. if (msSingleton.get() == nullptr)
  267. {
  268. msSingleton.reset(new Fish_FishCFG());
  269. }
  270. return msSingleton.get();
  271. }
  272. void Fish_FishCFG::Release()
  273. {
  274. msSingleton.reset(nullptr);
  275. }