Files
Leviathan/Client/Game/game/DB/SPetDB.h
T
2026-06-01 12:46:52 +02:00

154 lines
4.5 KiB
Objective-C

#pragma once
/**----------------------------------------------------------------------------------------------------
@file definition of pet database class
@author sonador
@date 2008.03.06
----------------------------------------------------------------------------------------------------*/
#include "MonsterBase.h"
#include <toolkit/khash.h>
#include "K3DTypes.h"
#include "Enc.h"
struct _PET_INFO_CLIENT : public _PET_INFO_FILE
{
_PET_INFO_CLIENT()
: _PET_INFO_FILE ()
, uid_client ( 0 )
#ifdef _DEBUG
, debug_name ( 0 )
#endif
{
}
ENC_INT uid_client;
#ifdef _DEBUG
const char* debug_name;
#endif
};
/**----------------------------------------------------------------------------------------------------
@class SPetInfoEx
@brief 팻 정보 획득에 사용할 수 있는 유용한 메소드를 정의한 클래스( 팻 정보 구조체를 감싼다. )
@author sonador
@date 2008.03.06
----------------------------------------------------------------------------------------------------*/
class SPetInfoEx
{
public:
SPetInfoEx( const _PET_INFO_CLIENT& Pet ) : m_Pet( &Pet ) {}
SPetInfoEx( const SPetInfoEx& rhs ) : m_Pet( rhs.m_Pet ) {}
// operator
operator const _PET_INFO_CLIENT*() const { return m_Pet; }
const _PET_INFO_CLIENT* operator ->() const { return m_Pet; }
const _PET_INFO_CLIENT& operator *() const { return *m_Pet; }
// method
int getID( void ) const { return m_Pet->uid_client; } // #2.1.2.4.3
int GetSpeciesID( void ) const { return m_Pet->specific_id; }
int GetAffiliation( void ) const { return m_Pet->affiliation; }
int GetAffiliationDetail( void ) const { return m_Pet->affiliationDetail; }
int getNameID( void ) const { return m_Pet->name_id; }
int getCageID( void ) const { return m_Pet->cage_id; }
int getSkillTreeID( void ) const { return m_Pet->skill_tree_id; }
PetBase::PET_ATTRIBUTE getAttributeFlag( void ) const { return (PetBase::PET_ATTRIBUTE)m_Pet->attribute_flag; }
float getSize( void ) const { return m_Pet->size; }
float getScale( void ) const { return m_Pet->scale; }
int getWalkType( void ) const { return m_Pet->walk_type; }
int getSlantType( void ) const { return m_Pet->slant_type; }
int getTextureGroupIndex( void ) const { return m_Pet->texture_group; }
K3DVector getFaceCutCameraPosition( void ) const;
float getTargetFxSize( void ) const { return m_Pet->target_fx_size; }
K3DVector getTargetFxPosition( void ) const;
const char* getModelFileName( void ) const { return m_Pet->model; }
int getMotionFileID( void ) const { return m_Pet->motion_file_id; }
private:
const _PET_INFO_CLIENT* m_Pet;
};
/**----------------------------------------------------------------------------------------------------
@class SPetDB
@brief 팻 정보를 관리하는 DB 클래스
@author sonador
@date 2008.03.06
----------------------------------------------------------------------------------------------------*/
class SPetDB
{
public:
SPetDB();
~SPetDB();
inline SPetInfoEx Find( ENC_INT PetID )
{
_PET_INFO_CLIENT* FoundPet = 0;
if( m_PetHash.lookup( PetID, FoundPet ) )
{
return SPetInfoEx( *FoundPet );
}
return SPetInfoEx( m_DummyPet );
}
inline int GetSpeciesID( ENC_INT PetID )
{
_PET_INFO_CLIENT* FoundPet( NULL );
if( m_PetHash.lookup( PetID, FoundPet ) )
{
return FoundPet->specific_id;
}
return NULL;
}
inline int GetAffiliationID( ENC_INT PetID )
{
_PET_INFO_CLIENT* FoundPet( NULL );
if( m_PetHash.lookup( PetID, FoundPet ) )
{
return FoundPet->affiliation;
}
return NULL;
}
inline int GetAffiliationDetailID( ENC_INT PetID )
{
_PET_INFO_CLIENT* FoundPet( NULL );
if( m_PetHash.lookup( PetID, FoundPet ) )
{
return FoundPet->affiliationDetail;
}
return NULL;
}
protected:
struct hashPr_mod_ENC_INT
{
typedef ENC_INT Key;
static inline unsigned getindex( const Key& key, int nCapacity ) { return unsigned( key.hash_id() ) % nCapacity; }
static inline bool isequal( const Key& key1, const Key& key2 ) { return key1 == key2; }
static inline bool isless( const Key& key1, const Key& key2 ) { return key1.prior( key2 ); }
};
typedef KHash< _PET_INFO_CLIENT*, hashPr_mod_ENC_INT > pet_hash_t;
void _init();
void _destroy();
void _load();
pet_hash_t m_PetHash;
_PET_INFO_CLIENT m_DummyPet;
public:
static SPetDB* m_pThis;
};
SPetDB& GetPetDB();