Skip to content

Commit a6c8bb9

Browse files
Julien2313markus-wa
authored andcommitted
event: add the real value of damage taken
(#244)
1 parent d80ff58 commit a6c8bb9

File tree

3 files changed

+50
-18
lines changed

3 files changed

+50
-18
lines changed

pkg/demoinfocs/events/events.go

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -359,15 +359,17 @@ const (
359359

360360
// PlayerHurt signals that a player has been damaged.
361361
type PlayerHurt struct {
362-
Player *common.Player // May be nil if the demo is partially corrupt (player is 'unconnected', see #156 and #172).
363-
Attacker *common.Player // May be nil if the player is taking world damage (e.g. fall damage) or if the demo is partially corrupt (player is 'unconnected', see #156 and #172).
364-
Health int
365-
Armor int
366-
Weapon *common.Equipment // May be EqUnknown for world-damage (falling / bomb).
367-
WeaponString string // Wrong for CZ, M4A1-S etc.
368-
HealthDamage int
369-
ArmorDamage int
370-
HitGroup HitGroup
362+
Player *common.Player // May be nil if the demo is partially corrupt (player is 'unconnected', see #156 and #172).
363+
Attacker *common.Player // May be nil if the player is taking world damage (e.g. fall damage) or if the demo is partially corrupt (player is 'unconnected', see #156 and #172).
364+
Health int
365+
Armor int
366+
Weapon *common.Equipment // May be EqUnknown for world-damage (falling / bomb).
367+
WeaponString string // Wrong for CZ, M4A1-S etc.
368+
HealthDamage int
369+
ArmorDamage int
370+
HealthDamageTaken int // HealthDamage excluding over-damage (e.g. if player has 5 health and is hit for 15 damage this would be 5 instead of 15)
371+
ArmorDamageTaken int // ArmorDamage excluding over-damage (e.g. if player has 5 armor and is hit for 15 armor damage this would be 5 instead of 15)
372+
HitGroup HitGroup
371373
}
372374

373375
// PlayerConnect signals that a player has started connecting.

pkg/demoinfocs/game_events.go

Lines changed: 39 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -340,20 +340,50 @@ func (geh gameEventHandler) playerDeath(data map[string]*msg.CSVCMsg_GameEventKe
340340
}
341341

342342
func (geh gameEventHandler) playerHurt(data map[string]*msg.CSVCMsg_GameEventKeyT) {
343+
userID := data["userid"].GetValShort()
344+
player := geh.playerByUserID32(userID)
343345
attacker := geh.playerByUserID32(data["attacker"].GetValShort())
346+
344347
wepType := common.MapEquipment(data["weapon"].GetValString())
345-
userID := data["userid"].GetValShort()
346348
wepType = geh.attackerWeaponType(wepType, userID)
347349

350+
health := int(data["health"].GetValByte())
351+
armor := int(data["armor"].GetValByte())
352+
353+
healthDamage := int(data["dmg_health"].GetValShort())
354+
armorDamage := int(data["dmg_armor"].GetValByte())
355+
healthDamageTaken := healthDamage
356+
armorDamageTaken := armorDamage
357+
358+
if healthDamageTaken > 100 {
359+
healthDamageTaken = 100
360+
}
361+
362+
if armorDamageTaken > 100 {
363+
armorDamageTaken = 100
364+
}
365+
366+
if player != nil {
367+
if health == 0 {
368+
healthDamageTaken = player.Health()
369+
}
370+
371+
if armor == 0 {
372+
armorDamageTaken = player.Armor()
373+
}
374+
}
375+
348376
geh.dispatch(events.PlayerHurt{
349-
Player: geh.playerByUserID32(userID),
350-
Attacker: attacker,
351-
Health: int(data["health"].GetValByte()),
352-
Armor: int(data["armor"].GetValByte()),
353-
HealthDamage: int(data["dmg_health"].GetValShort()),
354-
ArmorDamage: int(data["dmg_armor"].GetValByte()),
355-
HitGroup: events.HitGroup(data["hitgroup"].GetValByte()),
356-
Weapon: geh.getEquipmentInstance(attacker, wepType),
377+
Player: player,
378+
Attacker: attacker,
379+
Health: health,
380+
Armor: armor,
381+
HealthDamage: healthDamage,
382+
ArmorDamage: armorDamage,
383+
HealthDamageTaken: healthDamageTaken,
384+
ArmorDamageTaken: armorDamageTaken,
385+
HitGroup: events.HitGroup(data["hitgroup"].GetValByte()),
386+
Weapon: geh.getEquipmentInstance(attacker, wepType),
357387
})
358388
}
359389

test/default.golden

4.05 KB
Binary file not shown.

0 commit comments

Comments
 (0)