argument safety, reset card effect stacks on tick

This commit is contained in:
stryan 2021-07-25 22:53:40 -04:00
parent 8a20d97ad6
commit 08a3559c99
2 changed files with 36 additions and 10 deletions

View File

@ -78,6 +78,7 @@ func (b *Board) CanMove(id, src, dest int) bool {
func (b *Board) Move(id, src, dest int) bool {
brd := b.GetRow(id)
brd[dest] = brd[src]
brd[dest].Position = dest
brd[src] = NewEmpty(src)
return true
}
@ -96,8 +97,8 @@ func (b *Board) CanPlay(id int, c *Card, dest int) bool {
func (b *Board) Play(id int, c *Card, dest int, should bool) bool {
brd := b.GetRow(id)
if should {
brd[dest] = c
c.Position = dest
brd[dest] = c
} else {
return false
}
@ -150,8 +151,10 @@ func (b *Board) Attack(id, atk, def int) int {
func (b *Board) ResetCards() {
for _, v := range b.Sentinal {
v.Power = v.BasePower
v.Effects = []Effect{}
}
for _, v := range b.Scourge {
v.Power = v.BasePower
v.Effects = []Effect{}
}
}

View File

@ -248,12 +248,12 @@ func (g *Game) PlayerAct(id int, cmd string) *Deck {
return DeckFromCards(curr.Hand)
}
x_i, err := strconv.Atoi(cmd_s[1])
if x_i > 2 || x_i < 0 {
return nil
}
if err != nil {
panic(err)
}
if x_i > 2 || x_i < 0 {
return nil
}
x := g.CardBuffer.Cards[x_i]
buf := g.CardBuffer
for i, v := range buf.Cards {
@ -275,8 +275,15 @@ func (g *Game) PlayerAct(id int, cmd string) *Deck {
if !g.HasDrawn {
return nil
}
x_i, _ := strconv.Atoi(cmd_s[1])
y_i, _ := strconv.Atoi(cmd_s[2])
x_i, err := strconv.Atoi(cmd_s[1])
if err != nil {
log.Println(err)
return nil
}
y_i, err := strconv.Atoi(cmd_s[2])
if err != nil {
log.Println(err)
}
if g.GameBoard.CanMove(g.CurrentTurn, x_i, y_i) {
OracleMove(g.GameBoard.GetCard(g.CurrentTurn, x_i), x_i, y_i, g)
g.GameBoard.Move(g.CurrentTurn, x_i, y_i)
@ -292,8 +299,16 @@ func (g *Game) PlayerAct(id int, cmd string) *Deck {
if !g.HasDrawn {
return nil
}
x_i, _ := strconv.Atoi(cmd_s[1])
y_i, _ := strconv.Atoi(cmd_s[2])
x_i, err := strconv.Atoi(cmd_s[1])
if err != nil {
log.Println(err)
return nil
}
y_i, err := strconv.Atoi(cmd_s[2])
if err != nil {
log.Println(err)
return nil
}
if g.GameBoard.CanAttack(g.CurrentTurn, x_i, y_i) {
OracleAttack(g.GameBoard.GetCard(g.CurrentTurn, x_i), g)
res := g.GameBoard.Attack(g.CurrentTurn, x_i, y_i)
@ -338,8 +353,16 @@ func (g *Game) PlayerAct(id int, cmd string) *Deck {
if !g.HasDrawn {
return nil
}
x_i, _ := strconv.Atoi(cmd_s[1])
y_i, _ := strconv.Atoi(cmd_s[2])
x_i, err := strconv.Atoi(cmd_s[1])
if err != nil {
log.Println(err)
return nil
}
y_i, err := strconv.Atoi(cmd_s[2])
if err != nil {
log.Println(err)
return nil
}
card := curr.Hand[x_i]
shouldPlace := true
if g.GameBoard.CanPlay(g.CurrentTurn, card, y_i) {