Ejemplo n.º 1
0
        public Context1()
        {
            configWindow = new Form1();

            var configMenuItem = new MenuItem("Open", ShowConfig);
            var aboutMenuItem  = new MenuItem("About", ShowAbout);
            var exitMenuItem   = new MenuItem("Exit", Exit);

            voice = new SpeechSynthesizer();
            voice.SelectVoiceByHints(VoiceGender.Female);

            notifyIcon = new NotifyIcon
            {
                Icon        = System.Drawing.Icon.ExtractAssociatedIcon(System.Reflection.Assembly.GetEntryAssembly().ManifestModule.Name),
                ContextMenu = new ContextMenu(new[] { configMenuItem, aboutMenuItem, exitMenuItem }),
                Visible     = true
            };

            notifyIcon.MouseDoubleClick += ShowConfig;

            client = new WarframeClient();

            world = new ParsedWorld();
            world.OnOperationStarted      += OnOperationStarted;
            world.OnOperationEnded        += OnOperationEnded;
            world.OnOperationsInitialized += OnOperationsInitialized;
            world.OnPopupMessage          += Popup;
            world.OnSpeakMessage          += Speak;
            world.OnLogMessage            += Log;

            OnLoadExtractors();
            configWindow.OnSaveExtractors += OnSaveExtractors;

            world.TitanExtractor.OnExtractorFinished      += OnTitanExtractorFinished;
            configWindow.titanExtractorBox.CheckedChanged += TitanExtractorCheckChanged;

            world.DistillingExtractor.OnExtractorFinished      += OnDistillingExtractorFinished;
            configWindow.distillingExtractorBox.CheckedChanged += DistillingExtractorCheckChanged;

            var secondTimer = new System.Timers.Timer();

            secondTimer.Elapsed += SecondTimer;
            secondTimer.Interval = 1000;
            secondTimer.Enabled  = true;

            var minuteTimer = new System.Timers.Timer();

            minuteTimer.Elapsed += MinuteTimer;
            minuteTimer.Interval = 60000;
            minuteTimer.Enabled  = true;

            Log("System", "Connecting...");
            RefreshWorldState();

            configWindow.Show();
        }
Ejemplo n.º 2
0
        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);
            }
        }