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

📄 skillmanager_server.cpp

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

#include "stdafx.h"

#ifdef _MAPSERVER_

#include "SkillManager_server.h"

#include "UserTable.h"
#include "CharMove.h"

#include "Player.h"
#include "PackedData.h"

#include "BattleSystem_Server.h"
#include "MapDBMsgParser.h"

#include "ObjectStateManager.h"
//////////////////////////////////////////////////////////////////////
// Construction/Destruction
//////////////////////////////////////////////////////////////////////

enum eSkillReleaseKind
{
	eSkillReleaseKind_RELEASE,
	eSkillReleaseKind_Process,
	eSkillReleaseKind_BATTLE,
};
CSkillManager::CSkillManager()
{
	g_PoolSTLIST.Init(1000,500,"g_PoolSTLIST");
	m_ICHandle = NULL;
}

CSkillManager::~CSkillManager()
{
	Release();
	g_PoolSTLIST.Release();
}


void CSkillManager::Init()
{
	m_SkillInfoTable.Initialize(64);
	m_SkillObjectTable.Initialize(256);
	LoadSkillInfoList();

	m_SkillAreaMgr.LoadSkillAreaList();
	
	m_ICHandle = ICCreate();
	ICInitialize(m_ICHandle,SKILLOBJECT_ID_MAX);
}
void CSkillManager::Release()
{
	void* p;
	
	CSkillObject* pObject;
	m_SkillObjectTable.SetPositionHead();
	while(pObject = m_SkillObjectTable.GetData())
	{
		ReleaseSkillObject(pObject,eSkillReleaseKind_RELEASE);
	}
	m_SkillObjectTable.RemoveAll();

	m_SkillInfoTable.SetPositionHead();
	while(p = m_SkillInfoTable.GetData())
	{
		delete p;
	}
	m_SkillInfoTable.RemoveAll();

	m_SkillAreaMgr.Release();
	
	if(m_ICHandle)
	{
		ICRelease(m_ICHandle);
		m_ICHandle = NULL;
	}
}

void CSkillManager::LoadSkillInfoList()
{
	CMHFile file;
#ifdef _FILE_BIN_
	file.Init("Resource/SkillList.bin","rb");
#else
	file.Init("Resource/SkillList.txt","rt");
#endif
	if(file.IsInited() == FALSE)
	{
		ASSERTMSG(0,"SkillList甫 肺靛窍瘤 给沁嚼聪促.");
		return;
	}

	while(1)
	{
		if(file.IsEOF() != FALSE)
			break;

		CSkillInfo* pInfo = new CSkillInfo;
		pInfo->InitSkillInfo(&file);

		m_SkillInfoTable.Add(pInfo,pInfo->GetSkillIndex());
	}
	file.Release();
}

DWORD CSkillManager::GetNewSkillObjectID()
{
	static tempID = SKILLOBJECT_ID_START;
	if(++tempID >= SKILLOBJECT_ID_MAX)
		tempID = SKILLOBJECT_ID_START;
	return tempID;

	//return SKILLOBJECT_ID_START + ICAllocIndex(m_ICHandle);
}
void CSkillManager::ReleaseSkillObjectID(DWORD SkillObjectID)
{
	return;
	
	//ICFreeIndex(m_ICHandle,SkillObjectID - SKILLOBJECT_ID_START);
}

