Files
2022-10-26 12:25:11 +08:00

432 lines
9.5 KiB
C++

#include "StdAfx.h"
#include ".\fatiguemanager.h"
#include "FatigueOptionParser.h"
#include "Player.h"
#include "GameZone.h"
FatigueManager::FatigueManager(void)
{
m_pPlayer = NULL;
m_pCurFatigueType = NULL;
m_nSecPlayTime = 0;
m_CurDay = 0;
m_Init = FALSE;
m_CurTickCount = 0;
m_PreTickCount = 0;
m_bApplyFatigue = FALSE;
}
FatigueManager::~FatigueManager(void)
{
}
VOID FatigueManager::SetPlayTime( int nSecPlayTime )
{
m_nSecPlayTime = nSecPlayTime;
SetDBPlayTime( m_nSecPlayTime/60 );
}
VOID FatigueManager::AddPlayTime( int nSecPlayTime )
{
m_nSecPlayTime += nSecPlayTime;
SetDBPlayTime( m_nSecPlayTime/60 );
}
BYTE FatigueManager::GetCurFatigueTypeNum()
{
if( !m_pCurFatigueType )
return 0;
return m_pCurFatigueType->m_byType;
}
BOOL FatigueManager::IsMsgTimeExpired()
{
if( (m_pCurFatigueType->m_wMsgInterval > 0) && (m_nSecRemainMsgTime <= 0) )
return TRUE;
return FALSE;
}
BOOL FatigueManager::CheckAuth()
{
if( !m_pPlayer ) return FALSE;
#ifdef __CN_OO0510__FATIGUE_MATCHING_UPDATE
if( (m_pPlayer->GetAge() >= 18) && (m_pPlayer->GetRealNameAuth() == 1) )
return FALSE;
#endif
return TRUE;
}
void FatigueManager::Init( Player * pPlayer )
{
ASSERT( pPlayer );
m_pPlayer = pPlayer;
SetInit( FALSE );
m_nSecRemainMsgTime = 0;
int nMinPlayTime = 0;
BASE_PLAYERINFO* pInfo = NULL;
if( !m_pPlayer || !( pInfo = m_pPlayer->GetCharInfo() ) )
{
SUNLOG( eCRITICAL_LOG, "没有当前玩家的信息." );
return;
}
#ifdef __CN_OO0510__FATIGUE_MATCHING_UPDATE
nMinPlayTime = m_pPlayer->GetPlayTime();
#else
nMinPlayTime = pInfo->m_PlayLimitedTime;
#endif
if( nMinPlayTime < 0 )
{
SUNLOG( eCRITICAL_LOG, "当前玩家的游戏时间小于0. Time = %d", nMinPlayTime );
return;
}
if( FatigueOptionParser::Instance()->IsUse() )
{
m_PlayingTimer.SetTimer( FatigueOptionParser::Instance()->GetCheckCycle() * 1000 * 60 );
SetApplyFatigue( TRUE );
}
else
{
SetApplyFatigue( FALSE );
m_PlayingTimer.DisableCheckTime();
return;
}
SetPlayTime( nMinPlayTime * 60 );
SetPreTickCount( GetTickCount() );
#ifndef __CN_OO0510__FATIGUE_MATCHING_UPDATE
SYSTEMTIME sysTime; util::TimeSync::GetLocalTime( &sysTime );
SetCurDay( sysTime.wDay );
if( !CheckMaxPlayTime( sysTime ) )
SetPlayTime(0);
#endif //__CN_OO0510__FATIGUE_MATCHING_UPDATE
_FATIGUE_TYPE* pFatigueType = FatigueOptionParser::Instance()->GetFatigueTypeFromTime( GetMinutePlayTime() );
if( !pFatigueType )
{
SUNLOG( eCRITICAL_LOG, "当前玩家的游戏时间不存在疲劳类型.[%s], Time = %d", m_pPlayer->GetCharName(), GetMinutePlayTime() );
return;
}
else
{
m_pCurFatigueType = pFatigueType;
int nMinMsgRemainTime = 0;
if( nMinPlayTime == 0 )
{
nMinMsgRemainTime = m_pCurFatigueType->m_wMsgInterval;
}
else
{
int nMod = ( nMinPlayTime - m_pCurFatigueType->m_nStartTime ) % m_pCurFatigueType->m_wMsgInterval;
nMinMsgRemainTime = m_pCurFatigueType->m_wMsgInterval - nMod;
}
if( nMinMsgRemainTime <= 0 )
{
SUNLOG( eCRITICAL_LOG, "奇怪的信息间隔. [%s], MsgTime = %d", m_pPlayer->GetCharName(), GetMinutePlayTime() );
}
m_nSecRemainMsgTime = nMinMsgRemainTime*60;
}
SetInit( TRUE );
}
VOID FatigueManager::Update()
{
if( !IsApplyFatigue() || !GetInit() )
return;
if( m_PlayingTimer.IsExpired() )
{
InitTickCount();
if( FatigueOptionParser::Instance()->GetInitType() == FATIGUE_INIT_MIDNIGHT )
{
SYSTEMTIME sysTime;
util::TimeSync::GetLocalTime( &sysTime );
if( sysTime.wDay != GetCurDay() )
{
SetPlayTime(0);
SetCurDay( sysTime.wDay );
SetPreTickCount( GetCurTickCount() );
SendTimeMessage();
return;
}
}
else if( FatigueOptionParser::Instance()->GetInitType() == FATIGUE_INIT_OFFLINE )
{
//如果不是午夜,就是和中国一样的线下时间。这由DB处理。
}
else
{
SUNLOG( eCRITICAL_LOG, "奇怪的初始化类型. [%s] Type = %d", m_pPlayer->GetCharName(), FatigueOptionParser::Instance()->GetInitType() );
}
if( CanApplyFatigue() )
{
int nSecDiffTick = (int)(GetDiffTickCount() / 1000);
AddPlayTime( nSecDiffTick );
m_nSecRemainMsgTime -= nSecDiffTick;
}
SetPreTickCount( GetCurTickCount() );
}
if( IsMsgTimeExpired() )
{
m_nSecRemainMsgTime = m_pCurFatigueType->m_wMsgInterval*60;
SendTimeMessage();
}
if( (m_pCurFatigueType->m_nEndTime != -1) && (m_pCurFatigueType->m_nEndTime <= GetMinutePlayTime()) )
ChangeFatigueType();
}
BOOL FatigueManager::ChangeFatigueType()
{
_FATIGUE_TYPE* pFatigueType = FatigueOptionParser::Instance()->GetFatigueTypeFromTime( GetMinutePlayTime() );
if( pFatigueType && m_pCurFatigueType )
{
if( pFatigueType->m_byType != m_pCurFatigueType->m_byType )
{
m_pCurFatigueType = pFatigueType;
m_nSecRemainMsgTime = m_pCurFatigueType->m_wMsgInterval*60;
}
return TRUE;
}
else
{
SUNLOG( eCRITICAL_LOG, "当前游戏累计时间的疲劳度类型不存在.[%s] Type=%d", m_pPlayer->GetCharName(), pFatigueType->m_byType );
}
return FALSE;
}
VOID FatigueManager::InitTickCount()
{
SetCurTickCount( GetTickCount() );
}
BOOL FatigueManager::CheckMaxPlayTime( SYSTEMTIME& sysTime )
{
DWORD dwMaxTime = sysTime.wHour*60*60 + sysTime.wMinute*60 + sysTime.wSecond;
if( dwMaxTime < (DWORD)GetPlayTime() )
{
SUNLOG( eFULL_LOG, "游戏累计时间异常的玩家(单位:秒)[%s]CurTime=%u<Time=%u", m_pPlayer->GetCharName(), dwMaxTime, GetPlayTime() );
return FALSE;
}
return TRUE;
}
BOOL FatigueManager::SetDBPlayTime( int nPlayTime )
{
#ifdef __CN_OO0510__FATIGUE_MATCHING_UPDATE
if( !m_pPlayer )
{
SUNLOG( eCRITICAL_LOG, "没有可用疲劳度的用户信息." );
return FALSE;
}
m_pPlayer->SetPlayTime( nPlayTime );
#else
BASE_PLAYERINFO* pInfo = NULL;
if( !m_pPlayer || !( pInfo = m_pPlayer->GetCharInfo() ) )
{
SUNLOG( eCRITICAL_LOG, "没有可用疲劳度的默认用户信息." );
return FALSE;
}
pInfo->m_PlayLimitedTime = nPlayTime;
#endif
return TRUE;
}
BOOL FatigueManager::CanApplyFatigue()
{
if( !m_pPlayer ) return FALSE;
FatigueOptionParser* const pFatigueOptionParser = FatigueOptionParser::Instance();
if( !pFatigueOptionParser->ApplyInSSQField() )
{
sPOLICY_CHARACTER& rPolicyment = m_pPlayer->Policyment;
if( rPolicyment.FIELD & rPolicyment.PCC_IN_SSQ_FIELD_PLAYER )
return FALSE;
}
if( !pFatigueOptionParser->ApplyVillageTime() && m_pPlayer->GetGameZoneState() == ePRS_AT_VILLAGE )
return FALSE;
if( !pFatigueOptionParser->ApplyLobbyTime() && m_pPlayer->GetGameZoneState() == ePRS_AT_LOBBY )
return FALSE;
if( !pFatigueOptionParser->ApplySuperMaster() )
{
GameZone *pZone = m_pPlayer->GetGameZonePtr();
if( pZone && pZone->CanApplySuperMasterBenefit( m_pPlayer ) )
return FALSE;
}
if( !pFatigueOptionParser->ApplyDeadTime() && m_pPlayer->GetHP() == 0 )
return FALSE;
return TRUE;
}
void FatigueManager::SendTimeMessage( )
{
if( !m_pPlayer ) return;
MSG_CG_STATUS_FATIGUE_CHANGE_CMD msg;
msg.m_wPlayingTime = GetMinutePlayTime();
m_pPlayer->SendPacket( &msg, sizeof(MSG_CG_STATUS_FATIGUE_CHANGE_CMD) );
}
BYTE FatigueManager::GetItemDropRatio( )
{
BYTE byDropRatio = 100;
if( !IsApplyFatigue() ) return byDropRatio;
_FATIGUE_TYPE* pFatigueType = GetCurFatigueType();
if( pFatigueType )
byDropRatio = pFatigueType->m_byItemDropRatio;
return byDropRatio;
}
BYTE FatigueManager::GetExpRatio( )
{
BYTE byExpRatio = 100;
if( !IsApplyFatigue() ) return byExpRatio;
_FATIGUE_TYPE* pFatigueType = GetCurFatigueType();
if( pFatigueType )
byExpRatio = pFatigueType->m_byExpRatio;
return byExpRatio;
}
BOOL FatigueManager::GetItemPickUp()
{
BOOL bItemPickUp = TRUE;
if( !IsApplyFatigue() ) return bItemPickUp;
_FATIGUE_TYPE* pFatigueType = GetCurFatigueType();
if( pFatigueType )
bItemPickUp = pFatigueType->m_bItemPickUp;
return bItemPickUp;
}
BYTE FatigueManager::GetShareItemPickupRatio()
{
BYTE byPickupRatio = 100;
if( !IsApplyFatigue() ) return byPickupRatio;
_FATIGUE_TYPE* pFatigueType = GetCurFatigueType();
if( pFatigueType )
byPickupRatio = pFatigueType->m_bySharedItemPickupRatio;
return byPickupRatio;
}
BYTE FatigueManager::GetShareHeimPickupRatio()
{
BYTE byPickupRatio = 100;
if( !IsApplyFatigue() ) return byPickupRatio;
_FATIGUE_TYPE* pFatigueType = GetCurFatigueType();
if( pFatigueType )
byPickupRatio = pFatigueType->m_bySharedHeimPickupRatio;
return byPickupRatio;
}
BOOL FatigueManager::IsApplyFatigue()
{
if( !m_bApplyFatigue ) return FALSE;
if( !CheckAuth() ) return FALSE;
return TRUE;
}
_FATIGUE_TYPE* FatigueManager::GetCurFatigueType()
{
const BYTE fatigueTypeNum = GetCurFatigueTypeNum();
_FATIGUE_TYPE* pFatigueType =
FatigueOptionParser::Instance()->GetFatigueType( fatigueTypeNum );
if( !pFatigueType )
{
SUNLOG( eDEV_LOG, "[FatigueManager::GetCurFatigueType] Type = %d, "
"没有设置在该时间(%u)的疲劳度信息.",
fatigueTypeNum, GetMinutePlayTime() );
}
return pFatigueType;
}
BOOL FatigueManager::GetItemReward()
{
BOOL bItemReward = TRUE;
if( !IsApplyFatigue() ) return bItemReward;
_FATIGUE_TYPE* pFatigueType = GetCurFatigueType();
if( pFatigueType )
bItemReward = pFatigueType->m_bItemReward;
return bItemReward;
}
BYTE FatigueManager::GetHeimRewardRatio()
{
BYTE byHeimRatio = 100;
if( !IsApplyFatigue() ) return byHeimRatio;
_FATIGUE_TYPE* pFatigueType = GetCurFatigueType();
if( pFatigueType )
byHeimRatio = pFatigueType->m_byHeimRewardRatio;
return byHeimRatio;
}
BYTE FatigueManager::GetExpRewardRatio()
{
BYTE byExpRatio = 100;
if( !IsApplyFatigue() ) return byExpRatio;
_FATIGUE_TYPE* pFatigueType = GetCurFatigueType();
if( pFatigueType )
byExpRatio = pFatigueType->m_byExpRewardRatio;
return byExpRatio;
}