Repository: markus-wa/demoinfocs-golang
Pull request #369 (2022-11-25 07:19:02)

Adds new methods for getting total damage, and utility damage
Spent some time working out the most consistent way to calculate ADR, and kept running into issues. But found that the game tracked m_iMatchStats_Damage_Total. So added methods for pulling that as well as utility damage.

This makes really trivial to create those damage line graphs, for total damage, and utility damage. 

I added automated tests for these as well. 

codecov[bot]: # [Codecov](https://codecov.io/gh/markus-wa/demoinfocs-golang/pull/369?src=pr&el=h1&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=Markus) Report
Base: **92.02**% // Head: **92.03**% // Increases project coverage by **`+0.00%`** :tada:
> Coverage data is based on head [(`9929073`)](https://codecov.io/gh/markus-wa/demoinfocs-golang/pull/369?src=pr&el=desc&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=Markus) compared to base [(`81e862b`)](https://codecov.io/gh/markus-wa/demoinfocs-golang/commit/81e862b54239670d48b0dba5ee0d962209e31eab?el=desc&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=Markus).
> Patch coverage: 100.00% of modified lines in pull request are covered.

<details><summary>Additional details and impacted files</summary>


```diff
@@           Coverage Diff           @@
##           master     #369   +/-   ##
=======================================
  Coverage   92.02%   92.03%           
=======================================
  Files          32       32           
  Lines        3197     3201    +4     
=======================================
+ Hits         2942     2946    +4     
  Misses        198      198           
  Partials       57       57           
```


| [Impacted Files](https://codecov.io/gh/markus-wa/demoinfocs-golang/pull/369?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=Markus) | Coverage Δ | |
|---|---|---|
| [pkg/demoinfocs/common/player.go](https://codecov.io/gh/markus-wa/demoinfocs-golang/pull/369/diff?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=Markus#diff-cGtnL2RlbW9pbmZvY3MvY29tbW9uL3BsYXllci5nbw==) | `98.86% <100.00%> (+0.02%)` | :arrow_up: |

Help us with your feedback. Take ten seconds to tell us [how you rate us](https://about.codecov.io/nps?utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=Markus). Have a feature suggestion? [Share it here.](https://app.codecov.io/gh/feedback/?utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=Markus)

</details>

[:umbrella: View full report at Codecov](https://codecov.io/gh/markus-wa/demoinfocs-golang/pull/369?src=pr&el=continue&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=Markus).   
:loudspeaker: Do you have feedback about the report comment? [Let us know in this issue](https://about.codecov.io/codecov-pr-comment-feedback/?utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=Markus).


Patch:
diff --git a/pkg/demoinfocs/common/player.go b/pkg/demoinfocs/common/player.go
index 2b24bcf..a0b1e16 100644
--- a/pkg/demoinfocs/common/player.go
+++ b/pkg/demoinfocs/common/player.go
@@ -470,6 +470,16 @@ func (p *Player) MVPs() int {
 	return getInt(p.resourceEntity(), "m_iMVPs."+p.entityIDStr())
 }
 
+// TotalDamage returns the total health damage done by the player.
+func (p *Player) TotalDamage() int {
+	return getInt(p.resourceEntity(), "m_iMatchStats_Damage_Total."+p.entityIDStr())
+}
+
+// UtilityDamage returns the total damage done by the player with grenades.
+func (p *Player) UtilityDamage() int {
+	return getInt(p.resourceEntity(), "m_iMatchStats_UtilityDamage_Total."+p.entityIDStr())
+}
+
 // MoneySpentTotal returns the total amount of money the player has spent in the current match.
 func (p *Player) MoneySpentTotal() int {
 	return getInt(p.resourceEntity(), "m_iTotalCashSpent."+p.entityIDStr())


Test patch:
diff --git a/pkg/demoinfocs/common/player_test.go b/pkg/demoinfocs/common/player_test.go
index b9b264a..077e43a 100644
--- a/pkg/demoinfocs/common/player_test.go
+++ b/pkg/demoinfocs/common/player_test.go
@@ -486,6 +486,18 @@ func TestPlayer_MVPs(t *testing.T) {
 	assert.Equal(t, 4, pl.MVPs())
 }
 
+func TestPlayer_TotalDamage(t *testing.T) {
+	pl := playerWithResourceProperty("m_iMatchStats_Damage_Total", st.PropertyValue{IntVal: 2900})
+
+	assert.Equal(t, 2900, pl.TotalDamage())
+}
+
+func TestPlayer_UtilityDamage(t *testing.T) {
+	pl := playerWithResourceProperty("m_iMatchStats_UtilityDamage_Total", st.PropertyValue{IntVal: 420})
+
+	assert.Equal(t, 420, pl.UtilityDamage())
+}
+
 func TestPlayer_SteamID32(t *testing.T) {
 	pl := &Player{SteamID64: 76561198012952267}