119 lines
2.8 KiB
C++
119 lines
2.8 KiB
C++
#include "stdafx.h"
|
|
#include <windows.h>
|
|
#include "KTypes.h"
|
|
#include <kfile/KStream.h>
|
|
#include <kfile/KFileManager.h>
|
|
#include "SkillBaseFile.h"
|
|
#include "SItemEffectResourceDB.h"
|
|
#include "TemplateUtil.h"
|
|
#include "SLog.h"
|
|
#include "SDebug_Util.h"
|
|
|
|
SItemEffectResourceDB::SItemEffectResourceDB()
|
|
{
|
|
Init();
|
|
}
|
|
|
|
SItemEffectResourceDB::~SItemEffectResourceDB()
|
|
{
|
|
Destroy();
|
|
}
|
|
|
|
void SItemEffectResourceDB::Find( int setId, SItemEffectResourceDB::FoundResult& result ) const
|
|
{
|
|
std::pair< DBType::const_iterator, DBType::const_iterator > found = mDB.equal_range( setId );
|
|
|
|
for( ; found.first != found.second; ++found.first )
|
|
result.push_back( found.first->second );
|
|
}
|
|
|
|
void SItemEffectResourceDB::Find( int setId, int partCompositionId, SItemEffectResourceDB::FoundResult& result ) const
|
|
{
|
|
std::pair< DBType::const_iterator, DBType::const_iterator > found = mDB.equal_range( setId );
|
|
|
|
for( ; found.first != found.second; ++found.first )
|
|
{
|
|
const ItemEffectResource* fx = found.first->second;
|
|
|
|
if( fx->isPartOfItemComposition( partCompositionId ) )
|
|
result.push_back( fx );
|
|
}
|
|
}
|
|
|
|
void SItemEffectResourceDB::Init()
|
|
{
|
|
Load();
|
|
}
|
|
|
|
void SItemEffectResourceDB::Destroy()
|
|
{
|
|
rp::wipe_assoc( mDB );
|
|
}
|
|
|
|
void SItemEffectResourceDB::Load()
|
|
{
|
|
KStream * pRes = KFileManager::Instance().CreateStreamFromResource( "db_ItemEffectResource.rdb" );
|
|
if( !pRes ) return;
|
|
|
|
GAME_DB db_hdr;
|
|
|
|
pRes->Read( &db_hdr, sizeof(db_hdr) );
|
|
|
|
for( int i(0); db_hdr.nCount>i; i++ )
|
|
{
|
|
ItemEffectResource* pItemFx( new ItemEffectResource );
|
|
if( NULL == pItemFx )
|
|
{
|
|
SDEBUGLOG( "[ItemEffectResourceDB] 메모리 할당 실패 COUNT - [%u]", i );
|
|
continue;
|
|
}
|
|
|
|
memset( pItemFx, 0, sizeof( ItemEffectResource ) );
|
|
|
|
pRes->Read( pItemFx, sizeof(ItemEffectResource) );
|
|
|
|
std::pair< DBType::iterator, DBType::iterator > found = mDB.equal_range( pItemFx->id );
|
|
|
|
if( found.first == found.second )
|
|
{
|
|
mDB.insert( std::make_pair( pItemFx->id, pItemFx ) );
|
|
}
|
|
else
|
|
{
|
|
bool unique = true;
|
|
for( ; found.first != found.second; ++found.first )
|
|
{
|
|
if( found.first->second->ordinal_id == pItemFx->ordinal_id )
|
|
{
|
|
unique = false;
|
|
break;
|
|
}
|
|
}
|
|
|
|
if( unique )
|
|
{
|
|
mDB.insert( std::make_pair( pItemFx->id, pItemFx ) );
|
|
}
|
|
else
|
|
{
|
|
SDEBUGLOG( "[ItemEffectResourceDB] ordinal_id가 중복되었습니다. ID - [%u], Ordinal ID - [%u]", pItemFx->id, pItemFx->ordinal_id );
|
|
SAFE_DELETE( pItemFx );
|
|
}
|
|
}
|
|
}
|
|
|
|
KFileManager::Instance().DeleteStream( pRes );
|
|
}
|
|
|
|
SItemEffectResourceDB* SItemEffectResourceDB::m_pThis = NULL;
|
|
SItemEffectResourceDB& GetItemEffectResourceDB()
|
|
{
|
|
if( NULL == SItemEffectResourceDB::m_pThis )
|
|
SItemEffectResourceDB::m_pThis = new SItemEffectResourceDB;
|
|
|
|
return *SItemEffectResourceDB::m_pThis;
|
|
|
|
// static SItemEffectResourceDB itemEffectResourceDB;
|
|
// return itemEffectResourceDB;
|
|
}
|