From b2a1221d68fd79544e7182dc506b5d19657d78ea Mon Sep 17 00:00:00 2001 From: 1zc Date: Sun, 10 Mar 2024 20:51:38 +1100 Subject: [PATCH] Load bonus WRs in Map --- src/ST-Map/Map.cs | 65 +++++++++++++++++++++++++++++++++++++++++------ 1 file changed, 57 insertions(+), 8 deletions(-) diff --git a/src/ST-Map/Map.cs b/src/ST-Map/Map.cs index 947f9b4..acfd6b3 100644 --- a/src/ST-Map/Map.cs +++ b/src/ST-Map/Map.cs @@ -27,7 +27,7 @@ internal class Map /// /// Bonus World Record - Refer to as BonusWR[bonus#][style] /// - public Dictionary[] BonusWR { get; set; } = { new Dictionary() }; + public Dictionary[] BonusWR { get; set; } = new Dictionary[32]; public List ConnectedMapTimes { get; set; } = new List(); public List ReplayBots { get; set; } = new List { new ReplayPlayer() }; @@ -54,7 +54,15 @@ internal Map(string Name, TimerDatabase DB) { // Set map name this.Name = Name; + + // Initialize WR variables this.WR[0] = new PersonalBest(); // To-do: Implement styles + for (int i = 0; i < 32; i++) + { + BonusWR[i] = new Dictionary(); + BonusWR[i][0] = new PersonalBest(); // To-do: Implement styles + } + // Gathering zones from the map IEnumerable triggers = Utilities.FindAllEntitiesByDesignerName("trigger_multiple"); // Gathering info_teleport_destinations from the map @@ -266,14 +274,14 @@ internal void GetMapRecordAndTotals(TimerDatabase DB, int style = 0 ) // To-do: { // Get map world records Task reader = DB.Query($@" - SELECT MapTimes.*, Player.name + SELECT MapTimes.*, MIN(MapTimes.run_time) AS minimum, Player.name FROM MapTimes JOIN Player ON MapTimes.player_id = Player.id WHERE MapTimes.map_id = {this.ID} AND MapTimes.style = {style} + GROUP BY MapTimes.type ORDER BY MapTimes.run_time ASC; "); MySqlDataReader mapWrData = reader.Result; - int totalRows = 0; if (mapWrData.HasRows) { @@ -282,7 +290,22 @@ FROM MapTimes this.ConnectedMapTimes.Clear(); while (mapWrData.Read()) { - if (totalRows == 0) // We are sorting by `run_time ASC` so the first row is always the fastest run for the map and style combo :) + if (mapWrData.GetInt32("type") > 0) + { + this.BonusWR[mapWrData.GetInt32("type")][style].ID = mapWrData.GetInt32("id"); // WR ID for the Map and Style combo + this.BonusWR[mapWrData.GetInt32("type")][style].Ticks = mapWrData.GetInt32("run_time"); // Fastest run time (WR) for the Map and Style combo + this.BonusWR[mapWrData.GetInt32("type")][style].Type = mapWrData.GetInt32("type"); // Bonus type (0 = map, 1+ = bonus index) + this.BonusWR[mapWrData.GetInt32("type")][style].StartVelX = mapWrData.GetFloat("start_vel_x"); // Fastest run start velocity X for the Map and Style combo + this.BonusWR[mapWrData.GetInt32("type")][style].StartVelY = mapWrData.GetFloat("start_vel_y"); // Fastest run start velocity Y for the Map and Style combo + this.BonusWR[mapWrData.GetInt32("type")][style].StartVelZ = mapWrData.GetFloat("start_vel_z"); // Fastest run start velocity Z for the Map and Style combo + this.BonusWR[mapWrData.GetInt32("type")][style].EndVelX = mapWrData.GetFloat("end_vel_x"); // Fastest run end velocity X for the Map and Style combo + this.BonusWR[mapWrData.GetInt32("type")][style].EndVelY = mapWrData.GetFloat("end_vel_y"); // Fastest run end velocity Y for the Map and Style combo + this.BonusWR[mapWrData.GetInt32("type")][style].EndVelZ = mapWrData.GetFloat("end_vel_z"); // Fastest run end velocity Z for the Map and Style combo + this.BonusWR[mapWrData.GetInt32("type")][style].RunDate = mapWrData.GetInt32("run_date"); // Fastest run date for the Map and Style combo + this.BonusWR[mapWrData.GetInt32("type")][style].Name = mapWrData.GetString("name"); // Fastest run player name for the Map and Style combo + } + + else { this.WR[style].ID = mapWrData.GetInt32("id"); // WR ID for the Map and Style combo this.WR[style].Ticks = mapWrData.GetInt32("run_time"); // Fastest run time (WR) for the Map and Style combo @@ -295,16 +318,42 @@ FROM MapTimes this.WR[style].EndVelZ = mapWrData.GetFloat("end_vel_z"); // Fastest run end velocity Z for the Map and Style combo this.WR[style].RunDate = mapWrData.GetInt32("run_date"); // Fastest run date for the Map and Style combo this.WR[style].Name = mapWrData.GetString("name"); // Fastest run player name for the Map and Style combo + + this.ConnectedMapTimes.Add(mapWrData.GetInt32("id")); } - this.ConnectedMapTimes.Add(mapWrData.GetInt32("id")); - totalRows++; } } mapWrData.Close(); - this.TotalCompletions = totalRows; // Total completions for the map and style - this should maybe be added to PersonalBest class + + // Count completions + Task completionStats = DB.Query($@" + SELECT MapTimes.type, COUNT(*) as count + FROM MapTimes + WHERE MapTimes.map_id = {this.ID} + GROUP BY type; + "); + MySqlDataReader completionStatsResult = completionStats.Result; + + if (completionStatsResult.HasRows) + { + while (completionStatsResult.Read()) + { + if (completionStatsResult.GetInt32("type") > 0) + { + // To-do: bonus completion counts + } + + else + { + // Total completions for the map and style - this should maybe be added to PersonalBest class + this.TotalCompletions = completionStatsResult.GetInt32("count"); + } + } + } + completionStatsResult.Close(); // Get map world record checkpoints - if (totalRows != 0) + if (this.TotalCompletions != 0) { Task cpReader = DB.Query($"SELECT * FROM `Checkpoints` WHERE `maptime_id` = {this.WR[style].ID};"); MySqlDataReader cpWrData = cpReader.Result;