add targeting

This commit is contained in:
stryan 2021-11-10 17:39:58 -05:00
parent b07d824804
commit 1d45984958
2 changed files with 59 additions and 7 deletions

View File

@ -32,7 +32,7 @@ func LoadDeck(owner int, cards []int) *Deck {
}
func ValidateDeck(cards []int) bool {
if len(cards) < 7 {
if len(cards) < 15 {
return false
}
for _, v := range cards {

64
game.go
View File

@ -21,6 +21,8 @@ type Game struct {
CardBuffer *Deck
CanDraw bool
HasDrawn bool
QueuedEffect *Effect
TargetReq TargetStatus
Status GameStatus
}
@ -39,6 +41,8 @@ func NewGame(sentDeck []int, scoDeck []int) *Game {
CardBuffer: DeckFromCards([]*Card{}),
CanDraw: false,
HasDrawn: false,
QueuedEffect: nil,
TargetReq: TargetNone,
Status: StatusLobby,
}
}
@ -220,7 +224,7 @@ func (g *Game) PlayerAct(id int, cmd string) *Deck {
switch cmd_s[0] {
case "s":
//scry: return scry options off top of deck
if !g.CanDraw {
if !g.CanDraw || g.QueuedEffect != nil {
return nil
}
if g.CardBuffer.Size() <= 0 {
@ -229,7 +233,7 @@ func (g *Game) PlayerAct(id int, cmd string) *Deck {
return g.CardBuffer
case "d":
//draw: return player hand
if !g.CanDraw {
if !g.CanDraw || g.QueuedEffect != nil {
return nil
}
if len(cmd_s) != 2 || !g.CanDraw {
@ -261,7 +265,7 @@ func (g *Game) PlayerAct(id int, cmd string) *Deck {
if len(cmd_s) != 3 {
return nil
}
if !g.HasDrawn {
if !g.HasDrawn || g.QueuedEffect != nil {
return nil
}
x_i, err := strconv.Atoi(cmd_s[1])
@ -285,7 +289,7 @@ func (g *Game) PlayerAct(id int, cmd string) *Deck {
if len(cmd_s) != 3 {
return nil
}
if !g.HasDrawn {
if !g.HasDrawn || g.QueuedEffect != nil {
return nil
}
x_i, err := strconv.Atoi(cmd_s[1])
@ -333,12 +337,12 @@ func (g *Game) PlayerAct(id int, cmd string) *Deck {
return DeckFromCards([]*Card{})
}
case "p":
//play: return player boad or [] if invalid
//play: return player board or [] if invalid
if len(cmd_s) != 3 {
fmt.Println("not enough arguments")
return nil
}
if !g.HasDrawn {
if !g.HasDrawn || !g.QueuedEffect != nil {
return nil
}
x_i, err := strconv.Atoi(cmd_s[1])
@ -368,6 +372,54 @@ func (g *Game) PlayerAct(id int, cmd string) *Deck {
fmt.Println("couldn't play")
return DeckFromCards([]*Card{})
}
case "t":
//target: apply queued effect to target,return affected board or nil
if len(cmd_s) != 3 {
fmt.Println("not enough arguments")
return nil
}
if !g.HasDrawn || g.QueuedEffect == nil {
return nil
}
board, err := strconv.Atoi(cmd_s[1])
if err != nil {
log.Println(err)
return nil
}
pos, err := strconv.Atoi(cmd_s[2])
if err != nil {
log.Println(err)
return nil
}
if pos < 0 || pos >= 3 {
fmt.Println("board position out of bounds")
return nil
}
switch g.TargetStatus {
case TargetSelf:
if board != g.CurrentTurn && g.GetBoard(board)[pos].Id != g.QueuedEffect.Owner {
fmt.Println("self target not on self")
return nil
}
case TargetOwn:
if board != g.CurrentTurn {
fmt.Println("own target not on own board")
return nil
}
case TargetOpp:
if board == g.CurrentTurn {
fmt.Println("opponent target not on oponents board")
return nil
}
case TargetNone:
fmt.Println("NoneTarget'd ability?")
return nil
}
AddEffect(g.GetBoard(board)[pos], g.QueuedEffect)
g.QueuedEffect = nil
g.TargetStatus = TargetNone
return g.GetBoard(board)
default:
fmt.Println("Invalid act command")
return nil