Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/ST-Events/Players.cs
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ public HookResult OnPlayerConnect(EventPlayerConnectFull @event, GameEventInfo i
// To-do: hardcoded Style value
// Load MapTimes for the player's PB and their Checkpoints
playerList[player.UserId ?? 0].Stats.LoadMapTimesData(playerList[player.UserId ?? 0], DB); // Will reload PB and Checkpoints for the player for all styles
playerList[player.UserId ?? 0].Stats.PB[0].Checkpoint[0].LoadCheckpointsForRun(DB); // To-do: This really should go inside `LoadMapTimesData` imo cuz here we hardcoding load for Style 0 - regardless of index for `Checkpoint[X]` it will load all checkpoints
playerList[player.UserId ?? 0].Stats.LoadCheckpointsData(DB); // To-do: This really should go inside `LoadMapTimesData` imo cuz here we hardcoding load for Style 0

// Print join messages
Server.PrintToChatAll($"{PluginPrefix} {ChatColors.Green}{player.PlayerName}{ChatColors.Default} has connected from {ChatColors.Lime}{playerList[player.UserId ?? 0].Profile.Country}{ChatColors.Default}.");
Expand Down
20 changes: 10 additions & 10 deletions src/ST-Events/TriggerEndTouch.cs
Original file line number Diff line number Diff line change
Expand Up @@ -87,11 +87,11 @@ internal HookResult OnTriggerEndTouch(DynamicHook handler)
#endif

// Update the values
currentCheckpoint.CpEndVelX = velocity_x;
currentCheckpoint.CpEndVelY = velocity_y;
currentCheckpoint.CpEndVelZ = velocity_z;
currentCheckpoint.CpEndTouch = player.Timer.Ticks; // To-do: what type of value we store in DB ?
currentCheckpoint.CpAttempts += 1;
currentCheckpoint.EndVelX = velocity_x;
currentCheckpoint.EndVelY = velocity_y;
currentCheckpoint.EndVelZ = velocity_z;
currentCheckpoint.EndTouch = player.Timer.Ticks; // To-do: what type of value we store in DB ?
currentCheckpoint.Attempts += 1;

// Show Prespeed for stages - will be enabled/disabled by the user?
player.Controller.PrintToCenter($"Stage {Regex.Match(trigger.Entity.Name, "[0-9][0-9]?").Value} - Prespeed: {velocity.ToString("0")} u/s");
Expand Down Expand Up @@ -121,11 +121,11 @@ internal HookResult OnTriggerEndTouch(DynamicHook handler)
#endif

// Update the values
currentCheckpoint.CpEndVelX = velocity_x;
currentCheckpoint.CpEndVelY = velocity_y;
currentCheckpoint.CpEndVelZ = velocity_z;
currentCheckpoint.CpEndTouch = player.Timer.Ticks; // To-do: what type of value we store in DB ?
currentCheckpoint.CpAttempts += 1;
currentCheckpoint.EndVelX = velocity_x;
currentCheckpoint.EndVelY = velocity_y;
currentCheckpoint.EndVelZ = velocity_z;
currentCheckpoint.EndTouch = player.Timer.Ticks; // To-do: what type of value we store in DB ?
currentCheckpoint.Attempts += 1;

// Show Prespeed for stages - will be enabled/disabled by the user?
player.Controller.PrintToCenter($"Checkpoint {Regex.Match(trigger.Entity.Name, "[0-9][0-9]?").Value} - Prespeed: {velocity.ToString("0")} u/s");
Expand Down
6 changes: 3 additions & 3 deletions src/ST-Events/TriggerStartTouch.cs
Original file line number Diff line number Diff line change
Expand Up @@ -86,10 +86,10 @@ internal HookResult OnTriggerStartTouch(DynamicHook handler)
#endif

// Add entry in DB for the run
player.Stats.PB[0].SaveMapTime(player, DB); // Save the MapTime PB data
player.Stats.ThisRun.SaveMapTime(player, DB); // Save the MapTime PB data
player.Stats.LoadMapTimesData(player, DB); // Load the MapTime PB data again (will refresh the MapTime ID for the Checkpoints query)
player.Stats.PB[0].Checkpoint[0].SaveCurrentRunCheckpoints(player, DB); // Save the Checkpoints PB data
player.Stats.PB[0].Checkpoint[0].LoadCheckpointsForRun(DB); // Reload checkpoints for the run - we should really have this in `SaveMapTime` as well but we don't re-load PB data inside there so we need to do it here
player.Stats.ThisRun.SaveCurrentRunCheckpoints(player, DB); // Save this run's checkpoints
player.Stats.LoadCheckpointsData(DB); // Reload checkpoints for the run - we should really have this in `SaveMapTime` as well but we don't re-load PB data inside there so we need to do it here
CurrentMap.GetMapRecordAndTotals(DB); // Reload the Map record and totals for the HUD
}

