public async Task <bool> Run() { var area = World.CurrentArea; if (!area.IsMap && !area.IsOverworldArea) { return(false); } if (LokiPoe.InstanceInfo.Incursion.IncursionsRemaining != 0) { return(false); } var cache = CombatAreaCache.Current; if (cache.Storage["IsTempleCompleted"] != null) { return(false); } var alva = Incursion.CachedAlva; if (alva == null || alva.Unwalkable || alva.Ignored) { return(false); } var pos = alva.Position; if (pos.Distance > 20 || pos.PathDistance > 20) { if (!pos.TryCome()) { GlobalLog.Error($"[EnterTempleTask] Fail to move to {pos}. Alva is unwalkable."); alva.Unwalkable = true; } return(true); } var alvaObj = alva.Object; if (alvaObj == null) { GlobalLog.Error("[EnterTempleTask] Unexpected error. We are near cached Alva, but actual object is null."); alva.Ignored = true; return(true); } var portal = ActiveTemplePortal; if (portal == null) { var attempts = ++alva.InteractionAttempts; if (attempts > 7) { GlobalLog.Error("[EnterTempleTask] All attempts to interact with Alva have been spent."); alva.Ignored = true; return(true); } if (alvaObj.HasNpcFloatingIcon) { if (await PlayerAction.Interact(alvaObj)) { await Wait.Sleep(200); await Coroutines.CloseBlockingWindows(); } return(true); } if (await alvaObj.AsTownNpc().Converse("Enter Temple")) { await Coroutines.CloseBlockingWindows(); await Wait.For(() => ActiveTemplePortal != null, "Temple portals activation", 500, 10000); } return(true); } if (Settings.Instance.SkipTemple) { cache.Storage["IsTempleCompleted"] = true; return(true); } if (ErrorManager.GetErrorCount("EnterTemple") >= 5) { GlobalLog.Error("[EnterTempleTask] Failed to enter Temple portal 5 times."); alva.Ignored = true; return(true); } if (!await PlayerAction.TakePortal(portal)) { ErrorManager.ReportError("EnterTemple"); await Wait.SleepSafe(500); } return(true); }
public async Task <bool> Run() { var area = World.CurrentArea; if (!area.IsMap && !area.IsOverworldArea) { return(false); } if (CombatAreaCache.IsInIncursion) { return(false); } if (LokiPoe.InstanceInfo.Incursion.IncursionsRemaining == 0) { return(false); } var cache = CombatAreaCache.Current; if (cache.Storage["IsIncursionCompleted"] != null) { return(false); } var alva = cache.Storage["AlvaValai"] as CachedObject; if (alva == null || alva.Unwalkable || alva.Ignored) { return(false); } var pos = alva.Position; if (pos.IsFar || pos.IsFarByPath) { if (!pos.TryCome()) { GlobalLog.Error($"[EnterIncursionTask] Fail to move to {pos}. Alva is unwalkable."); alva.Unwalkable = true; } return(true); } var alvaObj = alva.Object; if (alvaObj == null) { GlobalLog.Error("[EnterIncursionTask] Unexpected error. We are near cached Alva, but actual object is null."); alva.Ignored = true; return(true); } var timePortal = TimePortal; if (timePortal == null) { GlobalLog.Error("[EnterIncursionTask] Unexpected error. There is no Time Portal near Alva."); cache.Storage["IsIncursionCompleted"] = true; return(true); } if (timePortal.Components.TransitionableComponent.Flag2 == 3) { GlobalLog.Warn("[EnterIncursionTask] Incursion in this area has been completed."); cache.Storage["IsIncursionCompleted"] = true; if (Settings.Instance.LeaveAfterIncursion) { FinishGridning(); } return(true); } if (!timePortal.IsTargetable) { var attempts = ++alva.InteractionAttempts; if (attempts > 5) { GlobalLog.Error("[EnterIncursionTask] All attempts to interact with Alva have been spent."); alva.Ignored = true; return(true); } if (alvaObj.HasNpcFloatingIcon) { if (await PlayerAction.Interact(alvaObj)) { await Wait.Sleep(200); await Coroutines.CloseBlockingWindows(); } return(true); } if (await alvaObj.AsTownNpc().Converse("Enter Incursion")) { await Coroutines.CloseBlockingWindows(); await Wait.For(() => timePortal.Fresh().IsTargetable, "Time Portal activation", 200, 5000); } return(true); } if (Settings.Instance.PortalBeforeIncursion && area.IsMap && !AnyPortalsNearby) { // Have to do this because portal spawned right near Time Portal has a high chance to overlap labels var distantPos = WorldPosition.FindPathablePositionAtDistance(30, 35, 5); if (distantPos != null) { await Move.AtOnce(distantPos, "away from Time Portal", 10); await PlayerAction.CreateTownPortal(); } else { await PlayerAction.CreateTownPortal(); } } if (ErrorManager.GetErrorCount("EnterIncursion") >= 5) { GlobalLog.Error("[EnterIncursionTask] Failed to enter Time Portal 5 times."); cache.Storage["IsIncursionCompleted"] = true; return(true); } if (await PlayerAction.TakeTransition(timePortal)) { GlobalLog.Warn("[EnterIncursionTask] IsInIncursion: true"); CombatAreaCache.IsInIncursion = true; SetRoomSettings(); } else { ErrorManager.ReportError("EnterIncursion"); await Wait.SleepSafe(500); } return(true); }