Skip to content

Commit 88ba5b8

Browse files
authored
Merge pull request #150 from markus-wa/issue/148-PlayerHurt-incorrect-alternate-weapons
fix PlayerHurt.Weapon (and other events) not working for alternate weapons
2 parents 51057b9 + ebff34b commit 88ba5b8

File tree

4 files changed

+31
-1
lines changed

4 files changed

+31
-1
lines changed

common/equipment.go

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -327,3 +327,20 @@ func (e Equipment) AmmoReserve2() int {
327327
func NewEquipment(wep EquipmentElement) Equipment {
328328
return Equipment{Weapon: wep, uniqueID: rand.Int63()}
329329
}
330+
331+
var equipmentToAlternative = map[EquipmentElement]EquipmentElement{
332+
EqP2000: EqUSP,
333+
EqP250: EqCZ, // for old demos where the CZ was the alternative for the P250
334+
EqFiveSeven: EqCZ,
335+
EqTec9: EqCZ,
336+
EqDeagle: EqRevolver,
337+
EqMP7: EqMP5,
338+
EqM4A4: EqM4A1,
339+
}
340+
341+
// EquipmentAlternative returns the EquipmentElement of the alternatively equippable weapon.
342+
// E.g. returns EquipmentAlternative(EqP2000) returns EqUSP.
343+
// Only works one way (default-to-alternative) as the Five-Seven and Tec-9 both map to the CZ-75.
344+
func EquipmentAlternative(eq EquipmentElement) EquipmentElement {
345+
return equipmentToAlternative[eq]
346+
}

common/equipment_test.go

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,3 +78,13 @@ func TestEquipment_AmmoReserve2_Grenade_OwnerNil(t *testing.T) {
7878

7979
assert.Equal(t, 0, wep.AmmoReserve2())
8080
}
81+
82+
func TestEquipmentAlternative(t *testing.T) {
83+
assert.Equal(t, EqUSP, EquipmentAlternative(EqP2000))
84+
assert.Equal(t, EqCZ, EquipmentAlternative(EqP250))
85+
assert.Equal(t, EqCZ, EquipmentAlternative(EqFiveSeven))
86+
assert.Equal(t, EqCZ, EquipmentAlternative(EqTec9))
87+
assert.Equal(t, EqRevolver, EquipmentAlternative(EqDeagle))
88+
assert.Equal(t, EqMP5, EquipmentAlternative(EqMP7))
89+
assert.Equal(t, EqM4A1, EquipmentAlternative(EqM4A4))
90+
}

datatables.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -461,6 +461,8 @@ func (p *Parser) bindWeapon(entity *st.Entity, wepType common.EquipmentElement)
461461
wepFix("_pist_p250", "_pist_cz_75", common.EqCZ)
462462
case common.EqDeagle:
463463
wepFix("_pist_deagle", "_pist_revolver", common.EqRevolver)
464+
case common.EqMP7:
465+
wepFix("_smg_mp7", "_smg_mp5sd", common.EqMP5)
464466
}
465467
}
466468

game_events.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -546,8 +546,9 @@ func mapGameEventData(d *msg.CSVCMsg_GameEventListDescriptorT, e *msg.CSVCMsg_Ga
546546
// Returns the players instance of the weapon if applicable or a new instance otherwise.
547547
func getPlayerWeapon(player *common.Player, wepType common.EquipmentElement) *common.Equipment {
548548
if player != nil {
549+
alternateWepType := common.EquipmentAlternative(wepType)
549550
for _, wep := range player.Weapons() {
550-
if wep.Weapon == wepType {
551+
if wep.Weapon == wepType || wep.Weapon == alternateWepType {
551552
return wep
552553
}
553554
}

0 commit comments

Comments
 (0)