Expand Down
51 changes: 41 additions & 10 deletions src/ST-Map/Map.cs
Original file line number Diff line number Diff line change
Expand Up @@ -56,14 +56,26 @@ internal Map(string Name, TimerDatabase DB)
trigger.Entity!.Name.Contains("stage1_start") ||
trigger.Entity!.Name.Contains("s1_start"))
{
this.StartZone = new Vector(trigger.AbsOrigin!.X, trigger.AbsOrigin!.Y, trigger.AbsOrigin!.Z);
bool foundPlayerSpawn = false; // Track whether a player spawn is found
foreach (CBaseEntity teleport in teleports)
{
if (teleport.Entity!.Name != null && IsInZone(trigger.AbsOrigin!, trigger.Collision.BoundingRadius, teleport.AbsOrigin!))
if (teleport.Entity!.Name != null &&
(IsInZone(trigger.AbsOrigin!, trigger.Collision.BoundingRadius, teleport.AbsOrigin!) ||
teleport.Entity!.Name.Contains("spawn_map_start") ||
teleport.Entity!.Name.Contains("spawn_stage1_start") ||
teleport.Entity!.Name.Contains("spawn_s1_start")))
{
this.StartZone = new Vector(teleport.AbsOrigin!.X, teleport.AbsOrigin!.Y, teleport.AbsOrigin!.Z);
this.StartZoneAngles = new QAngle(teleport.AbsRotation!.X, teleport.AbsRotation!.Y, teleport.AbsRotation!.Z);
foundPlayerSpawn = true;
break;
}
}

if (!foundPlayerSpawn)
{
this.StartZone = new Vector(trigger.AbsOrigin!.X, trigger.AbsOrigin!.Y, trigger.AbsOrigin!.Z);
}
}

// Map end zone
Expand All @@ -75,41 +87,60 @@ internal Map(string Name, TimerDatabase DB)
// Stage start zones
else if (Regex.Match(trigger.Entity.Name, "^s([1-9][0-9]?|tage[1-9][0-9]?)_start$").Success)
{
this.StageStartZone[Int32.Parse(Regex.Match(trigger.Entity.Name, "[0-9][0-9]?").Value) - 1] = new Vector(trigger.AbsOrigin!.X, trigger.AbsOrigin!.Y, trigger.AbsOrigin!.Z);

int stage = Int32.Parse(Regex.Match(trigger.Entity.Name, "[0-9][0-9]?").Value);
// Find an info_destination_teleport inside this zone to grab angles from
bool foundPlayerSpawn = false; // Track whether a player spawn is found
foreach (CBaseEntity teleport in teleports)
{
if (teleport.Entity!.Name != null && IsInZone(trigger.AbsOrigin!, trigger.Collision.BoundingRadius, teleport.AbsOrigin!))
if (teleport.Entity!.Name != null &&
(IsInZone(trigger.AbsOrigin!, trigger.Collision.BoundingRadius, teleport.AbsOrigin!) || (Regex.Match(teleport.Entity.Name, "^spawn_s([1-9][0-9]?|tage[1-9][0-9]?)_start$").Success && Int32.Parse(Regex.Match(teleport.Entity.Name, "[0-9][0-9]?").Value) == stage)))
{
this.StageStartZoneAngles[Int32.Parse(Regex.Match(trigger.Entity.Name, "[0-9][0-9]?").Value) - 1] = new QAngle(teleport.AbsRotation!.X, teleport.AbsRotation!.Y, teleport.AbsRotation!.Z);
this.StageStartZone[stage - 1] = new Vector(teleport.AbsOrigin!.X, teleport.AbsOrigin!.Y, teleport.AbsOrigin!.Z);
this.StageStartZoneAngles[stage - 1] = new QAngle(teleport.AbsRotation!.X, teleport.AbsRotation!.Y, teleport.AbsRotation!.Z);
this.Stages++; // Count stage zones for the map to populate DB
foundPlayerSpawn = true;
break;
}
}

if (!foundPlayerSpawn)
{
this.StageStartZone[stage - 1] = new Vector(trigger.AbsOrigin!.X, trigger.AbsOrigin!.Y, trigger.AbsOrigin!.Z);
}
}

// Checkpoint start zones (linear maps)
else if (Regex.Match(trigger.Entity.Name, "^map_c(p[1-9][0-9]?|heckpoint[1-9][0-9]?)$").Success)
{
this.CheckpointStartZone[Int32.Parse(Regex.Match(trigger.Entity.Name, "[0-9][0-9]?").Value) - 1] = new Vector(trigger.AbsOrigin!.X, trigger.AbsOrigin!.Y, trigger.AbsOrigin!.Z);
this.Checkpoints++; // Might be useful to have this in DB entry
// Do we need `info_destination_teleport` data for Checkpoint zones?
}

