Пример #1
0
VOID CObject_Character::Initial( VOID* pParam )
{
	//AxProfile::AxProfile_PopNode("ObjInit");
	CObject_Phy::Initial(pParam);

	m_bAnimationEnd				= FALSE;
	m_uFightStateTime	= 0;

	SetCurrentLogicCommand(NULL);
	m_fLogic_Speed				= 1.f;

	SetMapPosition( fVector2( GetPosition().x, GetPosition().z ) );
	
	//创建逻辑信息
	m_pCharacterData = CDataPool::GetMe()->CharacterData_Create(this);

	//创建信息板
	//AxProfile::AxProfile_PushNode("ObjInit_CreateBoard");
	if(!GetFakeObjectFlag()&& CGameProcedure::s_pUISystem)
	{
		m_pInfoBoard = CGameProcedure::s_pUISystem->CreateCreatureBoard();
		m_pInfoBoard->SetElement_ObjId(this->GetServerID());

		m_pInfoBoard->SetElement_LeaderFlag(FALSE);
		m_pInfoBoard->SetElement_Name("");
		m_pInfoBoard->SetElement_SaleSign(FALSE);
		SetElement_Title("",_TITLE::NO_TITLE);
		m_pInfoBoard->Show(FALSE);
	}
	//AxProfile::AxProfile_PopNode("ObjInit_CreateBoard");

	m_uTime_LogicEventListTick	= CGameProcedure::s_pTimeSystem->GetTimeNow();

	Enable(OSF_VISIABLE);
	Disalbe(OSF_OUT_VISUAL_FIELD);

	m_bDropBox_HaveData			= FALSE;
	m_nDropBox_ItemBoxID		= INVALID_ID;
	m_DropBox_OwnerGUID			= INVALID_ID;
	m_posDropBox_CreatePos		= WORLD_POS(-1.f, -1.f);

	m_bHideWeapon = FALSE;
	UpdateCharRace();
	UpdateCharModel();
	UpdateMountModel();

	SObjectInit *pCharacterInit = (SObjectInit*)pParam;
	if ( pCharacterInit != NULL )
	{
		// 状态信息
		RemoveAllImpact();
		Start_Idle();
	}
}
Пример #2
0
BOOL CObject_Dynamic::DoMove( FLOAT fElapseTime, FLOAT fSpeed )
{
	const fVector3* pRrePos = GetPrevPathNode();
	if ( m_listPathNode.empty() )
		return FALSE;

	// 当前位置
	fVector3 fvCurPos = GetPosition();
	// 当前的目标路径点
	fVector3 fvBeginPathNode = (*m_listPathNode.begin());

	// 当前位置与当前的目标路径点的距离
	fVector3 fvDistToBeginPathNode = fvBeginPathNode - fvCurPos;
	FLOAT fDir = GetFaceDir();

	// 这一帧可移动的路径长度
	FLOAT fMoveDist = fSpeed * fElapseTime;
	FLOAT fMoveDistSq = fMoveDist * fMoveDist;

	// 当前位置与当前的目标路径点路径长度的平方
	FLOAT fDistToBeginPathNodeSq = fvDistToBeginPathNode.x * fvDistToBeginPathNode.x + fvDistToBeginPathNode.z * fvDistToBeginPathNode.z;

	// 如果这一帧可移动的路径长度小于当前位置到当前的目标路径点路径长度
	if ( fDistToBeginPathNodeSq > fMoveDistSq )
	{
		FLOAT fTarDist = sqrt(fDistToBeginPathNodeSq) ;
		FLOAT fDistX = (fMoveDist*(fvBeginPathNode.x-fvCurPos.x))/fTarDist ;
		FLOAT fDistZ = (fMoveDist*(fvBeginPathNode.z-fvCurPos.z))/fTarDist ;
		
		
		fVector2 fvPos;
		fvPos.x = fvCurPos.x + fDistX;
		fvPos.y = fvCurPos.z + fDistZ;
		
		//需要位置修正,防止因为误差走入阻挡区内部
		if( CObjectManager::GetMe()->GetMySelf() == this && CPath::IsPointInUnreachRegion(fvPos))
		{
			fvPos = TDU_GetReflect(
						fVector2(pRrePos->x, pRrePos->z),
						fVector2(fvBeginPathNode.x, fvBeginPathNode.z),
						fvPos);//

		}

		SetMapPosition( fvPos );
	}
	else
	{
		fVector2 fvPos;
		// 目标路径是最后一点
		if ( !NextPathNode() )
		{
			fvPos.x = fvBeginPathNode.x;
			fvPos.y = fvBeginPathNode.z;
			//需要位置修正,防止因为误差走入阻挡区内部
			if( CObjectManager::GetMe()->GetMySelf() == this && CPath::IsPointInUnreachRegion(fvPos))
			{
				//行走路线的镜像点, 点pRrePos 与 fvBeginPathNode不能是同一个点
				fvPos = TDU_GetReflect(
							fVector2(pRrePos->x, pRrePos->z),
							fVector2(fvBeginPathNode.x, fvBeginPathNode.z),
							fvPos);//
			}

			SetMapPosition( fvPos );
			OnMoveStop( );
		}
		else
		{
			FLOAT fDistToBeginPathNode = sqrt( fDistToBeginPathNodeSq );
			fMoveDist -= fDistToBeginPathNode;

			fvPos.x = fvBeginPathNode.x;
			fvPos.y = fvBeginPathNode.z;
			SetMapPosition( fvPos );
			CalcMoveDir();
			fDir = GetFaceDir();

			FLOAT fDistX = sin( fDir ) * fMoveDist;
			FLOAT fDistZ = cos( fDir ) * fMoveDist;
			fvCurPos = fvBeginPathNode;
			fvPos.x = fvCurPos.x + fDistX;
			fvPos.y = fvCurPos.z + fDistZ;
			
			//需要位置修正,防止因为误差走入阻挡区内部
			if( CObjectManager::GetMe()->GetMySelf() == this && CPath::IsPointInUnreachRegion(fvPos))
			{
				// 得到新的映射向量
				pRrePos = GetPrevPathNode();
				fvBeginPathNode = (*m_listPathNode.begin());

				//行走路线的镜像点, 点pRrePos 与 fvBeginPathNode不能是同一个点
				fvPos = TDU_GetReflect(
							fVector2(pRrePos->x, pRrePos->z),
							fVector2(fvBeginPathNode.x, fvBeginPathNode.z),
							fvPos);//

			}//
			
			SetMapPosition( fvPos );
		}

//		RegisterToZone();
	}
	return TRUE;
}
Пример #3
0
BOOL CObject_Bus::Tick_Move(UINT uElapseTime)
{
	FLOAT fElapseTime = (FLOAT)uElapseTime / 1000.f;
	FLOAT fMoveDist = fElapseTime * GetMoveSpeed();
	FLOAT fDist = KLU_GetDist(fVector3(GetPosition().x, 0.f, GetPosition().z), fVector3(m_fvMoveTargetPos.x, 0.f, m_fvMoveTargetPos.z));
	if(fMoveDist >= fDist)
	{
		if(m_fvMoveTargetPos.y <= DEF_BUS_PATH_NODE_INVALID_Y)
		{
			SetMapPosition(fVector2(m_fvMoveTargetPos.x, m_fvMoveTargetPos.z));
		}
		else
		{
			SetPosition(m_fvMoveTargetPos);
		}
		StopMove();
	}
	else
	{
		if(fDist > 0.f)
		{
			fVector3 fvThisPos = GetPosition();
			fVector3 fvLen = m_fvMoveTargetPos - fvThisPos;
			if(m_fvMoveTargetPos.y <= DEF_BUS_PATH_NODE_INVALID_Y)
			{
				fvThisPos.x += (fvLen.x/fDist) * fMoveDist;
				fvThisPos.z += (fvLen.z/fDist) * fMoveDist;
				SetMapPosition(fVector2(fvThisPos.x, fvThisPos.z));
			}
			else
			{
				fvThisPos.x += (fvLen.x/fDist) * fMoveDist;
				fvThisPos.y += (fvLen.y/fDist) * fMoveDist;
				fvThisPos.z += (fvLen.z/fDist) * fMoveDist;
				SetPosition(fvThisPos);
			}
		}
	}

	FLOAT fFaceDir = GetFaceDir();
	if(fabsf(m_fTargetDir - fFaceDir) > 0.01f)
	{
		if(fabsf(m_fTargetDir - fFaceDir) < __PI * 5.f / 4.f
			&& fabsf(m_fTargetDir - fFaceDir) > __PI * 3.f / 4.f)
		{
			SetFaceDir(m_fTargetDir);
		}
		else
		{
			FLOAT fElapseDir = fElapseTime * __PI;
			if(m_fTargetDir - fFaceDir > __PI
				|| (m_fTargetDir - fFaceDir < 0.f && m_fTargetDir - fFaceDir > -__PI))
			{// 正转
				fFaceDir -= fElapseDir;
				if(fFaceDir < 0.f)
				{
					fFaceDir += 2.f *__PI;
				}
				SetFaceDir(fFaceDir);
			}
			else
			{// 反转
				fFaceDir += fElapseDir;
				if(fFaceDir > m_fTargetDir)
				{
					fFaceDir = m_fTargetDir;
				}
				SetFaceDir(fFaceDir);
			}
		}
	}
	return TRUE;
}