Files
Leviathan/Client/Game/game/GameSystem/SPetMgr.cpp
T
2026-06-01 12:46:52 +02:00

135 lines
3.3 KiB
C++

#include "stdafx.h"
#include "SPetMgr.h"
#include "SGame.h"
#include "SGameAvatarEx.h"
#include "SGameSystem.h"
#include "SGameMessage.h"
//#include "SGameMessageUI.h"
#include "SUISysMsgDefine.h"
extern SGameSystem * g_pCurrentGameSystem;
SPetMgr::SPetMgr()
: SGameUIMgr ()
{
}
SPetMgr::~SPetMgr()
{
}
void SPetMgr::Process( DWORD dwTime )
{
}
void SPetMgr::ResetInfo()
{
m_vPetDataList.clear();
m_SummonPet = DATA_PET();
}
const DATA_PET& SPetMgr::GetSummonPetData() const
{
return m_SummonPet;
}
DATA_PET* SPetMgr::IsLocalPet( AR_HANDLE hPetHandle )
{
if( !m_vPetDataList.empty() )
{
pet_data_vector_t::iterator itFound = std::find_if( m_vPetDataList.begin(), m_vPetDataList.end(), PetDataFinder( hPetHandle ) );
if( itFound != m_vPetDataList.end() )
return &(*itFound);
}
return 0;
}
SGameAvatarEx* SPetMgr::IsSummonPet( AR_HANDLE hPetHandle )
{
if( !m_vPetDataList.empty() )
{
pet_data_vector_t::iterator itFound = std::find_if( m_vPetDataList.begin(), m_vPetDataList.end(), PetDataFinder( hPetHandle ) );
if( itFound != m_vPetDataList.end() )
return itFound->pet_avatar;
}
return 0;
}
DATA_PET* SPetMgr::IsLocalPetCage( AR_HANDLE hPetCageHandle )
{
if( !m_vPetDataList.empty() )
{
pet_data_vector_t::iterator itFound = std::find_if( m_vPetDataList.begin(), m_vPetDataList.end(), PetCageFinder( hPetCageHandle ) );
if( itFound != m_vPetDataList.end() )
return &(*itFound);
}
return 0;
}
void SPetMgr::AddPet( SGameAvatarEx* pet, SMSG_ENTER* enterMsg )
{
if( !pet ) return;
if( !g_pCurrentGameSystem->GetLocalPlayer() ) return;
pet_data_vector_t::iterator itFound = std::find_if( m_vPetDataList.begin(), m_vPetDataList.end(), PetDataFinder( pet->GetArID() ) );
if( itFound != m_vPetDataList.end() )
{
pet->SetName( itFound->name );
pet->SetMaster( g_pCurrentGameSystem->GetLocalPlayer()->GetArID(), g_pCurrentGameSystem->GetLocalPlayer() );
if( itFound->pet_avatar != pet )
{
itFound->pet_avatar = pet;
m_SummonPet = *itFound;
// 팻 소환 메시지
m_pGame->SendGameInterfaceMsg( &SIMSG_UI_DISPLAY_SYS_MSG( SYS_MSG_SUMMON_PET ) );
}
else
{
m_SummonPet = *itFound;
}
}
}
void SPetMgr::RemovePet( AR_HANDLE hPetHandle )
{
pet_data_vector_t::iterator itFound = std::find_if( m_vPetDataList.begin(), m_vPetDataList.end(), PetDataFinder( hPetHandle ) );
if( itFound != m_vPetDataList.end() )
{
itFound->pet_avatar = 0;
if( m_SummonPet.pet_handle == hPetHandle )
{
m_SummonPet = DATA_PET();
}
// 팻 역소환 메시지
m_pGame->SendGameInterfaceMsg( &SIMSG_UI_DISPLAY_SYS_MSG( SYS_MSG_UNSUMMON_PET ) );
m_pGame->SendGameInterfaceMsg( &SIMSG_SHOW_UIWINDOW( SIMSG_TOGGLE_UIWINDOW::UIWINDOW_PET_COMMAND, false ) );
}
}
void SPetMgr::OnMsgAddPetInfo( struct SMSG_ADD_PET_INFO* msg )
{
DATA_PET pet;
pet.pet_handle = msg->pet_handle;
pet.cage_handle = msg->cage_handle;
pet.code = msg->code;
strcpy( pet.name, msg->name );
m_vPetDataList.push_back( pet );
}
void SPetMgr::OnMsgRemovePetInfo( struct SMSG_REMOVE_PET_INFO* msg )
{
struct PetDataRemover{
PetDataRemover( AR_HANDLE target ) : mTargetHandle( target ) {}
bool operator()( const DATA_PET& petData ) const
{
return petData.pet_handle == mTargetHandle;
}
AR_HANDLE mTargetHandle;
};
m_vPetDataList.erase( std::remove_if( m_vPetDataList.begin(), m_vPetDataList.end(), PetDataRemover( msg->pet_handle ) ), m_vPetDataList.end() );
}