void CSkillManager::OnSkillStartSyn(MSG_SKILL_START_SYN* pmsg)
{
	CSkillObject* pSObj;
	SKILLOBJECT_INFO info;
	VECTOR3 TargetPos;
	float TargetRadius;
	int SkillLevel = 1;
	CBattle* pBattle;
	CObject * pTargetObject = NULL;

	CObject* pOperator = g_pUserTable->FindUser(pmsg->Operator);
	if(pOperator == NULL)
		return;

	//KES HACK CHECK
	if( pOperator->GetObjectKind() == eObjectKind_Player )
	if( gCurTime - pOperator->GetSkillDelayStartTime() < 250 )
	{
		((CPlayer*)pOperator)->SpeedHackCheck();
	}

	pOperator->SetSkillDelayStartTime(gCurTime);

	CSkillInfo* pSkillInfo = GetSkillInfo(pmsg->SkillIdx);
	ASSERT(pSkillInfo);
	if(pSkillInfo == NULL)
		goto SkillStartNack;
	
	if(pOperator->GetObjectKind() == eObjectKind_Player)
	{
		SkillLevel = ((CPlayer*)pOperator)->GetMugongLevel(pmsg->SkillIdx);
		if(SkillLevel == 0 || SkillLevel == -1)	// 公傍捞 绝绰 版快捞芭唱 0己牢 版快
			goto SkillStartNack;
	}

//KES
	if( pOperator->GetState() == eObjectState_Immortal )
		OBJECTSTATEMGR_OBJ->EndObjectState( pOperator, eObjectState_Immortal, 0 );
//	

	// 阿辆 八荤
	if(pSkillInfo->IsExcutableSkillState(pOperator,SkillLevel) == FALSE)
		goto SkillStartNack;
	
	if(GetMainTargetPos(&pmsg->MainTarget,&TargetPos, &pTargetObject) == FALSE)	// 鸥百捞 绝促.
		goto SkillStartNack;
	GetMainTargetRadius(&pmsg->MainTarget,&TargetRadius);

	if(pSkillInfo->ComboTest(pOperator) == FALSE)
		goto SkillStartNack;

	if(pSkillInfo->IsInSkillRange(pOperator,&TargetPos,TargetRadius) == FALSE)
	{
		if(pTargetObject)
		{
			RESULTINFO DamageInfo;
			DamageInfo.Clear();
			pTargetObject->Damage(pOperator, &DamageInfo);
		}
		goto SkillStartNack;
	}
	
	
	if(pSkillInfo->CheckEvade(&pmsg->MainTarget) == TRUE)
		goto SkillStartNack;

	// 胶懦 坷宏璃飘 积己
	pSObj = pSkillInfo->GetSkillObject();

	info.SkillIdx = pmsg->SkillIdx;
	info.SkillObjectIdx = GetNewSkillObjectID();
	info.Direction = pmsg->SkillDir;
	info.Operator = pmsg->Operator;
	info.SkillLevel = SkillLevel;

	info.MainTarget = pmsg->MainTarget;

	info.Pos = *pSkillInfo->GetTargetAreaPivotPos(CCharMove::GetPosition(pOperator),&TargetPos);
	info.StartTime = gCurTime;

	// battle
	info.BattleID = pOperator->GetBattleID();
	pBattle = pOperator->GetBattle();
	info.BattleKind = pBattle->GetBattleKind();
	
	
	((CPlayer*)pOperator)->GetDelayGroup()->AddDelay(
		CDelayGroup::eDK_Skill,pSkillInfo->GetSkillIndex(),
		pSkillInfo->GetSkillInfo()->DelayTime);


	pSObj->Init(&info,&pmsg->TargetList);
	pSObj->SetBattle(pOperator->GetBattleID(),pOperator->GetBattleTeam());
	pSObj->SetGridID(pOperator->GetGridID());
	

	// 抛捞喉俊 殿废
	m_SkillObjectTable.Add(pSObj,pSObj->GetID());
	g_pServerSystem->AddSkillObject(pSObj,&info.Pos);
	

	return;

SkillStartNack:
	if(pOperator->GetObjectKind() != eObjectKind_Player)
		return;

	// for delete AmplifiedPower
	pOperator->GetSpecialStateParam1(eSpecialState_AmplifiedPowerPhy);

	CPlayer* pp = (CPlayer*)pOperator;
	MSGBASE msg;
	msg.Category = MP_SKILL;
	msg.Protocol = MP_SKILL_START_NACK;
	msg.dwObjectID = pp->GetID();
	pp->SendMsg(&msg,sizeof(msg));	

	return;
}

