97 lines
2.0 KiB
C++
97 lines
2.0 KiB
C++
#include "stdafx.h"
|
|
#include "SQuestLinkDB.h"
|
|
|
|
#include <Windows.h>
|
|
#include <kfile/KStream.h>
|
|
#include "KTypes.h"
|
|
#include <kfile/KFileManager.h>
|
|
#include <toolkit/XStringUtil.h>
|
|
#include "SDebug_Util.h"
|
|
#include "SkillBaseFile.h"
|
|
#include "QuestLink.h"
|
|
|
|
SQuestLinkDB::SQuestLinkDB()
|
|
{
|
|
Init();
|
|
}
|
|
|
|
SQuestLinkDB::~SQuestLinkDB()
|
|
{
|
|
Destroy();
|
|
}
|
|
|
|
void SQuestLinkDB::Init()
|
|
{
|
|
Load();
|
|
}
|
|
|
|
void SQuestLinkDB::Destroy()
|
|
{
|
|
//_LEAK_SUN
|
|
QuestLinkEx* phashQuestLinkRes = NULL;
|
|
bool res;
|
|
res = m_hashQuestLink.get_first_value( phashQuestLinkRes );
|
|
while ( res )
|
|
{
|
|
if ( phashQuestLinkRes != NULL )
|
|
{
|
|
delete phashQuestLinkRes;
|
|
}
|
|
res = m_hashQuestLink.get_next_value( phashQuestLinkRes );
|
|
}
|
|
|
|
m_hashQuestLink.clear();
|
|
}
|
|
|
|
QuestLinkEx* SQuestLinkDB::GetQuestLinkData( int nQuestCode )
|
|
{
|
|
QuestLinkEx* pPtr = NULL;
|
|
m_hashQuestLink.lookup( nQuestCode, pPtr );
|
|
return pPtr;
|
|
}
|
|
|
|
void SQuestLinkDB::Load()
|
|
{
|
|
KStream * pRes = KFileManager::Instance().CreateStreamFromResource( "db_QuestLink.rdb" );
|
|
if( !pRes ) return;
|
|
GAME_DB db_hdr;
|
|
QuestLink questLink;
|
|
|
|
pRes->Read( &db_hdr, sizeof(db_hdr) );
|
|
|
|
for( int i(0); db_hdr.nCount>i; i++ )
|
|
{
|
|
pRes->Read(&questLink, sizeof(QuestLink) );
|
|
|
|
QuestLinkEx* findEx = NULL;
|
|
if (m_hashQuestLink.lookup(questLink.quest_id, findEx))
|
|
{
|
|
convert(&questLink, findEx);
|
|
}
|
|
else
|
|
{
|
|
QuestLinkEx* ex = new QuestLinkEx;
|
|
convert(&questLink, ex);
|
|
m_hashQuestLink.add(ex->questCode, ex);
|
|
}
|
|
}
|
|
|
|
KFileManager::Instance().DeleteStream( pRes );
|
|
}
|
|
|
|
void SQuestLinkDB::convert(QuestLink const* questLink, QuestLinkEx* ex)
|
|
{
|
|
ex->questCode = questLink->quest_id;
|
|
if (1 == questLink->start_flag) ex->startNpcId.push_back(questLink->npc_id);
|
|
if (1 == questLink->progress_flag) ex->progressNpcId.push_back(questLink->npc_id);
|
|
if (1 == questLink->end_flag) ex->endNpcId.push_back(questLink->npc_id);
|
|
}
|
|
|
|
SQuestLinkDB* SQuestLinkDB::m_pThis = NULL;
|
|
SQuestLinkDB & GetQuestLinkDB()
|
|
{
|
|
if( NULL == SQuestLinkDB::m_pThis )
|
|
SQuestLinkDB::m_pThis = new SQuestLinkDB;
|
|
|
|
return *SQuestLinkDB::m_pThis;
|
|
} |