@@ -115,61 +115,45 @@ func (p *Parser) handleGameEvent(ge *msg.CSVCMsg_GameEvent) {
115115 case "weapon_fire" : // Weapon was fired
116116 data = mapGameEventData (d , ge )
117117
118- e := events. WeaponFiredEvent { Shooter : p .gameState .players [int (data ["userid" ].GetValShort ())]}
118+ shooter := p .gameState .players [int (data ["userid" ].GetValShort ())]
119119 wep := common .NewEquipment (data ["weapon" ].GetValString ())
120120
121- if e .Shooter != nil && wep .Class () != common .EqClassGrenade {
122- e .Weapon = e .Shooter .ActiveWeapon ()
123- } else {
124- e .Weapon = & wep
125- }
126-
127- p .eventDispatcher .Dispatch (e )
121+ p .eventDispatcher .Dispatch (events.WeaponFiredEvent {
122+ Shooter : shooter ,
123+ Weapon : getAttackingWeapon (& wep , shooter ),
124+ })
128125
129126 case "player_death" : // Player died
130127 data = mapGameEventData (d , ge )
131128
132- e := events.PlayerKilledEvent {
129+ killer := p .gameState .players [int (data ["attacker" ].GetValShort ())]
130+ wep := common .NewSkinEquipment (data ["weapon" ].GetValString (), data ["weapon_itemid" ].GetValString ())
131+
132+ p .eventDispatcher .Dispatch (events.PlayerKilledEvent {
133133 Victim : p .gameState .players [int (data ["userid" ].GetValShort ())],
134- Killer : p . gameState . players [ int ( data [ "attacker" ]. GetValShort ())] ,
134+ Killer : killer ,
135135 Assister : p .gameState .players [int (data ["assister" ].GetValShort ())],
136136 IsHeadshot : data ["headshot" ].GetValBool (),
137137 PenetratedObjects : int (data ["penetrated" ].GetValShort ()),
138- }
139-
140- wep := common .NewSkinEquipment (data ["weapon" ].GetValString (), data ["weapon_itemid" ].GetValString ())
141-
142- // FIXME: Should we do that last weapons > 0 check above as well?????
143- if e .Killer != nil && wep .Class () != common .EqClassGrenade && len (e .Killer .Weapons ) > 0 {
144- e .Weapon = e .Killer .ActiveWeapon ()
145- } else {
146- e .Weapon = & wep
147- }
148-
149- p .eventDispatcher .Dispatch (e )
138+ Weapon : getAttackingWeapon (& wep , killer ),
139+ })
150140
151141 case "player_hurt" : // Player got hurt
152142 data = mapGameEventData (d , ge )
153143
154- e := events.PlayerHurtEvent {
144+ attacker := p .gameState .players [int (data ["attacker" ].GetValShort ())]
145+ wep := common .NewEquipment (data ["weapon" ].GetValString ())
146+
147+ p .eventDispatcher .Dispatch (events.PlayerHurtEvent {
155148 Player : p .gameState .players [int (data ["userid" ].GetValShort ())],
156- Attacker : p . gameState . players [ int ( data [ " attacker" ]. GetValShort ())] ,
149+ Attacker : attacker ,
157150 Health : int (data ["health" ].GetValByte ()),
158151 Armor : int (data ["armor" ].GetValByte ()),
159152 HealthDamage : int (data ["dmg_health" ].GetValShort ()),
160153 ArmorDamage : int (data ["dmg_armor" ].GetValByte ()),
161154 HitGroup : common .HitGroup (data ["hitgroup" ].GetValByte ()),
162- }
163-
164- wep := common .NewEquipment (data ["weapon" ].GetValString ())
165-
166- if e .Attacker != nil && wep .Class () != common .EqClassGrenade && len (e .Attacker .Weapons ) > 0 {
167- e .Weapon = e .Attacker .ActiveWeapon ()
168- } else {
169- e .Weapon = & wep
170- }
171-
172- p .eventDispatcher .Dispatch (e )
155+ Weapon : getAttackingWeapon (& wep , attacker ),
156+ })
173157
174158 case "player_blind" : // Player got blinded by a flash
175159 data = mapGameEventData (d , ge )
@@ -438,6 +422,16 @@ func (p *Parser) handleGameEvent(ge *msg.CSVCMsg_GameEvent) {
438422 }
439423}
440424
425+ func getAttackingWeapon (wep * common.Equipment , attacker * common.Player ) * common.Equipment {
426+ class := wep .Class ()
427+ isSpecialWeapon := class == common .EqClassGrenade || (class == common .EqClassEquipment && wep .Weapon != common .EqKnife )
428+ if ! isSpecialWeapon && attacker != nil && len (attacker .Weapons ) > 0 {
429+ return attacker .ActiveWeapon ()
430+ } else {
431+ return wep
432+ }
433+ }
434+
441435func mapGameEventData (d * msg.CSVCMsg_GameEventListDescriptorT , e * msg.CSVCMsg_GameEvent ) map [string ]* msg.CSVCMsg_GameEventKeyT {
442436 data := make (map [string ]* msg.CSVCMsg_GameEventKeyT )
443437 for i , k := range d .Keys {
0 commit comments