2
0
Fork 0
You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

74 lines
1.6 KiB
C#

2 years ago
using Entitas;
using UnityEngine;
using Game;
2 years ago
public class AISystem : IExecuteSystem, IInitializeSystem
{
private IGroup<GameEntity> _entities;
2 years ago
public void Initialize()
{
_entities = Util.GetGroup(GameMatcher.AI);
}
2 years ago
public void Execute()
{
foreach (var entity in _entities)
{
2 years ago
UpdateAI(entity);
2 years ago
UpdateAIHungry(entity);
}
}
2 years ago
private static void UpdateAIHungry(GameEntity entity)
2 years ago
{
var ai = entity.aI;
var hp = entity.hp;
if (!hp.IsAlive)
{
return;
}
2 years ago
if (ai.IsHungryFull.Value)
{
return;
}
2 years ago
if (ai.AttackPermit.Value)
{
return;
}
2 years ago
var newHungry = ai.Hungry.Value + ai.HungryIncrease * ai.HungryIncreaseRate * Time.deltaTime;
ai.Hungry.Value = Mathf.Min(ai.HungryMax.Value, newHungry);
if (ai.Hungry.Value >= ai.HungryMax.Value)
{
ai.IsHungryFull.Value = true;
ai.Hungry.Value = 0;
}
}
2 years ago
private static void UpdateAI(GameEntity entity)
2 years ago
{
var ai = entity.aI;
var skill = entity.skill;
var hp = entity.hp;
if (!hp.IsAlive)
{
return;
}
2 years ago
ai.ThinkCdNow -= Time.deltaTime;
if (ai.ThinkCdNow > 0)
{
return;
}
2 years ago
ai.ThinkCdNow = ai.ThinkCdMax;
if (skill.IsRunning)
{
return;
}
2 years ago
ai.BehaviorTree.Tick();
2 years ago
}
}