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-01-27 16:43:51 +0100
commitd76655a521807f0aa6fae52de0a231a8531c660b (patch)
tree5013331e315146fdb138f3edb68b5f347885b0ad
parent74ae4f091755544906bb2bb38bd360cc4d7b6237 (diff)
downloadmuhqs-game-d76655a521807f0aa6fae52de0a231a8531c660b.tar.gz
muhqs-game-d76655a521807f0aa6fae52de0a231a8531c660b.zip
validate equip and switch actions
-rw-r--r--go/game/state.go40
1 files changed, 39 insertions, 1 deletions
diff --git a/go/game/state.go b/go/game/state.go
index d98595b4..347b5406 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,40 @@ 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, eTile, 1) {
+ return fmt.Errorf("Can only equip adjacent equipments")
+ }
+
+ return nil
+}
+
+func (s *State) IsValidArtifactSwitch(a *EquipAction) 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)
+ a := a.Artifact
+ aTile := TileOrContainingPermTile(a)
+ if !IsPositionInRange(uTile, aTile, 1) {
+ return fmt.Errorf("Can only switch position with adjacent equipments")
+ }
+
+ if a.Controller() != u.Controller() && a.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 +245,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:
}