123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261 |
- #include "stdafx.h"
- #include <cassert>
- #include <fstream>
- #include <iostream>
- #include <iostream>
- #include <boost/smart_ptr.hpp>
- #include <boost/algorithm/string.hpp>
- #include "tinyxml2.h"
- #include "M_VIPProfitCFG.h"
- #include "FileEncrypt.h"
- std::auto_ptr<M_VIPProfitCFG> M_VIPProfitCFG::msSingleton(nullptr);
- int M_VIPProfitCFG::GetCount()
- {
- return (int)mMapData.size();
- }
- const M_VIPProfitCFGData* M_VIPProfitCFG::GetData(int VipLv)
- {
- auto it = mMapData.find(VipLv);
- if (it != mMapData.end())
- {
- return &it->second;
- }
- return NULL;
- }
- boost::unordered_map<int, M_VIPProfitCFGData>& M_VIPProfitCFG::GetMapData()
- {
- return mMapData;
- }
- void M_VIPProfitCFG::Reload()
- {
- mMapData.clear();
- Load();
- }
- void M_VIPProfitCFG::Load(const std::string& path)
- {
- std::ifstream readStream(path, std::ios::binary);
- if (!readStream.is_open())
- {
- assert(false);
- return;
- }
- readStream.seekg(0, std::ios::end);
- int fileSize = readStream.tellg();
- boost::shared_array<char> buffer(new char[fileSize+1]);
- buffer.get()[fileSize] = '\0';
- readStream.seekg(0, std::ios::beg);
- readStream.read(buffer.get(), fileSize);
- readStream.close();
- FileEncrypt::decryptBuffer( buffer, fileSize );
- tinyxml2::XMLDocument xmlDoc;
- auto result = xmlDoc.Parse(buffer.get(), fileSize);
- if (result != tinyxml2::XML_SUCCESS)
- {
- assert(false);
- return;
- }
- auto root = xmlDoc.RootElement();
- if (root == NULL)
- {
- assert(false);
- return;
- }
- auto element = root->FirstChildElement("Data");
- while (element != NULL)
- {
- M_VIPProfitCFGData data;
- data.mVipLv = element->IntAttribute("VipLv");
- data.mVipExp = element->IntAttribute("VipExp");
- data.mOnlineReward = element->IntAttribute("OnlineReward");
- data.mMaxGiftslimit = element->IntAttribute("MaxGiftslimit");
- {
- const char* GiftUnlock = element->Attribute("GiftUnlock");
- std::vector<std::string> vecGiftUnlock;
- boost::split(vecGiftUnlock, GiftUnlock, boost::is_any_of(","));
- for (unsigned int i = 0; i < vecGiftUnlock.size(); i++)
- {
- data.mGiftUnlock.push_back(vecGiftUnlock[i]);
- }
- }
- {
- const char* RoomUnlock = element->Attribute("RoomUnlock");
- std::vector<std::string> vecRoomUnlock;
- boost::split(vecRoomUnlock, RoomUnlock, boost::is_any_of(","));
- for (unsigned int i = 0; i < vecRoomUnlock.size(); i++)
- {
- data.mRoomUnlock.push_back(vecRoomUnlock[i]);
- }
- }
- {
- const char* FishItemUnlock = element->Attribute("FishItemUnlock");
- std::vector<std::string> vecFishItemUnlock;
- boost::split(vecFishItemUnlock, FishItemUnlock, boost::is_any_of(","));
- for (unsigned int i = 0; i < vecFishItemUnlock.size(); i++)
- {
- data.mFishItemUnlock.push_back(vecFishItemUnlock[i]);
- }
- }
- data.mVipName = element->IntAttribute("VipName");
- data.mGiveTicket = element->IntAttribute("GiveTicket");
- data.mAttendance = element->IntAttribute("Attendance");
- data.mDailyLottery = element->IntAttribute("DailyLottery");
- data.mBrokenGift = element->IntAttribute("BrokenGift");
- data.mBankruptcyRelief = element->IntAttribute("BankruptcyRelief");
- data.mTodayMaxGold = element->IntAttribute("TodayMaxGold");
- data.mPropGun = element->IntAttribute("PropGun");
- data.mPropGunName = element->Attribute("PropGunName");
- data.mPropGunNameImg = element->Attribute("PropGunNameImg");
- data.mPropGunIcon = element->Attribute("PropGunIcon");
- {
- const char* CanStar = element->Attribute("CanStar");
- std::vector<std::string> vecCanStar;
- boost::split(vecCanStar, CanStar, boost::is_any_of(","));
- int temp;
- for (unsigned int i = 0; i < vecCanStar.size(); i++)
- {
- if (tinyxml2::XMLUtil::ToInt(vecCanStar[i].c_str(), &temp))
- {
- data.mCanStar.push_back(temp);
- }
- }
- }
- {
- const char* StarFixed = element->Attribute("StarFixed");
- std::vector<std::string> vecStarFixed;
- boost::split(vecStarFixed, StarFixed, boost::is_any_of(","));
- int temp;
- for (unsigned int i = 0; i < vecStarFixed.size(); i++)
- {
- if (tinyxml2::XMLUtil::ToInt(vecStarFixed[i].c_str(), &temp))
- {
- data.mStarFixed.push_back(temp);
- }
- }
- }
- data.mBuyMaterialsGiftLimit = element->IntAttribute("BuyMaterialsGiftLimit");
- data.mBuyWeekLimit = element->IntAttribute("BuyWeekLimit");
- {
- const char* BagShopSort = element->Attribute("BagShopSort");
- std::vector<std::string> vecBagShopSort;
- boost::split(vecBagShopSort, BagShopSort, boost::is_any_of(","));
- int temp;
- for (unsigned int i = 0; i < vecBagShopSort.size(); i++)
- {
- if (tinyxml2::XMLUtil::ToInt(vecBagShopSort[i].c_str(), &temp))
- {
- data.mBagShopSort.push_back(temp);
- }
- }
- }
- {
- const char* GoldShopSort = element->Attribute("GoldShopSort");
- std::vector<std::string> vecGoldShopSort;
- boost::split(vecGoldShopSort, GoldShopSort, boost::is_any_of(","));
- int temp;
- for (unsigned int i = 0; i < vecGoldShopSort.size(); i++)
- {
- if (tinyxml2::XMLUtil::ToInt(vecGoldShopSort[i].c_str(), &temp))
- {
- data.mGoldShopSort.push_back(temp);
- }
- }
- }
- {
- const char* GemShopSort = element->Attribute("GemShopSort");
- std::vector<std::string> vecGemShopSort;
- boost::split(vecGemShopSort, GemShopSort, boost::is_any_of(","));
- int temp;
- for (unsigned int i = 0; i < vecGemShopSort.size(); i++)
- {
- if (tinyxml2::XMLUtil::ToInt(vecGemShopSort[i].c_str(), &temp))
- {
- data.mGemShopSort.push_back(temp);
- }
- }
- }
- data.mTurretAddRate = element->IntAttribute("TurretAddRate");
- data.mSquamaExchange = element->IntAttribute("SquamaExchange");
- data.mAirDropsNumber = element->IntAttribute("AirDropsNumber");
- data.mOnlineRewardMultiples = element->FloatAttribute("OnlineRewardMultiples");
- data.mGoldenTurtleTime = element->IntAttribute("GoldenTurtleTime");
- data.mRechargeGoldRewardEx = element->IntAttribute("RechargeGoldRewardEx");
- {
- const char* DisplayVipReward1 = element->Attribute("DisplayVipReward1");
- std::vector<std::string> vecDisplayVipReward1;
- boost::split(vecDisplayVipReward1, DisplayVipReward1, boost::is_any_of(","));
- int temp;
- for (unsigned int i = 0; i < vecDisplayVipReward1.size(); i++)
- {
- if (tinyxml2::XMLUtil::ToInt(vecDisplayVipReward1[i].c_str(), &temp))
- {
- data.mDisplayVipReward1.push_back(temp);
- }
- }
- }
- {
- const char* VipReward1 = element->Attribute("VipReward1");
- std::vector<std::string> vecVipReward1;
- boost::split(vecVipReward1, VipReward1, boost::is_any_of(","));
- int temp;
- for (unsigned int i = 0; i < vecVipReward1.size(); i++)
- {
- if (tinyxml2::XMLUtil::ToInt(vecVipReward1[i].c_str(), &temp))
- {
- data.mVipReward1.push_back(temp);
- }
- }
- }
- {
- const char* DisplayVipReward2 = element->Attribute("DisplayVipReward2");
- std::vector<std::string> vecDisplayVipReward2;
- boost::split(vecDisplayVipReward2, DisplayVipReward2, boost::is_any_of(","));
- int temp;
- for (unsigned int i = 0; i < vecDisplayVipReward2.size(); i++)
- {
- if (tinyxml2::XMLUtil::ToInt(vecDisplayVipReward2[i].c_str(), &temp))
- {
- data.mDisplayVipReward2.push_back(temp);
- }
- }
- }
- data.mArenaUp = element->IntAttribute("ArenaUp");
- data.mVipMoney = element->IntAttribute("VipMoney");
- {
- const char* VipReward2 = element->Attribute("VipReward2");
- std::vector<std::string> vecVipReward2;
- boost::split(vecVipReward2, VipReward2, boost::is_any_of(","));
- int temp;
- for (unsigned int i = 0; i < vecVipReward2.size(); i++)
- {
- if (tinyxml2::XMLUtil::ToInt(vecVipReward2[i].c_str(), &temp))
- {
- data.mVipReward2.push_back(temp);
- }
- }
- }
- data.mPersonalPoolRebate = element->IntAttribute("PersonalPoolRebate");
- if (mMapData.find(data.mVipLv) != mMapData.end())std::cout <<"data refind:" << data.mVipLv << std::endl;
- assert(mMapData.find(data.mVipLv) == mMapData.end());
- mMapData.insert(std::make_pair(data.mVipLv, data));
- element = element->NextSiblingElement();
- }
- }
- void M_VIPProfitCFG::Load()
- {
- Load("../Config/M_VIPProfitCFG.xml");
- }
- M_VIPProfitCFG* M_VIPProfitCFG::GetSingleton()
- {
- if (msSingleton.get() == nullptr)
- {
- msSingleton.reset(new M_VIPProfitCFG());
- }
- return msSingleton.get();
- }
|