using System.Collections; using System.Collections.Generic; using UnityEngine; public class FriendlyNPCController : BasicEnemyNPCController { [SerializeField] private GameEventListener_RiftPlayer onPlayerSpawned; protected bool isReady = false; Taggable owner; protected override void Awake() { base.Awake(); onPlayerSpawned.Response.AddListener((riftPlayer) => EnableCombat(riftPlayer.GetComponent())); } protected override void Start() { base.Start(); } public void EnableCombat(Taggable player) { owner = player; isReady = true; } public void DisableCombat() { isReady = false; } protected override void Update() { if (isDead) return; if (!isReady) { SetAgentMoving(false); return; } counter += Time.deltaTime; if (HasTarget()) { ChasingUpdate(); } else { PatrollingUpdate(); } } protected override void PatrollingUpdate() { if (!HasAvailableTargets()) { //Debug.Log("BRAIN: !HasAVailableTargetsInside"); if (currentTarget != null) { //Debug.Log("BRAIN: TargetWasNull"); currentTarget = null; } if (agent.destination == null) { //Debug.Log("BRAIN: DEstination Null"); FollowOwner(); } else if (agent.remainingDistance < distanceToChangePatrolDestination) { //Debug.Log("BRAIN: StoppingDistanceReached"); FollowOwner(); } else { //Debug.Log("BRAIN: Else"); FollowOwner(); } } else { //Debug.Log("BRAIN: Else Else"); FollowOwner(); if (currentTarget == null) { UpdateCurrentTarget(GetClosestTarget()); } } } protected virtual void FollowOwner() { agent.speed = patrolAgentSpeed; patrolDestination = owner.transform.position; patrolDestination.y = 0f; UpdatePatrolTarget(patrolDestination); SetAgentMoving(true); //Debug.Log("BRAIN: Following owner"); } protected virtual void FollowInstruction(Vector3 instructionPosition) { agent.speed = patrolAgentSpeed; patrolDestination = instructionPosition; patrolDestination.y = 0f; UpdatePatrolTarget(patrolDestination); SetAgentMoving(true); } protected override void RPC_OnDeath(bool lootDropped) { if (isDead) return; //Debug.Log($"{this.gameObject.name} died!"); isDead = true; agent.enabled = false; //experienceOnDeath.Raise(health.GetMaxValue() * GameConstants.GameBalancing.HealthIntoExperienceMultiplier); //dropTable.DropLoot(lootDropped); animatorController.SetDead(); } }