aboutsummaryrefslogtreecommitdiff
path: root/go/game/player.go
diff options
context:
space:
mode:
authorFlorian Fischer <florian.fischer@muhq.space>2023-02-15 13:13:06 +0100
committerFlorian Fischer <florian.fischer@muhq.space>2025-01-27 16:43:49 +0100
commitf9ab2cfdb25eb3fcd85868a2e375326a9c8b6022 (patch)
treeb96f16e6cf4a6dcf93b9557a7219179ab2f46c8d /go/game/player.go
parent805cbf397589e5cb861f866713c2eb4bec9ce40b (diff)
downloadmuhqs-game-f9ab2cfdb25eb3fcd85868a2e375326a9c8b6022.tar.gz
muhqs-game-f9ab2cfdb25eb3fcd85868a2e375326a9c8b6022.zip
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
Diffstat (limited to 'go/game/player.go')
-rw-r--r--go/game/player.go63
1 files changed, 53 insertions, 10 deletions
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)
+}