Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bonus timing, misc. updates to codebase #13

Draft
wants to merge 42 commits into
base: dev
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
42 commits
Select commit Hold shift + click to select a range
9f18d8f
Use INT for ticks, not DECIMAL
1zc Feb 14, 2024
8223740
We now know what type to use lol
1zc Feb 14, 2024
4d65c0b
Add /stage as alias for /s
1zc Feb 14, 2024
299557a
!b/!bonus commands
1zc Feb 14, 2024
095e5db
Fix display bug with compact timing style
1zc Feb 14, 2024
55f2da7
Handle hours separately in full time-style
1zc Feb 14, 2024
dec76c2
Identify stage/bonus mode in hud
1zc Feb 14, 2024
7d4fa59
have /rs account for bonuses
1zc Feb 14, 2024
afa55ba
Foundational bonus stuff
1zc Feb 14, 2024
6e78f1d
Hibernation needs disabling
1zc Feb 14, 2024
5c93d1d
Fix incorrect stage indexing
1zc Feb 14, 2024
58f7cee
Account for stage 1
1zc Feb 14, 2024
d52084b
Correct bonus indexing
1zc Feb 14, 2024
d9d24c8
Add to-do to Map.cs
1zc Feb 14, 2024
6bc2cb0
Print plugin info on map load
1zc Feb 15, 2024
0625863
Update README goals list status
1zc Feb 15, 2024
ef8bc37
Implement `type` field from Map Times DB
1zc Feb 15, 2024
127dffc
Add some fn comments
1zc Feb 15, 2024
d789431
Documentation on some PlayerStats variables
1zc Feb 15, 2024
72b12dc
fix some data types
tslashd Feb 29, 2024
b62ba44
Merge branch 'bonus-timing' of https://github.com/CS2Surf/Timer into …
1zc Mar 2, 2024
cf415cc
Better command arg handling
1zc Mar 10, 2024
321d4ae
end zone foundations
1zc Mar 10, 2024
3020a4f
Load player's bonus times from DB
1zc Mar 10, 2024
62485f0
Fix typo in information for BonusPB
1zc Mar 10, 2024
05fbc6d
typo
1zc Mar 10, 2024
113f45f
Add options bonus param to SaveMapTime
1zc Mar 10, 2024
45acb41
Use new SaveMapTime in bonus time saving
1zc Mar 10, 2024
bc8114c
Comments for Map.WR & Map.BonusWR calls
1zc Mar 10, 2024
c3ba3a1
Handle starting and saving bonus replays
1zc Mar 10, 2024
4c917a3
Show relevant bonus info on HUD
1zc Mar 10, 2024
e59b148
Correct addressing of Array of Dictionaries
1zc Mar 10, 2024
7097e4e
Actually handle bonus run ticks + velocities
1zc Mar 10, 2024
b2a1221
Load bonus WRs in Map
1zc Mar 10, 2024
1906c24
Clear bonus goals in README
Mar 10, 2024
403117e
Account for style and bonus completion counts
1zc Mar 11, 2024
6463812
Merge branch 'bonus-timing' of https://github.com/CS2Surf/Timer into …
1zc Mar 11, 2024
eb9eff1
Populate Map.BonusCompletions[bonus][style]
1zc Mar 11, 2024
a6f1c34
Bad practice!!!!!
1zc Mar 11, 2024
b9fe9d7
Initialize Map.BonusCompletions dict
1zc Mar 11, 2024
b4948b3
Calculate rank per type
1zc Mar 11, 2024
bf83166
Account for bonus ranks on HUD
1zc Mar 11, 2024
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
8 changes: 4 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,11 +26,11 @@ Bold & Italics = being worked on.
- [ ] Save Stage times
- [X] Support for bonuses
- [X] Hook to their start/end zones
- [ ] Save Bonus times
- [X] Save Bonus times
- [X] Start/End trigger touch hooks
- [X] Load zone information automatically from standardised triggers: https://github.com/CS2Surf/Timer/wiki/CS2-Surf-Mapping
- [X] _**Support for stages (`/rs`, teleporting with `/s`)**_
- [ ] _**Support for bonuses (`/rs`, teleporting with `/b #`)**_
- [X] Support for stages (`/rs`, teleporting with `/s`)
- [X] Support for bonuses (`/rs`, teleporting with `/b #`)
- [ ] _**Start/End touch hooks implemented for all zones**_
- [ ] Surf configs
- [X] Server settings configuration
Expand All @@ -44,7 +44,7 @@ Bold & Italics = being worked on.
- [x] Map times
- [x] Checkpoint times
- [ ] Stage times
- [ ] Bonus times
- [X] Bonus times
- [X] Practice Mode implementation
- [ ] Announce records to Discord
- [ ] Stretch goal: sub-tick timing
Expand Down
1 change: 1 addition & 0 deletions cfg/SurfTimer/server_settings.cfg
tslashd marked this conversation as resolved.
Show resolved Hide resolved
Original file line number Diff line number Diff line change
Expand Up @@ -76,5 +76,6 @@ mp_warmup_end
mp_warmuptime 0
sv_holiday_mode 0
sv_party_mode 0
sv_hibernate_when_empty 0

