55 lines
1.6 KiB
C#
55 lines
1.6 KiB
C#
using System.Collections.Generic;
|
|
using AI;
|
|
using Base;
|
|
using Data;
|
|
using UnityEngine;
|
|
|
|
namespace Entity
|
|
{
|
|
public abstract class Entity:MonoBehaviour,ITick
|
|
{
|
|
public string name;
|
|
public bool playerControlled = false;
|
|
public AIBase aiTree;
|
|
public JobBase currentJob;
|
|
public AttributesDef runtimeAttributes;
|
|
public Vector3 direction;
|
|
|
|
private const int WarningInterval = 5000;
|
|
private int warningTicks = 0;
|
|
|
|
public void Tick()
|
|
{
|
|
if (currentJob == null || !currentJob.Running)
|
|
{
|
|
currentJob = aiTree.GetJob(this);
|
|
if (currentJob == null)
|
|
{
|
|
if (warningTicks<=0)
|
|
{
|
|
Debug.LogWarning($"{GetType().Name}类型的{name}没有分配到任何工作,给行为树末尾添加等待行为,避免由于没有工作导致无意义的反复查找工作导致性能问题");
|
|
warningTicks += WarningInterval;
|
|
}
|
|
|
|
warningTicks--;
|
|
return;
|
|
}
|
|
}
|
|
|
|
currentJob.Update();
|
|
}
|
|
|
|
public virtual void TryAttck()
|
|
{
|
|
|
|
}
|
|
|
|
public virtual void OnHit(Entity from)
|
|
{
|
|
var hit = from.runtimeAttributes.attack - runtimeAttributes.defense;
|
|
if (hit < 0)
|
|
hit = from.runtimeAttributes.attack / 100;
|
|
runtimeAttributes.health -= hit;
|
|
}
|
|
}
|
|
} |