copy slices to prevent weird slice overlap

This commit is contained in:
stryan 2021-11-19 13:53:43 -05:00
parent a28b45e5cf
commit 272903fabc
2 changed files with 11 additions and 7 deletions

14
game.go
View File

@ -52,7 +52,7 @@ func NewGame(sentDeck []int, scoDeck []int) *Game {
} }
func (g *Game) String() string { func (g *Game) String() string {
return fmt.Sprintf("Sen(%v): %v\n\n%v\n\nSco(%v): %v\nStatus:%v Draw:%v Turn:%v\nBuffers\nCardBuffer:%v\nSB:%v BB:%v\nEffectTarget:%v\nQueuedEffect:%v\n", g.SentinalPlayer.Life, g.SentinalPlayer.Hand, g.GameBoard, g.ScourgePlayer.Life, g.ScourgePlayer.Hand, g.Status, g.CanDraw, g.CurrentTurn, g.CardBuffer, g.ScryBuffer, g.CardBuffer, g.TargetReq, g.QueuedEffect) return fmt.Sprintf("Sen(%v): %v\n\n%v\n\nSco(%v): %v\nStatus:%v Draw:%v Turn:%v\nBuffers\nCardBuffer:%v\nSB:%v BB:%v\nEffectTarget:%v\nQueuedEffect:%v\n", g.SentinalPlayer.Life, g.SentinalPlayer.Hand, g.GameBoard, g.ScourgePlayer.Life, g.ScourgePlayer.Hand, g.Status, g.CanDraw, g.CurrentTurn, g.CardBuffer, g.ScryBuffer, g.BottomBuffer, g.TargetReq, g.QueuedEffect)
} }
func (g *Game) Parse(cmd *Command) *CommandResult { func (g *Game) Parse(cmd *Command) *CommandResult {
@ -155,6 +155,9 @@ func (g *Game) PlayerStateAct(id int, cmd string) *GameView {
return NewView(id, g) return NewView(id, g)
case "b": case "b":
//begin game //begin game
if g.Status == StatusPlaying {
break
}
if id == SentinalID { if id == SentinalID {
g.SentinalPlayer.Ready = true g.SentinalPlayer.Ready = true
} else if id == ScourgeID { } else if id == ScourgeID {
@ -248,7 +251,7 @@ func (g *Game) PlayerAct(id int, cmd string) *Deck {
g.ScryBuffer = curr.Life g.ScryBuffer = curr.Life
} }
if g.CardBuffer.Size() <= 0 { if g.CardBuffer.Size() <= 0 {
g.CardBuffer = DeckFromCards(currD.Scry(curr.Life)) g.CardBuffer = currD.Scry(g.ScryBuffer)
} }
g.ScryBuffer = 0 g.ScryBuffer = 0
return g.CardBuffer return g.CardBuffer
@ -275,11 +278,12 @@ func (g *Game) PlayerAct(id int, cmd string) *Deck {
if x.Owner != g.CurrentTurn { if x.Owner != g.CurrentTurn {
log.Println("drew a card from our deck that isn't our own") log.Println("drew a card from our deck that isn't our own")
} }
g.CardBuffer.Cards = append(g.CardBuffer.Cards[:x_i], g.CardBuffer.Cards[x_i+1:]...) g.CardBuffer = DeckFromCards(append(g.CardBuffer.Cards[:x_i], g.CardBuffer.Cards[x_i+1:]...))
currD.Bottom(g.CardBuffer.Cards) currD.Bottom(g.CardBuffer)
curr.Hand = append(curr.Hand, x) curr.Hand = append(curr.Hand, x)
g.CanDraw = false g.CanDraw = false
g.HasDrawn = true g.HasDrawn = true
g.CardBuffer.Reset()
return DeckFromCards(curr.Hand) return DeckFromCards(curr.Hand)
case "b": case "b":
if g.BottomBuffer == 0 || g.ScryBuffer != 0 { if g.BottomBuffer == 0 || g.ScryBuffer != 0 {
@ -298,7 +302,7 @@ func (g *Game) PlayerAct(id int, cmd string) *Deck {
} }
bottomTarget := g.CardBuffer.Cards[x_i] bottomTarget := g.CardBuffer.Cards[x_i]
g.CardBuffer.Cards = append(g.CardBuffer.Cards[:x_i], g.CardBuffer.Cards[x_i+1:]...) g.CardBuffer.Cards = append(g.CardBuffer.Cards[:x_i], g.CardBuffer.Cards[x_i+1:]...)
currD.Bottom([]*Card{bottomTarget}) currD.Bottom(DeckFromCards([]*Card{bottomTarget}))
g.BottomBuffer = g.BottomBuffer - 1 g.BottomBuffer = g.BottomBuffer - 1
if g.BottomBuffer > 0 { if g.BottomBuffer > 0 {
return g.CardBuffer return g.CardBuffer

View File

@ -243,7 +243,7 @@ func OracleEffect(c *Card, g *Game) {
if c.Owner != SentinalID && c.Owner != ScourgeID { if c.Owner != SentinalID && c.Owner != ScourgeID {
log.Println("card draw effect was played but with no owner?") log.Println("card draw effect was played but with no owner?")
} else { } else {
g.CardBuffer = DeckFromCards(g.GetDeck(c.Owner).Scry(1)) g.CardBuffer = g.GetDeck(c.Owner).Scry(1)
} }
g.CanDraw = true g.CanDraw = true
g.HasDrawn = false g.HasDrawn = false
@ -300,7 +300,7 @@ func OraclePlayerEffect(p *Player, g *Game) {
g.HasDrawn = false g.HasDrawn = false
RemovePlayerEffect(e.Owner, p) RemovePlayerEffect(e.Owner, p)
case 2: case 2:
g.CardBuffer = DeckFromCards(g.GetDeck(p.Id).Scry(1)) g.CardBuffer = g.GetDeck(p.Id).Scry(1)
g.CanDraw = true g.CanDraw = true
g.HasDrawn = false g.HasDrawn = false
RemovePlayerEffect(e.Owner, p) RemovePlayerEffect(e.Owner, p)