From cd720b439d647b843a13182cc2fdac5ad4ddbb12 Mon Sep 17 00:00:00 2001 From: Florian Fischer Date: Tue, 21 Feb 2023 09:03:32 +0100 Subject: validate equip and switch actions --- go/game/state.go | 41 ++++++++++++++++++++++++++++++++++++++++- 1 file changed, 40 insertions(+), 1 deletion(-) 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: } -- cgit v1.2.3