Add global message for picks
All checks were successful
continuous-integration/drone/push Build is passing

This commit is contained in:
Hamcha 2019-08-26 11:18:14 +02:00
parent c650813453
commit 603bab601d
2 changed files with 14 additions and 5 deletions

View file

@ -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)

View file

@ -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),
}