2024-12-21 10:04:04 +08:00
|
|
|
|
#include "stdafx.h"
|
|
|
|
|
|
#include "DnTalk.h"
|
|
|
|
|
|
|
|
|
|
|
|
#include "EtResourceMng.h"
|
|
|
|
|
|
#include <algorithm>
|
|
|
|
|
|
#include "DNUserSession.h"
|
|
|
|
|
|
#include "DnScriptManager.h"
|
|
|
|
|
|
|
|
|
|
|
|
#if defined(_VILLAGESERVER)
|
|
|
|
|
|
#include "DNUserSessionManager.h"
|
|
|
|
|
|
#include "DNScriptAPI.h"
|
|
|
|
|
|
|
|
|
|
|
|
#elif defined(_GAMESERVER)
|
|
|
|
|
|
#include "DNGameServerManager.h"
|
|
|
|
|
|
#include "DNRUDPGameServer.h"
|
|
|
|
|
|
#include "DNGameServerScriptAPI.h"
|
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
|
|
DnScriptManager* CDNTalk::m_pScriptManager = NULL;
|
|
|
|
|
|
|
|
|
|
|
|
CDNTalk::CDNTalk()
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
CDNTalk::~CDNTalk()
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
bool CDNTalk::Create(const WCHAR* wszTalkFileName, const WCHAR* wszScriptFileName)
|
|
|
|
|
|
{
|
|
|
|
|
|
static std::wstring __wszExt(L".lua");
|
|
|
|
|
|
|
|
|
|
|
|
m_wszTalkFileName = wszTalkFileName;
|
|
|
|
|
|
m_wszScriptFilename = wszScriptFileName;
|
|
|
|
|
|
|
|
|
|
|
|
RemoveStringW(m_wszScriptFilename, __wszExt );
|
|
|
|
|
|
return true;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void CDNTalk::SetScriptManager(DnScriptManager* pScriptManager)
|
|
|
|
|
|
{
|
|
|
|
|
|
m_pScriptManager = pScriptManager;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void CDNTalk::Destroy()
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
bool CDNTalk::CheckTalk(UINT nUserObjectID, IN std::wstring& wszIndex, IN std::wstring& wszTarget)
|
|
|
|
|
|
{
|
|
|
|
|
|
//@ <20><><EFBFBD>⼭ <20><><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20>ִ<EFBFBD> <20>ε<EFBFBD><CEB5><EFBFBD><EFBFBD><EFBFBD> Ÿ<><C5B8><EFBFBD><EFBFBD><EFBFBD><EFBFBD> Ȯ<><C8AE> <20>ѹ<EFBFBD> <20>ϰ<EFBFBD>
|
|
|
|
|
|
|
|
|
|
|
|
std::wstring wszCheckIndex;
|
|
|
|
|
|
wszCheckIndex = wszIndex;
|
|
|
|
|
|
ToLowerW(wszCheckIndex);
|
|
|
|
|
|
|
|
|
|
|
|
// <20><>ȭ <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20>ƴ<EFBFBD> <20><><EFBFBD>쿡<EFBFBD><ECBFA1> üũ <20>Ѵ<EFBFBD>.
|
|
|
|
|
|
if ( wszCheckIndex != L"start" )
|
|
|
|
|
|
{
|
|
|
|
|
|
#if defined(_VILLAGESERVER)
|
|
|
|
|
|
CDNUserSession* pUser = g_pUserSessionManager->FindUserSessionByObjectID(nUserObjectID);
|
|
|
|
|
|
#elif defined(_GAMESERVER)
|
|
|
|
|
|
CDNUserSession * pUser = NULL;
|
|
|
|
|
|
CDNRUDPGameServer * pServer = g_pGameServerManager->GetGameServerByUID(nUserObjectID);
|
|
|
|
|
|
if (pServer == NULL) return false;
|
|
|
|
|
|
|
|
|
|
|
|
pUser = pServer->GetSession(nUserObjectID);
|
|
|
|
|
|
if (pUser == NULL) return false;
|
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
|
|
TALK_PARAGRAPH& para = pUser->GetLastTalkParagraph();
|
|
|
|
|
|
|
|
|
|
|
|
bool bCheckSuccess = false;
|
|
|
|
|
|
|
|
|
|
|
|
// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD>쿣 üũ<C3BC><C5A9> <20><>ŵ<EFBFBD>Ѵ<EFBFBD>.
|
|
|
|
|
|
if ( pUser->GetSkipParagraphCheck() )
|
|
|
|
|
|
{
|
|
|
|
|
|
bCheckSuccess = true;
|
|
|
|
|
|
bool& bSkip = pUser->GetSkipParagraphCheck();
|
|
|
|
|
|
bSkip = false;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
for ( int i = 0 ; i < (int)para.Answers.size() ; i++ )
|
|
|
|
|
|
{
|
|
|
|
|
|
if ( para.Answers[i].szLinkIndex == wszIndex && para.Answers[i].szLinkTarget == wszTarget )
|
|
|
|
|
|
{
|
|
|
|
|
|
bCheckSuccess = true;
|
|
|
|
|
|
break;
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
if ( bCheckSuccess == false )
|
|
|
|
|
|
{
|
|
|
|
|
|
#ifndef _FINAL_BUILD
|
|
|
|
|
|
// <20><><EFBFBD><EFBFBD> <20>߸<EFBFBD><DFB8><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>.. ¥<><C2A5><EFBFBD><EFBFBD>.
|
|
|
|
|
|
|
|
|
|
|
|
std::wstring wszString;
|
|
|
|
|
|
wszString = L"[TalkCheck Error:";
|
|
|
|
|
|
wszString += wszIndex;
|
|
|
|
|
|
wszString += L" , ";
|
|
|
|
|
|
wszString += wszTarget;
|
|
|
|
|
|
|
|
|
|
|
|
pUser->SendChat(CHATTYPE_NORMAL, (int)wszString.size()*sizeof(WCHAR), L"", (WCHAR*)wszString.c_str());
|
|
|
|
|
|
|
|
|
|
|
|
#endif // _FINAL_BUILD
|
|
|
|
|
|
return false;
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
return true;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
bool CDNTalk::OnTalk(UINT nUserObjectID, UINT nNpcUniqueID, IN std::wstring& wszIndex, IN std::wstring& wszTarget)
|
|
|
|
|
|
{
|
|
|
|
|
|
if ( m_pScriptManager == NULL )
|
|
|
|
|
|
return false;
|
|
|
|
|
|
|
|
|
|
|
|
lua_State* pLua = m_pScriptManager->OpenState();
|
|
|
|
|
|
if ( !pLua )
|
|
|
|
|
|
return false;
|
|
|
|
|
|
|
|
|
|
|
|
char szIndex[512] = {0,};
|
|
|
|
|
|
ZeroMemory(szIndex, sizeof(char)*512);
|
|
|
|
|
|
WideCharToMultiByte( CP_ACP, 0, wszIndex.c_str(), -1, szIndex, 512, NULL, NULL );
|
|
|
|
|
|
|
|
|
|
|
|
char szTarget[512] = {0,};
|
|
|
|
|
|
ZeroMemory(szTarget, sizeof(char)*512);
|
|
|
|
|
|
WideCharToMultiByte( CP_ACP, 0, wszTarget.c_str(), -1, szTarget, 512, NULL, NULL );
|
|
|
|
|
|
|
|
|
|
|
|
std::wstring wszFuncName;
|
|
|
|
|
|
wszFuncName = m_wszScriptFilename;
|
|
|
|
|
|
wszFuncName += L"_OnTalk";
|
|
|
|
|
|
|
|
|
|
|
|
char szFunctionName[512] = {0,};
|
|
|
|
|
|
ZeroMemory(szFunctionName, sizeof(char)*512);
|
|
|
|
|
|
WideCharToMultiByte( CP_ACP, 0, wszFuncName.c_str(), -1, szFunctionName, 512, NULL, NULL );
|
|
|
|
|
|
|
|
|
|
|
|
#if defined(_VILLAGESERVER)
|
|
|
|
|
|
CDNUserSession* pUser = g_pUserSessionManager->FindUserSessionByObjectID(nUserObjectID);
|
|
|
|
|
|
if (!pUser) return false;
|
|
|
|
|
|
#elif defined(_GAMESERVER)
|
|
|
|
|
|
CDNUserSession * pUser = NULL;
|
|
|
|
|
|
CDNRUDPGameServer * pServer = g_pGameServerManager->GetGameServerByUID(nUserObjectID);
|
|
|
|
|
|
if (pServer == NULL) return false;
|
|
|
|
|
|
|
|
|
|
|
|
pUser = pServer->GetSession(nUserObjectID);
|
|
|
|
|
|
if (!pUser) return false;
|
|
|
|
|
|
#endif // _VILLAGESERVER
|
|
|
|
|
|
|
|
|
|
|
|
//g_Log.Log(LogType::_QUESTHACK, pUser, L"CDNTalk::OnTalk func(%S) user(%d) npc(%d) index(%S) , target(%S)\n", szFunctionName, nUserObjectID, nNpcUniqueID, szIndex, szTarget);
|
|
|
|
|
|
|
|
|
|
|
|
#if defined(_VILLAGESERVER)
|
|
|
|
|
|
lua_tinker::call<void>(pLua, szFunctionName, nUserObjectID, nNpcUniqueID, szIndex, szTarget );
|
|
|
|
|
|
#elif defined(_GAMESERVER)
|
|
|
|
|
|
//lua_tinker::call<void>(pLua, szFunctionName, pUser->GetGameRoom(), nUserObjectID, nNpcUniqueID, szIndex, szTarget );
|
|
|
|
|
|
m_pScriptManager->call<void>(pLua, szFunctionName, pUser->GetGameRoom(), nUserObjectID, nNpcUniqueID, szIndex, szTarget );
|
|
|
|
|
|
#endif // _VILLAGESERVER
|
|
|
|
|
|
|
|
|
|
|
|
#ifndef _FINAL_BUILD
|
|
|
|
|
|
std::string szMsg;
|
|
|
|
|
|
szMsg = FormatA("OnTalk func(%s) user(%d) npc(%d) index(%s) , target(%s)\n", szFunctionName, nUserObjectID, nNpcUniqueID, szIndex, szTarget );
|
|
|
|
|
|
#if defined(_VILLAGESERVER)
|
|
|
|
|
|
api_log_UserLog(nUserObjectID, szMsg.c_str() );
|
|
|
|
|
|
#elif defined(_GAMESERVER)
|
|
|
|
|
|
api_log_UserLog(pUser->GetGameRoom(), nUserObjectID, szMsg.c_str() );
|
|
|
|
|
|
#endif // _VILLAGESERVER
|
|
|
|
|
|
#endif // _FINAL_BUILD
|
|
|
|
|
|
|
|
|
|
|
|
// npc <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ٸ<EFBFBD>
|
|
|
|
|
|
if ( pUser->GetCalledNpcResponse() == false )
|
|
|
|
|
|
{
|
|
|
|
|
|
pUser->SendNextTalkError();
|
|
|
|
|
|
|
|
|
|
|
|
std::string szLocalMsg;
|
|
|
|
|
|
szLocalMsg = FormatA("GetCalledNpcResponse is FALSE func(%s) user(%d) npc(%d) index(%s) , target(%s)\n", szFunctionName, nUserObjectID, nNpcUniqueID, szIndex, szTarget );
|
|
|
|
|
|
#if defined(_VILLAGESERVER)
|
|
|
|
|
|
api_log_UserLog(nUserObjectID, szLocalMsg.c_str() );
|
|
|
|
|
|
#elif defined(_GAMESERVER)
|
|
|
|
|
|
api_log_UserLog(pUser->GetGameRoom(), nUserObjectID, szLocalMsg.c_str() );
|
|
|
|
|
|
#endif // _VILLAGESERVER
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
return true;
|
|
|
|
|
|
}
|