⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 player.cpp

📁 奇迹世界 部分源代码奇迹世界 部分源代码奇迹世界 部分源代码
💻 CPP
📖 第 1 页 / 共 2 页
字号:
// Player.cpp: implementation of the Player class.
//
//////////////////////////////////////////////////////////////////////
#include "stdafx.h"
#include "Player.h"
#include <iostream>
#include <assert.h>
#include <PacketStruct_AG.h>
#include "Map.h"
#include "Field.h"
#include "PlayerManager.h"
#include "ItemManager.h"
#include "ServerSession.h"
#include "NPC.h"
#include "SkillInfoParser.h"
#include "CharacterFormula.h"
#include "PublicMath.h"
#include "GameServer.h"
#include "MissionManager.h"
#include "QuestManager.h"
#include "TradeSlotContainer.h"
#include "TradeManager.h"
#include "VendorManager.h"
#include <SimpleModulus.h>
#include "SummonManager.h"
#include "SummonedNPCs.h"
#include "SlotManager.h"
#include "SkillManager.h"
#include "QuickManager.h"
#include "QuickStyleManager.h"
#include "MovementChecker.h"
#include "GameZone.h"
#include "TriggerManager.h"
#include <GMList.h>
#include "FileParser.h"
#include "WZTime.h"
#include "EtcStatus.h"
#include "StatusManager.h"
#include "RecoverStatus.h"
#include "PVPInfo.h"
#include "MoveStateControl.h"
#include "WZTime.h"
#include "AIParamParser.h"
#include "EventInventorySlotContainer.h"

using namespace std;

Player::Player():
m_pServerSession ( NULL ),
m_dwNextExp( 0 )
{
	SetObjectType( PLAYER_OBJECT );
	m_pItemManager			= new ItemManager;
	m_pSlotManager			= new SlotManager;
	m_pMissionManager		= new MissionManager;
	m_pQuestManager			= new QuestManager;
	m_pSkillManager			= new SkillManager;
	m_pQuickManager			= new QuickManager;
	m_pStyleManager			= new QuickStyleManager;
	m_pMovementChecker		= new MovementChecker;
	m_pPVPInfo				= new PVPInfo(this);

	m_pEventSlotContainer	= new EventInventorySlotContainer;
	m_Attr.SetOwner( this );
	m_bExpiredPlayer = TRUE;
	SetInvitationHostKey( 0 );
}

Player::~Player()
{
	SAFE_DELETE( m_pPVPInfo );
	SAFE_DELETE( m_pEventSlotContainer );
	SAFE_DELETE( m_pSlotManager );
	SAFE_DELETE( m_pItemManager );
	SAFE_DELETE( m_pMissionManager );
	SAFE_DELETE( m_pQuestManager );
	SAFE_DELETE( m_pSkillManager );
	SAFE_DELETE( m_pQuickManager );
	SAFE_DELETE( m_pStyleManager );
	SAFE_DELETE( m_pMovementChecker );
}


BOOL Player::Init()
{
	m_bExpiredPlayer = FALSE;

	m_pSlotManager->Init( this );
	m_pItemManager->Init( m_pSlotManager );
	m_pSkillManager->Init( m_pSlotManager );
	m_pQuickManager->Init( m_pSlotManager );
	m_pStyleManager->Init( m_pSlotManager );
	m_pEventSlotContainer->ClearAll();				//< 捞亥飘 牢亥配府 努府绢
	m_pEventSlotContainer->SetPlayer(this);

	m_pMovementChecker->Reset();
	

	m_DBPUpdateTimer.SetTimer( _DBP_UPDATE_CYCLE_DELAY );

	m_pMoveStateControl->Init( this, CMS_RUN );

	// 酿鸥烙 汲沥
	SCCharacter::SetCoolTime( TRUE, SKILL_COOLTIME_MARGIN );
	SCPlayer::SetItemCoolTime( TRUE, SKILL_COOLTIME_MARGIN );

	StopMoving();
	SetTradeContainer(NULL);
	SetVendorContainer(NULL);
	SetBehave(PLAYER_BEHAVE_IDLE_STATE);
	SetInvitationHostKey( 0 );

	m_pPVPInfo->Init();					//< PVPInfo 檬扁拳

	m_dwLastSendTick	= GetTickCount();
	m_dwSentSize		= 0;
	m_bDoingAction		= FALSE;
	m_byVkrReloadCount	= MAX_VALKYRIE_RELOAD_COUNT;
	m_PlayingTimer.SetTimer( PLAYTIME_UPDATE_CYCLE );
	m_ShapShotLogTimer.SetTimer( SNAPSHOT_LOG_CYCLE );

	//眠啊 捞悼加档厚啦 扁夯蔼 1
	m_fAddMoveSpeedRatio = 1.0f;

	SetMoveState( CMS_RUN );

	if (Character::Init())
	{
		// 檬扁拳瞪锭 促澜 肪诀 版氰摹 汲沥
		m_dwNextExp = 0;		// 快急 0捞搁 AddExp俊辑 汲沥窍档废 窍磊

		return TRUE;
	}

	return FALSE;
}

