uint CGAskDetailXinFaListHandler::Execute( CGAskDetailXinFaList* 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 ) ; ObjID_t ObjID = pHuman->GetID(); if( ObjID == INVALID_ID ) { Assert(FALSE) ; return PACKET_EXE_ERROR ; } Obj_Character *pTarget = (Obj_Character*)(pScene->GetObjManager()->GetObj(pPacket->getTargetID())); if( pTarget==NULL ) { Assert( pTarget ) ; return PACKET_EXE_ERROR ; } // 权限判断 // to be continue... if ( pTarget->GetObjType() != Obj::OBJ_TYPE_HUMAN && pTarget->GetObjType() != Obj::OBJ_TYPE_PET ) { g_pLog->FastSaveLog( LOG_FILE_1, "CGAskDetailXinFaListHandler: faile obj=%d scene=%d", ObjID, pScene->SceneID() ) ; return PACKET_EXE_CONTINUE; } GCDetailXinFaList Msg; Msg.setObjID( pTarget->GetID() ); Msg.setXinFaList(pHuman->Skill_GetXinFaList().m_Count, pHuman->Skill_GetXinFaList().m_aXinFa); pGamePlayer->SendPacket( &Msg ) ; g_pLog->FastSaveLog( LOG_FILE_1, "CGAskDetailXinFaListHandler: ok obj=%d scene=%d", ObjID, pScene->SceneID() ) ; return PACKET_EXE_CONTINUE ; __LEAVE_FUNCTION return PACKET_EXE_ERROR ; }
BOOL CommonSkill001_T::EffectOnUnitOnce(Obj_Character& rMe, Obj_Character& rTar, BOOL bCriticalFlag) const { __ENTER_FUNCTION SkillInfo_T& rSkillInfo = rMe.GetSkillInfo(); TargetingAndDepletingParams_T& rParams = rMe.GetTargetingAndDepletingParams(); if(FALSE==rTar.IsAlive() || FALSE == rTar.IsActiveObj() || Obj::OBJ_TYPE_HORSE != rTar.GetObjType()) { rParams.SetErrCode(OR_INVALID_TARGET); return FALSE; } if(Obj::OBJ_TYPE_HUMAN != rMe.GetObjType()) { rParams.SetErrCode(OR_U_CANNT_DO_THIS_RIGHT_NOW); return FALSE; } {// Test code INT nDataIndex = Skill_GetSkillInfoDescriptorValueByIndex(rSkillInfo, 0); g_ImpactCore.SendImpactToUnit(rTar, nDataIndex, rMe.GetID(), 500); } PET_LOG_PARAM PetLogParam; BOOL bRet = ((Obj_Human*)&rMe)->CaptureHorse(&PetLogParam,rTar.GetID()); GCManipulatePetRet msg; if(bRet) { msg.SetManipulateRet(GCManipulatePetRet::MANIPULATEPET_RET_CAPTURESUCC); ((Obj_Human*)&rMe)->GetPlayer()->SendPacket(&msg); // 向正在捕获的其它玩家发送失败消息 ((Obj_Horse&)rTar).SendCaptureFailedToOthers(rMe.GetID()); // 清空宠物身上所有的玩家数 ((Obj_Horse&)rTar).DelCapturer(rMe.GetID()); HorseManager* pHorseMgr = rMe.getScene()->GetHorseManager(); if (pHorseMgr) { pHorseMgr->RemoveHorse(rTar.GetID()); } PetLogParam.OPType = PET_OP_CATCH; SavePetLog(&PetLogParam); } else { // 减少该宠物身上的捕获玩家数 ((Obj_Horse&)rTar).DelCapturer(rMe.GetID()); msg.SetManipulateRet(GCManipulatePetRet::MANIPULATEPET_RET_CAPTUREFALID); ((Obj_Human*)&rMe)->GetPlayer()->SendPacket(&msg); } return TRUE; __LEAVE_FUNCTION return FALSE; }
INT CombatCore_T::MagicalDamage(Obj_Character& rMe, Obj_Character& rTar, INT nAdditionAttack, INT nAdditionDefence) { __ENTER_FUNCTION INT nDamage; INT nAttack = Attr_VerifyGeneralAttack(rMe.GetAttackMagic()+nAdditionAttack); INT nDefence = Attr_VerifyDefence(rTar.GetDefenceMagic()+nAdditionDefence); INT nIgnoreRate = 0; // calculate damage if(Obj::OBJ_TYPE_HUMAN==rTar.GetObjType()) { nIgnoreRate= rTar.ItemValue(IATTRIBUTE_IMMUNITY_P).m_Value; } if(0==nAttack+nDefence) { //never enter here nDamage = 0; } else { nDamage = nAttack*nAttack/(nAttack+nDefence); } 0>nIgnoreRate?nIgnoreRate=0:NULL; 100<nIgnoreRate?nIgnoreRate=100:NULL; nDamage = nDamage - Float2Int((nDamage*nIgnoreRate)/100.0f); 0>nDamage?nDamage=0:NULL; return nDamage; __LEAVE_FUNCTION return 0; }
INT CombatCore_T::CalculateHitRate(Obj_Character& rAttacker, Obj_Character& rTag) { __ENTER_FUNCTION INT nHit = rAttacker.GetHit(); INT nMiss = rTag.GetMiss(); nHit = Attr_VerifyHitMiss(nHit); nMiss = Attr_VerifyHitMiss(nMiss); //INT iItemPointRefix = 0; //INT iSkillPointRefix = 0; //if( rAttacker.GetObjType() == Obj::OBJ_TYPE_HUMAN ) //{ // //装备对属性的点数影响 // iItemPointRefix = static_cast<Obj_Human&>(rAttacker).GetIattributeHit(); //} //iSkillPointRefix = rAttacker.GetHitRefix(); //INT iItemPointRefixMiss = 0; //INT iSkillPointRefixMiss = 0; //if( rTag.GetObjType() == Obj::OBJ_TYPE_HUMAN ) //{ // //装备对属性的点数影响 // iItemPointRefixMiss = static_cast<Obj_Human&>(rTag).GetIattributeMiss(); //} //iSkillPointRefixMiss = rTag.GetMissRefix(); INT iRateHit = 0; if (Obj::OBJ_TYPE_HUMAN==rAttacker.GetObjType()) { Obj_Human& rHuman = (Obj_Human&)rAttacker; _ITEM_EFFECT* pIE=NULL; pIE = rHuman.ItemEffect(IATTRIBUTE_RATE_HIT); Assert( pIE ); if( pIE->IsActive() ) { iRateHit = pIE->m_Attr.m_Value; } } //总命中率=(75+攻击方总命中-受击方总闪避)/100+攻击方装备对命中率的影响+攻击方技能对命中率的影响-受击方装备对闪避率的影响-受击方技能对闪避率的影响 SkillInfo_T& oSkillInf = rAttacker.GetSkillInfo(); INT iRefix = oSkillInf.GetAccuracy(); if( iRefix < 0 ) { iRefix = 0; } INT iFainlHitRate = ((75 + nHit - nMiss)/100.0 + iRateHit/100.0 + iRefix/100.0) * 100.0; return iFainlHitRate; __LEAVE_FUNCTION return 0; }
INT CombatCore_T::SoilDamage(Obj_Character& rMe,Obj_Character& rTar, INT nAdditionalAttack, INT nAdditionalResist) { INT nDamage; INT nAttack = Attr_VerifyTraitAttack(rMe.GetAttackSoil()+nAdditionalAttack); INT nResist = Attr_VerifyResist(rTar.GetDefenceSoil()+nAdditionalResist); nDamage = AttrDamage(rMe, nResist, nAttack, IATTRIBUTE_SHIELD_SOIL); INT nIgnoreRate = 0; if(Obj::OBJ_TYPE_HUMAN==rTar.GetObjType()) { nIgnoreRate= (INT)(rTar.ItemValue(IATTRIBUTE_RATE_SOIL_ATT_REDUCE).m_Value); } nDamage = nDamage*(100.0-((double)nIgnoreRate))/100.0f; return nDamage; }
VOID StdImpact033_T::OnFadeOut(OWN_IMPACT& rImp, Obj_Character& rMe) const { INT nValue = 0; if(Obj::OBJ_TYPE_MONSTER == rMe.GetObjType()) { Obj_Monster& rMonster = (Obj_Monster&)rMe; INT nAI_Type = GetAiTypeRefix(rImp); rMonster.SetAIType(nAI_Type); AI_Monster * pAI = rMonster.GetMonsterAI(); if(NULL!=pAI) { Obj* pObj = Impact_GetCaster(rMe, rImp); if(NULL!=pObj) { pAI->AddPrimaryEnemy(pObj->GetID()); } } } }
INT CombatCore_T::NormalDamage( Obj_Character &rTar, INT nAttack, INT nDefence, INT iType ) { INT nDamage; INT nIgnoreRate = 0; // calculate damage if(Obj::OBJ_TYPE_HUMAN==rTar.GetObjType()) { nIgnoreRate = rTar.ItemValue(iType).m_Value; } if(0==nAttack+nDefence) { //never enter here nDamage = 0; } else { nDamage = nAttack - nDefence; } nDamage -= nIgnoreRate; 0>nDamage?nDamage=0:NULL; return nDamage; }
INT CombatCore_T::AttrDamage( Obj_Character &rTar, INT &nResist, INT nAttack, INT iType ) { INT nDamage; INT nIgnoreRate = 0; if(MAX_EFFECTIVE_RESIST<nResist) { nResist = MAX_EFFECTIVE_RESIST; } if(-MAX_EFFECTIVE_RESIST>nResist) { nResist = -MAX_EFFECTIVE_RESIST; } nDamage = Float2Int(nAttack*(100-nResist)/100); if(Obj::OBJ_TYPE_HUMAN==rTar.GetObjType()) { nIgnoreRate = rTar.ItemValue(iType).m_Value; } nDamage -= nIgnoreRate; 0>nDamage?nDamage=0:NULL; return nDamage; }
BOOL CombatCore_T::IsCriticalHit(Obj_Character& rAttacker, INT nCriticalRate, INT nRand, INT iToughness) { __ENTER_FUNCTION INT iSkillPointRefix = 0; SkillInfo_T& rSkillInf = rAttacker.GetSkillInfo(); iSkillPointRefix = rSkillInf.GetCriticalRate(); if( 0 > iSkillPointRefix ) { iSkillPointRefix = 0; } INT iRateCrit = 0; if (Obj::OBJ_TYPE_HUMAN==rAttacker.GetObjType()) { Obj_Human& rHuman = (Obj_Human&)rAttacker; _ITEM_EFFECT* pIE=NULL; pIE = rHuman.ItemEffect(IATTRIBUTE_RATE_CRIT); Assert( pIE ); if( pIE->IsActive() ) { iRateCrit = pIE->m_Attr.m_Value; } } //暴击率=(5+攻击方总暴击-受击方总韧性)/100+攻击方装备对暴击率的影响+攻击方技能对暴击率的影响 INT iFanlCriticalRate = Float2Int((( 5 + nCriticalRate - iToughness )/100.0 + iRateCrit/100.0 +iSkillPointRefix/100.f) * 100.0); iFanlCriticalRate = Attr_VerifyCritical(iFanlCriticalRate); if( nRand < iFanlCriticalRate ) return TRUE;//会心一击 return FALSE;//普通一击 __LEAVE_FUNCTION return FALSE; }
uint CGExchangeOkIIIHandler::Execute( CGExchangeOkIII* pPacket, Player* pPlayer ) { __ENTER_FUNCTION GamePlayer* pGamePlayer = (GamePlayer*)pPlayer ; Assert( pGamePlayer ) ; Obj_Human* pHuman = pGamePlayer->GetHuman() ; Assert( pHuman ) ; Scene* pScene = pHuman->getScene() ; if( pScene==NULL ) { Assert(FALSE) ; return PACKET_EXE_ERROR ; } //检查线程执行资源是否正确 Assert( MyGetCurrentThreadID()==pScene->m_ThreadID ) ; EXCHANGE_CERTIFY_EACH_OTHER(pHuman) ObjID_t DestID = pHuman->m_ExchangBox.m_ObjID; Obj_Character *pTarget = (Obj_Character*)(pScene->GetObjManager()->GetObj( DestID )); if(pTarget->GetObjType() != Obj::OBJ_TYPE_HUMAN) { g_pLog->FastSaveLog( LOG_FILE_1, "CGExchangeOkIIIHandler: %s ask not a human.", pHuman->GetName() ) ; return PACKET_EXE_CONTINUE; } Obj_Human* pDestHuman = (Obj_Human*)pTarget; if( pDestHuman == NULL ) { Assert(FALSE); return PACKET_EXE_CONTINUE; } // 不同阵营,不让查看 if( pHuman->IsEnemy( pDestHuman ) ) { g_pLog->FastSaveLog( LOG_FILE_1, "CGExchangeOkIIIHandler: %s cann't ask %s's detailattr ", pHuman->GetName(), pDestHuman->GetName() ) ; return PACKET_EXE_CONTINUE; } if(pHuman->m_ExchangBox.m_Status == ServerExchangeBox::EXCHANGE_WAIT_FOR_CONFIRM) { //设置可以交换 pHuman->m_ExchangBox.m_Status = ServerExchangeBox::EXCHANGE_CONFIRM_READY; if(pDestHuman->m_ExchangBox.m_Status == ServerExchangeBox::EXCHANGE_CONFIRM_READY) {//可以交换了 //1.变量初始化 ItemContainer* pMyExchangeContainer = &(pHuman->m_ExchangBox.m_Container); ItemContainer* pOtExchangeContainer = &(pDestHuman->m_ExchangBox.m_Container); ItemContainer* pMyExchangePetContainer = &(pHuman->m_ExchangBox.m_PetContainer); ItemContainer* pOtExchangePetContainer = &(pDestHuman->m_ExchangBox.m_PetContainer); _EXCHANGE_ITEM_LIST ItemListMeToOt; _EXCHANGE_ITEM_LIST ItemListOtToMe; ItemListMeToOt.Init(); ItemListOtToMe.Init(); //2.验证循环 g_pLog->FastSaveLog( LOG_FILE_1, "<交易> [%s] 与 [%s] 开始验证循环", pHuman->GetName(), pDestHuman->GetName()) ; for(INT i = 0; i<EXCHANGE_BOX_SIZE; i++) { if(pMyExchangeContainer->GetItem(i)->IsEmpty() == FALSE) { ItemListMeToOt.AddItem( pMyExchangeContainer->GetItem(i) ); } if(pOtExchangeContainer->GetItem(i)->IsEmpty() == FALSE) { ItemListOtToMe.AddItem( pOtExchangeContainer->GetItem(i) ); } } for(INT i = 0; i<EXCHANGE_PET_BOX_SIZE; i++) { if(pMyExchangePetContainer->GetItem(i)->IsEmpty() == FALSE) { ItemListMeToOt.AddItem( pMyExchangePetContainer->GetItem(i) ); } if(pOtExchangePetContainer->GetItem(i)->IsEmpty() == FALSE) { ItemListOtToMe.AddItem( pOtExchangePetContainer->GetItem(i) ); } } if( FALSE == HumanItemLogic::CanReceiveExchangeItemList( pHuman, ItemListOtToMe) ) {//空间不够 GCExchangeError MsgSelf; MsgSelf.SetID(EXCHANGE_MSG::ERR_NOT_ENOUGHT_ROOM_SELF); pHuman->GetPlayer()->SendPacket(&MsgSelf); GCExchangeError MsgOther; MsgOther.SetID(EXCHANGE_MSG::ERR_NOT_ENOUGHT_ROOM_OTHER); pDestHuman->GetPlayer()->SendPacket(&MsgOther); pHuman->m_ExchangBox.CleanUp(); pDestHuman->m_ExchangBox.CleanUp(); g_pLog->FastSaveLog( LOG_FILE_1, " <交易> [%s] 空间不够", pHuman->GetName()) ; return PACKET_EXE_CONTINUE; } if( FALSE == HumanItemLogic::CanReceiveExchangeItemList( pDestHuman, ItemListMeToOt) ) {//空间不够 GCExchangeError MsgSelf; MsgSelf.SetID(EXCHANGE_MSG::ERR_NOT_ENOUGHT_ROOM_SELF); pDestHuman->GetPlayer()->SendPacket(&MsgSelf); GCExchangeError MsgOther; MsgOther.SetID(EXCHANGE_MSG::ERR_NOT_ENOUGHT_ROOM_OTHER); pHuman->GetPlayer()->SendPacket(&MsgOther); pHuman->m_ExchangBox.CleanUp(); pDestHuman->m_ExchangBox.CleanUp(); g_pLog->FastSaveLog( LOG_FILE_1, " <交易> [%s] 空间不够", pDestHuman->GetName()) ; return PACKET_EXE_CONTINUE; } if( pHuman->m_ExchangBox.m_Money > pHuman->GetMoney() ) {//金钱非法 GCExchangeError MsgSelf; MsgSelf.SetID(EXCHANGE_MSG::ERR_NOT_ENOUGHT_MONEY_SELF); pHuman->GetPlayer()->SendPacket(&MsgSelf); GCExchangeError MsgOther; MsgOther.SetID(EXCHANGE_MSG::ERR_NOT_ENOUGHT_MONEY_OTHER); pDestHuman->GetPlayer()->SendPacket(&MsgOther); pHuman->m_ExchangBox.CleanUp(); pDestHuman->m_ExchangBox.CleanUp(); g_pLog->FastSaveLog( LOG_FILE_1, " <交易> [%s] 金钱不足", pHuman->GetName()) ; return PACKET_EXE_CONTINUE; } if( pDestHuman->m_ExchangBox.m_Money > pDestHuman->GetMoney() ) {//金钱非法 GCExchangeError MsgSelf; MsgSelf.SetID(EXCHANGE_MSG::ERR_NOT_ENOUGHT_MONEY_SELF); pDestHuman->GetPlayer()->SendPacket(&MsgSelf); GCExchangeError MsgOther; MsgOther.SetID(EXCHANGE_MSG::ERR_NOT_ENOUGHT_MONEY_OTHER); pHuman->GetPlayer()->SendPacket(&MsgOther); pHuman->m_ExchangBox.CleanUp(); pDestHuman->m_ExchangBox.CleanUp(); g_pLog->FastSaveLog( LOG_FILE_1, " <交易> [%s] 金钱不足", pDestHuman->GetName()) ; return PACKET_EXE_CONTINUE; } //2.1宠物验证 Obj_Pet* pDestPet = pDestHuman->GetPet(); Obj_Pet* pMyPet = pHuman->GetPet(); PET_GUID_t DestPetGuid; PET_GUID_t MyPetGuid; if(pDestPet) { DestPetGuid = pDestPet->GetPetGUID(); } if(pMyPet) { MyPetGuid = pMyPet->GetPetGUID(); } //如果是当前召唤出来的宠物,先收回来再换 for(INT i = 0; i<EXCHANGE_PET_BOX_SIZE; i++) { if(pMyExchangePetContainer->GetItem(i)->IsEmpty() == FALSE) { INT nPetLevel = pMyExchangePetContainer->GetItem(i)->GetLevel(); INT nHumanLevel = pDestHuman->GetLevel(); PET_GUID_t ExchPetGuid = pMyExchangePetContainer->GetItem(i)->GetPetGUID(); if(nPetLevel>nHumanLevel) { GCExchangeError Msg; Msg.SetID(EXCHANGE_MSG::ERR_PET_LEVEL_TOO_HIGH); pHuman->GetPlayer()->SendPacket(&Msg); pDestHuman->GetPlayer()->SendPacket(&Msg); pHuman->m_ExchangBox.CleanUp(); pDestHuman->m_ExchangBox.CleanUp(); g_pLog->FastSaveLog( LOG_FILE_1, " <交易> 宠物级别过高 petlevel = %d, humanlevel = %d", nPetLevel, nHumanLevel) ; return PACKET_EXE_CONTINUE; } if(ExchPetGuid == MyPetGuid) { pHuman->ReCallPet(); } } if(pOtExchangePetContainer->GetItem(i)->IsEmpty() == FALSE) { INT nPetLevel = pOtExchangePetContainer->GetItem(i)->GetLevel(); INT nHumanLevel = pHuman->GetLevel(); PET_GUID_t ExchPetGuid = pOtExchangePetContainer->GetItem(i)->GetPetGUID(); if(nPetLevel>nHumanLevel) { GCExchangeError Msg; Msg.SetID(EXCHANGE_MSG::ERR_PET_LEVEL_TOO_HIGH); pHuman->GetPlayer()->SendPacket(&Msg); pDestHuman->GetPlayer()->SendPacket(&Msg); pHuman->m_ExchangBox.CleanUp(); pDestHuman->m_ExchangBox.CleanUp(); g_pLog->FastSaveLog( LOG_FILE_1, " <交易> 宠物级别过高 petlevel = %d, humanlevel = %d", nPetLevel, nHumanLevel) ; return PACKET_EXE_CONTINUE; } if(ExchPetGuid == DestPetGuid) { pDestHuman->ReCallPet(); } } } //3.移动物品循环 g_pLog->FastSaveLog( LOG_FILE_1, "<交易> [%s] 与 [%s] 开始移动循环", pHuman->GetName(), pDestHuman->GetName()) ; GCExchangeSuccessIII MsgSuccessToMe, MsgSuccessToOt; GCExchangeSuccessIII::_SUCC_ITEM ItemListToMe[EXCHANGE_BOX_SIZE+EXCHANGE_PET_BOX_SIZE]; INT MyItemNum = 0; GCExchangeSuccessIII::_SUCC_ITEM ItemListToOt[EXCHANGE_BOX_SIZE+EXCHANGE_PET_BOX_SIZE]; INT OtItemNum = 0; BOOL bFlag = FALSE; //用来记录可以交换的物品 struct ExItem_t { UCHAR uItemType; INT nIndex; INT nIndexInEx; ExItem_t() { uItemType = 0; nIndex = -1; nIndexInEx = -1; } }; INT ExItemNumOt = 0; ExItem_t ExItemIndexInOt[EXCHANGE_BOX_SIZE]; INT ExItemNumMy = 0; ExItem_t ExItemIndexInMy[EXCHANGE_BOX_SIZE]; INT ExPetItemNumOt = 0; ExItem_t ExPetItemIndexInOt[EXCHANGE_PET_BOX_SIZE]; INT ExPetItemNumMy = 0; ExItem_t ExPetItemIndexInMy[EXCHANGE_PET_BOX_SIZE]; for(INT i = 0; i<EXCHANGE_BOX_SIZE; i++) { if(pMyExchangeContainer->GetItem(i)->IsEmpty() == FALSE) { Item* pItemRef = pMyExchangeContainer->GetItem(i); ItemContainer* pMyBagContainer = HumanItemLogic::GetItemContain(pHuman, pItemRef->GetItemTableIndex()); ExItemIndexInMy[ExItemNumMy].uItemType = pItemRef->GetItemClass(); ExItemIndexInMy[ExItemNumMy].nIndex = pMyBagContainer->GetIndexByGUID(&pItemRef->GetGUID()); ExItemIndexInMy[ExItemNumMy].nIndexInEx = i; ExItemNumMy++; } if(pOtExchangeContainer->GetItem(i)->IsEmpty() == FALSE) { Item* pItemRef = pOtExchangeContainer->GetItem(i); ItemContainer* pOtBagContainer = HumanItemLogic::GetItemContain(pDestHuman, pItemRef->GetItemTableIndex()); ExItemIndexInOt[ExItemNumOt].uItemType = pItemRef->GetItemClass(); ExItemIndexInOt[ExItemNumOt].nIndex = pOtBagContainer->GetIndexByGUID(&pItemRef->GetGUID()); ExItemIndexInOt[ExItemNumOt].nIndexInEx = i; ExItemNumOt++; } } for(INT i = 0; i<EXCHANGE_PET_BOX_SIZE; i++) { if(pMyExchangePetContainer->GetItem(i)->IsEmpty() == FALSE) { Item* pItemRef = pMyExchangePetContainer->GetItem(i); ItemContainer* pMyPetContainer = pHuman->GetPetContain(); ExPetItemIndexInMy[ExPetItemNumMy].nIndex = pMyPetContainer->GetIndexByGUID(&pItemRef->GetPetGUID()); ExPetItemIndexInMy[ExPetItemNumMy].nIndexInEx = i; ExPetItemNumMy++; } if(pOtExchangePetContainer->GetItem(i)->IsEmpty() == FALSE) { Item* pItemRef = pOtExchangePetContainer->GetItem(i); ItemContainer* pOtPetContainer = pDestHuman->GetPetContain(); ExPetItemIndexInOt[ExPetItemNumOt].nIndex = pOtPetContainer->GetIndexByGUID(&pItemRef->GetPetGUID()); ExPetItemIndexInOt[ExPetItemNumOt].nIndexInEx = i; ExPetItemNumOt++; } } //3.1先把能交换的交换掉,如果在对方的包中找到了正在跟自己交易的物品,直接交换这两个物品的位置 for(INT i = 0; i<EXCHANGE_BOX_SIZE; i++) { if(pMyExchangeContainer->GetItem(i)->IsEmpty() == FALSE) { INT result = 0; Item* pItemRef = pMyExchangeContainer->GetItem(i); //自己的容器 ItemContainer* pMyBagContainer = HumanItemLogic::GetItemContain(pHuman, pItemRef->GetItemTableIndex()); INT BagIndex = pMyBagContainer->GetIndexByGUID(&pItemRef->GetGUID()); //对方的容器 ItemContainer* pOtBagContainer = HumanItemLogic::GetItemContain(pDestHuman, pItemRef->GetItemTableIndex()); //去换能换得 for(INT j = 0; j<ExItemNumOt; j++) { //此位置已经无效 if(ExItemIndexInOt[j].nIndex == -1) continue; //只有同一类型的物品才能够交换 if(pItemRef->GetItemClass()!=ExItemIndexInOt[j].uItemType) continue; //解锁自己 g_ItemOperator.UnlockItem( pMyBagContainer, BagIndex ); //先解锁对方 g_ItemOperator.UnlockItem( pOtBagContainer, ExItemIndexInOt[j].nIndex ); //设置自己物品已经不是交易物品了 pMyBagContainer->GetItem(BagIndex)->SetInExchange(FALSE); //设置对方物品已经不是交易物品了 pOtBagContainer->GetItem(ExItemIndexInOt[j].nIndex)->SetInExchange(FALSE); //与一个对方欲交易的物品交换 result = g_ItemOperator.ExchangeItem ( pMyBagContainer, BagIndex, pOtBagContainer, ExItemIndexInOt[j].nIndex ); if(result<0) {//拷贝失败 GCExchangeError Msg; Msg.SetID(EXCHANGE_MSG::ERR_ILLEGAL); pHuman->GetPlayer()->SendPacket(&Msg); pDestHuman->GetPlayer()->SendPacket(&Msg); pHuman->m_ExchangBox.CleanUp(); pDestHuman->m_ExchangBox.CleanUp(); g_pLog->FastSaveLog( LOG_FILE_1, " <交易> [%s] <-> [%s] 物品 [%d]失败 result = %d", pHuman->GetName(), pDestHuman->GetName(), pItemRef->GetItemTableIndex(), result ); return PACKET_EXE_CONTINUE; } else { ITEM_LOG_PARAM ItemLogParam; ItemLogParam.OpType = ITEM_EXCHANGE_TOOTHER; ItemLogParam.CharGUID = pHuman->GetGUID(); ItemLogParam.TargetGUID = pDestHuman->GetGUID(); ItemLogParam.XPos = pHuman->getWorldPos()->m_fX; ItemLogParam.ZPos = pHuman->getWorldPos()->m_fZ; ItemLogParam.SceneID = pHuman->getScene()->SceneID(); ItemLogParam.ItemGuid = pItemRef->GetGUID(); ItemLogParam.ItemType = pItemRef->GetItemTableIndex(); ItemListToOt[OtItemNum].m_FromType = 0; ItemListToOt[OtItemNum].m_FromIndex = i; ItemListToOt[OtItemNum].m_ToType = EXCHANGE_MSG::POS_BAG; ItemListToOt[OtItemNum++].m_ToIndex = pOtBagContainer->ConIndex2BagIndex(ExItemIndexInOt[j].nIndex); ItemListToMe[MyItemNum].m_FromType = 0; ItemListToMe[MyItemNum].m_FromIndex = ExItemIndexInOt[j].nIndexInEx; ItemListToMe[MyItemNum].m_ToType = EXCHANGE_MSG::POS_BAG; ItemListToMe[MyItemNum++].m_ToIndex = pMyBagContainer->ConIndex2BagIndex(BagIndex); //从交易盒中删掉此物品,在后面的移动中就不用再移动它了 g_ItemOperator.EraseItem(pMyExchangeContainer, i); g_ItemOperator.EraseItem(pOtExchangeContainer, ExItemIndexInOt[j].nIndexInEx); ExItemIndexInOt[j].nIndex = -1; g_pLog->FastSaveLog( LOG_FILE_1, " <交易> [%s] <-> [%s] 物品 [%d]成功", pHuman->GetName(), pDestHuman->GetName(), pItemRef->GetItemTableIndex() ); break; } } } } //3.2不能交换的一个一个放进去,剩下的直接由系统找格放入 for(INT i = 0; i<EXCHANGE_BOX_SIZE; i++) { if(pMyExchangeContainer->GetItem(i)->IsEmpty() == FALSE) { INT result = 0; Item* pItemRef = pMyExchangeContainer->GetItem(i); //自己的容器 ItemContainer* pMyBagContainer = HumanItemLogic::GetItemContain(pHuman, pItemRef->GetItemTableIndex()); INT BagIndex = pMyBagContainer->GetIndexByGUID(&pItemRef->GetGUID()); //对方的容器 ItemContainer* pOtBagContainer = HumanItemLogic::GetItemContain(pDestHuman, pItemRef->GetItemTableIndex()); //先解锁 g_ItemOperator.UnlockItem( pMyBagContainer, BagIndex ); pMyBagContainer->GetItem(BagIndex)->SetInExchange(FALSE); //自动找格,支持自动叠加 //这里的自动找格改成可以自动叠加,这里会有一个问题,上面收取检测时是不考虑叠加状态的,所以,如果非叠加状态下的 //可以收取一系列物品,可叠加的一定可以接受。检测的范围会大一点。 result = g_ItemOperator.MoveItem ( pMyBagContainer, BagIndex, bFlag, pOtBagContainer ); if(result<0) {//拷贝失败 GCExchangeError Msg; Msg.SetID(EXCHANGE_MSG::ERR_ILLEGAL); pHuman->GetPlayer()->SendPacket(&Msg); pDestHuman->GetPlayer()->SendPacket(&Msg); pHuman->m_ExchangBox.CleanUp(); pDestHuman->m_ExchangBox.CleanUp(); g_pLog->FastSaveLog( LOG_FILE_1, " <交易> [%s] -> [%s] 物品 [%d]失败 result = %d", pHuman->GetName(), pDestHuman->GetName(), pItemRef->GetItemTableIndex(), result ); return PACKET_EXE_CONTINUE; } else { ITEM_LOG_PARAM ItemLogParam; ItemLogParam.OpType = ITEM_EXCHANGE_TOOTHER; ItemLogParam.CharGUID = pHuman->GetGUID(); ItemLogParam.TargetGUID = pDestHuman->GetGUID(); ItemLogParam.XPos = pHuman->getWorldPos()->m_fX; ItemLogParam.ZPos = pHuman->getWorldPos()->m_fZ; ItemLogParam.SceneID = pHuman->getScene()->SceneID(); ItemLogParam.ItemGuid = pItemRef->GetGUID(); ItemLogParam.ItemType = pItemRef->GetItemTableIndex(); ItemListToOt[OtItemNum].m_FromType = 0; ItemListToOt[OtItemNum].m_FromIndex = i; ItemListToOt[OtItemNum].m_ToType = EXCHANGE_MSG::POS_BAG; ItemListToOt[OtItemNum++].m_ToIndex = pOtBagContainer->ConIndex2BagIndex(result); g_pLog->FastSaveLog( LOG_FILE_1, " <交易> [%s] -> [%s] 物品 [%d]成功", pHuman->GetName(), pDestHuman->GetName(), pItemRef->GetItemTableIndex() ); } } if(pOtExchangeContainer->GetItem(i)->IsEmpty() == FALSE) { INT result = 0; Item* pItemRef = pOtExchangeContainer->GetItem(i); //对方的容器 ItemContainer* pOtBagContainer = HumanItemLogic::GetItemContain(pDestHuman, pItemRef->GetItemTableIndex()); INT BagIndex = pOtBagContainer->GetIndexByGUID(&pItemRef->GetGUID()); //自己的容器 ItemContainer* pMyBagContainer = HumanItemLogic::GetItemContain(pHuman, pItemRef->GetItemTableIndex()); //先解锁 g_ItemOperator.UnlockItem( pOtBagContainer, BagIndex ); pOtBagContainer->GetItem(BagIndex)->SetInExchange(FALSE); //自动找格,支持自动叠加 result = g_ItemOperator.MoveItem ( pOtBagContainer, BagIndex, bFlag, pMyBagContainer ); if(result<0) {//拷贝失败 GCExchangeError Msg; Msg.SetID(EXCHANGE_MSG::ERR_ILLEGAL); pHuman->GetPlayer()->SendPacket(&Msg); pDestHuman->GetPlayer()->SendPacket(&Msg); pHuman->m_ExchangBox.CleanUp(); pDestHuman->m_ExchangBox.CleanUp(); g_pLog->FastSaveLog( LOG_FILE_1, " <交易> [%s] -> [%s] 物品 [%d]失败 result = %d", pDestHuman->GetName(), pHuman->GetName(), pItemRef->GetItemTableIndex(), result ); return PACKET_EXE_CONTINUE; } else { ITEM_LOG_PARAM ItemLogParam; ItemLogParam.OpType = ITEM_EXCHANGE_TOOTHER; ItemLogParam.CharGUID = pDestHuman->GetGUID(); ItemLogParam.TargetGUID = pHuman->GetGUID(); ItemLogParam.XPos = pDestHuman->getWorldPos()->m_fX; ItemLogParam.ZPos = pDestHuman->getWorldPos()->m_fZ; ItemLogParam.SceneID = pDestHuman->getScene()->SceneID(); ItemLogParam.ItemGuid = pItemRef->GetGUID(); ItemLogParam.ItemType = pItemRef->GetItemTableIndex(); SaveItemLog(&ItemLogParam); ItemListToMe[MyItemNum].m_FromType = 0; ItemListToMe[MyItemNum].m_FromIndex = i; ItemListToMe[MyItemNum].m_ToType = EXCHANGE_MSG::POS_BAG; ItemListToMe[MyItemNum++].m_ToIndex = pMyBagContainer->ConIndex2BagIndex(result); g_pLog->FastSaveLog( LOG_FILE_1, " <交易> [%s] -> [%s] 物品 [%d]成功", pDestHuman->GetName(), pHuman->GetName(), pItemRef->GetItemTableIndex() ); } } } //3.3换宠物 g_pLog->FastSaveLog( LOG_FILE_1, "<交易> [%s] 与 [%s] 开始交换宠物", pHuman->GetName(), pDestHuman->GetName()) ; for(INT i = 0; i<EXCHANGE_PET_BOX_SIZE; i++) { INT result = 0; Item* pItemRef = pMyExchangePetContainer->GetItem(i); if(pItemRef->IsEmpty()) continue; PET_LOG_PARAM PetLogParam; PetLogParam.PetGUID = pItemRef->GetPetGUID(); PetLogParam.DataID = pItemRef->GetDataID(); //自己的容器 ItemContainer* pMyPetContainer = pHuman->GetPetContain(); INT PetIndexInBag = pMyPetContainer->GetIndexByGUID(&pItemRef->GetPetGUID()); //对方的容器 ItemContainer* pOtPetContainer = pDestHuman->GetPetContain(); //去换能换得 for(INT j = 0; j<ExPetItemNumOt; j++) { //如果无效 if(ExPetItemIndexInOt[j].nIndex == -1) continue; //解锁自己 g_ItemOperator.UnlockItem( pMyPetContainer, PetIndexInBag ); //先解锁对方 g_ItemOperator.UnlockItem( pOtPetContainer, ExPetItemIndexInOt[j].nIndex ); //设置自己物品已经不是交易物品了 pMyPetContainer->GetItem(PetIndexInBag)->SetInExchange(FALSE); //设置对方物品已经不是交易物品了 pOtPetContainer->GetItem(ExPetItemIndexInOt[j].nIndex )->SetInExchange(FALSE); //与一个对方欲交易的物品交换 result = g_ItemOperator.ExchangeItem ( pMyPetContainer, PetIndexInBag, pOtPetContainer, ExPetItemIndexInOt[j].nIndex ); if(result<0) {//拷贝失败 GCExchangeError Msg; Msg.SetID(EXCHANGE_MSG::ERR_ILLEGAL); pHuman->GetPlayer()->SendPacket(&Msg); pDestHuman->GetPlayer()->SendPacket(&Msg); pHuman->m_ExchangBox.CleanUp(); pDestHuman->m_ExchangBox.CleanUp(); g_pLog->FastSaveLog( LOG_FILE_1, " <交易> [%s] <-> [%s] 物品 [%d]失败 result = %d", pHuman->GetName(), pDestHuman->GetName(), pItemRef->GetItemTableIndex(), result ); return PACKET_EXE_CONTINUE; } else { PetLogParam.CharGUID = pDestHuman->GetGUID(); PetLogParam.OPType = PET_OP_EXCHANGE_OTHER; PetLogParam.SceneID = pDestHuman->getScene()->SceneID(); PetLogParam.TargetGUID = pHuman->GetGUID(); PetLogParam.XPos = pDestHuman->getWorldPos()->m_fX; PetLogParam.ZPos = pDestHuman->getWorldPos()->m_fZ; SavePetLog(&PetLogParam); ItemListToMe[MyItemNum].m_FromType = EXCHANGE_MSG::POS_PET; ItemListToMe[MyItemNum].m_FromIndex = ExPetItemIndexInOt[j].nIndexInEx; ItemListToMe[MyItemNum].m_ToType = EXCHANGE_MSG::POS_PET; ItemListToMe[MyItemNum++].m_ToIndex = PetIndexInBag; ItemListToOt[OtItemNum].m_FromType = EXCHANGE_MSG::POS_PET; ItemListToOt[OtItemNum].m_FromIndex = i; ItemListToOt[OtItemNum].m_ToType = EXCHANGE_MSG::POS_PET; ItemListToOt[OtItemNum++].m_ToIndex = ExPetItemIndexInOt[j].nIndex; //从交易盒中删掉此物品,在后面的移动中就不用再移动它了 g_ItemOperator.EraseItem(pMyExchangePetContainer, i); g_ItemOperator.EraseItem(pOtExchangePetContainer, ExPetItemIndexInOt[j].nIndexInEx); ExPetItemIndexInOt[j].nIndex = -1; g_pLog->FastSaveLog( LOG_FILE_1, " <交易> [%s] <-> [%s] 物品 [%s]成功", pHuman->GetName(), pDestHuman->GetName(), pItemRef->GetName() ); break; } } } //3.4移宠物 for(INT i = 0; i<EXCHANGE_PET_BOX_SIZE; i++) { if(pMyExchangePetContainer->GetItem(i)->IsEmpty() == FALSE) { INT result = 0; Item* pItemRef = pMyExchangePetContainer->GetItem(i); PET_LOG_PARAM PetLogParam; PetLogParam.PetGUID = pItemRef->GetPetGUID(); PetLogParam.DataID = pItemRef->GetDataID(); //自己的容器 ItemContainer* pMyPetContainer = pHuman->GetPetContain(); INT PetIndexInBag = pMyPetContainer->GetIndexByGUID(&pItemRef->GetPetGUID()); //对方的容器 ItemContainer* pOtPetContainer = pDestHuman->GetPetContain(); //先解锁 g_ItemOperator.UnlockItem( pMyPetContainer, PetIndexInBag ); pMyPetContainer->GetItem(PetIndexInBag)->SetInExchange(FALSE); //自动找格,支持自动叠加 //这里的自动找格改成可以自动叠加,这里会有一个问题,上面收取检测时是不考虑叠加状态的,所以,如果非叠加状态下的 //可以收取一系列物品,可叠加的一定可以接受。检测的范围会大一点。 result = g_ItemOperator.MoveItem ( pMyPetContainer, PetIndexInBag, pOtPetContainer ); if(result<0) {//拷贝失败 GCExchangeError Msg; Msg.SetID(EXCHANGE_MSG::ERR_ILLEGAL); pHuman->GetPlayer()->SendPacket(&Msg); pDestHuman->GetPlayer()->SendPacket(&Msg); pHuman->m_ExchangBox.CleanUp(); pDestHuman->m_ExchangBox.CleanUp(); g_pLog->FastSaveLog( LOG_FILE_1, " <交易> [%s] -> [%s] 宠物 [%s]失败 result = %d", pHuman->GetName(), pDestHuman->GetName(), pItemRef->GetName(), result ); return PACKET_EXE_CONTINUE; } else { PetLogParam.CharGUID = pDestHuman->GetGUID(); PetLogParam.OPType = PET_OP_EXCHANGE_OTHER; PetLogParam.SceneID = pDestHuman->getScene()->SceneID(); PetLogParam.TargetGUID = pHuman->GetGUID(); PetLogParam.XPos = pDestHuman->getWorldPos()->m_fX; PetLogParam.ZPos = pDestHuman->getWorldPos()->m_fZ; SavePetLog(&PetLogParam); ItemListToOt[OtItemNum].m_FromType = EXCHANGE_MSG::POS_PET; ItemListToOt[OtItemNum].m_FromIndex = i; ItemListToOt[OtItemNum].m_ToType = EXCHANGE_MSG::POS_PET; ItemListToOt[OtItemNum++].m_ToIndex = result; g_pLog->FastSaveLog( LOG_FILE_1, " <交易> [%s] -> [%s] 宠物 [%s]成功", pHuman->GetName(), pDestHuman->GetName(), pItemRef->GetName() ); } } if(pOtExchangePetContainer->GetItem(i)->IsEmpty() == FALSE) { INT result = 0; Item* pItemRef = pOtExchangePetContainer->GetItem(i); PET_LOG_PARAM PetLogParam; PetLogParam.PetGUID = pItemRef->GetPetGUID(); PetLogParam.DataID = pItemRef->GetDataID(); //对方的容器 ItemContainer* pOtPetContainer = pDestHuman->GetPetContain(); INT PetIndexInBag = pOtPetContainer->GetIndexByGUID(&pItemRef->GetPetGUID()); //自己的容器 ItemContainer* pMyPetContainer = pHuman->GetPetContain(); //先解锁 g_ItemOperator.UnlockItem( pOtPetContainer, PetIndexInBag ); pOtPetContainer->GetItem(PetIndexInBag)->SetInExchange(FALSE); //自动找格,支持自动叠加 result = g_ItemOperator.MoveItem ( pOtPetContainer, PetIndexInBag, pMyPetContainer ); if(result<0) {//拷贝失败 GCExchangeError Msg; Msg.SetID(EXCHANGE_MSG::ERR_ILLEGAL); pHuman->GetPlayer()->SendPacket(&Msg); pDestHuman->GetPlayer()->SendPacket(&Msg); pHuman->m_ExchangBox.CleanUp(); pDestHuman->m_ExchangBox.CleanUp(); g_pLog->FastSaveLog( LOG_FILE_1, " <交易> [%s] -> [%s] 宠物 [%s]失败 result = %d", pDestHuman->GetName(), pHuman->GetName(), pItemRef->GetName(), result ); return PACKET_EXE_CONTINUE; } else { PetLogParam.CharGUID = pHuman->GetGUID(); PetLogParam.OPType = PET_OP_EXCHANGE_OTHER; PetLogParam.SceneID = pHuman->getScene()->SceneID(); PetLogParam.TargetGUID = pDestHuman->GetGUID(); PetLogParam.XPos = pHuman->getWorldPos()->m_fX; PetLogParam.ZPos = pHuman->getWorldPos()->m_fZ; SavePetLog(&PetLogParam); ItemListToMe[MyItemNum].m_FromType = EXCHANGE_MSG::POS_PET; ItemListToMe[MyItemNum].m_FromIndex = i; ItemListToMe[MyItemNum].m_ToType = EXCHANGE_MSG::POS_PET; ItemListToMe[MyItemNum++].m_ToIndex = result; g_pLog->FastSaveLog( LOG_FILE_1, " <交易> [%s] -> [%s] 宠物 [%s]成功", pDestHuman->GetName(), pHuman->GetName(), pItemRef->GetName() ); } } } //2.换钱 g_pLog->FastSaveLog( LOG_FILE_1, "<交易> [%s] 与 [%s] 开始交换金钱", pHuman->GetName(), pDestHuman->GetName()) ; if( pHuman->m_ExchangBox.m_Money <= pHuman->GetMoney() && pHuman->m_ExchangBox.m_Money>0 ) { pDestHuman->SetMoney(pDestHuman->GetMoney()+pHuman->m_ExchangBox.m_Money); pHuman->SetMoney(pHuman->GetMoney()-pHuman->m_ExchangBox.m_Money); MONEY_LOG_PARAM MoneyLogParam; MoneyLogParam.CharGUID = pHuman->GetGUID(); MoneyLogParam.TargetGUID = pDestHuman->GetGUID(); MoneyLogParam.OPType = MONEY_EXCHANGE_OUTCOME; MoneyLogParam.Count = pHuman->m_ExchangBox.m_Money; MoneyLogParam.SceneID = pHuman->getScene()->SceneID(); MoneyLogParam.XPos = pHuman->getWorldPos()->m_fX; MoneyLogParam.ZPos = pHuman->getWorldPos()->m_fZ; SaveMoneyLog(&MoneyLogParam); MoneyLogParam.CharGUID = pDestHuman->GetGUID(); MoneyLogParam.TargetGUID = pHuman->GetGUID(); MoneyLogParam.OPType = MONEY_EXCHANGE_INCOME; MoneyLogParam.Count = pHuman->m_ExchangBox.m_Money; MoneyLogParam.SceneID = pDestHuman->getScene()->SceneID(); MoneyLogParam.XPos = pDestHuman->getWorldPos()->m_fX; MoneyLogParam.ZPos = pDestHuman->getWorldPos()->m_fZ; SaveMoneyLog(&MoneyLogParam); g_pLog->FastSaveLog( LOG_FILE_1, " <交易> [%s] -> [%s] 金钱 [%d]", pHuman->GetName(), pDestHuman->GetName(), pHuman->m_ExchangBox.m_Money ); } if( pDestHuman->m_ExchangBox.m_Money <= pDestHuman->GetMoney() && pDestHuman->m_ExchangBox.m_Money>0 ) { pHuman->SetMoney(pHuman->GetMoney()+pDestHuman->m_ExchangBox.m_Money); pDestHuman->SetMoney(pDestHuman->GetMoney() - pDestHuman->m_ExchangBox.m_Money); MONEY_LOG_PARAM MoneyLogParam; MoneyLogParam.CharGUID = pHuman->GetGUID(); MoneyLogParam.TargetGUID = pDestHuman->GetGUID(); MoneyLogParam.OPType = MONEY_EXCHANGE_INCOME; MoneyLogParam.Count = pDestHuman->m_ExchangBox.m_Money; MoneyLogParam.SceneID = pHuman->getScene()->SceneID(); MoneyLogParam.XPos = pHuman->getWorldPos()->m_fX; MoneyLogParam.ZPos = pHuman->getWorldPos()->m_fZ; SaveMoneyLog(&MoneyLogParam); MoneyLogParam.CharGUID = pDestHuman->GetGUID(); MoneyLogParam.TargetGUID = pHuman->GetGUID(); MoneyLogParam.OPType = MONEY_EXCHANGE_OUTCOME; MoneyLogParam.Count = pDestHuman->m_ExchangBox.m_Money; MoneyLogParam.SceneID = pDestHuman->getScene()->SceneID(); MoneyLogParam.XPos = pDestHuman->getWorldPos()->m_fX; MoneyLogParam.ZPos = pDestHuman->getWorldPos()->m_fZ; SaveMoneyLog(&MoneyLogParam); g_pLog->FastSaveLog( LOG_FILE_1, " <交易> [%s] -> [%s] 金钱 [%d]", pDestHuman->GetName(), pHuman->GetName(), pDestHuman->m_ExchangBox.m_Money ); } //给双方发送成功消息 MsgSuccessToMe.SetItemNum(MyItemNum); MsgSuccessToMe.SetItemList(ItemListToMe); pHuman->GetPlayer()->SendPacket(&MsgSuccessToMe); MsgSuccessToOt.SetItemNum(OtItemNum); MsgSuccessToOt.SetItemList(ItemListToOt); pDestHuman->GetPlayer()->SendPacket(&MsgSuccessToOt); g_pLog->FastSaveLog( LOG_FILE_1, "<交易> [%s] 与 [%s] 交易成功", pHuman->GetName(), pDestHuman->GetName()) ; //能走到这儿证明所有操作都已完成清空各自的交易盒 pHuman->m_ExchangBox.CleanUp(); pDestHuman->m_ExchangBox.CleanUp(); } else {//啥也不做,等待对方消息 } } else {//一定出错了 GCExchangeError Msg; Msg.SetID(EXCHANGE_MSG::ERR_ILLEGAL); pHuman->GetPlayer()->SendPacket(&Msg); pHuman->m_ExchangBox.CleanUp(); pDestHuman->GetPlayer()->SendPacket(&Msg); pDestHuman->m_ExchangBox.CleanUp(); return PACKET_EXE_CONTINUE; } return PACKET_EXE_CONTINUE ; __LEAVE_FUNCTION return PACKET_EXE_ERROR ; }
uint CGCharAskEquipmentHandler::Execute( CGCharAskEquipment* 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 ) ; ObjID_t ObjID = pPacket->getObjID(); if( ObjID == INVALID_ID ) { Assert(FALSE) ; return PACKET_EXE_ERROR ; } Obj* pObj = pScene->GetObjManager()->GetObj( ObjID ) ; if( pObj==NULL ) { g_pLog->FastSaveLog( LOG_FILE_1, "CGCharAskEquipmentHandler: not find obj=%d", ObjID ) ; return PACKET_EXE_CONTINUE ; } if( !IsCharacterObj( pObj->GetObjType() ) ) { g_pLog->FastSaveLog( LOG_FILE_1, "CGCharAskEquipmentHandler: not character obj=%d", ObjID ) ; return PACKET_EXE_CONTINUE ; } Obj_Character* pCharacter = (Obj_Character*)pObj ; GCCharEquipment Msg; Msg.setObjID(pCharacter->GetID()); if ( pCharacter->GetObjType() == Obj::OBJ_TYPE_HUMAN ) { Obj_Human* pDest = (Obj_Human*)pCharacter ; if(pDest->GetEquipID(HEQUIP_WEAPON)> 0) { Msg.setWeaponID(pDest->GetEquipID(HEQUIP_WEAPON)); UINT uGemID = GetEquipmentMaxLevelGemID(pDest->GetEquipContain()->GetItem(HEQUIP_WEAPON)); Msg.setWeaponGemID(uGemID); } if(pDest->GetEquipID(HEQUIP_BOOT)>0) { Msg.setBootID(pDest->GetEquipID(HEQUIP_BOOT)); UINT uGemID = GetEquipmentMaxLevelGemID(pDest->GetEquipContain()->GetItem(HEQUIP_BOOT)); Msg.setBootGemID(uGemID); } if(pDest->GetEquipID(HEQUIP_CUFF)>0) { Msg.setCuffID(pDest->GetEquipID(HEQUIP_CUFF)); UINT uGemID = GetEquipmentMaxLevelGemID(pDest->GetEquipContain()->GetItem(HEQUIP_CUFF)); Msg.setCuffGemID(uGemID); } if(pDest->GetEquipID(HEQUIP_CAP)>0) { Msg.setCapID(pDest->GetEquipID(HEQUIP_CAP)); UINT uGemID = GetEquipmentMaxLevelGemID(pDest->GetEquipContain()->GetItem(HEQUIP_CAP)); Msg.setCapGemID(uGemID); } if(pDest->GetEquipID(HEQUIP_ARMOR)>0) { Msg.setArmourID(pDest->GetEquipID(HEQUIP_ARMOR)); UINT uGemID = GetEquipmentMaxLevelGemID(pDest->GetEquipContain()->GetItem(HEQUIP_ARMOR)); Msg.setArmourGemID(uGemID); } pGamePlayer->SendPacket( &Msg ) ; } g_pLog->FastSaveLog( LOG_FILE_1, "CGCharAskEquipmentHandler: ok obj=%d scene=%d", ObjID, pScene->SceneID() ) ; return PACKET_EXE_CONTINUE ; __LEAVE_FUNCTION return PACKET_EXE_ERROR ; }
BOOL Obj_Pet::Init( const _OBJ_INIT *pInit ) { __ENTER_FUNCTION BOOL bResult = Obj_Character::Init( pInit ); if ( !bResult ) return FALSE; const _OBJ_PET_INIT *pPetInit = NULL; pPetInit = (const _OBJ_PET_INIT*)pInit; if ( pPetInit == NULL ) { Assert( FALSE && "Error Obj_Pet::Init, pPetInit = NULL" ); return FALSE; } m_GUID = pPetInit->m_GUID; m_CreatorID = pPetInit->m_CreatorID; m_pCreator = NULL; m_nIndex = pPetInit->m_nIndex; m_ScriptID = pPetInit->m_ScriptID ; if ( m_CreatorID != INVALID_ID ) { Obj_Character *pCreator = (Obj_Character*)(getScene()->GetObjManager()->GetObj(m_CreatorID) ); if (pCreator != NULL && pCreator->GetObjType() == OBJ_TYPE_HUMAN) m_pCreator = (Obj_Human*)pCreator; } if ( m_pCreator == NULL ) m_PetDB = pPetInit->m_PetDB; m_RespawnTime = pPetInit->m_RespawnTime; m_RespawnPos = pPetInit->m_Pos; m_OwnerID = pPetInit->m_CreatorID; //m_nCampType = INVALID_CAMP; m_HappinessTimer.BeginTimer( g_Config.m_ConfigInfo.m_PetHappinessInterval, g_pTimeManager->CurrentTime() ); m_LifeTimer.BeginTimer( g_Config.m_ConfigInfo.m_PetLifeInterval, g_pTimeManager->CurrentTime() ); // 如果招呼者有效则将该宠物所有的技能缓存起来 if (m_pCreator) { Item* pPetItem = m_pCreator->GetPetItem(GetPetGUID()); Assert(pPetItem); // 设置AI类型 SetAIType(pPetItem->GetAIType() ); for (INT i = 0; i < PET_MAX_SKILL_COUNT; ++i) { PushSkillToCache(pPetItem->GetSkill(i).m_nSkillID); } //if( m_pCreator->GetCampData() ) //{ // if( m_pCreator->GetCampData()->m_nCampID == CAMP_1 ) // m_nCampType = CAMP1_PET; // else if( m_pCreator->GetCampData()->m_nCampID == CAMP_2 ) // m_nCampType = CAMP2_PET; //} } else {// 在pet初始化的时候就生成宠物的所有属性(只有没有主人的宠物第一次生成时才构造所有属性) getScene()->GetPetManager()->MakeCapturePetAttrib(&m_PetDB); SetDataID(m_PetDB.m_nDataID); // 可能产生了变异,模型可能会改变 } // 使AI进入IDLE状态 GetAIObj()->ChangeState(ESTATE_IDLE); InitBackupAttr(); //附加效果数据 Impact_InitList(); return TRUE; __LEAVE_FUNCTION return FALSE; }
BOOL SkillCore_T::ActiveSkillNow(Obj_Character& rMe) const { __ENTER_FUNCTION SkillInfo_T& rSkillInfo = rMe.GetSkillInfo(); TargetingAndDepletingParams_T& rParams = rMe.GetTargetingAndDepletingParams(); if(FALSE==rMe.IsAlive()||FALSE==rMe.IsActiveObj()) { rParams.SetErrCode(OR_DIE); return FALSE; } rSkillInfo.Init(); if(FALSE==InstanceSkill(rSkillInfo, rMe, rParams.GetActivatedSkill(), rParams.GetSkillLevel())) { rParams.SetErrCode(OR_INVALID_SKILL); rParams.SetErrParam(rParams.GetActivatedSkill()); return FALSE; } //refix skill instance rMe.RefixSkill(rSkillInfo); //perform checking INT nLogicID = rSkillInfo.GetLogicID(); SkillLogic_T const* pLogic = g_SkillLogicList.GetLogicById(nLogicID); if(NULL==pLogic) { rParams.SetErrCode(OR_INVALID_SKILL); rParams.SetErrParam(rParams.GetActivatedSkill()); return FALSE; } if(TRUE == pLogic->IsPassive()) { AssertEx(FALSE,"[SkillCore_T::HeartBeat]: Found passive Skill!!!Data error!!"); rParams.SetErrCode(OR_ERROR); return FALSE; } if(TRUE == pLogic->CancelSkillEffect(rMe)) { rParams.SetErrCode(OR_OK); return TRUE; } //Prefix end if(FALSE==rMe.Skill_IsSkillCooldowned(rParams.GetActivatedSkill())&& FALSE==rParams.GetIgnoreConditionCheckFlag()) { rParams.SetErrCode(OR_COOL_DOWNING); return FALSE; } if(TRUE == rSkillInfo.GetMustUseWeaponFlag()) { if(Obj::OBJ_TYPE_HUMAN==rMe.GetObjType()) { Obj_Human* pHuman = (Obj_Human*)&rMe; Item* pItem=HumanItemLogic::GetEquip(pHuman, HEQUIP_WEAPON); if(NULL==pItem) { rParams.SetErrCode(OR_NEED_A_WEAPON); return FALSE; } else if(TRUE==pItem->IsEmpty()) { rParams.SetErrCode(OR_NEED_A_WEAPON); return FALSE; } } } if(FALSE==rParams.GetIgnoreConditionCheckFlag()) { if(FALSE == pLogic->IsConditionSatisfied(rMe)) { return FALSE; } if(FALSE==pLogic->SpecificOperationOnSkillStart(rMe)) { return FALSE; } } switch (rSkillInfo.GetSkillType()) { case SKILL_INSTANT_LAUNCHING: pLogic->StartLaunching(rMe); break; case SKILL_NEED_CHARGING: pLogic->StartCharging(rMe); break; case SKILL_NEED_CHANNELING: pLogic->StartChanneling(rMe); break; default: AssertEx(FALSE,"[SkillCore_T::ActiveSkillNow]: Try to active a un-active skill!"); break; } return TRUE; __LEAVE_FUNCTION return FALSE ; }
BOOL CombatCore_T::GetResultImpact(Obj_Character& rAttacker, Obj_Character& rDefencer, OWN_IMPACT& rImp) { __ENTER_FUNCTION INT nDamage = 0; INT nMaxDamage = 0; INT nSpecialEffectID = DAMAGE_SPECIAL_EFFECT_NEAR; //Init DI_DamagesByValue_T logic; if(INVALID_ID==rImp.GetDataIndex()) { g_ImpactCore.InitImpactFromData(IMP_DAMAGES_OF_ATTACKS, rImp, rAttacker); } else if(logic.ID!=Impact_GetLogicID(rImp) && DI_DamagesByRate_T::ID!=Impact_GetLogicID(rImp) ) { g_ImpactCore.InitImpactFromData(IMP_DAMAGES_OF_ATTACKS, rImp, rAttacker); } m_nAdditionalAttackNear += logic.GetDamageNear(rImp); m_nAdditionalAttackFar += logic.GetDamageFar(rImp); m_nAdditionalAttackMagicNear+= logic.GetDamageMagicNear(rImp); m_nAdditionalAttackMagicFar += logic.GetDamageMagicFar(rImp); m_nAdditionalAttackGold += logic.GetDamageGold(rImp); m_nAdditionalAttackWood += logic.GetDamageWood(rImp); m_nAdditionalAttackWater += logic.GetDamageWater(rImp); m_nAdditionalAttackFire += logic.GetDamageFire(rImp); m_nAdditionalAttackSoil += logic.GetDamageSoil(rImp); //Damage fluctuation INT nFluctuation = g_Config.m_ConfigInfo.m_nDefaultDamageFluctuation; MenPaiID_t nMenPai = 9; MenPai_Module::MenPai_T const* pMenPai = NULL; if(Obj::OBJ_TYPE_HUMAN==rAttacker.GetObjType()) { Obj_Human& rHuman = (Obj_Human&)rAttacker; nMenPai = rHuman.GetMenPai(); pMenPai = g_MenPaiLogicList.GetLogicById(nMenPai); if(NULL!=pMenPai) { nFluctuation=pMenPai->GetAttackFluctuation(); } } Scene* pScene = rAttacker.getScene(); // calculate the fluctuation INT nRand=50; if(NULL!=pScene) { nRand -= pScene->GetRand100(); } nFluctuation = Float2Int((2*nFluctuation*nRand)/100.0f); //Calculate Damages //Near nDamage = NearDamage(rAttacker, rDefencer, m_nAdditionalAttackNear, m_nAdditionalDefenceNear); // Refix damage with fluctuation nDamage = nDamage + nDamage*nFluctuation/100; logicDamages.SetDamageNear(rImp, nDamage); nMaxDamage = nDamage; nSpecialEffectID = DAMAGE_SPECIAL_EFFECT_NEAR; //Far nDamage = FarDamage(rAttacker, rDefencer, m_nAdditionalAttackFar, m_nAdditionalDefenceFar); // Refix damage with fluctuation nDamage = nDamage + nDamage*nFluctuation/100; logicDamages.SetDamageFar(rImp, nDamage); if(nMaxDamage<nDamage) { nMaxDamage = nDamage; nSpecialEffectID = DAMAGE_SPECIAL_EFFECT_FAR; } //近程内功 nDamage = MagicalNearDamage(rAttacker, rDefencer, m_nAdditionalAttackMagicNear, m_nAdditionalDefenceMagicNear); // Refix damage with fluctuation nDamage = nDamage + nDamage*nFluctuation/100; logicDamages.SetDamageMagicNear(rImp, nDamage); if(nMaxDamage<nDamage) { nMaxDamage = nDamage; nSpecialEffectID = DAMAGE_SPECIAL_EFFECT_MAGIC_NEAR; } //近程外功 nDamage = MagicalFarDamage(rAttacker, rDefencer, m_nAdditionalAttackMagicFar, m_nAdditionalDefenceMagicFar); // Refix damage with fluctuation nDamage = nDamage + nDamage*nFluctuation/100; logicDamages.SetDamageMagicFar(rImp, nDamage); if(nMaxDamage<nDamage) { nMaxDamage = nDamage; nSpecialEffectID = DAMAGE_SPECIAL_EFFECT_MAGIC_FAR; } //Gold nDamage = GoldDamage(rAttacker, rDefencer, m_nAdditionalAttackGold, m_nAdditionalDefenceGold); // Refix damage with fluctuation nDamage = nDamage + nDamage*nFluctuation/100; logicDamages.SetDamageGold(rImp, nDamage); if(nMaxDamage<nDamage) { nMaxDamage = nDamage; nSpecialEffectID = DAMAGE_SPECIAL_EFFECT_GOLD; } //Wood nDamage = WoodDamage(rAttacker, rDefencer, m_nAdditionalAttackWood, m_nAdditionalDefenceWood); // Refix damage with fluctuation nDamage = nDamage + nDamage*nFluctuation/100; logicDamages.SetDamageWood(rImp, nDamage); if(nMaxDamage<nDamage) { nMaxDamage = nDamage; nSpecialEffectID = DAMAGE_SPECIAL_EFFECT_WOOD; } //Water nDamage = WaterDamage(rAttacker, rDefencer, m_nAdditionalAttackWater, m_nAdditionalDefenceWater); // Refix damage with fluctuation nDamage = nDamage + nDamage*nFluctuation/100; logicDamages.SetDamageWater(rImp, nDamage); if(nMaxDamage<nDamage) { nMaxDamage = nDamage; nSpecialEffectID = DAMAGE_SPECIAL_EFFECT_WATER; } //Fire nDamage = FireDamage(rAttacker, rDefencer, m_nAdditionalAttackFire, m_nAdditionalDefenceFire); // Refix damage with fluctuation nDamage = nDamage + nDamage*nFluctuation/100; logicDamages.SetDamageFire(rImp, nDamage); if(nMaxDamage<nDamage) { nMaxDamage = nDamage; nSpecialEffectID = DAMAGE_SPECIAL_EFFECT_FIRE; } //Soil nDamage = SoilDamage(rAttacker, rDefencer, m_nAdditionalAttackSoil, m_nAdditionalDefenceSoil); // Refix damage with fluctuation nDamage = nDamage + nDamage*nFluctuation/100; logicDamages.SetDamageSoil(rImp, nDamage); if(nMaxDamage<nDamage) { nMaxDamage = nDamage; nSpecialEffectID = DAMAGE_SPECIAL_EFFECT_SOIL; } rImp.SetImpactID(nSpecialEffectID); return TRUE; __LEAVE_FUNCTION return FALSE; }
BOOL CommonSkill001_T::OnCancel(Obj_Character& rMe) const { __ENTER_FUNCTION SkillInfo_T& rSkillInfo = rMe.GetSkillInfo(); TargetingAndDepletingParams_T& rParams = rMe.GetTargetingAndDepletingParams(); Obj_Character* pTar = (Obj_Character*)(GetTargetObj(rMe)); if(NULL==pTar) { rParams.SetErrCode(OR_INVALID_TARGET); return FALSE; } if(NULL==pTar || FALSE==pTar->IsAlive() || FALSE == pTar->IsActiveObj() || Obj::OBJ_TYPE_PET != pTar->GetObjType()) { rParams.SetErrCode(OR_INVALID_TARGET); return FALSE; } GCManipulatePetRet msg; msg.SetGUID(((Obj_Human*)&rMe)->GetGUIDOfCallUpPet()); msg.SetFightingFlag(FALSE); msg.SetManipulateRet(GCManipulatePetRet::MANIPULATEPET_RET_CALLUPFALID); ((Obj_Human*)&rMe)->GetPlayer()->SendPacket(&msg); // 减少该宠物身上的捕获玩家数 ((Obj_Horse*)pTar)->DelCapturer(rMe.GetID()); return TRUE; __LEAVE_FUNCTION return FALSE; }
BOOL Obj_Pet::Init( const _OBJ_INIT *pInit ) { __ENTER_FUNCTION BOOL bResult = Obj_Character::Init( pInit ); if ( !bResult ) return FALSE; const _OBJ_PET_INIT *pPetInit = NULL; pPetInit = (const _OBJ_PET_INIT*)pInit; if ( pPetInit == NULL ) { Assert( FALSE && "Error Obj_Pet::Init, pPetInit = NULL" ); return FALSE; } m_GUID = pPetInit->m_GUID; m_CreatorID = pPetInit->m_CreatorID; m_pCreator = NULL; m_nIndex = pPetInit->m_nIndex; m_iLevel = pPetInit->m_PetDB.m_nLevel; if ( m_CreatorID != INVALID_ID ) { Obj_Character *pCreator = (Obj_Character*)(getScene()->GetObjManager()->GetObj(m_CreatorID) ); if (pCreator != NULL && pCreator->GetObjType() == OBJ_TYPE_HUMAN) m_pCreator = (Obj_Human*)pCreator; } if ( m_pCreator == NULL ) { m_PetDB = pPetInit->m_PetDB; return FALSE; } m_PetDB.m_nDataID = pPetInit->m_PetDB.m_nDataID; m_RespawnTime = pPetInit->m_RespawnTime; m_RespawnPos = pPetInit->m_Pos; m_OwnerID = pPetInit->m_CreatorID; m_HappinessTimer.BeginTimer( g_Config.m_ConfigInfo.m_PetHappinessInterval, g_pTimeManager->CurrentTime() ); SetDataID( m_pCreator->GetMonsterPetDataID() ); MONSTER_EXT_ATTR *pPetAttr = g_MonsterAttrExTbl.GetExtAttr( GetDataID() ); if(pPetAttr) { m_iLevel = pPetAttr->m_Level; } else { m_iLevel = 0; } PetManager* pPetManager = getScene()->GetPetManager(); if(pPetManager) { m_oInit = pPetManager->GetInitData(); } //初始化技能相关内容 InitLife(); SetHP( GetMaxHP() ); // 使AI进入IDLE状态 GetAIObj()->ChangeState(ESTATE_IDLE); InitBackupAttr(); //附加效果数据 Impact_InitList(); return TRUE; __LEAVE_FUNCTION return FALSE; }
uint CGAskSkillClassHandler::Execute( CGAskSkillClass* 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 ) ; ObjID_t ObjID = pHuman->GetID(); if( ObjID == INVALID_ID ) { Assert(FALSE) ; return PACKET_EXE_ERROR ; } Obj_Character *pTarget = (Obj_Character*)(pScene->GetObjManager()->GetObj(pPacket->getTargetID())); if( pTarget==NULL ) { Assert( pTarget ) ; return PACKET_EXE_ERROR ; } // 权限判断 // to be continue... if ( pTarget->GetObjType() != Obj::OBJ_TYPE_HUMAN && pTarget->GetObjType() != Obj::OBJ_TYPE_PET ) { g_pLog->FastSaveLog( LOG_FILE_1, "CGAskSkillClassHandler: faile obj=%d scene=%d", ObjID, pScene->SceneID() ) ; return PACKET_EXE_CONTINUE; } _XINFA_DB_LOAD XinFa; XinFa.m_Count = 0; INT nID, nScaned; for( nID = 0, nScaned = 0; nID < g_XinFaDataMgr.MAXSIZE && nScaned < g_XinFaDataMgr.Size(); ) { Combat_Module::Skill_Module::XinFaData_T const* pXinFaData = g_XinFaDataMgr.GetInstanceByID(nID); if( pXinFaData != NULL ) { nScaned ++; if( pHuman->GetMenPai() == pXinFaData->GetMenPai() ) { XinFa.m_aXinFa[XinFa.m_Count].m_nXinFaID = nID; XinFa.m_aXinFa[XinFa.m_Count].m_nXinFaLevel = 1; XinFa.m_Count ++; } if( XinFa.m_Count >= 3 ) break; } nID ++; } GCSkillClass Msg; Msg.setObjID( pTarget->GetID() ); Msg.setXinFaList(XinFa.m_Count, XinFa.m_aXinFa); pGamePlayer->SendPacket( &Msg ) ; g_pLog->FastSaveLog( LOG_FILE_1, "CGAskSkillClassHandler: ok obj=%d scene=%d", ObjID, pScene->SceneID() ) ; return PACKET_EXE_CONTINUE ; __LEAVE_FUNCTION return PACKET_EXE_ERROR ; }