|
9 | 9 |
|
10 | 10 | // Player contains mostly game-relevant player information. |
11 | 11 | type Player struct { |
12 | | - tickRate float64 // the in-game tick rate, used for IsBlinded() |
13 | | - ingameTickProvider ingameTickProvider // provider for the current in-game tick, used for IsBlinded() |
| 12 | + demoInfoProvider demoInfoProvider // provider for demo info such as tick-rate or current tick |
14 | 13 |
|
15 | 14 | SteamID int64 // int64 representation of the User's Steam ID |
16 | 15 | Position r3.Vector // In-game coordinates. Like the one you get from cl_showpos 1 |
@@ -73,11 +72,12 @@ func (p *Player) flashDurationTimeFull() time.Duration { |
73 | 72 | func (p *Player) FlashDurationTimeRemaining() time.Duration { |
74 | 73 | // In case the demo header is broken |
75 | 74 | // TODO: read tickRate from CVARs as fallback |
76 | | - if p.tickRate == 0 { |
| 75 | + tickRate := p.demoInfoProvider.TickRate() |
| 76 | + if tickRate == 0 { |
77 | 77 | return time.Duration(p.FlashDuration) * time.Second |
78 | 78 | } |
79 | 79 |
|
80 | | - timeSinceFlash := time.Duration(float64(p.ingameTickProvider()-p.FlashTick) / p.tickRate * float64(time.Second)) |
| 80 | + timeSinceFlash := time.Duration(float64(p.demoInfoProvider.IngameTick()-p.FlashTick) / tickRate * float64(time.Second)) |
81 | 81 | remaining := p.flashDurationTimeFull() - timeSinceFlash |
82 | 82 | if remaining < 0 { |
83 | 83 | return 0 |
@@ -159,37 +159,43 @@ func (p *Player) IsScoped() bool { |
159 | 159 | } |
160 | 160 |
|
161 | 161 | // CashSpentThisRound returns the amount of cash the player spent in the current round. |
| 162 | +// |
| 163 | +// Deprecated, use Player.AdditionalPlayerInformation.CashSpentThisRound instead. |
162 | 164 | func (p *Player) CashSpentThisRound() int { |
163 | | - return p.Entity.FindPropertyI("m_iCashSpentThisRound").Value().IntVal |
| 165 | + return p.AdditionalPlayerInformation.CashSpentThisRound |
164 | 166 | } |
165 | 167 |
|
166 | 168 | // CashSpentTotal returns the amount of cash the player spent during the whole game up to the current point. |
| 169 | +// |
| 170 | +// Deprecated, use Player.AdditionalPlayerInformation.TotalCashSpent instead. |
167 | 171 | func (p *Player) CashSpentTotal() int { |
168 | | - return p.Entity.FindPropertyI("m_iTotalCashSpent").Value().IntVal |
| 172 | + return p.AdditionalPlayerInformation.TotalCashSpent |
169 | 173 | } |
170 | 174 |
|
171 | 175 | // AdditionalPlayerInformation contains mostly scoreboard information. |
172 | 176 | type AdditionalPlayerInformation struct { |
173 | | - Kills int |
174 | | - Deaths int |
175 | | - Assists int |
176 | | - Score int |
177 | | - MVPs int |
178 | | - Ping int |
179 | | - ClanTag string |
180 | | - TotalCashSpent int |
| 177 | + Kills int |
| 178 | + Deaths int |
| 179 | + Assists int |
| 180 | + Score int |
| 181 | + MVPs int |
| 182 | + Ping int |
| 183 | + ClanTag string |
| 184 | + TotalCashSpent int |
| 185 | + CashSpentThisRound int |
181 | 186 | } |
182 | 187 |
|
183 | | -// ingameTickProvider is a function that returns the current ingame tick of the demo related to a player. |
184 | | -type ingameTickProvider func() int |
| 188 | +type demoInfoProvider interface { |
| 189 | + IngameTick() int // current in-game tick, used for IsBlinded() |
| 190 | + TickRate() float64 // in-game tick rate, used for Player.IsBlinded() |
| 191 | +} |
185 | 192 |
|
186 | 193 | // NewPlayer creates a *Player with an initialized equipment map. |
187 | 194 | // |
188 | 195 | // Intended for internal use only. |
189 | | -func NewPlayer(tickRate float64, ingameTickProvider ingameTickProvider) *Player { |
| 196 | +func NewPlayer(demoInfoProvider demoInfoProvider) *Player { |
190 | 197 | return &Player{ |
191 | | - RawWeapons: make(map[int]*Equipment), |
192 | | - tickRate: tickRate, |
193 | | - ingameTickProvider: ingameTickProvider, |
| 198 | + RawWeapons: make(map[int]*Equipment), |
| 199 | + demoInfoProvider: demoInfoProvider, |
194 | 200 | } |
195 | 201 | } |
0 commit comments