actually use custom decks
This commit is contained in:
parent
785936fada
commit
88c66f455c
@ -105,6 +105,28 @@ func (c *Coordinator) Coordinate(cmd *SessionCommand) *SessionCommandResult {
|
|||||||
Result: SessionRespError,
|
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:
|
case SessionCmdLeave:
|
||||||
m, exists := c.Matches[cmd.MatchID]
|
m, exists := c.Matches[cmd.MatchID]
|
||||||
if exists && m.PlayerIn(cmd.ID) {
|
if exists && m.PlayerIn(cmd.ID) {
|
||||||
|
@ -2,6 +2,7 @@ package coordinator
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
|
"log"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
. "git.saintnet.tech/tomecraft/tome_game"
|
. "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 {
|
func (s *Session) LoadDeck(id uuid.UUID, data string) SessionResp {
|
||||||
var deck []int
|
var deck []int
|
||||||
err := json.Unmarshal([]byte(data), &data)
|
err := json.Unmarshal([]byte(data), &deck)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
log.Printf("bad deck load error:%v data: %v", err, data)
|
||||||
return SessionRespLoadDeckError
|
return SessionRespLoadDeckError
|
||||||
}
|
}
|
||||||
valid := ValidateDeck(deck)
|
valid := ValidateDeck(deck)
|
||||||
if !valid {
|
if !valid {
|
||||||
|
log.Printf("%v attempted to load invalid deck: %v", id, data)
|
||||||
return SessionRespLoadDeckError
|
return SessionRespLoadDeckError
|
||||||
}
|
}
|
||||||
if id == s.p1 {
|
if id == s.p1 {
|
||||||
s.p1Deck = deck
|
s.p1Deck = deck
|
||||||
|
s.Game.SentinalDeck = LoadDeck(SentinalID, s.p1Deck)
|
||||||
} else if id == s.p2 {
|
} else if id == s.p2 {
|
||||||
s.p2Deck = deck
|
s.p2Deck = deck
|
||||||
|
s.Game.ScourgeDeck = LoadDeck(ScourgeID, s.p2Deck)
|
||||||
} else {
|
} else {
|
||||||
return SessionRespError
|
return SessionRespError
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user