actually use custom decks

This commit is contained in:
stryan 2021-11-08 16:57:58 -05:00
parent 785936fada
commit 88c66f455c
2 changed files with 28 additions and 1 deletions

View File

@ -105,6 +105,28 @@ func (c *Coordinator) Coordinate(cmd *SessionCommand) *SessionCommandResult {
Result: SessionRespError,
}
}
case SessionCmdLoadDeck:
m, exists := c.Matches[cmd.MatchID]
if !exists || !m.PlayerIn(cmd.ID) {
return &SessionCommandResult{
ID: cmd.ID,
MatchID: uuid.Nil,
Result: SessionRespError,
}
}
if m.Game != nil && m.Game.Status != StatusLobby {
return &SessionCommandResult{
ID: cmd.ID,
MatchID: m.ID,
Result: SessionRespLoadDeckError,
}
}
resp := m.LoadDeck(cmd.ID, cmd.Data)
return &SessionCommandResult{
ID: cmd.ID,
MatchID: m.ID,
Result: resp,
}
case SessionCmdLeave:
m, exists := c.Matches[cmd.MatchID]
if exists && m.PlayerIn(cmd.ID) {

View File

@ -2,6 +2,7 @@ package coordinator
import (
"encoding/json"
"log"
"time"
. "git.saintnet.tech/tomecraft/tome_game"
@ -84,18 +85,22 @@ func (s *Session) Play(id uuid.UUID, cmd *Command) *CommandResult {
func (s *Session) LoadDeck(id uuid.UUID, data string) SessionResp {
var deck []int
err := json.Unmarshal([]byte(data), &data)
err := json.Unmarshal([]byte(data), &deck)
if err != nil {
log.Printf("bad deck load error:%v data: %v", err, data)
return SessionRespLoadDeckError
}
valid := ValidateDeck(deck)
if !valid {
log.Printf("%v attempted to load invalid deck: %v", id, data)
return SessionRespLoadDeckError
}
if id == s.p1 {
s.p1Deck = deck
s.Game.SentinalDeck = LoadDeck(SentinalID, s.p1Deck)
} else if id == s.p2 {
s.p2Deck = deck
s.Game.ScourgeDeck = LoadDeck(ScourgeID, s.p2Deck)
} else {
return SessionRespError
}