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

📄 monster.cpp

📁 墨香最新私服
💻 CPP
📖 第 1 页 / 共 2 页
字号:
	SetTObject(NULL);	
}

void CMonster::GetSendMoveInfo(SEND_MOVEINFO* pRtInfo,CAddableInfoList* pAddInfoList)
{
	CObject::GetSendMoveInfo(pRtInfo,pAddInfoList);
	pRtInfo->KyungGongIdx = (WORD)m_stateParam.stateCur;	
}

float CMonster::DoGetMoveSpeed()
{
	WORD kind = GetMonsterKind();

	float Speed = 0.0;
	switch(m_stateParam.stateCur)
	{
	case eMA_WALKAROUND:
		{
			Speed = (float)GAMERESRCMNGR->GetMonsterListInfo(kind)->WalkMove;
		}
		break;
	case eMA_RUNAWAY:
		{
			Speed = (float)GAMERESRCMNGR->GetMonsterListInfo(kind)->RunawayMove;
		}
		break;
	case eMA_PERSUIT:
		{
			Speed = (float)GAMERESRCMNGR->GetMonsterListInfo(kind)->RunMove;
		}
		break;
	default:
		{
			Speed = 0;
//			ASSERT(0);
		}
		break;
	}

	return Speed;
}

void CMonster::OnStop()
{
	if(CCharMove::IsMoving(this) == FALSE) return;
	
	VECTOR3* pos = CCharMove::GetPosition(this);
	CCharMove::EndMove(this, gCurTime, pos);
	MOVE_POS msg;
	msg.Category = MP_MOVE;
	msg.Protocol = MP_MOVE_STOP;
	msg.dwMoverID = GetID();
	msg.cpos.Compress(pos);

	PACKEDDATA_OBJ->QuickSend(this,&msg,sizeof(msg));
}

void CMonster::OnMove( VECTOR3 * pPos )
{

	ASSERT(GetState() != eObjectState_Die);

	// 搬冠 惑怕捞扁锭巩俊 给 框流捞霸 窃
	if( GetState() == eObjectState_TiedUp_CanSkill ||
		GetState() == eObjectState_TiedUp )
		return;

	VECTOR3* curpos = CCharMove::GetPosition(this);
	if(m_MoveInfo.bMoving)
	{
		if(m_MoveInfo.GetMaxTargetPosIdx() != 0 && m_MoveInfo.GetTargetPosition(m_MoveInfo.GetMaxTargetPosIdx()-1)->x == pPos->x && m_MoveInfo.GetTargetPosition(m_MoveInfo.GetMaxTargetPosIdx()-1)->z == pPos->z)
			return;
	}
	if(curpos->x == pPos->x && curpos->z == pPos->z)
		return;

	//////////////////////////////////////////////////////////////////////////
	// 鸥老 棺 面倒..
	VECTOR3 tPos;
	BOOL preo = g_pServerSystem->GetMap()->GetTileManager()->IsPreoccupied(this,pPos);
	if(preo)
	{
		tPos = g_pServerSystem->GetMap()->GetTileManager()->GetNextCloserPos(this,pPos,curpos,100,1000);
	}
	else
	{
		tPos = *pPos;
	}

	m_MoveInfo.InitTargetPosition();
//	BOOL bInv = FALSE;
//	if(m_stateParam.stateCur == eMA_PERSUIT)
		//bInv = TRUE;
//gotoPATH:
	switch(PATHMGR->GetPath(&m_MoveInfo.CurPosition,pPos,m_MoveInfo.GetTargetPositionArray(), MAX_CHARTARGETPOSBUF_SIZE, m_MoveInfo.GetMaxTargetPosIdxRef(), this, FALSE))
	{	
	case PATH_BLOCKFAILED:
		{
			GSTATEMACHINE.SetState(this, eMA_RUNAWAY);
			return;

			VECTOR3 IDir;
			IDir.x = -m_MoveInfo.Move_Direction.x;
			IDir.z = -m_MoveInfo.Move_Direction.z;
			BeelinePoint(&m_MoveInfo.CurPosition, &IDir, 1000, pPos);
			OnMove(pPos);
		///	goto gotoPATH;
		}
		break;
	case PATH_FAILED:
		return;
	}

	WORD count = m_MoveInfo.GetMaxTargetPosIdx();

	// jsd 
	if( count == 0 )
		return;
	else if( count == 1 )
	{
		MOVE_ONETARGETPOS_FROMSERVER msg;
		SetProtocol(&msg,MP_MOVE,MP_MOVE_ONETARGET);
		msg.dwObjectID = GetID();
		msg.SetStartPos(curpos);
		msg.SetTargetPos(m_MoveInfo.GetTargetPosition(0));

		PACKEDDATA_OBJ->QuickSend(this,&msg,msg.GetSize());
	}
	else
	{
		MOVE_TARGETPOS msg;
		msg.Init();
		msg.Category = MP_MOVE;
		msg.Protocol = MP_MOVE_TARGET;
		msg.dwMoverID = GetID();
		msg.SetStartPos(&m_MoveInfo.CurPosition);
		//msg.tpos.Compress(&TargetPos);
		for(int i=0;i<count;++i)
			msg.AddTargetPos(m_MoveInfo.GetTargetPosition(i));

		PACKEDDATA_OBJ->QuickSend(this,&msg,msg.GetSize());
	}	

	//StartMove(pHero,gCurTime,&TargetPos);
	m_MoveInfo.SetCurTargetPosIdx(0);
	ASSERT(m_MoveInfo.GetCurTargetPosIdx()< m_MoveInfo.GetMaxTargetPosIdx());
	CCharMove::StartMoveEx(this,gCurTime,curpos,m_MoveInfo.GetTargetPosition(0));

}
void CMonster::DoStand()
{
	OnStop();
}
void CMonster::DoRest(BOOL bStart)
{
	OnStop();

}
BOOL CMonster::DoAttack( WORD attackNum )
{
	if( !m_pTObject ) return FALSE;

	OnStop();
	
	// yh
	if( IsInSpecialState(eSpecialState_Stun) )
		return TRUE;

	if( GetState() == eObjectState_TiedUp_CanMove ||
		GetState() == eObjectState_TiedUp )
		return TRUE;

	// LBS 老窜 阜酒壕聪促.
	if( GetGridID() != m_pTObject->GetGridID() )
	{
//		ASSERT(0);
		return TRUE;
	}

	SKILLMGR->MonsterAttack(attackNum, this, m_pTObject);
	
	return TRUE;
}

