Skip to content

Commit 3deab79

Browse files
committed
common: add Player.IsBlinded() helper function
See #71
1 parent 1f98bb0 commit 3deab79

File tree

2 files changed

+30
-1
lines changed

2 files changed

+30
-1
lines changed

common/player.go

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ type Player struct {
2727
AdditionalPlayerInformation *AdditionalPlayerInformation // Mostly scoreboard information such as kills, deaths, etc.
2828
ViewDirectionX float32
2929
ViewDirectionY float32
30-
FlashDuration float32 // How long this player is flashed for from now on
30+
FlashDuration float32 // Blindness duration from the flashbang currently affecting the player (seconds)
3131
Team Team
3232
IsBot bool
3333
IsDucking bool
@@ -40,6 +40,26 @@ func (p *Player) IsAlive() bool {
4040
return p.Hp > 0
4141
}
4242

43+
// IsBlinded returns true if the player is currently flashed (FlashDuration > 0).
44+
func (p *Player) IsBlinded() bool {
45+
return p.FlashDuration > 0
46+
}
47+
48+
/*
49+
Some interesting data regarding flashes.
50+
51+
player time flash-duration
52+
10 49m0.613347564s 0
53+
10 49m50.54364714s 3.4198754
54+
10 49m53.122207212s 3.8876143
55+
10 49m54.84124726s 2.1688643
56+
10 49m58.552811s 0
57+
58+
Going by the last two lines, the player should not have been blinded at ~49m57.0, but he was only cleared at ~49m58.5
59+
60+
This isn't very conclusive but it looks like IsFlashed isn't super reliable currently.
61+
*/
62+
4363
// ActiveWeapon returns the currently active / equipped weapon of the player.
4464
func (p *Player) ActiveWeapon() *Equipment {
4565
return p.RawWeapons[p.ActiveWeaponID]

common/player_test.go

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,3 +48,12 @@ func TestPlayerAlive(t *testing.T) {
4848
pl.Hp = -10
4949
assert.Equal(t, false, pl.IsAlive(), "Should be dead")
5050
}
51+
52+
func TestPlayerFlashed(t *testing.T) {
53+
pl := NewPlayer()
54+
55+
assert.False(t, pl.IsBlinded(), "Should not be flashed")
56+
57+
pl.FlashDuration = 2.3
58+
assert.True(t, pl.IsBlinded(), "Should be flashed")
59+
}

0 commit comments

Comments
 (0)