/******************************************************************
** 文件名: BagSystem.cpp
** 版 权: (C) 深圳网域计算机网络有限公司
** 创建人:
** 日 期:
** 版 本: 1.0
** 描 述:
** 应 用:
**************************** 修改记录 ******************************
** 修改人: Anonymous
** 日 期: 2009.2.18
** 描 述: 整理背包子系统代码
** 基本原则:
********************************************************************/
#include "stdafx.h"
#include "BagSystem.h"
#include "share\item\SortItem.h"
#include "warehouseDef.h"
#include "MagicItemSystem/IMagicItemSystem.h"
#include "Share/WarehouseExpendTable/IWarehouseExpendTable.h"
#include "db/WorldServer/DB_ActorLogin.h"
#include "GameEngine/IEntityBehaviorFSM.h"
#include "Entity/EquipSystemDef.h"
#include "IEntityBroadcastSystem.h"
#include "Pet\IPetCardTrans.h"
#include "Share\GlobalCfg\IGlobalCfg.h"
#include "NPCInteractive\IInteractSystem.h"
#include "NpcInteractDef.h"
#include "Entity/EntityErrorDef.h"
#include "property\EquipUpLevelProperty.h"
#include "ItemEquipSystem\IEquipUpLevelTable.h"
//////////////////////////////////////////////////////////////////////////
// global export function define
extern "C" __declspec(dllexport) IObject * createBagSystemFunc()
{
return new BagSystem();
}
//////////////////////////////////////////////////////////////////////////
// class member function define
BagSystem::BagSystem() : m_bActived(true),
m_bCreating(false),
m_bCreateSuccess(false),
m_hEntity(0),
m_dropMoneyCount(0),
m_moneyInStorage(0),
m_bagSlotCnt(0),
m_pitemInfo(0),
m_pitemLen(0),
m_pstorageItemInfo(0),
m_pstorageItemLen(0),
m_transBuf(0),
m_transBufLen(0),
m_bagSortCDObj(0),
m_stoageSortCDObj(0)
{
initMessageHandler();
}
BagSystem::~BagSystem()
{
// clear resource
clearBagRes();
clearStorageRes();
// delete buffering data
ITEM_SAFE_FREE(m_pitemInfo);
ITEM_SAFE_FREE(m_pstorageItemInfo);
ITEM_SAFE_FREE(m_transBuf);
unRegEquipSysMsgBroadCast();
}
HEntity BagSystem::getHandle()const
{
return m_hEntity;
}
Int32 BagSystem::getID()const
{
return IID_IBagSystem;
}
void BagSystem::registerMessageHandler(Uint32 msgId, MSG_HANDLER handler)
{
MSG_HANDLER_LIST::const_iterator iterEnd = m_mapMsgHandler.end();
if (iterEnd == m_mapMsgHandler.find(msgId))
{
m_mapMsgHandler[msgId] = handler;
}
}
void BagSystem::initMessageHandler()
{
registerMessageHandler(MSG_CG_ITEM_EQUIP_BAG, &BagSystem::onRecvEquipBag);
registerMessageHandler(MSG_CG_ITEM_REMOVE_BAG, &BagSystem::onRecvRemoveBag);
registerMessageHandler(MSG_CG_ITEM_MOVE_ITEM, &BagSystem::onRecvMoveItem);
registerMessageHandler(MSG_CG_ITEM_SPLIT_ITEM, &BagSystem::onRecvSplitEquip);
registerMessageHandler(MSG_CG_ITEM_DISCARD_ITEM, &BagSystem::onRecvDiscardItem);
registerMessageHandler(MSG_CG_ITEM_USE_ITEM, &BagSystem::onRecvUseItem);
registerMessageHandler(MSG_CG_ITEM_BOX_GET_ITEM, &BagSystem::onRecvBoxGetItem);
registerMessageHandler(MSG_CG_ITEM_BOX_OPEN, &BagSystem::onRecvBoxOpen);
registerMessageHandler(MSG_CG_ITEM_ADD_MEND, &BagSystem::onRecvAddMend);
registerMessageHandler(MSG_CG_ITEM_REMOVE_MEND, &BagSystem::onRecvRemoveMend);
registerMessageHandler(MSG_CG_ITEM_ADD_GEM, &BagSystem::onRecvAddGem);
registerMessageHandler(MSG_CG_ITEM_ADD_GEM_BATCH, &BagSystem::onRecvAddGemBatch);
registerMessageHandler(MSG_CG_ITEM_ADD_CHARM, &BagSystem::onRecvAddCharm);
registerMessageHandler(MSG_CG_ITEM_DECOMPOSE, &BagSystem::onRecvDecompose);
registerMessageHandler(MSG_CG_ITEM_LOCK, &BagSystem::onRecvLock);
registerMessageHandler(MSG_CG_ITEM_GEMBOX_CLOSED, &BagSystem::onRecvClientGemBoxUIClosed);
registerMessageHandler(MSG_CG_SORT_BAG, &BagSystem::onRecvSortBag);
registerMessageHandler(MSG_CG_SORT_BAG_FINISHED, &BagSystem::onRecvSortBagFinished);
registerMessageHandler(MSG_CG_ITEM_PUT_ITEM_TO_BAG, &BagSystem::onRecvPutItemToBag);
registerMessageHandler(MSG_CG_ITEM_PREPARE_TO_SORT, &BagSystem::onRecvPrepareToSortBag);
registerMessageHandler(MSG_CG_ITEM_UPLEVEL_EQUIP, &BagSystem::onRecvUpLevelEquip);
registerMessageHandler(MSG_CG_ITEM_EQUIP_INHERIT, &BagSystem::onRecvEquipInherit);
registerMessageHandler(MSG_CG_ITEM_COMPOSE, &BagSystem::onRecvItemCompose);
registerMessageHandler(MSG_CG_STORAGE_EQUIPBAG, &BagSystem::Storage_onRecvEquipBag);
registerMessageHandler(MSG_CG_STORAGE_MOVEITEM, &BagSystem::Storage_onRecvMoveItem);
registerMessageHandler(MSG_CG_STORAGE_PUT_MONEY, &BagSystem::Storage_onRecvPutMoney);
registerMessageHandler(MSG_CG_STORAGE_REMOVEBAG, &BagSystem::Storage_onRecvRemoveBag);
registerMessageHandler(MSG_CG_STORAGE_BUY_BAGSLOT, &BagSystem::Storage_onRecvBuyBagSlot);
registerMessageHandler(MSG_CG_STORAGE_MOVESTORAGEITEM, &BagSystem::Storage_onRecvMoveStorageItem);
registerMessageHandler(MSG_CG_STORAGE_EQUIPBAGFROMBAG, &BagSystem::Storage_onRecvEquipBagFromBag);
registerMessageHandler(MSG_CG_STORAGE_GET_BAGSLOT_EXPEND, &BagSystem::Storage_onRecvGetBuyBagSlotExpend);
registerMessageHandler(MSG_CG_STORAGE_DISCARD_ITEM, &BagSystem::Storage_onRecvDiscardItem);
registerMessageHandler(MSG_CG_STORAGE_SPLIT_ITEM, &BagSystem::Storage_onRecvSplitItem);
registerMessageHandler(MSG_CG_STORAGE_UNEQUIP_BAG_TO_BAGSYSTEM, &BagSystem::Storage_onRecvUnEquipBagToBagSystem);
registerMessageHandler(MSG_CG_STORAGE_SORT_BAG, &BagSystem::Storage_onRecvSortBag);
registerMessageHandler(MSG_CG_STORAGE_SORT_BAG_FINISHED, &BagSystem::onRecvSortStorageBagFinished);
registerMessageHandler(MSG_CG_STORAGE_PUT_ITEM_TO_BAG, &BagSystem::Storage_onRecvPutItemToBag);
registerMessageHandler(MSG_CG_STORAGE_PREPARE_TO_SORT, &BagSystem::Storage_onRecvPrepareToSortBag);
}
Int32 BagSystem::onRecv(ListenerHandle handle, Uint32 wParam, Uint32 lParam)
{
ibuffer in((void*)wParam,lParam);
Uint8 msg;
in >> msg;
Uint32 nLen = (Uint32)(in.size()-in.pos());
FCL_PROMON_ENTITYCMD("BagSystem", msg);
MSG_HANDLER_LIST::const_iterator iter = m_mapMsgHandler.find(msg);
if (iter != m_mapMsgHandler.end())
{
(this->*(iter->second))(in.current(), nLen);
}
return handle(wParam, lParam);
}
Int32 BagSystem::onEntityDead(ListenerHandle hf, Uint32 wParam, Uint32 lParam)
{
// 处理物品死亡消失
for (Uint32 bagid = 0; bagid < BAGS_BAG_MAX; ++bagid)
{
IPackage *pkg = getPackage(bagid);
if (pkg)
{
for(Uint32 slot = 0; slot < pkg->size(); ++slot)
{
IItem* pItem = getItemFromHandle(pkg->getItem(slot));
if (pItem)
{
if (ITEM_DROPOUT_DEAD == pItem->getProperty(PROP_WITHDEAD, Int32(0)))
{
destoryItem(bagid, slot);
}
}
}
}
}
return hf(wParam,lParam);
}
void BagSystem::preRelease()
{
unRegisterSubSysEvent();
unRegisterSubSysMessage();
IEntity* pEntity = getEntityFromHandle(m_hEntity);
if (pEntity)
{
ICoolDownSystem* cdSystem = (ICoolDownSystem*)pEntity->queryEntitySystem(IID_CoolDownSystem);
if (!cdSystem)
{
ITEM_ERROR(_FMT("%s 找不到实体的冷却子系统\n", __FUNCTION__));
return ;
}
ICoolDownObject **cdObjArray[2] = {
&m_bagSortCDObj,
&m_stoageSortCDObj
};
for (Int32 i = 0; i < 2; i++)
{
ICoolDownObject *pObj = *cdObjArray[i];
if (pObj)
{
ITEM_INFO(_FMT("%s 删除背包整理冷却[index=%d]对象\n", __FUNCTION__, i));
cdSystem->releaseCDObject(pObj);
pObj = 0;
}
}
}
}
void BagSystem::clearBagRes()
{
MapPackages::iterator iter;
MapPackages::iterator iterEnd = m_mapPackages.end();
for (iter = m_mapPackages.begin(); iter != iterEnd; ++iter)
{
Int32 bagId = iter->first;
IPackage *pPackage = iter->second;
if (pPackage)
{
for (Uint32 i = 0; i < pPackage->size(); ++i)
{
HItem hItem = pPackage->getItem(i);
IItem* pItem = getItemFromHandle(hItem);
if (pItem)