ORESULT AbilityInlay::OnProcOver(Obj_Human* pHuman) { __ENTER_FUNCTION Assert( pHuman ); ORESULT res; res = CanUseAbility(pHuman); // 以免过程中某些状态发生变化 if( res != OR_OK ) { return res; } AbilityOpera* pAbilityOpera; pAbilityOpera = pHuman->GetAbilityOpera(); Assert( pAbilityOpera ); BYTE GemBagIndex = pAbilityOpera->m_BagPos[0]; BYTE EquipBagIndex = pAbilityOpera->m_BagPos[1]; CHAR MaterialBagIndex1 = (CHAR)pAbilityOpera->m_BagPos[2]; CHAR MaterialBagIndex2 = (CHAR)pAbilityOpera->m_BagPos[3]; Item* pGemItem = HumanItemLogic::GetBagItem( pHuman, GemBagIndex ); Item* pEquipItem = HumanItemLogic::GetBagItem( pHuman, EquipBagIndex ); Item* pMaterialItem1 = NULL; Item* pMaterialItem2 = NULL; if( MaterialBagIndex1 != -1 ) { pMaterialItem1 = HumanItemLogic::GetBagItem( pHuman, MaterialBagIndex1 ); Assert(pMaterialItem1 != NULL); } if( MaterialBagIndex2 != -1 ) { pMaterialItem2 = HumanItemLogic::GetBagItem( pHuman, MaterialBagIndex2 ); Assert(pMaterialItem1 != NULL); } Assert( (pGemItem != NULL) && (pEquipItem != NULL) ); UINT GemIndex = pGemItem->GetItemTableIndex(); UINT EquipIndex = pEquipItem->GetItemTableIndex(); INT MaterialIndex1 = -1; INT MaterialIndex2 = -1; if( pMaterialItem1 ) { MaterialIndex1 = pMaterialItem1->GetItemTableIndex(); //if(pMaterialItem1) // pMaterialItem1->SetItemParam( 0, IPV_INT, INT( EquipBagIndex ) );//modi:lby20071114记录当前装备的id } if( pMaterialItem2 ) { MaterialIndex2 = pMaterialItem2->GetItemTableIndex(); //if(pMaterialItem2) //pMaterialItem2->SetItemParam( 0, IPV_INT, INT( EquipBagIndex ) );//modi:lby20071114记录当前装备的id } if( (pGemItem->IsLock()) || (pEquipItem->IsLock()) || (pGemItem->IsPWLock()) || (pEquipItem->IsPWLock()) ) { // 这里判断是否锁定,下面消耗时就不再判断了 return OR_STUFF_LACK; } if( pMaterialItem1 ) { if( pMaterialItem1->IsLock() || pMaterialItem1->IsPWLock() ) return OR_STUFF_LACK; } if( pMaterialItem2 ) { if( pMaterialItem2->IsLock() || pMaterialItem2->IsPWLock() ) return OR_STUFF_LACK; } EmbedResult flag; LuaInterface* pLuaInterface; pLuaInterface = pHuman->getScene()->GetLuaInterface(); // 脚本判断是否镶嵌成功,如果成功则主动加上熟练度 // 否则返回失败情况 flag = (EmbedResult)pLuaInterface->ExeScript_DDDDDD(ABILITY_LOGIC_SCRIPT, DEF_GEM_EMBED_PROCESS, (INT)pHuman->getScene()->SceneID(), (INT)pHuman->GetID(), (INT)EquipBagIndex, (INT)GemIndex, (INT)MaterialIndex1, (INT)MaterialIndex2 ) ; GCDiscardItemResult Msg; Msg.setResult( DISCARDITEM_SUCCESS ); GamePlayer* pGamePlayer = (GamePlayer*)(pHuman->GetPlayer()); ITEM_LOG_PARAM ItemLogParam; ItemLogParam.OpType = ITEM_INLAY_LOST; BOOL bRet = FALSE; switch(flag) { case EMBED_SUCCESS: { if( MaterialIndex1 != -1 ) { bRet = HumanItemLogic::EraseBagItem(&ItemLogParam,pHuman,MaterialBagIndex1); if(bRet) SaveItemLog(&ItemLogParam); } if( MaterialIndex2 != -1 ) { bRet = HumanItemLogic::EraseBagItem(&ItemLogParam,pHuman,MaterialBagIndex2); if(bRet) SaveItemLog(&ItemLogParam); } INT nRet ;//= pHuman->UseGem(GemBagIndex, EquipBagIndex); if(USEGEM_SUCCESS == nRet) { g_ImpactCore.SendImpactToUnit(*pHuman, 49, pHuman->GetID()); } return OnProcSuccess(pHuman); } case GEM_GONE: if( MaterialIndex1 != -1 ) { bRet = HumanItemLogic::EraseBagItem(&ItemLogParam,pHuman,GemBagIndex); if(bRet) SaveItemLog(&ItemLogParam); } if( MaterialIndex2 != -1 ) { bRet = HumanItemLogic::EraseBagItem(&ItemLogParam,pHuman,MaterialBagIndex2); if(bRet) SaveItemLog(&ItemLogParam); } bRet = HumanItemLogic::EraseBagItem(&ItemLogParam,pHuman,GemBagIndex); if(bRet) SaveItemLog(&ItemLogParam); Msg.setItemTableIndex( GemIndex ); Msg.setBagIndex( GemBagIndex ); pGamePlayer->SendPacket( &Msg ); return OR_FAILURE; case EQUIP_GONE: if( MaterialIndex1 != -1 ) { bRet = HumanItemLogic::EraseBagItem(&ItemLogParam,pHuman,EquipBagIndex); if(bRet) SaveItemLog(&ItemLogParam); } if( MaterialIndex2 != -1 ) { bRet = HumanItemLogic::EraseBagItem(&ItemLogParam,pHuman,MaterialBagIndex2); if(bRet) SaveItemLog(&ItemLogParam); } bRet = HumanItemLogic::EraseBagItem(&ItemLogParam,pHuman,EquipBagIndex); if(bRet) SaveItemLog(&ItemLogParam); Msg.setItemTableIndex( EquipIndex ); Msg.setBagIndex( EquipBagIndex ); pGamePlayer->SendPacket( &Msg ); return OR_FAILURE; case BOTH_GONE: if( MaterialIndex1 != -1 ) { bRet = HumanItemLogic::EraseBagItem(&ItemLogParam,pHuman,EquipBagIndex); if(bRet) SaveItemLog(&ItemLogParam); } if( MaterialIndex2 != -1 ) { bRet = HumanItemLogic::EraseBagItem(&ItemLogParam,pHuman,GemBagIndex); if(bRet) SaveItemLog(&ItemLogParam); } bRet = HumanItemLogic::EraseBagItem(&ItemLogParam,pHuman,EquipBagIndex); if(bRet) SaveItemLog(&ItemLogParam); bRet = HumanItemLogic::EraseBagItem(&ItemLogParam,pHuman,GemBagIndex); if(bRet) SaveItemLog(&ItemLogParam); Msg.setItemTableIndex( GemIndex ); Msg.setBagIndex( GemBagIndex ); pGamePlayer->SendPacket( &Msg ); Msg.setItemTableIndex( EquipIndex ); Msg.setBagIndex( EquipBagIndex ); pGamePlayer->SendPacket( &Msg ); return OR_FAILURE; case ENERGY_NOT_ENOUGH: return OR_NOT_ENOUGH_ENERGY; case GEM_DEGRADE_1: { if( MaterialIndex1 != -1 ) { bRet = HumanItemLogic::EraseBagItem(&ItemLogParam,pHuman,MaterialBagIndex1); if(bRet) SaveItemLog(&ItemLogParam); } if( MaterialIndex2 != -1 ) { bRet = HumanItemLogic::EraseBagItem(&ItemLogParam,pHuman,MaterialBagIndex2); if(bRet) SaveItemLog(&ItemLogParam); } bRet = HumanItemLogic::EraseBagItem(&ItemLogParam,pHuman,GemBagIndex); if(bRet) SaveItemLog(&ItemLogParam); _ITEM_TYPE type = ConvertSerial2ItemType(GemIndex); /* if(type.m_Quality>1) { type.m_Quality--; ITEM_LOG_PARAM ItemLogParam; ItemLogParam.OpType = ITEM_CREATE_REMOVE_GEM; ItemLogParam.CharGUID = pHuman->GetGUID(); ItemLogParam.SceneID = pHuman->getScene()->SceneID(); ItemLogParam.XPos = pHuman->getWorldPos()->m_fX; ItemLogParam.ZPos = pHuman->getWorldPos()->m_fZ; UINT GemBagIndex_Temp = GemBagIndex; HumanItemLogic::CreateItemToBag(&ItemLogParam,pHuman,type.ToSerial(),GemBagIndex_Temp,ITEM_DROP_MONSTER); }*/ Msg.setItemTableIndex( GemIndex ); Msg.setBagIndex( GemBagIndex ); pGamePlayer->SendPacket( &Msg ); } return OR_FAILURE; case GEM_DEGRADE_2: { if( MaterialIndex1 != -1 ) { bRet = HumanItemLogic::EraseBagItem(&ItemLogParam,pHuman,MaterialBagIndex1); if(bRet) SaveItemLog(&ItemLogParam); } if( MaterialIndex2 != -1 ) { bRet = HumanItemLogic::EraseBagItem(&ItemLogParam,pHuman,MaterialBagIndex2); if(bRet) SaveItemLog(&ItemLogParam); } bRet = HumanItemLogic::EraseBagItem(&ItemLogParam,pHuman,GemBagIndex); if(bRet) SaveItemLog(&ItemLogParam); _ITEM_TYPE type = ConvertSerial2ItemType(GemIndex); /*if(type.m_Quality>2) { type.m_Quality -= 2; ITEM_LOG_PARAM ItemLogParam; ItemLogParam.OpType = ITEM_CREATE_REMOVE_GEM; ItemLogParam.CharGUID = pHuman->GetGUID(); ItemLogParam.SceneID = pHuman->getScene()->SceneID(); ItemLogParam.XPos = pHuman->getWorldPos()->m_fX; ItemLogParam.ZPos = pHuman->getWorldPos()->m_fZ; UINT GemBagIndex_Temp = GemBagIndex; HumanItemLogic::CreateItemToBag(&ItemLogParam,pHuman,type.ToSerial(),GemBagIndex_Temp,ITEM_DROP_MONSTER); }*/ Msg.setItemTableIndex( GemIndex ); Msg.setBagIndex( GemBagIndex ); pGamePlayer->SendPacket( &Msg ); } return OR_FAILURE; case GEM_DEGRADE_3: { if( MaterialIndex1 != -1 ) { bRet = HumanItemLogic::EraseBagItem(&ItemLogParam,pHuman,MaterialBagIndex1); if(bRet) SaveItemLog(&ItemLogParam); } if( MaterialIndex2 != -1 ) { bRet = HumanItemLogic::EraseBagItem(&ItemLogParam,pHuman,MaterialBagIndex2); if(bRet) SaveItemLog(&ItemLogParam); } bRet = HumanItemLogic::EraseBagItem(&ItemLogParam,pHuman,GemBagIndex); if(bRet) SaveItemLog(&ItemLogParam); _ITEM_TYPE type = ConvertSerial2ItemType(GemIndex); /*if(type.m_Quality>3) { type.m_Quality -= 3; ITEM_LOG_PARAM ItemLogParam; ItemLogParam.OpType = ITEM_CREATE_REMOVE_GEM; ItemLogParam.CharGUID = pHuman->GetGUID(); ItemLogParam.SceneID = pHuman->getScene()->SceneID(); ItemLogParam.XPos = pHuman->getWorldPos()->m_fX; ItemLogParam.ZPos = pHuman->getWorldPos()->m_fZ; UINT GemBagIndex_Temp = GemBagIndex; HumanItemLogic::CreateItemToBag(&ItemLogParam,pHuman,type.ToSerial(),GemBagIndex_Temp,ITEM_DROP_MONSTER); }*/ Msg.setItemTableIndex( GemIndex ); Msg.setBagIndex( GemBagIndex ); pGamePlayer->SendPacket( &Msg ); } return OR_FAILURE; default: Assert(FALSE); return OR_ERROR; } __LEAVE_FUNCTION return OR_ERROR; }
ORESULT AbilityMachining::OnProcSuccess(Obj_Human* pHuman) { __ENTER_FUNCTION Assert( pHuman ); AbilityOpera* pAbilityOpera; pAbilityOpera = pHuman->GetAbilityOpera(); Assert( pAbilityOpera ); LuaInterface* pLuaInterface; pLuaInterface = pHuman->getScene()->GetLuaInterface(); GamePlayer* pGamePlayer; pGamePlayer = (GamePlayer*)pHuman->GetPlayer(); Assert( pGamePlayer != NULL ); switch( pAbilityOpera->m_SubType ) { case NORMAL_TYPE: break; case GEM_COMPOUND: { _ITEM_TYPE GemType; UINT bi; ITEM_LOG_PARAM ItemLogParam; ItemLogParam.OpType = ITEM_CREATE_ABILITY_COMPOUD; ItemLogParam.CharGUID = pHuman->GetGUID(); ItemLogParam.SceneID = pHuman->getScene()->SceneID(); ItemLogParam.XPos = pHuman->getWorldPos()->m_fX; ItemLogParam.ZPos = pHuman->getWorldPos()->m_fZ; GemType = ConvertSerial2ItemType( pAbilityOpera->m_uItemIndex ); //GemType.m_Quality++; HumanItemLogic::CreateItemToBag(&ItemLogParam,pHuman,GemType.ToSerial(),bi); if(bi==INVALID_INDEX) //创建失败 { return OR_ERROR; } SaveItemLog(&ItemLogParam); GCNotifyEquip Msg; Msg.SetBagIndex( bi ); Item* pItem = HumanItemLogic::GetBagItem(pHuman,bi); Assert(pItem); pItem->SaveValueTo(Msg.GetItem()); pGamePlayer->SendPacket(&Msg); // 发送成功消息以及物品和状态变化 GCAbilitySucc SuccMsg; SuccMsg.SetAbilityID( EAN_GEM_COMPOUNDED ); SuccMsg.SetPrescriptionID( INVALID_ID ); SuccMsg.SetItemSerial( GemType.ToSerial() ); //SuccMsg.SetSuccFlag( TRUE ); pGamePlayer->SendPacket( &SuccMsg ); } break; case GEM_EMBED: // 不需要额外的处理了 { // 发送成功消息以及物品和状态变化 Item* pItem = HumanItemLogic::GetBagItem(pHuman, pAbilityOpera->m_BagPos[1]); Assert( pItem ); GCAbilitySucc SuccMsg; SuccMsg.SetAbilityID( EAN_GEM_EMBEDDED ); SuccMsg.SetPrescriptionID( INVALID_ID ); SuccMsg.SetItemSerial( pItem->GetItemTableIndex() ); //SuccMsg.SetSuccFlag( TRUE ); pGamePlayer->SendPacket( &SuccMsg ); } break; default: Assert(FALSE); return OR_ERROR; } // 判断一下熟练度是否足够升级了 pLuaInterface->ExeScript_DDD( ABILITY_LOGIC_SCRIPT, "CheckAbilityLevel", (INT)pHuman->getScene()->SceneID(), (INT)pHuman->GetID(), (INT)pAbilityOpera->m_AbilityID ) ; return OR_OK; __LEAVE_FUNCTION return OR_ERROR; }
uint CGShopSellHandler::Execute( CGShopSell* 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 m_nBagIndex = pPacket->GetBagIndex(); //包中的位置 UINT UniqueID = pPacket->GetUniqueID(); SceneID_t SceneID = UniqueID>>16; ObjID_t NpcObjID= UniqueID&0x00ff; if(SceneID != pScene->SceneID()) { g_pLog->FastSaveLog( LOG_FILE_1, "CGShopSellHandler Illegal scene ObjName = %s", pHuman->GetName()) ; return PACKET_EXE_CONTINUE ; } //距离判定 Obj* pNpcObj = (Obj*) (pScene->GetObjManager()->GetObj(NpcObjID)); if(pNpcObj == NULL) { g_pLog->FastSaveLog( LOG_FILE_1, "CGShopSellHandler Illegal Obj ObjName = %s", pHuman->GetName()) ; return PACKET_EXE_CONTINUE ; } FLOAT fDist = MySqrt(pNpcObj->getWorldPos(), pHuman->getWorldPos()); if(fDist>MAX_NPC_DISTANCE) { g_pLog->FastSaveLog( LOG_FILE_1, "CGShopSellHandler Out Of Range ObjName = %s", pHuman->GetName()) ; return PACKET_EXE_CONTINUE ; } Item* pCurrentItem = HumanItemLogic::GetItem(pHuman,m_nBagIndex); if(!pCurrentItem||ConvertSerial2ItemType(pCurrentItem->GetItemTableIndex()).isNull()) { //背包索引不存在 g_pLog->FastSaveLog( LOG_FILE_1, "ERROR:CGShopSellHandler m_nBagIndex=%d PlayerName=s%", m_nBagIndex, pHuman->GetName()) ; return PACKET_EXE_CONTINUE; } //判定这个商人是不是收购这个物品 _SHOP* pShop = pHuman->Shop( ) ; //商店不存在 if(!pShop) { g_pLog->FastSaveLog( LOG_FILE_1, "ERROR:CGShopSellHandler Npc Shop Lose"); return PACKET_EXE_CONTINUE; } //查询收购等级限制 if( pCurrentItem->GetItemClass() == ICLASS_EQUIP ) { if( pCurrentItem->GetRequireLevel() > pShop->m_nBuyLevel ) { return PACKET_EXE_CONTINUE; } } else { if( pCurrentItem->GetItemLevel() > pShop->m_nBuyLevel ) { return PACKET_EXE_CONTINUE; } } BOOL bCanBuy = TRUE; if(pShop->m_nBuyType != SHOP_All) { switch(pShop->m_nBuyType) { case SHOP_All: { } break; case SHOP_DEFENCE: //防具 { if( ICLASS_EQUIP == pCurrentItem->GetItemClass()) { if( pCurrentItem->GetEquipPoint() != HEQUIP_CAP && pCurrentItem->GetEquipPoint() != HEQUIP_ARMOR && pCurrentItem->GetEquipPoint() != HEQUIP_CUFF && pCurrentItem->GetEquipPoint() != HEQUIP_BOOT ) { bCanBuy = FALSE; } } else { bCanBuy = FALSE; } } break; case SHOP_ADORN: //饰物 { if( ICLASS_EQUIP == pCurrentItem->GetItemClass()) { if( pCurrentItem->GetEquipPoint() != HEQUIP_SASH && pCurrentItem->GetEquipPoint() != HEQUIP_RING && pCurrentItem->GetEquipPoint() != HEQUIP_NECKLACE && pCurrentItem->GetEquipPoint() != HEQUIP_RIDER) { bCanBuy = FALSE; } } else { bCanBuy = FALSE; } } break; case SHOP_WEAPON: //武器 { if( ICLASS_EQUIP == pCurrentItem->GetItemClass()) { if( pCurrentItem->GetEquipPoint() != HEQUIP_WEAPON ) { bCanBuy = FALSE; } } else { bCanBuy = FALSE; } } break; case SHOP_FOOD: //食物 { if( ICLASS_COMITEM != pCurrentItem->GetItemClass()) { bCanBuy = FALSE; } } break; case SHOP_MATERIAL: //材料 { if( ICLASS_MATERIAL != pCurrentItem->GetItemClass()) { bCanBuy = FALSE; } } break; case SHOP_COMITEM: //药品 { if( ICLASS_COMITEM != pCurrentItem->GetItemClass()) { bCanBuy = FALSE; } } break; default: { bCanBuy = FALSE; break; } } } //是否返回失败消息??? if(bCanBuy == FALSE) { return PACKET_EXE_CONTINUE; } INT iPrice = ShopMgr::ConvertItemType2Money(ConvertSerial2ItemType(pCurrentItem->GetItemTableIndex())); iPrice *= pCurrentItem->GetLayedNum(); //2006-4-21 //玩家向商店出售已经鉴定过的物品或者无需鉴定的物品按照基础价格*系数A(=1/3) 计算; //若出售未鉴定物品,价格应该更低,设此价格系数为B(=1/10),这个有待于调整,请在config中开放调整A,B的接口。 //耐久衰减系数D=当前耐久/最大耐久 //修理失败衰减次数F=1/(修理失败次数+1) //因此最终的出售价格为V=基础价格B*A*D*F //再乘以商店得价格比例 FLOAT fCur = 1; FLOAT fMax = 1; INT iFailTimes = 0; if(pCurrentItem->GetItemClass() == ICLASS_EQUIP) { fCur = (FLOAT)pCurrentItem->GetDurPoints(); fMax = (FLOAT)pCurrentItem->GetMaxDurPoint(); iFailTimes = pCurrentItem->GetFailTimes(); } if(pCurrentItem->GetItemIdent()) { iPrice = (INT)( ((FLOAT)iPrice/(FLOAT)3.0) * (fCur/fMax) * ((FLOAT)1/(FLOAT)(iFailTimes+1)) * (pShop->m_scale) ); } else { iPrice = (INT)( ((FLOAT)iPrice/(FLOAT)10.0) * (fCur/fMax) * ((FLOAT)1/(FLOAT)(iFailTimes+1)) * (pShop->m_scale) ); } //备份一下,一会儿放到购回列表里 _ITEM tempitem; pCurrentItem->SaveValueTo(&tempitem); //备份到回购列表中 pHuman->AddToSoldList(m_nBagIndex, iPrice); //给钱 pHuman->SetMoney( pHuman->GetMoney() + iPrice); MONEY_LOG_PARAM MoneyLogParam; MoneyLogParam.CharGUID = pHuman->GetGUID(); MoneyLogParam.OPType = MONEY_SHOP_SELL; MoneyLogParam.Count = iPrice; MoneyLogParam.SceneID = pHuman->getScene()->SceneID(); MoneyLogParam.XPos = pHuman->getWorldPos()->m_fX; MoneyLogParam.ZPos = pHuman->getWorldPos()->m_fZ; SaveMoneyLog(&MoneyLogParam); //把这个回购商品显示到界面 GCShopSoldList::_MERCHANDISE_ITEM SoldItem; SoldItem.item_data = tempitem; GCShopSoldList MsgSold; MsgSold.SetMerchadiseNum(1); MsgSold.SetMerchadiseList(&SoldItem); pHuman->GetPlayer()->SendPacket( &MsgSold ); GCShopSell MsgSell; pHuman->GetPlayer()->SendPacket( &MsgSell ); g_pLog->FastSaveLog( LOG_FILE_1, "CGShopSellHandler m_nBagIndex=%d ", m_nBagIndex ) ; return PACKET_EXE_CONTINUE; __LEAVE_FUNCTION return PACKET_EXE_ERROR ; }