mirror of
https://github.com/Alex-Rachel/TEngine.git
synced 2025-08-14 16:51:28 +00:00
[+] 接入ET8服务端
[+] 接入ET8服务端
This commit is contained in:
@@ -0,0 +1,92 @@
|
||||
using System;
|
||||
|
||||
namespace ET
|
||||
{
|
||||
[EntitySystemOf(typeof(AIComponent))]
|
||||
[FriendOf(typeof(AIComponent))]
|
||||
[FriendOf(typeof(AIDispatcherComponent))]
|
||||
public static partial class AIComponentSystem
|
||||
{
|
||||
[Invoke(TimerInvokeType.AITimer)]
|
||||
public class AITimer: ATimer<AIComponent>
|
||||
{
|
||||
protected override void Run(AIComponent self)
|
||||
{
|
||||
try
|
||||
{
|
||||
self.Check();
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
Log.Error($"move timer error: {self.Id}\n{e}");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
[EntitySystem]
|
||||
private static void Awake(this AIComponent self, int aiConfigId)
|
||||
{
|
||||
self.AIConfigId = aiConfigId;
|
||||
self.Timer = self.Fiber().TimerComponent.NewRepeatedTimer(1000, TimerInvokeType.AITimer, self);
|
||||
}
|
||||
|
||||
[EntitySystem]
|
||||
private static void Destroy(this AIComponent self)
|
||||
{
|
||||
self.Fiber().TimerComponent?.Remove(ref self.Timer);
|
||||
self.CancellationToken?.Cancel();
|
||||
self.CancellationToken = null;
|
||||
self.Current = 0;
|
||||
}
|
||||
|
||||
private static void Check(this AIComponent self)
|
||||
{
|
||||
if (self.Parent == null)
|
||||
{
|
||||
self.Fiber().TimerComponent.Remove(ref self.Timer);
|
||||
return;
|
||||
}
|
||||
|
||||
var oneAI = AIConfigCategory.Instance.AIConfigs[self.AIConfigId];
|
||||
|
||||
foreach (AIConfig aiConfig in oneAI.Values)
|
||||
{
|
||||
|
||||
AAIHandler aaiHandler = AIDispatcherComponent.Instance.Get(aiConfig.Name);
|
||||
|
||||
if (aaiHandler == null)
|
||||
{
|
||||
Log.Error($"not found aihandler: {aiConfig.Name}");
|
||||
continue;
|
||||
}
|
||||
|
||||
int ret = aaiHandler.Check(self, aiConfig);
|
||||
if (ret != 0)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
if (self.Current == aiConfig.Id)
|
||||
{
|
||||
break;
|
||||
}
|
||||
|
||||
self.Cancel(); // 取消之前的行为
|
||||
ETCancellationToken cancellationToken = new ETCancellationToken();
|
||||
self.CancellationToken = cancellationToken;
|
||||
self.Current = aiConfig.Id;
|
||||
|
||||
aaiHandler.Execute(self, aiConfig, cancellationToken).Coroutine();
|
||||
return;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
private static void Cancel(this AIComponent self)
|
||||
{
|
||||
self.CancellationToken?.Cancel();
|
||||
self.Current = 0;
|
||||
self.CancellationToken = null;
|
||||
}
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user