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

📄 pkmanager.cpp

📁 墨香最新私服
💻 CPP
📖 第 1 页 / 共 2 页
字号:
// PKManager.cpp: implementation of the CPKManager class.
//
//////////////////////////////////////////////////////////////////////

#include "stdafx.h"
#include "PKManager.h"
#include "UserTable.h"
#include "PackedData.h"
#include "Player.h"
#include "..\[CC]Header\CommonGameFunc.h"
#include "LootingManager.h"
#include "MapDBMsgParser.h"
#include "cConstLinkedList.h"
#include "ItemManager.h"
#include "MugongManager.h"

#include "..\[CC]Header\GameResourceManager.h"
#include "FameManager.h"

//////////////////////////////////////////////////////////////////////
// Construction/Destruction
//////////////////////////////////////////////////////////////////////

CPKManager::CPKManager()
{
}

CPKManager::~CPKManager()
{

}

void CPKManager::Init( BOOL bPKAllow )
{
	m_bPKAllow = bPKAllow;
}

void CPKManager::SetPKAllowWithMsg( BOOL bAllow )
{
	if( m_bPKAllow == bAllow ) return;
	m_bPKAllow = bAllow;
	
	MSG_BYTE msg;
	msg.Category	= MP_PK;
	msg.Protocol	= MP_PK_PKALLOW_CHANGED;
	
	CObject* pObject = NULL;
	g_pUserTable->SetPositionUserHead();
	while( pObject = g_pUserTable->GetUserData() )
	{
		if( pObject->GetObjectKind() != eObjectKind_Player ) continue;

		if( bAllow == FALSE )
		{
			if( ((CPlayer*)pObject)->IsPKMode() )
				((CPlayer*)pObject)->PKModeOffForce();
			//风泼窍带巴档 牡浇?
		}

		msg.bData		= bAllow;
						
		((CPlayer*)pObject)->SendMsg( &msg, sizeof( msg ) );
	}
}

void CPKManager::DiePanelty( CPlayer* pDiePlayer, CObject* pAttacker )
{
	//厚公矫浚 磷绰 菩澄萍啊 绝促. 厚公肺 沥寸窍霸 磷菌促.
	if( pDiePlayer->m_bNeedRevive == FALSE )
		return;

	//厩疙摹 臭阑锭 磷栏搁 罐绰 菩澄萍.	
	PKPlayerDiePanelty( pDiePlayer );

	if( pAttacker->GetObjectKind() != eObjectKind_Player )
		return;

	//PK窍搁 罐绰 厩疙摹
	PKPlayerKillPanelty( pDiePlayer, (CPlayer*)pAttacker );

	//么混寸窍搁 罐绰 菩澄萍.
	PKPlayerKiiledByWantedPanelty( pDiePlayer, (CPlayer*)pAttacker );
}


void CPKManager::PKPlayerKillPanelty( CPlayer* pDiePlayer, CPlayer* pAttacker )
{
	if( pAttacker->IsPKMode() )
	{
		if( !pDiePlayer->IsPKMode() )
		{
			DWORD dwBadFame = pAttacker->GetBadFame();
			DWORD dwAddBadFame = 0;
			if( dwBadFame < 50 )
				dwAddBadFame = 2;
			else if( dwBadFame < 4000 )
				dwAddBadFame = 5;
			else if( dwBadFame < 20000 )
				dwAddBadFame = 10;
			else if( dwBadFame < 80000 )
				dwAddBadFame = 30;
			else if( dwBadFame < 400000 )
				dwAddBadFame = 50;
			else if( dwBadFame < 1600000 )
				dwAddBadFame = 80;
			else if( dwBadFame < 8000000 )
				dwAddBadFame = 100;
			else if( dwBadFame < 32000000 )
				dwAddBadFame = 200;
			else if( dwBadFame < 100000000 )
				dwAddBadFame = 300;
			else if( dwBadFame < 500000000 )
				dwAddBadFame = 500;
			else
				dwAddBadFame = 600;
			
			if( dwBadFame + dwAddBadFame < 1000000000 )
				pAttacker->SetBadFame( dwBadFame + dwAddBadFame );
			else
				pAttacker->SetBadFame( 1000000000 );	//10撅
			
			BadFameCharacterUpdate( pAttacker->GetID(), pAttacker->GetBadFame() );
			FAMEMGR->SendBadFameMsg( pAttacker, pAttacker->GetBadFame() );
		}

		//眠啊
		pAttacker->AddPKContinueTime( 60000 );	//混扁 瘤加矫埃 刘啊
	}
}

