diff --git a/internal/game/board.go b/internal/game/board.go index df7e9ff..db4935c 100644 --- a/internal/game/board.go +++ b/internal/game/board.go @@ -24,8 +24,11 @@ func (b *Board) String() string { func (b *Board) GetRow(id int) []*Card { if id == SentinalID { return b.Sentinal[:] - } else { + } else if id == ScourgeID { return b.Scourge[:] + } else { + log.Println("asked for invalid row") + return nil } } @@ -151,10 +154,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{} + v.Effects = []*Effect{} } for _, v := range b.Scourge { v.Power = v.BasePower - v.Effects = []Effect{} + v.Effects = []*Effect{} } } diff --git a/internal/game/card.go b/internal/game/card.go index f684b50..1a44fad 100644 --- a/internal/game/card.go +++ b/internal/game/card.go @@ -16,7 +16,7 @@ type Card struct { Owner int `json:"owner"` Position int `json:"position"` Spell bool `json:"spell"` - Effects []Effect `json:"effects"` + Effects []*Effect `json:"effects"` } type CardType int @@ -57,7 +57,7 @@ func NewCard(v, o, p int, id uuid.UUID) *Card { Owner: o, Position: p, Spell: OracleSpell(CardType(v), nil), - Effects: []Effect{}, + Effects: []*Effect{}, } } @@ -72,7 +72,7 @@ func NewEmpty(p int) *Card { Owner: -1, Position: p, Spell: false, - Effects: []Effect{}, + Effects: []*Effect{}, } } diff --git a/internal/game/effect.go b/internal/game/effect.go index 28a5232..7806b30 100644 --- a/internal/game/effect.go +++ b/internal/game/effect.go @@ -1,6 +1,10 @@ package game -import "github.com/google/uuid" +import ( + "log" + + "github.com/google/uuid" +) type Effect struct { Owner uuid.UUID @@ -19,14 +23,17 @@ func RemoveEffect(source uuid.UUID, c *Card) { } } -func AddEffect(c *Card, e Effect) { +func AddEffect(c *Card, e *Effect) { if c.Type == EmptyValue { + log.Println("Can't add effect to empty card") return } for _, v := range c.Effects { if v.Owner == e.Owner && v.ID == e.ID { + log.Println("can't stack effects") return } } + log.Printf("applying %v to %v", e, c) c.Effects = append(c.Effects, e) } diff --git a/internal/game/game.go b/internal/game/game.go index c40b45c..22664fc 100644 --- a/internal/game/game.go +++ b/internal/game/game.go @@ -127,13 +127,13 @@ func (g *Game) StateChanges() { } //reapply card effects g.GameBoard.ResetCards() - for _, v := range g.GameBoard.Sentinal { - OracleTick(v, g) //apply effect stacks first - OracleEffect(v, g) //actually activate effects + for i := 0; i < len(g.GameBoard.Sentinal); i++ { + OracleTick(g.GameBoard.Sentinal[i], g) //apply effect stacks first + OracleTick(g.GameBoard.Scourge[i], g) } - for _, v := range g.GameBoard.Scourge { - OracleTick(v, g) - OracleEffect(v, g) + for i := 0; i < len(g.GameBoard.Sentinal); i++ { + OracleEffect(g.GameBoard.Sentinal[i], g) //activate effects + OracleEffect(g.GameBoard.Scourge[i], g) } //check life //this is second on purpose so that it shadows deck out win conditions diff --git a/internal/game/oracle.go b/internal/game/oracle.go index 80f3de0..2f00508 100644 --- a/internal/game/oracle.go +++ b/internal/game/oracle.go @@ -1,5 +1,7 @@ package game +import "log" + func OracleUpkeep(c *Card, g *Game) { switch c.Type { case Eight: @@ -39,13 +41,16 @@ func OracleEnters(c *Card, g *Game) { c.Sick = false return case Four: - AddEffect(c, Effect{c.Id, c.Id, 2}) + AddEffect(c, &Effect{c.Id, c.Id, 2}) case Eight: c.Counters = 0 } } func OracleTick(c *Card, g *Game) { + if c.Type == EmptyValue { + return + } row := g.GameBoard.GetRow(c.Owner) switch c.Type { @@ -53,25 +58,25 @@ func OracleTick(c *Card, g *Game) { //+1 to all for _, v := range row { if v.Id != c.Id { - AddEffect(v, Effect{c.Id, v.Id, 1}) + AddEffect(v, &Effect{c.Id, v.Id, 1}) } } case Three: //+1 around it if c.Position-1 >= 0 { - v := row[c.Position-1] - AddEffect(v, Effect{c.Id, v.Id, 1}) + AddEffect(row[c.Position-1], &Effect{c.Id, row[c.Position-1].Id, 1}) } if c.Position+1 <= 3 { - v := row[c.Position+1] - AddEffect(v, Effect{c.Id, v.Id, 1}) - + AddEffect(row[c.Position+1], &Effect{c.Id, row[c.Position+1].Id, 1}) } } } func OracleLeaves(c *Card, g *Game) { + if c.Empty() { + return + } row := g.GameBoard.GetRow(c.Owner) switch c.Type { case Two: @@ -123,8 +128,13 @@ func OracleAttack(c *Card, g *Game) { } func OracleEffect(c *Card, g *Game) { + if c.Empty() { + return + } for _, e := range c.Effects { switch e.ID { + case 0: + log.Println("dummy effect applied. probably a bug") case 1: c.Power = c.Power + 1 case 2: @@ -136,6 +146,8 @@ func OracleEffect(c *Card, g *Game) { g.CanDraw = true g.HasDrawn = false RemoveEffect(e.Owner, c) + default: + log.Println("wrong effect type") } } }