コード例 #1
0
uint CGStallApplyHandler::Execute( CGStallApply* 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->__IsPasswordProtect(MINORPASSWD_INFO::PROTECT_STALL))
	{
		if (!pHuman->__IsPasswordUnlock())
		{
			g_pLog->FastSaveLog( LOG_FILE_1, "ERROR: ObjID=%d  Password lock", pHuman->GetID()) ;
			return PACKET_EXE_CONTINUE ;
		}
	}
	
	//交易状态不可操作
	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 ;
	}

	//获得本地税率
	UINT	PosTax		= 0;
	BYTE	TradeTax	= 0;
	GCStallApply	Msg;

	//验证是否有资格摆摊
	if(pHuman->GetLevel()<30)
	{
		g_pLog->FastSaveLog( LOG_FILE_1, "ERROR: CGStallApplyHandler::ObjID=%d level = %d ", pHuman->GetID(), pHuman->GetLevel()) ;
		return PACKET_EXE_CONTINUE ;
	}
	if(pHuman->m_ExchangBox.m_Status >= ServerExchangeBox::EXCHANGE_SYNCH_DATA)
	{
		g_pLog->FastSaveLog( LOG_FILE_1, "ERROR: CGStallApplyHandler::ExchangBox.m_Status >= ServerExchangeBox::EXCHANGE_SYNCH_DATA ") ;
		return PACKET_EXE_CONTINUE ;
	}

	//摆摊地点判断
	StallInfoManager* pStallInfoMgr = pScene->GetStallInfoManager();
	if(pStallInfoMgr)
	{
		UINT PosX = (UINT)pHuman->getWorldPos()->m_fX;
		UINT PosZ = (UINT)pHuman->getWorldPos()->m_fZ;
		BOOL bCanStall = pStallInfoMgr->CanStall(PosX, PosZ);
		if(bCanStall == FALSE)
		{
			Msg.SetIsCanStall(FALSE);
		}
		else
		{
			PosTax		= pStallInfoMgr->StallPosPayment(PosX, PosZ);
			TradeTax	= pStallInfoMgr->StallExchangeTax(PosX, PosZ);

			pHuman->m_StallBox.CleanUp();
			pHuman->m_StallBox.SetStallStatus(ServerStallBox::STALL_READY);
			pHuman->m_StallBox.GetBBS()->LoadTitle();

			Msg.SetIsCanStall(TRUE);
			Msg.SetPosTax(PosTax);
			Msg.SetTradeTax(TradeTax);
		}
	}

	//验证完毕,通知客户端确定
	pGamePlayer->SendPacket(&Msg);

	g_pLog->FastSaveLog( LOG_FILE_1, "CGStallApplyHandler::ObjID=%d ", pHuman->GetID()) ;
	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 ;
}