infoclassmanager.cpp
来自「天之炼狱1服务器端源文件游戏服务端不完整」· C++ 代码 · 共 236 行
CPP
236 行
//--------------------------------------------------------------------//// Filename : InfoClassManager.cpp// Written By : Elca////--------------------------------------------------------------------// include files#include "InfoClassManager.h"#include "ItemInfo.h"#include "VariableManager.h"//--------------------------------------------------------------------------------// constructor//--------------------------------------------------------------------------------InfoClassManager::InfoClassManager () throw (): m_InfoCount(0), m_pItemInfos(NULL), m_TotalRatio(0), m_AveragePrice(0){}//--------------------------------------------------------------------------------// destructor//--------------------------------------------------------------------------------InfoClassManager::~InfoClassManager() throw (){ if (m_pItemInfos != NULL) { for (uint i = 0 ; i <= m_InfoCount ; i ++) SAFE_DELETE(m_pItemInfos[i]); SAFE_DELETE_ARRAY(m_pItemInfos); }}//--------------------------------------------------------------------------------// init//--------------------------------------------------------------------------------void InfoClassManager::init () throw (Error){ __BEGIN_TRY load(); //Assert(m_InfoCount>0); m_TotalRatio = 0; m_AveragePrice = 0; int count = 0; for (uint i=0; i<=m_InfoCount; i++) { Ratio_t itemRatio = m_pItemInfos[i]->getRatio(); if (itemRatio > 0) { // item type甸狼 total ratio甫 备茄促. m_TotalRatio += itemRatio; // 啊拜 醚钦 m_AveragePrice += m_pItemInfos[i]->getPrice(); count ++; } } // 啊拜 乞闭 if (count > 1) { m_AveragePrice /= count; } Assert(m_pItemInfos[0]!=NULL); // 啊拜 刘啊摹 m_AveragePrice /= 1000; m_AveragePrice *= 100; __END_CATCH}//--------------------------------------------------------------------------------// reload item infos//--------------------------------------------------------------------------------void InfoClassManager::reload() throw( Error ){ __BEGIN_TRY removeAllItemInfo(); init(); __END_CATCH}//--------------------------------------------------------------------------------// add item info//--------------------------------------------------------------------------------void InfoClassManager::addItemInfo (ItemInfo* pItemInfo) throw (DuplicatedException , Error){ __BEGIN_TRY Assert(pItemInfo != NULL); Assert(pItemInfo->getItemType() < Item::ITEM_CLASS_MAX); Assert(m_pItemInfos[pItemInfo->getItemType()] == NULL); m_pItemInfos[pItemInfo->getItemType()] = pItemInfo; __END_CATCH}//--------------------------------------------------------------------------------// get item info//--------------------------------------------------------------------------------ItemInfo* InfoClassManager::getItemInfo (ItemType_t itemType) const throw (NoSuchElementException , Error){ __BEGIN_TRY //Assert(itemType < Item::ITEM_CLASS_MAX); Assert(m_pItemInfos[itemType] != NULL); return m_pItemInfos[itemType]; __END_CATCH}//--------------------------------------------------------------------------------// remove all item infos//--------------------------------------------------------------------------------void InfoClassManager::removeAllItemInfo() throw( Error ){ __BEGIN_TRY if ( m_pItemInfos != NULL ) { for ( uint i = 0; i <= m_InfoCount ; i++ ) SAFE_DELETE( m_pItemInfos[i] ); } __END_CATCH}//--------------------------------------------------------------------------------// get Random ItemType//--------------------------------------------------------------------------------ItemType_t InfoClassManager::getRandomItemType() const throw (Error){ __BEGIN_TRY // DB俊 肋给 甸绢啊乐阑荐档 乐栏骨肺 犬牢秦毫具茄促. if (m_TotalRatio==0 || m_InfoCount==0) return 0; int gambleRatio = g_pVariableManager->getGambleItemTypeRatio(); // 200% int failRatio = m_pItemInfos[0]->getRatio(); // 0锅 酒捞袍狼 犬伏捞 角菩且 犬伏捞促. int succeedRatio = m_TotalRatio - failRatio; // 0锅 酒捞袍阑 力寇茄霸 己傍且 犬伏捞促. int newTotalRatio = failRatio + getPercentValue(succeedRatio, gambleRatio); // 角菩 + 己傍*gambleRatio int itemTypeRatio = rand()%newTotalRatio; int ratio; int ratioSum = 0; /* cout << "m_TotalRatio = " << m_TotalRatio << ", fail/succeed = " << failRatio<< "/" << succeedRatio << ", newTotalRatio = " << newTotalRatio << ", select = " << itemTypeRatio << endl; */ // 0锅篮 角菩肺 焊绊.. for (uint i=0; i<=m_InfoCount; i++) { ItemInfo* pInfo = m_pItemInfos[i]; ratio = pInfo->getRatio(); // 0捞 酒囱 版快俊父 gambleRatio甫 利侩茄促. // 0篮 角菩酒捞袍栏肺 焊绊.. 唱赣瘤父 犬伏阑 刘啊矫挪促. if (i!=0) { //cout << "[" << i << "] " << ratio; ratio = getPercentValue(ratio, gambleRatio); //cout << " --> " << ratio; } else { //cout << "[" << i << "] " << ratio; } ratioSum += ratio; //cout << " , ratioSum/Select = " << ratioSum << "/" << itemTypeRatio << endl; if (itemTypeRatio < ratioSum) { // i锅掳 type阑 急琶茄促. 酒付 pInfo->getItemType()==i 捞摆瘤父.. return pInfo->getItemType(); } } // 捞凡 荐 乐阑鳖? -_-; // getPercentValue俊 蝶扼辑... 傈眉客 阿阿且锭 坷瞒啊 乐阑 荐 乐栏骨肺 啊瓷窍促. return 0; __END_CATCH}//--------------------------------------------------------------------------------// toString for debug//--------------------------------------------------------------------------------string InfoClassManager::toString() const throw (){ StringStream msg; msg << "InfoClassManager("; for (uint i = 0 ; i <= m_InfoCount ; i ++) { msg << m_pItemInfos[i]->toString(); } msg << ")"; return msg.toString();}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?