aboutsummaryrefslogtreecommitdiff
path: root/go/game/state.go
diff options
context:
space:
mode:
authorFlorian Fischer <florian.fischer@muhq.space>2023-02-08 17:50:10 +0100
committerFlorian Fischer <florian.fischer@muhq.space>2025-08-20 15:50:10 +0200
commit45df9bf319d38db916ca983b8c92bb912f5ce9ee (patch)
treed7966002dad4a20bc3ef385bd152554fe278a6df /go/game/state.go
parenteb10f6f4940ecd09fd7d881fe5e1735ff146f919 (diff)
downloadmuhqs-game-45df9bf319d38db916ca983b8c92bb912f5ce9ee.tar.gz
muhqs-game-45df9bf319d38db916ca983b8c92bb912f5ce9ee.zip
intermediate commit
Diffstat (limited to 'go/game/state.go')
-rw-r--r--go/game/state.go48
1 files changed, 31 insertions, 17 deletions
diff --git a/go/game/state.go b/go/game/state.go
index 98ac9c31..5c2fd053 100644
--- a/go/game/state.go
+++ b/go/game/state.go
@@ -111,7 +111,7 @@ func (s *State) IsValidPlay(a *PlayAction) error {
}
if a.Card.IsPermanent() {
- spawn := a.Targets().sel[0].(*Tile)
+ spawn := a.Target().sel[0].(*Tile)
if !slices.Contains(s.AvailableSpawnTiles(a.Source().(*Player), a.Card), spawn) {
return fmt.Errorf("Spawn %v is not a valid spawn tile for %s",
spawn.Position.String(), a.Card.Name)
@@ -127,7 +127,7 @@ func (s *State) IsValidMove(a *MoveAction) error {
}
u := a.Source().(*Unit)
- tile := relaxedTileTarget(a, a.Targets().sel[0])
+ tile := relaxedTileTarget(a, a.Target().sel[0])
if !slices.Contains(u.MoveRangeTiles(s.Map), tile) {
return fmt.Errorf("Unit %s@%v can not move to %s",
@@ -152,7 +152,7 @@ func (s *State) IsValidAttack(a *AttackAction) error {
return fmt.Errorf("%s can not attack", unit.card.Name)
}
- target := a.Targets().sel[0].(Permanent)
+ target := a.Target().sel[0].(Permanent)
if !IsPositionInRange(unit.tile.Position, target.Tile().Position, unit.Attack.MaxRange()) {
return fmt.Errorf("Attack target on %s is not in attack range %d of %s on %s",
target.Tile().Position.String(), unit.Attack.MaxRange(), unit.card.Name,
@@ -163,16 +163,17 @@ func (s *State) IsValidAttack(a *AttackAction) error {
}
func (s *State) isValidBuy(a *BuyAction) error {
+ card := a.card()
if s.Map.HasStores() {
var storeTiles []*Tile
for pos, store := range s.Map.Stores {
- if slices.Contains(store.cards, a.card) {
+ if slices.Contains(store.cards, card) {
storeTiles = append(storeTiles, s.Map.TileAt(pos))
}
}
if storeTiles == nil {
- return fmt.Errorf("no store contains %s", a.card.Name)
+ return fmt.Errorf("no store contains %s", card.Name)
}
controlsUnitOnStore := false
@@ -183,11 +184,15 @@ func (s *State) isValidBuy(a *BuyAction) error {
}
if !controlsUnitOnStore {
return fmt.Errorf("%s' controls no unit on a store containing %s",
- a.player.Name, a.card.Name)
+ a.player.Name, card.Name)
}
- } else if !slices.Contains(a.player.Store.cards, a.card) {
- return fmt.Errorf("%s's store does not contain %s", a.player.Name, a.card.Name)
+ } else if !slices.Contains(a.player.Store.cards, card) {
+ return fmt.Errorf("%s's store does not contain %s", a.player.Name, card.Name)
+ }
+
+ if !a.card().IsBuyable() {
+ return fmt.Errorf("Card %s is not buyable", card.Name)
}
return nil
@@ -226,14 +231,11 @@ func (s *State) DeclareAction(a Action) {
err = a.CheckTargets(s)
if err != nil {
- switch a := a.(type) {
+ switch a.(type) {
case *BuyAction:
if s.ActivePhase != Phases.BuyPhase {
err = fmt.Errorf("Cards can only be bought during one's buy phase")
}
- if !a.card.IsBuyable() {
- err = fmt.Errorf("Card %s is not buyable", a.card.Name)
- }
case *FreeAction:
default:
if !s.Stack.IsEmpty() {
@@ -249,7 +251,7 @@ func (s *State) DeclareAction(a Action) {
s.pushAction(a)
}
- s.broadcastNotification(NewDeclaredActionNotification(a, err))
+ s.broadcastNotification(newDeclaredActionNotification(a, err))
}
func (s *State) AllPassing(skipFirst bool) bool {
@@ -260,7 +262,7 @@ func (s *State) AllPassing(skipFirst bool) bool {
}
for ; i < nPlayers; i++ {
p := s.Players[(i+s.ActivePlayer.Id-1)%nPlayers]
- p.Ctrl.SendNotification(NewPriorityNotification())
+ p.Ctrl.SendNotification(newPriorityNotification())
a := p.Ctrl.RecvAction()
switch a.(type) {
case *PassPriority:
@@ -385,13 +387,13 @@ func (s *State) EnemyUnits(player *Player) []*Unit {
func (s *State) resolvePlay(p *Player, c *Card, targets *Targets) {
switch c.Type {
case CardTypes.Unit:
- tile := targets.sel[0].(*Tile)
+ tile := targets.ts[0].sel[0].(*Tile)
s.AddNewUnit(c, tile.Position, p)
case CardTypes.Artifact:
- tile := targets.sel[0].(*Tile)
+ tile := targets.ts[0].sel[0].(*Tile)
s.AddNewArtifact(c, tile.Position, p)
case CardTypes.Equipment:
- if tile, ok := targets.sel[0].(*Tile); ok {
+ if tile, ok := targets.ts[0].sel[0].(*Tile); ok {
s.addNewEquipment(c, tile.Position, p)
}
case CardTypes.Spell:
@@ -469,3 +471,15 @@ func (s *State) AvailableSpawnTiles(p *Player, c *Card) []*Tile {
return tiles
}
+
+func (s *State) redistributeMapStoreCards() {
+ poc := NewPileOfCards()
+ for _, store := range s.Map.Stores {
+ store.MoveInto(poc)
+ }
+ s.Map.distributeStoreCards(poc, s.Rand)
+
+ for _, p := range s.Players {
+ p.clearKnownStore()
+ }
+}