void CSkillManager::OnAddObjectToSkillObjectArea(DWORD SkillObjectID,DWORD ObjectID)
{
	CSkillObject* pSObj = GetSkillObject(SkillObjectID);
	if(pSObj == NULL)
		return;

	CObject* pObject = g_pUserTable->FindUser(ObjectID);
	if(pObject == NULL)
		return;

	pSObj->AddTargetObject(pObject);
}

void CSkillManager::OnRemoveObjectToSkillObjectArea(DWORD SkillObjectID,DWORD ObjectID)
{
	CSkillObject* pSObj = GetSkillObject(SkillObjectID);
	if(pSObj == NULL)
		return;

	pSObj->RemoveTargetObject(ObjectID);
}

CSkillObject* CSkillManager::GetSkillObject(DWORD SkillObjID)
{
	return (CSkillObject*)m_SkillObjectTable.GetData(SkillObjID);
}
CSkillInfo* CSkillManager::GetSkillInfo(WORD SkillInfoIdx)
{
	return (CSkillInfo*)m_SkillInfoTable.GetData(SkillInfoIdx);
}

void CSkillManager::ReleaseSkillObject(CSkillObject* pSkillObject,int ReleaseKind)
{
	CSkillInfo* pSInfo = GetSkillInfo(pSkillObject->GetSkillIdx());
//	ASSERT(pSInfo);
	if(!pSInfo)
	{
		ASSERTMSG(0,"秽!!!!!! 吝夸茄镑 捞芭 焊搁 辣龋茄抛 怖 楷遏官恩!!!");
		return;
	}

	m_SkillObjectTable.Remove(pSkillObject->GetID());
	g_pServerSystem->RemoveSkillObject(pSkillObject->GetID());
	ReleaseSkillObjectID(pSkillObject->GetID());

	pSInfo->ReleaseSkillObject(pSkillObject,ReleaseKind);	
}

void CSkillManager::OnSkillStartEffect(MSG_DWORD2* pmsg)
{
	CObject* pObject = g_pUserTable->FindUser(pmsg->dwData1);
	if(pObject == NULL)
		return;
	
	PACKEDDATA_OBJ->QuickSendExceptObjectSelf(pObject,pmsg,sizeof(MSG_DWORD2));
}

void CSkillManager::OnSkillOperateSyn(MSG_SKILL_OPERATE* pmsg)
{
	CSkillObject* pSObj = GetSkillObject(pmsg->SkillObjectID);
	if(pSObj == NULL)
		return;

	CObject* pReqObj = g_pUserTable->FindUser(pmsg->RequestorID);
	if(pReqObj == NULL)
		return;
		
	BOOL rt = pSObj->Operate(pReqObj,&pmsg->MainTarget,&pmsg->TargetList);
	ASSERT(rt);
}

void CSkillManager::NetworkMsgParse(BYTE Protocol,void* pMsg)
{
	switch(Protocol)
	{
	case MP_SKILL_START_SYN:
		{
			MSG_SKILL_START_SYN* pmsg = (MSG_SKILL_START_SYN*)pMsg;
			OnSkillStartSyn(pmsg);
		}
		break;
	case MP_SKILL_ADDOBJECT_TO_SKILLOBJECTAREA_SYN:
		{
			MSG_DWORD2* pmsg = (MSG_DWORD2*)pMsg;
			OnAddObjectToSkillObjectArea(pmsg->dwData1,pmsg->dwData2);
		}
		break;
	case MP_SKILL_REMOVEOBJECT_FROM_SKILLOBJECTAREA_SYN:
		{
			MSG_DWORD2* pmsg = (MSG_DWORD2*)pMsg;
			OnRemoveObjectToSkillObjectArea(pmsg->dwData1,pmsg->dwData2);
		}
		break;
	case MP_SKILL_STARTEFFECT:
		{
			MSG_DWORD2* pmsg = (MSG_DWORD2*)pMsg;
			OnSkillStartEffect(pmsg);			
		}
		break;
	case MP_SKILL_OPERATE_SYN:
		{
			MSG_SKILL_OPERATE* pmsg = (MSG_SKILL_OPERATE*)pMsg;
			OnSkillOperateSyn(pmsg);
		}
		break;
	}
}