void CPKManager::PKPlayerKiiledByWantedPanelty( CPlayer* pDiePlayer, CPlayer* pAttacker )
{
	//die <--PKPlayer
	//attack <--has wanted player

	if( pAttacker->IsWantedOwner( pDiePlayer->GetWantedIdx() ) )	//么混鼻阑 啊柳惑措俊霸 磷菌促.
	{
//肯拳 : 厩疙摹 皑家 ========
		DWORD dwBadFame = pDiePlayer->GetBadFame();

		if( dwBadFame != 0 )
		{
			DWORD dwMinusBadFame = 0;
			
			if( dwBadFame < 50 )
				dwMinusBadFame = 2;
			else if( dwBadFame < 4000 )
				dwMinusBadFame = 5;
			else if( dwBadFame < 20000 )
				dwMinusBadFame = 10;
			else if( dwBadFame < 80000 )
				dwMinusBadFame = 30;
			else if( dwBadFame < 400000 )
				dwMinusBadFame = 50;
			else if( dwBadFame < 1600000 )
				dwMinusBadFame = 80;
			else if( dwBadFame < 8000000 )
				dwMinusBadFame = 100;
			else if( dwBadFame < 32000000 )
				dwMinusBadFame = 200;
			else if( dwBadFame < 100000000 )
				dwMinusBadFame = 300;
			else if( dwBadFame < 500000000 )
				dwMinusBadFame = 500;
			else
				dwMinusBadFame = 600;
			
			if( dwBadFame > dwMinusBadFame )
				pDiePlayer->SetBadFame( dwBadFame - dwMinusBadFame );
			else
				pDiePlayer->SetBadFame( 0 );	//0
			BadFameCharacterUpdate( pDiePlayer->GetID(), pDiePlayer->GetBadFame() );
			FAMEMGR->SendBadFameMsg( pDiePlayer, pDiePlayer->GetBadFame() );
		}
//==============

		//力力 //公傍捞 绝绢柳促.	//昏力... %父 3% 眠啊登绢 公炼扒 磷菌阑矫俊 其澄萍甫 罐绰促.
/*
		int nRatio = 0;	//公傍颇鲍 犬伏
		
		CItemSlot* pWear	= pDiePlayer->GetSlot( eItemTable_Weared );
		CItemSlot* pInven	= pDiePlayer->GetSlot( eItemTable_Inventory );
		if( pWear->GetItemCount() + pInven->GetItemCount() < 8 )
		{
			if( dwBadFame < 50 )
				nRatio = 0;
			else if( dwBadFame < 4000 )
				nRatio = 20;
			else if( dwBadFame < 20000 )
				nRatio = 25;
			else if( dwBadFame < 80000 )
				nRatio = 30;
			else if( dwBadFame < 400000 )
				nRatio = 40;
			else if( dwBadFame < 1600000 )
				nRatio = 50;
			else if( dwBadFame < 8000000 )
				nRatio = 60;
			else if( dwBadFame < 32000000 )
				nRatio = 70;
			else if( dwBadFame < 100000000 )
				nRatio = 80;
			else if( dwBadFame < 500000000 )
				nRatio = 90;
			else
				nRatio = 100;
		}
		
		if( nRatio != 0 )
		{
			int nSeed = rand()%100;
			if( nSeed < nRatio )
			{
				MUGONG_TOTALINFO TotalInfo;
				pDiePlayer->GetMugongTotalInfo( &TotalInfo );
				cConstLinkedList<const MUGONGBASE*> ListMugong;
				for( int i = 0 ; i < SLOT_MUGONGTOTAL_NUM ; ++i )
				{
					if( TotalInfo.mugong[i].dwDBIdx != 0 )
					{
						ListMugong.AddTail( &TotalInfo.mugong[i] );
					}
				}
				
				if( ListMugong.GetCount() == 0 ) 
				{
					//朝副 公傍档 绝促. 
					return;
				}
				
				int nIndex = rand()%ListMugong.GetCount();
				const MUGONGBASE* pMugong = ListMugong.GetAt(nIndex);
				
				if( pMugong )
				if( MUGONGMNGR->RemMugong( pDiePlayer, pMugong->wIconIdx, pMugong->Position ) )
				{
					MSG_MUGONG_REM_ACK ToMsg;
					ToMsg.Category		= MP_PK;
					ToMsg.Protocol		= MP_PK_DESTROY_MUGONG;
					ToMsg.dwObjectID	= pDiePlayer->GetID();
					ToMsg.wMugongIdx	= pMugong->wIconIdx;
					ToMsg.TargetPos		= pMugong->Position;
						
					pDiePlayer->SendMsg(&ToMsg, sizeof(ToMsg));
				}
					
				ListMugong.DeleteAll();
			}
		}
		*/
	}
}

