Exemplo n.º 1
0
        public override async Task <string> Run(string parameters, CancellationToken cancellationToken)
        {
            if (string.IsNullOrWhiteSpace(Program.Saliens.Token))
            {
                return("{{warn}}No token has been set.");
            }

            if (Program.Saliens.PlanetDetails == null)
            {
                return("No planet information available yet.");
            }

            var planet = Program.Saliens.JoinedPlanet;

            if (planet == null)
            {
                return("No planet has been joined.");
            }

            if (planet.Zones == null)
            {
                planet = await SaliensApi.GetPlanet(parameters);

                var index = Program.Saliens.PlanetDetails.FindIndex(p => p.Id == parameters);
                Program.Saliens.PlanetDetails[index] = planet;
            }

            return(planet.ToConsoleBlock());
        }
        protected override string FormatState(PlayerInfoResponse playerInfo, DiscordPresence presence)
        {
            bool hasActivePlanet   = !string.IsNullOrWhiteSpace(playerInfo.ActivePlanet);
            bool hasActiveZone     = !string.IsNullOrWhiteSpace(playerInfo.ActiveZonePosition);
            bool hasActiveBossZone = !string.IsNullOrWhiteSpace(playerInfo.ActiveBossGame);

            var state = "Inactive";

            if (hasActivePlanet && (hasActiveZone || hasActiveBossZone))
            {
                state = $"Planet {playerInfo.ActivePlanet} - ";
                if (hasActiveBossZone)
                {
                    state += $"Boss Zone";
                }
                else if (hasActiveZone)
                {
                    state += $"Zone {playerInfo.ActiveZonePosition}";
                }
                var planet = SaliensApi.GetPlanet(playerInfo.ActivePlanet);
                if (hasActiveZone && int.TryParse(playerInfo.ActiveZonePosition, out int zonePos))
                {
                    var zone = planet.Zones[zonePos];
                    if (zone != null)
                    {
                        state += $" ({zone.RealDifficulty.ToString().Substring(0, 1)})";
                    }
                }
            }
            else if (hasActivePlanet && !hasActiveZone)
            {
                state = $"Planet {playerInfo.ActivePlanet}";
            }
            return(state);
        }
Exemplo n.º 3
0
        public override async Task <string> Run(string parameters, CancellationToken cancellationToken)
        {
            var split = parameters.Split(' ');

            if (split.Length != 2)
            {
                return("{err}Invalid amount of parameters.");
            }

            if (Program.Saliens.PlanetDetails == null)
            {
                return("No planet information available yet.");
            }

            var planet = Program.Saliens.PlanetDetails.FirstOrDefault(p => p.Id == split[0]);

            if (planet == null)
            {
                return("{err}Unknown planet id.");
            }

            if (!int.TryParse(split[1], out int zonePos))
            {
                return("{err}Invalid zone position.");
            }

            if (planet.Zones == null || planet.Zones.Count == 0)
            {
                var index = Program.Saliens.PlanetDetails.FindIndex(p => p.Id == planet.Id);
                planet = await SaliensApi.GetPlanet(planet.Id);

                Program.Saliens.PlanetDetails[index] = planet;
            }

            var zone = planet.Zones.FirstOrDefault(z => z.ZonePosition == zonePos);

            if (zone == null)
            {
                return("{err}Unknown zone position.");
            }

            return(zone.ToConsoleBlock());
        }
