public override async ETTask Execute(AIComponent aiComponent, AIConfig aiConfig, ETCancellationToken cancellationToken) { Scene zoneScene = aiComponent.DomainScene(); Unit myUnit = UnitHelper.GetMyUnitFromZoneScene(zoneScene); if (myUnit == null) { return; } Log.Debug("开始巡逻"); while (true) { XunLuoPathComponent xunLuoPathComponent = myUnit.GetComponent <XunLuoPathComponent>(); Vector3 nextTarget = xunLuoPathComponent.GetCurrent(); int ret = await myUnit.MoveToAsync(nextTarget, cancellationToken); if (ret != 0) { return; } xunLuoPathComponent.MoveNext(); } }
public override async ETVoid Execute(AIComponent aiComponent, AIConfig aiConfig, ETCancellationToken cancellationToken) { Scene zoneScene = aiComponent.DomainScene(); Unit myUnit = zoneScene.GetComponent <UnitComponent>().MyUnit; if (myUnit == null) { return; } // 停在当前位置 zoneScene.GetComponent <SessionComponent>().Session.Send(new C2M_Stop()); Log.Debug("开始攻击"); for (int i = 0; i < 100000; ++i) { Log.Debug($"攻击: {i}次"); // 因为协程可能被中断,任何协程都要传入cancellationToken,判断如果是中断则要返回 bool timeRet = await TimerComponent.Instance.WaitAsync(1000, cancellationToken); if (!timeRet) { return; } } }
public override async ETTask Execute(AIComponent aiComponent, AIConfig aiConfig, ETCancellationToken cancellationToken) { Unit myUnit = aiComponent.GetParent <Unit>(); if (myUnit == null) { return; } Log.Info("开始追逐"); ZhuiZhuAimComponent zhuiZhuAimPathComponent = myUnit.GetComponent <ZhuiZhuAimComponent>(); while (zhuiZhuAimPathComponent?.Aim != null) { Vector3 nextTarget = zhuiZhuAimPathComponent.Aim.Position; #if SERVER myUnit.FindPathMoveToAsync(nextTarget, cancellationToken).Coroutine(); await TimerComponent.Instance.WaitAsync(100); #else myUnit.MoveToAsync(nextTarget, cancellationToken).Coroutine(); await TimerComponent.Instance.WaitAsync(10); #endif if (Vector3.Distance(nextTarget, myUnit.Position) < 0.1f) { zhuiZhuAimPathComponent.Arrived(); } } }
public override int Check(AIComponent aiComponent, AIConfig aiConfig) { long sec = TimeHelper.ClientNow() / 1000 % 15; if (sec >= 10) { return(0); } return(1); }
public override void EndInit() { for (int i = 0; i < list.Count; i++) { AIConfig config = list[i]; config.EndInit(); this.dict.Add(config.Id, config); } this.AfterEndInit(); }
public override int Check(AIComponent aiComponent, AIConfig aiConfig) { Unit myUnit = aiComponent.GetParent <Unit>(); Log.Info("Check"); if (myUnit == null) { Log.Info("myUnit == null"); return(1); } ZhuiZhuAimComponent zhuiZhuAimPathComponent = myUnit.GetComponent <ZhuiZhuAimComponent>(); if (zhuiZhuAimPathComponent == null || zhuiZhuAimPathComponent.Aim == null) { Log.Info("zhuiZhuAimPathComponent == null||zhuiZhuAimPathComponent.Aim==null"); return(2); } return(0); }
// 协程编写必须可以取消 public abstract ETTask Execute(AIComponent aiComponent, AIConfig aiConfig, ETCancellationToken cancellationToken);
// 检查是否满足条件 public abstract int Check(AIComponent aiComponent, AIConfig aiConfig);