5
5
"strings"
6
6
7
7
"github.com/golang/geo/r3"
8
+ "github.com/markus-wa/go-unassert"
8
9
9
10
"github.com/markus-wa/demoinfocs-golang/common"
10
11
"github.com/markus-wa/demoinfocs-golang/events"
@@ -24,36 +25,40 @@ const (
24
25
25
26
func (p * Parser ) mapEquipment () {
26
27
for _ , sc := range p .stParser .ServerClasses () {
28
+ switch sc .Name () {
29
+ case "CC4" :
30
+ p .equipmentMapping [sc ] = common .EqBomb
31
+ continue
32
+
33
+ case "CWeaponNOVA" :
34
+ fallthrough
35
+ case "CWeaponSawedoff" :
36
+ fallthrough
37
+ case "CWeaponXM1014" :
38
+ p .equipmentMapping [sc ] = common .MapEquipment (strings .ToLower (sc .Name ()[7 :]))
39
+ continue
40
+ }
41
+
27
42
baseClasses := sc .BaseClasses ()
28
43
for _ , bc := range baseClasses {
29
44
if bc .Name () == "CBaseGrenade" { // Grenades projectiles, i.e. thrown by player
30
45
p .equipmentMapping [sc ] = common .MapEquipment (strings .ToLower (sc .DataTableName ()[3 :]))
46
+ break
31
47
}
32
- }
33
48
34
- if len (baseClasses ) > 6 && baseClasses [6 ].Name () == "CWeaponCSBase" {
35
- if len (baseClasses ) > 7 {
36
- switch baseClasses [7 ].Name () {
37
- case "CWeaponCSBaseGun" :
38
- // Most guns
39
- p .equipmentMapping [sc ] = common .MapEquipment (strings .ToLower (sc .DataTableName ()[9 :]))
40
- case "CBaseCSGrenade" :
41
- // Nades
42
- p .equipmentMapping [sc ] = common .MapEquipment (strings .ToLower (sc .DataTableName ()[3 :]))
43
- }
44
- } else if sc .Name () == "CKnife" || (len (baseClasses ) > 6 && baseClasses [6 ].Name () == "CKnife" ) {
49
+ if bc .Name () == "CKnife" {
45
50
p .equipmentMapping [sc ] = common .EqKnife
46
- } else {
47
- switch sc . Name () {
48
- case "CC4" :
49
- p . equipmentMapping [ sc ] = common . EqBomb
50
- case "CWeaponNOVA" :
51
- fallthrough
52
- case "CWeaponSawedoff" :
53
- fallthrough
54
- case "CWeaponXM1014" :
55
- p .equipmentMapping [sc ] = common .MapEquipment (strings .ToLower (sc .Name ()[7 :]))
56
- }
51
+ break
52
+ }
53
+
54
+ if bc . Name () == "CWeaponCSBaseGun" { // most guns
55
+ p . equipmentMapping [ sc ] = common . MapEquipment ( strings . ToLower ( sc . DataTableName ()[ 9 :]))
56
+ break
57
+ }
58
+
59
+ if bc . Name () == "CBaseCSGrenade" { // nades
60
+ p .equipmentMapping [sc ] = common .MapEquipment (strings .ToLower (sc .DataTableName ()[3 :]))
61
+ break
57
62
}
58
63
}
59
64
}
@@ -375,7 +380,17 @@ func (p *Parser) bindGrenadeProjectiles(entity *st.Entity) {
375
380
proj .EntityID = entityID
376
381
p .gameState .grenadeProjectiles [entityID ] = proj
377
382
383
+ var wep common.EquipmentElement
378
384
entity .OnCreateFinished (func () {
385
+ // copy the weapon so it doesn't get overwritten by a new entity in Parser.weapons
386
+ wepCopy := * (getPlayerWeapon (proj .Thrower , wep ))
387
+ proj .WeaponInstance = & wepCopy
388
+
389
+ unassert .NotNilf (proj .WeaponInstance , "couldn't find grenade instance for player" )
390
+ if proj .WeaponInstance != nil {
391
+ unassert .NotNilf (proj .WeaponInstance .Owner , "getPlayerWeapon() returned weapon instance with Owner=nil" )
392
+ }
393
+
379
394
p .gameEventHandler .addThrownGrenade (proj .Thrower , proj .WeaponInstance )
380
395
381
396
p .eventDispatcher .Dispatch (events.GrenadeProjectileThrow {
@@ -389,9 +404,7 @@ func (p *Parser) bindGrenadeProjectiles(entity *st.Entity) {
389
404
390
405
entity .FindPropertyI ("m_nModelIndex" ).OnUpdate (func (val st.PropertyValue ) {
391
406
proj .Weapon = p .grenadeModelIndices [val .IntVal ]
392
-
393
- equipment := common .NewEquipment (p .grenadeModelIndices [val .IntVal ])
394
- proj .WeaponInstance = & equipment
407
+ wep = p .grenadeModelIndices [val .IntVal ]
395
408
})
396
409
397
410
// @micvbang: not quite sure what the difference between Thrower and Owner is.
0 commit comments