Fish_FishCFG.cpp 6.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231
  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_FishCFG.h"
  10. #include "FileEncrypt.h"
  11. std::auto_ptr<Fish_FishCFG> Fish_FishCFG::msSingleton(nullptr);
  12. int Fish_FishCFG::GetCount()
  13. {
  14. return (int)mMapData.size();
  15. }
  16. const Fish_FishCFGData* Fish_FishCFG::GetData(int ID)
  17. {
  18. auto it = mMapData.find(ID);
  19. if (it != mMapData.end())
  20. {
  21. return &it->second;
  22. }
  23. return NULL;
  24. }
  25. boost::unordered_map<int, Fish_FishCFGData>& Fish_FishCFG::GetMapData()
  26. {
  27. return mMapData;
  28. }
  29. void Fish_FishCFG::Reload()
  30. {
  31. mMapData.clear();
  32. Load();
  33. }
  34. void Fish_FishCFG::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_FishCFGData data;
  67. data.mID = element->IntAttribute("ID");
  68. data.mFishName = element->Attribute("FishName");
  69. data.mModelID = element->IntAttribute("ModelID");
  70. data.mScore = element->IntAttribute("Score");
  71. data.mFishPoints = element->IntAttribute("FishPoints");
  72. {
  73. const char* Dimensity = element->Attribute("Dimensity");
  74. std::vector<std::string> vecDimensity;
  75. boost::split(vecDimensity, Dimensity, boost::is_any_of(","));
  76. int temp;
  77. for (unsigned int i = 0; i < vecDimensity.size(); i++)
  78. {
  79. if (tinyxml2::XMLUtil::ToInt(vecDimensity[i].c_str(), &temp))
  80. {
  81. data.mDimensity.push_back(temp);
  82. }
  83. }
  84. }
  85. data.mType = element->IntAttribute("Type");
  86. data.mDropGem = element->IntAttribute("DropGem");
  87. data.mShowRadius = element->IntAttribute("ShowRadius");
  88. data.mLayer = element->IntAttribute("Layer");
  89. data.mCanNetHit = element->BoolAttribute("CanNetHit");
  90. {
  91. const char* ServerDieParam = element->Attribute("ServerDieParam");
  92. std::vector<std::string> vecServerDieParam;
  93. boost::split(vecServerDieParam, ServerDieParam, boost::is_any_of(","));
  94. int temp;
  95. for (unsigned int i = 0; i < vecServerDieParam.size(); i++)
  96. {
  97. if (tinyxml2::XMLUtil::ToInt(vecServerDieParam[i].c_str(), &temp))
  98. {
  99. data.mServerDieParam.push_back(temp);
  100. }
  101. }
  102. }
  103. {
  104. const char* DieEffectParam = element->Attribute("DieEffectParam");
  105. std::vector<std::string> vecDieEffectParam;
  106. boost::split(vecDieEffectParam, DieEffectParam, boost::is_any_of(","));
  107. float temp;
  108. for (unsigned int i = 0; i < vecDieEffectParam.size(); i++)
  109. {
  110. if (tinyxml2::XMLUtil::ToFloat(vecDieEffectParam[i].c_str(), &temp))
  111. {
  112. data.mDieEffectParam.push_back(temp);
  113. }
  114. }
  115. }
  116. data.mDieEffect = element->IntAttribute("DieEffect");
  117. data.mShockScreen = element->BoolAttribute("ShockScreen");
  118. data.mDropGold = element->IntAttribute("DropGold");
  119. data.mEffectType = element->IntAttribute("EffectType");
  120. data.mGoldPlate = element->IntAttribute("GoldPlate");
  121. data.mScreenPlate = element->IntAttribute("ScreenPlate");
  122. {
  123. const char* DieSoundID = element->Attribute("DieSoundID");
  124. std::vector<std::string> vecDieSoundID;
  125. boost::split(vecDieSoundID, DieSoundID, boost::is_any_of(","));
  126. int temp;
  127. for (unsigned int i = 0; i < vecDieSoundID.size(); i++)
  128. {
  129. if (tinyxml2::XMLUtil::ToInt(vecDieSoundID[i].c_str(), &temp))
  130. {
  131. data.mDieSoundID.push_back(temp);
  132. }
  133. }
  134. }
  135. data.mShowBook = element->BoolAttribute("ShowBook");
  136. data.mBookIcon = element->Attribute("BookIcon");
  137. data.mBookScale = element->FloatAttribute("BookScale");
  138. data.mBookName = element->Attribute("BookName");
  139. data.mBookInfo = element->Attribute("BookInfo");
  140. data.mIsBOSS = element->BoolAttribute("IsBOSS");
  141. data.mIsFrozen = element->BoolAttribute("IsFrozen");
  142. data.mIsLottery = element->BoolAttribute("IsLottery");
  143. data.mShowStar = element->BoolAttribute("ShowStar");
  144. data.mRadius = element->FloatAttribute("Radius");
  145. data.mDisplayItem = element->IntAttribute("DisplayItem");
  146. {
  147. const char* ItemBubble = element->Attribute("ItemBubble");
  148. std::vector<std::string> vecItemBubble;
  149. boost::split(vecItemBubble, ItemBubble, boost::is_any_of(","));
  150. int temp;
  151. for (unsigned int i = 0; i < vecItemBubble.size(); i++)
  152. {
  153. if (tinyxml2::XMLUtil::ToInt(vecItemBubble[i].c_str(), &temp))
  154. {
  155. data.mItemBubble.push_back(temp);
  156. }
  157. }
  158. }
  159. {
  160. const char* ChatBubble = element->Attribute("ChatBubble");
  161. std::vector<std::string> vecChatBubble;
  162. boost::split(vecChatBubble, ChatBubble, boost::is_any_of(","));
  163. int temp;
  164. for (unsigned int i = 0; i < vecChatBubble.size(); i++)
  165. {
  166. if (tinyxml2::XMLUtil::ToInt(vecChatBubble[i].c_str(), &temp))
  167. {
  168. data.mChatBubble.push_back(temp);
  169. }
  170. }
  171. }
  172. {
  173. const char* ChatOffset = element->Attribute("ChatOffset");
  174. std::vector<std::string> vecChatOffset;
  175. boost::split(vecChatOffset, ChatOffset, boost::is_any_of(","));
  176. int temp;
  177. for (unsigned int i = 0; i < vecChatOffset.size(); i++)
  178. {
  179. if (tinyxml2::XMLUtil::ToInt(vecChatOffset[i].c_str(), &temp))
  180. {
  181. data.mChatOffset.push_back(temp);
  182. }
  183. }
  184. }
  185. data.mItemBubbleScale = element->FloatAttribute("ItemBubbleScale");
  186. data.mCanBomb = element->BoolAttribute("CanBomb");
  187. data.mShowIndex = element->IntAttribute("ShowIndex");
  188. data.mShowType = element->IntAttribute("ShowType");
  189. data.mShowScore = element->Attribute("ShowScore");
  190. data.mBombRange = element->IntAttribute("BombRange");
  191. data.mCanHitByBulletHead = element->Attribute("CanHitByBulletHead");
  192. data.mScoreType = element->IntAttribute("ScoreType");
  193. {
  194. const char* TimesRange = element->Attribute("TimesRange");
  195. std::vector<std::string> vecTimesRange;
  196. boost::split(vecTimesRange, TimesRange, boost::is_any_of(","));
  197. int temp;
  198. for (unsigned int i = 0; i < vecTimesRange.size(); i++)
  199. {
  200. if (tinyxml2::XMLUtil::ToInt(vecTimesRange[i].c_str(), &temp))
  201. {
  202. data.mTimesRange.push_back(temp);
  203. }
  204. }
  205. }
  206. data.mKillAndSendScore = element->IntAttribute("KillAndSendScore");
  207. if (mMapData.find(data.mID) != mMapData.end())std::cout <<"data refind:" << data.mID << std::endl;
  208. assert(mMapData.find(data.mID) == mMapData.end());
  209. mMapData.insert(std::make_pair(data.mID, data));
  210. element = element->NextSiblingElement();
  211. }
  212. }
  213. void Fish_FishCFG::Load()
  214. {
  215. Load("../Config/Fish_FishCFG.xml");
  216. }
  217. Fish_FishCFG* Fish_FishCFG::GetSingleton()
  218. {
  219. if (msSingleton.get() == nullptr)
  220. {
  221. msSingleton.reset(new Fish_FishCFG());
  222. }
  223. return msSingleton.get();
  224. }