From 5e7edff241ad1df3ae6a3b2acc459da5f1df7646 Mon Sep 17 00:00:00 2001 From: T <74899888+tslashd@users.noreply.github.com> Date: Sat, 23 Dec 2023 11:54:37 +0200 Subject: [PATCH] add SaveMapTime;utilize CurrentRun class a bit more --- src/ST-Events/TriggerEndTouch.cs | 3 +++ src/ST-Events/TriggerStartTouch.cs | 20 ++++++------------- src/ST-Player/PlayerStats.cs | 31 +++++++++++++++++++++--------- 3 files changed, 31 insertions(+), 23 deletions(-) diff --git a/src/ST-Events/TriggerEndTouch.cs b/src/ST-Events/TriggerEndTouch.cs index ad993b8..4bcf6a9 100644 --- a/src/ST-Events/TriggerEndTouch.cs +++ b/src/ST-Events/TriggerEndTouch.cs @@ -60,6 +60,9 @@ internal HookResult OnTriggerEndTouch(DynamicHook handler) // Prespeed display player.Controller.PrintToCenter($"Prespeed: {velocity.ToString("0")} u/s"); + player.Stats.ThisRun.StartVelX = velocity_x; // Start pre speed for the run + player.Stats.ThisRun.StartVelY = velocity_y; // Start pre speed for the run + player.Stats.ThisRun.StartVelZ = velocity_z; // Start pre speed for the run #if DEBUG player.Controller.PrintToChat($"CS2 Surf DEBUG >> CBaseTrigger_{ChatColors.LightRed}EndTouchFunc{ChatColors.Default} -> {ChatColors.Green}Map Start Zone"); diff --git a/src/ST-Events/TriggerStartTouch.cs b/src/ST-Events/TriggerStartTouch.cs index 947026d..2fd2654 100644 --- a/src/ST-Events/TriggerStartTouch.cs +++ b/src/ST-Events/TriggerStartTouch.cs @@ -100,21 +100,13 @@ at System.Delegate.DynamicInvokeImpl(Object[] args) $"start_vel_z=VALUES(start_vel_z), end_vel_x=VALUES(end_vel_x), end_vel_y=VALUES(end_vel_y), end_vel_z=VALUES(end_vel_z), run_date=VALUES(run_date);"); #endif + // Populate speed values + player.Stats.ThisRun.EndVelX = velocity_x; // End pre speed for the run + player.Stats.ThisRun.EndVelY = velocity_y; // End pre speed for the run + player.Stats.ThisRun.EndVelZ = velocity_z; // End pre speed for the run // Add entry in DB for the run - // To-do: add `type` - // To-do: get the `start_vel` values for the run from CP implementation in other repository implementation of checkpoints and their speeds - Task updatePlayerRunTask = DB.Write($"INSERT INTO `MapTimes` " + - $"(`player_id`, `map_id`, `style`, `type`, `stage`, `run_time`, `start_vel_x`, `start_vel_y`, `start_vel_z`, `end_vel_x`, `end_vel_y`, `end_vel_z`, `run_date`) " + - $"VALUES ({player.Profile.ID}, {CurrentMap.ID}, 0, 0, 0, {player.Stats.PB[0].RunTime}, " + - $"123.000, 456.000, 789.000, {velocity_x}, {velocity_y}, {velocity_z}, {(int)DateTimeOffset.UtcNow.ToUnixTimeSeconds()}) " + // To-do: get the `start_vel` values for the run from CP implementation - $"ON DUPLICATE KEY UPDATE run_time=VALUES(run_time), start_vel_x=VALUES(start_vel_x), start_vel_y=VALUES(start_vel_y), " + - $"start_vel_z=VALUES(start_vel_z), end_vel_x=VALUES(end_vel_x), end_vel_y=VALUES(end_vel_y), end_vel_z=VALUES(end_vel_z), run_date=VALUES(run_date);"); - if (updatePlayerRunTask.Result <= 0) - throw new Exception($"CS2 Surf ERROR >> OnTriggerStartTouch (Map end zone) -> Failed to insert/update player run in database. Player: {player.Profile.Name} ({player.Profile.SteamID})"); - else - player.Stats.LoadMapTimesData(player.Profile.ID, CurrentMap.ID, DB); // Load the MapTime PB data again (will refresh the MapTime ID for the Checkpoints query) - updatePlayerRunTask.Dispose(); - + player.Stats.PB[0].SaveMapTime(player, DB, CurrentMap.ID); // Save the MapTime PB data + player.Stats.LoadMapTimesData(player.Profile.ID, CurrentMap.ID, DB); // Load the MapTime PB data again (will refresh the MapTime ID for the Checkpoints query) player.Stats.PB[0].SaveCurrentRunCheckpoints(player, DB); // Save the Checkpoints PB data player.Stats.PB[0].LoadCheckpointsForRun(player.Stats.PB[0].ID, DB); // Load the Checkpoints PB data again } diff --git a/src/ST-Player/PlayerStats.cs b/src/ST-Player/PlayerStats.cs index 493f027..f367c64 100644 --- a/src/ST-Player/PlayerStats.cs +++ b/src/ST-Player/PlayerStats.cs @@ -6,12 +6,12 @@ internal class CurrentRun { public Dictionary Checkpoint { get; set; } // Current RUN checkpoints tracker public int RunTime { get; set; } // To-do: will be the last (any) zone end touch time - public float StartVelX { get; set; } - public float StartVelY { get; set; } - public float StartVelZ { get; set; } - public float EndVelX { get; set; } - public float EndVelY { get; set; } - public float EndVelZ { get; set; } + public float StartVelX { get; set; } // This will store MAP START VELOCITY X + public float StartVelY { get; set; } // This will store MAP START VELOCITY Y + public float StartVelZ { get; set; } // This will store MAP START VELOCITY Z + public float EndVelX { get; set; } // This will store MAP END VELOCITY X + public float EndVelY { get; set; } // This will store MAP END VELOCITY Y + public float EndVelZ { get; set; } // This will store MAP END VELOCITY Z public int RunDate { get; set; } // Add other properties as needed @@ -59,9 +59,6 @@ internal class PersonalBest public float EndVelY { get; set; } public float EndVelZ { get; set; } public int RunDate { get; set; } - public float currentRunStartVelX { get; set; } - public float currentRunStartVelY { get; set; } - public float currentRunStartVelZ { get; set; } // Add other properties as needed internal class CheckpointObject @@ -238,6 +235,22 @@ public void SaveCurrentRunCheckpoints(Player player, TimerDatabase DB) } } } + + public void SaveMapTime(Player player, TimerDatabase DB, int mapId) + { + // Add entry in DB for the run + // To-do: add `type` + // To-do: get the `start_vel` values for the run from CP implementation in other repository implementation of checkpoints and their speeds + Task updatePlayerRunTask = DB.Write($"INSERT INTO `MapTimes` " + + $"(`player_id`, `map_id`, `style`, `type`, `stage`, `run_time`, `start_vel_x`, `start_vel_y`, `start_vel_z`, `end_vel_x`, `end_vel_y`, `end_vel_z`, `run_date`) " + + $"VALUES ({player.Profile.ID}, {mapId}, 0, 0, 0, {player.Stats.PB[0].RunTime}, " + + $"{player.Stats.ThisRun.StartVelX}, {player.Stats.ThisRun.StartVelY}, {player.Stats.ThisRun.StartVelZ}, {player.Stats.ThisRun.EndVelX}, {player.Stats.ThisRun.EndVelY}, {player.Stats.ThisRun.EndVelZ}, {(int)DateTimeOffset.UtcNow.ToUnixTimeSeconds()}) " + // To-do: get the `start_vel` values for the run from CP implementation + $"ON DUPLICATE KEY UPDATE run_time=VALUES(run_time), start_vel_x=VALUES(start_vel_x), start_vel_y=VALUES(start_vel_y), " + + $"start_vel_z=VALUES(start_vel_z), end_vel_x=VALUES(end_vel_x), end_vel_y=VALUES(end_vel_y), end_vel_z=VALUES(end_vel_z), run_date=VALUES(run_date);"); + if (updatePlayerRunTask.Result <= 0) + throw new Exception($"CS2 Surf ERROR >> internal class PersonalBest -> SaveMapTime -> Failed to insert/update player run in database. Player: {player.Profile.Name} ({player.Profile.SteamID})"); + updatePlayerRunTask.Dispose(); + } } internal class PlayerStats