Odds2_VIP.cpp 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107
  1. #include "stdafx.h"
  2. #include "tinyxml2/tinyxml2.h"
  3. #include "LuaCfgHelper.h"
  4. #include <iostream>
  5. #include <boost/algorithm/string.hpp>
  6. #include "Odds2_VIP.h"
  7. std::auto_ptr<Odds2_VIP> Odds2_VIP::msSingleton(nullptr);
  8. int Odds2_VIP::GetCount()
  9. {
  10. return (int)mMapData.size();
  11. }
  12. const Odds2_VIPData* Odds2_VIP::GetData(int VIPlvl)
  13. {
  14. auto it = mMapData.find(VIPlvl);
  15. if (it != mMapData.end())
  16. {
  17. return &it->second;
  18. }
  19. return NULL;
  20. }
  21. const std::map<int, Odds2_VIPData>& Odds2_VIP::GetMapData()
  22. {
  23. return mMapData;
  24. }
  25. void Odds2_VIP::Load()
  26. {
  27. tinyxml2::XMLDocument xmlDoc;
  28. std::string content = FileUtils::getInstance()->getStringFromFile("Config/Odds2_VIP.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. Odds2_VIPData data;
  46. data.mVIPlvl = element->IntAttribute("VIPlvl");
  47. data.mExpectedProfit = element->IntAttribute("ExpectedProfit");
  48. data.mBuffID = element->IntAttribute("BuffID");
  49. data.mDragonValue = element->IntAttribute("DragonValue");
  50. if (mMapData.find(data.mVIPlvl) != mMapData.end())std::cout <<"data refind:" << data.mVIPlvl << std::endl;
  51. CCASSERT(mMapData.find(data.mVIPlvl) == mMapData.end(), "data.mVIPlvl is exists");
  52. mMapData.insert(std::make_pair(data.mVIPlvl, data));
  53. element = element->NextSiblingElement();
  54. }
  55. CCLOG("Odds2_VIP Loaded. Load Data:%u", mMapData.size());
  56. }
  57. void Odds2_VIP::LoadLua()
  58. {
  59. LuaEngine::getInstance()->executeScriptFile("config/Odds2_VIP");
  60. lua_State* L = LuaEngine::getInstance()->getLuaStack()->getLuaState();
  61. lua_getglobal(L, "Odds2_VIP");
  62. CCASSERT(lua_istable(L, -1) == 1, "is not table");
  63. lua_pushstring(L, "datas");
  64. lua_gettable(L, -2);
  65. CCASSERT(lua_istable(L, -1) == 1, "is not table");
  66. lua_pushnil(L);
  67. while(lua_next(L, 2))
  68. {
  69. CCASSERT(lua_istable(L, -1) == 1, "is not table");
  70. Odds2_VIPData data;
  71. LuaCfgHelper::readInt(L, "VIPlvl", data.mVIPlvl);
  72. LuaCfgHelper::readInt(L, "ExpectedProfit", data.mExpectedProfit);
  73. LuaCfgHelper::readInt(L, "BuffID", data.mBuffID);
  74. LuaCfgHelper::readInt(L, "DragonValue", data.mDragonValue);
  75. if (mMapData.find(data.mVIPlvl) != mMapData.end())std::cout <<"data refind:" << data.mVIPlvl << std::endl;
  76. CCASSERT(mMapData.find(data.mVIPlvl) == mMapData.end(), "data.mVIPlvl is exists");
  77. mMapData.insert(std::make_pair(data.mVIPlvl, data));
  78. lua_pop(L, 1);
  79. }
  80. lua_settop(L, 0);
  81. CCLOG("Odds2_VIP Loaded. Load Data:%u", mMapData.size());
  82. }
  83. void Odds2_VIP::Reload()
  84. {
  85. mMapData.clear();
  86. Load();
  87. }
  88. Odds2_VIP* Odds2_VIP::GetSingleton()
  89. {
  90. if (msSingleton.get() == nullptr)
  91. {
  92. msSingleton.reset(new Odds2_VIP());
  93. }
  94. return msSingleton.get();
  95. }
  96. void Odds2_VIP::Release()
  97. {
  98. msSingleton.reset(nullptr);
  99. }