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; case CGBankAddItem::AUTO_POS_BOX2: { //先查询是不是有可以合并的物品,(只在本租赁箱中) if( pBagItem->IsCanLay() ) { for( INT i=RENTBOX2_START_INDEX; i<RENTBOX3_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 = RENTBOX2_START_INDEX; if(0 == bSplice) { while( ITEMREFPTRISVALID(HumanItemLogic::GetBankItem(pHuman, indextemp)) && indextemp < RENTBOX3_START_INDEX ) { indextemp++; } if(indextemp == RENTBOX3_START_INDEX) { indexTo = indextemp-1; } else { indexTo = indextemp; } } } break; case CGBankAddItem::AUTO_POS_BOX3: { //先查询是不是有可以合并的物品,(只在本租赁箱中) if( pBagItem->IsCanLay() ) { for( INT i=RENTBOX3_START_INDEX; i<RENTBOX4_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 = RENTBOX3_START_INDEX; if(0 == bSplice) { while( ITEMREFPTRISVALID(HumanItemLogic::GetBankItem(pHuman, indextemp)) && indextemp < RENTBOX4_START_INDEX ) { indextemp++; } if(indextemp == RENTBOX4_START_INDEX) { indexTo = indextemp-1; } else { indexTo = indextemp; } } } break; case CGBankAddItem::AUTO_POS_BOX4: { //先查询是不是有可以合并的物品,(只在本租赁箱中) if( pBagItem->IsCanLay() ) { for( INT i=RENTBOX4_START_INDEX; i<RENTBOX5_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 = RENTBOX4_START_INDEX; if(0 == bSplice) { while( ITEMREFPTRISVALID(HumanItemLogic::GetBankItem(pHuman, indextemp)) && indextemp < RENTBOX5_START_INDEX ) { indextemp++; } if(indextemp == RENTBOX5_START_INDEX) { indexTo = indextemp-1; } else { indexTo = indextemp; } } } break; case CGBankAddItem::AUTO_POS_BOX5: { //先查询是不是有可以合并的物品,(只在本租赁箱中) if( pBagItem->IsCanLay() ) { for( INT i=RENTBOX5_START_INDEX; i<MAX_BANK_SIZE; 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 = RENTBOX5_START_INDEX; if(0 == bSplice) { while( ITEMREFPTRISVALID(HumanItemLogic::GetBankItem(pHuman, indextemp)) && indextemp < MAX_BANK_SIZE ) { indextemp++; } if(indextemp == MAX_BANK_SIZE) { indexTo = indextemp-1; } else { indexTo = indextemp; } } } break; //检查直接选定的目标是不是可以合并 default: { if( pBagItem->IsCanLay() ) { Item *pItemFrom = pBagContainer->GetItem(pBagContainer->BagIndex2ConIndex(indexFrom)); Item *pItemTo = pBankContainer->GetItem(indexTo); if( pItemFrom->GetItemTableIndex() == pItemTo->GetItemTableIndex() ) { bSplice = 2; nSpliceTo = indexTo; } } } break; } //验证位置的合法性 if( indexFrom>=0 && indexFrom<MAX_BAG_SIZE && indexTo>=0 && (indexTo<(UINT)(pHuman->__GetBankEndIndex()) || (indexTo>=251 && indexTo<=255) ) ) { if(1 == bSplice) //执行合并 { //验证位置里是否有东西 if(ITEMREFPTRISVALID(HumanItemLogic::GetItem(pHuman, indexFrom))) { if(ITEMREFPTRISVALID(HumanItemLogic::GetBankItem(pHuman, nSpliceTo))) { g_ItemOperator.SpliceItem(pBagContainer, (UINT)pBagContainer->BagIndex2ConIndex(indexFrom), pBankContainer, (UINT)nSpliceTo); Item *pItemBag = pBagContainer->GetItem(pBagContainer->BagIndex2ConIndex(indexFrom)); Item *pItemBank= pBankContainer->GetItem(nSpliceTo); //发一个通知更新银行的消息 GCBankItemInfo MsgBankItemInfo; MsgBankItemInfo.setBankIndex((WORD)nSpliceTo); MsgBankItemInfo.setIsNull(pItemBank->IsEmpty()); pItemBank->SaveValueTo(MsgBankItemInfo.getItem()); pGamePlayer->SendPacket( &MsgBankItemInfo ); //发送一个通知背包更新的消息 GCItemInfo MsgBagItemInfo; MsgBagItemInfo.setID((WORD)indexFrom); MsgBagItemInfo.setIsNull(pItemBag->IsEmpty()); pItemBag->SaveValueTo(MsgBagItemInfo.getItem()); pGamePlayer->SendPacket( &MsgBagItemInfo ); } } g_pLog->FastSaveLog( LOG_FILE_1, "CGBankAddItemHandler Empty Item indexFrom = %d", indexFrom) ; return PACKET_EXE_CONTINUE; } else if(2 == bSplice) { //验证位置里是否有东西 if(ITEMREFPTRISVALID(HumanItemLogic::GetItem(pHuman, indexFrom))) { if(ITEMREFPTRISVALID(HumanItemLogic::GetBankItem(pHuman, nSpliceTo))) { g_ItemOperator.MoveSpliceItem(pBagContainer, (UINT)pBagContainer->BagIndex2ConIndex(indexFrom), pBankContainer, (UINT)nSpliceTo); Item *pItemBag = pBagContainer->GetItem(pBagContainer->BagIndex2ConIndex(indexFrom)); Item *pItemBank= pBankContainer->GetItem(nSpliceTo); //发一个通知更新银行的消息 GCBankItemInfo MsgBankItemInfo; MsgBankItemInfo.setBankIndex((WORD)nSpliceTo); MsgBankItemInfo.setIsNull(pItemBank->IsEmpty()); pItemBank->SaveValueTo(MsgBankItemInfo.getItem()); pGamePlayer->SendPacket( &MsgBankItemInfo ); //发送一个通知背包更新的消息 GCItemInfo MsgBagItemInfo; MsgBagItemInfo.setID((WORD)indexFrom); MsgBagItemInfo.setIsNull(pItemBag->IsEmpty()); pItemBag->SaveValueTo(MsgBagItemInfo.getItem()); pGamePlayer->SendPacket( &MsgBagItemInfo ); } } g_pLog->FastSaveLog( LOG_FILE_1, "CGBankAddItemHandler Empty Item indexFrom = %d", indexFrom) ; return PACKET_EXE_CONTINUE; } else //不执行合并 { //验证位置里是否有东西 if(ITEMREFPTRISVALID(HumanItemLogic::GetItem(pHuman, indexFrom))) { if(ITEMREFPTRISVALID(HumanItemLogic::GetBankItem(pHuman, indexTo))) //执行了交换 { //判断银行内的这个物品是不是能够放入背包中 ItemContainer* pBankContainer = pHuman->GetBankContain(); Item *pItem = pBankContainer->GetItem(indexTo); ItemContainer *pHumanCon = HumanItemLogic::GetItemContain(pHuman, pItem->GetItemTableIndex()); if( !pHumanCon ) { //返回错误信息 Msg.SetFromType(GCBankAddItem::ERROR_POS); break; } if( !pHumanCon->IsInContainer(indexFrom) ) { //返回错误信息 Msg.SetFromType(GCBankAddItem::ERROR_POS); break; } g_ItemOperator.ExchangeItem(pBagContainer, pBagContainer->BagIndex2ConIndex(indexFrom), pBankContainer, (UINT)indexTo); //执行了交换 Msg.SetOperateType(GCBankAddItem::OPERATE_SWAP); } else //执行了移动 { g_ItemOperator.MoveItem(pBagContainer, pBagContainer->BagIndex2ConIndex(indexFrom), pBankContainer, (UINT)indexTo); //执行了移动 Msg.SetOperateType(GCBankAddItem::OPERATE_MOVE); } Msg.SetFromType(GCBankAddItem::BAG_POS); Msg.SetIndexFrom(indexFrom); Msg.SetIndexTo(indexTo); } else { Msg.SetFromType(GCBankAddItem::ERROR_POS); } } } else //数据不合法 { Msg.SetFromType(GCBankAddItem::ERROR_POS); } } break; default: break; } pGamePlayer->SendPacket( &Msg ) ; g_pLog->FastSaveLog( LOG_FILE_1, "CGBankAddItemHandler: indexFrom=%d, indexTo=%d", indexFrom, indexTo ) ; return PACKET_EXE_CONTINUE ; __LEAVE_FUNCTION return PACKET_EXE_ERROR ; }
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()); pGamePlayer->SendPacket(&msg2); } g_pLog->FastSaveLog( LOG_FILE_1, "CGBankSwapItemHandler: MoveSpliceItem" ) ; return PACKET_EXE_CONTINUE ; } else { //判断银行内的这个物品是不是能够放入背包中 ItemContainer* pBankContainer = pHuman->GetBankContain(); Item *pItem = pBankContainer->GetItem(indexTo); ItemContainer *pHumanCon = HumanItemLogic::GetItemContain(pHuman, pItem->GetItemTableIndex()); if( !pHumanCon ) { //返回错误信息 Msg.SetToType(GCBankSwapItem::ERROR_POS); break; } if( !pHumanCon->IsInContainer(indexFrom) ) { //返回错误信息 Msg.SetToType(GCBankSwapItem::ERROR_POS); break; } g_ItemOperator.ExchangeItem(pBagContainer, pBagContainer->BagIndex2ConIndex(indexFrom), pBankContainer, (UINT)indexTo); Msg.SetFromType(GCBankSwapItem::BAG_POS); Msg.SetToType(GCBankSwapItem::BANK_POS); Msg.SetIndexFrom(indexFrom); Msg.SetIndexTo(indexTo); } } else { Msg.SetFromType(GCBankSwapItem::ERROR_POS); Msg.SetToType(GCBankSwapItem::ERROR_POS); } } else { Msg.SetFromType(GCBankSwapItem::ERROR_POS); Msg.SetToType(GCBankSwapItem::ERROR_POS); } } break; default: break; } } break; case CGBankSwapItem::BANK_POS: { switch(pPacket->GetToType()) { case CGBankSwapItem::BAG_POS: // Bank->Bag { //验证位置的合法性 if( indexTo>=0 && indexTo<MAX_BAG_SIZE && indexFrom>=0 && indexFrom<(UINT)(pHuman->__GetBankEndIndex()) ) { if(ITEMREFPTRISVALID(HumanItemLogic::GetBankItem(pHuman, indexFrom)) && ITEMREFPTRISVALID(HumanItemLogic::GetItem(pHuman, indexTo)) ) { ItemContainer* pBagContainer = HumanItemLogic::GetContainer(pHuman,indexFrom); ItemContainer* pBankContainer = pHuman->GetBankContain(); //判断银行内的这个物品是不是能够放入背包中 Item *pItem = pBankContainer->GetItem(indexFrom); ItemContainer *pHumanCon = HumanItemLogic::GetItemContain(pHuman, pItem->GetItemTableIndex()); if( !pHumanCon ) { //返回错误信息 Msg.SetToType(GCBankSwapItem::ERROR_POS); break; } if( !pHumanCon->IsInContainer(indexTo) ) { //返回错误信息 Msg.SetToType(GCBankSwapItem::ERROR_POS); break; } g_ItemOperator.ExchangeItem(pBagContainer, pBagContainer->BagIndex2ConIndex(indexTo), pBankContainer, (UINT)indexFrom); //pHuman->GetDB()->SwapBankWithBag(indexTo, indexFrom); Msg.SetFromType(GCBankSwapItem::BANK_POS); Msg.SetToType(GCBankSwapItem::BAG_POS); Msg.SetIndexFrom(indexFrom); Msg.SetIndexTo(indexTo); } else { Msg.SetFromType(GCBankSwapItem::ERROR_POS); Msg.SetToType(GCBankSwapItem::ERROR_POS); } } else { Msg.SetFromType(GCBankSwapItem::ERROR_POS); Msg.SetToType(GCBankSwapItem::ERROR_POS); } } break; case CGBankSwapItem::EQUIP_POS: { } break; case CGBankSwapItem::BANK_POS: //Bank->Bank { ItemContainer *pBankContainer = pHuman->GetBankContain(); Item *pItem1 = pBankContainer->GetItem( indexFrom ); INT nSpliceType = 0; INT nSpliceTo = -1; //银行容器 ItemContainer* pBankContain = pHuman->GetBankContain(); Item *pItem = pBankContain->GetItem(indexFrom); UINT TempIndexTo = indexTo; if(pItem->IsEmpty()||pItem1->IsEmpty()) { g_pLog->FastSaveLog( LOG_FILE_1, "CGBankSwapItemHandler: Too much click" ) ; return PACKET_EXE_CONTINUE; } switch(TempIndexTo) { case CGBankSwapItem::AUTO_POS_BOX1: { if(pItem1->IsCanLay()) { for(INT i=RENTBOX1_START_INDEX; i<RENTBOX2_START_INDEX; i++) { Item *pItem2 = pBankContain->GetItem(i); if( pItem1->GetItemTableIndex() == pItem2->GetItemTableIndex() && pItem1->GetLayedNum() + pItem2->GetLayedNum() <= pItem2->GetMaxLayedNum() ) { nSpliceType = 1; nSpliceTo = i; indexTo = i; break; } } } BYTE indextemp = RENTBOX1_START_INDEX; if(0 == nSpliceType) { while( ITEMREFPTRISVALID(HumanItemLogic::GetBankItem(pHuman, indextemp)) && indextemp < RENTBOX2_START_INDEX ) { indextemp++; } if(indextemp == RENTBOX2_START_INDEX) { indexTo = indextemp-1; } else { indexTo = indextemp; } } } break; case CGBankSwapItem::AUTO_POS_BOX2: { if(pItem1->IsCanLay()) { for(INT i=RENTBOX2_START_INDEX; i<RENTBOX3_START_INDEX; i++) { Item *pItem2 = pBankContain->GetItem(i); if( pItem1->GetItemTableIndex() == pItem2->GetItemTableIndex() && pItem1->GetLayedNum() + pItem2->GetLayedNum() <= pItem2->GetMaxLayedNum() ) { nSpliceType = 1; nSpliceTo = i; indexTo = i; break; } } } BYTE indextemp = RENTBOX2_START_INDEX; if(0 == nSpliceType) { while( ITEMREFPTRISVALID(HumanItemLogic::GetBankItem(pHuman, indextemp)) && indextemp < RENTBOX3_START_INDEX ) { indextemp++; } if(indextemp == RENTBOX3_START_INDEX) { indexTo = indextemp-1; } else { indexTo = indextemp; } } } break; case CGBankSwapItem::AUTO_POS_BOX3: { if(pItem1->IsCanLay()) { for(INT i=RENTBOX3_START_INDEX; i<RENTBOX4_START_INDEX; i++) { Item *pItem2 = pBankContain->GetItem(i); if( pItem1->GetItemTableIndex() == pItem2->GetItemTableIndex() && pItem1->GetLayedNum() + pItem2->GetLayedNum() <= pItem2->GetMaxLayedNum() ) { nSpliceType = 1; nSpliceTo = i; indexTo = i; break; } } } BYTE indextemp = RENTBOX3_START_INDEX; if(0 == nSpliceType) { while( ITEMREFPTRISVALID(HumanItemLogic::GetBankItem(pHuman, indextemp)) && indextemp < RENTBOX4_START_INDEX ) { indextemp++; } if(indextemp == RENTBOX4_START_INDEX) { indexTo = indextemp-1; } else { indexTo = indextemp; } } } break; case CGBankSwapItem::AUTO_POS_BOX4: { if(pItem1->IsCanLay()) { for(INT i=RENTBOX4_START_INDEX; i<RENTBOX5_START_INDEX; i++) { Item *pItem2 = pBankContain->GetItem(i); if( pItem1->GetItemTableIndex() == pItem2->GetItemTableIndex() && pItem1->GetLayedNum() + pItem2->GetLayedNum() <= pItem2->GetMaxLayedNum() ) { nSpliceType = 1; nSpliceTo = i; indexTo = i; break; } } } BYTE indextemp = RENTBOX4_START_INDEX; if(0 == nSpliceType) { while( ITEMREFPTRISVALID(HumanItemLogic::GetBankItem(pHuman, indextemp)) && indextemp < RENTBOX5_START_INDEX ) { indextemp++; } if(indextemp == RENTBOX5_START_INDEX) { indexTo = indextemp-1; } else { indexTo = indextemp; } } } break; case CGBankSwapItem::AUTO_POS_BOX5: { if(pItem1->IsCanLay()) { for(INT i=RENTBOX5_START_INDEX; i<MAX_BANK_SIZE; i++) { Item *pItem2 = pBankContain->GetItem(i); if( pItem1->GetItemTableIndex() == pItem2->GetItemTableIndex() && pItem1->GetLayedNum() + pItem2->GetLayedNum() <= pItem2->GetMaxLayedNum() ) { nSpliceType = 1; nSpliceTo = i; indexTo = i; break; } } } BYTE indextemp = RENTBOX5_START_INDEX; if(0 == nSpliceType) { while( ITEMREFPTRISVALID(HumanItemLogic::GetBankItem(pHuman, indextemp)) && indextemp < MAX_BANK_SIZE ) { indextemp++; } if(indextemp == MAX_BANK_SIZE) { indexTo = indextemp-1; } else { indexTo = indextemp; } } } break; default: { if(pItem->IsCanLay()) { Item *pItem2 = pBankContainer->GetItem(indexTo); if( pItem1->GetItemTableIndex() == pItem2->GetItemTableIndex() ) { nSpliceType = 2; nSpliceTo = indexTo; } } } break; } //验证位置的合法性 if( indexTo>=0 && indexTo<(UINT)(pHuman->__GetBankEndIndex()) && indexFrom>=0 && indexFrom<(UINT)(pHuman->__GetBankEndIndex()) ) { if(1 == nSpliceType) //执行合并 { //验证位置里是否有东西 if(ITEMREFPTRISVALID(HumanItemLogic::GetBankItem(pHuman, indexFrom))) { if(ITEMREFPTRISVALID(HumanItemLogic::GetBankItem(pHuman, nSpliceTo))) { g_ItemOperator.SpliceItem(pBankContainer, (UINT)indexFrom, pBankContainer, (UINT)nSpliceTo); Item *pItem1 = pBankContainer->GetItem(indexFrom); Item *pItem2 = pBankContainer->GetItem(nSpliceTo); //发一个通知更新银行的消息 GCBankItemInfo MsgBankItemInfo1; MsgBankItemInfo1.setBankIndex((WORD)indexFrom); MsgBankItemInfo1.setIsNull(pItem1->IsEmpty()); pItem1->SaveValueTo(MsgBankItemInfo1.getItem()); pGamePlayer->SendPacket( &MsgBankItemInfo1 ); //发送一个通知背包更新的消息 GCBankItemInfo MsgBankItemInfo2; MsgBankItemInfo2.setBankIndex((WORD)nSpliceTo); MsgBankItemInfo2.setIsNull(pItem2->IsEmpty()); pItem2->SaveValueTo(MsgBankItemInfo2.getItem()); pGamePlayer->SendPacket( &MsgBankItemInfo2 ); } } g_pLog->FastSaveLog( LOG_FILE_1, "CGBankSwapItemHandler: empty item" ) ; return PACKET_EXE_CONTINUE; } if(2 == nSpliceType) //执行合并 { //验证位置里是否有东西 if(ITEMREFPTRISVALID(HumanItemLogic::GetBankItem(pHuman, indexFrom))) { if(ITEMREFPTRISVALID(HumanItemLogic::GetBankItem(pHuman, nSpliceTo))) { g_ItemOperator.MoveSpliceItem(pBankContainer, (UINT)indexFrom, pBankContainer, (UINT)nSpliceTo); Item *pItem1 = pBankContainer->GetItem(indexFrom); Item *pItem2 = pBankContainer->GetItem(nSpliceTo); //发一个通知更新银行的消息 GCBankItemInfo MsgBankItemInfo1; MsgBankItemInfo1.setBankIndex((WORD)indexFrom); MsgBankItemInfo1.setIsNull(pItem1->IsEmpty()); pItem1->SaveValueTo(MsgBankItemInfo1.getItem()); pGamePlayer->SendPacket( &MsgBankItemInfo1 ); //发送一个通知背包更新的消息 GCBankItemInfo MsgBankItemInfo2; MsgBankItemInfo2.setBankIndex((WORD)nSpliceTo); MsgBankItemInfo2.setIsNull(pItem2->IsEmpty()); pItem2->SaveValueTo(MsgBankItemInfo2.getItem()); pGamePlayer->SendPacket( &MsgBankItemInfo2 ); } } g_pLog->FastSaveLog( LOG_FILE_1, "CGBankSwapItemHandler: empty item indexFrom = %d", indexFrom ) ; return PACKET_EXE_CONTINUE; } if(indexTo == indexFrom) { /*Msg.SetFromType(GCBankSwapItem::ERROR_POS); Msg.SetToType(GCBankSwapItem::ERROR_POS);*/ } else if(ITEMREFPTRISVALID(HumanItemLogic::GetBankItem(pHuman, indexFrom))) { if(ITEMREFPTRISVALID(HumanItemLogic::GetBankItem(pHuman, indexTo))) { ItemContainer* pBankContainer = pHuman->GetBankContain(); g_ItemOperator.ExchangeItem(pBankContainer, (UINT)indexFrom, pBankContainer, (UINT)indexTo); } else { ItemContainer* pBankContainer = pHuman->GetBankContain(); g_ItemOperator.MoveItem(pBankContainer, (UINT)indexFrom, pBankContainer, (UINT)indexTo); } //pHuman->GetDB()->SwapBankWithBank(indexTo, indexFrom); Msg.SetFromType(GCBankSwapItem::BANK_POS); Msg.SetToType(GCBankSwapItem::BANK_POS); Msg.SetIndexFrom(indexFrom); Msg.SetIndexTo(indexTo); } else { Msg.SetFromType(GCBankSwapItem::ERROR_POS); Msg.SetToType(GCBankSwapItem::ERROR_POS); } } else { Msg.SetFromType(GCBankSwapItem::ERROR_POS); Msg.SetToType(GCBankSwapItem::ERROR_POS); } } break; default: break; } } break; default: break; } pGamePlayer->SendPacket(&Msg); g_pLog->FastSaveLog( LOG_FILE_1, "CGBankSwapItemHandler: indexFrom=%d, indexTo=%d", indexFrom, indexTo ) ; return PACKET_EXE_CONTINUE ; __LEAVE_FUNCTION return PACKET_EXE_ERROR ; }
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()) { return PACKET_EXE_CONTINUE; } ItemContainer* pExtraContainer = pHuman->GetExtraContain(); //将物品放入扩展包 ItemContainer* pExtraBagContainer = HumanItemLogic::GetBagByExtraContainPos(pHuman, index2); if (pExtraBagContainer == NULL) { g_pLog->FastSaveLog( LOG_FILE_1, "CGPackage_SwapItem: index2=%d, is invalid", index2) ; return PACKET_EXE_ERROR; } INT index_container1 = pBagContainer->BagIndex2ConIndex(index1); INT index_container2 = pExtraContainer->BagIndex2ConIndex(index2); //扩展包不存在 if (!pExtraBagContainer->IsValid()) { if (pItem1->GetItemClass() == ICLASS_EXTRABAG) { INT ret = g_ItemOperator.MoveItem(pBagContainer, index_container1, pExtraContainer, index_container2); if (ret>=0) { msg.SetResult(SWITCHITEM_SUCCESS); msg.SetPackageIndex1(index1); msg.SetPackageIndex2(index2); pGamePlayer->SendPacket(&msg); Item* pDestItem = pExtraContainer->GetItem(index_container2); Assert(pDestItem); if (pDestItem->GetExtraBagBeginTime() == INVALID_TIME) { pDestItem->SetExtraBagBeginTime(); } pHuman->ReInitExtraBag(); g_pLog->FastSaveLog( LOG_FILE_1, "CGPackage_SwapItem: use extrabagitem, index2=%d ", index2 ) ; return PACKET_EXE_CONTINUE; } msg.SetResult(SWITCHITEM_FAIL); pGamePlayer->SendPacket(&msg); return PACKET_EXE_CONTINUE; } g_pLog->FastSaveLog( LOG_FILE_1, "CGPackage_SwapItem: index2=%d, can't put", index2) ; return PACKET_EXE_CONTINUE; } if (pExtraBagContainer->IsInContainer(index1)) { return PACKET_EXE_CONTINUE; } if (pExtraBagContainer->IsCanUse()) { INT nBagIndex = -1; nBagIndex =g_ItemOperator.MoveItem(pBagContainer, index_container1, pExtraBagContainer, -1); if (nBagIndex>=0) { msg.SetResult(SWITCHITEM_SUCCESS); msg.SetPackageIndex1(index1); msg.SetPackageIndex2(pExtraBagContainer->ConIndex2BagIndex(nBagIndex)); pGamePlayer->SendPacket(&msg); g_pLog->FastSaveLog( LOG_FILE_1, "CGPackage_SwapItem: index1=%d, index2=%d Success", index1, index2 ) ; return PACKET_EXE_CONTINUE; } msg.SetResult(SWITCHITEM_FAIL); pGamePlayer->SendPacket(&msg); return PACKET_EXE_CONTINUE; } msg.SetResult(SWITCHITEM_FAIL); pGamePlayer->SendPacket(&msg); return PACKET_EXE_CONTINUE; } if (index2 == BASE_BAG_POS) { if (index1<MAX_SINGLEBAG_SIZE) { return PACKET_EXE_CONTINUE; } ItemContainer* pBagContainer = pHuman->GetBaseContain(); ItemContainer* pExtraBagContainer = HumanItemLogic::GetBagContainer(pHuman, index1); if (pExtraBagContainer == NULL) { g_pLog->FastSaveLog( LOG_FILE_1, "CGPackage_SwapItem: index1=%d, index2=%d fail", index1, index2 ) ; return PACKET_EXE_ERROR; } INT index_container1 = pExtraBagContainer->BagIndex2ConIndex(index1); INT nBagIndex = -1; nBagIndex =g_ItemOperator.MoveItem(pExtraBagContainer, index_container1, pBagContainer, -1); if (nBagIndex>=0) { msg.SetResult(SWITCHITEM_SUCCESS); msg.SetPackageIndex1(index1); msg.SetPackageIndex2(pBagContainer->ConIndex2BagIndex(nBagIndex)); pGamePlayer->SendPacket(&msg); g_pLog->FastSaveLog( LOG_FILE_1, "CGPackage_SwapItem: index1=%d, index2=%d Success", index1, index2 ) ; return PACKET_EXE_CONTINUE; } msg.SetResult(SWITCHITEM_FAIL); pGamePlayer->SendPacket(&msg); return PACKET_EXE_CONTINUE; } //调用物品底层交换物品 Item* pItem1 = HumanItemLogic::GetBagItem(pHuman, index1); Item* pItem2 = HumanItemLogic::GetBagItem(pHuman, index2); if ((pItem1==NULL)||(pItem2==NULL)) { g_pLog->FastSaveLog( LOG_FILE_1, "CGPackage_SwapItem: index1=%d, index2=%d pos fail", index1, index2) ; return PACKET_EXE_ERROR; } //判断是否在同一个容器内 ItemContainer* pBagContainer = HumanItemLogic::GetBagContainer(pHuman, index1); if(pBagContainer != HumanItemLogic::GetBagContainer(pHuman, index2)) return PACKET_EXE_CONTINUE; if (!pBagContainer->IsCanUse()) { msg.SetResult(SWITCHITEM_SOURCEEXTRBAG_ITEM_FAIL); pGamePlayer->SendPacket(&msg); return PACKET_EXE_CONTINUE; } //转换Index基数 INT index_container1 = pBagContainer->BagIndex2ConIndex(index1); INT index_container2 = pBagContainer->BagIndex2ConIndex(index2); //两个物品格都是空格 if(pItem1->IsEmpty() && pItem2->IsEmpty()) { return PACKET_EXE_CONTINUE; } // Item1 -> Item2(EMPTY) else if(!(pItem1->IsEmpty()) && pItem2->IsEmpty()) { bSucc = g_ItemOperator.MoveItem(pBagContainer, index_container1, pBagContainer, index_container2) >= 0; } // Item1(EMPTY) <- Item2 else if(pItem1->IsEmpty() && !(pItem2->IsEmpty())) { bSucc = g_ItemOperator.MoveItem(pBagContainer, index_container2, pBagContainer, index_container1) >= 0; } // Item1 <-> Item2 else { ITEM_LOG_PARAM ItemLogParam; //合并相同的物品 //1、判断两个物品是不是可以叠加的 if(pItem1->GetItemTableIndex() == pItem2->GetItemTableIndex() && pItem1->IsCanLay()) { int Count = pItem1->GetLayedNum(); //2、转移物品 if(g_ItemOperator.MoveItem(pBagContainer, index_container1, index_container2) >= 0) { //合并成功,将结果通知客户端,不能只发送Index,需要包括内容; _ITEM temp1; pItem1->SaveValueTo(&temp1); GCItemInfo msg1; msg1.setID(index1); msg1.setIsNull(pItem1->IsEmpty()); msg1.setItem(&temp1); pGamePlayer->SendPacket(&msg1); _ITEM temp2; pItem2->SaveValueTo(&temp2); GCItemInfo msg2; msg2.setID(index2); msg2.setIsNull(pItem2->IsEmpty()); msg2.setItem(&temp2); pGamePlayer->SendPacket(&msg2); ITEM_LOG_PARAM ItemLogParam; ItemLogParam.OpType = ITEM_TILED_BAG_DEST; ItemLogParam.CharGUID = pHuman->GetGUID(); ItemLogParam.SceneID = pHuman->getScene()->SceneID(); ItemLogParam.XPos = pHuman->getWorldPos()->m_fX; ItemLogParam.ZPos = pHuman->getWorldPos()->m_fZ; ItemLogParam.ContainerPos = index2; ItemLogParam.Count = Count; ItemLogParam.ItemGuid = pItem2->GetGUID(); SaveItemLog(&ItemLogParam); ItemLogParam.OpType = ITEM_TILED_BAG_DEST; ItemLogParam.CharGUID = pHuman->GetGUID(); ItemLogParam.SceneID = pHuman->getScene()->SceneID(); ItemLogParam.XPos = pHuman->getWorldPos()->m_fX; ItemLogParam.ZPos = pHuman->getWorldPos()->m_fZ; ItemLogParam.ContainerPos = index1; ItemLogParam.Count = Count; ItemLogParam.ItemGuid = pItem1->GetGUID(); SaveItemLog(&ItemLogParam); return PACKET_EXE_CONTINUE ; } } // 交换两物品 bSucc = g_ItemOperator.ExchangeItem(pBagContainer, index_container1, pBagContainer, index_container2) == ITEMOE_SUCCESS; } 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 Succ=%s", index1, index2, bSucc?"TRUE":"FALSE" ) ; return PACKET_EXE_CONTINUE ; __LEAVE_FUNCTION return PACKET_EXE_ERROR ; }