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.
83 lines
2.2 KiB
C#
83 lines
2.2 KiB
C#
using Entitas;
|
|
using UnityEngine;
|
|
using Game;
|
|
public class AISystem : IExecuteSystem, IInitializeSystem
|
|
{
|
|
private IGroup<GameEntity> _entities;
|
|
public void Initialize()
|
|
{
|
|
_entities = Util.GetGroup(GameMatcher.AI);
|
|
}
|
|
public void Execute()
|
|
{
|
|
foreach (var entity in _entities)
|
|
{
|
|
UpdateAIBlueprint(entity);
|
|
UpdateAIHungry(entity);
|
|
}
|
|
}
|
|
|
|
private 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 void UpdateAIBlueprint(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;
|
|
}
|
|
ai.Data.Entity = entity.ID();
|
|
ai.Data.Owner = entity.Owner();
|
|
ai.Data.Target = entity.Target();
|
|
if (!ai.IsInit)
|
|
{
|
|
ai.IsInit = true;
|
|
Util.RunBp(GameConst.BlueprintAICommon, GameConst.BpEntranceEnter, ai.Data);
|
|
Util.RunBp(id.Data.Blueprint, GameConst.BpEntranceEnter, ai.Data);
|
|
}
|
|
ai.ThinkCdNow -= Time.deltaTime;
|
|
if (ai.ThinkCdNow > 0)
|
|
{
|
|
return;
|
|
}
|
|
ai.ThinkCdNow = ai.ThinkCdMax;
|
|
if (Util.EntityIsStagger(entity))
|
|
{
|
|
return;
|
|
}
|
|
if (skill.IsRunning)
|
|
{
|
|
return;
|
|
}
|
|
Util.RunBp(GameConst.BlueprintAICommon, GameConst.BpEntranceUpdate, ai.Data);
|
|
Util.RunBp(id.Data.Blueprint, GameConst.BpEntranceUpdate, ai.Data);
|
|
}
|
|
|
|
} |