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

📄 expdistributor.cpp

📁 墨香最新私服
💻 CPP
字号:
// ExpDistributor.cpp: implementation of the CExpDistributor class.
//
//////////////////////////////////////////////////////////////////////

#include "stdafx.h"
#include "ExpDistributor.h"
#include "UserTable.h"
#include "CharMove.h"
#include "AttackManager.h"
#include "PartyManager.h"
#include "Party.h"

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

CExpDistributor::CExpDistributor()
{
	m_DamageObjectTableSolo.Initialize(MAX_POINTACCEPTOBJECT_NUM);
	m_DamageObjectTableParty.Initialize(MAX_POINTACCEPTOBJECT_NUM);
}

CExpDistributor::~CExpDistributor()
{
	Release();
}

void CExpDistributor::Release()
{
	DAMAGEOBJ *sobj, *pobj = NULL;
	m_DamageObjectTableSolo.SetPositionHead();
	while(sobj = m_DamageObjectTableSolo.GetData())
		delete sobj;
	m_DamageObjectTableSolo.RemoveAll();

	m_DamageObjectTableParty.SetPositionHead();
	while(pobj = m_DamageObjectTableParty.GetData())
		delete pobj;
	m_DamageObjectTableParty.RemoveAll();
}

void CExpDistributor::AddDamageObject(CPlayer* pPlayer, DWORD damage)
{
	CYHHashTable<DAMAGEOBJ> * pTable;
	DWORD dwID = 0;
	if(pPlayer->GetPartyIdx())
	{
		pTable = &m_DamageObjectTableParty;
		dwID = pPlayer->GetPartyIdx();
	}
	else
	{
		pTable = &m_DamageObjectTableSolo;
		dwID = pPlayer->GetID();
	}

	DAMAGEOBJ * pDObj = pTable->GetData(dwID);
	if(pDObj != NULL)
	{
		pDObj->dwData += damage;
	}
	else
	{
		DAMAGEOBJ * newObj = new DAMAGEOBJ;
		newObj->dwID = dwID;
		newObj->dwData = damage;
		
		pTable->Add(newObj, newObj->dwID);
	}
}


