From 603bab601d89604a16c2353a33b5f2a55bd22063 Mon Sep 17 00:00:00 2001 From: Hamcha Date: Mon, 26 Aug 2019 11:18:14 +0200 Subject: [PATCH] Add global message for picks --- draftbot/draftbot_test.go | 9 +++++---- draftbot/session.go | 10 +++++++++- 2 files changed, 14 insertions(+), 5 deletions(-) diff --git a/draftbot/draftbot_test.go b/draftbot/draftbot_test.go index d68105c..3962e80 100644 --- a/draftbot/draftbot_test.go +++ b/draftbot/draftbot_test.go @@ -102,10 +102,11 @@ func TestDraftSession(t *testing.T) { for packi := 0; packi < 4; packi++ { mock.expect("draft-newpack") for cardi := 0; cardi < 12; cardi++ { + mock.expect("draft-newpick") // Get packs - msg1 := mock.expect("draft-newpick") + msg1 := mock.expect("draft-availablepicks") pack1 := msg1.Data.(draft.Pack) - msg2 := mock.expect("draft-newpick") + msg2 := mock.expect("draft-availablepicks") pack2 := msg2.Data.(draft.Pack) // Pick first card in each pack mock.message(msg1.To, "pick", pack1[0].ID) @@ -210,7 +211,7 @@ func TestDraftSessionButEverythingGoesWrong(t *testing.T) { // Try to make someone join a session that already started mock.message("test-owner", "start", nil) - mock.multiexpect("session-start", "draft-order", "draft-newpack", "draft-newpick", "draft-newpick") + mock.multiexpect("session-start", "draft-order", "draft-newpack", "draft-newpick", "draft-availablepicks", "draft-availablepicks") mock.message("c", "join", nil) mock.expect("session-already-started") @@ -329,7 +330,7 @@ func TestDraftPositioning(t *testing.T) { // Start the session mock.message("test-owner", "start", nil) - mock.multiexpect("session-start", "draft-order", "draft-newpack", "draft-newpick", "draft-newpick") + mock.multiexpect("session-start", "draft-order", "draft-newpack", "draft-newpick", "draft-availablepicks", "draft-availablepicks") } makeSession("even", draftbot.PosEven) diff --git a/draftbot/session.go b/draftbot/session.go index cd8c04c..2b3dc94 100644 --- a/draftbot/session.go +++ b/draftbot/session.go @@ -222,19 +222,27 @@ func (s *session) handlePicks() { s.messages <- room.Message{ Channel: "draft", Type: "draft-newpack", + Data: []int{currentPack, totalPacks}, Message: fmt.Sprintf("Opening pack %d (of %d)", currentPack, totalPacks), } // Pick loop, this `for` handles exactly one round of packs for { + s.messages <- room.Message{ + To: "draft", + Type: "draft-newpick", + Message: fmt.Sprintf("New pick for pack #%d", currentPack), + } + // Make bots pick their cards for _, bot := range s.Bots { bot.PickNext() } + // Tell every players their new cards for pname, player := range s.Players { s.messages <- room.Message{ To: pname, - Type: "draft-newpick", + Type: "draft-availablepicks", Data: player.CurrentPack, Message: fmt.Sprintf("You got these cards: %s", player.CurrentPack), }