From 79155fc5f85e212dfe1873935e88e47ba971747a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lars=20K=C3=B6lpin?= Date: Sun, 31 May 2020 22:30:00 +0200 Subject: [PATCH] feat(grenades): Add grenade events to json (#33) --- events.go | 59 ++++ events.md | 91 ++++++ examples/minimal.json | 505 +++++++++++++++++++++++--------- examples/minimal.mp | Bin 5058 -> 6328 bytes examples/minimal.pb | Bin 1988 -> 2588 bytes protobuf/gen/proto/replay.proto | 11 +- protobuf/gen/replay.pb.go | 103 ++++--- protobuf/protobuf.go | 9 + replay/replay.go | 49 ++-- 9 files changed, 626 insertions(+), 201 deletions(-) diff --git a/events.go b/events.go index fcf43d3..59650af 100644 --- a/events.go +++ b/events.go @@ -65,6 +65,7 @@ func (defaultEventHandlers) RegisterAll(ec *EventCollector) { EventHandlers.Default.RegisterPlayerDisconnect(ec) EventHandlers.Default.RegisterWeaponFired(ec) EventHandlers.Default.RegisterChatMessage(ec) + EventHandlers.Default.RegisterGrenadeEvents(ec) } func (defaultEventHandlers) RegisterMatchStarted(ec *EventCollector) { @@ -175,6 +176,49 @@ func (defaultEventHandlers) RegisterChatMessage(ec *EventCollector) { }) } +func (defaultEventHandlers) RegisterGrenadeEvents(ec *EventCollector) { + ec.AddHandler(func(smokeStartEvent events.SmokeStart) { + eb := withGrenadePosition(buildEvent(rep.EventSmokeStart), smokeStartEvent) + eb.intAttr(rep.AttrKindThrowerID, smokeStartEvent.Thrower.EntityID) + ec.AddEvent(eb.build()) + }) + ec.AddHandler(func(smokeExpired events.SmokeExpired) { + eb := withGrenadePosition(buildEvent(rep.EventSmokeExpired), smokeExpired) + eb.intAttr(rep.AttrKindThrowerID, smokeExpired.Thrower.EntityID) + ec.AddEvent(eb.build()) + }) + ec.AddHandler(func(decoyStart events.DecoyStart) { + eb := withGrenadePosition(buildEvent(rep.EventDecoyStart), decoyStart) + eb.intAttr(rep.AttrKindThrowerID, decoyStart.Thrower.EntityID) + ec.AddEvent(eb.build()) + }) + ec.AddHandler(func(decoyExpired events.DecoyExpired) { + eb := withGrenadePosition(buildEvent(rep.EventDecoyExpired), decoyExpired) + eb.intAttr(rep.AttrKindThrowerID, decoyExpired.Thrower.EntityID) + ec.AddEvent(eb.build()) + }) + ec.AddHandler(func(fireStart events.FireGrenadeStart) { + eb := withGrenadePosition(buildEvent(rep.EventFireGrenadeStart), fireStart) + // Adding a AttrKindThrowerID throws a Nil Reference + ec.AddEvent(eb.build()) + }) + ec.AddHandler(func(fireExpired events.FireGrenadeExpired) { + eb := withGrenadePosition(buildEvent(rep.EventFireGrenadeExpired), fireExpired) + // Adding a AttrKindThrowerID throws a Nil Reference + ec.AddEvent(eb.build()) + }) + ec.AddHandler(func(heEvent events.HeExplode) { + eb := withGrenadePosition(buildEvent(rep.EventHEGrenadeExplosion), heEvent) + eb.intAttr(rep.AttrKindThrowerID, heEvent.Thrower.EntityID) + ec.AddEvent(eb.build()) + }) + ec.AddHandler(func(flashExplode events.FlashExplode) { + eb := withGrenadePosition(buildEvent(rep.EventFlashExplosion), flashExplode) + eb.intAttr(rep.AttrKindThrowerID, flashExplode.Thrower.EntityID) + ec.AddEvent(eb.build()) + }) +} + type extraEventHandlers struct{} func (extraEventHandlers) RegisterAll(ec *EventCollector) { @@ -207,6 +251,13 @@ func (b *eventBuilder) intAttr(key string, value int) *eventBuilder { return b } +func (b *eventBuilder) floatAttr(key string, value float64) { + b.event.Attributes = append(b.event.Attributes, rep.EventAttribute{ + Key: key, + NumVal: value, + }) +} + func (b eventBuilder) build() rep.Event { return b.event } @@ -226,3 +277,11 @@ func createEvent(eventName string) rep.Event { func createEntityEvent(eventName string, entityID int) rep.Event { return buildEvent(eventName).intAttr(rep.AttrKindEntityID, entityID).build() } + +func withGrenadePosition(eb *eventBuilder, e events.GrenadeEventIf) *eventBuilder { + eb.floatAttr("x", e.Base().Position.X) + eb.floatAttr("y", e.Base().Position.Y) + eb.floatAttr("z", e.Base().Position.Z) + + return eb +} diff --git a/events.md b/events.md index 647519d..5941baa 100644 --- a/events.md +++ b/events.md @@ -11,6 +11,14 @@ - [`disconnect`](#disconnect) - [`round_started`](#round_started) - [`round_ended`](#round_ended) +- [`smoke_started`](#smoke_started) +- [`smoke_expired`](#smoke_expired) +- [`decoy_started`](#decoy_started) +- [`decoy_expired`](#decoy_expired) +- [`fire_grenade_started`](#fire_grenade_started) +- [`fire_grenade_expired`](#fire_grenade_expired) +- [`he_grenade_explosion`](#he_grenade_explosion) +- [`flash_explosion`](#flash_explosion) ## Attributes @@ -84,3 +92,86 @@ | --- | --- | --- | | `winner` | `numVal` | see [`Team`](https://pkg.go.dev/github.com/markus-wa/demoinfocs-golang/v2/pkg/demoinfocs/common?tab=doc#Team) | | `reason` | `numVal` | see [`RoundEndReason`](https://pkg.go.dev/github.com/markus-wa/demoinfocs-golang/v2/pkg/demoinfocs/events?tab=doc#RoundEndReason) | + +### `smoke_started` + +| attribute | type | description | +| --- | --- | --- | +| `x` | `numVal` | The x-coordinate used in the CS:GO space | +| `y` | `numVal` | The y-coordinate used in the CS:GO space | +| `z` | `numVal` | The z-coordinate used in the CS:GO space | +| `throwerEntityId` | `numVal` | The entityId of the throwing player | + +### `smoke_expired` + +| attribute | type | description | +| --- | --- | --- | +| `x` | `numVal` | The x-coordinate used in the CS:GO space | +| `y` | `numVal` | The y-coordinate used in the CS:GO space | +| `z` | `numVal` | The z-coordinate used in the CS:GO space | +| `throwerEntityId` | `numVal` | The entityId of the throwing player | + + +### `decoy_started` + +| attribute | type | description | +| --- | --- | --- | +| `x` | `numVal` | The x-coordinate used in the CS:GO space | +| `y` | `numVal` | The y-coordinate used in the CS:GO space | +| `z` | `numVal` | The z-coordinate used in the CS:GO space | +| `throwerEntityId` | `numVal` | The entityId of the throwing player | + + +### `decoy_expired` + +| attribute | type | description | +| --- | --- | --- | +| `x` | `numVal` | The x-coordinate used in the CS:GO space | +| `y` | `numVal` | The y-coordinate used in the CS:GO space | +| `z` | `numVal` | The z-coordinate used in the CS:GO space | +| `throwerEntityId` | `numVal` | The entityId of the throwing player | + +### `fire_grenade_started` + +| attribute | type | description | +| --- | --- | --- | +| `x` | `numVal` | The x-coordinate used in the CS:GO space | +| `y` | `numVal` | The y-coordinate used in the CS:GO space | +| `z` | `numVal` | The z-coordinate used in the CS:GO space | + +### `fire_grenade_expired` + +| attribute | type | description | +| --- | --- | --- | +| `x` | `numVal` | The x-coordinate used in the CS:GO space | +| `y` | `numVal` | The y-coordinate used in the CS:GO space | +| `z` | `numVal` | The z-coordinate used in the CS:GO space | + + +### `fire_grenade_expired` + +| attribute | type | description | +| --- | --- | --- | +| `x` | `numVal` | The x-coordinate used in the CS:GO space | +| `y` | `numVal` | The y-coordinate used in the CS:GO space | +| `z` | `numVal` | The z-coordinate used in the CS:GO space | + + +### `he_grenade_explosion` + +| attribute | type | description | +| --- | --- | --- | +| `x` | `numVal` | The x-coordinate used in the CS:GO space | +| `y` | `numVal` | The y-coordinate used in the CS:GO space | +| `z` | `numVal` | The z-coordinate used in the CS:GO space | +| `throwerEntityId` | `numVal` | The entityId of the throwing player | + +### `flash_explosion` + +| attribute | type | description | +| --- | --- | --- | +| `x` | `numVal` | The x-coordinate used in the CS:GO space | +| `y` | `numVal` | The y-coordinate used in the CS:GO space | +| `z` | `numVal` | The z-coordinate used in the CS:GO space | +| `throwerEntityId` | `numVal` | The entityId of the throwing player | + diff --git a/examples/minimal.json b/examples/minimal.json index 0332dd6..01f21fc 100644 --- a/examples/minimal.json +++ b/examples/minimal.json @@ -6,48 +6,49 @@ }, "entities": [ { - "id": 8, - "name": "eswc.com | Samy", - "team": 1 - }, - { - "id": 9, - "name": "crisby", - "team": 3 + "id": 5, + "name": "ALEX * Intel", + "team": 2 }, { - "id": 11, - "name": "mistou * Cooler Master", + "id": 7, + "name": "Ex6TenZ-BALLISTIX", "team": 2 }, { - "id": 12, - "name": "Ptikrazy", + "id": 8, + "name": "eswc.com | Samy", "team": 1 }, { - "id": 13, - "name": "keev", + "id": 10, + "name": "syrsoNR", "team": 3 }, { - "id": 3, - "name": "to1nou * Seagate", - "team": 2 + "id": 1, + "name": "ESWC TV - By VeryGames.net", + "team": 0, + "isNpc": true }, { - "id": 5, - "name": "ALEX * Intel", + "id": 2, + "name": "xms*ASUS ♥ /F/", "team": 2 }, { - "id": 7, - "name": "Ex6TenZ-BALLISTIX", + "id": 3, + "name": "to1nou * Seagate", "team": 2 }, { - "id": 10, - "name": "syrsoNR", + "id": 4, + "name": "tiziaN", + "team": 3 + }, + { + "id": 13, + "name": "keev", "team": 3 }, { @@ -56,20 +57,19 @@ "team": 3 }, { - "id": 1, - "name": "ESWC TV - By VeryGames.net", - "team": 0, - "isNpc": true + "id": 9, + "name": "crisby", + "team": 3 }, { - "id": 2, - "name": "xms*ASUS ♥ /F/", + "id": 11, + "name": "mistou * Cooler Master", "team": 2 }, { - "id": 4, - "name": "tiziaN", - "team": 3 + "id": 12, + "name": "Ptikrazy", + "team": 1 }, { "id": 6, @@ -81,59 +81,6 @@ { "tick": 51, "entityUpdates": [ - { - "entityId": 13, - "positions": [ - { - "x": -1572, - "y": 722, - "z": 1614 - } - ], - "angleX": 270, - "angleY": 359, - "hp": 100 - }, - { - "entityId": 2, - "positions": [ - { - "x": 513, - "y": -85, - "z": 1744 - } - ], - "angleX": 170, - "angleY": 4, - "hp": 24, - "armor": 83, - "hasHelmet": true - }, - { - "entityId": 4, - "positions": [ - { - "x": -817, - "y": -451, - "z": 1614 - } - ], - "angleX": 92, - "angleY": 12, - "hp": 97 - }, - { - "entityId": 10, - "positions": [ - { - "x": -1382, - "y": 815, - "z": 1614 - } - ], - "angleX": 270, - "hp": 100 - }, { "entityId": 5, "positions": [ @@ -161,6 +108,19 @@ "angleX": 182, "hp": 100 }, + { + "entityId": 13, + "positions": [ + { + "x": -1572, + "y": 722, + "z": 1614 + } + ], + "angleX": 270, + "angleY": 359, + "hp": 100 + }, { "entityId": 14, "positions": [ @@ -191,6 +151,21 @@ "armor": 98, "hasHelmet": true }, + { + "entityId": 2, + "positions": [ + { + "x": 513, + "y": -85, + "z": 1744 + } + ], + "angleX": 170, + "angleY": 4, + "hp": 24, + "armor": 83, + "hasHelmet": true + }, { "entityId": 3, "positions": [ @@ -205,66 +180,62 @@ "hp": 100, "armor": 100, "hasHelmet": true - } - ] - }, - { - "tick": 102, - "entityUpdates": [ + }, { - "entityId": 7, + "entityId": 4, "positions": [ { - "x": 2973, - "y": 250, - "z": 1613 + "x": -817, + "y": -451, + "z": 1614 } ], - "angleX": 182, - "hp": 100 + "angleX": 92, + "angleY": 12, + "hp": 97 }, { - "entityId": 11, + "entityId": 10, "positions": [ { - "x": 112, - "y": -366, + "x": -1382, + "y": 815, "z": 1614 } ], - "angleX": 201, - "angleY": 1, - "hp": 16, - "armor": 98, - "hasHelmet": true - }, + "angleX": 270, + "hp": 100 + } + ] + }, + { + "tick": 102, + "entityUpdates": [ { - "entityId": 14, + "entityId": 10, "positions": [ { - "x": -825, - "y": 606, - "z": 1636 + "x": -1382, + "y": 815, + "z": 1614 } ], - "angleX": 86, - "angleY": 8, - "hp": 8, - "armor": 86, - "hasHelmet": true + "angleX": 270, + "hp": 100 }, { - "entityId": 13, + "entityId": 3, "positions": [ { - "x": -1572, - "y": 722, - "z": 1614 + "x": 374, + "y": 167, + "z": 1613 } ], - "angleX": 270, - "angleY": 359, - "hp": 100 + "angleX": 150, + "hp": 100, + "armor": 100, + "hasHelmet": true }, { "entityId": 4, @@ -280,43 +251,44 @@ "hp": 97 }, { - "entityId": 10, + "entityId": 5, "positions": [ { - "x": -1382, - "y": 815, - "z": 1614 + "x": -29, + "y": 368, + "z": 1613 } ], - "angleX": 270, - "hp": 100 + "angleX": 101, + "angleY": 353, + "hp": 11, + "armor": 86, + "hasHelmet": true }, { - "entityId": 3, + "entityId": 7, "positions": [ { - "x": 374, - "y": 167, + "x": 2973, + "y": 250, "z": 1613 } ], - "angleX": 150, - "hp": 100, - "armor": 100, - "hasHelmet": true + "angleX": 182, + "hp": 100 }, { - "entityId": 5, + "entityId": 14, "positions": [ { - "x": -29, - "y": 368, - "z": 1613 + "x": -825, + "y": 606, + "z": 1636 } ], - "angleX": 101, - "angleY": 353, - "hp": 11, + "angleX": 86, + "angleY": 8, + "hp": 8, "armor": 86, "hasHelmet": true }, @@ -333,6 +305,21 @@ "angleY": 2, "hp": 100 }, + { + "entityId": 11, + "positions": [ + { + "x": 112, + "y": -366, + "z": 1614 + } + ], + "angleX": 201, + "angleY": 1, + "hp": 16, + "armor": 98, + "hasHelmet": true + }, { "entityId": 2, "positions": [ @@ -347,6 +334,19 @@ "hp": 24, "armor": 83, "hasHelmet": true + }, + { + "entityId": 13, + "positions": [ + { + "x": -1572, + "y": 722, + "z": 1614 + } + ], + "angleX": 270, + "angleY": 359, + "hp": 100 } ] } @@ -507,6 +507,84 @@ } ] }, + { + "nr": 903, + "events": [ + { + "name": "decoy_started", + "attrs": [ + { + "key": "x", + "numVal": -261.5856628417969 + }, + { + "key": "y", + "numVal": 1296.1536865234375 + }, + { + "key": "z", + "numVal": 1689.03125 + }, + { + "key": "throwerEntityId", + "numVal": 14 + } + ] + } + ] + }, + { + "nr": 1312, + "events": [ + { + "name": "decoy_expired", + "attrs": [ + { + "key": "x", + "numVal": -261.5856628417969 + }, + { + "key": "y", + "numVal": 1296.1536865234375 + }, + { + "key": "z", + "numVal": 1689.03125 + }, + { + "key": "throwerEntityId", + "numVal": 14 + } + ] + } + ] + }, + { + "nr": 2480, + "events": [ + { + "name": "smoke_started", + "attrs": [ + { + "key": "x", + "numVal": 943.7857055664062 + }, + { + "key": "y", + "numVal": -716.610107421875 + }, + { + "key": "z", + "numVal": 1616.003173828125 + }, + { + "key": "throwerEntityId", + "numVal": 13 + } + ] + } + ] + }, { "nr": 2516, "events": [ @@ -560,9 +638,152 @@ } ] }, + { + "nr": 3249, + "events": [ + { + "name": "fire_grenade_started", + "attrs": [ + { + "key": "x", + "numVal": 933.8363647460938 + }, + { + "key": "y", + "numVal": 658.8897705078125 + }, + { + "key": "z", + "numVal": 1834.861328125 + } + ] + } + ] + }, + { + "nr": 3342, + "events": [ + { + "name": "he_grenade_explosion", + "attrs": [ + { + "key": "x", + "numVal": 786.9524536132812 + }, + { + "key": "y", + "numVal": -961.5076293945312 + }, + { + "key": "z", + "numVal": 1666.120361328125 + }, + { + "key": "throwerEntityId", + "numVal": 13 + } + ] + } + ] + }, + { + "nr": 3428, + "events": [ + { + "name": "fire_grenade_expired", + "attrs": [ + { + "key": "x", + "numVal": 933.8363647460938 + }, + { + "key": "y", + "numVal": 658.8897705078125 + }, + { + "key": "z", + "numVal": 1834.861328125 + } + ] + } + ] + }, + { + "nr": 3622, + "events": [ + { + "name": "smoke_expired", + "attrs": [ + { + "key": "x", + "numVal": 920.5975341796875 + }, + { + "key": "y", + "numVal": 269.741943359375 + }, + { + "key": "z", + "numVal": 1616.0150146484375 + }, + { + "key": "throwerEntityId", + "numVal": 9 + } + ] + } + ] + }, + { + "nr": 3916, + "events": [ + { + "name": "flash_explosion", + "attrs": [ + { + "key": "x", + "numVal": 146.4983367919922 + }, + { + "key": "y", + "numVal": -703.4071044921875 + }, + { + "key": "z", + "numVal": 1666.1900634765625 + }, + { + "key": "throwerEntityId", + "numVal": 13 + } + ] + } + ] + }, { "nr": 4565, "events": [ + { + "name": "flash_explosion", + "attrs": [ + { + "key": "x", + "numVal": -67.47831726074219 + }, + { + "key": "y", + "numVal": 326.1033020019531 + }, + { + "key": "z", + "numVal": 1772.932861328125 + }, + { + "key": "throwerEntityId", + "numVal": 7 + } + ] + }, { "name": "flashed", "attrs": [ diff --git a/examples/minimal.mp b/examples/minimal.mp index abc45180bb43074c4dcc43cf23ca4be91b212c7e..b2d36f6224179e3c9be1901c088f47dbe920c169 100644 GIT binary patch delta 1351 zcmX@4zQb^W%fyfN6I~Q08!(DYj$;g;ctLUURz`7d-X(d7xv5LCQ&Y<(+c7FkOo*O* zhS7F1BXh%KP9~4Z-OMv5A7>MooXBJ}`8NyKWEB>d$&;D#CTFlHOg_$<2V_f6Ucf2~ zR4+N%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