public static void UpdateHubInfo(bool forced = false) { List <TCHubJson.Summit> JSummit; DateTime endtime; using WebClient wc = new(); bool Connected = true; string JSummitString = string.Empty; try { JSummitString = wc.DownloadString(Program.TCHubJson.Summit); } catch (WebException e) { Connected = false; Program.Client.Logger.LogInformation(CustomLogEvents.TCHub, e, "Connection error. Either wrong API link, or the Hub is down."); } if (Connected) { JSummit = JsonConvert.DeserializeObject <List <TCHubJson.Summit> >(JSummitString); if (forced) { endtime = TCHubLastUpdated; } else { endtime = CustomMethod.EpochConverter(JSummit[0].End_Date * 1000); } if (endtime != TCHubLastUpdated || forced) { TCHubLastUpdated = endtime; Program.TCHubDictionary = JsonConvert.DeserializeObject <Dictionary <string, string> >(wc.DownloadString(Program.TCHubJson.Dictionary)); Program.JSummit = JSummit; Program.TCHub = JsonConvert.DeserializeObject <TCHubJson.TCHub>(wc.DownloadString(Program.TCHubJson.GameData)); for (int i = 0; i < JSummit[0].Events.Length; i++) { var ThisEvent = JSummit[0].Events[i]; EventLogoBitArr[i] = wc.DownloadData($"https://www.thecrew-hub.com/gen/assets/summits/{ThisEvent.Img_Path}"); } for (int i = 0; i < 4; i++) { for (int j = 0; j < JSummit[i].Rewards.Length; j++) { RewardsImageBitArr[i, j] = wc.DownloadData($"https://www.thecrew-hub.com/gen/assets/summits/{JSummit[i].Rewards[j].Img_Path}"); } } Program.Client.Logger.LogInformation(CustomLogEvents.TCHub, $"Info downloaded for {JSummit[0].Summit_ID} summit."); } } }
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) ); }