Skip to content

Commit

Permalink
add SaveMapTime;utilize CurrentRun class a bit more
Browse files Browse the repository at this point in the history
  • Loading branch information
tslashd committed Dec 23, 2023
1 parent ef15fb6 commit 5e7edff
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 23 deletions.
3 changes: 3 additions & 0 deletions src/ST-Events/TriggerEndTouch.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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");
Expand Down
20 changes: 6 additions & 14 deletions src/ST-Events/TriggerStartTouch.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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<int> 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
}
Expand Down
31 changes: 22 additions & 9 deletions src/ST-Player/PlayerStats.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,12 @@ internal class CurrentRun
{
public Dictionary<int, PersonalBest.CheckpointObject> 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

Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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<int> 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
Expand Down

0 comments on commit 5e7edff

Please sign in to comment.