void CSkillManager::Process()
{
	CSkillObject* pSObj;
	DWORD rtCode;
	m_SkillObjectTable.SetPositionHead();
	while(pSObj = m_SkillObjectTable.GetData())
	{
		rtCode = pSObj->Update();
		if(rtCode == SO_DESTROYOBJECT)
		{
			ReleaseSkillObject(pSObj,eSkillReleaseKind_Process);
		}
	}
}

void CSkillManager::GetMainTargetRadius(MAINTARGET* pMainTarget,float* pRtRadius)
{
	if(pMainTarget->MainTargetKind == MAINTARGET::MAINTARGETKIND_POS)
		*pRtRadius = 0;
	else
	{
		CObject* pTarget = g_pUserTable->FindUser(pMainTarget->dwMainTargetID);
		*pRtRadius = pTarget->GetRadius();
	}	
}

BOOL gTestMonsterAttack = TRUE;
void CSkillManager::MonsterAttack(WORD SkillIdx,CObject* pMonster,CObject* pTarget)
{
	if(gTestMonsterAttack == FALSE)
		return;

	CBattle* pBattle;
	CSkillInfo* pSkillInfo = GetSkillInfo(SkillIdx);
	ASSERT(pSkillInfo);
	if(pSkillInfo == NULL)
		return;
	
	VECTOR3* pMonPos = CCharMove::GetPosition(pMonster);
	VECTOR3* pTargetPos = CCharMove::GetPosition(pTarget);
	VECTOR3 dir = *pTargetPos - *pMonPos;
	DIRINDEX diridx = RADTODIR(VECTORTORAD(dir));


	// 胶懦 坷宏璃飘 积己
	SKILLOBJECT_INFO info;
	CSkillObject* pSObj = pSkillInfo->GetSkillObject();

	info.SkillIdx = SkillIdx;
	info.SkillObjectIdx = GetNewSkillObjectID();
	info.Direction = diridx;
	info.Operator = pMonster->GetID();
	info.MainTarget.MainTargetKind = MAINTARGET::MAINTARGETKIND_OBJECTID;
	info.MainTarget.dwMainTargetID = pTarget->GetID();

	info.Pos = *pSkillInfo->GetTargetAreaPivotPos(pMonPos,pTargetPos);
	info.StartTime = gCurTime;
	info.SkillLevel = 1;

	
	// battle
	info.BattleID = pMonster->GetBattleID();
	pBattle = pMonster->GetBattle();
	info.BattleKind = pBattle->GetBattleKind();



	CTargetList TList;
	TList.Clear();
	CTargetListIterator iter(&TList);
	iter.AddTargetWithNoData(pTarget->GetID(),SKILLRESULTKIND_NEGATIVE);
	iter.Release();

	// 抛捞喉俊 殿废
	pSObj->Init(&info,&TList);
	pSObj->SetBattle(pMonster->GetBattleID(),pMonster->GetBattleTeam());
	pSObj->SetGridID(pMonster->GetGridID());

	
	m_SkillObjectTable.Add(pSObj,pSObj->GetID());
	g_pServerSystem->AddSkillObject(pSObj,&info.Pos);
}

