160 lines
3.7 KiB
C++
160 lines
3.7 KiB
C++
#include "stdafx.h"
|
|
#include "SQuestDB.h"
|
|
|
|
#include <Windows.h>
|
|
#include <kfile/KStream.h>
|
|
#include "KTypes.h"
|
|
#include <kfile/KFileManager.h>
|
|
#include <toolkit/XStringUtil.h>
|
|
#include "QuestBase.h"
|
|
#include "SkillBaseFile.h"
|
|
#include "SDebug_Util.h"
|
|
#include "SStringDB.h"
|
|
|
|
extern HWND g_hWnd;
|
|
|
|
SQuestDB::SQuestDB()
|
|
{
|
|
Init();
|
|
}
|
|
|
|
SQuestDB::~SQuestDB()
|
|
{
|
|
Destroy();
|
|
}
|
|
|
|
void SQuestDB::Init()
|
|
{
|
|
Load();
|
|
}
|
|
|
|
void SQuestDB::Destroy()
|
|
{
|
|
SAFE_DELETE_VECTOR( m_vQuestList );
|
|
}
|
|
|
|
QuestBase* SQuestDB::GetQuestData( int nQuestCode )
|
|
{
|
|
QuestBase* pPtr = NULL;
|
|
m_hashQuest.lookup( nQuestCode, pPtr );
|
|
return pPtr;
|
|
}
|
|
|
|
void SQuestDB::Load()
|
|
{
|
|
KStream * pRes = KFileManager::Instance().CreateStreamFromResource( "db_Quest.rdb" );
|
|
if( !pRes ) return;
|
|
GAME_DB db_hdr;
|
|
|
|
pRes->Read( &db_hdr, sizeof(db_hdr) );
|
|
|
|
#ifdef _DEV_RDB_
|
|
// Compare the RDB size with the header size
|
|
int fileSize = pRes->Size() - ( STR_DATE_BUFFER + sizeof( int ) );
|
|
int headerSize = sizeof(QuestBase) * db_hdr.nCount;
|
|
if( fileSize != headerSize )
|
|
{
|
|
char str[512] = { NULL, };
|
|
sprintf( str, "[RDB Error!] Creation date: %s\nFile: %s\nFile size: %d\nHeader size: %d\n",
|
|
db_hdr.szDate,
|
|
__FILE__,
|
|
fileSize,
|
|
headerSize
|
|
);
|
|
|
|
//MessageBox( g_hWnd, str, "Error", MB_OK );
|
|
|
|
if( MessageBox( g_hWnd, "The RDB does not match the client. Do you want to force quit?", "Error", MB_YESNO ) == IDYES )
|
|
{
|
|
exit( 1 );
|
|
}
|
|
}
|
|
#endif
|
|
|
|
for( int i(0); db_hdr.nCount>i; i++ )
|
|
{
|
|
QuestBase * pQuest = new QuestBase;
|
|
memset( pQuest, 0, sizeof(QuestBase) );
|
|
|
|
pRes->Read( pQuest, sizeof(QuestBase) );
|
|
m_hashQuest.add( pQuest->nCode, pQuest );
|
|
m_vQuestList.push_back( pQuest );
|
|
}
|
|
|
|
KFileManager::Instance().DeleteStream( pRes );
|
|
}
|
|
|
|
SQuestDB* SQuestDB::m_pThis = NULL;
|
|
SQuestDB & GetQuestDB()
|
|
{
|
|
if( NULL == SQuestDB::m_pThis )
|
|
SQuestDB::m_pThis = new SQuestDB;
|
|
|
|
return *SQuestDB::m_pThis;
|
|
|
|
// static SQuestDB Questdb;
|
|
// return Questdb;
|
|
}
|
|
|
|
void SQuestDB::printQuestTagStatus(QuestBase const* quest)
|
|
{
|
|
std::vector<std::string> extractQuestTargetList;
|
|
|
|
extern void extractQuestTarget(std::vector<std::string>& questTargetList, int questCode);
|
|
extern std::string ParseQuestText( const char *szQuestString, int nQuestCode ); // GameVM.cpp
|
|
|
|
extractQuestTarget(extractQuestTargetList, quest->nCode);
|
|
|
|
if (extractQuestTargetList.empty()) return;
|
|
|
|
std::string str;
|
|
/// 설명
|
|
str = ParseQuestText(GetStringDB().GetString(quest->nQuestTextId), quest->nCode);
|
|
int explainCount = replaceQuestTargetToText(extractQuestTargetList, str);
|
|
|
|
// 목표
|
|
str = ParseQuestText(GetStringDB().GetString(quest->nSummaryTextId), quest->nCode);
|
|
int summaryCount = replaceQuestTargetToText(extractQuestTargetList, str);
|
|
|
|
if (0 == explainCount || 0 == summaryCount)
|
|
{
|
|
_oprint("[%d] : ", quest->nCode);
|
|
if (0 == explainCount) _oprint("no explain(%d) / ", quest->nQuestTextId);
|
|
if (0 == summaryCount) _oprint("no summary(%d)", quest->nSummaryTextId);
|
|
|
|
_oprint(" (");
|
|
std::vector<std::string>::iterator it = extractQuestTargetList.begin();
|
|
for (; it != extractQuestTargetList.end(); ++it)
|
|
{
|
|
_oprint("%s, ", it->c_str());
|
|
}
|
|
_oprint(")");
|
|
|
|
_oprint("\n");
|
|
}
|
|
|
|
extractQuestTargetList.clear();
|
|
}
|
|
|
|
int SQuestDB::replaceQuestTargetToText(std::vector<std::string> const& extractQuestTargetList, std::string& text)
|
|
{
|
|
int count = 0;
|
|
std::string replaceText;
|
|
std::vector<std::string>::const_iterator it = extractQuestTargetList.begin();
|
|
for (; it != extractQuestTargetList.end(); ++it)
|
|
{
|
|
replaceText = makeQuestTargetTagText(*it);
|
|
count += XStringUtil::Replace(text, *it, replaceText);
|
|
if (0 != count)
|
|
break;
|
|
}
|
|
|
|
return count;
|
|
}
|
|
|
|
std::string SQuestDB::makeQuestTargetTagText(std::string const& str)
|
|
{
|
|
std::string strRet;
|
|
XStringUtil::Format(strRet, "<#ff0000>%s<#ffffff>", str.c_str());
|
|
return strRet;
|
|
} |