sv_cheats 0
88 changes: 78 additions & 10 deletions src/ST-Commands/PlayerCommands.cs
Original file line number Diff line number Diff line change
Expand Up @@ -32,43 +32,62 @@ public void PlayerResetStage(CCSPlayerController? player, CommandInfo command)

// To-do: players[userid].Timer.Reset() -> teleport player
Player SurfPlayer = playerList[player.UserId ?? 0];
if (SurfPlayer.Timer.Stage != 0 && CurrentMap.StageStartZone[SurfPlayer.Timer.Stage] != new Vector(0, 0, 0))
Server.NextFrame(() => player.PlayerPawn.Value!.Teleport(CurrentMap.StageStartZone[SurfPlayer.Timer.Stage], CurrentMap.StageStartZoneAngles[SurfPlayer.Timer.Stage], new Vector(0, 0, 0)));
else // Reset back to map start
Server.NextFrame(() => player.PlayerPawn.Value!.Teleport(CurrentMap.StartZone, new QAngle(0, 0, 0), new Vector(0, 0, 0)));

if (SurfPlayer.Timer.IsBonusMode)
{
if (SurfPlayer.Timer.Bonus != 0 && CurrentMap.BonusStartZone[SurfPlayer.Timer.Bonus] != new Vector(0, 0, 0))
Server.NextFrame(() => player.PlayerPawn.Value!.Teleport(CurrentMap.BonusStartZone[SurfPlayer.Timer.Bonus], CurrentMap.BonusStartZoneAngles[SurfPlayer.Timer.Bonus], new Vector(0, 0, 0)));
else // Reset back to map start
Server.NextFrame(() => player.PlayerPawn.Value!.Teleport(CurrentMap.StartZone, new QAngle(0, 0, 0), new Vector(0, 0, 0)));
}

else
{
if (SurfPlayer.Timer.Stage != 0 && CurrentMap.StageStartZone[SurfPlayer.Timer.Stage] != new Vector(0, 0, 0))
Server.NextFrame(() => player.PlayerPawn.Value!.Teleport(CurrentMap.StageStartZone[SurfPlayer.Timer.Stage], CurrentMap.StageStartZoneAngles[SurfPlayer.Timer.Stage], new Vector(0, 0, 0)));
else // Reset back to map start
Server.NextFrame(() => player.PlayerPawn.Value!.Teleport(CurrentMap.StartZone, new QAngle(0, 0, 0), new Vector(0, 0, 0)));
}

return;
}

