Skip to content
This repository has been archived by the owner on Jan 22, 2024. It is now read-only.

Commit

Permalink
feat(grenades): Add grenade events to json (#33)
Browse files Browse the repository at this point in the history
  • Loading branch information
LarsKoelpin authored May 31, 2020
1 parent ab7e72a commit 79155fc
Show file tree
Hide file tree
Showing 9 changed files with 626 additions and 201 deletions.
59 changes: 59 additions & 0 deletions events.go
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -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) {
Expand Down Expand Up @@ -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
}
Expand All @@ -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
}
91 changes: 91 additions & 0 deletions events.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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 |

Loading

0 comments on commit 79155fc

Please sign in to comment.