diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..11b8e7b --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +/cmd/server/server diff --git a/cmd/server/games.go b/cmd/server/games.go index 3e0b66b..1988379 100644 --- a/cmd/server/games.go +++ b/cmd/server/games.go @@ -6,6 +6,7 @@ import ( "encoding/json" "fmt" "io" + "slices" "time" ) @@ -100,6 +101,7 @@ type ( EventAssignmentRotation struct { Killer string Killed string + KillWord string Assignments map[string]Assignment } ) @@ -155,10 +157,22 @@ func (games Games) GameState(ctx context.Context, id string) (GameState, error) if err := json.Unmarshal(payload, &assignmentRotation); err != nil { return err } + + if killer, ok := result.Players[assignmentRotation.Killer]; !ok { + } else if victim, ok := result.Players[assignmentRotation.Killed]; !ok { + } else { + killer.Kills = append(killer.Kills, Kill{ + Timestamp: timestamp, + Victim: assignmentRotation.Killed, + Public: slices.Contains(victim.KillWords.Assignment.Public, assignmentRotation.KillWord), + }) + result.Players[assignmentRotation.Killer] = killer + } + // TODO gather current assignees // TODO get victim's target // TODO assign victim's target to killer - // TODO randomize everyone else so not the same as before + // TODO randomize everyone else so not the same as before AND not self return fmt.Errorf("not impl: assignment rotation: %+v", assignmentRotation) default: return fmt.Errorf("unknown event type %d: %s", peek.Type, payload)