void CSkillManager::MonsterAttack(WORD SkillIdx,CObject* pMonster,VECTOR3* pTargetPos)
{
	if(gTestMonsterAttack == FALSE)
		return;

	CBattle* pBattle;
	CSkillInfo* pSkillInfo = GetSkillInfo(SkillIdx);
	ASSERT(pSkillInfo);
	if(pSkillInfo == NULL)
		return;
	
	VECTOR3* pMonPos = CCharMove::GetPosition(pMonster);
	VECTOR3 dir = *pTargetPos - *pMonPos;
	DIRINDEX diridx = RADTODIR(VECTORTORAD(dir));


	// 胶懦 坷宏璃飘 积己
	SKILLOBJECT_INFO info;
	CSkillObject* pSObj = pSkillInfo->GetSkillObject();

	info.SkillIdx = SkillIdx;
	info.SkillObjectIdx = GetNewSkillObjectID();
	info.Direction = diridx;
	info.Operator = pMonster->GetID();
	info.MainTarget.MainTargetKind = MAINTARGET::MAINTARGETKIND_OBJECTID;
	info.MainTarget.dwMainTargetID = 0;

	info.Pos = *pSkillInfo->GetTargetAreaPivotPos(pMonPos,pTargetPos);
	info.StartTime = gCurTime;
	info.SkillLevel = 1;

	
	// battle
	info.BattleID = pMonster->GetBattleID();
	pBattle = pMonster->GetBattle();
	info.BattleKind = pBattle->GetBattleKind();
	
	
	CTargetList tlist;

	WORD Radius = pSkillInfo->GetSkillInfo()->TargetRange;
	WORD AreaNum = pSkillInfo->GetSkillInfo()->TargetAreaIdx;
	
	if(AreaNum != 0)
	{
		CSkillArea* pSkillArea = GetSkillArea(pMonPos,pTargetPos,pSkillInfo);	// Area狼 吝缴谅钎鳖瘤 悸泼登绢廉 柯促.
		g_pUserTable->GetTargetInArea(pSkillArea,&tlist);
	}
	else if(Radius != 0)
	{
		g_pUserTable->GetTargetInRange(pSkillInfo->GetTargetAreaPivotPos(pMonPos,pTargetPos),Radius,&tlist);
	}
	
	
	// 抛捞喉俊 殿废
	pSObj->Init(&info,&tlist);
	pSObj->SetBattle(pMonster->GetBattleID(),pMonster->GetBattleTeam());
	pSObj->SetGridID(pMonster->GetGridID());
	
	
	m_SkillObjectTable.Add(pSObj,pSObj->GetID());
	g_pServerSystem->AddSkillObject(pSObj,&info.Pos);
}

CSkillArea* CSkillManager::GetSkillArea(VECTOR3* pObjPos, VECTOR3* pTargetPos, CSkillInfo* pSkillInfo)
{
	VECTOR3 DirVec = *pTargetPos - *pObjPos;
	float fRad = VECTORTORAD(DirVec);
	DIRINDEX dir = RADTODIR(fRad);
	CSkillArea* pArea = GetSkillArea(dir,pSkillInfo->GetSkillAreaIndex());
	
	// Area狼 吝缴谅钎鳖瘤 悸泼登绢廉 柯促.
	VECTOR3* pPos;
	pPos = pSkillInfo->GetTargetAreaPivotPos(pObjPos,pTargetPos);
	pArea->SetCenterPos(pPos);

	return pArea;	
}

CSkillArea* CSkillManager::GetSkillArea(DIRINDEX dir,WORD SkillAreaIndex)
{
	CSkillArea* pArea = m_SkillAreaMgr.GetSkillArea(SkillAreaIndex,dir);
	
	return pArea;	
}

void CSkillManager::ReleaseSkillArea(CSkillArea* pSkillArea)
{
	m_SkillAreaMgr.ReleaseSkillArea(pSkillArea);
}

void CSkillManager::ReleaseAllSkillInBattle(DWORD BattleID)
{
	CSkillObject* pSObj;
	m_SkillObjectTable.SetPositionHead();
	while(pSObj = m_SkillObjectTable.GetData())
	{
		if(pSObj->GetBattleID() == BattleID)
			ReleaseSkillObject(pSObj,eSkillReleaseKind_BATTLE);
	}	
}

#endif

⌨️ 快捷键说明

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