[ConsoleCommand("css_s", "Teleport to a stage")]
[ConsoleCommand("css_stage", "Teleport to a stage")]
[CommandHelper(whoCanExecute: CommandUsage.CLIENT_ONLY)]
public void PlayerGoToStage(CCSPlayerController? player, CommandInfo command)
{
if (player == null)
return;

int stage = Int32.Parse(command.ArgByIndex(1)) - 1;
if (stage > CurrentMap.Stages - 1 && CurrentMap.Stages > 0)
stage = CurrentMap.Stages - 1;
int stage = Int32.Parse(command.ArgByIndex(1));

// Must be 1 argument
if (command.ArgCount < 2 || stage < 0)
if (command.ArgCount < 2 || stage <= 0)
{
#if DEBUG
player.PrintToChat($"CS2 Surf DEBUG >> css_s >> Arg#: {command.ArgCount} >> Args: {Int32.Parse(command.ArgByIndex(1))}");
player.PrintToChat($"CS2 Surf DEBUG >> css_stage >> Arg#: {command.ArgCount} >> Args: {Int32.Parse(command.ArgByIndex(1))}");
#endif

player.PrintToChat($"{PluginPrefix} {ChatColors.Red}Invalid arguments. Usage: {ChatColors.Green}!s <stage>");
return;
}

else if (CurrentMap.Stages <= 0)
{
player.PrintToChat($"{PluginPrefix} {ChatColors.Red}This map has no stages.");
return;
}

else if (stage > CurrentMap.Stages)
{
player.PrintToChat($"{PluginPrefix} {ChatColors.Red}Invalid stage provided, this map has {ChatColors.Green}{CurrentMap.Stages} stages.");
return;
}

if (CurrentMap.StageStartZone[stage] != new Vector(0, 0, 0))
{
if (stage == 0)
if (stage == 1)
Server.NextFrame(() => player.PlayerPawn.Value!.Teleport(CurrentMap.StartZone, CurrentMap.StartZoneAngles, new Vector(0, 0, 0)));
else
Server.NextFrame(() => player.PlayerPawn.Value!.Teleport(CurrentMap.StageStartZone[stage], CurrentMap.StageStartZoneAngles[stage], new Vector(0, 0, 0)));
Expand All @@ -84,6 +103,55 @@ public void PlayerGoToStage(CCSPlayerController? player, CommandInfo command)
player.PrintToChat($"{PluginPrefix} {ChatColors.Red}Invalid stage provided. Usage: {ChatColors.Green}!s <stage>");
}

[ConsoleCommand("css_b", "Teleport to a bonus")]
[ConsoleCommand("css_bonus", "Teleport to a bonus")]
[CommandHelper(whoCanExecute: CommandUsage.CLIENT_ONLY)]
public void PlayerGoToBonus(CCSPlayerController? player, CommandInfo command)
{
if (player == null)
return;

int bonus;

// Check for argument count
if (command.ArgCount < 2)
{
if (CurrentMap.Bonuses > 0)
bonus = 1;
else
{
player.PrintToChat($"{PluginPrefix} {ChatColors.Red}Invalid arguments. Usage: {ChatColors.Green}!bonus <bonus>");
return;
}
}

else
bonus = Int32.Parse(command.ArgByIndex(1));

if (CurrentMap.Bonuses <= 0)
{
player.PrintToChat($"{PluginPrefix} {ChatColors.Red}This map has no bonuses.");
return;
}

else if (bonus > CurrentMap.Bonuses)
{
player.PrintToChat($"{PluginPrefix} {ChatColors.Red}Invalid bonus provided, this map has {ChatColors.Green}{CurrentMap.Bonuses} bonuses.");
return;
}

if (CurrentMap.BonusStartZone[bonus] != new Vector(0, 0, 0))
{
playerList[player.UserId ?? 0].Timer.Reset();
playerList[player.UserId ?? 0].Timer.IsBonusMode = true;

Server.NextFrame(() => player.PlayerPawn.Value!.Teleport(CurrentMap.BonusStartZone[bonus], CurrentMap.BonusStartZoneAngles[bonus], new Vector(0, 0, 0)));
}

else
player.PrintToChat($"{PluginPrefix} {ChatColors.Red}Invalid bonus provided. Usage: {ChatColors.Green}!bonus <bonus>");
}

[ConsoleCommand("css_spec", "Moves a player automaticlly into spectator mode")]
public void MovePlayerToSpectator(CCSPlayerController? player, CommandInfo command)
{
Expand Down
34 changes: 29 additions & 5 deletions src/ST-Events/TriggerEndTouch.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,11 @@ namespace SurfTimer;

public partial class SurfTimer
{
// Trigger end touch handler - CBaseTrigger_EndTouchFunc
// internal HookResult OnTriggerEndTouch(DynamicHook handler)
/// <summary>
/// Handler for trigger end touch hook - CBaseTrigger_EndTouchFunc
/// </summary>
/// <returns>CounterStrikeSharp.API.Core.HookResult</returns>
/// <exception cref="Exception"></exception>
internal HookResult OnTriggerEndTouch(CEntityIOOutput output, string name, CEntityInstance activator, CEntityInstance caller, CVariant value, float delay)
{
// CBaseTrigger trigger = handler.GetParam<CBaseTrigger>(0);
Expand Down Expand Up @@ -50,7 +53,7 @@ internal HookResult OnTriggerEndTouch(CEntityIOOutput output, string name, CEnti
}

// MAP START ZONE
if (!player.Timer.IsStageMode)
if (!player.Timer.IsStageMode && !player.Timer.IsBonusMode)
{
player.Timer.Start();
player.ReplayRecorder.CurrentSituation = ReplayFrameSituation.START_RUN;
Expand Down Expand Up @@ -103,7 +106,7 @@ internal HookResult OnTriggerEndTouch(CEntityIOOutput output, string name, CEnti
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.EndTouch = player.Timer.Ticks;
currentCheckpoint.Attempts += 1;
// Assign the updated currentCheckpoint back to the list as `currentCheckpoint` is supposedly a copy of the original object
player.Stats.ThisRun.Checkpoint[player.Timer.Checkpoint] = currentCheckpoint;
Expand Down Expand Up @@ -139,7 +142,7 @@ internal HookResult OnTriggerEndTouch(CEntityIOOutput output, string name, CEnti
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.EndTouch = player.Timer.Ticks;
currentCheckpoint.Attempts += 1;
// Assign the updated currentCheckpoint back to the list as `currentCheckpoint` is supposedly a copy of the original object
player.Stats.ThisRun.Checkpoint[player.Timer.Checkpoint] = currentCheckpoint;
Expand All @@ -152,6 +155,27 @@ internal HookResult OnTriggerEndTouch(CEntityIOOutput output, string name, CEnti
// Handle the case where the index is out of bounds
}
}

// Bonus start zones -- hook into (b)onus#_start
else if (Regex.Match(trigger.Entity.Name, "^b([1-9][0-9]?|onus[1-9][0-9]?)_start$").Success)
{
#if DEBUG
player.Controller.PrintToChat($"CS2 Surf DEBUG >> CBaseTrigger_{ChatColors.LightRed}EndTouchFunc{ChatColors.Default} -> {ChatColors.Yellow}Bonus {Regex.Match(trigger.Entity.Name, "[0-9][0-9]?").Value} Start Zone");
#endif

// BONUS START ZONE
if (!player.Timer.IsStageMode && player.Timer.IsBonusMode)
{
player.Timer.Start();
// To-do: bonus replay
}

// 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
}
}

return HookResult.Continue;
Expand Down
Loading
Loading