// Bonus start zones
else if (Regex.Match(trigger.Entity.Name, "^b([1-9][0-9]?|onus[1-9][0-9]?)_start$").Success)
{
this.BonusStartZone[Int32.Parse(Regex.Match(trigger.Entity.Name, "[0-9][0-9]?").Value) - 1] = new Vector(trigger.AbsOrigin!.X, trigger.AbsOrigin!.Y, trigger.AbsOrigin!.Z);
int bonus = Int32.Parse(Regex.Match(trigger.Entity.Name, "[0-9][0-9]?").Value);

// Find an info_destination_teleport inside this zone to grab angles from
bool foundPlayerSpawn = false; // Track whether a player spawn is found
foreach (CBaseEntity teleport in teleports)
{
if (teleport.Entity!.Name != null && IsInZone(trigger.AbsOrigin!, trigger.Collision.BoundingRadius, teleport.AbsOrigin!))
if (teleport.Entity!.Name != null &&
(IsInZone(trigger.AbsOrigin!, trigger.Collision.BoundingRadius, teleport.AbsOrigin!) || (Regex.Match(teleport.Entity.Name, "^spawn_b([1-9][0-9]?|onus[1-9][0-9]?)_start$").Success && Int32.Parse(Regex.Match(teleport.Entity.Name, "[0-9][0-9]?").Value) == bonus)))
{
this.BonusStartZoneAngles[Int32.Parse(Regex.Match(trigger.Entity.Name, "[0-9][0-9]?").Value) - 1] = new QAngle(teleport.AbsRotation!.X, teleport.AbsRotation!.Y, teleport.AbsRotation!.Z);
this.BonusStartZone[bonus - 1] = new Vector(teleport.AbsOrigin!.X, teleport.AbsOrigin!.Y, teleport.AbsOrigin!.Z);
this.BonusStartZoneAngles[bonus - 1] = new QAngle(teleport.AbsRotation!.X, teleport.AbsRotation!.Y, teleport.AbsRotation!.Z);
this.Bonuses++; // Count bonus zones for the map to populate DB
foundPlayerSpawn = true;
break;
}
}

if (!foundPlayerSpawn)
{
this.BonusStartZone[bonus - 1] = new Vector(trigger.AbsOrigin!.X, trigger.AbsOrigin!.Y, trigger.AbsOrigin!.Z);
}
}

else if (Regex.Match(trigger.Entity.Name, "^b([1-9][0-9]?|onus[1-9][0-9]?)_end$").Success)
Expand Down
8 changes: 4 additions & 4 deletions src/ST-Player/PlayerHUD.cs
Original file line number Diff line number Diff line change
Expand Up @@ -119,10 +119,10 @@ public void DisplayCheckpointMessages(string PluginPrefix) // To-do: PluginPrefi
// Can check checkpoints count instead of try/catch
try
{
pbTime = _player.Stats.PB[0].Checkpoint[_player.Timer.Checkpoint].CpTicks;
pbSpeed = (float)Math.Sqrt(_player.Stats.PB[0].Checkpoint[_player.Timer.Checkpoint].CpStartVelX * _player.Stats.PB[0].Checkpoint[_player.Timer.Checkpoint].CpStartVelX
+ _player.Stats.PB[0].Checkpoint[_player.Timer.Checkpoint].CpStartVelY * _player.Stats.PB[0].Checkpoint[_player.Timer.Checkpoint].CpStartVelY
+ _player.Stats.PB[0].Checkpoint[_player.Timer.Checkpoint].CpStartVelZ * _player.Stats.PB[0].Checkpoint[_player.Timer.Checkpoint].CpStartVelZ);
pbTime = _player.Stats.PB[0].Checkpoint[_player.Timer.Checkpoint].Ticks;
pbSpeed = (float)Math.Sqrt(_player.Stats.PB[0].Checkpoint[_player.Timer.Checkpoint].StartVelX * _player.Stats.PB[0].Checkpoint[_player.Timer.Checkpoint].StartVelX
+ _player.Stats.PB[0].Checkpoint[_player.Timer.Checkpoint].StartVelY * _player.Stats.PB[0].Checkpoint[_player.Timer.Checkpoint].StartVelY
+ _player.Stats.PB[0].Checkpoint[_player.Timer.Checkpoint].StartVelZ * _player.Stats.PB[0].Checkpoint[_player.Timer.Checkpoint].StartVelZ);

#if DEBUG
Console.WriteLine($"CS2 Surf DEBUG >> DisplayCheckpointMessages -> [TIME] Got pbTime from _player.Stats.PB[0].Checkpoint[{_player.Timer.Checkpoint} = {pbTime}]");
Expand Down
Loading