void CPKManager::PKPlayerDiePanelty( CPlayer* pPlayer )
{
	//磷菌阑锭 扁夯利栏肺 歹 啊秦瘤绰 菩澄萍
	PKModeExitPanelty( pPlayer );
	//厘馒酒捞袍 颇鲍
	DWORD dwBadFame = pPlayer->GetBadFame();

	int nMinDestroyItemNum	= 0;
	int nMaxDestroyItemNum	= 0;

	if( g_pServerSystem->GetNation() == eNATION_CHINA )
	{
		if( dwBadFame < 30 ) return;
	}

	if( dwBadFame == 0 )
	{
		nMinDestroyItemNum = 0;
		nMaxDestroyItemNum = 0;
	}
	else if( dwBadFame < 4000 )
	{
		nMinDestroyItemNum = 1;
		nMaxDestroyItemNum = 1;
//		nDestroyRatio = 50;
	}
	else if( dwBadFame < 20000 )
	{
		nMinDestroyItemNum = 1;
		nMaxDestroyItemNum = 2;
//		nDestroyRatio = 60;
	}
	else if( dwBadFame < 80000 )
	{
		nMinDestroyItemNum = 1;
		nMaxDestroyItemNum = 2;
//		nDestroyRatio = 70;
	}
	else if( dwBadFame < 400000 )
	{
		nMinDestroyItemNum = 1;
		nMaxDestroyItemNum = 2;
//		nDestroyRatio = 80;
	}
	else if( dwBadFame < 1600000 )
	{
		nMinDestroyItemNum = 1;
		nMaxDestroyItemNum = 3;
//		nDestroyRatio = 90;
	}
	else if( dwBadFame < 8000000 )
	{
		nMinDestroyItemNum = 1;
		nMaxDestroyItemNum = 3;
//		nDestroyRatio = 100;
	}
	else if( dwBadFame < 32000000 )
	{
		nMinDestroyItemNum = 1;
		nMaxDestroyItemNum = 4;
//		nDestroyRatio = 100;
	}
	else if( dwBadFame < 100000000 )
	{
		nMinDestroyItemNum = 1;
		nMaxDestroyItemNum = 4;
//		nDestroyRatio = 100;
	}
	else if( dwBadFame < 500000000 )
	{
		nMinDestroyItemNum = 1;
		nMaxDestroyItemNum = 4;
//		nDestroyRatio = 100;
	}
	else
	{
		nMinDestroyItemNum = 2;
		nMaxDestroyItemNum = 4;
//		nDestroyRatio = 100;
	}

	int nDestroyRatio	= dwBadFame ? (int)(0.3070f * sqrt((float)dwBadFame) + 2.6930f) : 0;	//公扁, 公傍, 漂扁 葛滴 秦寸
	
	BOOL bWantedPlayer = FALSE;
	if( pPlayer->GetWantedIdx() != 0 )	//泅惑裹捞搁 3%刘啊
	{
		nDestroyRatio += 3;
		bWantedPlayer = TRUE;
	}

	if( nDestroyRatio == 0 ) return;	//颇鲍犬伏捞 绝栏搁 府畔.

⌨️ 快捷键说明

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