void CExpDistributor::ExpDitribute(DWORD KillerID,VECTOR3* pKilledPosition,LEVELTYPE MonsterLevel,DWORD MonsterTotalLife, DWORD GridID)
{
	////////////////// 磷菌促 ////////////////////////////////////////////////////////////
	DAMAGEOBJ *obj = NULL;
	VECTOR3* PlayerPosition;
	DWORD Damage;

	//贾肺
	m_DamageObjectTableSolo.SetPositionHead();
	while(obj = m_DamageObjectTableSolo.GetData())
	{
		CPlayer* pReceivePlayer = (CPlayer *)g_pUserTable->FindUser(obj->dwID);
		if(pReceivePlayer == NULL)	// 版氰摹 罐阑 敲饭捞绢啊 唱艾栏搁 continue;
			continue;

		Damage = obj->dwData;
		delete obj;

		if(Damage > MonsterTotalLife)
			Damage = MonsterTotalLife;

		if(Damage == 0)
			continue;
		
		if(pReceivePlayer->IsVimuing() == TRUE)
			continue;

		PlayerPosition = CCharMove::GetPosition(pReceivePlayer);
	
		// 磷牢 荤恩捞搁 漂扁摹甫 啊廉埃促.
		if(pReceivePlayer->GetID() == KillerID)
		{
			SendAbilityExp(pReceivePlayer, MonsterLevel);
		}
		if(CalcDistanceXZ(pKilledPosition, PlayerPosition) < POINT_VALID_DISTANCE)
		{
			SendPersonalExp(pReceivePlayer,MonsterLevel,MonsterTotalLife,Damage);
		}
	}
	m_DamageObjectTableSolo.RemoveAll();

	//颇萍
	DAMAGEOBJ* pPobj = NULL;
	m_DamageObjectTableParty.SetPositionHead();
	while(pPobj = m_DamageObjectTableParty.GetData())
	{
		CParty* pParty = PARTYMGR->GetParty(pPobj->dwID);
		if(pParty==NULL) //颇萍啊 秦魂灯栏搁 continue
		{
			continue;
		}
		CalcAndSendPartyExp(pParty, pPobj->dwData, pKilledPosition, MonsterTotalLife, GridID, KillerID, MonsterLevel);
	}
	m_DamageObjectTableParty.RemoveAll();


/*
	m_DamageObjectTable.SetPositionHead();
	while(obj = m_DamageObjectTable.GetData())
	{
		CPlayer* pReceivePlayer = (CPlayer *)g_pUserTable->FindUser(obj->dwObjectID);
		Damage = obj->dwData;
		delete obj;
		
		if(Damage > MonsterTotalLife)
			Damage = MonsterTotalLife;

		if(Damage == 0)
			continue;
		
		if(pReceivePlayer == NULL)	// 版氰摹 罐阑 敲饭捞绢啊 唱艾栏搁 continue;
			continue;
		
		PlayerPosition = CCharMove::GetPosition(pReceivePlayer);
	
		if(CalcDistanceXZ(pKilledPosition, PlayerPosition) < POINT_VALID_DISTANCE)
		{
			if(pReceivePlayer->GetPartyIdx())
			{
				//颇萍 版氰摹甫 历厘茄促. 
				if(Damage > MonsterTotalLife)
					Damage  = MonsterTotalLife;
				SavePartyExp(pReceivePlayer, Damage);
			}
//				CalcAndSavePartyExp(pReceivePlayer,MonsterLevel,MonsterTotalLife,Damage, pKilledPosition);
			else
				SendPersonalExp(pReceivePlayer,MonsterLevel,MonsterTotalLife,Damage);
		}
		
		// 磷牢 荤恩捞搁 漂扁摹甫 啊廉埃促.
		if(pReceivePlayer->GetID() == KillerID)
		{
			DWORD AbilityExp = CalcObtainAbilityExp(MonsterLevel,pReceivePlayer->GetLevel());
			if(AbilityExp)
				pReceivePlayer->AddAbilityExp(AbilityExp);
		}
	}
	m_DamageObjectTable.RemoveAll();
	SendPartyExp();
*/
}

void CExpDistributor::SendPersonalExp(CPlayer* pReceivePlayer,LEVELTYPE MonsterLevel,DWORD MonsterTotalLife,DWORD Damage)
{
	DWORD Exp = CalcObtainExp(MonsterLevel,pReceivePlayer->GetLevel(),MonsterTotalLife,Damage);
	if(Exp == 0)
		return;
	pReceivePlayer->AddPlayerExpPoint(Exp);
	pReceivePlayer->AddPlayerMugongExpPoint(Exp);
}