Exemplo n.º 4
0
        public override async Task <string> Run(string parameters, CancellationToken cancellationToken)
        {
            if (Program.Saliens.PlanetDetails == null)
            {
                return("No planet information available yet.");
            }

            var planet = Program.Saliens.PlanetDetails.FirstOrDefault(p => p.Id == parameters);

            if (planet == null)
            {
                return("{err}Unknown planet id.");
            }

            if (planet.Zones == null || planet.Zones.Count == 0)
            {
                // Zones not available yet, request them manually
                var index = Program.Saliens.PlanetDetails.FindIndex(p => p.Id == planet.Id);
                planet = await SaliensApi.GetPlanet(planet.Id);

                Program.Saliens.PlanetDetails[index] = planet;
            }

            var active   = planet.Zones.Where(z => !z.Captured);
            var captured = planet.Zones.Where(z => z.Captured);

            return($"Zones on {{planet}}planet {planet.Id} ({planet.State.Name}){{reset}}{Environment.NewLine}" +
                   $"Captured zones:{Environment.NewLine}" +
                   $"{string.Join(Environment.NewLine, captured.Select(z => z.ToConsoleLine()))}{Environment.NewLine}{Environment.NewLine}" +

                   $"Active zones:{Environment.NewLine}" +
                   $"{string.Join(Environment.NewLine, active.Select(z => z.ToConsoleLine()))}{Environment.NewLine}{Environment.NewLine}" +

                   $"To see more information about a zone, use the command: {{command}}zone {{param}}<planet_id> <zone_pos>{{reset}}{Environment.NewLine}" +
                   $"where {{param}}<planet_id>{{reset}} is replaced with the planet id,{Environment.NewLine}" +
                   $"and {{param}}<zone_pos>{{reset}} is replaced with the zone position");
        }
Exemplo n.º 5
0
        public override async Task <string> Run(string parameters, CancellationToken cancellationToken)
        {
            if (Program.Saliens.PlanetDetails == null)
            {
                return("No planet information available yet.");
            }

            var planet = Program.Saliens.PlanetDetails.FirstOrDefault(p => p.Id == parameters);

            if (planet == null)
            {
                return("{err}Unknown planet id.");
            }

            if (planet.Zones == null)
            {
                planet = await SaliensApi.GetPlanet(parameters);

                var index = Program.Saliens.PlanetDetails.FindIndex(p => p.Id == parameters);
                Program.Saliens.PlanetDetails[index] = planet;
            }

            return(planet.ToConsoleBlock());
        }
Exemplo n.º 6
0
        public override async Task <string> Run(string parameters, CancellationToken cancellationToken)
        {
            if (!string.IsNullOrWhiteSpace(parameters) && parameters != "all" && parameters != "live")
            {
                return("{err}Invalid parameter.");
            }

            if (Program.Saliens.PlanetDetails == null)
            {
                return("No planet information available yet.");
            }

            var planetDetails = Program.Saliens.PlanetDetails.OrderBy(p => p.State.Priority);

            var active = planetDetails.Where(p => p.State.Running);
            var future = planetDetails.Where(p => !p.State.Active && !p.State.Captured);

            if (parameters == "all" || parameters == "live")
            {
                var captured = planetDetails.Where(p => p.State.Captured);
                this.WriteConsole("Captured planets:");
                await PrintPlanets(captured);

                this.WriteConsole("");
                this.WriteConsole("Upcoming planets:");
                await PrintPlanets(future);

                this.WriteConsole("");
            }
            this.WriteConsole("Active planets:");
            await PrintPlanets(active);

            this.WriteConsole("");
            if (string.IsNullOrWhiteSpace(parameters))
            {
                this.WriteConsole("Upcoming planets:");
                await PrintPlanets(future.Take(1));

                this.WriteConsole("");
            }

            return($"To get a list of all planets, use the command: {{command}}planets {{param}}all{{reset}}{Environment.NewLine}" +
                   $"To fully refresh the list of planets, use the command: {{command}}planets {{param}}live{{reset}}{Environment.NewLine}{Environment.NewLine}" +

                   $"To see more information about a planet, use the command: {{command}}planet {{param}}<id>{{reset}}{Environment.NewLine}" +
                   $"where {{param}}<id>{{reset}} is replaced with the planet id.");

            async Task PrintPlanets(IEnumerable <Planet> planets)
            {
                var tasks = planets.Select(p => parameters == "live" || p.Zones == null ? SaliensApi.GetPlanet(p.Id) : Task.FromResult(p));

                foreach (var task in tasks)
                {
                    var planet = await task;
                    var i      = Program.Saliens.PlanetDetails.FindIndex(p => p.Id == planet.Id);
                    Program.Saliens.PlanetDetails[i] = planet;
                    this.WriteConsole(planet.ToConsoleLine());
                }
            }
        }