Skip to content

Commit 860fed1

Browse files
DandrewsDevdandrews
andauthored
Adds new methods for getting total damage, and utility damage as well as automated tests. (#369)
Co-authored-by: dandrews <[email protected]>
1 parent 81e862b commit 860fed1

File tree

2 files changed

+22
-0
lines changed

2 files changed

+22
-0
lines changed

pkg/demoinfocs/common/player.go

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -470,6 +470,16 @@ func (p *Player) MVPs() int {
470470
return getInt(p.resourceEntity(), "m_iMVPs."+p.entityIDStr())
471471
}
472472

473+
// TotalDamage returns the total health damage done by the player.
474+
func (p *Player) TotalDamage() int {
475+
return getInt(p.resourceEntity(), "m_iMatchStats_Damage_Total."+p.entityIDStr())
476+
}
477+
478+
// UtilityDamage returns the total damage done by the player with grenades.
479+
func (p *Player) UtilityDamage() int {
480+
return getInt(p.resourceEntity(), "m_iMatchStats_UtilityDamage_Total."+p.entityIDStr())
481+
}
482+
473483
// MoneySpentTotal returns the total amount of money the player has spent in the current match.
474484
func (p *Player) MoneySpentTotal() int {
475485
return getInt(p.resourceEntity(), "m_iTotalCashSpent."+p.entityIDStr())

pkg/demoinfocs/common/player_test.go

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -486,6 +486,18 @@ func TestPlayer_MVPs(t *testing.T) {
486486
assert.Equal(t, 4, pl.MVPs())
487487
}
488488

489+
func TestPlayer_TotalDamage(t *testing.T) {
490+
pl := playerWithResourceProperty("m_iMatchStats_Damage_Total", st.PropertyValue{IntVal: 2900})
491+
492+
assert.Equal(t, 2900, pl.TotalDamage())
493+
}
494+
495+
func TestPlayer_UtilityDamage(t *testing.T) {
496+
pl := playerWithResourceProperty("m_iMatchStats_UtilityDamage_Total", st.PropertyValue{IntVal: 420})
497+
498+
assert.Equal(t, 420, pl.UtilityDamage())
499+
}
500+
489501
func TestPlayer_SteamID32(t *testing.T) {
490502
pl := &Player{SteamID64: 76561198012952267}
491503

0 commit comments

Comments
 (0)