void CExpDistributor::CalcAndSendPartyExp(CParty* pParty, DWORD TotalDamage, VECTOR3* pKilledPosition, DWORD MonsterTotalLife, DWORD GridID, DWORD KillerID, LEVELTYPE MonsterLevel)
{
	DAMAGEOBJ *obj = NULL;
	VECTOR3* PlayerPosition;
	DWORD PartyOnlineNum=0;
	CPlayer* pPlayer[MAX_PARTY_LISTNUM] = {0,};
	DWORD PlayerID;
	float levelavg = 0;
	LEVELTYPE maxlevel = 0;  
	LEVELTYPE curlevel = 0;
	DWORD onlinenumconfirm = 0;
	

	for(int n=0;n<MAX_PARTY_LISTNUM;++n)
	{
		PlayerID = pParty->GetMemberID(n);
		if(PlayerID == 0)
			continue; 
		pPlayer[n] = (CPlayer*)g_pUserTable->FindUser(PlayerID);
		if(!pPlayer[n])	
			continue;
		if(pPlayer[n]->GetInitState() != PLAYERINITSTATE_INITED)
			continue;
		if(pPlayer[n]->GetGridID() != GridID)
			continue;
		PlayerPosition = CCharMove::GetPosition(pPlayer[n]);
		if(CalcDistanceXZ(pKilledPosition, PlayerPosition) > POINT_VALID_DISTANCE)
			continue;
		
		++onlinenumconfirm;
		curlevel = pPlayer[n]->GetLevel();
		if(maxlevel < curlevel)
			maxlevel = curlevel;
		levelavg += curlevel;		
	}
	
	levelavg /= (float)onlinenumconfirm;
	
	EXPTYPE partyexp = CalcObtainExp(MonsterLevel,maxlevel,MonsterTotalLife,TotalDamage);
	EXPTYPE exp=0;
	
	for(n=0;n<MAX_PARTY_LISTNUM;++n)
	{
		if(!pPlayer[n])  
			continue;
		if(!pParty->IsMemberLogIn(n))
			continue;
		if(pPlayer[n]->GetGridID() != GridID)
			continue;
		if(pPlayer[n]->GetState() == eObjectState_Die)
			continue;
		PlayerPosition = CCharMove::GetPosition(pPlayer[n]);
		if(CalcDistanceXZ(pKilledPosition, PlayerPosition) > POINT_VALID_DISTANCE)
			continue;
		
		//磷牢 荤恩捞搁 漂扁摹
		if(pPlayer[n]->GetID() == KillerID)
		{
			SendAbilityExp(pPlayer[n], MonsterLevel);			
		}

		curlevel = pPlayer[n]->GetLevel();
		if(onlinenumconfirm != 1)
			//exp = partyexp * ( (curlevel/levelavg)*(10+onlinenumconfirm)/9.f ) / (float)(onlinenumconfirm);
			exp = partyexp * ( curlevel * (10 + onlinenumconfirm) / 9.f / (float)levelavg ) 
									/ (float)onlinenumconfirm;
		else
			exp = partyexp;
		if(exp == 0)
			continue;
		
		pPlayer[n]->AddPlayerExpPoint(exp);
		pPlayer[n]->AddPlayerMugongExpPoint(exp);
	}

/*	CParty* pParty = PARTYMGR->GetParty(pReceivePlayer->GetPartyIdx());
	if(pParty==NULL)
	{
		ASSERT(0);
		return;
	}
	DWORD PartyOnlineNum = pParty->GetOnlineMemberNum();
	CPlayer* pPlayer[MAX_PARTY_LISTNUM] = {0,};
	DWORD PlayerID;
	float levelavg = 0;
	LEVELTYPE maxlevel = 0;  
	LEVELTYPE curlevel;
	DWORD onlinenumconfirm = 0;
	VECTOR3* PlayerPosition;

	DAMAGEOBJ *pobj = NULL;
	
	while(pobj = m_DamageObjectTable.GetData())
	{
		CPlayer* pAnotherOne = (CPlayer *)g_pUserTable->FindUser(pobj->dwObjectID);
		if(!pAnotherOne)
			continue;
		if( pAnotherOne->GetPartyIdx() == pReceivePlayer->GetPartyIdx())
		{
			if(Damage > MonsterTotalLife)
				Damage  = MonsterTotalLife;
			Damage = Damage + pobj->dwData; //颇萍 单固瘤
		}
	}

	for(int n=0;n<MAX_PARTY_LISTNUM;++n)
	{
		PlayerID = pParty->GetMemberID(n);
		if(PlayerID == 0) //歹捞惑狼 颇萍盔篮 绝促.
			break; 
		pPlayer[n] = (CPlayer*)g_pUserTable->FindUser(PlayerID);
		if(!pPlayer[n])	
			continue;
		if(pPlayer[n]->GetBattleID() != pReceivePlayer->GetBattleID())
			continue;
		if(pPlayer[n]->GetInitState() != PLAYERINITSTATE_INITED)
			continue;
		PlayerPosition = CCharMove::GetPosition(pPlayer[n]);
		if(CalcDistanceXZ(pKilledPosition, PlayerPosition) > POINT_VALID_DISTANCE)
			continue;

		++onlinenumconfirm;
		curlevel = pPlayer[n]->GetLevel();
		if(maxlevel < curlevel)
			maxlevel = curlevel;
		levelavg += curlevel;		
	}
//	ASSERT(onlinenumconfirm == PartyOnlineNum);
	levelavg /= (float)onlinenumconfirm;

	EXPTYPE partyexp = CalcObtainExp(MonsterLevel,maxlevel,MonsterTotalLife,Damage);
	EXPTYPE exp=0;
	
	for(n=0;n<MAX_PARTY_LISTNUM;++n)
	{
		if(!pPlayer[n])
			continue;
		if(!pParty->IsMemberLogIn(n))
			continue;
		if(pPlayer[n]->GetBattleID() != pReceivePlayer->GetBattleID())
			continue;
		PlayerPosition = CCharMove::GetPosition(pPlayer[n]);
		if(CalcDistanceXZ(pKilledPosition, PlayerPosition) > POINT_VALID_DISTANCE)
			continue;

		curlevel = pPlayer[n]->GetLevel();
		if(onlinenumconfirm != 1)
			exp = partyexp * ( (curlevel/levelavg)*(10+onlinenumconfirm)/9.f ) / (float)(onlinenumconfirm);
		else
			exp = partyexp;
		if(exp == 0)
			continue;
		AddExpObject(pPlayer[n],exp);
	}
*/
}

