Esempio n. 1
0
        public static Image <Rgba32> BuildSummitImage(List <TCHubJson.Summit> JSummit, TCHubJson.Rank Events, TCHubJson.TceSummitSubs UserInfo)
        {
            int[,] WidthHeight = new int[, ] {
                { 0, 249 }, { 373, 249 }, { 0, 493 }, { 373, 493 }, { 747, 0 }, { 747, 249 }, { 0, 0 }, { 249, 0 }, { 498, 0 }
            };
            Font Basefont     = Program.Fonts.CreateFont("HurmeGeometricSans3W03-Blk", 18);
            Font SummitCaps15 = Program.Fonts.CreateFont("HurmeGeometricSans3W03-Blk", 15);
            Font SummitCaps12 = Program.Fonts.CreateFont("HurmeGeometricSans3W03-Blk", 12.5f);

            var AllignCenter = new TextOptions()
            {
                HorizontalAlignment = HorizontalAlignment.Center,
                VerticalAlignment   = VerticalAlignment.Top
            };
            var AllignTopLeft = new TextOptions()
            {
                HorizontalAlignment = HorizontalAlignment.Left,
                VerticalAlignment   = VerticalAlignment.Top
            };
            var AllignTopRight = new TextOptions()
            {
                HorizontalAlignment = HorizontalAlignment.Right,
                VerticalAlignment   = VerticalAlignment.Top
            };

            Image <Rgba32> BaseImage = new(1127, 765);

            Parallel.For(0, 9, (i, state) =>
            {
                var ThisEvent = JSummit[0].Events[i];
                var Activity  = Events.Activities.Where(w => w.Activity_ID.Equals(ThisEvent.ID.ToString())).ToArray();

                byte[] EventLogoBit             = TimerMethod.EventLogoBitArr[i];
                using Image <Rgba32> EventImage = Image.Load <Rgba32>(EventLogoBit);
                if (i == 5)
                {
                    EventImage.Mutate(ctx => ctx.
                                      Resize(380, 483)
                                      );
                }
                else if (i >= 0 && i <= 3)
                {
                    EventImage.Mutate(ctx => ctx.
                                      Resize(368, 239)
                                      );
                }
                if (Activity.Length > 0)
                {
                    using WebClient wc     = new();
                    string ThisEventNameID = string.Empty;
                    if (ThisEvent.Is_Mission)
                    {
                        ThisEventNameID = Program.TCHub.Missions.Where(w => w.ID == ThisEvent.ID).Select(s => s.Text_ID).FirstOrDefault();
                    }
                    else
                    {
                        ThisEventNameID = Program.TCHub.Skills.Where(w => w.ID == ThisEvent.ID).Select(s => s.Text_ID).FirstOrDefault();
                    }

                    string[] EventTitle = (CustomMethod.HubNameLookup(ThisEventNameID)).Replace("\"", string.Empty).Split(' ');
                    TCHubJson.SummitLeaderboard leaderboard = JsonConvert.DeserializeObject <TCHubJson.SummitLeaderboard>(wc.DownloadString($"https://api.thecrew-hub.com/v1/summit/{JSummit[0].ID}/leaderboard/{UserInfo.Platform}/{ThisEvent.ID}?page_size=1"));
                    StringBuilder sb = new();
                    for (int j = 0; j < EventTitle.Length; j++)
                    {
                        if (j == 3)
                        {
                            sb.AppendLine();
                        }
                        sb.Append(EventTitle[j] + " ");
                    }
                    string ActivityResult = $"Score: {Activity[0].Score}";
                    if (leaderboard.Score_Format == "time")
                    {
                        ActivityResult = $"Time: {CustomMethod.ScoreToTime(Activity[0].Score)}";
                    }
                    else if (sb.ToString().Contains("SPEEDTRAP"))
                    {
                        ActivityResult = $"Speed: {Activity[0].Score.ToString().Insert(3, ".")} km/h";
                    }
                    else if (sb.ToString().Contains("ESCAPE"))
                    {
                        ActivityResult = $"Distance: {Activity[0].Score}m";
                    }
                    using (Image <Rgba32> TitleBar = new(EventImage.Width, 40))
                        using (Image <Rgba32> ScoreBar = new(EventImage.Width, 40))
                        {
                            ScoreBar.Mutate(ctx => ctx.Fill(Color.Black));
                            TitleBar.Mutate(ctx => ctx.Fill(Color.Black));
                            EventImage.Mutate(ctx => ctx
                                              .DrawImage(ScoreBar, new Point(0, EventImage.Height - ScoreBar.Height), 0.7f)
                                              .DrawImage(TitleBar, new Point(0, 0), 0.7f)
                                              .DrawText(new DrawingOptions {
                                TextOptions = AllignTopLeft
                            }, sb.ToString(), SummitCaps15, Color.White, new PointF(5, 0))
                                              .DrawText(new DrawingOptions {
                                TextOptions = AllignTopLeft
                            }, $"Rank: {Activity[0].Rank + 1}", Basefont, Color.White, new PointF(5, EventImage.Height - 22))
                                              .DrawText(new DrawingOptions {
                                TextOptions = AllignTopRight
                            }, ActivityResult, Basefont, Color.White, new PointF(EventImage.Width - 5, EventImage.Height - 42))
                                              .DrawText(new DrawingOptions {
                                TextOptions = AllignTopRight
                            }, $"Points: {Activity[0].Points}", Basefont, Color.White, new PointF(EventImage.Width - 5, EventImage.Height - 22))
                                              );
                        }
                    BaseImage.Mutate(ctx => ctx
                                     .DrawImage(EventImage, new Point(WidthHeight[i, 0], WidthHeight[i, 1]), 1)
                                     );
                }
Esempio n. 2
0
        public async Task Summit(CommandContext ctx)
        {
            await ctx.TriggerTypingAsync();

            string PCJson = string.Empty, XBJson = string.Empty, PSJson = string.Empty, StadiaJson = string.Empty;
            string imageLoc = $"{Program.tmpLoc}{ctx.User.Id}-summit.png";

            byte[]   SummitLogo;
            DateTime endtime;

            int platforms = 4;

            using (WebClient wc = new())
            {
                List <TCHubJson.Summit> JSummit = Program.JSummit;
                PCJson = wc.DownloadString($"https://api.thecrew-hub.com/v1/summit/{JSummit[0].ID}/score/pc/profile/a92d844e-9c57-4b8c-a249-108ef42d4500");
                XBJson = wc.DownloadString($"https://api.thecrew-hub.com/v1/summit/{JSummit[0].ID}/score/x1/profile/a92d844e-9c57-4b8c-a249-108ef42d4500");
                PSJson = wc.DownloadString($"https://api.thecrew-hub.com/v1/summit/{JSummit[0].ID}/score/ps4/profile/a92d844e-9c57-4b8c-a249-108ef42d4500");
                try
                {
                    StadiaJson = wc.DownloadString($"https://api.thecrew-hub.com/v1/summit/{JSummit[0].ID}/score/stadia/profile/a92d844e-9c57-4b8c-a249-108ef42d4500");
                }
                catch (Exception)
                {
                    platforms = 3;
                }

                SummitLogo = wc.DownloadData($"https://www.thecrew-hub.com/gen/assets/summits/{JSummit[0].Cover_Small}");

                endtime = CustomMethod.EpochConverter(JSummit[0].End_Date * 1000);
            }
            TCHubJson.Rank[] Events = Array.Empty <TCHubJson.Rank>();
            if (platforms == 4)
            {
                Events = new TCHubJson.Rank[4] {
                    JsonConvert.DeserializeObject <TCHubJson.Rank>(PCJson), JsonConvert.DeserializeObject <TCHubJson.Rank>(PSJson), JsonConvert.DeserializeObject <TCHubJson.Rank>(XBJson), JsonConvert.DeserializeObject <TCHubJson.Rank>(StadiaJson)
                };
            }
            else
            {
                Events = new TCHubJson.Rank[3] {
                    JsonConvert.DeserializeObject <TCHubJson.Rank>(PCJson), JsonConvert.DeserializeObject <TCHubJson.Rank>(PSJson), JsonConvert.DeserializeObject <TCHubJson.Rank>(XBJson)
                };
            }
            string[,] pts = new string[platforms, 4];
            for (int i = 0; i < Events.Length; i++)
            {
                for (int j = 0; j < Events[i].Tier_entries.Length; j++)
                {
                    if (Events[i].Tier_entries[j].Points == 4294967295)
                    {
                        pts[i, j] = "-";
                    }
                    else
                    {
                        pts[i, j] = Events[i].Tier_entries[j].Points.ToString();
                    }
                }
            }
            using (Image <Rgba32> PCImg = Image.Load <Rgba32>("Assets/Summit/PC.jpeg"))
                using (Image <Rgba32> PSImg = Image.Load <Rgba32>("Assets/Summit/PS.jpg"))
                    using (Image <Rgba32> XBImg = Image.Load <Rgba32>("Assets/Summit/XB.png"))
                        using (Image <Rgba32> StadiaImg = Image.Load <Rgba32>("Assets/Summit/STADIA.png"))
                            using (Image <Rgba32> BaseImg = new(300 * platforms, 643))
                            {
                                Image <Rgba32>[] PlatformImg = new Image <Rgba32>[4] {
                                    PCImg, PSImg, XBImg, StadiaImg
                                };
                                Parallel.For(0, Events.Length, (i, state) =>
                                {
                                    using Image <Rgba32> TierImg   = Image.Load <Rgba32>("Assets/Summit/SummitBase.png");
                                    using Image <Rgba32> SummitImg = Image.Load <Rgba32>(SummitLogo);
                                    using Image <Rgba32> FooterImg = new(300, 30);
                                    SummitImg.Mutate(ctx => ctx.Crop(300, SummitImg.Height));
                                    Color TextColour     = Color.WhiteSmoke;
                                    Point SummitLocation = new(0 + (300 * i), 0);
                                    Font Basefont        = Program.Fonts.CreateFont("HurmeGeometricSans3W03-Blk", 30);
                                    Font FooterFont      = Program.Fonts.CreateFont("HurmeGeometricSans3W03-Blk", 15);
                                    FooterImg.Mutate(ctx => ctx
                                                     .Fill(Color.Black)
                                                     .DrawText($"TOTAL PARTICIPANTS: {Events[i].Player_Count}", FooterFont, TextColour, new PointF(10, 10))
                                                     );
                                    BaseImg.Mutate(ctx => ctx
                                                   .DrawImage(SummitImg, SummitLocation, 1)
                                                   .DrawImage(TierImg, SummitLocation, 1)
                                                   .DrawText(pts[i, 3], Basefont, TextColour, new PointF(80 + (300 * i), 365))
                                                   .DrawText(pts[i, 2], Basefont, TextColour, new PointF(80 + (300 * i), 435))
                                                   .DrawText(pts[i, 1], Basefont, TextColour, new PointF(80 + (300 * i), 505))
                                                   .DrawText(pts[i, 0], Basefont, TextColour, new PointF(80 + (300 * i), 575))
                                                   .DrawImage(FooterImg, new Point(0 + (300 * i), 613), 1)
                                                   .DrawImage(PlatformImg[i], new Point(0 + (300 * i), 0), 1)
                                                   );
                                });