Skip to content

Commit 5cd67ef

Browse files
committed
common: add Player.IsReloading attribute
1 parent 99e66a0 commit 5cd67ef

File tree

4 files changed

+24
-1
lines changed

4 files changed

+24
-1
lines changed

common/player.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@ type Player struct {
4848
IsDucking bool
4949
IsDefusing bool
5050
IsPlanting bool
51+
IsReloading bool
5152
HasDefuseKit bool
5253
HasHelmet bool
5354
}

datatables.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -304,6 +304,7 @@ func (p *Parser) bindNewPlayer(playerEntity st.IEntity) {
304304

305305
// Active weapon
306306
playerEntity.FindPropertyI("m_hActiveWeapon").OnUpdate(func(val st.PropertyValue) {
307+
pl.IsReloading = false
307308
pl.ActiveWeaponID = val.IntVal & entityHandleIndexMask
308309
})
309310

@@ -431,6 +432,10 @@ func (p *Parser) bindWeapon(entity *st.Entity, wepType common.EquipmentElement)
431432

432433
entity.FindPropertyI("m_iClip1").OnUpdate(func(val st.PropertyValue) {
433434
eq.AmmoInMagazine = val.IntVal - 1
435+
436+
if eq.Owner != nil {
437+
eq.Owner.IsReloading = false
438+
}
434439
})
435440
// Some weapons in some demos might be missing this property
436441
if reserveAmmoProp := entity.FindPropertyI("m_iPrimaryReserveAmmoCount"); reserveAmmoProp != nil {

demoinfocs_test.go

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -123,6 +123,21 @@ func TestDemoInfoCs(t *testing.T) {
123123
}
124124
})
125125

126+
// reload checks
127+
p.RegisterEventHandler(func(reload events.WeaponReload) {
128+
if !reload.Player.IsReloading {
129+
t.Error("Player started reloading but IsReloading is false")
130+
}
131+
})
132+
133+
p.RegisterEventHandler(func(start events.RoundFreezetimeEnd) {
134+
for _, pl := range p.GameState().Participants().All() {
135+
if pl.IsReloading {
136+
t.Error("Player is reloading at the start of the round")
137+
}
138+
}
139+
})
140+
126141
// Check some things at match start
127142
p.RegisterEventHandler(func(events.MatchStart) {
128143
participants := gs.Participants()

game_events.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -281,8 +281,10 @@ func (geh gameEventHandler) weaponFire(data map[string]*msg.CSVCMsg_GameEventKey
281281
}
282282

283283
func (geh gameEventHandler) weaponReload(data map[string]*msg.CSVCMsg_GameEventKeyT) {
284+
pl := geh.playerByUserID32(data["userid"].GetValShort())
285+
pl.IsReloading = true
284286
geh.dispatch(events.WeaponReload{
285-
Player: geh.playerByUserID32(data["userid"].GetValShort()),
287+
Player: pl,
286288
})
287289
}
288290

0 commit comments

Comments
 (0)