Skip to content

Commit 359e3d6

Browse files
committed
Add caused fouls to multiple fouls event
1 parent fc9463c commit 359e3d6

File tree

1 file changed

+11
-4
lines changed

1 file changed

+11
-4
lines changed

internal/app/statemachine/change_gameevent.go

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -40,8 +40,14 @@ func (s *StateMachine) processChangeAddGameEvent(newState *state.State, change *
4040
if byTeam == state.Team_UNKNOWN || byTeam == team {
4141
log.Printf("Team %v got a foul for %v", byTeam, gameEvent)
4242
newState.TeamInfo(team).AddFoul(gameEvent)
43-
if len(newState.TeamInfo(team).Fouls)%3 == 0 {
44-
changes = append(changes, s.multipleFoulsChange(team))
43+
numFouls := len(newState.TeamInfo(team).Fouls)
44+
if numFouls%3 == 0 {
45+
var causedGameEvents []*state.GameEvent
46+
for i := numFouls - 3; i < numFouls; i++ {
47+
causedGameEvents = append(causedGameEvents, newState.TeamInfo(team).Fouls[i].CausedByGameEvent)
48+
}
49+
50+
changes = append(changes, s.multipleFoulsChange(team, causedGameEvents))
4551
}
4652
}
4753
}
@@ -284,11 +290,12 @@ func (s *StateMachine) isGoalValid(newState *state.State, gameEvent *state.GameE
284290
}
285291

286292
// multipleFoulsChange creates a multiple fouls event change
287-
func (s *StateMachine) multipleFoulsChange(byTeam state.Team) *Change {
293+
func (s *StateMachine) multipleFoulsChange(byTeam state.Team, events []*state.GameEvent) *Change {
288294
return createGameEventChange(state.GameEvent_MULTIPLE_FOULS, state.GameEvent{
289295
Event: &state.GameEvent_MultipleFouls_{
290296
MultipleFouls: &state.GameEvent_MultipleFouls{
291-
ByTeam: &byTeam,
297+
ByTeam: &byTeam,
298+
CausedGameEvents: events,
292299
},
293300
},
294301
},

0 commit comments

Comments
 (0)