本文整理汇总了C++中ItemContainer::GetItem方法的典型用法代码示例。如果您正苦于以下问题:C++ ItemContainer::GetItem方法的具体用法?C++ ItemContainer::GetItem怎么用?C++ ItemContainer::GetItem使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ItemContainer
的用法示例。
在下文中一共展示了ItemContainer::GetItem方法的14个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1:
Item* HumanItemLogic::GetBankItem(Obj_Human* pHuman,UINT BankIndex)
{
__ENTER_FUNCTION
Assert(BankIndex<MAX_BANK_SIZE);
Assert(BankIndex>=0);
if(BankIndex<0||BankIndex>MAX_BANK_SIZE)
{
AssertEx(FALSE,"HumanItemLogic::GetBankItem() BankIndex 不在合法范围 ");
return NULL;
}
ItemContainer* pBankContainer = pHuman->GetBankContain();
Assert(pBankContainer);
if(!pBankContainer)
{
return NULL;
}
return pBankContainer->GetItem((UINT)BankIndex);
__LEAVE_FUNCTION
return NULL;
}
示例2: Execute
uint CGAskMyBagListHandler::Execute(CGAskMyBagList* pPacket, Player* pPlayer )
{
__ENTER_FUNCTION
GamePlayer* pGamePlayer = (GamePlayer*)pPlayer ;
Assert( pGamePlayer ) ;
Obj_Human* pHuman = pGamePlayer->GetHuman() ;
Assert( pHuman ) ;
Scene* pScene = pHuman->getScene() ;
if( pScene==NULL )
{
Assert(FALSE) ;
return PACKET_EXE_ERROR ;
}
//检查线程执行资源是否正确
Assert( MyGetCurrentThreadID()==pScene->m_ThreadID ) ;
ASK_BAG_MODE mode = pPacket->GetAskMode();
GCMyBagList Msg;
switch(mode)
{
case ASK_ALL:
{
_BAG_ITEM ItemIterator;
_ITEM_GUID NullGuid;
uint AllAskCount = 0;
uint nItemCount = 0;
memset(&NullGuid,0,sizeof(_ITEM_GUID));
Msg.SetAskMode(ASK_ALL);
//读取扩展容器
ItemContainer* pExtraContainer = pHuman->GetExtraContain();
Assert(pExtraContainer);
for( INT i=0; i<pExtraContainer->GetContainerSize(); i++ )
{
//临时代码
Item* pItem = HumanItemLogic::GetExtraContainerItem(pHuman,pExtraContainer->ConIndex2BagIndex(i));
Assert(pItem);
if(!(pItem->IsEmpty()))
{
ItemIterator.m_nndex = pExtraContainer->ConIndex2BagIndex(i);
pItem->SaveValueTo(&ItemIterator.m_nItemData);
Msg.SetAskItemData(&ItemIterator,nItemCount);
++nItemCount;
}
}
//读取基本背包
ItemContainer* pBaseContainer = pHuman->GetBaseContain();
Assert(pBaseContainer);
for( INT i=0; i<pBaseContainer->GetContainerSize(); i++ )
{
//临时代码
Item* pItem = pBaseContainer->GetItem(i);
Assert(pItem);
if(!(pItem->IsEmpty()))
{
ItemIterator.m_nndex = pBaseContainer->ConIndex2BagIndex(i);
pItem->SaveValueTo(&ItemIterator.m_nItemData);
Msg.SetAskItemData(&ItemIterator,nItemCount);
++nItemCount;
}
}
//读取扩展背包
for (INT j=0; j<MAX_EXTRA_BAG_NUM; ++j)
{
ItemContainer* pBaseContainer = pHuman->GetExtraBagContain(j);
Assert(pBaseContainer);
if (pBaseContainer->IsValid())
{
for( INT i=0; i<pBaseContainer->GetContainerSize(); i++ )
{
//临时代码
Item* pItem = pBaseContainer->GetItem(i);
Assert(pItem);
if(!(pItem->IsEmpty()))
{
ItemIterator.m_nndex = pBaseContainer->ConIndex2BagIndex(i);
pItem->SaveValueTo(&ItemIterator.m_nItemData);
Msg.SetAskItemData(&ItemIterator,nItemCount);
++nItemCount;
}
}
}
}
Msg.SetItemCount(nItemCount);
//.........这里部分代码省略.........
示例3: Execute
uint CGExchangeOkIIIHandler::Execute( CGExchangeOkIII* pPacket, Player* pPlayer )
{
__ENTER_FUNCTION
GamePlayer* pGamePlayer = (GamePlayer*)pPlayer ;
Assert( pGamePlayer ) ;
Obj_Human* pHuman = pGamePlayer->GetHuman() ;
Assert( pHuman ) ;
Scene* pScene = pHuman->getScene() ;
if( pScene==NULL )
{
Assert(FALSE) ;
return PACKET_EXE_ERROR ;
}
//检查线程执行资源是否正确
Assert( MyGetCurrentThreadID()==pScene->m_ThreadID ) ;
EXCHANGE_CERTIFY_EACH_OTHER(pHuman)
ObjID_t DestID = pHuman->m_ExchangBox.m_ObjID;
Obj_Character *pTarget = (Obj_Character*)(pScene->GetObjManager()->GetObj( DestID ));
if(pTarget->GetObjType() != Obj::OBJ_TYPE_HUMAN)
{
g_pLog->FastSaveLog( LOG_FILE_1, "CGExchangeOkIIIHandler: %s ask not a human.", pHuman->GetName() ) ;
return PACKET_EXE_CONTINUE;
}
Obj_Human* pDestHuman = (Obj_Human*)pTarget;
if( pDestHuman == NULL )
{
Assert(FALSE);
return PACKET_EXE_CONTINUE;
}
// 不同阵营,不让查看
if( pHuman->IsEnemy( pDestHuman ) )
{
g_pLog->FastSaveLog( LOG_FILE_1, "CGExchangeOkIIIHandler: %s cann't ask %s's detailattr ", pHuman->GetName(), pDestHuman->GetName() ) ;
return PACKET_EXE_CONTINUE;
}
if(pHuman->m_ExchangBox.m_Status == ServerExchangeBox::EXCHANGE_WAIT_FOR_CONFIRM)
{
//设置可以交换
pHuman->m_ExchangBox.m_Status = ServerExchangeBox::EXCHANGE_CONFIRM_READY;
if(pDestHuman->m_ExchangBox.m_Status == ServerExchangeBox::EXCHANGE_CONFIRM_READY)
{//可以交换了
//1.变量初始化
ItemContainer* pMyExchangeContainer = &(pHuman->m_ExchangBox.m_Container);
ItemContainer* pOtExchangeContainer = &(pDestHuman->m_ExchangBox.m_Container);
ItemContainer* pMyExchangePetContainer = &(pHuman->m_ExchangBox.m_PetContainer);
ItemContainer* pOtExchangePetContainer = &(pDestHuman->m_ExchangBox.m_PetContainer);
_EXCHANGE_ITEM_LIST ItemListMeToOt;
_EXCHANGE_ITEM_LIST ItemListOtToMe;
ItemListMeToOt.Init();
ItemListOtToMe.Init();
//2.验证循环
g_pLog->FastSaveLog( LOG_FILE_1, "<交易> [%s] 与 [%s] 开始验证循环", pHuman->GetName(), pDestHuman->GetName()) ;
for(INT i = 0; i<EXCHANGE_BOX_SIZE; i++)
{
if(pMyExchangeContainer->GetItem(i)->IsEmpty() == FALSE)
{
ItemListMeToOt.AddItem( pMyExchangeContainer->GetItem(i) );
}
if(pOtExchangeContainer->GetItem(i)->IsEmpty() == FALSE)
{
ItemListOtToMe.AddItem( pOtExchangeContainer->GetItem(i) );
}
}
for(INT i = 0; i<EXCHANGE_PET_BOX_SIZE; i++)
{
if(pMyExchangePetContainer->GetItem(i)->IsEmpty() == FALSE)
{
ItemListMeToOt.AddItem( pMyExchangePetContainer->GetItem(i) );
}
if(pOtExchangePetContainer->GetItem(i)->IsEmpty() == FALSE)
{
ItemListOtToMe.AddItem( pOtExchangePetContainer->GetItem(i) );
}
}
if( FALSE == HumanItemLogic::CanReceiveExchangeItemList( pHuman, ItemListOtToMe) )
{//空间不够
GCExchangeError MsgSelf;
MsgSelf.SetID(EXCHANGE_MSG::ERR_NOT_ENOUGHT_ROOM_SELF);
pHuman->GetPlayer()->SendPacket(&MsgSelf);
GCExchangeError MsgOther;
MsgOther.SetID(EXCHANGE_MSG::ERR_NOT_ENOUGHT_ROOM_OTHER);
pDestHuman->GetPlayer()->SendPacket(&MsgOther);
pHuman->m_ExchangBox.CleanUp();
pDestHuman->m_ExchangBox.CleanUp();
g_pLog->FastSaveLog( LOG_FILE_1, " <交易> [%s] 空间不够", pHuman->GetName()) ;
return PACKET_EXE_CONTINUE;
//.........这里部分代码省略.........
示例4: Execute
uint CGManipulateMountHandler::Execute(CGManipulateMount* pPacket, Player* pPlayer )
{
__ENTER_FUNCTION
GamePlayer* pGamePlayer = (GamePlayer*)pPlayer ;
Assert( pGamePlayer ) ;
Obj_Human* pHuman = pGamePlayer->GetHuman() ;
Assert( pHuman ) ;
Scene* pScene = pHuman->getScene() ;
if( pScene==NULL )
{
Assert(FALSE) ;
return PACKET_EXE_ERROR ;
}
//检查线程执行资源是否正确
Assert( MyGetCurrentThreadID()==pScene->m_ThreadID ) ;
//切场景时丢弃换装消息
if(pGamePlayer->GetPlayerStatus()!=PS_SERVER_NORMAL ||
!pHuman->IsActiveObj() )
{
g_pLog->FastSaveLog( LOG_FILE_1, "CGManipulateMountHandler: change scene") ;
return PACKET_EXE_CONTINUE;
}
//交易状态不可操作
if(pHuman->m_ExchangBox.m_Status > 0)
{//丢弃
g_pLog->FastSaveLog( LOG_FILE_1, "ERROR: ObjID=%d, ExchangBox::m_Status>0" ,pHuman->GetID()) ;
return PACKET_EXE_CONTINUE ;
}
//摆摊状态不可操作
if(pHuman->m_StallBox.GetStallStatus() == ServerStallBox::STALL_OPEN)
{//丢弃
g_pLog->FastSaveLog( LOG_FILE_1, "ERROR: ObjID=%d, ServerStallBox::STALL_OPEN" ,pHuman->GetID()) ;
return PACKET_EXE_CONTINUE ;
}
Assert( NULL != pPacket ) ;
BYTE bagIndex = pPacket->getBagIndex();
BYTE mountIndex = pPacket->getMountIndex();
INT mountID = pPacket->getMountID();
ItemContainer* pMountContainer = HumanItemLogic::GetMountContainer(pHuman);
if (pMountContainer == NULL)
{
g_pLog->FastSaveLog( LOG_FILE_1, "CGManipulateMountHandler BagIndex is invalid, BagIndex = %d", mountIndex) ;
return PACKET_EXE_ERROR;
}
GCManipulateMountResult Msg;
switch(pPacket->getMountOperator())
{
case CGManipulateMount::MANIPULATE_EQUIP_MOUNT:
{
ItemContainer* pBagContainer = HumanItemLogic::GetBagContainer(pHuman, bagIndex);
_ITEM* pSourceItem = pBagContainer->GetItem(bagIndex)->GetItemData();
INT result = g_ItemOperator.MoveItem(pBagContainer, bagIndex, pMountContainer);
if (ITEMOE_SUCCESS <= result)
{
MOUNT_INFO* mountInfo = pSourceItem->GetMountData();
INT elapseMinute = g_pTimeManager->DiffDWORDTime(g_pTimeManager->GetANSITime(), mountInfo->m_nObtainDate);
const INT MINUTE_IN_ONE_DAY = 1488;
mountInfo->m_nObtainDate = (UINT)g_pTimeManager->GetANSITime();
mountInfo->m_nRemainTime = mountInfo->m_nLife * MINUTE_IN_ONE_DAY - elapseMinute;
if(CGManipulateMount::EQUIP_BIND == (CGManipulateMount::MOUNT_BIND_TYPE) mountInfo->m_nBindType)
mountInfo->m_bIsBinded = TRUE;
Msg.setResult(TRUE);
Msg.setMountObtainDate(mountInfo->m_nObtainDate);
Msg.setMountIsBinded(mountInfo->m_bIsBinded);
Msg.setMountRemainTime(mountInfo->m_nRemainTime);
Msg.setMountGUID(pSourceItem->m_ItemGUID);
}
else
{
Msg.setResult(FALSE);
}
Msg.setBagIndex(bagIndex);
Msg.setMountIndex(result);
Msg.setMountOperator(GCManipulateMountResult::MANIPULATE_EQUIP_MOUNT);
pGamePlayer->SendPacket( &Msg ) ;
}
break;
case CGManipulateMount::MANIPULATE_CALL_MOUNT:
{
INT addtionSpeed = pHuman->GetDB()->GetMountDB()->m_pItem[mountIndex].GetMountData()->m_nAddtionSpeed;
pHuman->GetDB()->SetMountID(mountID);
pHuman->GetDB()->SetMountIndex(mountIndex);
//.........这里部分代码省略.........
示例5: Execute
UINT CGEquipRefiningHandler::Execute( CGEquipRefining* pPacket, Player* pPlayer )
{
__ENTER_FUNCTION
GamePlayer* pGamePlayer = (GamePlayer*)pPlayer ;
Assert( pGamePlayer ) ;
Obj_Human* pHuman = pGamePlayer->GetHuman() ;
Assert( pHuman ) ;
Scene* pScene = pHuman->getScene() ;
if( pScene==NULL )
{
Assert(FALSE) ;
return PACKET_EXE_ERROR ;
}
//检查线程执行资源是否正确
Assert( MyGetCurrentThreadID()==pScene->m_ThreadID );
//切场景时丢弃换装消息
//交易状态不可操作
//摆摊状态不可操作
// 获取炼化的装备
BYTE iEquipItemPos = pPacket->GetEquipItemPos();
Assert(iEquipItemPos >= 0 );
Assert(iEquipItemPos <= MAX_BAG_SIZE);
GCEquipRefining msg;
ItemContainer* pBagContainer = HumanItemLogic::GetBagContainer(pHuman, iEquipItemPos);
if (pBagContainer == NULL)
{
g_pLog->FastSaveLog( LOG_FILE_1, "CGEquipRefiningHandler equipment BagIndex is invalid, BagIndex = %d", iEquipItemPos) ;
msg.SetResult(EQUIPREFINING_NOT_SUCH_ITEM);
pGamePlayer->SendPacket(&msg);
return PACKET_EXE_CONTINUE;
}
Item* pEquipment = pBagContainer->GetItem(pBagContainer->BagIndex2ConIndex(iEquipItemPos));
Assert(NULL != pEquipment);
//一些验证:星级,等级...
if( NULL == pEquipment || ICLASS_EQUIP != pEquipment->GetItemClass() || !(pEquipment->IsRuler(IRL_DISCARD) )
|| pEquipment->IsAdsorbMagic() || pEquipment->GetRequireLevel() < EQUIP_REFINING_MIN_LEVEL //已经附魔或者需求等级小于40
|| 0 == pEquipment->GetEquipGemCount()) //没有镶嵌宝石
{
g_pLog->FastSaveLog( LOG_FILE_1, "CGEquipRefiningHandler equipment type is invalid, BagIndex = %d", iEquipItemPos) ;
msg.SetResult(EQUIPREFINING_NOT_SUCH_ITEM);
pGamePlayer->SendPacket(&msg);
return PACKET_EXE_CONTINUE;
}
//获取炼化神器
BYTE iRefiningItemPos = pPacket->GetRefiningItemPos();
Assert(iRefiningItemPos >= 0 );
Assert(iRefiningItemPos <= MAX_BAG_SIZE);
pBagContainer = HumanItemLogic::GetBagContainer(pHuman, iRefiningItemPos);
if (pBagContainer == NULL)
{
g_pLog->FastSaveLog( LOG_FILE_1, "CGEquipRefiningHandler refining BagIndex is invalid, BagIndex = %d", iRefiningItemPos) ;
msg.SetResult(EQUIPREFINING_NOT_SUCH_ITEM);
pGamePlayer->SendPacket(&msg);
return PACKET_EXE_CONTINUE;
}
Item* pRefiningItem = pBagContainer->GetItem(pBagContainer->BagIndex2ConIndex(iRefiningItemPos));
Assert(NULL != pRefiningItem);
if(NULL == pRefiningItem || pRefiningItem->GetItemClass() != ICLASS_COMITEM || pRefiningItem->GetItemType() != COMITEM_EQUIP_REFINING)
{
g_pLog->FastSaveLog( LOG_FILE_1, "CGEquipRefiningHandler refining type is invalid, BagIndex = %d", iRefiningItemPos) ;
msg.SetResult(EQUIPREFINING_NOT_SUCH_ITEM);
pGamePlayer->SendPacket(&msg);
return PACKET_EXE_CONTINUE;
}
//逻辑处理
COMMITEM_INFO_TB* pGet = g_ItemTable.GetCommItemInfoTB(pRefiningItem->GetItemTableIndex());
Assert(NULL != pGet);
if ((pEquipment->GetRequireLevel()-1)/10+1 != pGet->m_nLevel)//验证等级
{
msg.SetResult(EQUIPREFINING_NOT_SUCH_ITEM);
pGamePlayer->SendPacket(&msg);
return PACKET_EXE_CONTINUE;
}
if ( 0 == pEquipment->GetAttrCount())// && pEquipment->GetLevel()
{
msg.SetResult(EQUIPREFINING_NOT_HAVE_ATTR);
pGamePlayer->SendPacket(&msg);
return PACKET_EXE_CONTINUE;
}
//EQUIP_TB* pGet = g_ItemTable.GetEquipTB(pEquipment->GetItemTableIndex());
//Assert(NULL != pGet);
//删除装备和炼化神符道具
UINT iPrice = pEquipment->GetSellPrice();//保留将要删除的装备属性给后面用
BYTE iRequireLevel = pEquipment->GetRequireLevel();
BYTE curEquipPoint = pEquipment->GetEquipPoint();
BYTE attrCount = 0;
//.........这里部分代码省略.........
示例6: Execute
uint CGEquipExChangePaiTypeHandler::Execute(CGEquipExChangePaiType* pPacket,Player* pPlayer)
{
__ENTER_FUNCTION
GamePlayer* pGamePlayer = (GamePlayer*)pPlayer;
Assert( pGamePlayer );
Obj_Human* pHuman = pGamePlayer->GetHuman();
Assert( pHuman );
Scene* pScene = pHuman->getScene();
if( pScene==NULL )
{
Assert(FALSE);
return PACKET_EXE_ERROR;
}
//检查线程执行资源是否正确
Assert( MyGetCurrentThreadID()==pScene->m_ThreadID );
//交易状态不可操作
if(pHuman->m_ExchangBox.m_Status > 0)
{//丢弃
g_pLog->FastSaveLog( LOG_FILE_1, "ERROR: ObjID=%d, ExchangBox::m_Status>0" ,pHuman->GetID()) ;
return PACKET_EXE_CONTINUE ;
}
//摆摊状态不可操作
if(pHuman->m_StallBox.GetStallStatus() == ServerStallBox::STALL_OPEN)
{//丢弃
g_pLog->FastSaveLog( LOG_FILE_1, "ERROR: ObjID=%d, ServerStallBox::STALL_OPEN" ,pHuman->GetID()) ;
return PACKET_EXE_CONTINUE ;
}
//摆摊不可操作
if(pHuman->m_StallBox.GetStallStatus() == ServerStallBox::STALL_OPEN)
{//丢弃
g_pLog->FastSaveLog( LOG_FILE_1, "ERROR: ObjID=%d, ServerStallBox::STALL_OPEN" ,pHuman->GetID()) ;
return PACKET_EXE_CONTINUE ;
}
ObjID_t NpcObjID= pPacket->GetUniqueID();
Obj* pNpcObj = pScene->GetObjManager()->GetObj(NpcObjID);
if (pNpcObj == NULL)
{
return PACKET_EXE_ERROR;
}
else
{
if( pNpcObj->GetObjType() != Obj::OBJ_TYPE_MONSTER )
{
return PACKET_EXE_ERROR;
}
}
FLOAT fDist = MySqrt(pNpcObj->getWorldPos(), pHuman->getWorldPos());
if(fDist>MAX_NPC_DISTANCE)
{
g_pLog->FastSaveLog( LOG_FILE_1, "CGEquipExChangePaiTypeHandler Out Of Range ObjName = %s", pHuman->GetName()) ;
return PACKET_EXE_CONTINUE ;
}
EQUIPEXCHANGEPAITTYPE_RESULT Result = EQUIPEXCHANGEPAITTYPE_FAIL;
GCEquipExChangePaiTypeResult ResultPacket;
Item* pEquip1Item = NULL;
Item* pEquip2Item = NULL;
INT Equip1Point = INVALID_ITEM_POS;
INT Equip2Point = INVALID_ITEM_POS;
if(pPacket->GetEquip1PosType()>=INVALID_ITEM_POS_TYPE)
{
g_pLog->FastSaveLog( LOG_FILE_1, "CGEquipExChangePaiTypeHandler Equip posType error, posType=%d", pPacket->GetEquip1PosType()) ;
return PACKET_EXE_ERROR;
}
if(pPacket->GetEquip1PosType() == ENUM_BAG)
{
ItemContainer* pItemContainer1 = HumanItemLogic::GetBagContainer(pHuman,pPacket->GetPos1());
if( pItemContainer1 == NULL )
{
g_pLog->FastSaveLog( LOG_FILE_1, "CGEquipExChangePaiTypeHandler: BagIndex error, BagIndex=%d", pPacket->GetPos1()) ;
return PACKET_EXE_ERROR;
}
if (!pItemContainer1->IsCanUse())
{
Result = EQUIPEXCHANGEPAITTYPE_BAG_INVALID;
ResultPacket.SetResult(Result);
pGamePlayer->SendPacket(&ResultPacket);;
g_pLog->FastSaveLog( LOG_FILE_1, "CGEquipExChangePaiTypeHandler: ItemContainer is invalid, ContainerType=%d, BagIndex=%d",
pItemContainer1->GetContainerType(), pPacket->GetPos1()) ;
return PACKET_EXE_ERROR;
}
pEquip1Item = pItemContainer1->GetItem(pItemContainer1->BagIndex2ConIndex(pPacket->GetPos1()));
if(pEquip1Item->IsEmpty())
{
Result = EQUIPEXCHANGEPAITTYPE_EQUIP_FAIL;
ResultPacket.SetResult(Result);
pGamePlayer->SendPacket(&ResultPacket);
g_pLog->FastSaveLog( LOG_FILE_1, "CGEquipExChangePaiTypeHandler Equip empyty, bagpos=%d", pPacket->GetPos1()) ;
//.........这里部分代码省略.........
示例7: Execute
uint CGBankSwapItemHandler::Execute( CGBankSwapItem* pPacket, Player* pPlayer )
{
__ENTER_FUNCTION
GamePlayer* pGamePlayer = (GamePlayer*)pPlayer ;
Assert( pGamePlayer ) ;
Obj_Human* pHuman = pGamePlayer->GetHuman() ;
Assert( pHuman ) ;
Scene* pScene = pHuman->getScene() ;
if( pScene==NULL )
{
Assert(FALSE) ;
return PACKET_EXE_ERROR ;
}
//检查线程执行资源是否正确
Assert( MyGetCurrentThreadID()==pScene->m_ThreadID ) ;
UINT indexFrom = pPacket->GetIndexFrom();
UINT indexTo = pPacket->GetIndexTo();
GCBankSwapItem Msg;
switch(pPacket->GetFromType())
{
case CGBankSwapItem::EQUIP_POS:
{
switch(pPacket->GetToType())
{
case CGBankSwapItem::BAG_POS:
{
}
break;
case CGBankSwapItem::EQUIP_POS:
{
}
break;
case CGBankSwapItem::BANK_POS:
{
}
break;
default:
break;
}
}
break;
case CGBankSwapItem::BAG_POS:
{
switch(pPacket->GetToType())
{
case CGBankSwapItem::BAG_POS:
{
}
break;
case CGBankSwapItem::EQUIP_POS:
{
}
break;
case CGBankSwapItem::BANK_POS: // Bag->Bank
{
//验证位置的合法性
if( indexFrom>=0
&& indexFrom<MAX_BAG_SIZE
&& indexTo>=0
&& indexTo<(UINT)(pHuman->__GetBankEndIndex())
)
{
//验证位置里是否有东西
if( ITEMREFPTRISVALID(HumanItemLogic::GetItem(pHuman, indexFrom))
&&ITEMREFPTRISVALID(HumanItemLogic::GetBankItem(pHuman, indexTo))
)
{
ItemContainer* pBagContainer =
HumanItemLogic::GetContainer(pHuman,indexFrom);
ItemContainer* pBankContainer = pHuman->GetBankContain();
Item *pItem1 = pBagContainer->GetItem(pBagContainer->BagIndex2ConIndex(indexFrom));
Item *pItem2 = pBankContainer->GetItem(indexTo);
//检测是否能够合并,如果可以,就执行合并而不是交换
if(pItem1->GetItemTableIndex() == pItem2->GetItemTableIndex() && pItem1->IsCanLay())
{
if(g_ItemOperator.MoveSpliceItem( pBagContainer,
(UCHAR)indexFrom,
pBankContainer,
indexTo)
== ITEMOE_SUCCESS)
{
GCItemInfo msg1;
msg1.setID(indexFrom);
msg1.setIsNull(pItem1->IsEmpty());
pItem1->SaveValueTo(msg1.getItem());
pGamePlayer->SendPacket(&msg1);
GCBankItemInfo msg2;
msg2.setBankIndex(indexTo);
msg2.setIsNull(pItem2->IsEmpty());
pItem2->SaveValueTo(msg2.getItem());
//.........这里部分代码省略.........
示例8: Execute
UINT CGUseEquipHandler::Execute(CGUseEquip* pPacket, Player* pPlayer )
{
__ENTER_FUNCTION
GamePlayer* pGamePlayer = (GamePlayer*)pPlayer ;
Assert( pGamePlayer ) ;
Obj_Human* pHuman = pGamePlayer->GetHuman() ;
Assert( pHuman ) ;
Scene* pScene = pHuman->getScene() ;
if( pScene==NULL )
{
Assert(FALSE) ;
return PACKET_EXE_ERROR ;
}
//检查线程执行资源是否正确
Assert( MyGetCurrentThreadID()==pScene->m_ThreadID ) ;
//切场景时丢弃换装消息
if(pGamePlayer->GetPlayerStatus()!=PS_SERVER_NORMAL ||
!pHuman->IsActiveObj() )
{
g_pLog->FastSaveLog( LOG_FILE_1, "CGUseEquipmentHandler: change scene") ;
return PACKET_EXE_CONTINUE;
}
BYTE BagIndex = pPacket->getBagIndex();
if( BagIndex == INVALID_BAG_INDEX )
{
Assert(FALSE) ; //包发错了
return PACKET_EXE_CONTINUE ;
}
Item* pUseItem = HumanItemLogic::GetItem(pHuman,BagIndex);
GCUseEquipResult Msg;
//////////////////////////////////////////////////////////////////////////
//装配条件判断
UCHAR itemClass = pUseItem->GetItemClass();
if(itemClass == ICLASS_EQUIP)
{
//需求等级判断
if(pUseItem->GetRequireLevel()>pHuman->GetLevel())
{
Msg.setResult(USEEQUIP_IDENT_FAIL);
pGamePlayer->SendPacket( &Msg ) ;
}
//鉴定判断
else if(pUseItem->GetItemQual() == EQUALITY_BLUE && pUseItem->GetItemIdent() == FALSE)
{
Msg.setResult(USEEQUIP_LEVEL_FAIL);
pGamePlayer->SendPacket( &Msg ) ;
}
else
{
HUMAN_EQUIP Equip_Point =(HUMAN_EQUIP)pUseItem->GetEquipPoint();
//const _ITEM* pEquip = pHuman->GetEquip(Equip_Point);
ItemContainer* pEquipContainer = pHuman->GetEquipContain();
if(!pEquipContainer)
{
Assert(pEquipContainer);
return PACKET_EXE_CONTINUE;
}
Item* pEquipItem = pEquipContainer->GetItem((UINT)Equip_Point);
if(!pEquipItem)
{
Assert(pEquipItem);
return PACKET_EXE_CONTINUE;
}
BOOL bEquipStatus = (!pEquipItem->IsEmpty());
ItemContainer* pBagContainer =
HumanItemLogic::GetContainer(pHuman,BagIndex);
if(bEquipStatus)
{
//装备上物品,替换下来装备点数据
g_ItemOperator.ExchangeItem(pBagContainer,
pBagContainer->BagIndex2ConIndex(BagIndex),
pEquipContainer,
(UINT)Equip_Point);
}
else
{
//pHuman->GetDB()->OverWriteBag2Equip(BagIndex,Equip_Point);
g_ItemOperator.MoveItem(pBagContainer,
//.........这里部分代码省略.........
示例9: Execute
uint CGBankAddItemHandler::Execute( CGBankAddItem* pPacket, Player* pPlayer )
{
__ENTER_FUNCTION
GamePlayer* pGamePlayer = (GamePlayer*)pPlayer ;
Assert( pGamePlayer ) ;
Obj_Human* pHuman = pGamePlayer->GetHuman() ;
Assert( pHuman ) ;
Scene* pScene = pHuman->getScene() ;
if( pScene==NULL )
{
Assert(FALSE) ;
return PACKET_EXE_ERROR ;
}
//检查线程执行资源是否正确
Assert( MyGetCurrentThreadID()==pScene->m_ThreadID ) ;
UINT indexFrom = pPacket->GetIndexFrom();
UINT indexTo = pPacket->GetIndexTo();
GCBankAddItem Msg;
switch(pPacket->GetFromType())
{
case CGBankAddItem::EQUIP_POS:
{
pHuman->GetDB()->OverWriteEquip2Bank((HUMAN_EQUIP)indexFrom, indexTo);
Msg.SetFromType(GCBankAddItem::EQUIP_POS);
Msg.SetIndexFrom(indexFrom);
Msg.SetIndexTo(indexTo);
}
break;
case CGBankAddItem::BAG_POS: //Bag->Bank
{
ItemContainer *pBankContainer = pHuman->GetBankContain();
ItemContainer *pBagContainer = HumanItemLogic::GetContainer(pHuman,indexFrom);
Item *pBagItem = pBagContainer->GetItem( pBagContainer->BagIndex2ConIndex(indexFrom) );
//防止连续点击
if(pBagItem->IsEmpty())
{
g_pLog->FastSaveLog( LOG_FILE_1, "CGBankAddItemHandler too many click") ;
return PACKET_EXE_CONTINUE;
}
//Item *pBankItem = pBankContainer->GetItem( indexTo );
//合并标志
INT bSplice = 0;
INT nSpliceTo = -1;
UINT TempIndexTo = indexTo;
//自动搜索空格租赁箱1
switch(TempIndexTo)
{
case CGBankAddItem::AUTO_POS_BOX1:
{
//先查询是不是有可以合并的物品,(只在本租赁箱中)
if( pBagItem->IsCanLay() )
{
for( INT i=RENTBOX1_START_INDEX; i<RENTBOX2_START_INDEX; i++ )
{
Item *pBankItem = pBankContainer->GetItem(i);
// 验证是否可以叠加成功
if( pBankItem->GetItemTableIndex() == pBagItem->GetItemTableIndex() &&
pBankItem->GetLayedNum() + pBagItem->GetLayedNum() <= pBankItem->GetMaxLayedNum() )
{
bSplice = 1;
nSpliceTo = i;
indexTo = i;
break;
}
}
}
//没有可以叠加的物品,就寻找一个空格
BYTE indextemp = RENTBOX1_START_INDEX;
if(0 == bSplice)
{
while( ITEMREFPTRISVALID(HumanItemLogic::GetBankItem(pHuman, indextemp))
&& indextemp < RENTBOX2_START_INDEX
)
{
indextemp++;
}
if(indextemp == RENTBOX2_START_INDEX)
{
indexTo = indextemp-1;
}
else
{
indexTo = indextemp;
}
}
}
break;
//.........这里部分代码省略.........
示例10: Execute
uint CGExchangeSynchItemIIHandler::Execute( CGExchangeSynchItemII* pPacket, Player* pPlayer )
{
__ENTER_FUNCTION
GamePlayer* pGamePlayer = (GamePlayer*)pPlayer ;
Assert( pGamePlayer ) ;
Obj_Human* pHuman = pGamePlayer->GetHuman() ;
Assert( pHuman ) ;
Scene* pScene = pHuman->getScene() ;
if( pScene==NULL )
{
Assert(FALSE) ;
return PACKET_EXE_ERROR ;
}
//检查线程执行资源是否正确
Assert( MyGetCurrentThreadID()==pScene->m_ThreadID ) ;
//验证交易状态
EXCHANGE_CERTIFY_EACH_OTHER(pHuman) // 验证交易双方是否掉线合法
EXCHANGE_CERTIFY_ISLOCK(pHuman) // 验证当前人物的交易状态是否已经上锁
ObjID_t DestID = pHuman->m_ExchangBox.m_ObjID;
Obj_Human* pDestHuman = pScene->GetHumanManager()->GetHuman( DestID );
EXCHANGE_CERTIFY_STATUS(pHuman, EXCHANGE_SYNCH_DATA) // 验证当前人物的交易状态是否正确
EXCHANGE_CERTIFY_STATUS(pDestHuman, EXCHANGE_SYNCH_DATA)
//操作
BYTE Opt = pPacket->GetOpt();
BYTE FromType = pPacket->GetFromType();
BYTE ToType = pPacket->GetToType();
BYTE FromIndex = pPacket->GetFromIndex();
BYTE ToIndex = pPacket->GetToIndex();
PET_GUID_t PetGuid = pPacket->GetPetGuid();
_ITEM ItemTemp;
GCExchangeSynchII Msg;
GCExchangeError MsgError;
ItemContainer* pExchangeContainer = &(pHuman->m_ExchangBox.m_Container);
ItemContainer* pExchangePetContainer = &(pHuman->m_ExchangBox.m_PetContainer);
switch(Opt)
{
case OPT_ERROR:
{
}
break;
case OPT_ADDITEM:
{
switch(FromType)
{
case POS_BAG:
{
//验证位置里是否有东西
Item* pItem = HumanItemLogic::GetBagItem(pHuman, FromIndex);
if ( pItem != NULL && pItem->GetItemClass() == ICLASS_EQUIP)
{
if(pItem->GetEquipBindLevel()>0) // 装备绑定
{
MsgError.SetID(ERR_ITEM_LOCKED);
pGamePlayer->SendPacket(&MsgError);
g_pLog->FastSaveLog( LOG_FILE_1, "<交易> [%s] 该物品[%d]已绑定,不可交易", pHuman->GetName(), FromIndex ) ;
return PACKET_EXE_CONTINUE;
}
}
if (pItem == NULL)
{
MsgError.SetID(ERR_ILLEGAL);
pGamePlayer->SendPacket(&MsgError);
g_pLog->FastSaveLog( LOG_FILE_1, "<交易> [%s] 背包位置 [%d] 处不存在物品", pHuman->GetName(), FromIndex ) ;
return PACKET_EXE_CONTINUE;
}
if(pItem->IsEmpty() == FALSE)
{
ItemContainer* pBagContainer = HumanItemLogic::GetBagContainer(pHuman, FromIndex);
if ( pBagContainer == NULL )
{
MsgError.SetID(ERR_ILLEGAL);
pGamePlayer->SendPacket(&MsgError);
g_pLog->FastSaveLog( LOG_FILE_1, "<交易> [%s] 背包不存在", pHuman->GetName() ) ;
return PACKET_EXE_CONTINUE;
}
//先查一遍交易盒中是不是已经有该物品了
for(INT i = 0; i<EXCHANGE_BOX_SIZE; i++)
{
_ITEM_GUID guid = (pBagContainer->GetItem(pBagContainer->BagIndex2ConIndex(FromIndex)))->GetGUID() ;
if(pExchangeContainer->GetItem(i)->GetGUID() == guid)
{//物品已经在交易盒中,丢弃该消息
return PACKET_EXE_CONTINUE ;
}
}
//自动找格
INT result =
//.........这里部分代码省略.........
示例11: Execute
uint CGStallAddItemHandler::Execute( CGStallAddItem* pPacket, Player* pPlayer )
{
__ENTER_FUNCTION
GamePlayer* pGamePlayer = (GamePlayer*)pPlayer ;
Assert( pGamePlayer ) ;
Obj_Human* pHuman = pGamePlayer->GetHuman() ;
Assert( pHuman ) ;
Scene* pScene = pHuman->getScene() ;
if( pScene==NULL )
{
Assert(FALSE) ;
return PACKET_EXE_ERROR ;
}
//检查线程执行资源是否正确
Assert( MyGetCurrentThreadID()==pScene->m_ThreadID ) ;
//操作
_ITEM_GUID ItemGuid = pPacket->GetObjGUID();
UINT ItemPrice = pPacket->GetPrice();
BYTE FromType = pPacket->GetFromType();
PET_GUID_t PetGuid = pPacket->GetPetGUID();
if(pHuman->m_StallBox.GetStallStatus() != ServerStallBox::STALL_OPEN)
{
GCStallError Msg;
Msg.SetID(STALL_MSG::ERR_ILLEGAL);
pGamePlayer->SendPacket(&Msg);
g_pLog->FastSaveLog( LOG_FILE_1, "ERROR: CGStallAddItemHandler::ObjID=%d ERR_ILLEGAL: != ServerStallBox::STALL_OPEN", pHuman->GetID()) ;
return PACKET_EXE_CONTINUE ;
}
ItemContainer* pStallContainer = pHuman->m_StallBox.GetContainer();
ItemContainer* pStallPetContainer = pHuman->m_StallBox.GetPetContainer();
GCStallError MsgError;
GCStallAddItem MsgAddItem;
switch(FromType)
{
case STALL_MSG::POS_BAG :
{
//ItemContainer* pMatContainer = pHuman->GetMatContain();
ItemContainer* pBaseContainer = pHuman->GetBaseContain();
//ItemContainer* pBagContainer = NULL;
//if(pMatContainer->GetIndexByGUID(&ItemGuid) >= 0)
//{
// pBagContainer = pMatContainer;
//}
//else if(pBaseContainer->GetIndexByGUID(&ItemGuid) >=0 )
//{
// pBagContainer = pBaseContainer;
//}
//else
//{//guid非法
// Assert(0);
// GCStallError Msg;
// Msg.SetID(STALL_MSG::ERR_ILLEGAL);
// pGamePlayer->SendPacket(&Msg);
// g_pLog->FastSaveLog( LOG_FILE_1, "ERROR: CGStallAddItemHandler::ObjID=%d, ERR_ILLEGAL:World = %d, Server = %d, Serial = %d "
// ,pHuman->GetID(), ItemGuid.m_World, ItemGuid.m_Server, ItemGuid.m_Serial) ;
// return PACKET_EXE_CONTINUE ;
//}
INT IndexInBag = pBaseContainer->GetIndexByGUID(&ItemGuid);
//先查一遍摊位盒中是不是已经有该物品了
for(INT i = 0; i<STALL_BOX_SIZE; i++)
{
if(pStallContainer->GetItem(i)->GetGUID() == ItemGuid )
{//物品已经在t摊位盒中,丢弃该消息
g_pLog->FastSaveLog( LOG_FILE_1, "ERROR: CGStallAddItemHandler::ObjID=%d, Already in box "
,pHuman->GetID()) ;
return PACKET_EXE_CONTINUE ;
}
}
//拷贝到摊位盒
//自动找格
INT result =
g_ItemOperator.CopyItem
(
pBaseContainer,
IndexInBag,
pStallContainer
);
if(result>=0)
{//拷贝成功,
//发送消息给双方客户端
Item* pIt = pStallContainer->GetItem(result);
if(pIt->IsEmpty() == FALSE)
{
//先锁定此物品
g_ItemOperator.LockItem( pBaseContainer, IndexInBag );
//.........这里部分代码省略.........
示例12: Execute
uint CGEquipLevelupHandler::Execute(CGEquipLevelup* pPacket,Player* pPlayer)
{
__ENTER_FUNCTION
GamePlayer* pGamePlayer = (GamePlayer*)pPlayer;
Assert( pGamePlayer );
Obj_Human* pHuman = pGamePlayer->GetHuman();
Assert( pHuman );
Scene* pScene = pHuman->getScene();
if( pScene==NULL )
{
Assert(FALSE);
return PACKET_EXE_ERROR;
}
//检查线程执行资源是否正确
Assert( MyGetCurrentThreadID()==pScene->m_ThreadID );
//交易状态不可操作
if(pHuman->m_ExchangBox.m_Status > 0)
{//丢弃
g_pLog->FastSaveLog( LOG_FILE_1, "ERROR: ObjID=%d, ExchangBox::m_Status>0" ,pHuman->GetID()) ;
return PACKET_EXE_CONTINUE ;
}
//摆摊状态不可操作
if(pHuman->m_StallBox.GetStallStatus() == ServerStallBox::STALL_OPEN)
{//丢弃
g_pLog->FastSaveLog( LOG_FILE_1, "ERROR: ObjID=%d, ServerStallBox::STALL_OPEN" ,pHuman->GetID()) ;
return PACKET_EXE_CONTINUE ;
}
Item* pEquipItem = NULL;
UINT EquipPoint = INVALID_ITEM_POS;
UINT BagIndex = INVALID_ITEM_POS;
EQUIPLEVEUP_RESULT nResult = EQUIPLEVEUP_FAIL;
GCEquipLevelupResult Msg;
switch(pPacket->GetEquipPosType())
{
case ENUM_EQUIP_POINT:
{
EquipPoint = pPacket->GetPos();
if(EquipPoint>HEQUIP_ADORN2)
{
g_pLog->FastSaveLog( LOG_FILE_1, "CGEquipLevelupHandler: EquipPoint error, EquipPoint=%d", EquipPoint) ;
return PACKET_EXE_ERROR;
}
ItemContainer* pEquipContainer = pHuman->GetEquipContain();
if(NULL==pEquipContainer)
{
AssertEx(FALSE,"[CGUseGem]: NULL EquipContainer pointer found!");
}
pEquipItem = pEquipContainer->GetItem((UINT)EquipPoint);
Assert(pEquipItem);
if(pEquipItem->IsEmpty())
{
nResult = EQUIPLEVEUP_EQUIP_FAIL;
Msg.SetResult(nResult);
pGamePlayer->SendPacket( &Msg ) ;
g_pLog->FastSaveLog( LOG_FILE_1, "CGEquipLevelupHandler pEquipItem is Null at EquipPoint= %d", EquipPoint) ;
return PACKET_EXE_CONTINUE;
}
Assert (pEquipItem->GetItemClass() == ICLASS_EQUIP);
if(!(pPacket->getItemID() == pEquipItem->GetGUID()))
{
nResult = EQUIPLEVEUP_EQUIP_FAIL;
Msg.SetResult(nResult);
pGamePlayer->SendPacket( &Msg ) ;
g_pLog->FastSaveLog( LOG_FILE_1, "CGEquipLevelupHandler GUID is different ") ;
return PACKET_EXE_CONTINUE;
}
}
break;
case ENUM_BAG:
{
BagIndex = pPacket->GetPos();
ItemContainer* pItemContainer = HumanItemLogic::GetBagContainer(pHuman,BagIndex);
if( pItemContainer == NULL )
{
g_pLog->FastSaveLog( LOG_FILE_1, "CGEquipLevelupHandler: BagIndex error, BagIndex=%d", BagIndex) ;
return PACKET_EXE_ERROR;
}
if (!pItemContainer->IsCanUse())
{
nResult = EQUIPLEVEUP_BAG_INVALID;
Msg.SetResult(nResult);
pGamePlayer->SendPacket( &Msg ) ;
g_pLog->FastSaveLog( LOG_FILE_1, "CGEquipLevelupHandler: ItemContainer is invalid, ContainerType=%d, BagIndex=%d",
pItemContainer->GetContainerType(), BagIndex) ;
return PACKET_EXE_ERROR;
}
pEquipItem = pItemContainer->GetItem(pItemContainer->BagIndex2ConIndex(BagIndex));
//.........这里部分代码省略.........
示例13: Execute
uint CGStallRemoveItemHandler::Execute( CGStallRemoveItem* pPacket, Player* pPlayer )
{
__ENTER_FUNCTION
GamePlayer* pGamePlayer = (GamePlayer*)pPlayer ;
Assert( pGamePlayer ) ;
Obj_Human* pHuman = pGamePlayer->GetHuman() ;
Assert( pHuman ) ;
Scene* pScene = pHuman->getScene() ;
if( pScene==NULL )
{
Assert(FALSE) ;
return PACKET_EXE_ERROR ;
}
//检查线程执行资源是否正确
Assert( MyGetCurrentThreadID()==pScene->m_ThreadID ) ;
_ITEM_GUID ItemGuid = pPacket->GetObjGUID();
PET_GUID_t PetGuid = pPacket->GetPetGUID();
BYTE ToType = pPacket->GetToType();
UINT Serial = pPacket->GetSerial();
if(pHuman->m_StallBox.GetStallStatus() != ServerStallBox::STALL_OPEN)
{
GCStallError Msg;
Msg.SetID(STALL_MSG::ERR_ILLEGAL);
pGamePlayer->SendPacket(&Msg);
g_pLog->FastSaveLog( LOG_FILE_1, "ERROR: CGStallRemoveItemHandler::ObjName=%s, ERR_ILLEGAL: != ServerStallBox::STALL_OPEN"
,pHuman->GetName()) ;
return PACKET_EXE_CONTINUE;
}
ItemContainer* pStallContainer = pHuman->m_StallBox.GetContainer();
ItemContainer* pStallPetContainer = pHuman->m_StallBox.GetPetContainer();
GCStallError MsgError;
GCStallRemoveItem MsgRemoveItem;
switch(ToType)
{
case STALL_MSG::POS_BAG:
{
INT IndexInStall = pStallContainer->GetIndexByGUID(&ItemGuid);
if(IndexInStall<0)
{
MsgError.SetID(STALL_MSG::ERR_NEED_NEW_COPY);
pGamePlayer->SendPacket(&MsgError);
g_pLog->FastSaveLog( LOG_FILE_1, "ERROR: CGStallRemoveItemHandler::ObjName=%s, ERR_NEED_NEW_COPY: IndexInStall = %d"
,pHuman->GetName(), IndexInStall) ;
return PACKET_EXE_CONTINUE;
}
if( pHuman->m_StallBox.GetSerialByIndex(IndexInStall) > Serial)
{
MsgError.SetID(STALL_MSG::ERR_NEED_NEW_COPY);
pGamePlayer->SendPacket(&MsgError);
g_pLog->FastSaveLog( LOG_FILE_1, "ERROR: CGStallRemoveItemHandler::ObjName=%s, ERR_NEED_NEW_COPY: Serial = %d, BoxSerial = %d"
,pHuman->GetName(), Serial, pHuman->m_StallBox.GetSerialByIndex(IndexInStall)) ;
return PACKET_EXE_CONTINUE;
}
Item* pItem = pStallContainer->GetItem(IndexInStall);
ItemContainer* pBagContainer = HumanItemLogic::GetItemContain(pHuman, pItem->GetItemTableIndex());
INT IndexInBag = pBagContainer->GetIndexByGUID(&ItemGuid);
if(IndexInBag<0)
{
MsgError.SetID(STALL_MSG::ERR_ILLEGAL);
pHuman->m_StallBox.CleanUp();
pGamePlayer->SendPacket(&MsgError);
g_pLog->FastSaveLog( LOG_FILE_1, "ERROR: CGStallRemoveItemHandler::ObjName=%s, ERR_ILLEGAL: IndexInBag = %d"
,pHuman->GetName(), IndexInBag) ;
return PACKET_EXE_CONTINUE;
}
//解锁原背包中的物品
g_ItemOperator.UnlockItem( pBagContainer, IndexInBag );
//干掉物品
if(g_ItemOperator.EraseItem(pStallContainer, IndexInStall)>0)
{
pHuman->m_StallBox.IncSerialByIndex(IndexInStall);
pHuman->m_StallBox.SetPriceByIndex(IndexInStall, 0);
}
else
{
MsgError.SetID(STALL_MSG::ERR_ILLEGAL);
pHuman->m_StallBox.CleanUp();
pGamePlayer->SendPacket(&MsgError);
g_pLog->FastSaveLog( LOG_FILE_1, "ERROR: CGStallRemoveItemHandler::ObjName=%s, ERR_ILLEGAL: IndexInStall = %d"
,pHuman->GetName(), IndexInStall) ;
return PACKET_EXE_CONTINUE;
}
//通知客户端
MsgRemoveItem.SetObjGUID( ItemGuid );
MsgRemoveItem.SetSerial( pHuman->m_StallBox.GetSerialByIndex(IndexInStall) );
MsgRemoveItem.SetToType( STALL_MSG::POS_BAG );
//.........这里部分代码省略.........
示例14: if
uint CGPackage_SwapItemHandler :: Execute( CGPackage_SwapItem* pPacket, Player* pPlayer )
{
__ENTER_FUNCTION
GamePlayer* pGamePlayer = (GamePlayer*)pPlayer ;
Assert( pGamePlayer ) ;
Obj_Human* pHuman = pGamePlayer->GetHuman() ;
Assert( pHuman ) ;
Scene* pScene = pHuman->getScene() ;
if( pScene==NULL )
{
Assert(FALSE) ;
return PACKET_EXE_ERROR;
}
//检查线程执行资源是否正确
Assert( MyGetCurrentThreadID()==pScene->m_ThreadID ) ;
//得到所要交换的两个索引
INT index1 = pPacket->GetPackageIndex1();
INT index2 = pPacket->GetPackageIndex2();
INT bSucc = -1;
GCPackage_SwapItem msg;
//扩展包互换 禁止
if ((index1>=EXTRA_CONTAINER_OFFSET)&&(index2>=EXTRA_CONTAINER_OFFSET))
{
msg.SetResult(SWITCHITEM_EXTRBAG_EXCHANGE_FAIL);
pGamePlayer->SendPacket(&msg);
g_pLog->FastSaveLog( LOG_FILE_1, "CGPackage_SwapItem: index1=%d, index2=%d extrabag fail",
index1, index2) ;
return PACKET_EXE_CONTINUE;
}
if (index1>=EXTRA_CONTAINER_OFFSET)
{
ItemContainer* pExtraBagContainer = HumanItemLogic::GetBagByExtraContainPos(pHuman, index1);
//位置无效
if (pExtraBagContainer == NULL)
{
g_pLog->FastSaveLog( LOG_FILE_1, "CGPackage_SwapItem: index1=%d, is invalid", index1) ;
return PACKET_EXE_ERROR;
}
//扩展包不存在
if (!pExtraBagContainer->IsValid())
{
msg.SetResult(SWITCHITEM_SOURCEEXTRBAG_NOALIVE);
pGamePlayer->SendPacket(&msg);
g_pLog->FastSaveLog( LOG_FILE_1, "CGPackage_SwapItem: index1=%d, extrabag is not alive", index1) ;
return PACKET_EXE_CONTINUE;
}
//非空扩展包不许移动
if (!pExtraBagContainer->IsEmpty())
{
msg.SetResult(SWITCHITEM_SOURCEEXTRBAG_ITEM_FAIL);
pGamePlayer->SendPacket(&msg);
g_pLog->FastSaveLog( LOG_FILE_1, "CGPackage_SwapItem: index1=%d, extrabag has items", index1) ;
return PACKET_EXE_CONTINUE;
}
ItemContainer* pExtraContainer = pHuman->GetExtraContain();
INT index_container1 = pExtraContainer->BagIndex2ConIndex(index1);
ItemContainer* pBagContainer = HumanItemLogic::GetBagContainer(pHuman, index2);
INT index_container2 = pBagContainer->BagIndex2ConIndex(index2);
if (pExtraBagContainer->IsInContainer(index2))
{
return PACKET_EXE_CONTINUE;
}
Item* pItem2 = pBagContainer->GetItem(index_container2);
//不能将扩展包移动到有物品位置
if (!pItem2->IsEmpty())
{
msg.SetResult(SWITCHITEM_SOURCEEXTRBAG_ITEM_FAIL);
pGamePlayer->SendPacket(&msg);
g_pLog->FastSaveLog( LOG_FILE_1, "CGPackage_SwapItem: index1=%d, extrabag has items", index1) ;
return PACKET_EXE_CONTINUE;
}
bSucc = g_ItemOperator.MoveItem(pExtraContainer, index_container1, pBagContainer, index_container2);
if (bSucc>=0)
{
pHuman->ReInitExtraBag();
msg.SetResult(SWITCHITEM_SUCCESS);
msg.SetPackageIndex1(index1);
msg.SetPackageIndex2(index2);
pGamePlayer->SendPacket(&msg);
g_pLog->FastSaveLog( LOG_FILE_1, "CGPackage_SwapItem: index1=%d, index2=%d Success",
index1, index2 ) ;
return PACKET_EXE_CONTINUE;
}
}
if ((index2>=EXTRA_CONTAINER_OFFSET)&&(index2<BASE_BAG_POS))
{
ItemContainer* pBagContainer = HumanItemLogic::GetBagContainer(pHuman, index1);
Item* pItem1 = pBagContainer->GetItem(pBagContainer->BagIndex2ConIndex(index1));
if (pItem1->IsEmpty())
//.........这里部分代码省略.........