DragonNest/Server/DNGameServer/MasterRewardSystem.cpp

252 lines
16 KiB
C++
Raw Normal View History

2024-12-20 16:56:44 +08:00
<EFBFBD><EFBFBD>
#include "Stdafx.h"
#include "MasterRewardSystem.h"
#include "DNUserSession.h"
#include "DNGameRoom.h"
#include "DnGameTask.h"
#include "DNGameDataManager.h"
#include "DNDBConnection.h"
using namespace MasterSystem;
CRewardSystem::CRewardSystem( CDNGameRoom* pGameRoom )
:m_pGameRoom(pGameRoom)
{
}
void CRewardSystem::Update( CDNUserSession* pSession, TAGetMasterSystemCountInfo* pPacket )
{
TCountInfo Info( pPacket->iMasterCount, pPacket->iPupilCount, pPacket->iClassmateCount );
if( Info.bIsAllZero() )
{
std::map<INT64,TCountInfo>::iterator itor = m_mCountRepository.find( pPacket->biCharacterDBID );
if( itor == m_mCountRepository.end() )
return;
m_mCountRepository.erase( itor );
}
else
{
std::map<INT64,TCountInfo>::iterator itor = m_mCountRepository.find( pPacket->biCharacterDBID );
if( itor == m_mCountRepository.end() )
{
m_mCountRepository.insert( std::make_pair(pPacket->biCharacterDBID,Info) );
}
else
{
if( (*itor).second != Info )
(*itor).second = Info;
}
}
if( pPacket->bClientSend == true )
{
if( pSession )
pSession->SendMasterSystemCountInfo( Info.iMasterCount, Info.iPupilCount, Info.iClassmateCount );
}
}
void CRewardSystem::GetCountInfo( CDNUserSession* pSession, TCountInfo& CountInfo )
{
CountInfo.Clear();
if( pSession == NULL )
return;
std::map<INT64,TCountInfo>::iterator itor = m_mCountRepository.find( pSession->GetCharacterDBID() );
if( itor != m_mCountRepository.end() )
CountInfo = (*itor).second;
}
void CRewardSystem::RequestRefresh()
{
for( UINT i=0 ;i<m_pGameRoom->GetUserCount() ; ++i )
{
CDNUserSession* pSession = m_pGameRoom->GetUserData(i);
if( pSession && pSession->GetState() == SESSION_STATE_GAME_PLAY )
pSession->QueryGetMasterSystemCountInfo( true );
}
}
const CRewardSystem::TCountInfo* CRewardSystem::GetCountInfo( CDNUserSession* pSession )
{
if( pSession == NULL )
return NULL;
if( m_mCountRepository.empty() )
return NULL;
std::map<INT64,TCountInfo>::iterator itor = m_mCountRepository.find( pSession->GetCharacterDBID() );
if( itor == m_mCountRepository.end() )
return NULL;
return &(*itor).second;
}
bool CRewardSystem::bIsDurabilityReward( CDNUserSession* pSession )
{
const TCountInfo* pCountInfo = GetCountInfo( pSession );
if( pCountInfo == NULL )
return false;
// Ȑ<EFBFBD>@<EFBFBD> <EFBFBD>t<EFBFBD> <EFBFBD><EFBFBD>t<EFBFBD><EFBFBD>t<EFBFBD>|<EFBFBD>t<EFBFBD> <EFBFBD><EFBFBD>l<EFBFBD>ij <EFBFBD><EFBFBD><EFBFBD><EFBFBD>.
if( pCountInfo->iPupilCount > 0 )
return true;
return false;
}
bool CRewardSystem::bIsFatigueReward( CDNUserSession* pSession )
{
// ֬<EFBFBD> 0<EFBFBD><EFBFBD><EFBFBD>@<EFBFBD> <EFBFBD><EFBFBD>l<EFBFBD>ij <EFBFBD><EFBFBD><EFBFBD><EFBFBD> <EFBFBD><EFBFBD> <<EFBFBD>\<EFBFBD>ij <EFBFBD><EFBFBD><EFBFBD><EFBFBD> <EFBFBD>ȴ<EFBFBD><EFBFBD> <EFBFBD>t<EFBFBD> L<EFBFBD>8<EFBFBD><EFBFBD><EFBFBD> <EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><<EFBFBD>\<EFBFBD> <<EFBFBD>\<EFBFBD>ij<EFBFBD><EFBFBD><EFBFBD><EFBFBD> <EFBFBD><EFBFBD>l<EFBFBD> h<EFBFBD><EFBFBD>|<EFBFBD> <EFBFBD><EFBFBD><EFBFBD><EFBFBD>.
return bIsDurabilityReward( pSession );
}
float CRewardSystem::GetExpRewardRate( CDNUserSession* pSession )
{
const TCountInfo* pCountInfo = GetCountInfo( pSession );
if( pCountInfo == NULL )
return 0.f;
// Ȑ<EFBFBD><EFBFBD> <EFBFBD>ǔ<EFBFBD> <EFBFBD><EFBFBD><EFBFBD><EFBFBD>
if( pCountInfo->iPupilCount > 0 )
{
return MasterSystem::Reward::PupilCountExpBonusRate/100.f;
}
// <EFBFBD>¹<EFBFBD>t<EFBFBD> <EFBFBD><EFBFBD>p<EFBFBD><EFBFBD><EFBFBD> ٳ0<EFBFBD><EFBFBD> <EFBFBD>ǔ<EFBFBD> <EFBFBD><EFBFBD><EFBFBD><EFBFBD>
else if( pCountInfo->iMasterCount > 0 || pCountInfo->iClassmateCount > 0 )
{
return ((pCountInfo->iMasterCount*CGlobalWeightTable::GetInstance().GetValue( CGlobalWeightTable::MasterSystem_MasterCountExpBonusRate ))
+(pCountInfo->iClassmateCount*CGlobalWeightTable::GetInstance().GetValue( CGlobalWeightTable::MasterSystem_ClassmateCountExpBonusRate )));
}
return 0.f;
}
float CRewardSystem::GetTreasureBoxRewardRate( CDNUserSession* pSession )
{
const TCountInfo* pCountInfo = GetCountInfo( pSession );
if( pCountInfo == NULL )
return 0.f;
// <EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>t<EFBFBD>t<EFBFBD> <EFBFBD><EFBFBD><<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
if( pCountInfo->iPupilCount > 0 || pCountInfo->iMasterCount )
return CGlobalWeightTable::GetInstance().GetValue( CGlobalWeightTable::MasterSystem_TreasureBoxBonusRate );
return 0.f;
}
void CRewardSystem::RequestDungeonClear( CDNUserSession* pSession )
{
const TCountInfo* pCountInfo = GetCountInfo( pSession );
if( pCountInfo == NULL )
return;
CDNGameRoom* pGameRoom = pSession->GetGameRoom();
if( pGameRoom == NULL || pGameRoom->GetGameTask() == NULL )
return;
if( pCountInfo->iPupilCount > 0 )
{
DNTableFileFormat *pMapSox = GetDNTable( CDnTableDB::TMAP );
DNTableFileFormat *pEnterDungeonSox = GetDNTable( CDnTableDB::TDUNGEONENTER );
if( pMapSox == NULL || pEnterDungeonSox == NULL )
return;
if( !pMapSox->IsExistItem( pGameRoom->GetGameTask()->GetEnterMapTableID() ) )
return;
int nDungeonEnterTableID = pMapSox->GetFieldFromLablePtr( pGameRoom->GetGameTask()->GetEnterMapTableID(), "_EnterConditionTableID" )->GetInteger();
if( nDungeonEnterTableID < 1 || !pEnterDungeonSox->IsExistItem( nDungeonEnterTableID ) )
return;
int nLevel = pEnterDungeonSox->GetFieldFromLablePtr( nDungeonEnterTableID, "_LvlMin" )->GetInteger();
//
TMasterSystemGainTableData* pGainTable = g_pDataManager->GetMasterSystemGainTableData( nLevel, pGameRoom->m_StageDifficulty );
if( pGainTable == NULL )
return;
if( pSession->CheckDBConnection() == false )
return;
// <EFBFBD> <EFBFBD>X<EFBFBD> ȩ<EFBFBD>
if( pGainTable->iRepectPoint > 0 )
pSession->GetDBConnection()->QueryModMasterSystemRespectPoint( pSession, pGainTable->iRepectPoint );
// <EFBFBD><EFBFBD><EFBFBD> 8<EFBFBD><EFBFBD>ij ȩ<EFBFBD>
if( pGainTable->iFavorPoint > 0 )
{
for( int i=0 ; i<pSession->GetMasterSystemData()->SimpleInfo.cCharacterDBIDCount ; ++i )
{
// t<EFBFBD><EFBFBD><EFBFBD> Ȑ<EFBFBD><EFBFBD> <EFBFBD>t<EFBFBD> DungeonClear <EFBFBD><EFBFBD>а?
if( pGameRoom->GetUserSessionByCharDBID( pSession->GetMasterSystemData()->SimpleInfo.OppositeInfo[i].CharacterDBID) == NULL )
continue;
pSession->GetDBConnection()->QueryModMasterSystemFavorPoint( pSession, pSession->GetCharacterDBID(), pSession->GetMasterSystemData()->SimpleInfo.OppositeInfo[i].CharacterDBID, pGainTable->iFavorPoint );
pSession->GetDBConnection()->QueryGetMasterSystemSimpleInfo( pSession->GetDBThreadID(), pSession, true, MasterSystem::EventType::DungeonClear );
pSession->QueryGetMasterSystemCountInfo( true );
}
}
}
}
int CRewardSystem::GetMasterSystemAddExp( CDNUserSession* pSession, float fExp, bool bStageClear )
{
const TCountInfo* pCountInfo = GetCountInfo( pSession );
if( pCountInfo == NULL )
return 0;
TPlayerCommonLevelTableInfo* pPlayerCommonLevelTableInfo = g_pDataManager->GetPlayerCommonLevelTable(pSession->GetLevel());
if( !pPlayerCommonLevelTableInfo )
return 0;
float fReturn = 0;
// <EFBFBD>¹<EFBFBD>|<EFBFBD>L<EFBFBD>
if( pCountInfo->iPupilCount > 0 )
{
if( bStageClear )
fReturn = (pPlayerCommonLevelTableInfo->fMasterGainExp*(pSession->GetTotalMasterDecreaseFatigue()+pSession->GetDecreaseFatigue())*pCountInfo->iPupilCount);
else
fReturn = fExp;
int nAddPercent = 0;
for(int i=0; i<pSession->GetMasterSystemData()->SimpleInfo.cCharacterDBIDCount; ++i)
{
// t<EFBFBD><EFBFBD><EFBFBD> Ȑ<EFBFBD><EFBFBD> <EFBFBD>t<EFBFBD> DungeonClear <EFBFBD><EFBFBD>а?
if( pSession->GetMasterSystemData()->SimpleInfo.OppositeInfo[i].CharacterDBID
&& m_pGameRoom->GetUserSessionByCharDBID( pSession->GetMasterSystemData()->SimpleInfo.OppositeInfo[i].CharacterDBID) == NULL )
continue;
nAddPercent += g_pDataManager->GetMasterSysFeelAddExp(pSession->GetMasterSystemData()->SimpleInfo.OppositeInfo[i].nFavorPoint );
}
fReturn = (fReturn*(nAddPercent/100.f));
}
else if( pCountInfo->iMasterCount > 0 )
{
// Ȑ<EFBFBD>|<EFBFBD>L<EFBFBD>..
int nAddPercent = 0;
for(int i=0; i<pSession->GetMasterSystemData()->SimpleInfo.cCharacterDBIDCount; ++i)
{
// t<EFBFBD><EFBFBD><EFBFBD> <EFBFBD>¹<EFBFBD>t<EFBFBD> <EFBFBD>t<EFBFBD> DungeonClear <EFBFBD><EFBFBD>а?
if( pSession->GetMasterSystemData()->SimpleInfo.OppositeInfo[i].CharacterDBID
&& m_pGameRoom->GetUserSessionByCharDBID( pSession->GetMasterSystemData()->SimpleInfo.OppositeInfo[i].CharacterDBID) == NULL )
continue;
nAddPercent += g_pDataManager->GetMasterSysFeelAddExp(pSession->GetMasterSystemData()->SimpleInfo.OppositeInfo[i].nFavorPoint );
}
fReturn = fExp*(nAddPercent/100.f);
}
return (int)fReturn;
}
void CRewardSystem::UpdateFavor( CDNUserSession* pSession, INT64 biPupilCharacterDBID, int nAddFavor)
{
for( int i=0 ; i<pSession->GetMasterSystemData()->SimpleInfo.cCharacterDBIDCount ; ++i )
{
// t<EFBFBD><EFBFBD><EFBFBD> Ȑ<EFBFBD><EFBFBD> <EFBFBD>t<EFBFBD> DungeonClear <EFBFBD><EFBFBD>а?
if( pSession->GetMasterSystemData()->SimpleInfo.OppositeInfo[i].CharacterDBID == biPupilCharacterDBID )
{
(const_cast<TMasterSystemData*>(pSession->GetMasterSystemData()))->SimpleInfo.OppositeInfo[i].nFavorPoint += nAddFavor;
break;
}
}
}