예제 #1
0
        private RaceFuel GetFuelUsage(RaceFuel data)
        {
            data.fuelPerMinute = data.fuelUsageL * 1000 / data.lapTimeMs * 60;

            data.fuel     = data.raceLaps * data.fuelUsageL;
            data.fuelSave = data.fuel + (data.reserveLaps * data.fuelUsageL);

            return(data);
        }
예제 #2
0
        public async Task FuelLaps(int race_laps, string lap_time, string fuel_usage, int reserve_laps = 3)
        {
            RaceFuel data = new RaceFuel
            {
                raceLaps    = race_laps,
                lapTimeMs   = (int)ParseLaptime(lap_time).TotalMilliseconds,
                fuelUsageL  = double.Parse(fuel_usage, CultureInfo.InvariantCulture),
                reserveLaps = reserve_laps
            };


            /* calculating race time here, as called function is generic and requires this value */

            data.raceTimeS = data.raceLaps * data.lapTimeMs / 1000;


            data = GetFuelUsage(data);
            await Context.Channel.SendMessageAsync(embed : data.toEmbed(Context.Client.CurrentUser, Context.User));
        }
예제 #3
0
            /// <summary>
            /// Create an embed which visualised this struct
            /// </summary>
            /// <param name="bot">optional for Author header</param>
            /// <param name="user">optional for Footer text</param>
            /// <returns></returns>
            public Embed toEmbed(SocketSelfUser bot = null, SocketUser user = null)
            {
                /* this cannot be used in anonymous expressions */
                RaceFuel data = this;


                var builder = new EmbedBuilder()
                {
                    Color = Color.Blue,
                    Title = "Fuel Calculation",
                };



                builder.AddField(x =>
                {
                    x.Name     = "Racetime";
                    x.Value    = TimeSpan.FromSeconds(data.raceTimeS).ToString(@"hh\:mm");
                    x.IsInline = true;
                });

                builder.AddField(x =>
                {
                    x.Name     = "Laptime";
                    x.Value    = TimeSpan.FromMilliseconds(data.lapTimeMs).ToString(@"mm\:ss\.fff");
                    x.IsInline = true;
                });


                builder.AddField(x =>
                {
                    x.Name     = "Fuel per Lap";
                    x.Value    = data.fuelUsageL;
                    x.IsInline = true;
                });

                builder.AddField(x =>
                {
                    x.Name     = "Racelaps";
                    x.Value    = data.raceLaps;
                    x.IsInline = true;
                });

                builder.AddField(x =>
                {
                    x.Name     = "Fuel per Minute (est.)";
                    x.Value    = data.fuelPerMinute.ToString("0.00");
                    x.IsInline = true;
                });

                builder.AddField(x =>
                {
                    x.Name     = "Minimum Fuel Required";
                    x.Value    = data.fuel.ToString("0.00") + "l";
                    x.IsInline = false;
                });


                double reserve_laps_perc = data.reserveLaps / (double)data.raceLaps * 100;

                builder.AddField(x =>
                {
                    x.Name     = $"Safe Fuel (+{data.reserveLaps} laps / +{(int)reserve_laps_perc}%)";
                    x.Value    = data.fuelSave.ToString("0.00") + "l";
                    x.IsInline = false;
                });



                if (bot != null)
                {
                    builder.WithAuthor(a =>
                    {
                        a.Name    = bot.Username;
                        a.IconUrl = $"https://cdn.discordapp.com/avatars/{bot.Id}/{bot.AvatarId}.png";
                    });
                }


                if (user is SocketGuildUser gUser)
                {
                    string uName = (gUser.Nickname != null) ? gUser.Nickname : gUser.Username;

                    builder.WithFooter(f =>
                    {
                        f.Text    = $"Calculation requested by {uName}";
                        f.IconUrl = $"https://cdn.discordapp.com/avatars/{gUser.Id}/{gUser.AvatarId}.png";
                    });
                }

                return(builder.Build());
            }