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.
124 lines
3.6 KiB
C#
124 lines
3.6 KiB
C#
|
2 years ago
|
using Entitas;
|
||
|
|
using Game;
|
||
|
|
|
||
|
|
namespace Game
|
||
|
|
{
|
||
|
|
public enum EAIModuleType
|
||
|
|
{
|
||
|
|
Spectator,
|
||
|
|
Melee,
|
||
|
|
LongRange,
|
||
|
|
Max,
|
||
|
|
}
|
||
|
|
}
|
||
|
|
|
||
|
|
[Game]
|
||
|
|
public class AIComponent : IComponent
|
||
|
|
{
|
||
|
|
public BlueprintBasicData Data;
|
||
|
|
public bool IsInit = false;
|
||
|
|
public float ThinkCdMax;//思考频率
|
||
|
|
public float ThinkCdNow;
|
||
|
|
public MetaData<float> Hungry = new MetaData<float>();
|
||
|
|
public MetaData<float> HungryMax = new MetaData<float>();
|
||
|
|
public MetaData<EAIModuleType> ModuleType = new MetaData<EAIModuleType>();
|
||
|
|
public float HungryIncrease; //饥饿值自增速率
|
||
|
|
public float HungryIncreaseRate; //饥饿值自增倍率
|
||
|
|
public MetaData<bool> IsHungryFull = new MetaData<bool>();//饥饿值满
|
||
|
|
public MetaData<bool> AttackPermit = new MetaData<bool>();//攻击权限
|
||
|
|
}
|
||
|
|
|
||
|
|
namespace Game
|
||
|
|
{
|
||
|
|
public abstract partial class Util
|
||
|
|
{
|
||
|
|
public static void ClearAI(GameEntity entity)
|
||
|
|
{
|
||
|
|
var ai = entity.aI;
|
||
|
|
ai.IsInit = false;
|
||
|
|
ai.Hungry.Value = 0;
|
||
|
|
ai.HungryMax.Value = 1;
|
||
|
|
ai.IsHungryFull.Value = false;
|
||
|
|
ai.AttackPermit.Value = false;
|
||
|
|
}
|
||
|
|
public static void SetThinkCd(int entity, float cd)
|
||
|
|
{
|
||
|
|
var e = Util.GetEntity(entity);
|
||
|
|
if (e != null)
|
||
|
|
{
|
||
|
|
e.aI.ThinkCdMax = cd;
|
||
|
|
//设置一个随机的初始值
|
||
|
|
e.aI.ThinkCdNow = GameRandom.Random(0, cd);
|
||
|
|
}
|
||
|
|
}
|
||
|
|
public static void SetHungryBasic(int entity, float max, float now, float increase)
|
||
|
|
{
|
||
|
|
var e = Util.GetEntity(entity);
|
||
|
|
if (e != null)
|
||
|
|
{
|
||
|
|
var ai = e.aI;
|
||
|
|
ai.HungryMax.Value = max;
|
||
|
|
ai.Hungry.Value = now;
|
||
|
|
ai.HungryIncrease = increase;
|
||
|
|
}
|
||
|
|
}
|
||
|
|
public static void SetHungryIncreaseRate(int entity, float increaseRate)
|
||
|
|
{
|
||
|
|
var e = Util.GetEntity(entity);
|
||
|
|
if (e != null)
|
||
|
|
{
|
||
|
|
var ai = e.aI;
|
||
|
|
ai.HungryIncreaseRate = increaseRate;
|
||
|
|
}
|
||
|
|
}
|
||
|
|
public static void SetAIModuleType(int entity, EAIModuleType type)
|
||
|
|
{
|
||
|
|
var e = Util.GetEntity(entity);
|
||
|
|
if (e != null)
|
||
|
|
{
|
||
|
|
var ai = e.aI;
|
||
|
|
ai.ModuleType.Value = type;
|
||
|
|
}
|
||
|
|
}
|
||
|
|
public static EAIModuleType GetAIModuleType(int entity)
|
||
|
|
{
|
||
|
|
var e = Util.GetEntity(entity);
|
||
|
|
if (e != null)
|
||
|
|
{
|
||
|
|
var ai = e.aI;
|
||
|
|
return ai.ModuleType.Value;
|
||
|
|
}
|
||
|
|
return EAIModuleType.Spectator;
|
||
|
|
}
|
||
|
|
public static void SetAttackPermit(int entity, bool value)
|
||
|
|
{
|
||
|
|
var e = Util.GetEntity(entity);
|
||
|
|
if (e != null)
|
||
|
|
{
|
||
|
|
var ai = e.aI;
|
||
|
|
ai.AttackPermit.Value = value;
|
||
|
|
ai.IsHungryFull.Value = false;
|
||
|
|
}
|
||
|
|
}
|
||
|
|
public static bool GetAttackPermit(int entity)
|
||
|
|
{
|
||
|
|
var e = Util.GetEntity(entity);
|
||
|
|
if (e != null)
|
||
|
|
{
|
||
|
|
var ai = e.aI;
|
||
|
|
return ai.AttackPermit.Value;
|
||
|
|
}
|
||
|
|
return false;
|
||
|
|
}
|
||
|
|
public static bool GetHungryFull(int entity)
|
||
|
|
{
|
||
|
|
var e = Util.GetEntity(entity);
|
||
|
|
if (e != null)
|
||
|
|
{
|
||
|
|
var ai = e.aI;
|
||
|
|
return ai.IsHungryFull.Value;
|
||
|
|
}
|
||
|
|
return false;
|
||
|
|
}
|
||
|
|
}
|
||
|
|
}
|