-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: implement anti-C-Bug mechanism for Desert Eagle (#304)
1 parent
6880e74
commit 94775b7
Showing
2 changed files
with
58 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
namespace CTF.Application.Players.AntiCBug; | ||
|
||
public class AntiCBugSystem(UnixTimeSeconds unixTimeSeconds) : ISystem | ||
{ | ||
[Event] | ||
public void OnPlayerConnect(Player player) | ||
{ | ||
player.AddComponent<LastFiredTimeComponent>(); | ||
} | ||
|
||
[Event] | ||
public void OnPlayerKeyStateChange(Player player, Keys newKeys, Keys oldKeys) | ||
{ | ||
if (player.State != PlayerState.OnFoot) | ||
return; | ||
|
||
var lastFiredTimeComponent = player.GetComponent<LastFiredTimeComponent>(); | ||
if (player.SpecialAction != SpecialAction.Duck && | ||
KeyUtils.HasPressed(newKeys, oldKeys, Keys.Fire)) | ||
{ | ||
lastFiredTimeComponent.Value = player.Weapon switch | ||
{ | ||
Weapon.Deagle => unixTimeSeconds.Value, | ||
_ => default | ||
}; | ||
} | ||
else if (KeyUtils.HasPressed(newKeys, oldKeys, Keys.Crouch)) | ||
{ | ||
long currentTime = unixTimeSeconds.Value; | ||
long elapsedTime = currentTime - lastFiredTimeComponent.Value; | ||
if (elapsedTime < 1) | ||
{ | ||
player.GameText("~r~~h~DON'T C-BUG!", 3000, 4); | ||
player.ApplyAnimation( | ||
animationLibrary: "PED", | ||
animationName: "getup", | ||
fDelta: 4.1f, | ||
loop: false, | ||
lockX: false, | ||
lockY: false, | ||
freeze: false, | ||
time: 0, | ||
forceSync: false | ||
); | ||
} | ||
} | ||
} | ||
} |
10 changes: 10 additions & 0 deletions
10
src/Application/Players/AntiCBug/LastFiredTimeComponent.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
namespace CTF.Application.Players.AntiCBug; | ||
|
||
/// <summary> | ||
/// Represents a component that stores the last shot time and | ||
/// is used to detect rapid shooting techniques such as C-Bug. | ||
/// </summary> | ||
public class LastFiredTimeComponent : Component | ||
{ | ||
public long Value { get; set; } | ||
} |