protected async void RefreshWorldState() { Task <WorldState> task; try { task = client.GetWorldStateAsync("pc/"); await task; } catch (Exception ex) { if (status != ConnectionStatus.Issue) { Log("System", "Having trouble retrieving world state. Will retry every minute."); Log("Exception", ex.Message); Utilities.DebugLog($"[CONNECTION] {ex.InnerException}"); } status = ConnectionStatus.Issue; return; } if (status == ConnectionStatus.Connecting) { Log("System", "Connected. Scanning for alerts matching your filter..."); } if (status == ConnectionStatus.Issue) { Log("System", "Reconnected."); } status = ConnectionStatus.Connected; world.Tick(task.Result); }
static async Task Main(string[] args) { void WriteCountedHeading(string heading, int shown, int total) { WriteHeading(heading + (shown == total ? string.Empty : $" ({shown} of {total} shown)")); } void WriteEvents <T, T2, T3>(IEnumerable <T> events, Func <T, bool> preFilter, Func <T, T2> transform, Func <T2, bool> postFilter, string heading, Func <T2, T3> orderBy, Func <T2, string> writer, Func <T2, bool> isCritical = null) { var filteredEvents = events.Where(preFilter).Select(transform); if (postFilter != null) { filteredEvents = filteredEvents.Where(postFilter); } if (!filteredEvents.Any()) { return; } WriteCountedHeading(heading, filteredEvents.Count(), events.Count()); foreach (var filteredEvent in filteredEvents.OrderBy(orderBy)) { if (isCritical != null) { Console.ForegroundColor = isCritical(filteredEvent) ? ConsoleColor.Red : ConsoleColor.Gray; } Console.WriteLine(writer(filteredEvent)); if (isCritical != null) { Console.ResetColor(); } } Console.WriteLine(); } var token = new CancellationTokenSource(); Console.CancelKeyPress += (s, e) => { token.Cancel(); }; var client = new WarframeClient(); WorldState worldState; try { while (!token.IsCancellationRequested) { try { worldState = await client.GetWorldStateAsync(Platform.PC).ConfigureAwait(false); } catch (Exception e) when(e is HttpRequestException || e is OperationCanceledException || e is TaskCanceledException) { continue; } Console.Clear(); WriteHeading($"Earth: {(worldState.EarthCycle.IsDay ? "Night" : "Day")} in {worldState.EarthCycle.TimeRemaining} | " + $"Plains: {(worldState.CetusCycle.IsDay ? "Night" : "Day")} in {worldState.CetusCycle.TimeRemaining} | " + $"Vallis: {(worldState.VallisCycle.IsWarm ? "Cold" : "Warm")} in {worldState.VallisCycle.TimeRemaining}"); if (worldState.VoidTrader != null) { WriteVoidTrader(new FiniteEvent <VoidTrader>(worldState.VoidTrader, worldState)); } if (worldState.Nightwave != null) { WriteNightwave(new FiniteEvent <Nightwave>(worldState.Nightwave, worldState)); } WriteEvents(worldState.Events, _ => true, e => new FiniteEvent <Event>(e, worldState), e => e.TimeToExpiry > TimeSpan.Zero, "EVENTS", e => e.TimeToExpiry, FormatEvent); WriteEvents(worldState.Alerts, IsUsefulAlert, a => new FiniteEvent <Alert>(a, worldState), a => a.TimeToExpiry > TimeSpan.Zero, "ALERTS", a => a.TimeToExpiry, FormatAlert, a => a.Event.Mission.IsNightmare || IsAnyItemCriticallyImportant(a.Event.Mission.Reward)); WriteEvents(worldState.Invasions.Where(i => !i.IsCompleted), IsInterestingInvasion, i => new { Invasion = i, OrderedCompletion = Math.Min(i.Completion, 100 - i.Completion), }, null, "INVASIONS", i => i.OrderedCompletion, i => FormatInvasion(i.Invasion), i => IsAnyItemCriticallyImportant(i.Invasion.AttackerReward) || IsAnyItemCriticallyImportant(i.Invasion.DefenderReward)); WriteEvents(worldState.Fissures, IsFarmableFissure, f => new FiniteEvent <Fissure>(f, worldState), null, "FISSURES", f => f.TimeToExpiry, FormatFissure); await Task.Delay(TimeSpan.FromMinutes(1), token.Token).ConfigureAwait(false); /* * var key = Console.ReadKey(true); * * if (key.Modifiers.HasFlag(ConsoleModifiers.Control) && key.Key == ConsoleKey.C) * { * token.Cancel(); * } */ } await Task.Yield(); } catch (Exception e) { Console.WriteLine(e); } }