コード例 #1
0
uint CGManipulatePetHandler::Execute( CGManipulatePet* pPacket, Player* pPlayer )
{
__ENTER_FUNCTION

	GamePlayer* pGamePlayer = (GamePlayer*)pPlayer ;
	Assert( pGamePlayer ) ;

	Obj_Human* pHuman = pGamePlayer->GetHuman() ;
	Assert( pHuman ) ;
	
	Scene* pScene = pHuman->getScene() ;
	if( pScene==NULL )
	{
		Assert(FALSE) ;
		return PACKET_EXE_ERROR ;
	}

	//检查线程执行资源是否正确
	Assert( MyGetCurrentThreadID()==pScene->m_ThreadID ) ;

	Item *pPetItem = pHuman->GetPetItem(pPacket->GetGUID());
	if(pPetItem == NULL)
		return PACKET_EXE_CONTINUE;

	if(pPetItem->IsLock())
	{
		return PACKET_EXE_CONTINUE;
	}

	INT nType = pPacket->GetManipulateType();
	switch(nType)
	{
	case MANIPULATE_CREATEPET:
		{// 召唤宠物
			ORESULT oResult = pHuman->TestCallUpPet(pPacket->GetGUID() );
			if( OR_SUCCEEDED(oResult) )
			{
				AI_Human* pHumanAI = (AI_Human*)(pHuman->GetAIObj());
				if (pHumanAI)
				{
					ObjID_t idSkill = CALL_UP_PET;
					oResult = pHumanAI->PushCommand_UseSkill(idSkill, 1, -1, -1.f, -1.f, 0.f, INVALID_GUID);
				}
			}
			if( OR_FAILED(oResult) )
			{
				GCManipulatePetRet msg;
				msg.SetManipulateRet(GCManipulatePetRet::MANIPULATEPET_RET_CALLUPFALID);
				pGamePlayer->SendPacket(&msg);

				pHuman->SendOperateResultMsg(oResult);
				return PACKET_EXE_CONTINUE;
			}

			pHuman->ReCallPet();
			pHuman->SetGUIDOfCallUpPet(pPacket->GetGUID());
		}
		break;
	case MANIPULATE_DELETEPET:
		{// 收回宠物
			ORESULT oResult = pHuman->ReCallPet();
			GCManipulatePetRet msg;
			if (OR_FAILED(oResult))
			{
				msg.SetManipulateRet(GCManipulatePetRet::MANIPULATEPET_RET_RECALLFALID);
			}
			else if (OR_SUCCEEDED(oResult))
			{
				msg.SetManipulateRet(GCManipulatePetRet::MANIPULATEPET_RET_RECALLSUCC);
			}
			pGamePlayer->SendPacket(&msg);
		}
		break;
	case MANIPULATE_FREEPET:
		{// 放生宠物
			PET_LOG_PARAM	PetLogParam;
			ORESULT oResult = pHuman->FreePetToNature(&PetLogParam,pPacket->GetGUID());
			GCManipulatePetRet msg;
			if (OR_FAILED(oResult))
			{
				msg.SetManipulateRet(GCManipulatePetRet::MANIPULATEPET_RET_FREEFALID);
			}
			else if (OR_SUCCEEDED(oResult))
			{
				msg.SetManipulateRet(GCManipulatePetRet::MANIPULATEPET_RET_FREESUCC);
			}
			pGamePlayer->SendPacket(&msg);
		}
		break;
	case MANIPULATE_ASKOTHERPETINFO:
		{// 察看其他玩家的宠物信息
			ObjID_t objID = pPacket->GetObjID();
			Obj* pObj = pScene->GetObjManager()->GetObj(objID);
			if (pObj && pObj->GetObjType() == Obj::OBJ_TYPE_PET)
			{
				Obj_Human* pCreator = ((Obj_Pet*)pObj)->GetCreator();
				if (pCreator)
				{
					PET_GUID_t guidpet = ((Obj_Pet*)pObj)->GetPetGUID();
					if(guidpet.IsNull())
					{
						return PACKET_EXE_CONTINUE;
					}
					Item* pPetItem = pCreator->GetPetItem(guidpet);
					if(!pPetItem) 
					{
						return PACKET_EXE_CONTINUE;
					}

					GCDetailAttrib_Pet msg;
					pCreator->CalculatePetDetailAttrib(msg, pPetItem);
					msg.SetExtraInfoLength(1);
					BYTE bFlag;
					bFlag = TYPE_CONTEX_MENU_OTHER_PET;
					msg.SetExtraInfoData(&bFlag);
					pHuman->GetPlayer()->SendPacket(&msg);
				}
				else
				{
					pHuman->SendOperateResultMsg(OR_CANNOT_ASK_PETDETIAL);
				}
			}
		}
		break;
	default:
		break;
	}
	return PACKET_EXE_CONTINUE ;

__LEAVE_FUNCTION

	return PACKET_EXE_ERROR ;
}
コード例 #2
0
uint CGStallEstablishHandler::Execute( CGStallEstablish* 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 ) ;

	// 通过AI判断当前状态下能否摆摊
	AI_Human* pAIHuman = (AI_Human*)(pHuman->GetAIObj());
	if (!pAIHuman) {
		return PACKET_EXE_ERROR;
	}

	ORESULT oResult = pAIHuman->PushCommand_Stall();
	if (OR_OK != oResult) {
		pHuman->SendOperateResultMsg(oResult);
		return PACKET_EXE_ERROR;
	}
	//验证是否有资格摆摊
	if(pHuman->m_StallBox.GetStallStatus() != ServerStallBox::STALL_READY)
	{
		GCStallError	Msg;
		Msg.SetID(STALL_MSG::ERR_ILLEGAL);
		pHuman->m_StallBox.CleanUp();
		pGamePlayer->SendPacket(&Msg);
		g_pLog->FastSaveLog( LOG_FILE_1, "ERROR: CGStallEstablishHandler::ObjID=%d, ERR_ILLEGAL:!= ServerStallBox::STALL_READY"
			,pHuman->GetID()) ;
		return PACKET_EXE_CONTINUE ;
	}
	
	UINT	PosTax		= 0;
	BYTE	TradeTax	= 0;
	StallInfoManager* pStallInfoMgr = pScene->GetStallInfoManager();
	if(pStallInfoMgr)
	{
		UINT PosX = (UINT)pHuman->getWorldPos()->m_fX;
		UINT PosZ = (UINT)pHuman->getWorldPos()->m_fZ;
		PosTax	  = pStallInfoMgr->StallPosPayment(PosX, PosZ);
		TradeTax  = pStallInfoMgr->StallExchangeTax(PosX, PosZ);

		if(pHuman->GetMoney() < PosTax)
		{
			GCStallError	Msg;
			Msg.SetID(STALL_MSG::ERR_NOT_ENOUGH_MONEY_TO_OPEN);
			pHuman->m_StallBox.CleanUp();
			pGamePlayer->SendPacket(&Msg);
			g_pLog->FastSaveLog( LOG_FILE_1, "ERROR: CGStallEstablishHandler::ObjID=%d, ERR_NOT_ENOUGH_MONEY_TO_OPEN"
				,pHuman->GetID()) ;
			return PACKET_EXE_CONTINUE ;
		}
		else
		{
			pHuman->SetMoney(pHuman->GetMoney() - PosTax);
			MONEY_LOG_PARAM	MoneyLogParam;
			MoneyLogParam.CharGUID	=	pHuman->GetGUID();
			MoneyLogParam.OPType	=	MONEY_EXCHANGE_STALL_TAX;	
			MoneyLogParam.Count		=	PosTax;
			MoneyLogParam.SceneID	=	pHuman->getScene()->SceneID();
			MoneyLogParam.XPos		=	pHuman->getWorldPos()->m_fX;
			MoneyLogParam.ZPos		=	pHuman->getWorldPos()->m_fZ;
			SaveMoneyLog(&MoneyLogParam);

		}

		//验证完毕,设置摊位盒
		pHuman->m_StallBox.SetStallStatus(ServerStallBox::STALL_OPEN);
		pHuman->m_StallBox.SetStallIsOpen(TRUE);//这个语句会引起客户端的显示更新
		pHuman->m_StallBox.SetPosTax(PosTax);
		pHuman->m_StallBox.SetTradeTax(TradeTax);
		//pHuman->m_StallBox.SetFirstPage(0);

		//占了这格,不准别人再摆摊了
		pStallInfoMgr->SetCanStall(PosX, PosZ, FALSE);
		pHuman->m_StallBox.SetStallPos(PosX, PosZ);

		//通知自己初始化自己的摊位盒
		GCStallEstablish Msg;
		pGamePlayer->SendPacket(&Msg);
		g_pLog->FastSaveLog( LOG_FILE_1, "CGStallEstablishHandler::ObjID=%d"
			,pHuman->GetID()) ;
	}
	else
	{
		Assert(0);
	}

		return PACKET_EXE_CONTINUE ;

	__LEAVE_FUNCTION

		return PACKET_EXE_ERROR ;
}