BOOL CMonster::DoWalkAround()
{
	int ran=0;
	VECTOR3 Target;
	VECTOR3 * pThisPos = CCharMove::GetPosition(this);
	//VECTOR3 domainPoint = RESPAWNMGR->GetOBJ_REGEN(GetID())->vPos;
	//VECTOR3 domainPoint = *GROUPMGR->GetRegenObject(GetMonsterGroupNum(), GetBattleID(), GetID())->GetPos();
	// YH 捞亥飘府妮捞唱 荐访厘殿俊急 ProtoType 救持绢林绰巴栏肺 荐沥
	CRegenPrototype* pProtoType = REGENMGR->GetPrototype(GetSubID());
	VECTOR3 domainPoint = pProtoType ? pProtoType->vPos : *pThisPos;
	VECTOR3 decisionPoint;
	AdjacentPointForOriginPoint(pThisPos, &domainPoint, (float)10000, &decisionPoint);

	float dx=0,dz=0;
	ran = rand();
	if(m_pSInfo->DomainRange==0)
		m_pSInfo->DomainRange = 1;
	
	dx = float(ran%m_pSInfo->DomainRange) * (ran%2?1:-1);
	ran = rand();
	dz = float(ran%m_pSInfo->DomainRange) * (ran%2?1:-1);
	Target.x = decisionPoint.x + dx;
	Target.z = decisionPoint.z + dz;

	if(Target.x < 10.0f)
		Target.x = 10.0f;
	else if(Target.x > 51200.0f)
		Target.x = 51200.0f;

	if(Target.z < 10.0f)
		Target.z = 10.0f;
	else if(Target.z > 51200.0f)
		Target.z = 51200.0f;
	
	//taiyo 烙矫贸府 
	VECTOR3 CollisonPos;
	
	MAPTYPE MapNum = GAMERESRCMNGR->GetLoadMapNum();
	if(g_pServerSystem->GetMap()->CollisionCheck(pThisPos,&Target,&CollisonPos,this) == TRUE)
	{
		Target.x = decisionPoint.x - dx;
		Target.z = decisionPoint.z - dz;
	}
	if(g_pServerSystem->GetMap()->CollisionCheck(pThisPos,&Target,&CollisonPos,this) == TRUE)
	{
		Target.x = decisionPoint.x + dx;
		Target.z = decisionPoint.z - dz;
	}
	if(g_pServerSystem->GetMap()->CollisionCheck(pThisPos,&Target,&CollisonPos,this) == TRUE)
	{
		Target.x = decisionPoint.x - dx;
		Target.z = decisionPoint.z + dz;
	}

	//YH2DO
	if(Target.x < 10)
		Target.x = 10;
	else if(Target.x > 51200)
		Target.x = 51200;
	if(Target.z < 10)
		Target.z = 10;
	else if(Target.z > 51200)
		Target.z = 51200;
	
	OnMove(&Target);

	return TRUE;
}

