Fish_GiantSharkIntegral.cpp 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141
  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_GiantSharkIntegral.h"
  7. std::auto_ptr<Fish_GiantSharkIntegral> Fish_GiantSharkIntegral::msSingleton(nullptr);
  8. int Fish_GiantSharkIntegral::GetCount()
  9. {
  10. return (int)mMapData.size();
  11. }
  12. const Fish_GiantSharkIntegralData* Fish_GiantSharkIntegral::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_GiantSharkIntegralData>& Fish_GiantSharkIntegral::GetMapData()
  22. {
  23. return mMapData;
  24. }
  25. void Fish_GiantSharkIntegral::Load()
  26. {
  27. tinyxml2::XMLDocument xmlDoc;
  28. std::string content = FileUtils::getInstance()->getStringFromFile("Config/Fish_GiantSharkIntegral.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_GiantSharkIntegralData data;
  46. data.mID = element->IntAttribute("ID");
  47. data.mName = element->Attribute("Name");
  48. data.mMinimumIntegral = element->IntAttribute("MinimumIntegral");
  49. data.mMaximumIntegral = element->IntAttribute("MaximumIntegral");
  50. data.mGold = element->IntAttribute("Gold");
  51. data.mAdditionalRewards = element->IntAttribute("AdditionalRewards");
  52. data.mRewardCard = element->IntAttribute("RewardCard");
  53. data.mDisplaySort = element->IntAttribute("DisplaySort");
  54. data.mDisplayCardType = element->Attribute("DisplayCardType");
  55. data.mNewGiftWeight = element->IntAttribute("NewGiftWeight");
  56. data.mNewWeight = element->IntAttribute("NewWeight");
  57. data.mGiftWeight = element->IntAttribute("GiftWeight");
  58. data.mComWeight = element->IntAttribute("ComWeight");
  59. data.mNorWeight = element->IntAttribute("NorWeight");
  60. data.mOnListWeight = element->IntAttribute("OnListWeight");
  61. data.mNewGiftWeight1 = element->IntAttribute("NewGiftWeight1");
  62. data.mNewWeight1 = element->IntAttribute("NewWeight1");
  63. data.mGiftWeight1 = element->IntAttribute("GiftWeight1");
  64. data.mComWeight1 = element->IntAttribute("ComWeight1");
  65. data.mNorWeight1 = element->IntAttribute("NorWeight1");
  66. data.mOnListWeight1 = element->IntAttribute("OnListWeight1");
  67. if (mMapData.find(data.mID) != mMapData.end())std::cout <<"data refind:" << data.mID << std::endl;
  68. CCASSERT(mMapData.find(data.mID) == mMapData.end(), "data.mID is exists");
  69. mMapData.insert(std::make_pair(data.mID, data));
  70. element = element->NextSiblingElement();
  71. }
  72. CCLOG("Fish_GiantSharkIntegral Loaded. Load Data:%u", mMapData.size());
  73. }
  74. void Fish_GiantSharkIntegral::LoadLua()
  75. {
  76. LuaEngine::getInstance()->executeScriptFile("config/Fish_GiantSharkIntegral");
  77. lua_State* L = LuaEngine::getInstance()->getLuaStack()->getLuaState();
  78. lua_getglobal(L, "Fish_GiantSharkIntegral");
  79. CCASSERT(lua_istable(L, -1) == 1, "is not table");
  80. lua_pushstring(L, "datas");
  81. lua_gettable(L, -2);
  82. CCASSERT(lua_istable(L, -1) == 1, "is not table");
  83. lua_pushnil(L);
  84. while(lua_next(L, 2))
  85. {
  86. CCASSERT(lua_istable(L, -1) == 1, "is not table");
  87. Fish_GiantSharkIntegralData data;
  88. LuaCfgHelper::readInt(L, "ID", data.mID);
  89. LuaCfgHelper::readString(L, "Name", data.mName);
  90. LuaCfgHelper::readInt(L, "MinimumIntegral", data.mMinimumIntegral);
  91. LuaCfgHelper::readInt(L, "MaximumIntegral", data.mMaximumIntegral);
  92. LuaCfgHelper::readInt(L, "Gold", data.mGold);
  93. LuaCfgHelper::readInt(L, "AdditionalRewards", data.mAdditionalRewards);
  94. LuaCfgHelper::readInt(L, "RewardCard", data.mRewardCard);
  95. LuaCfgHelper::readInt(L, "DisplaySort", data.mDisplaySort);
  96. LuaCfgHelper::readString(L, "DisplayCardType", data.mDisplayCardType);
  97. LuaCfgHelper::readInt(L, "NewGiftWeight", data.mNewGiftWeight);
  98. LuaCfgHelper::readInt(L, "NewWeight", data.mNewWeight);
  99. LuaCfgHelper::readInt(L, "GiftWeight", data.mGiftWeight);
  100. LuaCfgHelper::readInt(L, "ComWeight", data.mComWeight);
  101. LuaCfgHelper::readInt(L, "NorWeight", data.mNorWeight);
  102. LuaCfgHelper::readInt(L, "OnListWeight", data.mOnListWeight);
  103. LuaCfgHelper::readInt(L, "NewGiftWeight1", data.mNewGiftWeight1);
  104. LuaCfgHelper::readInt(L, "NewWeight1", data.mNewWeight1);
  105. LuaCfgHelper::readInt(L, "GiftWeight1", data.mGiftWeight1);
  106. LuaCfgHelper::readInt(L, "ComWeight1", data.mComWeight1);
  107. LuaCfgHelper::readInt(L, "NorWeight1", data.mNorWeight1);
  108. LuaCfgHelper::readInt(L, "OnListWeight1", data.mOnListWeight1);
  109. if (mMapData.find(data.mID) != mMapData.end())std::cout <<"data refind:" << data.mID << std::endl;
  110. CCASSERT(mMapData.find(data.mID) == mMapData.end(), "data.mID is exists");
  111. mMapData.insert(std::make_pair(data.mID, data));
  112. lua_pop(L, 1);
  113. }
  114. lua_settop(L, 0);
  115. CCLOG("Fish_GiantSharkIntegral Loaded. Load Data:%u", mMapData.size());
  116. }
  117. void Fish_GiantSharkIntegral::Reload()
  118. {
  119. mMapData.clear();
  120. Load();
  121. }
  122. Fish_GiantSharkIntegral* Fish_GiantSharkIntegral::GetSingleton()
  123. {
  124. if (msSingleton.get() == nullptr)
  125. {
  126. msSingleton.reset(new Fish_GiantSharkIntegral());
  127. }
  128. return msSingleton.get();
  129. }
  130. void Fish_GiantSharkIntegral::Release()
  131. {
  132. msSingleton.reset(nullptr);
  133. }