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 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)); if(pEquipItem->IsEmpty()) { nResult = EQUIPLEVEUP_EQUIP_FAIL; Msg.SetResult(nResult); pGamePlayer->SendPacket( &Msg ) ; g_pLog->FastSaveLog( LOG_FILE_1, "Obj_Human::EquipLevelup pEquipItem is Null at BagIndex= %d", BagIndex) ; return PACKET_EXE_CONTINUE; } if (pEquipItem->GetItemClass() != ICLASS_EQUIP) { nResult = EQUIPLEVEUP_EQUIP_FAIL; Msg.SetResult(nResult); pGamePlayer->SendPacket( &Msg ) ; g_pLog->FastSaveLog( LOG_FILE_1, "EquipLevelup GetItemClass is not ICLASS_EQUIP ") ; return PACKET_EXE_CONTINUE; } if(!(pPacket->getItemID() == pEquipItem->GetGUID())) { nResult = EQUIPLEVEUP_EQUIP_FAIL; Msg.SetResult(nResult); pGamePlayer->SendPacket( &Msg ) ; g_pLog->FastSaveLog( LOG_FILE_1, "Obj_Human::EquipLevelup GUID is different ") ; return PACKET_EXE_CONTINUE; } if (pEquipItem->GetItemType() > EQUIP_ADORN) { nResult = EQUIPLEVEUP_EQUIP_FAIL; Msg.SetResult(nResult); pGamePlayer->SendPacket( &Msg ) ; g_pLog->FastSaveLog( LOG_FILE_1, "Obj_Human::EquipLevelup GUID is different ") ; return PACKET_EXE_CONTINUE; } } break; default: { g_pLog->FastSaveLog( LOG_FILE_1, "CGEquipLevelupHandler: EquipFromType error, EquipFromType=%d", pPacket->GetEquipPosType()) ; return PACKET_EXE_ERROR; } break; } INT nCurLevel = pEquipItem->GetCurLevel(); if(nCurLevel >=MAX_EQUIP_LEVELUP_NUM) { g_pLog->FastSaveLog( LOG_FILE_1, "CGEquipLevelupHandler LEVEL full ") ; nResult = EQUIPLEVEUP_FULL_FAIL; Msg.SetResult(nResult); pGamePlayer->SendPacket( &Msg ) ; return PACKET_EXE_CONTINUE; } nResult = (EQUIPLEVEUP_RESULT)pHuman->EquipLevelup(pEquipItem, pPacket->getGemID(), pPacket->GetGemNum()); if(nResult == EQUIPLEVEUP_FAIL) { g_pLog->FastSaveLog( LOG_FILE_1, "CGEquipLevelupHandler: pHuman->AddHole Fail") ; return PACKET_EXE_ERROR; } Msg.SetResult(nResult); pGamePlayer->SendPacket( &Msg ) ; ////////////////////////////////////////////////////////////////////////// if((nResult == EQUIPLEVEUP_SUCCESS)||(nResult == EQUIPLEVEUP_FAIL_SUCCESS)) { if(pPacket->GetEquipPosType() == ENUM_EQUIP_POINT) { pHuman->ItemEffectFlush(); pHuman->SetEquipVer(pHuman->GetEquipVer()+1); INT Equip_Point = pPacket->GetPos(); UINT RetPart = 0; GCDetailEquipList SelfMsg; SelfMsg.setObjID( pHuman->GetID() ); Item* pEquipItem = HumanItemLogic::GetEquip(pHuman, (HUMAN_EQUIP)Equip_Point); if(!pEquipItem) { Assert(FALSE); } if(pEquipItem->IsEmpty()) { Assert(FALSE); } pEquipItem->SaveValueTo(SelfMsg.GetEquipData((HUMAN_EQUIP)Equip_Point)); RetPart|=(1<<((UINT)Equip_Point)); SelfMsg.SetAskPart(RetPart); pGamePlayer->SendPacket( &SelfMsg ) ; } else { GCItemInfo EquipMsg; EquipMsg.setIsNull(FALSE); EquipMsg.setID(BagIndex); pEquipItem->SaveValueTo(EquipMsg.getItem()); pHuman->GetPlayer()->SendPacket(&EquipMsg); } } g_pLog->FastSaveLog( LOG_FILE_1, "CGEquipLevelupHandler: success nResult=%d", nResult ) ; return PACKET_EXE_CONTINUE; __LEAVE_FUNCTION return PACKET_EXE_ERROR; }
uint CGEquipSuitExchangeHandler::Execute(CGEquipSuitExchange* 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(pGamePlayer->GetPlayerStatus()!=PS_SERVER_NORMAL || !pHuman->IsActiveObj() ) { g_pLog->FastSaveLog( LOG_FILE_1, "CGEquipSuitExchangeHandler: change scene") ; 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 ; } UINT nSuitNum = pPacket->getEquipSuitNum(); if( nSuitNum > MAX_EQUIP_SUIT_NUM ) { return PACKET_EXE_ERROR ; } ItemContainer* pEquipContainer = pHuman->GetEquipContain(); Assert(pEquipContainer); _SUIT_SETTING suitSetting = pHuman->GetEquipSuitSetting(nSuitNum); GCEquipSuitExchangeResult Msg; GCDetailEquipList SelfMsg; GCCharEquipment OtherMsg; SelfMsg.setObjID( pHuman->GetID() ); BOOL bChange = FALSE; UINT RetPart = 0; //遍历所有套装 for(INT i=0; i<HEQUIP_NUMBER; ++i) { //存在套装数据 if(!suitSetting.m_EquipData[i].isNull()) { //检查装备栏 Item* pEquip = pEquipContainer->GetItem(i); Assert(pEquip); //装备有变化,装备栏数据与保存的对应位置套装信息不一致,需要到背包里找 if(!(pEquip->GetGUID() == suitSetting.m_EquipData[i])) { INT nPos = INVALID_INDEX; ItemContainer* pBagContainer = HumanItemLogic::GetBagItemContain(pHuman, &suitSetting.m_EquipData[i], nPos); //背包里也找不到,需记录下来(卖掉了?丢掉了?。。) if(nPos == INVALID_INDEX) { EXCHANGE_EQUIP_INFO ExchangeInfo; ExchangeInfo.m_BagIndex = INVALID_ITEM_POS; ExchangeInfo.m_EquipPoint = INVALID_ITEM_POS; Msg.setEquipInfo(ExchangeInfo, i); continue; } //找到了 Item* pExchangeItem = HumanItemLogic::GetBagItem(pHuman, nPos); Assert(pExchangeItem->GetItemClass() == ICLASS_EQUIP); if(pExchangeItem->GetEquipPoint() != i) { if(pExchangeItem->GetEquipPoint() == HEQUIP_RING1) { Assert(i == HEQUIP_RING2); } else if(pExchangeItem->GetEquipPoint() == HEQUIP_ADORN1) { Assert(i == HEQUIP_ADORN2); } else Assert(0); } //玩家可能等级变了 if(pExchangeItem->GetRequireLevel() > pHuman->GetLevel() ) { EXCHANGE_EQUIP_INFO ExchangeInfo; ExchangeInfo.m_BagIndex = INVALID_ITEM_POS; ExchangeInfo.m_EquipPoint = i; Msg.setEquipInfo(ExchangeInfo, i); g_pLog->FastSaveLog( LOG_FILE_1, "CGEquipSuitExchangeHandler: Equiplevel , pEquip->GetRequireLevel()=%d", pEquip->GetRequireLevel() ) ; continue; } //可能换职业了 if(!pExchangeItem->IsWuMenPai()) { if(!pExchangeItem->InReqJob(pHuman->GetMenPai())) { EXCHANGE_EQUIP_INFO ExchangeInfo; ExchangeInfo.m_BagIndex = INVALID_ITEM_POS; ExchangeInfo.m_EquipPoint = i; Msg.setEquipInfo(ExchangeInfo, i); g_pLog->FastSaveLog( LOG_FILE_1, "CGEquipSuitExchangeHandler: ReqJob") ; continue; } } if (pEquip->IsEmpty()) { g_ItemOperator.MoveItem( pBagContainer, pBagContainer->BagIndex2ConIndex(nPos), pEquipContainer, i ) ; } else { if (pBagContainer->IsCanUse()) { //与装备的物品进行交换 g_ItemOperator.ExchangeItem(pBagContainer, pBagContainer->BagIndex2ConIndex(nPos), pEquipContainer, i); } else //背包已经过期 { EXCHANGE_EQUIP_INFO ExchangeInfo; ExchangeInfo.m_BagIndex = INVALID_ITEM_POS; ExchangeInfo.m_EquipPoint = INVALID_ITEM_POS; Msg.setEquipInfo(ExchangeInfo, i); continue; } } EXCHANGE_EQUIP_INFO ExchangeInfo; ExchangeInfo.m_BagIndex = nPos; ExchangeInfo.m_EquipPoint = i; Msg.setEquipInfo(ExchangeInfo, i); //交换到人身上了,重新获取一下 Item* pEquipItem = HumanItemLogic::GetEquip(pHuman, (HUMAN_EQUIP)i); if(!pEquipItem) { Assert(FALSE); return PACKET_EXE_CONTINUE; } Assert(!pEquipItem->IsEmpty()); pEquipItem->SaveValueTo(SelfMsg.GetEquipData((HUMAN_EQUIP)i)); RetPart|=(1<<((UINT)i)); SelfMsg.SetAskPart(RetPart); RetPart = 0; //如果可见 if(pHuman->IsVisualPart((HUMAN_EQUIP)i)) { OtherMsg.setObjID(pHuman->GetID()); OtherMsg.setID((HUMAN_EQUIP)i, pEquipItem->GetItemTableIndex()); } //换装了 bChange = TRUE; } //装备正穿着呢,不需要通知 continue; } else { //根本没有呀 EXCHANGE_EQUIP_INFO ExchangeInfo; ExchangeInfo.m_BagIndex = INVALID_ITEM_POS; ExchangeInfo.m_EquipPoint = i; Msg.setEquipInfo(ExchangeInfo, i); } } if(bChange) { Msg.setResult(EQUIPSUIT_SUCCESS); pGamePlayer->SendPacket(&Msg); pGamePlayer->SendPacket( &SelfMsg ) ; pScene->BroadCast(&OtherMsg,pHuman,TRUE); pHuman->SetEquipVer(pHuman->GetEquipVer()+1); //刷新装备对人物的属性影响 pHuman->ItemEffectFlush(); } else { Msg.setResult(EQUIPSUIT_SUCCESS); pGamePlayer->SendPacket(&Msg); } g_pLog->FastSaveLog( LOG_FILE_1, "CGEquipSuitExchangeHandler: nSuitNum=%d", nSuitNum ) ; return PACKET_EXE_CONTINUE ; __LEAVE_FUNCTION return PACKET_EXE_ERROR ; }
UINT CGSouXiaRefiningHandler::Execute( CGSouXiaRefining* 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 iRefiningSouXiaItem = pPacket->GetRefiningSouXiaIndex(); Assert(iRefiningSouXiaItem >= 0 ); Assert(iRefiningSouXiaItem <= MAX_BAG_SIZE); BYTE iRefiningSouXiaItem2 = pPacket->GetRefiningSouXia2Index(); Assert(iRefiningSouXiaItem2 >= 0 ); Assert(iRefiningSouXiaItem2 <= MAX_BAG_SIZE); BYTE iRefiningItem = pPacket->GetRefiningItemIndex(); Assert(iRefiningItem >= 0 ); Assert(iRefiningItem <= MAX_BAG_SIZE); GCSouXiaRefining refiningMsg; // 背包索引获取搜侠道具信息并验证 ItemContainer* pBagContainer = HumanItemLogic::GetBagContainer(pHuman, iRefiningSouXiaItem); if (pBagContainer == NULL) { g_pLog->FastSaveLog( LOG_FILE_1, "CGSouXiaRefining souxia BagIndex is invalid, BagIndex = %d", iRefiningSouXiaItem) ; return PACKET_EXE_ERROR; } Item* pRefiningSouXiaItem = pBagContainer->GetItem(pBagContainer->BagIndex2ConIndex(iRefiningSouXiaItem)); if(pRefiningSouXiaItem->GetItemClass() != ICLASS_EQUIP || EQUIP_SOUXIA != pRefiningSouXiaItem->GetItemType()) { g_pLog->FastSaveLog( LOG_FILE_1, "CGSouXiaRefining souxia type is invalid, BagIndex = %d", iRefiningSouXiaItem) ; refiningMsg.SetResult(GET_ITEM_ERROR); pGamePlayer->SendPacket(&refiningMsg); return PACKET_EXE_ERROR; } // 背包索引获取第二本搜侠录道具信息 pBagContainer = HumanItemLogic::GetBagContainer(pHuman, iRefiningSouXiaItem2); if (pBagContainer == NULL) { g_pLog->FastSaveLog( LOG_FILE_1, "CGSouXiaRefining souxia BagIndex is invalid, BagIndex = %d", iRefiningSouXiaItem2) ; return PACKET_EXE_ERROR; } Item* pRefiningSouXiaItem2 = pBagContainer->GetItem(pBagContainer->BagIndex2ConIndex(iRefiningSouXiaItem2)); if(pRefiningSouXiaItem2->GetItemClass() != ICLASS_EQUIP || EQUIP_SOUXIA != pRefiningSouXiaItem2->GetItemType()) { g_pLog->FastSaveLog( LOG_FILE_1, "CGSouXiaRefining souxia type is invalid, BagIndex = %d", iRefiningSouXiaItem2) ; refiningMsg.SetResult(GET_ITEM_ERROR); pGamePlayer->SendPacket(&refiningMsg); return PACKET_EXE_ERROR; } // 背包索引获取炼化道具信息 pBagContainer = HumanItemLogic::GetBagContainer(pHuman, iRefiningItem); if (pBagContainer == NULL) { g_pLog->FastSaveLog( LOG_FILE_1, "CGSouXiaRefining refiningItem BagIndex is invalid, BagIndex = %d", iRefiningItem) ; return PACKET_EXE_ERROR; } Item* pRefiningItem = pBagContainer->GetItem(pBagContainer->BagIndex2ConIndex(iRefiningItem)); if(pRefiningItem->GetItemClass() != ICLASS_COMITEM || COMITEM_SOUXIA != pRefiningItem->GetItemType()) { g_pLog->FastSaveLog( LOG_FILE_1, "CGSouXiaRefining refiningItem type is invalid, BagIndex = %d", iRefiningSouXiaItem2) ; refiningMsg.SetResult(GET_ITEM_ERROR); pGamePlayer->SendPacket(&refiningMsg); return PACKET_EXE_ERROR; } SOUXIA_INFO_TB* pGet = g_ItemTable.GetSouXiaTB(pRefiningItem->GetItemTableIndex()); if (NULL != pGet && ITEM_REFINING == pGet->m_nUseType) { if(pGet->m_nNeedLevel > pHuman->GetLevel()) // 使用道具没有达到限制等级 { refiningMsg.SetResult(HUMAN_LEVEL_NOT_ENOUGH); Player* pPlayer = pHuman->GetPlayer(); if( pPlayer != NULL ) { pPlayer->SendPacket( &refiningMsg ); } return PACKET_EXE_CONTINUE; } } // 炼化逻辑 ItemParamValue ipv = (ItemParamValue)IPV_INT; INT iParamSouXiaID = pRefiningSouXiaItem->GetItemParam(0,ipv); INT iParamSouXiaPos = pRefiningSouXiaItem->GetItemParam(4,ipv); INT iParamSouXiaID2 = pRefiningSouXiaItem2->GetItemParam(0,ipv); INT iParamSouXiaPos2 = pRefiningSouXiaItem2->GetItemParam(4,ipv); //两本捜侠录都为空 if ( (iParamSouXiaID == 0 && iParamSouXiaPos <= 0 ) && (iParamSouXiaID2 == 0 && iParamSouXiaPos2 <= 0 )) { refiningMsg.SetResult(SOUXIA_EMPTY); Player* pPlayer = pHuman->GetPlayer(); if( pPlayer != NULL ) { pPlayer->SendPacket( &refiningMsg ); } return PACKET_EXE_CONTINUE; } BOOL bRefiningResult = FALSE; BYTE refiningType = 0; BYTE refiningRule = 0; SHORT refiningRate = -1; BYTE randNum = pScene->GetRand100(); SOUXIA_DATA randSouXiaData;//炼化随机后取得的新数据 if (pGet->m_nRefiningRule[0][0] > 0)//炼化技能道具 { refiningRule = pGet->m_nRefiningRule[0][0]; refiningRate = pGet->m_nRefiningRule[0][1]; if (randNum < refiningRate) { bRefiningResult = SouXiaLogic::RefiningSouXia(pHuman, pRefiningSouXiaItem, pRefiningSouXiaItem2, refiningRule, randSouXiaData, ITEM_SOUXIASKILL); refiningType = ITEM_SOUXIASKILL; } } else if (pGet->m_nRefiningRule[1][0] > 0)//炼化配方道具 { refiningRule = pGet->m_nRefiningRule[1][0]; refiningRate = pGet->m_nRefiningRule[1][1]; if (randNum < refiningRate) { bRefiningResult = SouXiaLogic::RefiningSouXia(pHuman, pRefiningSouXiaItem, pRefiningSouXiaItem2, refiningRule, randSouXiaData, ITEM_PRODUCT); refiningType = ITEM_PRODUCT; } } else if (pGet->m_nRefiningRule[2][0] > 0)//炼化神兽召唤道具 { refiningRule = pGet->m_nRefiningRule[2][0]; refiningRate = pGet->m_nRefiningRule[2][1]; if (randNum < refiningRate) { bRefiningResult = SouXiaLogic::RefiningSouXia(pHuman, pRefiningSouXiaItem, pRefiningSouXiaItem2, refiningRule, randSouXiaData, ITEM_PET_ZHAOHUAN); refiningType = ITEM_PET_ZHAOHUAN; } } else if (pGet->m_nRefiningRule[3][0] > 0)//炼化坐骑召唤道具 { refiningRule = pGet->m_nRefiningRule[3][0]; refiningRate = pGet->m_nRefiningRule[3][1]; if (randNum < refiningRate) { bRefiningResult = SouXiaLogic::RefiningSouXia(pHuman, pRefiningSouXiaItem, pRefiningSouXiaItem2, refiningRule, randSouXiaData, ITEM_ZUOJI_ZHAOHUAN); refiningType = ITEM_ZUOJI_ZHAOHUAN; } } if (!bRefiningResult) { refiningMsg.SetResult(SOUXIA_SKILL_REFINING_FAIL); Player* pPlayer = pHuman->GetPlayer(); if( pPlayer != NULL ) { pPlayer->SendPacket( &refiningMsg ); } return PACKET_EXE_CONTINUE; } // 手续费用的扣除 // 成功删除使用的道具和捜侠录 if (randNum <= refiningRate) { UINT newSouXiaIndex = 0; BYTE newSouXiaCurPos = 0; // 取玩家身上捜侠录的数据pos 和 skillId if (iParamSouXiaID == 0 && iParamSouXiaPos <= 0)//第一本为空 { newSouXiaIndex = iParamSouXiaID2; newSouXiaCurPos = iParamSouXiaPos2; } if (iParamSouXiaID2 == 0 && iParamSouXiaPos2 <= 0)//第二本为空 { newSouXiaIndex = iParamSouXiaID; newSouXiaCurPos = iParamSouXiaPos; } // 第一本的最大页数 BYTE maxPage = 0, maxPage2 = 0; pGet = g_ItemTable.GetSouXiaTB(pRefiningSouXiaItem->GetItemTableIndex()); Assert(pGet); maxPage = pGet->m_nMaxPages[0]; // 第二本最大页数 pGet = g_ItemTable.GetSouXiaTB(pRefiningSouXiaItem2->GetItemTableIndex()); Assert(pGet); maxPage2 = pGet->m_nMaxPages[0]; ITEM_LOG_PARAM ItemLogParam; ItemLogParam.OpType = ITEM_REFINING_SOUXIA; UINT newSouXiaBagIndex = 0;//新的捜侠录item背包索引 if (maxPage >= maxPage2) // 第一本的最大页大于第二本则保留第一本 { BOOL bRet = HumanItemLogic::EraseBagItem(&ItemLogParam,pHuman, pBagContainer->BagIndex2ConIndex(iRefiningSouXiaItem2)); if(bRet) { SaveItemLog(&ItemLogParam); } else { refiningMsg.SetResult(ERASE_ITEM_FAIL); pGamePlayer->SendPacket(&refiningMsg); return PACKET_EXE_CONTINUE; } if (iParamSouXiaPos2 >= 0) { pHuman->EraseSouXia(iParamSouXiaPos2);//人身上销毁第二本 } newSouXiaBagIndex = iRefiningSouXiaItem;//保留第一本的数据的bagindex if ( (iParamSouXiaID > 0 && iParamSouXiaPos >= 0) && (iParamSouXiaID2 > 0 && iParamSouXiaPos2 >= 0)) { newSouXiaIndex = iParamSouXiaID; newSouXiaCurPos = iParamSouXiaPos; } } else // 销毁第一本 { BOOL bRet = HumanItemLogic::EraseBagItem(&ItemLogParam,pHuman, pBagContainer->BagIndex2ConIndex(iRefiningSouXiaItem)); if(bRet) { SaveItemLog(&ItemLogParam); } else { refiningMsg.SetResult(ERASE_ITEM_FAIL); pGamePlayer->SendPacket(&refiningMsg); return PACKET_EXE_CONTINUE; } if (iParamSouXiaPos >= 0) { pHuman->EraseSouXia(iParamSouXiaPos);//人身上销毁第一本 } newSouXiaBagIndex = iRefiningSouXiaItem2;//保留第二本的数据的bagindex if ( (iParamSouXiaID > 0 && iParamSouXiaPos >= 0) && (iParamSouXiaID2 > 0 && iParamSouXiaPos2 >= 0)) { newSouXiaIndex = iParamSouXiaID2; newSouXiaCurPos = iParamSouXiaPos2; } } Assert (newSouXiaIndex > 0 && newSouXiaCurPos >= 0); randSouXiaData.m_CurPos = newSouXiaCurPos; randSouXiaData.m_SouXiaID = newSouXiaIndex; // 销毁炼化道具 BOOL bRet = HumanItemLogic::EraseBagItem(&ItemLogParam,pHuman, pBagContainer->BagIndex2ConIndex(iRefiningItem)); if(bRet) { SaveItemLog(&ItemLogParam); } else { refiningMsg.SetResult(ERASE_ITEM_FAIL); pGamePlayer->SendPacket(&refiningMsg); return PACKET_EXE_CONTINUE; } // 改变保留的捜侠录道具的信息 Item* pNewSouXiaItem = HumanItemLogic::GetBagItem(pHuman, pBagContainer->BagIndex2ConIndex(newSouXiaBagIndex)); Assert(pNewSouXiaItem); bRet = g_ItemOperator.SetItemParam( pHuman->GetBaseContain(),pHuman->GetBaseContain()->BagIndex2ConIndex(newSouXiaBagIndex),0, ipv, newSouXiaIndex); if (!bRet) { return PACKET_EXE_CONTINUE; } bRet = g_ItemOperator.SetItemParam( pHuman->GetBaseContain(),pHuman->GetBaseContain()->BagIndex2ConIndex(newSouXiaBagIndex), 4, ipv, newSouXiaCurPos); if (!bRet) { return PACKET_EXE_CONTINUE; } /*bRet = g_ItemOperator.SetItemParam( pHuman->GetBaseContain(),pHuman->GetBaseContain()->BagIndex2ConIndex(newSouXiaBagIndex),8, ipv, refiningType); if (!bRet) { return PACKET_EXE_CONTINUE; }*/ // 以上设置ITEM param注意保存到文件,并且要通知ITEM 的param 改变 GCItemInfo Msg; Msg.setID( newSouXiaBagIndex ); Msg.setIsNull(FALSE); pNewSouXiaItem->SaveValueTo(Msg.getItem()); pHuman->GetPlayer()->SendPacket(&Msg); pHuman->SetSouXia(randSouXiaData, newSouXiaCurPos); // 保存到文件 _SOUXIA_DB_LOAD SouXia_db_Load; SouXia_db_Load.m_SouXiaData[newSouXiaCurPos] = randSouXiaData; pHuman->GetDB()->SetSouXiaDBInfo(&SouXia_db_Load, newSouXiaCurPos); // 发送新的捜侠录消息 refiningMsg.SetNewItemBagIndex(newSouXiaBagIndex); refiningMsg.SetSouXiaData(&randSouXiaData);//炼化以后的捜侠录数据 refiningMsg.SetCurRefiningType(refiningType); refiningMsg.SetResult(SOUXIA_REFINING_SUCCESS); Player* pPlayer = pHuman->GetPlayer(); if( pPlayer != NULL ) { pPlayer->SendPacket( &refiningMsg ); } } return PACKET_EXE_CONTINUE; __LEAVE_FUNCTION return PACKET_EXE_ERROR; }
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; _ITEM_ATTR tmpItemAttr[MAX_ITEM_ATTR]; for (BYTE index=0; index<pEquipment->GetAttrCount(); ++index) { tmpItemAttr[index] = pEquipment->GetEquipAttr(index); if (tmpItemAttr[index].m_AttrType > 0) { attrCount++; } } Assert(attrCount == pEquipment->GetAttrCount()); //开始删除装备和扣除金钱 BOOL bRet = FALSE; ITEM_LOG_PARAM ItemLogParam; ItemLogParam.OpType = ITEM_EQUIP_REFINING; bRet = HumanItemLogic::EraseBagItem(&ItemLogParam,pHuman, pBagContainer->BagIndex2ConIndex(iEquipItemPos)); if(bRet) { SaveItemLog(&ItemLogParam); } else { msg.SetResult(EQUIPREFINING_ERASE_ITEM_FAIL); pGamePlayer->SendPacket(&msg); return PACKET_EXE_CONTINUE; } //删除炼化道具 bRet = HumanItemLogic::EraseBagItem(&ItemLogParam,pHuman, pBagContainer->BagIndex2ConIndex(iRefiningItemPos)); if(bRet) { SaveItemLog(&ItemLogParam); } else { msg.SetResult(EQUIPREFINING_ERASE_ITEM_FAIL); pGamePlayer->SendPacket(&msg); return PACKET_EXE_CONTINUE; } UINT iSoulBeadBagIndex = 0; Item* pSoulBeadItem = NULL; //武魂珠 if (HEQUIP_MAINHAND == curEquipPoint) { bRet = HumanItemLogic::CreateItemToBag(&ItemLogParam,pHuman,ITEM_WU_SOUL_BEAD, iSoulBeadBagIndex); if(bRet) { SaveItemLog(&ItemLogParam); } else { msg.SetResult(EQUIPREFINING_ERASE_ITEM_FAIL); pGamePlayer->SendPacket(&msg); return PACKET_EXE_CONTINUE; } pSoulBeadItem = pBagContainer->GetItem(pBagContainer->BagIndex2ConIndex(iSoulBeadBagIndex)); Assert(NULL != pSoulBeadItem); Assert(ICLASS_SOUL_BEAD == pSoulBeadItem->GetItemClass()); pSoulBeadItem->SetSoulBeadPrice(iPrice);//由基本价格计算得出 pSoulBeadItem->SetSoulBeadNeedLevel(iRequireLevel); pSoulBeadItem->SetWuSoulBeadAttr(attrCount, tmpItemAttr); }//器魂珠 else if (EQUIP_CAP == pEquipment->GetItemType()//EQUIP_PIFENG == pEquipment->GetEquipPoint() || || EQUIP_SHOULDER == pEquipment->GetItemType() || EQUIP_HAND == pEquipment->GetItemType() || EQUIP_ARMOR == pEquipment->GetItemType() || EQUIP_BOOT == pEquipment->GetItemType()) { bRet = HumanItemLogic::CreateItemToBag(&ItemLogParam,pHuman,ITEM_WU_SOUL_BEAD, iSoulBeadBagIndex); if(bRet) { SaveItemLog(&ItemLogParam); } else { msg.SetResult(EQUIPREFINING_ERASE_ITEM_FAIL); pGamePlayer->SendPacket(&msg); return PACKET_EXE_CONTINUE; } pSoulBeadItem = pBagContainer->GetItem(pBagContainer->BagIndex2ConIndex(iSoulBeadBagIndex)); Assert(NULL != pSoulBeadItem); Assert(ICLASS_SOUL_BEAD == pSoulBeadItem->GetItemClass()); pSoulBeadItem->SetSoulBeadPrice(iPrice);//由基本价格计算得出 pSoulBeadItem->SetSoulBeadNeedLevel(iRequireLevel); pSoulBeadItem->SetQiSoulBeadAttr(attrCount, tmpItemAttr); } // 通知增加道具到背包 GCNotifyEquip ItemMsg; Assert(pSoulBeadItem); ItemMsg.SetBagIndex(iSoulBeadBagIndex); pSoulBeadItem->SaveValueTo(ItemMsg.GetItem()); pGamePlayer->SendPacket(&ItemMsg); msg.SetResult(EQUIPREFINING_SUCCESS); //pGamePlayer->SendPacket(&msg); return PACKET_EXE_CONTINUE; __LEAVE_FUNCTION return PACKET_EXE_ERROR; }
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, pBagContainer->BagIndex2ConIndex(BagIndex), pEquipContainer, (UINT)Equip_Point); } Item* pEquip = pEquipContainer->GetItem((UINT)Equip_Point); if(pEquip&&pEquip->IsCanEquipBind()) { g_ItemOperator.SetItemBind(pEquipContainer,(UINT)Equip_Point); } Msg.setBagIndex(BagIndex); Msg.setEquipPoint(Equip_Point); Msg.setEquipID(pEquipItem->GetGUID()); Msg.setEquipResID(pEquipItem->GetItemTableIndex()); Msg.setItemResID(pUseItem->GetItemTableIndex()); Msg.setBagItemId(pUseItem->GetGUID()); Msg.setResult(USEEQUIP_SUCCESS); pGamePlayer->SendPacket( &Msg ) ; pHuman->SetEquipVer(pHuman->GetEquipVer()+1); //刷新装备对人物的属性影响 pHuman->ItemEffectFlush(); //如果可见 if(pHuman->IsVisualPart(Equip_Point)) { GCCharEquipment OtherMsg; OtherMsg.setObjID(pHuman->GetID()); if(Equip_Point == HEQUIP_WEAPON) { UINT uGemID = GetEquipmentMaxLevelGemID(pEquip); OtherMsg.setID(Equip_Point,pEquip->GetItemTableIndex(), uGemID); } else { OtherMsg.setID(Equip_Point,pEquip->GetItemTableIndex(), -1); } pScene->BroadCast(&OtherMsg,pHuman,TRUE); } WORD RetPart = 0; GCDetailEquipList SelfMsg; SelfMsg.setObjID( pHuman->GetID() ); pEquipItem = HumanItemLogic::GetEquip(pHuman,Equip_Point); if(!pEquipItem) { Assert(FALSE); return PACKET_EXE_CONTINUE; } if(pEquipItem->IsEmpty()) { g_pLog->FastSaveLog( LOG_FILE_1, "CGUseEquipmentHandler: Equip_Point =%d Fail", Equip_Point ) ; return PACKET_EXE_CONTINUE; } pEquipItem->SaveValueTo(SelfMsg.GetEquipData(Equip_Point)); RetPart|=(1<<((INT)Equip_Point)); SelfMsg.SetAskPart(RetPart); pGamePlayer->SendPacket( &SelfMsg ) ; } } else { Msg.setResult(USEEQUIP_TYPE_FAIL); Msg.setBagIndex(0); Msg.setEquipPoint(0); pGamePlayer->SendPacket( &Msg ) ; } g_pLog->FastSaveLog( LOG_FILE_1, "CGUseEquipmentHandler: BagIndex=%d", BagIndex ) ; return PACKET_EXE_CONTINUE ; __LEAVE_FUNCTION return PACKET_EXE_ERROR ; }
uint CGEquipRemouldHandler::Execute(CGEquipRemould* 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; EQUIPREMOULD_RESULT nResult = EQUIPREMOULD_FAIL; GCEquipRemouldResult Msg; switch(pPacket->GetEquipPosType()) { case ENUM_EQUIP_POINT: { EquipPoint = pPacket->GetPos(); if(EquipPoint>HEQUIP_ADORN2) { g_pLog->FastSaveLog( LOG_FILE_1, "CGEquipRemouldHandler: EquipPoint error, EquipPoint=%d", EquipPoint) ; return PACKET_EXE_ERROR; } ItemContainer* pEquipContainer = pHuman->GetEquipContain(); if(NULL==pEquipContainer) { AssertEx(FALSE,"[CGEquipRemouldHandler]: NULL EquipContainer pointer found!"); } pEquipItem = pEquipContainer->GetItem((UINT)EquipPoint); Assert(pEquipItem); if(pEquipItem->IsEmpty()) { nResult = EQUIPREMOULD_EQUIP_FAIL; Msg.SetResult(nResult); pGamePlayer->SendPacket( &Msg ) ; g_pLog->FastSaveLog( LOG_FILE_1, "CGEquipRemouldHandler pEquipItem is Null at EquipPoint= %d", EquipPoint) ; return PACKET_EXE_CONTINUE; } Assert (pEquipItem->GetItemClass() == ICLASS_EQUIP); if(!(pPacket->getItemID() == pEquipItem->GetGUID())) { nResult = EQUIPREMOULD_EQUIP_FAIL; Msg.SetResult(nResult); pGamePlayer->SendPacket( &Msg ) ; g_pLog->FastSaveLog( LOG_FILE_1, "CGEquipRemouldHandler 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, "CGEquipRemouldHandler: BagIndex error, BagIndex=%d", BagIndex) ; return PACKET_EXE_ERROR; } if (!pItemContainer->IsCanUse()) { nResult = EQUIPREMOULD_BAG_INVALID; Msg.SetResult(nResult); pGamePlayer->SendPacket( &Msg ) ; g_pLog->FastSaveLog( LOG_FILE_1, "CGEquipRemouldHandler: ItemContainer is invalid, ContainerType=%d, BagIndex=%d", pItemContainer->GetContainerType(), BagIndex) ; return PACKET_EXE_ERROR; } pEquipItem = pItemContainer->GetItem(pItemContainer->BagIndex2ConIndex(BagIndex)); if(pEquipItem->IsEmpty()) { nResult = EQUIPREMOULD_EQUIP_FAIL; Msg.SetResult(nResult); pGamePlayer->SendPacket( &Msg ) ; g_pLog->FastSaveLog( LOG_FILE_1, "CGEquipRemouldHandler pEquipItem is Null at BagIndex= %d", BagIndex) ; return PACKET_EXE_CONTINUE; } if (pEquipItem->GetItemClass() != ICLASS_EQUIP) { nResult = EQUIPREMOULD_EQUIP_FAIL; Msg.SetResult(nResult); pGamePlayer->SendPacket( &Msg ) ; g_pLog->FastSaveLog( LOG_FILE_1, "CGEquipRemouldHandler GetItemClass is not ICLASS_EQUIP ") ; return PACKET_EXE_CONTINUE; } if(!(pPacket->getItemID() == pEquipItem->GetGUID())) { nResult = EQUIPREMOULD_EQUIP_FAIL; Msg.SetResult(nResult); pGamePlayer->SendPacket( &Msg ) ; g_pLog->FastSaveLog( LOG_FILE_1, "CGEquipRemouldHandler GUID is different ") ; return PACKET_EXE_CONTINUE; } if (pEquipItem->GetItemType() > EQUIP_ADORN) { nResult = EQUIPREMOULD_EQUIP_FAIL; Msg.SetResult(nResult); pGamePlayer->SendPacket( &Msg ) ; g_pLog->FastSaveLog( LOG_FILE_1, "CGEquipRemouldHandler GUID is different ") ; return PACKET_EXE_CONTINUE; } } break; default: { g_pLog->FastSaveLog( LOG_FILE_1, "CGEquipRemouldHandler: EquipFromType error, EquipFromType=%d", pPacket->GetEquipPosType()) ; return PACKET_EXE_ERROR; } break; } if (pEquipItem->GetEquipFromType() != ITEM_CREATE) { nResult = EQUIPREMOULD_TYPE_FAIL; Msg.SetResult(nResult); pGamePlayer->SendPacket( &Msg ) ; g_pLog->FastSaveLog( LOG_FILE_1, "CGEquipRemouldHandler Type error ") ; return PACKET_EXE_CONTINUE; } ITEM_PRODUCT_INFO_TB* pCreateTB = g_ItemTable.GetItemProductInfoTB(pEquipItem->GetItemTableIndex()); if(pCreateTB == NULL) { nResult = EQUIPREMOULD_EQUIP_FAIL; Msg.SetResult(nResult); pGamePlayer->SendPacket(&Msg); return PACKET_EXE_CONTINUE; } if (pCreateTB->m_nRemouldInfoCount != pPacket->GetValidNum()) { return PACKET_EXE_ERROR; } if (pCreateTB->m_RemouldMoney > pHuman->GetMoney()) { nResult = EQUIPREMOULD_MONEY_FAIL; Msg.SetResult(nResult); pGamePlayer->SendPacket(&Msg); return PACKET_EXE_CONTINUE; } struct MATERIAL_REQ { UINT m_nIndex; UINT m_nCount; }; MATERIAL_REQ MaterialIndex[MAX_REMOULD_MATERIAL_NUM]; UINT nEquipScore = 0; for (UINT i=0; i<pCreateTB->m_nRemouldInfoCount; ++i) { REMOULDITEM_INFO RemouldInfo = pCreateTB->m_RemouldInfo[i]; EQUIPREMOULD_MATERIAL_INFO MaterialInfo = pPacket->GetMaterialReq(i); if(MaterialInfo.m_nMaterialType != RemouldInfo.m_MaterialType) { nResult = EQUIPREMOULD_MATERIAL_FAIL; Msg.SetResult(nResult); pGamePlayer->SendPacket( &Msg ) ; g_pLog->FastSaveLog( LOG_FILE_1, "CGEquipRemouldHandler MaterialType error") ; return PACKET_EXE_CONTINUE; } if(MaterialInfo.m_nMaterialLevel < RemouldInfo.m_NeedLevel) { nResult = EQUIPREMOULD_MATERIAL_LEVEL; Msg.SetResult(nResult); pGamePlayer->SendPacket( &Msg ) ; g_pLog->FastSaveLog( LOG_FILE_1, "CGEquipRemouldHandler MaterialLevel fail") ; return PACKET_EXE_CONTINUE; } UINT nMaterialIndex = GenMaterialIndex(MaterialInfo.m_nMaterialType, MaterialInfo.m_nMaterialLevel); //查询物品表该材料是否存在 COMMITEM_INFO_TB* pMaterialInfoTB = g_ItemTable.GetCommItemInfoTB(nMaterialIndex); if(pMaterialInfoTB == NULL) { return PACKET_EXE_ERROR; } INT nCount = HumanItemLogic::CalcBagItemCount(pHuman, nMaterialIndex); if (nCount<RemouldInfo.m_MaterialNum) { nResult = EQUIPREMOULD_MATERIAL_COUNT; Msg.SetResult(nResult); pGamePlayer->SendPacket( &Msg ) ; g_pLog->FastSaveLog( LOG_FILE_1, "CGEquipRemouldHandler Material num fail") ; return PACKET_EXE_CONTINUE; } //获取对应材料分 MATERIAL_LEVEL_INFO_TB* pMaterialLevelInfo = g_ItemTable.GetMaterialInfoTB(MaterialInfo.m_nMaterialLevel); Assert(pMaterialLevelInfo != NULL); if (!pMaterialLevelInfo) { g_pLog->FastSaveLog( LOG_FILE_1, "[CGEquipRemouldHandler::Execute] GetMaterialInfoTB index is error [%d]",MaterialInfo.m_nMaterialLevel); return PACKET_EXE_ERROR; } nEquipScore = nEquipScore + pMaterialLevelInfo->m_MaterialValue; MaterialIndex[i].m_nIndex = nMaterialIndex; MaterialIndex[i].m_nCount = pCreateTB->m_RemouldInfo[i].m_MaterialNum; } nResult = (EQUIPREMOULD_RESULT)pHuman->EquipRemould(pEquipItem, nEquipScore); if(nResult == EQUIPREMOULD_FAIL) { g_pLog->FastSaveLog( LOG_FILE_1, "CGEquipRemouldHandler: pHuman->AddHole Fail") ; return PACKET_EXE_ERROR; } if (nResult == EQUIPREMOULD_SUCCESS) { ITEM_LOG_PARAM LogParam; LogParam.OpType = ITEM_REMOULD_CONSUME; LogParam.CharGUID = pHuman->GetGUID(); LogParam.XPos = pHuman->getWorldPos()->m_fX; LogParam.ZPos = pHuman->getWorldPos()->m_fZ; LogParam.SceneID = pHuman->getScene()->SceneID(); for (UINT i=0; i<pCreateTB->m_nRemouldInfoCount; ++i) { if(HumanItemLogic::EraseBagItem(&LogParam, pHuman,MaterialIndex[i].m_nIndex, MaterialIndex[i].m_nCount)) { SaveItemLog(&LogParam); } } pHuman->SetMoney(pHuman->GetMoney() - pCreateTB->m_RemouldMoney); MONEY_LOG_PARAM MoneyLogParam; MoneyLogParam.CharGUID = pHuman->GetGUID(); MoneyLogParam.OPType = MONEY_REMOULD_REDUCE; MoneyLogParam.Count = (INT)pCreateTB->m_RemouldMoney; MoneyLogParam.SceneID = pHuman->getScene()->SceneID(); MoneyLogParam.XPos = pHuman->getWorldPos()->m_fX; MoneyLogParam.ZPos = pHuman->getWorldPos()->m_fZ; SaveMoneyLog(&MoneyLogParam); } Msg.SetResult(nResult); pGamePlayer->SendPacket( &Msg ) ; ////////////////////////////////////////////////////////////////////////// if((nResult == EQUIPREMOULD_SUCCESS)||(nResult == EQUIPREMOULD_MAX_FAIL)) { if(pPacket->GetEquipPosType() == ENUM_EQUIP_POINT) { pHuman->ItemEffectFlush(); pHuman->SetEquipVer(pHuman->GetEquipVer()+1); INT Equip_Point = pPacket->GetPos(); UINT RetPart = 0; GCDetailEquipList SelfMsg; SelfMsg.setObjID( pHuman->GetID() ); Item* pEquipItem = HumanItemLogic::GetEquip(pHuman, (HUMAN_EQUIP)Equip_Point); if(!pEquipItem) { Assert(FALSE); } if(pEquipItem->IsEmpty()) { Assert(FALSE); } pEquipItem->SaveValueTo(SelfMsg.GetEquipData((HUMAN_EQUIP)Equip_Point)); RetPart|=(1<<((UINT)Equip_Point)); SelfMsg.SetAskPart(RetPart); pGamePlayer->SendPacket( &SelfMsg ) ; } else { GCItemInfo ItemMsg; ItemMsg.setIsNull(FALSE); ItemMsg.setID(BagIndex); pEquipItem->SaveValueTo(ItemMsg.getItem()); pHuman->GetPlayer()->SendPacket(&ItemMsg); } } g_pLog->FastSaveLog( LOG_FILE_1, "CGEquipRemouldHandler: success nResult=%d", nResult ) ; return PACKET_EXE_CONTINUE; __LEAVE_FUNCTION return PACKET_EXE_ERROR; }
uint CGShopSpecialRepairHandler::Execute( CGShopSpecialRepair* 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 ; } BYTE Opt = pPacket->GetOpt(); BYTE BagIndex = pPacket->GetBagIndex(); //包中的位置 Item* pCurItem = NULL; INT MoneySpent = 0; INT MoneyLast = 0; INT MoneyHave = pHuman->GetMoney(); INT RepairedIndex = 0; GCShopSpecialRepairResult MsgResult; GCShopSpecialRepairResult::REPAIRED_ITEM ItemList; if(Opt == CGShopSpecialRepair::FromBag) { //一定是修理单个 ItemContainer* pItemContainer = HumanItemLogic::GetBagContainer(pHuman, BagIndex); if (pItemContainer == NULL) { g_pLog->FastSaveLog( LOG_FILE_1, "CGShopSpecialRepairHandler BagIndex is invalid, BagIndex = %d", BagIndex) ; return PACKET_EXE_ERROR; } if (!pItemContainer->IsCanUse()) { g_pLog->FastSaveLog( LOG_FILE_1, "CGShopSpecialRepairHandler extrabag is invalid time BagIndex = %d", BagIndex) ; return PACKET_EXE_CONTINUE ; } pCurItem = pItemContainer->GetItem(pItemContainer->BagIndex2ConIndex(BagIndex)); if(!pCurItem->IsEmpty()) { if(pCurItem->GetItemClass() != ICLASS_EQUIP) { g_pLog->FastSaveLog( LOG_FILE_1, "CGShopSpecialRepairHandler pCurItem->GetItemClass() != ICLASS_EQUIP ") ; return PACKET_EXE_ERROR ; } EQUIP_SPECIALREPAIR_TB* pSpecialRepair = g_ItemTable.GetSpecialRepairTB(); Assert (pSpecialRepair != NULL); if (!pSpecialRepair) { g_pLog->FastSaveLog( LOG_FILE_1, "[CGShopSpecialRepairHandler::Execute] GetSpecialRepairTB index is error"); return PACKET_EXE_ERROR; } //获得Human背包中对应ItemIndex的物品位置 UINT nItemCount = HumanItemLogic::CalcBagItemCount(pHuman, pSpecialRepair->m_ItemID); if((nItemCount == 0)||(nItemCount < pPacket->GetItemNum())) { MsgResult.SetResult(EQUIPSPECIALREPAIR_ITEM); pGamePlayer->SendPacket(&MsgResult); g_pLog->FastSaveLog( LOG_FILE_1, "CGShopSpecialRepairHandler nItemIndex = %d", pSpecialRepair->m_ItemID) ; return PACKET_EXE_CONTINUE ; } FLOAT fCur = (FLOAT)pCurItem->GetDurPoints(); FLOAT fMax = (FLOAT)pCurItem->GetMaxDurPoint(); FLOAT fCurMax = (FLOAT)pCurItem->GetCurMaxDurPoint(); if(fMax != fCurMax) { UINT nUsedItem = 0; for (UINT i=0; i<pPacket->GetItemNum(); ++i) { ++nUsedItem; fCurMax = pSpecialRepair->m_RecoverPoint + fCurMax; if (fCurMax>=fMax) { fCurMax = fMax; break; } } HumanItemLogic::SetBagItemCurMaxDur(pHuman,(UINT)BagIndex, (INT)fCurMax); HumanItemLogic::SetBagItemDur(pHuman,(UINT)BagIndex, (INT)fCurMax); ITEM_LOG_PARAM LogParam; LogParam.OpType = ITEM_SPECIALREPAIR_CONSUME; LogParam.CharGUID = pHuman->GetGUID(); LogParam.XPos = pHuman->getWorldPos()->m_fX; LogParam.ZPos = pHuman->getWorldPos()->m_fZ; LogParam.SceneID = pHuman->getScene()->SceneID(); BOOL bOK = HumanItemLogic::EraseBagItem(&LogParam,pHuman, pSpecialRepair->m_ItemID, nUsedItem); Assert(bOK); SaveItemLog(&LogParam); ItemList.IsIn = GCShopSpecialRepairResult::BAG; ItemList.nCurDur = pCurItem->GetDurPoints(); ItemList.nCurMaxDur = pCurItem->GetCurMaxDurPoint(); ItemList.BagIndex = BagIndex; MsgResult.SetResult(EQUIPSPECIALREPAIR_SUCCESS); MsgResult.SetReList(&ItemList); pHuman->GetPlayer()->SendPacket(&MsgResult); return PACKET_EXE_CONTINUE ; } else { MsgResult.SetResult(EQUIPSPECIALREPAIR_NOREAPIR); pGamePlayer->SendPacket(&MsgResult); g_pLog->FastSaveLog( LOG_FILE_1, "CGShopSpecialRepairHandler needn't repair") ; return PACKET_EXE_CONTINUE ; } } else { g_pLog->FastSaveLog( LOG_FILE_1, "CGShopSpecialRepairHandler BagIndex = %d", BagIndex) ; return PACKET_EXE_CONTINUE ; } } else if(Opt == CGShopSpecialRepair::FromEquip) { pCurItem = HumanItemLogic::GetEquip(pHuman,(HUMAN_EQUIP)BagIndex); if(!pCurItem->IsEmpty()) {//有东西 if(pCurItem->GetItemClass() != ICLASS_EQUIP) { g_pLog->FastSaveLog( LOG_FILE_1, "CGShopSpecialRepairHandler pCurItem->GetItemClass() != ICLASS_EQUIP ") ; return PACKET_EXE_ERROR ; } EQUIP_SPECIALREPAIR_TB* pSpecialRepair = g_ItemTable.GetSpecialRepairTB(); Assert (pSpecialRepair != NULL); if (!pSpecialRepair) { g_pLog->FastSaveLog( LOG_FILE_1, "[CGShopSpecialRepairHandler::Execute] GetSpecialRepairTB index is error"); return PACKET_EXE_ERROR; } //获得Human背包中对应ItemIndex的物品位置 UINT nItemCount = HumanItemLogic::CalcBagItemCount(pHuman, pSpecialRepair->m_ItemID); if((nItemCount == 0)||(nItemCount < pPacket->GetItemNum())) { MsgResult.SetResult(EQUIPSPECIALREPAIR_ITEM); pGamePlayer->SendPacket(&MsgResult); g_pLog->FastSaveLog( LOG_FILE_1, "CGShopSpecialRepairHandler nItemIndex = %d", pSpecialRepair->m_ItemID) ; return PACKET_EXE_CONTINUE ; } FLOAT fCur = (FLOAT)pCurItem->GetDurPoints(); FLOAT fMax = (FLOAT)pCurItem->GetMaxDurPoint(); FLOAT fCurMax = (FLOAT)pCurItem->GetCurMaxDurPoint(); if(fMax != fCurMax) { UINT nUsedItem = 0; for (UINT i=0; i<pPacket->GetItemNum(); ++i) { ++nUsedItem; fCurMax = pSpecialRepair->m_RecoverPoint + fCurMax; if (fCurMax>=fMax) { fCurMax = fMax; break; } } HumanItemLogic::SetCurEquipMaxDur(pHuman,(HUMAN_EQUIP)BagIndex, (INT)fCurMax); HumanItemLogic::SetEquipDur(pHuman,(HUMAN_EQUIP)BagIndex, (INT)fCurMax); ITEM_LOG_PARAM LogParam; LogParam.OpType = ITEM_SPECIALREPAIR_CONSUME; LogParam.CharGUID = pHuman->GetGUID(); LogParam.XPos = pHuman->getWorldPos()->m_fX; LogParam.ZPos = pHuman->getWorldPos()->m_fZ; LogParam.SceneID = pHuman->getScene()->SceneID(); BOOL bOK = HumanItemLogic::EraseBagItem(&LogParam,pHuman, pSpecialRepair->m_ItemID,nUsedItem); Assert(bOK); SaveItemLog(&LogParam); ItemList.IsIn = GCShopSpecialRepairResult::EQUIP; ItemList.nCurDur = pCurItem->GetDurPoints(); ItemList.nCurMaxDur = pCurItem->GetCurMaxDurPoint(); ItemList.BagIndex = BagIndex; MsgResult.SetResult(EQUIPSPECIALREPAIR_SUCCESS); MsgResult.SetReList(&ItemList); pHuman->GetPlayer()->SendPacket(&MsgResult); if ((INT)fCur == 0) { pHuman->ItemEffectFlush(); } return PACKET_EXE_CONTINUE ; } else { MsgResult.SetResult(EQUIPSPECIALREPAIR_NOREAPIR); pGamePlayer->SendPacket(&MsgResult); g_pLog->FastSaveLog( LOG_FILE_1, "CGShopSpecialRepairHandler needn't repair") ; return PACKET_EXE_CONTINUE ; } } } g_pLog->FastSaveLog( LOG_FILE_1, "ERROR:CGShopSpecialRepairHandler error Opt=", Opt); return PACKET_EXE_ERROR; __LEAVE_FUNCTION return PACKET_EXE_ERROR ; }
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 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 = g_ItemOperator.CopyItem ( pBagContainer, pBagContainer->BagIndex2ConIndex(FromIndex), pExchangeContainer ); if(result>=0) {//拷贝成功, //发送消息给双方客户端 Item* pIt = pExchangeContainer->GetItem(result); g_pLog->FastSaveLog( LOG_FILE_1, "<交易> [%s] 加入交易物品 [%d]", pHuman->GetName(), pIt->GetItemTableIndex() ) ; if( pIt != NULL && pIt->IsEmpty() == FALSE ) { INT iConIndex = pBagContainer->BagIndex2ConIndex(FromIndex); //先锁定此物品 g_ItemOperator.LockItem( pBagContainer, iConIndex ); //标示次物品已经放在交易栏中,计算空间用 pBagContainer->GetItem(iConIndex)->SetInExchange(TRUE); //再发 pIt->SaveValueTo(&ItemTemp);//取出实例 /* 先发自己 */ Msg.SetIsMyself(TRUE);//发给自己 Msg.SetOpt(OPT_ADDITEM);//设置操作类型 Msg.SetFromType(POS_BAG);//设置来自类型 Msg.SetFromIndex(FromIndex);//设置来自索引 Msg.SetToIndex(result);//设置目标位置索引 pGamePlayer->SendPacket(&Msg); /* 再发对方 */ Msg.SetIsMyself(FALSE);//发给对方 Msg.SetOpt(OPT_ADDITEM);//设置操作类型 Msg.SetToIndex(result); _EXCHANGE_ITEM Exitem; Exitem.byNumber = ItemTemp.GetItemCount(); Exitem.isBlueEquip = 1; Exitem.item_data = ItemTemp; Exitem.uBagPos = result; Msg.SetItem(&Exitem); pDestHuman->GetPlayer()->SendPacket(&Msg); //改变物品 自己解锁 pHuman->m_ExchangBox.m_IsLocked = FALSE; if(pDestHuman->m_ExchangBox.m_IsLocked == TRUE) {//如果对方已经加锁 pDestHuman->m_ExchangBox.m_IsLocked = FALSE; GCExchangeSynchLock MsgToDes, MsgToSelf; //通知对方,解双方锁 MsgToDes.SetIsBoth(TRUE); MsgToDes.SetIsLocked(FALSE); pDestHuman->GetPlayer()->SendPacket(&MsgToDes); //通知自己解对方锁 MsgToSelf.SetIsMyself(FALSE); MsgToSelf.SetIsLocked(FALSE); pHuman->GetPlayer()->SendPacket(&MsgToSelf); } else {//对方没有加锁,直接同步 GCExchangeSynchLock MsgToDes; MsgToDes.SetIsMyself (FALSE); MsgToDes.SetIsLocked(FALSE); pDestHuman->GetPlayer()->SendPacket(&MsgToDes); } } else { MsgError.SetID(ERR_ILLEGAL); pGamePlayer->SendPacket(&MsgError); g_pLog->FastSaveLog( LOG_FILE_1, "<交易> [%s] 加入非法交易物品 [%d]", pHuman->GetName(), pIt->GetItemTableIndex() ) ; return PACKET_EXE_CONTINUE ; }//if( pIt != NULL && pIt->IsEmpty() == FALSE ) } else {//拷贝失败 MsgError.SetID(ERR_NOT_ENOUGHT_EXROOM); pGamePlayer->SendPacket(&MsgError); g_pLog->FastSaveLog( LOG_FILE_1, "<交易> [%s] 交易盒没有足够空间", pHuman->GetName() ) ; return PACKET_EXE_CONTINUE ; }//if(result>=0) } else { MsgError.SetID(ERR_ILLEGAL); pGamePlayer->SendPacket(&MsgError); g_pLog->FastSaveLog( LOG_FILE_1, "<交易> [%s] 没有获取到所要交易的背包物品", pHuman->GetName() ) ; return PACKET_EXE_CONTINUE ; }//if(pItem->IsEmpty() == FALSE) } break; case POS_EQUIP: { } break; case POS_PET: { } break; default: break; } } break; case OPT_REMOVEITEM: { switch(ToType) { case POS_BAG: { Item* pIt = pExchangeContainer->GetItem(FromIndex); if( pIt != NULL && pIt->IsEmpty() == FALSE ) { INT BagIndex = -1; ItemContainer* pBagContainer = HumanItemLogic::GetBagItemContain( pHuman,&pIt->GetGUID(), BagIndex); if ( pBagContainer == NULL ) { MsgError.SetID(ERR_ILLEGAL); pGamePlayer->SendPacket(&MsgError); g_pLog->FastSaveLog( LOG_FILE_1, "<交易> [%s] 背包不存在", pHuman->GetName() ) ; return PACKET_EXE_CONTINUE; } //从交易盒中删掉此物品 if(g_ItemOperator.EraseItem(pExchangeContainer, FromIndex)) { //解锁此物品 g_ItemOperator.UnlockItem( pBagContainer, BagIndex ); //标示次物品已经取消放在交易栏中,计算空间用 pBagContainer->GetItem(BagIndex)->SetInExchange(FALSE); g_pLog->FastSaveLog( LOG_FILE_1, "<交易> [%s] 删除交易物品 [%d]", pHuman->GetName(), BagIndex) ; //发消息 if(BagIndex>=0) { /* 先发自己 */ Msg.SetIsMyself(TRUE);//发给自己 Msg.SetOpt(OPT_REMOVEITEM);//设置操作类型 Msg.SetToType(POS_BAG);//设置目的类型 Msg.SetToIndex(BagIndex);//设置目的索引 Msg.SetFromIndex(FromIndex);//设置来源索引 pGamePlayer->SendPacket(&Msg); /* 再发对方 */ Msg.SetIsMyself(FALSE);//发给对方 Msg.SetOpt(OPT_REMOVEITEM);//设置操作类型 Msg.SetFromIndex(FromIndex);//设置来源索引 pDestHuman->GetPlayer()->SendPacket(&Msg); //改变物品 自己解锁 pHuman->m_ExchangBox.m_IsLocked = FALSE; if(pDestHuman->m_ExchangBox.m_IsLocked == TRUE) {//如果对方已经加锁 pDestHuman->m_ExchangBox.m_IsLocked = FALSE; GCExchangeSynchLock MsgToDes, MsgToSelf; //通知对方,解双方锁 MsgToDes.SetIsBoth(TRUE); MsgToDes.SetIsLocked(FALSE); pDestHuman->GetPlayer()->SendPacket(&MsgToDes); //通知自己解对方锁 MsgToSelf.SetIsMyself(FALSE); MsgToSelf.SetIsLocked(FALSE); pHuman->GetPlayer()->SendPacket(&MsgToSelf); } else {//对方没有加锁,直接同步 GCExchangeSynchLock MsgToDes; MsgToDes.SetIsMyself (FALSE); MsgToDes.SetIsLocked(FALSE); pDestHuman->GetPlayer()->SendPacket(&MsgToDes); } } else { MsgError.SetID(ERR_ILLEGAL); pGamePlayer->SendPacket(&MsgError); return PACKET_EXE_CONTINUE; } } else { MsgError.SetID(ERR_ILLEGAL); pGamePlayer->SendPacket(&MsgError); g_pLog->FastSaveLog( LOG_FILE_1, "<交易> [%s] 删除交易盒位置 [%d] 处的物品时出错", pHuman->GetName(), FromIndex ) ; return PACKET_EXE_CONTINUE; } } else { MsgError.SetID(ERR_ILLEGAL); pGamePlayer->SendPacket(&MsgError); g_pLog->FastSaveLog( LOG_FILE_1, "<交易> [%s] 交易盒位置 [%d] 处不存在物品", pHuman->GetName(), FromIndex ) ; return PACKET_EXE_CONTINUE; } } break; case POS_EQUIP: { } break; case POS_PET: { } break; default: break; } } break; case OPT_ADDPET: { ItemContainer* pPetContainer = pHuman->GetPetContain(); FromIndex = pPetContainer->GetIndexByGUID( &PetGuid ); if (255 == FromIndex) { g_pLog->FastSaveLog( LOG_FILE_1, "<交易> [%s] 加入非法交易宠物", pHuman->GetName()) ; return PACKET_EXE_CONTINUE ; } //先查一遍交易盒中是不是已经有该物品了 for(INT i = 0; i<EXCHANGE_PET_BOX_SIZE; i++) { if(pExchangePetContainer->GetItem(i)->GetPetGUID() == pPetContainer->GetItem(FromIndex)->GetPetGUID() ) {//物品已经在交易盒中,丢弃该消息 return PACKET_EXE_CONTINUE ; } } //自动找格 INT result = g_ItemOperator.CopyItem ( pPetContainer, FromIndex, pExchangePetContainer ); if(result>=0) {//拷贝成功 Item* pIt = pExchangePetContainer->GetItem(result); g_pLog->FastSaveLog( LOG_FILE_1, "<交易> [%s] 加入交易宠物 [%s]", pHuman->GetName(), pIt->GetName() ) ; if(pIt->IsEmpty() == FALSE) { //先锁定此物品 g_ItemOperator.LockItem( pPetContainer, FromIndex ); //标示次物品已经放在交易栏中,计算空间用 pPetContainer->GetItem(FromIndex)->SetInExchange(TRUE); /* 先发自己 */ Msg.SetIsMyself(TRUE);//发给自己 Msg.SetOpt(OPT_ADDPET);//设置操作类型 Msg.SetToIndex(result);//设置目的地位置 Msg.SetPetGuid(PetGuid);//宠物GUID pGamePlayer->SendPacket(&Msg); /* 再发对方 */ GCDetailAttrib_Pet PetMsgDetail; //组装GCDetailAttrib_Pet结构 Obj_Human::CalculatePetDetailAttrib(PetMsgDetail, pIt); PetMsgDetail.SetTradeIndex( result ); PET_EXTRA_STRUCT::GCExchangePetView_t ExtraPetInfo; ExtraPetInfo.m_bFlag = TYPE_EXCHANGE; PetMsgDetail.SetExtraInfoLength(ExtraPetInfo.GetSize()); PetMsgDetail.SetExtraInfoData((BYTE*)&ExtraPetInfo); pDestHuman->GetPlayer()->SendPacket(&PetMsgDetail); //改变金钱 自己解锁 pHuman->m_ExchangBox.m_IsLocked = FALSE; if(pDestHuman->m_ExchangBox.m_IsLocked == TRUE) {//如果对方已经加锁 pDestHuman->m_ExchangBox.m_IsLocked = FALSE; GCExchangeSynchLock MsgToDes, MsgToSelf; //通知对方,解双方锁 MsgToDes.SetIsBoth(TRUE); MsgToDes.SetIsLocked(FALSE); pDestHuman->GetPlayer()->SendPacket(&MsgToDes); //通知自己解对方锁 MsgToSelf.SetIsMyself(FALSE); MsgToSelf.SetIsLocked(FALSE); pHuman->GetPlayer()->SendPacket(&MsgToSelf); } else {//对方没有加锁,直接同步 GCExchangeSynchLock MsgToDes; MsgToDes.SetIsMyself (FALSE); MsgToDes.SetIsLocked(FALSE); pDestHuman->GetPlayer()->SendPacket(&MsgToDes); } } else { MsgError.SetID(ERR_ILLEGAL); pGamePlayer->SendPacket(&MsgError); g_pLog->FastSaveLog( LOG_FILE_1, "<交易> [%s] 加入非法交易宠物 [%s]", pHuman->GetName(), pIt->GetName() ) ; return PACKET_EXE_CONTINUE ; } } } break; case OPT_REMOVEPET: { ItemContainer* pPetContainer = pHuman->GetPetContain(); INT nIndexInPet = pPetContainer->GetIndexByGUID(&PetGuid); FromIndex = pExchangePetContainer->GetIndexByGUID(&PetGuid); if(g_ItemOperator.EraseItem(pExchangePetContainer, FromIndex)) { //解锁此物品 g_ItemOperator.UnlockItem( pPetContainer, nIndexInPet ); //标示次物品已经放在交易栏中,计算空间用 pPetContainer->GetItem(nIndexInPet)->SetInExchange(FALSE); //发消息 g_pLog->FastSaveLog( LOG_FILE_1, "<交易> [%s] 删除交易宠物 [%s]", pHuman->GetName(), pPetContainer->GetItem(nIndexInPet)->GetName()) ; if(nIndexInPet>=0) { /* 先发自己 */ Msg.SetIsMyself(TRUE);//发给自己 Msg.SetOpt(OPT_REMOVEPET);//设置操作类型 Msg.SetPetGuid(PetGuid);//宠物GUID pGamePlayer->SendPacket(&Msg); /* 再发对方 */ Msg.SetIsMyself(FALSE);//发给对方 Msg.SetOpt(OPT_REMOVEPET);//设置操作类型 Msg.SetPetGuid(PetGuid);//宠物GUID pDestHuman->GetPlayer()->SendPacket(&Msg); //改变金钱 自己解锁 pHuman->m_ExchangBox.m_IsLocked = FALSE; if(pDestHuman->m_ExchangBox.m_IsLocked == TRUE) {//如果对方已经加锁 pDestHuman->m_ExchangBox.m_IsLocked = FALSE; GCExchangeSynchLock MsgToDes, MsgToSelf; //通知对方,解双方锁 MsgToDes.SetIsBoth(TRUE); MsgToDes.SetIsLocked(FALSE); pDestHuman->GetPlayer()->SendPacket(&MsgToDes); //通知自己解对方锁 MsgToSelf.SetIsMyself(FALSE); MsgToSelf.SetIsLocked(FALSE); pHuman->GetPlayer()->SendPacket(&MsgToSelf); } else {//对方没有加锁,直接同步 GCExchangeSynchLock MsgToDes; MsgToDes.SetIsMyself (FALSE); MsgToDes.SetIsLocked(FALSE); pDestHuman->GetPlayer()->SendPacket(&MsgToDes); } } else { MsgError.SetID(ERR_ILLEGAL); pGamePlayer->SendPacket(&MsgError); return PACKET_EXE_CONTINUE; } } else { MsgError.SetID(ERR_ILLEGAL); pGamePlayer->SendPacket(&MsgError); g_pLog->FastSaveLog( LOG_FILE_1, "<交易> [%s] 删除交易盒位置 [%d] 处的物品时出错", pHuman->GetName(), FromIndex ) ; return PACKET_EXE_CONTINUE; } } break; default: break; } return PACKET_EXE_CONTINUE ; __LEAVE_FUNCTION return PACKET_EXE_ERROR ; }
uint CGAskLockObjHandler::Execute(CGAskLockObj* 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 LockType = pPacket->GetLockType(); BYTE lockObj = pPacket->GetLockObj(); GCAddLockObj msg; // 如果要执行加锁先查询玩家是不是还有足够的精力(为一个物品或者宠物加保护,需要10点精力) if(pPacket->GetLockType() == CGAskLockObj::OPR_LOCK) { if( LOCK_A_OBJ_NEED_ENERGY > pHuman->GetEnergy() ) { msg.SetLockObj(GCAddLockObj::LOCK_ITEM); msg.SetResult(GCAddLockObj::RESULT_NO_JINGLI); pHuman->GetPlayer()->SendPacket(&msg); return PACKET_EXE_CONTINUE ; } } switch(lockObj) { case CGAskLockObj::LOCK_ITEM: //物品 { msg.SetLockObj(GCAddLockObj::LOCK_ITEM); INT nItemIndex = HumanItemLogic::GetBagItemPosByGUID( pHuman, pPacket->GetItemGUID() ); if(INVALID_ID == nItemIndex) { return PACKET_EXE_CONTINUE ; } Item* pItem = HumanItemLogic::GetBagItem( pHuman, nItemIndex ); if(!pItem) { return PACKET_EXE_CONTINUE ; } ItemContainer* pCon = HumanItemLogic::GetBagContainer( pHuman, nItemIndex ); if(!pCon) { return PACKET_EXE_CONTINUE ; } if(LockType == CGAskLockObj::OPR_LOCK) //加锁 { if(g_ItemOperator.SetItemPWLock(pCon, pCon->BagIndex2ConIndex(nItemIndex), TRUE)) { //扣除精力 pHuman->SetEnergy(pHuman->GetEnergy() - LOCK_A_OBJ_NEED_ENERGY); msg.SetResult(GCAddLockObj::RESULT_LOCK_OK); GCItemInfo MsgItem; MsgItem.setIsNull(FALSE); MsgItem.setID((WORD)nItemIndex); pItem->SaveValueTo(MsgItem.getItem()); pHuman->GetPlayer()->SendPacket(&MsgItem); } } else if(LockType == CGAskLockObj::OPR_UNLOCK) //去锁 { if(g_ItemOperator.SetItemPWLock(pCon, pCon->BagIndex2ConIndex(nItemIndex), FALSE)) { msg.SetResult(GCAddLockObj::RESULT_UNLOCK_OK); GCItemInfo MsgItem; MsgItem.setIsNull(FALSE); MsgItem.setID((WORD)nItemIndex); pItem->SaveValueTo(MsgItem.getItem()); pHuman->GetPlayer()->SendPacket(&MsgItem); } } } break; case CGAskLockObj::LOCK_PET: //宠物 { msg.SetLockObj(GCAddLockObj::LOCK_PET); } break; default: break; } pHuman->GetPlayer()->SendPacket(&msg); 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 ; }