From f9ab2cfdb25eb3fcd85868a2e375326a9c8b6022 Mon Sep 17 00:00:00 2001 From: Florian Fischer Date: Wed, 15 Feb 2023 13:13:06 +0100 Subject: intermediate commit * fix a lot of target and action bugs * check target selection before adding it to the prompt * use the store view for stores on the map * fix card highlighting in CardGrid * Only prompt for Upkeep-/DiscardActions if appropriate * Add helper for areaEffects granting new FullActions * Add Target() helper selecting the first target to the Action interface * Fix BuyAction and DiscardAction targets * Remember the stores a player has seen --- go/game/player.go | 63 ++++++++++++++++++++++++++++++++++++++++++++++--------- 1 file changed, 53 insertions(+), 10 deletions(-) (limited to 'go/game/player.go') diff --git a/go/game/player.go b/go/game/player.go index 1215479f..a69f2cd3 100644 --- a/go/game/player.go +++ b/go/game/player.go @@ -24,6 +24,7 @@ type Player struct { gameState *State Color color.Color Ctrl PlayerControl + knownStores map[Position]bool } func NewPlayer(id int, name string, deck *Deck, gameState *State) *Player { @@ -42,6 +43,7 @@ func NewPlayer(id int, name string, deck *Deck, gameState *State) *Player { Store: store, gameState: gameState, Ctrl: nil, + knownStores: make(map[Position]bool), } return &p } @@ -78,15 +80,26 @@ func (p *Player) Upkeep() { // TODO: handle upkeep triggers - for _, unit := range p.gameState.Units { - if unit.controller != p { - continue + // Skip upkeep prompt if player does not controll any units + controllsUnits := false + for _, u := range p.gameState.Units { + if u.Controller() == p { + controllsUnits = true + break } + } + if !controllsUnits { + return + } + + a := prompt(p.Ctrl, newUpkeepPrompt(p)) - // TODO: let players decide if they want to pay the upkeep - p.Resource -= unit.UpkeepCost() - unit.onUpkeep() + if _, ok := a.(*PassPriority); ok { + a = newUpkeepAction(p) } + + p.gameState.DeclareAction(a) + p.gameState.Stack.Resolve() } func (p *Player) ActionPhase() { @@ -102,12 +115,15 @@ func (p *Player) ActionPhase() { func (p *Player) BuyPhase() { a := promptBuy(p.Ctrl) - log.Println(a) + if _, ok := a.(*PassPriority); ok { return } - p.gameState.DeclareAction(a) - p.gameState.Stack.Resolve() + + if a.Targets().HasSelections() { + p.gameState.DeclareAction(a) + p.gameState.Stack.Resolve() + } } func (p *Player) discardHand() { @@ -121,6 +137,10 @@ func (p *Player) DiscardCard(c *Card) { } func (p *Player) DiscardPhase() { + if p.Hand.Size() == 0 { + return + } + cards := p.PromptHandCardSelection(0, p.Hand.Size()) for _, c := range cards { p.DiscardCard(c) @@ -136,7 +156,7 @@ func (p *Player) PromptHandCardSelection(min, max int) []*Card { log.Fatalf("Invalid hand card selection: %v", err) } - return utils.InterfaceSliceToTypedSlice[*Card](a.Targets().ts[0].sel) + return utils.InterfaceSliceToTypedSlice[*Card](a.Target().sel) case *PassPriority: return nil default: @@ -163,3 +183,26 @@ func (p *Player) IsEnemy(other *Player) bool { // TODO: support coop / teams return p != other } + +func (p *Player) AvailableStores() (stores []*Store) { + m := p.gameState.Map + for pos, store := range m.Stores { + t := m.TileAt(pos) + if t.Permanent != nil && t.Permanent.Controller() == p { + stores = append(stores, store) + } + } + return +} + +func (p *Player) KnowsStore(pos Position) bool { + return p.knownStores[pos] +} + +func (p *Player) addKnownStore(pos Position) { + p.knownStores[pos] = true +} + +func (p *Player) clearKnownStore() { + p.knownStores = make(map[Position]bool) +} -- cgit v1.2.3