116 lines
2.4 KiB
C#
116 lines
2.4 KiB
C#
using System.Collections;
|
|
using HurricaneVR.Framework.Components;
|
|
using NodeCanvas.Framework;
|
|
using UnityEngine;
|
|
using Zero;
|
|
|
|
public class NpcBotSpiderCombat : NpcCombatAbstract
|
|
{
|
|
|
|
[SerializeField] private float health;
|
|
public override float GetHealth() => health;
|
|
|
|
[SerializeField] private float cooldownTimeAttack = 2f;
|
|
[SerializeField] private ExtGunBase weapon;
|
|
[SerializeField] private Transform head;
|
|
[SerializeField] private Quaternion headOffset;
|
|
[SerializeField] private GameObject explosionPrefab;
|
|
|
|
private bool isRange;
|
|
private Transform targetToAim;
|
|
private float nextTime;
|
|
private Status status;
|
|
private PlayerTargetPosition playerTarget;
|
|
|
|
public override Status UpdateTime()
|
|
{
|
|
nextTime += Time.deltaTime;
|
|
UpdateCombatTime();
|
|
return Status.Success;
|
|
}
|
|
|
|
public override Status Attack(GameObject target, bool isRange)
|
|
{
|
|
SetCombatState();
|
|
if(targetToAim != target.transform)
|
|
{
|
|
playerTarget = target.GetComponent<PlayerTargetPosition>();
|
|
UpdateAim(target.transform);
|
|
}
|
|
targetToAim = target.transform;
|
|
if(status == Status.Running)
|
|
{
|
|
return status;
|
|
}
|
|
StartCoroutine(AttackState(target.transform, isRange));
|
|
return status;
|
|
}
|
|
|
|
IEnumerator AttackState(Transform target, bool isRange)
|
|
{
|
|
if (nextTime >= cooldownTimeAttack)
|
|
{
|
|
status = Status.Running;
|
|
|
|
this.isRange = isRange;
|
|
UpdateAim(target);
|
|
status = Status.Success;
|
|
nextTime = 0;
|
|
weapon.CallShoot();
|
|
}
|
|
|
|
yield return null;
|
|
}
|
|
|
|
public void UpdateAim(Transform target)
|
|
{
|
|
if (playerTarget)
|
|
{
|
|
target = playerTarget.GetTarget();
|
|
}
|
|
|
|
head.transform.LookAt(target);
|
|
var pos = head.transform.rotation * headOffset;
|
|
head.transform.rotation = pos;
|
|
weapon.transform.LookAt(target);
|
|
}
|
|
|
|
public override Status Aggressive()
|
|
{
|
|
return Status.Success;
|
|
}
|
|
|
|
public override Status GetAttackStatus()
|
|
{
|
|
if (nextTime < cooldownTimeAttack) return Status.Running;
|
|
return Status.Success;
|
|
}
|
|
|
|
public override Status ResetCooldown()
|
|
{
|
|
nextTime = cooldownTimeAttack;
|
|
return Status.Success;
|
|
}
|
|
|
|
public void OnHit(HVRDamageProvider damageProvider, RaycastHit hit)
|
|
{
|
|
health -= damageProvider.Damage;
|
|
|
|
if(health <= 0)
|
|
{
|
|
health = 0;
|
|
if(explosionPrefab)
|
|
{
|
|
var explosion = Instantiate(explosionPrefab, transform.position, Quaternion.identity);
|
|
Destroy(explosion, 2f);
|
|
explosionPrefab = null;
|
|
}
|
|
Destroy(gameObject, 2f);
|
|
}
|
|
else
|
|
{
|
|
SetCombatState();
|
|
}
|
|
}
|
|
}
|