apply effect stacks, then parse stacks
This commit is contained in:
parent
08a3559c99
commit
2e512b655b
@ -24,8 +24,11 @@ func (b *Board) String() string {
|
|||||||
func (b *Board) GetRow(id int) []*Card {
|
func (b *Board) GetRow(id int) []*Card {
|
||||||
if id == SentinalID {
|
if id == SentinalID {
|
||||||
return b.Sentinal[:]
|
return b.Sentinal[:]
|
||||||
} else {
|
} else if id == ScourgeID {
|
||||||
return b.Scourge[:]
|
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() {
|
func (b *Board) ResetCards() {
|
||||||
for _, v := range b.Sentinal {
|
for _, v := range b.Sentinal {
|
||||||
v.Power = v.BasePower
|
v.Power = v.BasePower
|
||||||
v.Effects = []Effect{}
|
v.Effects = []*Effect{}
|
||||||
}
|
}
|
||||||
for _, v := range b.Scourge {
|
for _, v := range b.Scourge {
|
||||||
v.Power = v.BasePower
|
v.Power = v.BasePower
|
||||||
v.Effects = []Effect{}
|
v.Effects = []*Effect{}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -16,7 +16,7 @@ type Card struct {
|
|||||||
Owner int `json:"owner"`
|
Owner int `json:"owner"`
|
||||||
Position int `json:"position"`
|
Position int `json:"position"`
|
||||||
Spell bool `json:"spell"`
|
Spell bool `json:"spell"`
|
||||||
Effects []Effect `json:"effects"`
|
Effects []*Effect `json:"effects"`
|
||||||
}
|
}
|
||||||
|
|
||||||
type CardType int
|
type CardType int
|
||||||
@ -57,7 +57,7 @@ func NewCard(v, o, p int, id uuid.UUID) *Card {
|
|||||||
Owner: o,
|
Owner: o,
|
||||||
Position: p,
|
Position: p,
|
||||||
Spell: OracleSpell(CardType(v), nil),
|
Spell: OracleSpell(CardType(v), nil),
|
||||||
Effects: []Effect{},
|
Effects: []*Effect{},
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -72,7 +72,7 @@ func NewEmpty(p int) *Card {
|
|||||||
Owner: -1,
|
Owner: -1,
|
||||||
Position: p,
|
Position: p,
|
||||||
Spell: false,
|
Spell: false,
|
||||||
Effects: []Effect{},
|
Effects: []*Effect{},
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1,6 +1,10 @@
|
|||||||
package game
|
package game
|
||||||
|
|
||||||
import "github.com/google/uuid"
|
import (
|
||||||
|
"log"
|
||||||
|
|
||||||
|
"github.com/google/uuid"
|
||||||
|
)
|
||||||
|
|
||||||
type Effect struct {
|
type Effect struct {
|
||||||
Owner uuid.UUID
|
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 {
|
if c.Type == EmptyValue {
|
||||||
|
log.Println("Can't add effect to empty card")
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
for _, v := range c.Effects {
|
for _, v := range c.Effects {
|
||||||
if v.Owner == e.Owner && v.ID == e.ID {
|
if v.Owner == e.Owner && v.ID == e.ID {
|
||||||
|
log.Println("can't stack effects")
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
log.Printf("applying %v to %v", e, c)
|
||||||
c.Effects = append(c.Effects, e)
|
c.Effects = append(c.Effects, e)
|
||||||
}
|
}
|
||||||
|
@ -127,13 +127,13 @@ func (g *Game) StateChanges() {
|
|||||||
}
|
}
|
||||||
//reapply card effects
|
//reapply card effects
|
||||||
g.GameBoard.ResetCards()
|
g.GameBoard.ResetCards()
|
||||||
for _, v := range g.GameBoard.Sentinal {
|
for i := 0; i < len(g.GameBoard.Sentinal); i++ {
|
||||||
OracleTick(v, g) //apply effect stacks first
|
OracleTick(g.GameBoard.Sentinal[i], g) //apply effect stacks first
|
||||||
OracleEffect(v, g) //actually activate effects
|
OracleTick(g.GameBoard.Scourge[i], g)
|
||||||
}
|
}
|
||||||
for _, v := range g.GameBoard.Scourge {
|
for i := 0; i < len(g.GameBoard.Sentinal); i++ {
|
||||||
OracleTick(v, g)
|
OracleEffect(g.GameBoard.Sentinal[i], g) //activate effects
|
||||||
OracleEffect(v, g)
|
OracleEffect(g.GameBoard.Scourge[i], g)
|
||||||
}
|
}
|
||||||
//check life
|
//check life
|
||||||
//this is second on purpose so that it shadows deck out win conditions
|
//this is second on purpose so that it shadows deck out win conditions
|
||||||
|
@ -1,5 +1,7 @@
|
|||||||
package game
|
package game
|
||||||
|
|
||||||
|
import "log"
|
||||||
|
|
||||||
func OracleUpkeep(c *Card, g *Game) {
|
func OracleUpkeep(c *Card, g *Game) {
|
||||||
switch c.Type {
|
switch c.Type {
|
||||||
case Eight:
|
case Eight:
|
||||||
@ -39,13 +41,16 @@ func OracleEnters(c *Card, g *Game) {
|
|||||||
c.Sick = false
|
c.Sick = false
|
||||||
return
|
return
|
||||||
case Four:
|
case Four:
|
||||||
AddEffect(c, Effect{c.Id, c.Id, 2})
|
AddEffect(c, &Effect{c.Id, c.Id, 2})
|
||||||
case Eight:
|
case Eight:
|
||||||
c.Counters = 0
|
c.Counters = 0
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func OracleTick(c *Card, g *Game) {
|
func OracleTick(c *Card, g *Game) {
|
||||||
|
if c.Type == EmptyValue {
|
||||||
|
return
|
||||||
|
}
|
||||||
row := g.GameBoard.GetRow(c.Owner)
|
row := g.GameBoard.GetRow(c.Owner)
|
||||||
|
|
||||||
switch c.Type {
|
switch c.Type {
|
||||||
@ -53,25 +58,25 @@ func OracleTick(c *Card, g *Game) {
|
|||||||
//+1 to all
|
//+1 to all
|
||||||
for _, v := range row {
|
for _, v := range row {
|
||||||
if v.Id != c.Id {
|
if v.Id != c.Id {
|
||||||
AddEffect(v, Effect{c.Id, v.Id, 1})
|
AddEffect(v, &Effect{c.Id, v.Id, 1})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
case Three:
|
case Three:
|
||||||
//+1 around it
|
//+1 around it
|
||||||
if c.Position-1 >= 0 {
|
if c.Position-1 >= 0 {
|
||||||
v := row[c.Position-1]
|
AddEffect(row[c.Position-1], &Effect{c.Id, row[c.Position-1].Id, 1})
|
||||||
AddEffect(v, Effect{c.Id, v.Id, 1})
|
|
||||||
|
|
||||||
}
|
}
|
||||||
if c.Position+1 <= 3 {
|
if c.Position+1 <= 3 {
|
||||||
v := row[c.Position+1]
|
AddEffect(row[c.Position+1], &Effect{c.Id, row[c.Position+1].Id, 1})
|
||||||
AddEffect(v, Effect{c.Id, v.Id, 1})
|
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func OracleLeaves(c *Card, g *Game) {
|
func OracleLeaves(c *Card, g *Game) {
|
||||||
|
if c.Empty() {
|
||||||
|
return
|
||||||
|
}
|
||||||
row := g.GameBoard.GetRow(c.Owner)
|
row := g.GameBoard.GetRow(c.Owner)
|
||||||
switch c.Type {
|
switch c.Type {
|
||||||
case Two:
|
case Two:
|
||||||
@ -123,8 +128,13 @@ func OracleAttack(c *Card, g *Game) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func OracleEffect(c *Card, g *Game) {
|
func OracleEffect(c *Card, g *Game) {
|
||||||
|
if c.Empty() {
|
||||||
|
return
|
||||||
|
}
|
||||||
for _, e := range c.Effects {
|
for _, e := range c.Effects {
|
||||||
switch e.ID {
|
switch e.ID {
|
||||||
|
case 0:
|
||||||
|
log.Println("dummy effect applied. probably a bug")
|
||||||
case 1:
|
case 1:
|
||||||
c.Power = c.Power + 1
|
c.Power = c.Power + 1
|
||||||
case 2:
|
case 2:
|
||||||
@ -136,6 +146,8 @@ func OracleEffect(c *Card, g *Game) {
|
|||||||
g.CanDraw = true
|
g.CanDraw = true
|
||||||
g.HasDrawn = false
|
g.HasDrawn = false
|
||||||
RemoveEffect(e.Owner, c)
|
RemoveEffect(e.Owner, c)
|
||||||
|
default:
|
||||||
|
log.Println("wrong effect type")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user