Skip to content

Commit 40df288

Browse files
authored
events: add BombDefuseAborted event (#88)
1 parent 05b10c8 commit 40df288

File tree

5 files changed

+22
-1
lines changed

5 files changed

+22
-1
lines changed

common/player.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ type Player struct {
3333
Team Team
3434
IsBot bool
3535
IsDucking bool
36+
IsDefusing bool
3637
HasDefuseKit bool
3738
HasHelmet bool
3839
}

datatables.go

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -270,6 +270,14 @@ func (p *Parser) bindNewPlayer(playerEntity *st.Entity) {
270270
i2 := i // Copy so it stays the same
271271
playerEntity.BindProperty("m_iAmmo."+fmt.Sprintf("%03d", i2), &pl.AmmoLeft[i2], st.ValTypeInt)
272272
}
273+
274+
playerEntity.FindProperty("m_bIsDefusing").OnUpdate(func(val st.PropertyValue) {
275+
if p.gameState.currentDefuser == pl && pl.IsDefusing && val.IntVal == 0 {
276+
p.eventDispatcher.Dispatch(events.BombDefuseAborted{Player: pl})
277+
p.gameState.currentDefuser = nil
278+
}
279+
pl.IsDefusing = val.IntVal != 0
280+
})
273281
}
274282

275283
func (p *Parser) bindWeapons() {

events/events.go

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -283,6 +283,13 @@ type BombDefuseStart struct {
283283

284284
func (BombDefuseStart) implementsBombEventIf() {}
285285

286+
// BombDefuseAborted signals that the defuser aborted the action.
287+
type BombDefuseAborted struct {
288+
Player *common.Player
289+
}
290+
291+
func (BombDefuseAborted) implementsBombEventIf() {}
292+
286293
// BombDropped signals that the bomb (C4) has been dropped onto the ground.
287294
// Not fired if it has been dropped to another player (see BombPickup for this).
288295
type BombDropped struct {

game_events.go

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -331,15 +331,19 @@ func (p *Parser) handleGameEvent(ge *msg.CSVCMsg_GameEvent) {
331331
p.eventDispatcher.Dispatch(events.BombPlanted{BombEvent: e})
332332
case "bomb_defused":
333333
p.eventDispatcher.Dispatch(events.BombDefused{BombEvent: e})
334+
p.gameState.currentDefuser = nil
334335
case "bomb_exploded":
335336
p.eventDispatcher.Dispatch(events.BombExplode{BombEvent: e})
337+
p.gameState.currentDefuser = nil
336338
}
337339

338340
case "bomb_begindefuse": // Defuse started
339341
data = mapGameEventData(d, ge)
340342

343+
p.gameState.currentDefuser = p.gameState.playersByUserID[int(data["userid"].GetValShort())]
344+
341345
p.eventDispatcher.Dispatch(events.BombDefuseStart{
342-
Player: p.gameState.playersByUserID[int(data["userid"].GetValShort())],
346+
Player: p.gameState.currentDefuser,
343347
HasKit: data["haskit"].GetValBool(),
344348
})
345349

game_state.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ type GameState struct {
2424
isWarmupPeriod bool
2525
isMatchStarted bool
2626
lastFlasher *common.Player // Last player whose flash exploded, used to find the attacker for player_blind events
27+
currentDefuser *common.Player // Player currently defusing the bomb, if any
2728
}
2829

2930
type ingameTickNumber int

0 commit comments

Comments
 (0)