VOID Player::Release()
{
	m_bExpiredPlayer = TRUE;
	if( GetBehave() == PLAYER_BEHAVE_TRADE_STATE )
	{
		Player * pPlayer = GetTradeContainer()->GetCounterPlayer();
		g_TradeManager.DestroyTradeContainer( this );

		MSG_CG_TRADE_CANCEL_CMD cmsg;
		pPlayer->SendPacket( &cmsg, sizeof(cmsg) );
	}
	else if( GetBehave() == PLAYER_BEHAVE_VENDOR_ESTABLISHER_STATE )
	{
		RC::eVENDOR_RESULT rt = g_VendorManager.EndVendor( this );
		ASSERT( rt == RC::RC_VENDOR_SUCCESS );
		MSG_CG_VENDOR_END_BRD bmsg;
		bmsg.m_dwPlayerKey = GetObjectKey();
		SendPacketAround( &bmsg, sizeof(bmsg), FALSE );
	}
	else if( GetBehave() == PLAYER_BEHAVE_VENDOR_OBSERVER_STATE )
	{
		RC::eVENDOR_RESULT rt = g_VendorManager.EndViewVendor( this );
		ASSERT( rt == RC::RC_VENDOR_SUCCESS );
	}

	m_pSlotManager->Release();
	m_pQuickManager->Release();
	m_pStyleManager->Release();
	m_pItemManager->Release();
	m_pSkillManager->Release();

	// 酿鸥烙 秦力
	SCCharacter::FreeCoolTime( TRUE );
	SCPlayer::FreeItemCoolTime( TRUE );

	Character::Release();
	m_Attr.Clear();
}

VOID Player::Create( ServerSession * pServerSession, KEYTYPE UserKey, const TCHAR * pszID )
{
	ASSERT( pServerSession );
	ASSERT( pServerSession->GetServerType() == AGENT_SERVER );
	SetServerSession( pServerSession );
	SetUserKey( UserKey );
	SetState( PLAYER_CREATED );
	SetUserID( pszID );

}

VOID Player::Destroy()
{
	SetServerSession( NULL );
	SetUserKey( 0 );
	SetState( PLAYER_DESTROYED );
}

VOID Player::Update( DWORD dwDeltaTick )
{
	Character::Update( dwDeltaTick );

	if( m_DBPUpdateTimer.IsExpired() )
	{
		/// DBProxy肺 诀单捞飘 菩哦阑 朝赴促.
		SerializeInfoToDBProxy();
	}

	// 敲饭捞鸥烙 盎脚(盒窜困)
	if( m_PlayingTimer.IsExpired() )
	{
		GetCharInfo()->m_PlayLimitedTime += PLAYTIME_UPDATE_CYCLE / 60000;

		// 泅犁 矫埃捞 24矫(0矫)甫 逞菌栏搁 檬扁拳茄促.
		SYSTEMTIME sysTime;		GetLocalTime( &sysTime );
		if( (sysTime.wHour == 23 && sysTime.wMinute == 59) || (sysTime.wHour == 0 && sysTime.wMinute == 0) )
		{
			GetCharInfo()->m_PlayLimitedTime = 0;
		}
	}

	// 咀记 掉饭捞 眉农
	if( IsDoingAction() && IsActionExpired() )
	{
		SetActionDelay( 0 );
	}

	if( IsMoving() )
	{
		float fMoveSpeed = m_pMoveStateControl->GetMoveSpeed();

		// 胶乔靛琴 眉目 捞悼加档 函版(加档啊 官诧 泅犁 困摹甫 持绢霖促)
		WzVector wvSpeedChangedPos;		GetPos( &wvSpeedChangedPos );
		GetMovementChecker()->SetMoveSpeed( fMoveSpeed * 1000, wvSpeedChangedPos );

		// 捞悼 傈 冀磐 牢郸胶
		DWORD dwPrevSectorIndex = GetSectorIndex();

		// 捞悼阑 茄促.
		PathProgress( (float)dwDeltaTick * fMoveSpeed );

		// 捞悼 饶 冀磐 牢郸胶
		WzVector wvCurPos;		GetPos( &wvCurPos );
		DWORD dwAfterSectorIndex = GetField()->GetSectorIndex( &wvCurPos );

		// Sector啊 函版登菌阑 版快
		if( dwPrevSectorIndex != dwAfterSectorIndex )
		{
			SetOldSectorIndex( dwPrevSectorIndex );
			SetSectorIndex( dwAfterSectorIndex );
			GetField()->ChangeSector( this );
		}
	}

	// 胶忱鸡 肺弊 眠啊.
	// 老沥矫埃捞 瘤唱搁 捞 何盒 龋免..
	if( m_ShapShotLogTimer.IsExpired() )
		GAMELOG->WriteSnapShot( this, g_pGameServer->GetServerGUID() );
}

