Example #1
0
        public override async ETTask Execute(AIComponent aiComponent, AIConfig aiConfig, ETCancellationToken cancellationToken)
        {
            Scene clientScene = aiComponent.DomainScene();

            Unit myUnit = Client.UnitHelper.GetMyUnitFromClientScene(clientScene);

            if (myUnit == null)
            {
                return;
            }

            // 停在当前位置
            clientScene.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;
                }
            }
        }
Example #2
0
        public override async ETTask Execute(AIComponent aiComponent, AIConfig aiConfig, ETCancellationToken cancellationToken)
        {
            Scene clientScene = aiComponent.DomainScene();

            Unit myUnit = Client.UnitHelper.GetMyUnitFromClientScene(clientScene);

            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();
            }
        }