using Entitas; using UnityEngine; using Game; public class AISystem : IExecuteSystem, IInitializeSystem { private IGroup _entities; public void Initialize() { _entities = Util.GetGroup(GameMatcher.AI); } public void Execute() { foreach (var entity in _entities) { UpdateAI(entity); UpdateAIHungry(entity); } } private static void UpdateAIHungry(GameEntity entity) { var ai = entity.aI; var hp = entity.hp; if (!hp.IsAlive) { return; } if (ai.IsHungryFull.Value) { return; } if (ai.AttackPermit.Value) { return; } 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; } } private static void UpdateAI(GameEntity entity) { var id = entity.iD; var ai = entity.aI; var skill = entity.skill; var hp = entity.hp; var buff = entity.buff; if (!hp.IsAlive) { return; } if (!ai.IsInit) { ai.IsInit = true; } ai.ThinkCdNow -= Time.deltaTime; if (ai.ThinkCdNow > 0) { return; } ai.ThinkCdNow = ai.ThinkCdMax; if (skill.IsRunning) { return; } ai.BehaviorTree.Tick(); } }