//-------------------------------------------------------------------------------------------------
// 菩哦 Send 棺 技记 包访
//-------------------------------------------------------------------------------------------------
BOOL Player::SendPacket( MSG_BASE_FORWARD * pMsg, WORD wSize, BOOL bCrypt )
{
	static BYTE byEncryptBuf[10000];

	pMsg->m_dwKey = GetUserKey();

	if( bCrypt )
	{
		ASSERT( wSize < 10000 );
		// 墨抛绊府 most bit 悸泼
		pMsg->m_byCategory |= 0x01 << 7;
		// 鞠龋拳
		wSize = g_pEncryptor->Encrypt( byEncryptBuf, pMsg, wSize );
		pMsg = (MSG_BASE_FORWARD*)byEncryptBuf;
	}

	////////////////////////////////////////////////////////////////////////////////////
	// for dubugging
#ifdef _DEBUG
	DWORD curTick = GetTickCount();
	if( curTick - m_dwLastSendTick >= 1000 )
	{
		if( m_dwSentSize > 2000 )
		{
			SUNLOG( eMIDDLE_LOG,  "[Player::SendPacket] %d bytes have sent per second. PlayerObjectKey(%d)", m_dwSentSize, GetObjectKey() );
		}
		m_dwSentSize = 0;
		m_dwLastSendTick = curTick;
	}
	m_dwSentSize += wSize;
#endif
	////////////////////////////////////////////////////////////////////////////////////

	return m_pServerSession->Send( (BYTE*)pMsg, wSize );
}

BOOL Player::SendExPacket( DWORD dwNumberOfMessages, BYTE **pMsg, WORD *pwSize )
{
	MSG_BASE_FORWARD *pSendMsg = (MSG_BASE_FORWARD*)pMsg[0];

	pSendMsg->m_dwKey = GetUserKey();

	return m_pServerSession->SendEx( dwNumberOfMessages, pMsg, pwSize );
}
BOOL Player::SendToGuildServer( MSG_BASE_FORWARD * pMsg, WORD wSize )
{
	ASSERT( g_pGameServer );
	pMsg->m_dwKey = GetUserKey();
	return g_pGameServer->SendToGuildServer( pMsg, wSize );
}
BOOL Player::SendToGameDBPServer( MSG_BASE_FORWARD * pMsg, WORD wSize )
{
	ASSERT( g_pGameServer );
	pMsg->m_dwKey = GetUserKey();
	return g_pGameServer->SendToGameDBPServer( pMsg, wSize );
}
VOID Player::ForceDisconnect( eDISCONNECT_REASON Reason )
{
	MSG_AG_CONNECTION_UNREGISTER_CMD msg;
	msg.m_byCategory	= AG_CONNECTION;
	msg.m_byProtocol	= AG_CONNECTION_UNREGISTER_CMD;
	SendPacket( &msg, sizeof(msg) );
}

//-------------------------------------------------------------------------------------------------
// 鞘靛 立加 棺 唱啊扁
//-------------------------------------------------------------------------------------------------
VOID Player::OnEnterField(Field* pField, WzVector* pwzVec)
{
	Character::OnEnterField(pField, pwzVec);

	SetState(PLAYER_MAP_ENTER);	

	AIParamInfo& stAIParamInfo = AIParamParser::Instance()->GetInfo();

	// 滚辑目客 绩档快绰 HP, MP 府哩 林扁啊 促福促.
	if( GetCharType() == eCHAR_BERSERKER || GetCharType() == eCHAR_SHADOW )
	{
		// HP 府哩
		m_pStatusManager->AllocStatus( eCHAR_STATE_ETC_AUTO_RECOVER_HP, BASE_EXPIRE_TIME_INFINITY, stAIParamInfo.m_wPLAYER_HP_REGEN_PERIOD );

		// MP 府哩
		m_pStatusManager->AllocStatus( eCHAR_STATE_ETC_AUTO_RECOVER_MP, BASE_EXPIRE_TIME_INFINITY, stAIParamInfo.m_wPLAYER_MP_REGEN_PERIOD );
	}
	else
	{
		// 惯虐府, 郡府, 靛贰帮
		// HP, MP 府哩
		m_pStatusManager->AllocStatus( eCHAR_STATE_ETC_AUTO_RECOVER_HPMP, BASE_EXPIRE_TIME_INFINITY, stAIParamInfo.m_wPLAYER_HP_REGEN_PERIOD );
	}
}

VOID Player::OnLeaveField()
{
	// field甫 栋唱搁 飘府芭俊辑 唱吭促绊 舅妨霖促.
	GetField()->GetTriggerManager()->Disconnected(GetUserKey());

	Character::OnLeaveField();

	// field甫 栋唱搁 葛电 惑怕甫 秦力茄促? => 瞒饶俊 粱歹 绊妨!!!
	m_pStatusManager->Release();
}


//-------------------------------------------------------------------------------------------------
// 惑怕 函拳
//-------------------------------------------------------------------------------------------------
// !!!!!!
#include "PVPManager.h"
#include "GamePVPRoom.h"

BOOL Player::OnDead()
{
	SASSERT( GetHP() == 0, "[Player::OnDead] GetHP() != 0" );

	if( Character::OnDead() )
	{
		// 捞悼 吝瘤
		StopMoving();

		// 磷澜阑 舅妨林磊.
		WzVector curPos;	GetPos(&curPos);

		MSG_CG_STATUS_DEAD_BRD sendMsg;

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -