예제 #1
0
        public void Reset()
        {
            foreach (var coroutine in Coroutines)
            {
                coroutine.Reset();
            }

            if (WaypointNumber == 13)
            {
                var firstCoroutine = Coroutines.FirstOrDefault();
                if (firstCoroutine != null && !(firstCoroutine is MoveToPositionCoroutine))
                {
                    //<SafeMoveTo questId="312429" stepId="2" x="2401" y="4537" z="-2" pathPrecision="5" pathPointLimit="250" scene="trOut_Highlands_Roads_EW_03" statusText="" />
                    Coroutines.Insert(0, new MoveToPositionCoroutine(71150, new Vector3(2401, 4537, -2)));
                }
            }
            //if (WaypointNumber == 14)
            //{
            //    var firstCoroutine = Coroutines.FirstOrDefault();
            //    if (firstCoroutine != null && !(firstCoroutine is MoveToPositionCoroutine))
            //    {
            //        //<SafeMoveTo questId="312429" stepId="2" x="2401" y="4537" z="-2" pathPrecision="5" pathPointLimit="250" scene="trOut_Highlands_Roads_EW_03" statusText="" />
            //        Coroutines.Insert(0, new MoveToPositionCoroutine(new Vector3(1472, 4027, 38)));
            //    }

            //}
        }
예제 #2
0
        public IEnumerator TestRepeatWhile()
        {
            // ensure never executed on false
            var done = false;

            Coroutines.RepeatWhile(() => false, () => done = true).Start();
            Assert.IsFalse(done);
            yield return(null);

            yield return(null);

            Assert.IsFalse(done);

            // ensure stops once false
            var c = 0;

            Coroutines.RepeatWhile(() => !done, () => ++ c).Start();
            for (var i = c; i < 10; ++i)
            {
                Assert.AreEqual(i, c);
                yield return(null);
            }

            var finalC = c;

            done = true;
            yield return(null);

            Assert.AreEqual(finalC, c);
            yield return(null);

            Assert.AreEqual(finalC, c);
        }
예제 #3
0
        public IEnumerator TestAfterwards()
        {
            var repDone        = false;
            var afterwardsDone = false;

            Coroutines.RepeatWhile(() => false, () => repDone = true)
            .Afterwards(() => afterwardsDone = true).Start();
            Assert.IsFalse(repDone);
            Assert.IsTrue(afterwardsDone);
            yield return(null);

            Assert.IsFalse(repDone);
            Assert.IsTrue(afterwardsDone);

            // test that it works even with exceptions
            var counter = 0;

            Coroutines.RepeatWhile(
                () => true,
                () => { throw new Exception("Planned test exception"); })
            .Afterwards(() => counter++).Start();
            LogAssert.Expect(LogType.Exception, new Regex(".*"));
            yield return(null);

            yield return(null);

            yield return(null);

            Assert.AreEqual(counter, 1);
        }
예제 #4
0
파일: Runner.cs 프로젝트: zxc88645/ExileApi
        public Coroutine Run(IEnumerator enumerator, IPlugin owner, string name = null)
        {
            if (enumerator == null)
            {
                throw new NullReferenceException("Coroutine cant not be null.");
            }

            var routine = new Coroutine(enumerator, owner, name);

            lock (locker)
            {
                var first = Coroutines.FirstOrDefault(x => x.Name == routine.Name && x.Owner == routine.Owner);

                if (first != null)
                {
                    CountFalseAddCoroutines++;
                    return(first);
                }

                Coroutines.Add(routine);
                CoroutinePerformance.TryGetValue(routine.Name, out var t);
                CoroutinePerformance[routine.Name] = t;

                CountAddCoroutines++;
                return(routine);
            }
        }
예제 #5
0
    public override void Execute(IMessage message)
    {
        // //-----------------关联命令-----------------------
        // AppFacade.Instance.RegisterCommand(NotiConst.DISPATCH_MESSAGE, typeof(SocketCommand));

        Coroutines.StartACoroutineWithCallback(UpdateAssetBundles(), InitManager);
    }
예제 #6
0
 public static void Dispose()
 {
     if (!Coroutines.IsInitialising && IsInitialised)
     {
         EditorCoroutineUtility.StartCoroutineOwnerless(Coroutines.Dispose());
     }
 }
예제 #7
0
            public static void Prefix(UdpConnection __instance, byte sendOption, ref Il2CppSystem.Action ackCallback)
            {
                if (sendOption != 8 || AmongUsClient.Instance == null || AmongUsClient.Instance.connection == null || !AmongUsClient.Instance.connection.Equals(__instance))
                {
                    return;
                }

                ackCallback = (Action)(() =>
                {
                    if (__instance.State == ConnectionState.Connected)
                    {
                        return;
                    }

                    Logger <ReactorPlugin> .Debug("Hello was acked, waiting for modded handshake response");

                    var coroutine = Coroutines.Start(Coroutine(__instance));

                    __instance.Disconnected = Il2CppSystem.Delegate.Combine(
                        (Il2CppSystem.EventHandler <DisconnectedEventArgs>)(Action <Il2CppSystem.Object, DisconnectedEventArgs>) ((_, _) =>
                    {
                        Coroutines.Stop(coroutine);
                    }),
                        __instance.Disconnected
                        ).Cast <Il2CppSystem.EventHandler <DisconnectedEventArgs> >();
                });
            }
        public void SummonOutsider()
        {
            this.summonCounter++;
            if (this.summonCounter >= this.PsiEvent.SummonLocations.Length)
            {
                this.summonCounter = 0;
            }
            GameObject     spawnLocation = this.PsiEvent.SummonLocations[this.summonCounter];
            SpriteRenderer circleSprite  = spawnLocation.GetComponent <SpriteRenderer>();

            circleSprite.color = Color.clear;
            this.PsiEvent.SummonLocations[this.summonCounter].SetActive(true);
            Coroutines.EaseSpriteColor(
                target: circleSprite,
                color: Color.red,
                duration: 2f,
                callback: () =>
            {
                int randomIndex = Random.Range(0, this.PsiEvent.Enemies.Length);
                Instantiate(
                    this.PsiEvent.Enemies[randomIndex],
                    circleSprite.transform.position,
                    Quaternion.identity);
                spawnLocation.SetActive(false);
            });
        }
예제 #9
0
    public void FadeOutLevelMusic()
    {
        Services.Clock.eventManager.Unregister <Measure>(DynamicLevelMusicVolumes);
        previousVolumes = new List <float>();
        var to_destroy = levelMusicHolder;

        foreach (AudioSource source in levelMusicSources)
        {
            previousVolumes.Add(source.volume);
        }

        for (int i = 0; i < levelMusicSources.Count; i++)
        {
            AudioSource to_change      = levelMusicSources[i];
            float       starting_value = previousVolumes[i];
            float       new_value      = 0.0f;

            StartCoroutine(Coroutines.DoOverEasedTime(Services.Clock.MeasureLength(), Easing.Linear,
                                                      t =>
            {
                float new_volume = Mathf.Lerp(starting_value, new_value, t);
                to_change.volume = new_volume;
            }));
        }

        Delay(() =>
        {
            Destroy(to_destroy);
        }, Services.Clock.MeasureLength() * 2);
    }
예제 #10
0
    public TaskTree SlowMo(float duration, Vector3 location)
    {
        shaking = false;
        float startOrthographicSize = Camera.main.orthographicSize;

        ActionTask slow_down = new ActionTask(() =>
        {
            StartCoroutine(Coroutines.DoOverEasedTime(duration / 2, Easing.QuadEaseOut,
                                                      t =>
            {
                transform.position           = new Vector3(Mathf.Lerp(basePos.x, location.x, t), Mathf.Lerp(basePos.y, location.y, t), -10f);
                Camera.main.orthographicSize = Mathf.Lerp(startOrthographicSize, 4, t);
            }));
        });

        Wait wait = new Wait(duration / 2);

        ActionTask speed_up = new ActionTask(() =>
        {
            StartCoroutine(Coroutines.DoOverEasedTime(duration / 2, Easing.QuintEaseIn,
                                                      t =>
            {
                transform.position           = new Vector3(Mathf.Lerp(location.x, basePos.x, t), Mathf.Lerp(location.y, basePos.y, t), -10f);
                Camera.main.orthographicSize = Mathf.Lerp(4, startOrthographicSize, t);
            }));
        });

        Wait wait2 = new Wait(duration / 2);

        ActionTask reset = new ActionTask(() => { Camera.main.orthographicSize = startOrthographicSize; SetPosition(basePos); });

        TaskTree to_return = new TaskTree(slow_down, new TaskTree(wait, new TaskTree(speed_up, new TaskTree(wait2, new TaskTree(reset)))));

        return(to_return);
    }
예제 #11
0
 public void ShowGameOver() =>
 StartCoroutine(Coroutines.WaitForSeconds(gameOverScreenDelayTime,
                                          () =>
 {
     gameOverAnimator.gameObject.SetActive(true);
     gameOverAnimator.SetTrigger(GameOverIn);
 }));
예제 #12
0
    public TaskTree SlowTimeScale(float duration)
    {
        slow_mo = true;

        ActionTask slow_down = new ActionTask(() =>
        {
            StartCoroutine(Coroutines.DoOverEasedTime(duration / 2, Easing.QuintEaseOut,
                                                      t =>
            {
                Time.timeScale = Mathf.Lerp(1f, 0.1f, t);
            }));
        });

        Wait wait = new Wait(duration / 2);

        ActionTask speed_up = new ActionTask(() =>
        {
            StartCoroutine(Coroutines.DoOverEasedTime(duration / 2, Easing.QuintEaseIn,
                                                      t =>
            {
                Time.timeScale = Mathf.Lerp(0.1f, 1f, t);
            }));
        });

        Wait wait2 = new Wait(duration / 2);

        ActionTask reset = new ActionTask(() => { Time.timeScale = 1f; slow_mo = false; });

        TaskTree to_return = new TaskTree(slow_down, new TaskTree(wait, new TaskTree(speed_up, new TaskTree(wait2, new TaskTree(reset)))));

        return(to_return);
    }
예제 #13
0
        void Start()
        {
            Coroutines.Start(TestYieldNull());

            Coroutines.Start(TestAsyncApi(0));
            Coroutines.Start(TestAsyncApi(0.1f));

            Coroutines.Start(TestTooFastCallback());

            Coroutines.Start(TestMultiLevel());

            //Coroutines.Start( TestException() );

            // Unity Coroutine
            //StartCoroutine( TestException() );

            Coroutines.Start(TestGetResult());
            Coroutines.Start(TestGetResult_InvalidType());
            Coroutines.Start(TestGetResult_Exception());

            Coroutines.Start(TestAsyncApiWrapper_Normal());
            Coroutines.Start(TestAsyncApiWrapper_BeginException());
            Coroutines.Start(TestAsyncApiWrapper_EndException());

            Coroutines.Start(TestTryFinally());
        }
예제 #14
0
        private IEnumerator BeginGameEffect()
        {
            if (RelicCollection == null)
            {
                RelicCollection = new RelicCollection();
            }
            else
            {
                RelicCollection.Reset();
            }

            if (StatisticManager == null)
            {
                StatisticManager = new StatisticManager();
            }
            else
            {
                StatisticManager.Reset();
            }

            // Fire a game begun event.
            OnGameBegun(EventArgs.Empty);

            yield return(Coroutines.Pause(TimingHelper.GetFrameCount(2.5f)));

            // Kick off the game with a coalsced phase. This should always be the Calm phase and we do want the player to be notified of this.
            PhaseManager.CoalescePlane();

            // Add a coroutine to handle updating remaining game time.
            CoroutineManager.Add(UpdateRemainingGameTimeKey, UpdateGameTimer());
        }
예제 #15
0
        private static async Task <bool> CreateNewInstance(AreaTransition transition)
        {
            var name = transition.Name;

            if (!await Coroutines.InteractWith(transition, true))
            {
                GlobalLog.Error($"[CreateNewInstance] Fail to interact with \"{name}\" transition.");
                return(false);
            }

            if (!await Wait.For(() => LokiPoe.InGameState.InstanceManagerUi.IsOpened, "instance manager opening"))
            {
                return(false);
            }

            if (Settings.Instance.ArtificialDelays)
            {
                await Wait.ArtificialDelay();
            }

            GlobalLog.Debug($"[CreateNewInstance] Creating new instance for \"{name}\".");

            var err = LokiPoe.InGameState.InstanceManagerUi.JoinNewInstance();

            if (err != LokiPoe.InGameState.JoinInstanceResult.None)
            {
                GlobalLog.Error($"[CreateNewInstance] Fail to create a new instance. Error: \"{err}\".");
                return(false);
            }
            GlobalLog.Debug($"[CreateNewInstance] New instance for \"{name}\" has been successfully created.");
            return(true);
        }
예제 #16
0
    public TaskTree SlowMo(float duration)
    {
        silent = true;
        ActionTask slow_down = new ActionTask(() =>
        {
            StartCoroutine(Coroutines.DoOverEasedTime(duration / 2, Easing.Linear,
                                                      t =>
            {
                Services.AudioManager.SetPitch(Mathf.Lerp(1, 0.1f, t));
            }));
        });

        Wait wait = new Wait(duration / 2);

        ActionTask speed_up = new ActionTask(() =>
        {
            StartCoroutine(Coroutines.DoOverEasedTime(duration / 2, Easing.Linear,
                                                      t =>
            {
                Services.AudioManager.SetPitch(Mathf.Lerp(0.1f, 1, t));
            }));
        });

        Wait wait2 = new Wait(duration / 2);

        ActionTask reset = new ActionTask(() => { Services.AudioManager.SetPitch(1f); silent = false; });

        TaskTree to_return = new TaskTree(slow_down, new TaskTree(wait, new TaskTree(speed_up, new TaskTree(wait2, new TaskTree(reset)))));

        return(to_return);
    }
예제 #17
0
        public static async Task <bool> Interact(NetworkObject obj, int attempts)
        {
            if (obj == null)
            {
                GlobalLog.Error("[Interact] Object for interaction is null.");
                return(false);
            }

            var name = obj.Name;

            GlobalLog.Debug($"[Interact] Now going to interact with \"{name}\".");

            for (int i = 1; i <= attempts; i++)
            {
                if (!LokiPoe.IsInGame || LokiPoe.Me.IsDead)
                {
                    break;
                }

                await Coroutines.CloseBlockingWindows();

                await Coroutines.FinishCurrentAction();

                await Wait.LatencySleep();

                if (await Coroutines.InteractWith(obj))
                {
                    GlobalLog.Debug($"[Interact] \"{name}\" has been successfully interacted.");
                    return(true);
                }
                GlobalLog.Error($"[Interact] Fail to interact with \"{name}\". Attempt: {i}/{attempts}.");
                await Wait.SleepSafe(100, 200);
            }
            return(false);
        }
예제 #18
0
    public void ScreenTap()
    {
        if (!tapOnce)
        {
            GetComponent <Animator>().enabled = false;
            tapScreenControl.GetComponent <Collider2D>().enabled = false;
            StartCoroutine(Coroutines.AnimateScale(gameObject, Vector3.zero, 10, () => {
                ShowCoin();
                tapScreenControl.GetComponent <Collider2D>().enabled = true;
            }));
            foreach (GameObject star in stars)
            {
                StartCoroutine(Coroutines.AnimateScale(star, Vector3.zero, 10));
            }


            tapOnce = true;
        }
        else
        {
            AkSoundEngine.SetRTPCValue("Menu_Music", 0f, null, 500);
            AkSoundEngine.PostEvent("Stop_Menu_Music", gameObject);
            FindObjectOfType <SceneLoader>().LoadScene("StartScreen");
        }
    }
 public void Shrink()
 {
     Coroutines.TimedAction(1f, (float delta) =>
     {
         SetScaleMod(1f - delta);
     }, null);
 }
예제 #20
0
            public static void Prefix(UdpConnection __instance, byte sendOption, ref Il2CppSystem.Action ackCallback)
            {
                if (sendOption != 8 || AmongUsClient.Instance == null || AmongUsClient.Instance.connection == null || !AmongUsClient.Instance.connection.Equals(__instance))
                {
                    return;
                }

                if (!PluginSingleton <ReactorPlugin> .Instance.ModdedHandshake.Value)
                {
                    return;
                }

                ackCallback = (System.Action)(() =>
                {
                    if (__instance.State != ConnectionState.Connected)
                    {
                        PluginSingleton <ReactorPlugin> .Instance.Log.LogDebug("Hello was acked, waiting for modded handshake response");

                        Coroutines.Start(Coroutine());

                        __instance.add_Disconnected((Action <Il2CppSystem.Object, DisconnectedEventArgs>)((a, b) =>
                        {
                            Coroutines.Stop(Coroutine());
                        }));
                    }
                });
            }
예제 #21
0
        public virtual void SetItemsAsync <T>(int capacity, System.Action onComplete, System.Action <T, int> onItem = null) where T : IComponent
        {
            Coroutines.StopAll(this);

            if (capacity == this.Count() && capacity > 0)
            {
                Coroutines.Run(this.ForEachAsync <T>(() => {
                    this.ForEach <T>((item, idx) => {
                        if (item is WindowComponent)
                        {
                            (item as WindowComponent).Show();
                        }
                    });

                    if (onComplete != null)
                    {
                        onComplete.Invoke();
                    }
                }, onItem), this);

                return;
            }

            this.Clear();

            Coroutines.Run(this.SetItemsAsync_INTERNAL(capacity, onComplete, onItem), this);
        }
예제 #22
0
    private void Start()
    {
        rb         = GetComponent <Rigidbody2D>();
        hs         = GetComponent <HealthSystem>();
        dr         = GetComponent <DamageReceiver>();
        lava       = FindObjectOfType <Lava>();
        coroutines = Coroutines.GetInstance();
        sf         = FindObjectOfType <ScreenFader>();
        anim       = GetComponent <Animator>();
        pc         = GetComponent <PlayerController>();
        sr         = GetComponent <SpriteRenderer>();
        tr         = GetComponent <Transform>();

        SetRespawnPoint(tr.position);

        #region delegate_subscriptions
        //I am fully aware of the fact that had I used unityEvents, I could do this in the inspector:
        pc.OnStartedRunning  += (() => { sfx.TryStartPlayLooped("Run"); });
        pc.OnStoppedRunning  += (() => { sfx.TryStopPlayLooped("Run"); });
        pc.OnStartedClimbing += (() => { sfx.TryStartPlayLooped("ClimbLadder"); });
        pc.OnStoppedClimbing += (() => { sfx.TryStopPlayLooped("ClimbLadder"); });
        pc.OnJumped          += (() => { sfx.TryPlayOnce("Jump"); });
        pc.OnHitGround       += (() => { sfx.TryPlayOnce("GroundImpact"); });
        pc.OnClimbedOnce     += (() => { sfx.TryPlayOnce("GrabbedLadder"); });
        dr.OnTakenDamage     += (() => { sfx.TryPlayOnce("Damaged"); });
        OnDamagedByLava      += (() => { sfx.TryPlayOnce("TouchLava"); });

        hs.OnDeath     += Death;
        dr.OnDamagedBy += ProcessDamager;
        #endregion delegate_subscriptions
    }
예제 #23
0
        public static async Task AtOnce(Vector2i pos, string destination, int minDistance = 20)
        {
            if (LokiPoe.MyPosition.Distance(pos) <= minDistance)
            {
                return;
            }

            while (LokiPoe.MyPosition.Distance(pos) > minDistance)
            {
                if (LogInterval.Elapsed)
                {
                    await Coroutines.CloseBlockingWindows();

                    GlobalLog.Debug($"[MoveAtOnce] Moving to {destination} at {pos} (distance: {LokiPoe.MyPosition.Distance(pos)})");
                }

                if (!LokiPoe.IsInGame || LokiPoe.Me.IsDead || BotManager.IsStopping)
                {
                    return;
                }

                TowardsWalkable(pos, destination);
                await Wait.Sleep(50);
            }
            await Coroutines.FinishCurrentAction();
        }
예제 #24
0
    void PlayTutorial()
    {
        WaveInfo waveInfo = new WaveInfo
        {
            minNumberOfBoxes     = 1,
            maxNumberOfBoxes     = 2,
            minNumberOfDecals    = 1,
            maxNumberOfDecals    = 2,
            spawnAfterSeconds    = 0.0f,
            canSpawnGarbage      = false,
            canSpawnCrossedLabel = false
        };

        StartCoroutine(Coroutines.Chain(
                           Coroutines.Wait(2.0f),
                           tutorialCanvas.DisplayText("Hello!", 3.0f),
                           Coroutines.Wait(1.0f),
                           tutorialCanvas.DisplayText("Welcome to \"Rooster Express, Inc.\" We hope that you enjoy this job as much as we enjoy having you here!", 5.5f),
                           Coroutines.Wait(1.0f),
                           tutorialCanvas.DisplayText("Your job here will consist in picking up packages from that place over there and putting them in these conveyor belts...", 5.5f),
                           Coroutines.Wait(1.0f),
                           tutorialCanvas.DisplayText("But you have to make sure they go in the right conveyor, or some clients won't receive their packages in time.", 5.5f),
                           Coroutines.Wait(1.0f),
                           Coroutines.Join(
                               tutorialCanvas.DisplayText("Look, let's try it...", 2.0f),
                               Coroutines.Wrap(() => spawner.SpawnBoxes(waveInfo))),
                           Coroutines.Wait(2.5f),
                           Coroutines.Wrap(() => CreateTutorialBoxSpawnAndDeliver(waveInfo))
                           ));
    }
예제 #25
0
        public IEnumerator TestRepeatEverySeconds()
        {
            var c = 0;

            Coroutines.RepeatEverySeconds(1, () => ++ c, 3).Start();
            yield return(new WaitForSeconds(.5f));

            Assert.AreEqual(c, 1);
            yield return(new WaitForSeconds(1));

            Assert.AreEqual(c, 2);
            yield return(new WaitForSeconds(1));

            Assert.AreEqual(c, 3);
            yield return(new WaitForSeconds(1));

            Assert.AreEqual(c, 3);

            c = 0;
            var done = false;

            Coroutines.RepeatEverySeconds(1, () => ++ c).YieldWhile(() => !done).Start();
            yield return(new WaitForSeconds(.5f));

            Assert.AreEqual(c, 1);
            yield return(new WaitForSeconds(1));

            Assert.AreEqual(c, 2);
            done = true;
            yield return(new WaitForSeconds(1));

            Assert.AreEqual(c, 2);
        }
예제 #26
0
 private void CreateTutorialBoxSpawnAndDeliver(WaveInfo waveInfo)
 {
     StartCoroutine(Coroutines.Chain(
                        _CreateTutorialBoxSpawnAndDeliver(waveInfo),
                        Coroutines.Wrap(() =>
     {
         if (!gm.playerCompletedFirstTaskSuccessful)
         {
             gm.playerCompletedFirstTask = false;
             StartCoroutine(Coroutines.Chain(
                                Coroutines.Join(
                                    Coroutines.Wait(2.0f),
                                    tutorialCanvas.DisplayText("... Ok, let's try again.", 2.0f),
                                    Coroutines.Wrap(() => spawner.SpawnBoxes(waveInfo))),
                                Coroutines.Wait(3.0f),
                                Coroutines.Wrap(() => CreateTutorialBoxSpawnAndDeliver(waveInfo))
                                ));
             return;
         }
         else
         {
             StartCoroutine(Coroutines.Chain(
                                tutorialCanvas.DisplayText("Good job!", 2.0f),
                                Coroutines.Wrap(() => CreateTutorialDifferentDisplayGarbage())
                                ));
         }
     })));
 }
예제 #27
0
        public IEnumerator TestYieldWhile()
        {
            // ensure never executed on false
            var done = false;

            Coroutines.RepeatWhile(() => true, () => done = true)
            .YieldWhile(() => false).Start();
            Assert.IsFalse(done);
            yield return(null);

            yield return(null);

            Assert.IsFalse(done);

            // ensure stops once false
            var c = 0;

            Coroutines.RepeatWhile(() => true, () => ++ c)
            // ReSharper disable once AccessToModifiedClosure
            .YieldWhile(() => !done).Start();
            for (var i = c; i < 10; ++i)
            {
                Assert.AreEqual(i, c);
                yield return(null);
            }
            var finalC = c;

            done = true;
            yield return(null);

            Assert.AreEqual(finalC, c);
            yield return(null);

            Assert.AreEqual(finalC, c);
        }
예제 #28
0
        public static async Task <bool> Interact(NetworkObject obj, Func <bool> success, string desc, int timeout = 3000)
        {
            if (obj == null)
            {
                GlobalLog.Error("[Interact] Object for interaction is null.");
                return(false);
            }

            var name = obj.Name;

            GlobalLog.Debug($"[Interact] Now going to interact with \"{name}\".");

            await Coroutines.CloseBlockingWindows();

            await Coroutines.FinishCurrentAction();

            await Wait.LatencySleep();

            if (await Coroutines.InteractWith(obj))
            {
                if (!await Wait.For(success, desc, 100, timeout))
                {
                    return(false);
                }

                GlobalLog.Debug($"[Interact] \"{name}\" has been successfully interacted.");
                return(true);
            }
            GlobalLog.Error($"[Interact] Fail to interact with \"{name}\".");
            await Wait.SleepSafe(300, 500);

            return(false);
        }
예제 #29
0
        public IEnumerator TestRepeatForSeconds()
        { // how do you even test this properly when it depends on framerate?
            var c = 0;

            Coroutines.RepeatForSeconds(2, () => ++ c).Start();
            for (var i = c; i < 10; ++i)
            {
                Assert.AreEqual(i, c);
                yield return(null);
            }

            yield return(Coroutines.WaitForSeconds(1));

            for (var i = c; i < 10; ++i)
            {
                Assert.AreEqual(i, c);
                yield return(null);
            }

            yield return(new WaitForSeconds(1.1f));

            var lastC = c;

            yield return(new WaitForSeconds(1));

            Assert.AreEqual(lastC, c);
        }
예제 #30
0
        public async Task <bool> PerformKiting(IEnumerable <CachedNetworkObject> dangerousObjects, CachedNetworkObject nearestThreat, float dangerRadius, Stopwatch stopwatchToReset = null)
        {
            if (dangerousObjects.Any())
            {
                if (nearestThreat != null && nearestThreat.Distance <= dangerRadius)
                {
                    Log.InfoFormat("[DangerDodger] Initiating kiting.");
                    List <Vector2> positions    = dangerousObjects.Select(o => o.Position.ToVector2()).ToList();
                    Vector2        dangerCenter = GeometryHelper.getAveragePoint(positions);
                    Log.InfoFormat("[DangerDodger] NearestThreat.Name: [{0}], NearestThreat.Position: [{1}], DangerCenter: [{2}]", nearestThreat.Name, nearestThreat.Position, dangerCenter);
                    //The escape angle represents the shortest way out of the danger.
                    double   escapeAngle = GeometryHelper.getAngleBetweenPoints(dangerCenter, LokiPoe.Me.Position.ToVector2());
                    Vector2i newPosition = MoveHelper.CalcSafePosition(escapeAngle, DangerDodgerSettings.Instance.StepLength);

                    if (newPosition != LokiPoe.Me.Position)
                    {
                        //PlayerMover.MoveTowards(newPosition) Does not seem to work when the character is busy.
                        Log.InfoFormat("[DangerDodger] Kiting towards a safer position. CurrentPosition: [{0}], NewPosition: [{1}]", LokiPoe.Me.Position, newPosition);
                        if (!await Coroutines.MoveToLocation(newPosition, 5, 1000))
                        {
                            Log.ErrorFormat("[DangerDodger] Error kiting towards safe position. ");
                        }
                    }
                    return(true);
                }
            }
            else
            {
                if (stopwatchToReset != null)
                {//In some cases, we don't restart the stopwatch when the threat is still nearby. The bot could decide to go pick up some item in the middle of danger zone at any moment ;.;
                    stopwatchToReset.Restart();
                }
            }
            return(false);
        }