Files
2026-06-01 12:46:52 +02:00

750 lines
16 KiB
C++

// SGameObject.cpp: implementation of the SGameObject class.
//
//////////////////////////////////////////////////////////////////////
#include "stdafx.h"
#include "SGameObject.h"
#include "SGameMessage.h"
#include "SGameWork.h"
float GetViewRadian( K3DVector tpos, K3DVector spos )
{
K3DVector viewVec = (tpos-spos);
viewVec.z = 0.f;
float fLen = viewVec.Magnitude();
float fDX = fabsf(viewVec.x);
float fDY = fabsf(viewVec.y);
float fTheta = ( fDX > fDY ) ? acosf( fDX / fLen ) : asinf( fDY / fLen );
if( fLen == 0.f )
return 0.f;
if( viewVec.x >= 0.f )
{ fTheta = (viewVec.y >= 0.f) ? fTheta : ((2.f * K3D_PI) - fTheta); }
else
{ fTheta = (viewVec.y >= 0.f) ? (K3D_PI - fTheta) : (K3D_PI + fTheta); }
return fTheta;
}
//////////////////////////////////////////////////////////////////////
// Construction/Destruction
//////////////////////////////////////////////////////////////////////
//Effect 받은 횟수
void SGameObject::EffectAddRef()
{
++m_nEffectRef;
}
void SGameObject::EffectDelRef()
{
// assert( m_nEffectRef > 0 && "Invalid EffectRef" );
if( m_nEffectRef <= 0 )
{
m_nEffectRef = 0;
return;
}
--m_nEffectRef;
}
SGameObject::SGameObject()
{
m_bIsActivated = false;
m_pArObject = NULL;
m_pMsgHandler = NULL;
K3DMatrixIdentity( m_mTransform );
m_fScale = 1.f;
m_bIsInit = false;
m_nEffectRef = 0;
m_wCurTile = 0;
m_bInWater = false;
}
SGameObject::~SGameObject()
{
Destroy();
}
bool SGameObject::Initialize()
{
return true;
}
void SGameObject::Destroy()
{
for( unsigned int i(0); m_vMsgList.size()>i; i++ )
{
delete m_vMsgList.front();
m_vMsgList.pop();
}
for( unsigned int i(0); m_vWorkList.size()>i; i++ )
{
delete m_vWorkList[i];
}
m_vWorkList.clear();
}
void SGameObject::SetKnockBack( const K3DVector vPosition, const float fSpeed )
{
if( m_pArObject ) //LocalPlayer 임
{
m_pArObject->onKnockBack( GetArID(), ArPosition( vPosition.x, vPosition.y, vPosition.z ), fSpeed );
}
else
{
m_arObject.mv.SetKnockBack( ArPosition( vPosition.x, vPosition.y, vPosition.z ), fSpeed, 0, 0 );
}
}
K3DVector * SGameObject::GetPosition()
{
if( m_pArObject ) //Local Player 임
{
m_mTransform._41 = m_pArObject->GetMyPos().x;
m_mTransform._42 = m_pArObject->GetMyPos().y;
}
else
{
m_mTransform._41 = GetArObject().mv.x;
m_mTransform._42 = GetArObject().mv.y;
}
return &m_mTransform.GetPosVector();
}
K3DVector* SGameObject::GetEndPosition()
{
if( m_pArObject ) //Local Player 임
{
m_mTransform._41 = m_pArObject->GetMyPos().GetTX();
m_mTransform._42 = m_pArObject->GetMyPos().GetTY();
}
else
{
m_mTransform._41 = GetArObject().mv.GetTX();
m_mTransform._42 = GetArObject().mv.GetTY();
}
return &m_mTransform.GetPosVector();
}
bool SGameObject::Activate()
{
m_bIsActivated = true;
return true;
}
bool SGameObject::Deactivate()
{
m_bIsActivated = false;
return true;
}
void SGameObject::SetArcadiaClient( ArcadiaClient * pArcadiaClient )
{
m_pArObject = pArcadiaClient;
}
void SGameObject::DropItem( AR_HANDLE handle )
{
if( m_pMsgHandler )
return m_pMsgHandler->DropItem( handle );
}
//게임 시스템 메세지 출력
void SGameObject::AddChatMessage( const char * pStr )
{
if( m_pMsgHandler )
return m_pMsgHandler->AddChatMessage( pStr );
}
// 게임내 공지 채팅만 출력, kappamind.
void SGameObject::AddNoticeMessageOnly( const char * pStr )
{
if( m_pMsgHandler )
return m_pMsgHandler->AddNoticeMessageOnly( pStr );
}
void SGameObject::RqChatting( int nChatType, const char * pName, const char * pStr )
{
if( m_pMsgHandler )
return m_pMsgHandler->RqChatting( nChatType, pName, pStr );
}
void SGameObject::GetNearVertices( float x, float y, K3DVertex* pGetVertices ) const
{
if ( m_pMsgHandler )
return m_pMsgHandler->GetNearVertices( x, y, pGetVertices );
}
void SGameObject::GetNearVertices( float x, float y, int cx, int cy, K3DVertex* pGetVertices ) const
{
if ( m_pMsgHandler )
return m_pMsgHandler->GetNearVertices( x, y, pGetVertices );
}
void SGameObject::GetTerrainTriangle( float x, float y, K3DVector& v1, K3DVector& v2, K3DVector& v3 ) const
{
if ( m_pMsgHandler )
m_pMsgHandler->GetTerrainTriangle( x, y, v1, v2, v3 );
}
bool SGameObject::GetHeight( const float x, const float y, float& out, WORD& wTile )
{
if ( m_pMsgHandler )
{
return m_pMsgHandler->GetHeight( x, y, out, wTile );
}
return false;
}
bool SGameObject::GetOnlyTerrainHeight( const float x, const float y, float& out )
{
if ( m_pMsgHandler )
{
return m_pMsgHandler->GetOnlyTerrainHeight( x, y, out );
}
return false;
}
void SGameObject::GetTerrainVisibleDistance( K3DVector & vCameraPos, float & fTerrainVisibleDist )
{
if ( m_pMsgHandler )
m_pMsgHandler->GetTerrainVisibleDistance( vCameraPos, fTerrainVisibleDist );
}
void SGameObject::SetMoveTargetPos( const float x, const float y, const float z, bool bChase )
{
if ( m_pMsgHandler )
m_pMsgHandler->SetMoveTargetPos( x, y, z, bChase );
}
bool SGameObject::IsBlockedAttribute( const float x, const float y )
{
if ( m_pMsgHandler )
return m_pMsgHandler->IsBlockedAttribute( x, y );
return false;
}
void SGameObject::Get2DPos( K3DVector & pos, K3DVector & _2Dpos )
{
if ( m_pMsgHandler )
m_pMsgHandler->Get2DPos( pos, _2Dpos );
}
SGameObject * SGameObject::GetGameObject( AR_HANDLE objHandle )
{
if ( m_pMsgHandler )
return m_pMsgHandler->GetGameObject( objHandle );
return NULL;
}
SGameObject * SGameObject::GetItemObject( K3DVector & pos, float & fDist, int nItemType, float fLimitDistance ) // sonador #2.1.2.4.3 팻 조작 UI 연동
{
if ( m_pMsgHandler )
return m_pMsgHandler->GetItemObject( pos, fDist, nItemType, fLimitDistance );
return NULL;
}
SGameObject * SGameObject::GetMobObject( K3DVector & pos )
{
if ( m_pMsgHandler )
return m_pMsgHandler->GetMobObject( pos );
return NULL;
}
SGameObject* SGameObject::GetGameTransportCreatureObject( AR_HANDLE objHandle )
{
if ( m_pMsgHandler )
return m_pMsgHandler->GetGameTransportCreatureObject( objHandle );
return NULL;
}
int SGameObject::GetItemClass()
{
return 0;
}
int SGameObject::GetMaterial() //재질
{
return 0;
}
int SGameObject::GetMovingType()
{
return 0;
}
bool SGameObject::GetGroundMaterial( int & nTile ) //지형 재질
{
nTile = m_wCurTile;
if( m_bInWater ) return true;
return false;
}
void SGameObject::PlayerInsideWaterExistence( K3DVector & vPlayerPosition, bool & bInWater )
{
if ( m_pMsgHandler ) m_pMsgHandler->PlayerInsideWaterExistence( vPlayerPosition, bInWater );
else bInWater = false;
}
int SGameObject::GetCurrentLocation()
{
if ( m_pMsgHandler )
return m_pMsgHandler->GetCurrentLocation();
return -1;
}
bool SGameObject::CheckPlayerMountLocation()
{
if ( m_pMsgHandler )
return m_pMsgHandler->CheckPlayerMountLocation();
return false;
}
int SGameObject::GetAttrCellLength()
{
if ( m_pMsgHandler )
return m_pMsgHandler->GetAttrCellLength();
return 1;
}
void SGameObject::WarpComplete( struct SGameMessage * pMsg )
{
if ( m_pMsgHandler )
return m_pMsgHandler->WarpComplete( pMsg );
}
void SGameObject::Rq_TakeItem( AR_HANDLE objHandle )
{
if ( m_pMsgHandler )
return m_pMsgHandler->Rq_TakeItem( objHandle );
}
void SGameObject::Rq_PutOnOffItem( AR_HANDLE hTarget, AR_HANDLE hItem, int nPosition )
{
if ( m_pMsgHandler )
return m_pMsgHandler->Rq_PutOnOffItem( hTarget, hItem, nPosition );
}
bool SGameObject::Rq_ChagePKMode( bool bOnOff )
{
if ( m_pMsgHandler )
return m_pMsgHandler->Rq_ChagePKMode( bOnOff );
return false;
}
void SGameObject::DelOwnerEffect( AR_HANDLE hOwner )
{
if ( m_pMsgHandler )
m_pMsgHandler->DelOwnerEffect( hOwner );
}
void SGameObject::DelEffect( int nEffectID )
{
if ( m_pMsgHandler )
m_pMsgHandler->DelEffect( nEffectID );
}
void SGameObject::AddAction( struct SGameMessage* pMsg )
{
if ( m_pMsgHandler )
return m_pMsgHandler->AddAction( pMsg );
}
void SGameObject::AddChaosEffect( int nChaosCnt ) // TODO : 서버에서 구현 완료되면 삭제하자
{
if ( m_pMsgHandler )
return m_pMsgHandler->AddChaosEffect( nChaosCnt );
}
int SGameObject::AddOtherEffect( int nFxID, struct OtherFxData* fxdata )
{
if ( m_pMsgHandler )
return m_pMsgHandler->AddOtherEffect( nFxID, fxdata );
return 0;
}
void SGameObject::EndOtherEffect( int nFxID )
{
if ( m_pMsgHandler ) m_pMsgHandler->EndOtherEffect( nFxID );
}
int SGameObject::AddEffect( FX_DATA * pFX_data )
{
if ( m_pMsgHandler )
return m_pMsgHandler->AddEffect( pFX_data );
assert( 0 && "메세지 핸들러 없음" );
return -1;
}
int SGameObject::AddEffect( struct FX_DATA_EX * pFX_data )
{
if ( m_pMsgHandler )
return m_pMsgHandler->AddEffect( pFX_data );
assert( 0 && "메세지 핸들러 없음" );
return -1; //존재 하지 않음.
}
int SGameObject::AddEffect( AR_HANDLE hAttacker, AR_HANDLE hTarget, AR_HANDLE hOwner, int nEffectID, int nEffectPos, bool bIsLoopFx )
{
if ( m_pMsgHandler )
return m_pMsgHandler->AddEffect( hAttacker, hTarget, hOwner, nEffectID, nEffectPos, bIsLoopFx );
assert( 0 && "메세지 핸들러 없음" );
return -1;
}
int SGameObject::AddAttackEffect( struct FX_DATA * pFX_data )
{
if ( m_pMsgHandler )
return m_pMsgHandler->AddAttackEffect( pFX_data );
assert( 0 && "메세지 핸들러 없음" );
return -1; //존재 하지 않음.
}
void SGameObject::EndLoopFx( int nEffectID )
{
if ( m_pMsgHandler )
return m_pMsgHandler->EndLoopFx( nEffectID );
assert( 0 && "메세지 핸들러 없음" );
}
void SGameObject::AddStateEffect( SGameMessage * pGameMsg )
{
if ( m_pMsgHandler )
return m_pMsgHandler->AddStateEffect( pGameMsg );
assert( 0 && "메세지 핸들러 없음" );
}
void SGameObject::UpdateStateEffect( SGameMessage * pGameMsg )
{
if ( m_pMsgHandler )
return m_pMsgHandler->UpdateStateEffect( pGameMsg );
assert( 0 && "메세지 핸들러 없음" );
}
void SGameObject::DelStateEffect( SGameMessage * pGameMsg )
{
if ( m_pMsgHandler )
return m_pMsgHandler->DelStateEffect( pGameMsg );
assert( 0 && "메세지 핸들러 없음" );
}
void SGameObject::DelStateEffect( int nDelObjType )
{
if ( m_pMsgHandler )
return m_pMsgHandler->DelStateEffect( nDelObjType );
assert( 0 && "메세지 핸들러 없음" );
}
bool SGameObject::UseSkill( AR_HANDLE caster, int nSkillId, int nSkill_Lv, AR_TIME cast_time )
{
if ( m_pMsgHandler ) return m_pMsgHandler->UseSkill( caster, nSkillId, nSkill_Lv, cast_time );
return false;
}
int SGameObject::StartSound( const char * pSoundName )
{
if ( m_pMsgHandler )
return m_pMsgHandler->StartSound( pSoundName );
return -1;
}
int SGameObject::StartSound( SGameAvatarEx* pCaster, const char * pSoundName, K3DVector pos, bool bUse3D, int nVolume, bool bLoop, bool bSoundOption[SOUND_OP_MAX] )
{
if ( m_pMsgHandler )
return m_pMsgHandler->StartSound( pCaster, pSoundName, pos, bUse3D, nVolume, bLoop, bSoundOption );
return -1;
}
int SGameObject::StartSound( const char * pSoundName, K3DVector pos )
{
if ( m_pMsgHandler )
return m_pMsgHandler->StartSound( pSoundName, pos );
return -1;
}
void SGameObject::StopSound( const char * pSoundName, int nPlayIdx )
{
if ( m_pMsgHandler )
return m_pMsgHandler->StopSound( pSoundName, nPlayIdx );
}
void SGameObject::OnSkillDamage( AR_HANDLE caster, AR_HANDLE target, struct SGameMessage* pDamage )
{
if ( m_pMsgHandler )
m_pMsgHandler->OnSkillDamage( caster, target, pDamage );
}
void SGameObject::OnDamage( AR_HANDLE caster, AR_HANDLE target, struct SGameMessage* pDamage )
{
if ( m_pMsgHandler )
m_pMsgHandler->OnDamage( caster, target, pDamage );
}
void SGameObject::OnDotDamage( struct SMSG_DAMAGE* pDamage, bool bFinalDmg )
{
if ( m_pMsgHandler )
m_pMsgHandler->OnDotDamage( pDamage, bFinalDmg );
}
void SGameObject::OnDisplayDamage( struct SMSG_DAMAGE* pDamage )
{
if ( m_pMsgHandler )
m_pMsgHandler->OnDisplayDamage( pDamage );
}
void SGameObject::OnUISync( AR_HANDLE caster, AR_HANDLE target )
{
if( m_pMsgHandler )
m_pMsgHandler->OnUISync( caster, target );
}
void SGameObject::OnDead()
{
if ( m_pMsgHandler )
m_pMsgHandler->OnDead();
}
void SGameObject::ReqMove( AR_HANDLE handle, const ArPosition & target, const ArPosition * targetposdata, int count, bool bSpeedSync )
{
if ( m_pMsgHandler )
m_pMsgHandler->ReqMove( handle, target, targetposdata, count, bSpeedSync );
m_ArPosition = target;
}
void SGameObject::SetMessageHandler( SGameObject *pMsgHandler )
{
m_pMsgHandler = pMsgHandler;
}
void SGameObject::CorrectivePosition( K3DVector & pos, K3DVector & newpos )
{
if ( m_pMsgHandler )
m_pMsgHandler->CorrectivePosition( pos, newpos );
}
void SGameObject::SendMsg( SGameObject *pGO, const TS_MESSAGE *msg )
{
if ( m_pMsgHandler )
m_pMsgHandler->SendMsg( pGO, msg );
}
void SGameObject::SendMsg( const TS_MESSAGE *msg )
{
if ( m_pMsgHandler )
m_pMsgHandler->SendMsg( msg );
}
void SGameObject::AddMsg( SGameMessage * msg )
{
m_vMsgList.push( msg );
}
void SGameObject::SendGameInterfaceMsg( struct SGameMessage * game_msg ) //인터페이스 메니저로 바로 처리
{
//이것을 쓸 수 있게 하자..
if ( m_pMsgHandler )
m_pMsgHandler->SendGameInterfaceMsg( game_msg );
}
void SGameObject::SendGameMsg( SGameMessage * game_msg )
{
//이것을 쓸 수 있게 하자..
if ( m_pMsgHandler )
m_pMsgHandler->SendGameMsg( game_msg );
}
void SGameObject::FastWork( class SGameWork * work )
{
work->Process( 0 );
}
void SGameObject::AddWork ( class SGameWork * work )
{
m_vWorkList.push_back( work );
}
int SGameObject::AddEnhanceEffect( class SGameAvatarEx* pAvatar, int nWeaponEffectPos, EnhanceFX* pEnhanceFx, int nItemClass )
{
if ( m_pMsgHandler )
return m_pMsgHandler->AddEnhanceEffect( pAvatar, nWeaponEffectPos, pEnhanceFx, nItemClass );
assert( 0 && "메세지 핸들러 없음" );
return -1;
}
void SGameObject::RemoveEnhanceEffect( int nParticleID )
{
if ( m_pMsgHandler )
m_pMsgHandler->RemoveEnhanceEffect( nParticleID );
else
assert( 0 && "메세지 핸들러 없음" );
}
void SGameObject::SetRenderEnhanceFx( int nParticleID, bool bRender )
{
if ( m_pMsgHandler )
m_pMsgHandler->SetRenderEnhanceFx( nParticleID, bRender );
else
assert( 0 && "메세지 핸들러 없음" );
}
//void SGameObject::FindDetour(const K3DVertex& vStart, const K3DVertex& vEnd, bool bChase)
//{
// if(m_pMsgHandler) m_pMsgHandler->FindDetour(vStart, vEnd, bChase);
//}
//
//bool SGameObject::ChaseDetour(const K3DVertex& vTarget, K3DVertex& vMovePos)
//{
// if(m_pMsgHandler)
// {
// return m_pMsgHandler->ChaseDetour(vTarget, vMovePos);
// }
// else
// {
// return false;
// }
//}
//bool SGameObject::MoveDetour(K3DVertex& vtMovePos)
//{
// if(m_pMsgHandler)
// {
// return m_pMsgHandler->MoveDetour(vtMovePos);
// }
//
// return false;
//}
//
//bool SGameObject::IsMovingDetour()
//{
// if(m_pMsgHandler)
// {
// return m_pMsgHandler->IsMovingDetour();
// }
//
// return false;
//}
//
//size_t SGameObject::GetDetourSize()
//{
// if(m_pMsgHandler)
// {
// return m_pMsgHandler->GetDetourSize();
// }
//
// return 0;
//}
//
//bool SGameObject::GetDetourPoint(size_t index, int& x, int& y)
//{
// if(m_pMsgHandler)
// {
// return m_pMsgHandler->GetDetourPoint(index, x, y);
// }
//
// return false;
//}
bool SGameObject::CollisionToLine( const K3DVector& vStart, const K3DVector& vEnd )
{
if( m_pMsgHandler )
return m_pMsgHandler->CollisionToLine( vStart, vEnd );
return false;
}
void SGameObject::FindDetour( const K3DVertex& vStart, const K3DVertex& vEnd, PATH& vPath, bool bRestraint, bool bChase, bool bIsPlayer )
{
if( m_pMsgHandler ) m_pMsgHandler->FindDetour( vStart, vEnd, vPath, bRestraint, bChase, bIsPlayer );
}
//bool SGameObject::IsChasing()
//{
// if(m_pMsgHandler)
// {
// return m_pMsgHandler->IsChasing();
// }
//
// return false;
//}
//
//int SGameObject::GetDetourStep()
//{
// if(m_pMsgHandler)
// {
// return m_pMsgHandler->GetDetourStep();
// }
//
// return 0;
//}
void SGameObject::SetPKMode( bool bMode )
{
if( m_pMsgHandler )
m_pMsgHandler->SetPKMode( bMode );
else
assert( 0 && "메세지 핸들러 없음" );
}
int SGameObject::GetPlayerCurrentLocation()
{
if( m_pMsgHandler ) return m_pMsgHandler->GetPlayerCurrentLocation();
assert( 0 && "메세지 핸들러 없음" );
return false;
}
bool SGameObject::IsPartyRaidMemeber( AR_HANDLE hTarget )
{
if( m_pMsgHandler ) return m_pMsgHandler->IsPartyRaidMemeber( hTarget );
return false;
}
void SGameObject::SetRenderOtherPlayer( int nRender )
{
if ( m_pMsgHandler ) m_pMsgHandler->SetRenderOtherPlayer( nRender );
}
bool SGameObject::PlayerInTown( SGameAvatarEx* pPlayer )
{
if ( m_pMsgHandler ) return m_pMsgHandler->PlayerInTown( pPlayer );
return false;
}