diff --git a/game.go b/game.go index ff1fa1c..4ba3251 100644 --- a/game.go +++ b/game.go @@ -20,6 +20,7 @@ type Game struct { CurrentTurn int CardBuffer *Deck ScryBuffer int + BottomBuffer int CanDraw bool HasDrawn bool QueuedEffect *Effect @@ -41,6 +42,7 @@ func NewGame(sentDeck []int, scoDeck []int) *Game { CurrentTurn: 0, //start with no turn CardBuffer: DeckFromCards([]*Card{}), ScryBuffer: 0, + BottomBuffer: 0, CanDraw: false, HasDrawn: false, QueuedEffect: nil, @@ -254,9 +256,10 @@ func (g *Game) PlayerAct(id int, cmd string) *Deck { } x_i, err := strconv.Atoi(cmd_s[1]) if err != nil { - panic(err) + log.Printf("error converting draw target %v", err) + return nil } - if x_i > 2 || x_i < 0 { + if x_i > g.CardBuffer.Size() || x_i < 0 { return nil } x := g.CardBuffer.Cards[x_i] @@ -269,7 +272,31 @@ func (g *Game) PlayerAct(id int, cmd string) *Deck { g.CanDraw = false g.HasDrawn = true return DeckFromCards(curr.Hand) - + case "b": + if g.BottomBuffer == 0 || g.ScryBuffer == 0 { + return nil + } + if len(cmd_s) != 2 { + return nil + } + x_i, err := strconv.Atoi(cmd_s[1]) + if err != nil { + log.Printf("error converting bottom target %v", err) + return nil + } + if x_i > g.CardBuffer.Size() || x_i < 0 { + return nil + } + bottomTarget := g.CardBuffer.Cards[x_i] + g.CardBuffer.Cards = append(g.CardBuffer.Cards[:x_i], g.CardBuffer.Cards[x_i+1:]...) + currD.Bottom([]*Card{bottomTarget}) + g.BottomBuffer = g.BottomBuffer - 1 + if g.BottomBuffer > 0 { + return g.CardBuffer + } else { + g.BottomBuffer = 0 + return nil + } case "m": //move: return player board or [] if invalid if len(cmd_s) != 3 { @@ -313,7 +340,7 @@ func (g *Game) PlayerAct(id int, cmd string) *Deck { return nil } if g.GameBoard.CanAttack(g.CurrentTurn, x_i, y_i) { - OracleAttack(g.GameBoard.GetCard(g.CurrentTurn, x_i), g) + OracleAttack(g.GameBoard.GetCard(g.CurrentTurn, x_i), x_i, y_i, g) res := g.GameBoard.Attack(g.CurrentTurn, x_i, y_i) var aid, did int aid = g.GetPlayer(id).Id @@ -401,6 +428,12 @@ func (g *Game) PlayerAct(id int, cmd string) *Deck { log.Println(err) return nil } + if pos == -1 { + fmt.Println("no target requested, fizzling effect") + g.QueuedEffect = nil + g.TargetReq = TargetNone + return DeckFromCards(g.GetBoard(board)) + } if pos < 0 || pos >= 3 { fmt.Println("board position out of bounds") return nil @@ -482,6 +515,15 @@ func (g *Game) GetOpponentDeck(id int) *Deck { func (g *Game) GetBoard(id int) []*Card { return g.GameBoard.GetRow(id) } +func (g *Game) GetOpponentBoard(id int) []*Card { + if id == SentinalID { + return g.GameBoard.GetRow(ScourgeID) + } else if id == ScourgeID { + return g.GameBoard.GetRow(SentinalID) + } else { + return nil + } +} func (g *Game) GetGrave(id int) *Deck { if id == SentinalID { diff --git a/oracle.go b/oracle.go index 049ad0a..64218c8 100644 --- a/oracle.go +++ b/oracle.go @@ -15,6 +15,11 @@ func OracleUpkeep(c *Card, g *Game) { g.GameBoard.Remove(c) g.Bury(c) } + case Hologram: + if c.Counters >= 3 { + g.GameBoard.Remove(c) + g.Bury(c) + } default: c.Sick = false } @@ -31,7 +36,7 @@ func OracleSpell(c CardType, g *Game) bool { } func OracleToken(c CardType, g *Game) bool { switch c { - case GoblinSpawn: + case GoblinSpawn, Dud: return true default: return false @@ -54,7 +59,7 @@ func OracleEnters(c *Card, g *Game) { c.Sick = false return case Scholar: - AddPlayerEffect(g.GetPlayer(c.Owner), &Effect{c.Id, uuid.Nil, 2, 1}) + AddPlayerEffect(g.GetPlayer(c.Owner), &Effect{c.Id, uuid.Nil, 2, 1, true}) case ShieldWall, Tree: c.Counters = 0 case HealthPotion: @@ -70,20 +75,27 @@ func OracleEnters(c *Card, g *Game) { } } case Ally: - g.QueuedEffect = &Effect{c.Id, uuid.Nil, 2, 1} + g.QueuedEffect = &Effect{c.Id, uuid.Nil, 2, 1, true} g.TargetReq = TargetOwn case Enemy: - g.QueuedEffect = &Effect{c.Id, uuid.Nil, 2, -1} + g.QueuedEffect = &Effect{c.Id, uuid.Nil, 2, -1, true} g.TargetReq = TargetOpp case Chupacabra: - g.QueuedEffect = &Effect{c.Id, uuid.Nil, 4, 0} + g.QueuedEffect = &Effect{c.Id, uuid.Nil, 4, 0, true} g.TargetReq = TargetOpp case Duelist: - g.QueuedEffect = &Effect{c.Id, uuid.Nil, 6, 1} + g.QueuedEffect = &Effect{c.Id, uuid.Nil, 6, 1, true} g.TargetReq = TargetOwn case Vanguard: - g.QueuedEffect = &Effect{c.Id, uuid.Nil, 7, 1} + g.QueuedEffect = &Effect{c.Id, uuid.Nil, 7, 1, true} g.TargetReq = TargetOwn + case Elephant: + g.QueuedEffect = &Effect{c.Id, uuid.Nil, 9, 0, false} + g.TargetReq = TargetOppEmpty + case Mesmerist: + g.GetOpponentDeck(c.Owner).Shuffle() + case Diviner: + AddPlayerEffect(g.GetPlayer(c.Owner), &Effect{c.Id, uuid.Nil, 3, 2, true}) } } @@ -98,20 +110,20 @@ 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, 1}) + AddEffect(v, &Effect{c.Id, v.Id, 1, 1, true}) } } case Paladin: //+1 around it if c.Position-1 >= 0 { - AddEffect(row[c.Position-1], &Effect{c.Id, row[c.Position-1].Id, 1, 1}) + AddEffect(row[c.Position-1], &Effect{c.Id, row[c.Position-1].Id, 1, 1, true}) } if c.Position+1 <= 3 { - AddEffect(row[c.Position+1], &Effect{c.Id, row[c.Position+1].Id, 1, 1}) + AddEffect(row[c.Position+1], &Effect{c.Id, row[c.Position+1].Id, 1, 1, true}) } case Tree: if c.Counters >= 5 { - AddEffect(row[c.Position], &Effect{c.Id, row[c.Position].Id, 1, 8}) + AddEffect(row[c.Position], &Effect{c.Id, row[c.Position].Id, 1, 8, true}) } } @@ -154,6 +166,8 @@ func OracleEndstep(c *Card, g *Game) { func OraclePower(c CardType, g *Game) int { //this is horrible switch c { + case Dud: + return 0 case Speedster, HealthPotion, Tree, Goblin, GoblinSpawn, Chupacabra: return 1 case Commander, Ally: @@ -162,13 +176,16 @@ func OraclePower(c CardType, g *Game) int { return 3 case Scholar, Vanguard: return 4 - case Warrior: + case Warrior, Elephant: return 5 - case Fighter: + case Fighter, Mesmerist, Diviner: return 6 case Seven: return 7 + case ShieldWall, Hologram: + return 8 default: + log.Printf("played card %v without power in oracle", c) return int(c) } } @@ -187,14 +204,18 @@ func OracleMove(c *Card, src, dest int, g *Game) { } } -func OracleAttack(c *Card, g *Game) { +func OracleAttack(c *Card, src, dest int, g *Game) { c.Sick = true + switch c.Type { + case Hologram: + row := g.GetOpponentBoard(c.Owner) + if row[dest].Type == EmptyValue { + c.Power = 0 + } + } } func OracleEffect(c *Card, g *Game) { - if c.Empty() { - return - } for _, e := range c.Effects { switch e.ID { case 0: @@ -234,7 +255,9 @@ func OracleEffect(c *Card, g *Game) { } else { c.Power = c.Power + e.Modifier } - + case 9: //create dud + RemoveEffect(e.Owner, c) + c = NewCard(int(Dud), c.Owner, c.Position, uuid.Nil) default: log.Println("wrong effect type") } @@ -255,6 +278,10 @@ func OraclePlayerEffect(p *Player, g *Game) { g.CanDraw = true g.HasDrawn = false RemovePlayerEffect(e.Owner, p) + case 3: + g.ScryBuffer = e.Modifier + g.BottomBuffer = e.Modifier - 1 + RemovePlayerEffect(e.Owner, p) } } }