From 3d36d1d0254b8aeecc889a2a49cbcced458cbe9c Mon Sep 17 00:00:00 2001 From: Florian Fischer Date: Sat, 25 Feb 2023 23:08:47 +0100 Subject: intermediate commit * Implement move artifact action * Fix widget update memory leak * update the highlights not during on each frame * do not update the unchanged label of a button * Allow to exit the game by pressing 'q' * Implement some cards from the magic set * Improve permanent formatting * Some tweaks to UnitAI code --- go/game/state.go | 43 +++++++++++++++++++++++++++++++++++++++---- 1 file changed, 39 insertions(+), 4 deletions(-) (limited to 'go/game/state.go') diff --git a/go/game/state.go b/go/game/state.go index 82dccf15..604e4530 100644 --- a/go/game/state.go +++ b/go/game/state.go @@ -25,6 +25,7 @@ type State struct { Permanents []Permanent Units []*Unit Rand *rand.Rand + EotEffects []effect } func NewState() *State { @@ -88,6 +89,8 @@ func (s *State) Loop() []*Player { s.ActivePhase = Phases.DiscardPhase p.discardPhase() + s.endOfTurn() + winners = s.Map.WinCondition(s) } } @@ -233,6 +236,27 @@ func (s *State) IsValidArtifactSwitch(a *ArtifactSwitchAction) error { return nil } +func (s *State) IsValidArtifactMove(a *ArtifactMoveAction) 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 { @@ -250,6 +274,8 @@ func (s *State) ValidateAction(a Action) (err error) { err = s.IsValidEquip(a) case *ArtifactSwitchAction: err = s.IsValidArtifactSwitch(a) + case *ArtifactMoveAction: + err = s.IsValidArtifactMove(a) case *BuyAction: } @@ -407,10 +433,6 @@ func (s *State) fight(p1, p2 Permanent) { p2.fight(p1) } -func (s *State) MoveUnit(u *Unit, t *Tile) { - u.move(s, t) -} - func (s *State) switchPermanents(p1 Permanent, p2 Permanent) { t1 := TileOrContainingPermTile(p1) t2 := TileOrContainingPermTile(p2) @@ -555,3 +577,16 @@ func (s *State) redistributeMapStoreCards() { p.clearKnownStore() } } + +func (s *State) addEotEffect(e effect) { + e.apply(s) + s.EotEffects = append(s.EotEffects, e) +} + +func (s *State) endOfTurn() { + for _, e := range s.EotEffects { + e.end(s) + } + + s.EotEffects = []effect{} +} -- cgit v1.2.3