2024-12-21 10:04:04 +08:00
|
|
|
|
|
|
|
|
|
|
#include "Stdafx.h"
|
|
|
|
|
|
#include "ReputationSystemEventHandlerForServer.h"
|
|
|
|
|
|
#include "ReputationSystemRepository.h"
|
|
|
|
|
|
#include "DNUserSession.h"
|
|
|
|
|
|
#include "DNDBConnection.h"
|
|
|
|
|
|
#include "NpcReputationSystem.h"
|
|
|
|
|
|
#include "DNGameDataManager.h"
|
|
|
|
|
|
#include "TimeSet.h"
|
|
|
|
|
|
|
|
|
|
|
|
#if defined( PRE_ADD_NPC_REPUTATION_SYSTEM )
|
|
|
|
|
|
|
|
|
|
|
|
CServerReputationSystemEventHandler::CServerReputationSystemEventHandler( CDNUserSession* pSession )
|
|
|
|
|
|
:m_pSession(pSession)
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void CServerReputationSystemEventHandler::OnComplete( IReputationSystem* pReputation, IReputationSystem::eType Type )
|
|
|
|
|
|
{
|
|
|
|
|
|
switch( Type )
|
|
|
|
|
|
{
|
|
|
|
|
|
case IReputationSystem::NpcMalice:
|
|
|
|
|
|
{
|
|
|
|
|
|
#if defined( PRE_REMOVE_NPCREPUTATION_MALICE )
|
|
|
|
|
|
#else
|
|
|
|
|
|
CReputationSystemRepository* pRepository = m_pSession->GetReputationSystem();
|
|
|
|
|
|
_ASSERT( pRepository );
|
|
|
|
|
|
|
|
|
|
|
|
_ASSERT( dynamic_cast<CNpcReputationSystem*>(pReputation) );
|
|
|
|
|
|
CNpcReputationSystem* pNpcReputaion = static_cast<CNpcReputationSystem*>(pReputation);
|
|
|
|
|
|
|
|
|
|
|
|
// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|
|
|
|
|
pRepository->SetNpcReputation( pNpcReputaion->GetNpcID(), IReputationSystem::NpcFavor, 0 ); // ȣ<><C8A3> <20>ʱ<EFBFBD>ȭ
|
|
|
|
|
|
pRepository->SetNpcReputation( pNpcReputaion->GetNpcID(), Type, 0 ); // <20><><EFBFBD><EFBFBD> <20>ʱ<EFBFBD>ȭ
|
|
|
|
|
|
|
|
|
|
|
|
TReputeTableData* pReputationTable = g_pDataManager->GetReputeTableData( pNpcReputaion->GetNpcID() );
|
|
|
|
|
|
if (!pReputationTable) break;
|
|
|
|
|
|
|
|
|
|
|
|
// ģ<>ѻ<EFBFBD><D1BB><EFBFBD>
|
|
|
|
|
|
for( UINT i=0 ; i<pReputationTable->vFavorNpcID.size() ; ++i )
|
|
|
|
|
|
{
|
|
|
|
|
|
REPUTATION_TYPE value = pRepository->GetNpcReputation( pReputationTable->vFavorNpcID[i], IReputationSystem::NpcFavor );
|
|
|
|
|
|
value = value*pReputationTable->iFavorGroupBomb/100;
|
|
|
|
|
|
|
|
|
|
|
|
pRepository->AddNpcReputation( pReputationTable->vFavorNpcID[i], IReputationSystem::NpcFavor, -value ); // ȣ<><C8A3><EFBFBD><EFBFBD> <20>϶<EFBFBD>
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// <20>Ⱦ<EFBFBD><C8BE>ϴ»<CFB4><C2BB><EFBFBD>
|
|
|
|
|
|
for( UINT i=0 ; i<pReputationTable->vMaliceNpcID.size() ; ++i )
|
|
|
|
|
|
{
|
|
|
|
|
|
REPUTATION_TYPE value = pRepository->GetNpcReputation( pReputationTable->vMaliceNpcID[i], IReputationSystem::NpcFavor );
|
|
|
|
|
|
value = value*pReputationTable->iMaliceGroupBomb/100;
|
|
|
|
|
|
|
|
|
|
|
|
pRepository->AddNpcReputation( pReputationTable->vMaliceNpcID[i], IReputationSystem::NpcFavor, value ); // ȣ<><C8A3><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD>
|
|
|
|
|
|
}
|
|
|
|
|
|
#endif // #if defined( PRE_REMOVE_NPCREPUTATION_MALICE )
|
|
|
|
|
|
|
|
|
|
|
|
break;
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void CServerReputationSystemEventHandler::OnChange( IReputationSystem::eType Type )
|
|
|
|
|
|
{
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
#if defined( PRE_ADD_REPUTATION_EXPOSURE )
|
|
|
|
|
|
void CServerReputationSystemEventHandler::OnCommit( std::map<IReputationSystem*,size_t>& Reputation, bool bClientSend )
|
|
|
|
|
|
{
|
|
|
|
|
|
if( m_pSession == NULL || m_pSession->GetDBConnection() == NULL || m_pSession->GetReputationSystem() == NULL )
|
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
|
|
std::vector<TNpcReputation> vData;
|
|
|
|
|
|
m_pSession->GetReputationSystem()->GetCommitData( vData );
|
|
|
|
|
|
|
|
|
|
|
|
if( vData.empty() )
|
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
|
|
// DB M/W <20><><EFBFBD><EFBFBD>
|
|
|
|
|
|
CDNDBConnection* pDBCon = m_pSession->GetDBConnection();
|
|
|
|
|
|
pDBCon->QueryModNpcReputation( m_pSession, vData );
|
|
|
|
|
|
|
|
|
|
|
|
// <20><><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD>
|
|
|
|
|
|
if( bClientSend )
|
|
|
|
|
|
m_pSession->SendModReputation( vData );
|
|
|
|
|
|
}
|
|
|
|
|
|
#else
|
|
|
|
|
|
void CServerReputationSystemEventHandler::OnCommit( std::map<IReputationSystem*,int>& Reputation, bool bClientSend )
|
|
|
|
|
|
{
|
|
|
|
|
|
if( m_pSession == NULL || m_pSession->GetDBConnection() == NULL || m_pSession->GetReputationSystem() == NULL )
|
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
|
|
std::vector<TNpcReputation> vData;
|
|
|
|
|
|
m_pSession->GetReputationSystem()->GetCommitData( vData );
|
|
|
|
|
|
|
|
|
|
|
|
if( vData.empty() )
|
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
|
|
// DB M/W <20><><EFBFBD><EFBFBD>
|
|
|
|
|
|
CDNDBConnection* pDBCon = m_pSession->GetDBConnection();
|
|
|
|
|
|
pDBCon->QueryModNpcReputation( m_pSession, vData );
|
|
|
|
|
|
|
|
|
|
|
|
// <20><><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD>
|
|
|
|
|
|
if( bClientSend )
|
|
|
|
|
|
m_pSession->SendModReputation( vData );
|
|
|
|
|
|
}
|
|
|
|
|
|
#endif // #if defined( PRE_ADD_REPUTATION_EXPOSURE )
|
|
|
|
|
|
|
|
|
|
|
|
void CServerReputationSystemEventHandler::OnConnect( __time64_t tTime, bool bSend )
|
|
|
|
|
|
{
|
|
|
|
|
|
std::vector<int> vNpcData;
|
|
|
|
|
|
std::vector<TNpcReputation> vNpcReputation;
|
|
|
|
|
|
|
|
|
|
|
|
CReputationSystemRepository* pReputationSystem = m_pSession->GetReputationSystem();
|
|
|
|
|
|
pReputationSystem->GetAllNpcData( vNpcData );
|
|
|
|
|
|
|
|
|
|
|
|
for( UINT i=0 ; i<vNpcData.size() ; ++i )
|
|
|
|
|
|
{
|
|
|
|
|
|
vNpcReputation.push_back( TNpcReputation( vNpcData[i],
|
|
|
|
|
|
static_cast<int>(pReputationSystem->GetNpcReputation(vNpcData[i],IReputationSystem::NpcFavor)),
|
|
|
|
|
|
static_cast<int>(pReputationSystem->GetNpcReputation(vNpcData[i],IReputationSystem::NpcMalice)) ) );
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
#if defined( _VILLAGESERVER )
|
|
|
|
|
|
// 1<>ϴ<EFBFBD> <20><><EFBFBD>̴<EFBFBD> <20><>ġ
|
|
|
|
|
|
if( bSend == false && m_pSession->GetLastServerType() == SERVERTYPE_LOGIN )
|
|
|
|
|
|
{
|
|
|
|
|
|
CTimeSet timeSet;
|
|
|
|
|
|
__time64_t tLocalTime = timeSet.GetTimeT64_LC();
|
|
|
|
|
|
|
|
|
|
|
|
INT64 GapSec = tLocalTime-tTime;
|
|
|
|
|
|
int GapDay = static_cast<int>(GapSec/(60*60*24));
|
|
|
|
|
|
|
|
|
|
|
|
//if( GapDay > 0 ) // <20>ش<EFBFBD><D8B4><EFBFBD><EFBFBD><EFBFBD> <20>ӽ<EFBFBD> <20><>Ȱ<EFBFBD><C8B0>ȭ
|
|
|
|
|
|
if(0)
|
|
|
|
|
|
{
|
|
|
|
|
|
for( UINT i=0 ; i<vNpcData.size() ; ++i )
|
|
|
|
|
|
{
|
|
|
|
|
|
#if defined( _WORK )
|
|
|
|
|
|
WCHAR wszBuf[MAX_PATH];
|
|
|
|
|
|
int iBeforeFavor,iBeforeMalice = 0;
|
|
|
|
|
|
int iAfterFavor,iAfterMalice = 0;
|
|
|
|
|
|
#endif // #if defined( _WORK )
|
|
|
|
|
|
TReputeTableData* pReputationTable = g_pDataManager->GetReputeTableData( vNpcData[i] );
|
|
|
|
|
|
if( pReputationTable == NULL )
|
|
|
|
|
|
continue;
|
|
|
|
|
|
|
|
|
|
|
|
#if defined( _WORK )
|
|
|
|
|
|
iBeforeFavor = static_cast<int>(pReputationSystem->GetNpcReputation(vNpcData[i],IReputationSystem::NpcFavor));
|
|
|
|
|
|
iBeforeMalice = static_cast<int>(pReputationSystem->GetNpcReputation(vNpcData[i],IReputationSystem::NpcMalice));
|
|
|
|
|
|
#endif // #if defined( _WORK )
|
|
|
|
|
|
|
|
|
|
|
|
pReputationSystem->AddNpcReputation( vNpcData[i], IReputationSystem::NpcFavor, pReputationTable->iTakeFavorPerDay*GapDay*-1, false );
|
|
|
|
|
|
pReputationSystem->AddNpcReputation( vNpcData[i], IReputationSystem::NpcMalice, pReputationTable->iAddMalicePerDay*GapDay, false );
|
|
|
|
|
|
|
|
|
|
|
|
for( UINT j=0 ; j<vNpcReputation.size() ; ++j )
|
|
|
|
|
|
{
|
|
|
|
|
|
if( vNpcReputation[j].iNpcID == vNpcData[i] )
|
|
|
|
|
|
{
|
|
|
|
|
|
vNpcReputation[j].iFavorPoint = static_cast<int>(pReputationSystem->GetNpcReputation(vNpcData[i],IReputationSystem::NpcFavor));
|
|
|
|
|
|
vNpcReputation[j].iMalicePoint = static_cast<int>(pReputationSystem->GetNpcReputation(vNpcData[i],IReputationSystem::NpcMalice));
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
#if defined( _WORK )
|
|
|
|
|
|
iAfterFavor = static_cast<int>(pReputationSystem->GetNpcReputation(vNpcData[i],IReputationSystem::NpcFavor));
|
|
|
|
|
|
iAfterMalice = static_cast<int>(pReputationSystem->GetNpcReputation(vNpcData[i],IReputationSystem::NpcMalice));
|
|
|
|
|
|
wsprintf( wszBuf, L"[NPC:%d] %d<><64> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> Favor:%d->%d Malice:%d->%d", vNpcData[i], GapDay, iBeforeFavor, iAfterFavor, iBeforeMalice, iAfterMalice );
|
|
|
|
|
|
m_pSession->SendDebugChat( wszBuf );
|
|
|
|
|
|
#endif // #if defined( _WORK )
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
pReputationSystem->Commit( false );
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
#endif // #if defined( _VILLAGESERVER )
|
|
|
|
|
|
|
|
|
|
|
|
if( bSend )
|
|
|
|
|
|
{
|
|
|
|
|
|
m_pSession->SendReputationList( vNpcReputation );
|
|
|
|
|
|
m_pSession->SendUnionMembershipList(m_pSession->GetItem());
|
|
|
|
|
|
#if defined (_VILLAGESERVER)
|
|
|
|
|
|
m_pSession->SendUnionPoint();
|
|
|
|
|
|
#endif // #if defined (_VILLAGESERVER)
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
#endif // #if defined( PRE_ADD_NPC_REPUTATION_SYSTEM )
|