void CExpDistributor::SendPartyExp()
{
/*
	EXPOBJ* obj;
	m_ExpObjectTable.SetPositionHead();
	while(obj = m_ExpObjectTable.GetData())
	{
		obj->pPlayer->AddPlayerExpPoint(obj->Exp);
		obj->pPlayer->AddPlayerMugongExpPoint(obj->Exp);

		delete obj;
	}
	m_ExpObjectTable.RemoveAll();*/

}

DWORD CExpDistributor::CalcObtainExp(LEVELTYPE MonsterLevel,LEVELTYPE KillerLevel,DWORD TotalLife,DWORD Damage)
{
	DWORD ObtainPoint = ATTACKMGR->GetAttackCalc().GetPlayerPoint(MonsterLevel,MonsterLevel - KillerLevel);
	/*
	啊)	1		= 100% 单固瘤 : 版氰摹 100%
	唱)	0.8~1	= 80%~100%固父 单固瘤 : 版氰摹 80%
	促)	0.6~0.8	= 60%~80% 固父 单固瘤 : 版氰摹 60%
	扼)	0.4~0.6			40%~60% 固父 单固瘤 : 版氰摹 40%
	付)	0.2~0.4			20%~40% 固父 单固瘤 : 版氰摹 20%
	官)	0~0.2			20%固父 : 版氰摹 绝澜.
	*/
	DWORD perc = Damage*100 / TotalLife;
	if( (100 <= perc) )
	{
		ObtainPoint = ObtainPoint;
	}
	else if( (80 <= perc) && (perc < 100) )
	{
		ObtainPoint = (DWORD)(ObtainPoint*0.8);
	}
	else if( (60 <= perc) && (perc < 80) )
	{
		ObtainPoint = (DWORD)(ObtainPoint*0.6);
	}
	else if( (40 <= perc) && (perc < 60) )
	{
		ObtainPoint = (DWORD)(ObtainPoint*0.4);
	}
	else if( (20 <= perc) && (perc < 40) )
	{
		ObtainPoint = (DWORD)(ObtainPoint*0.2);
	}
	else
	{
		ObtainPoint = 0;
	}

	return ObtainPoint;
}

DWORD CExpDistributor::CalcObtainAbilityExp(LEVELTYPE MonsterLevel,LEVELTYPE KillerLevel)
{
	//嚼垫 漂扁摹 剧
	//*. 嚼垫 : [阁胶磐狼 饭骇] - [磊脚 饭骇蔼] + 5 (0捞窍搁 "0")
	if(MonsterLevel+5 < KillerLevel)
		return 0;
	else
		return MonsterLevel - KillerLevel + 5;

}

void CExpDistributor::SendAbilityExp(CPlayer* pReceivePlayer, LEVELTYPE MonsterLevel)
{
	DWORD AbilityExp = CalcObtainAbilityExp(MonsterLevel,pReceivePlayer->GetLevel());
	if(AbilityExp)
		pReceivePlayer->AddAbilityExp(AbilityExp);
}

⌨️ 快捷键说明

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