186 lines
4.9 KiB
C#
186 lines
4.9 KiB
C#
using Photon.Pun;
|
|
using System.Collections;
|
|
using System.Collections.Generic;
|
|
using UnityEngine;
|
|
|
|
public class DragonEnemyNPCController : BasicEnemyNPCController
|
|
{
|
|
[Header("Boss Related:")]
|
|
[SerializeField] protected GameEvent onBossDead;
|
|
|
|
DragonAnimatorController dragonAnimator;
|
|
|
|
[Header("Dragon Related:")]
|
|
[SerializeField] protected GameEvent onDragonDead;
|
|
[SerializeField] protected Transform NorthMostFlyingPoint;
|
|
[SerializeField] protected Transform SouthMostFlyingPoint;
|
|
|
|
protected bool isFlying = false;
|
|
protected bool isAwake = false;
|
|
|
|
public bool IsFlying => isFlying;
|
|
public bool IsAwake => isAwake;
|
|
|
|
|
|
public NPCAbilityPriorityManager flyingAbilityPriorityManager;
|
|
private NPCSightControllerBase sightController;
|
|
|
|
protected int attackCounter = 0;
|
|
|
|
Vector3 planedPosition = new Vector3();
|
|
Vector3 planedDestination = new Vector3();
|
|
float currentFlyingDistance;
|
|
|
|
Vector3 pickedFlyingDestination;
|
|
|
|
protected override void Awake()
|
|
{
|
|
base.Awake();
|
|
|
|
sightController = GetComponentInChildren<NPCSightControllerBase>();
|
|
}
|
|
|
|
protected override void Start()
|
|
{
|
|
base.Start();
|
|
|
|
dragonAnimator = (DragonAnimatorController)animatorController;
|
|
|
|
isAwake = false;
|
|
dragonAnimator.SetAwake(IsAwake);
|
|
}
|
|
|
|
public void SetAwakeState(bool isAwake)
|
|
{
|
|
this.isAwake = isAwake;
|
|
|
|
sightController.SetSightRange(isAwake ? GameConstants.GameBalancing.DragonFlyingSightRange : 20f);
|
|
|
|
dragonAnimator.SetAwake(isAwake);
|
|
}
|
|
|
|
public void SetFlyingState(bool flying)
|
|
{
|
|
if (flying)
|
|
pickedFlyingSpot = false;
|
|
|
|
this.isFlying = flying;
|
|
|
|
projectileRange = isFlying ? GameConstants.GameBalancing.DragonFlyingAttackRange : 22f;
|
|
|
|
|
|
|
|
dragonAnimator.SetFlying(flying);
|
|
}
|
|
|
|
[PunRPC]
|
|
protected override void RPC_OnDeath(bool lootDropped)
|
|
{
|
|
if (isDead) return;
|
|
|
|
onBossDead.Raise();
|
|
onDragonDead.Raise();
|
|
|
|
base.RPC_OnDeath(lootDropped);
|
|
}
|
|
|
|
protected override void OnNewTargetIdentified()
|
|
{
|
|
if (!isAwake)
|
|
SetAwakeState(true);
|
|
|
|
base.OnNewTargetIdentified();
|
|
}
|
|
|
|
protected override void TryAttack()
|
|
{
|
|
base.TryAttack();
|
|
}
|
|
|
|
protected override void GetHighestPriorityAvailableAbility()
|
|
{
|
|
if(isFlying)
|
|
ability = flyingAbilityPriorityManager.GetHighestPriorityAvailableAbility();
|
|
else
|
|
ability = abilityPriorityManager.GetHighestPriorityAvailableAbility();
|
|
}
|
|
|
|
public override void OnAttackAnimationEventTriggered()
|
|
{
|
|
base.OnAttackAnimationEventTriggered();
|
|
|
|
if (!photonView.IsMine) return;
|
|
|
|
attackCounter++;
|
|
if (attackCounter >= GetCorrectNumberOfAttacksBasedOnStance())
|
|
{
|
|
attackCounter = 0;
|
|
SetFlyingState(!isFlying);
|
|
}
|
|
}
|
|
|
|
|
|
bool pickedFlyingSpot = false;
|
|
|
|
protected override void ChasingUpdate()
|
|
{
|
|
if (!photonView.IsMine) return;
|
|
if (!isAwake) return;
|
|
|
|
if (IsReadyToAttack())
|
|
{
|
|
TryAttack();
|
|
}
|
|
else if (isFlying)
|
|
{
|
|
if (!pickedFlyingSpot)
|
|
{
|
|
pickedFlyingSpot = true;
|
|
pickedFlyingDestination = Random.Range(0, 2) > 0 ? NorthMostFlyingPoint.position : SouthMostFlyingPoint.position;
|
|
SetupAgentStats(pickedFlyingDestination, true);
|
|
}
|
|
|
|
planedPosition = agent.transform.position;
|
|
planedPosition.y = 0f;
|
|
|
|
planedDestination = agent.destination;
|
|
planedDestination.y = 0f;
|
|
|
|
currentFlyingDistance = Vector3.Distance(planedPosition, planedDestination);
|
|
if (currentFlyingDistance <= distanceToChangePatrolDestination)
|
|
SetupAgentStats(pickedFlyingDestination == NorthMostFlyingPoint.position ? SouthMostFlyingPoint.position : NorthMostFlyingPoint.position, true);
|
|
}
|
|
else
|
|
{
|
|
SetupAgentStats(currentTarget.transform.position, true);
|
|
|
|
if (agent.remainingDistance > agent.stoppingDistance)
|
|
SetAgentMoving(true);
|
|
else
|
|
SetAgentMoving(false);
|
|
}
|
|
}
|
|
|
|
protected override void SetupAgentStats(Vector3 destination, bool chasing = false)
|
|
{
|
|
base.SetupAgentStats(destination, chasing);
|
|
|
|
if (isFlying)
|
|
agent.speed = GameConstants.GameBalancing.DragonFlyingSpeed;
|
|
}
|
|
|
|
protected override void PatrollingUpdate()
|
|
{
|
|
if (!photonView.IsMine) return;
|
|
if (!isAwake) return;
|
|
}
|
|
|
|
protected int GetCorrectNumberOfAttacksBasedOnStance()
|
|
{
|
|
if (IsFlying)
|
|
return GameConstants.GameBalancing.DragonFlyingAttacksNeededToChangeToGroundStance;
|
|
else
|
|
return GameConstants.GameBalancing.DragonGroundAttacksNeededToChangeToFlyingStance;
|
|
}
|
|
}
|