aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorFlorian Fischer <florian.fischer@muhq.space>2023-02-21 09:03:32 +0100
committerFlorian Fischer <florian.fischer@muhq.space>2025-08-20 15:52:12 +0200
commitcd720b439d647b843a13182cc2fdac5ad4ddbb12 (patch)
tree8a384b6a12aebf51b17dd8fc726d02a448bb4e51
parent2c1c5090b59079f4ce74ac40985ea993a5389a39 (diff)
downloadmuhqs-game-cd720b439d647b843a13182cc2fdac5ad4ddbb12.tar.gz
muhqs-game-cd720b439d647b843a13182cc2fdac5ad4ddbb12.zip
validate equip and switch actions
-rw-r--r--go/game/state.go41
1 files changed, 40 insertions, 1 deletions
diff --git a/go/game/state.go b/go/game/state.go
index d98595b4..0ef8c4d4 100644
--- a/go/game/state.go
+++ b/go/game/state.go
@@ -107,7 +107,7 @@ func (s *State) stateBasedActions() {
func (s *State) IsValidPlay(a *PlayAction) error {
if s.ActivePhase != Phases.ActionPhase {
- log.Panicf("Play actions can only be declared during one's actions phase")
+ return fmt.Errorf("Play actions can only be declared during one's actions phase")
}
if a.Card.IsPermanent() {
@@ -198,6 +198,41 @@ func (s *State) isValidBuy(a *BuyAction) error {
return nil
}
+func (s *State) IsValidEquip(a *EquipAction) error {
+ if s.ActivePhase != Phases.ActionPhase {
+ return fmt.Errorf("Play actions can only be declared during one's actions phase")
+ }
+
+ uTile := TileOrContainingPermTile(a.Source().(*Unit))
+ eTile := TileOrContainingPermTile(a.equipment)
+ if !IsPositionInRange(uTile.Position, eTile.Position, 1) {
+ return fmt.Errorf("Can only equip adjacent equipments")
+ }
+
+ return nil
+}
+
+func (s *State) IsValidArtifactSwitch(a *ArtifactSwitchAction) error {
+ if s.ActivePhase != Phases.ActionPhase {
+ return fmt.Errorf("Play actions can only be declared during one's actions phase")
+ }
+
+ u := a.Source().(*Unit)
+ uTile := TileOrContainingPermTile(u)
+ artifact := a.Artifact
+ aTile := TileOrContainingPermTile(artifact)
+ if !IsPositionInRange(uTile.Position, aTile.Position, 1) {
+ return fmt.Errorf("Can only switch position with adjacent equipments")
+ }
+
+ solid, err := artifact.XEffect("solid")
+ if err != nil && artifact.Controller() != u.Controller() && solid > 0 {
+ return fmt.Errorf("Can only switch with solid artifacts you control")
+ }
+
+ return nil
+}
+
func (s *State) ValidateAction(a Action) (err error) {
err = a.CheckTargets(s)
if err != nil {
@@ -211,6 +246,10 @@ func (s *State) ValidateAction(a Action) (err error) {
err = s.IsValidMove(a)
case *AttackAction:
err = s.IsValidAttack(a)
+ case *EquipAction:
+ err = s.IsValidEquip(a)
+ case *ArtifactSwitchAction:
+ err = s.IsValidArtifactSwitch(a)
case *BuyAction:
}