BOOL CMonster::DoPursuit(CObject * pTObject)
{
	CObject * pObj = pTObject;
	if( !m_pTObject)
		return FALSE;
	else
		pObj = m_pTObject;

	if(!pObj) return FALSE;

	VECTOR3 TObjectPos = *CCharMove::GetPosition(pObj);

	OnMove(&TObjectPos);

	return TRUE;
}

void CMonster::DoRunaway()
{
	MONSTEREX_LIST * pEXSInfo = (MONSTEREX_LIST *)m_pSInfo;
	VECTOR3 MovePoint;
	VECTOR3 * pThisPos = CCharMove::GetPosition(this);

	switch(m_aiParam.RunawayType)
	{
	case eRunawayType_Help:
		{
			ASSERT(m_aiParam.pHelperMonster);
			VECTOR3 * pHelperPos = CCharMove::GetPosition(m_aiParam.pHelperMonster);
			MovePoint.x = pHelperPos->x;
			MovePoint.y = 0;
			MovePoint.z = pHelperPos->z;
		}
		break;
	case eRunawayType_General:
		{
			m_aiParam.pHelperMonster = NULL;

			VECTOR3 IDir;
			IDir.x = -m_MoveInfo.Move_Direction.x;
			IDir.z = -m_MoveInfo.Move_Direction.z;
			BeelinePoint(pThisPos, &IDir, pEXSInfo->RunawayDistance, &MovePoint);
		}
		break;
	}
	VECTOR3 Target;

	Target.x = MovePoint.x;
	Target.z = MovePoint.z;

	if(Target.x < 10.0f)
		Target.x = 10.0f;
	else if(Target.x > 51200.0f)
		Target.x = 51200.0f;

	if(Target.z < 10.0f)
		Target.z = 10.0f;
	else if(Target.z > 51200.0f)
		Target.z = 51200.0f;

	//taiyo 烙矫贸府 
	VECTOR3 CollisonPos;
	
	MAPTYPE MapNum = GAMERESRCMNGR->GetLoadMapNum();
	if(g_pServerSystem->GetMap()->CollisionCheck(pThisPos,&Target,&CollisonPos,this) == TRUE)
	{
		Target.x = MovePoint.x - 100;
		Target.z = MovePoint.z - 100;
	}
	if(g_pServerSystem->GetMap()->CollisionCheck(pThisPos,&Target,&CollisonPos,this) == TRUE)
	{
		Target.x = MovePoint.x + 100;
		Target.z = MovePoint.z - 100;
	}
	if(g_pServerSystem->GetMap()->CollisionCheck(pThisPos,&Target,&CollisonPos,this) == TRUE)
	{
		Target.x = MovePoint.x - 100;
		Target.z = MovePoint.z + 100;
	}


	if(Target.x < 10)
		Target.x = 10;
	if(Target.z < 10)
		Target.z = 10;
	if(Target.x > 51200)
		Target.x = 51200;
	if(Target.z > 51200)
		Target.z = 51200;
	
	OnMove(&Target);
}

CMonster * CMonster::DoFriendSearch(DWORD Range)
{
	return (CMonster *)g_pServerSystem->GetGridSystem()->FindMonsterInRange(CCharMove::GetPosition(this), (float)Range, this, FIND_FIRST );
}

CObject * CMonster::DoSearch()
{
	return g_pServerSystem->GetGridSystem()->FindPlayerInRange(CCharMove::GetPosition(this), (float)m_pSInfo->SearchRange, this,(BYTE)m_pSInfo->TargetSelect );
}

CObject * CMonster::OnCollisionObject()
{
	return g_pServerSystem->GetGridSystem()->FindPlayerInRange(CCharMove::GetPosition(this), (float)m_pSInfo->MonsterRadius, this, FIND_FIRST );
}

void CMonster::Drop()
{
	VECTOR3* KilledPosition = CCharMove::GetPosition(this);
	DWORD TotalLife = GetSMonsterList()->Life;
	m_Distributer.Distribute(m_KillerPlayer,KilledPosition,m_DropItemId, m_dwDropItemRatio, this);
}

void CMonster::AddStatus(CStatus* pStatus)
{
	CObject::AddStatus(pStatus);

	if(pStatus->GetFlag() & STATUS_FLAG_MOVE)
	{
		MoveStop();
		DoPursuit();
	}
}

void CMonster::RemoveStatus(CStatus* pStatus)
{
	CObject::RemoveStatus(pStatus);

	if(pStatus->GetFlag() & STATUS_FLAG_MOVE)
	{
		MoveStop();
		DoPursuit();
	}
}

⌨️ 快捷键说明

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