add player effects, initial support for arbitrary scrying

This commit is contained in:
stryan 2021-11-11 15:08:38 -05:00
parent 059a0acd3b
commit 8230a94357
3 changed files with 35 additions and 9 deletions

10
game.go
View File

@ -19,6 +19,7 @@ type Game struct {
ScourgeGrave *Deck ScourgeGrave *Deck
CurrentTurn int CurrentTurn int
CardBuffer *Deck CardBuffer *Deck
ScryBuffer int
CanDraw bool CanDraw bool
HasDrawn bool HasDrawn bool
QueuedEffect *Effect QueuedEffect *Effect
@ -39,6 +40,7 @@ func NewGame(sentDeck []int, scoDeck []int) *Game {
ScourgeGrave: DeckFromCards([]*Card{}), ScourgeGrave: DeckFromCards([]*Card{}),
CurrentTurn: 0, //start with no turn CurrentTurn: 0, //start with no turn
CardBuffer: DeckFromCards([]*Card{}), CardBuffer: DeckFromCards([]*Card{}),
ScryBuffer: 0,
CanDraw: false, CanDraw: false,
HasDrawn: false, HasDrawn: false,
QueuedEffect: nil, QueuedEffect: nil,
@ -112,6 +114,10 @@ func (g *Game) StateChanges() {
g.Status = StatusSentinalWin g.Status = StatusSentinalWin
} }
} }
//apply CurrentTurn player effects
for i := 0; i < len(g.GetPlayer(g.CurrentTurn).Effects); i++ {
OraclePlayerEffect(g.GetPlayer(g.CurrentTurn), g)
}
//reapply card effects //reapply card effects
g.GameBoard.ResetCards() g.GameBoard.ResetCards()
for i := 0; i < len(g.GameBoard.Sentinal); i++ { for i := 0; i < len(g.GameBoard.Sentinal); i++ {
@ -227,9 +233,13 @@ func (g *Game) PlayerAct(id int, cmd string) *Deck {
if !g.CanDraw || g.QueuedEffect != nil { if !g.CanDraw || g.QueuedEffect != nil {
return nil return nil
} }
if g.ScryBuffer == 0 {
g.ScryBuffer = curr.Life
}
if g.CardBuffer.Size() <= 0 { if g.CardBuffer.Size() <= 0 {
g.CardBuffer = DeckFromCards(currD.Scry(curr.Life)) g.CardBuffer = DeckFromCards(currD.Scry(curr.Life))
} }
g.ScryBuffer = 0
return g.CardBuffer return g.CardBuffer
case "d": case "d":
//draw: return player hand //draw: return player hand

View File

@ -54,7 +54,7 @@ func OracleEnters(c *Card, g *Game) {
c.Sick = false c.Sick = false
return return
case Scholar: case Scholar:
AddEffect(c, &Effect{c.Id, c.Id, 2, 1}) AddPlayerEffect(g.GetPlayer(c.Owner), &Effect{c.Id, uuid.Nil, 2, 1})
case ShieldWall, Tree: case ShieldWall, Tree:
c.Counters = 0 c.Counters = 0
case HealthPotion: case HealthPotion:
@ -154,13 +154,13 @@ func OracleEndstep(c *Card, g *Game) {
func OraclePower(c CardType, g *Game) int { func OraclePower(c CardType, g *Game) int {
//this is horrible //this is horrible
switch c { switch c {
case Speedster, HealthPotion, Tree, Goblin: case Speedster, HealthPotion, Tree, Goblin, GoblinSpawn, Chupacabra:
return 1 return 1
case Commander, Ally: case Commander, Ally:
return 2 return 2
case Paladin: case Paladin, Duelist:
return 3 return 3
case Scholar: case Scholar, Vanguard:
return 4 return 4
case Warrior: case Warrior:
return 5 return 5
@ -243,3 +243,18 @@ func OracleEffect(c *Card, g *Game) {
c.Power = 0 c.Power = 0
} }
} }
func OraclePlayerEffect(p *Player, g *Game) {
if p == nil {
return
}
for _, e := range p.Effects {
switch e.ID {
case 2:
g.CardBuffer = DeckFromCards(g.GetDeck(p.Id).Scry(1))
g.CanDraw = true
g.HasDrawn = false
RemovePlayerEffect(e.Owner, p)
}
}
}

View File

@ -6,10 +6,11 @@ import (
func NewPlayer(name string, id int) *Player { func NewPlayer(name string, id int) *Player {
return &Player{ return &Player{
Name: name, Name: name,
Id: id, Id: id,
Hand: []*Card{}, Hand: []*Card{},
Life: 3, Life: 3,
Ready: false, Ready: false,
Effects: []*Effect{},
} }
} }