Ally/War commands

This commit is contained in:
Ilia Denisov
2025-09-28 22:43:27 +03:00
parent 6510676237
commit 128d6862a7
14 changed files with 315 additions and 74 deletions
+32
View File
@@ -0,0 +1,32 @@
package game
import "github.com/iliadenisov/galaxy/pkg/model/game"
func DeclareWar(configure func(*Param), from, to string) (err error) {
control(configure, func(c *ctrl) { c.execute(func(r Repo) { err = updateRelation(r, from, to, game.RelationWar) }) })
return
}
func DeclarePeace(configure func(*Param), from, to string) (err error) {
control(configure, func(c *ctrl) { c.execute(func(r Repo) { err = updateRelation(r, from, to, game.RelationPeace) }) })
return
}
func updateRelation(r Repo, hostRace, opponentRace string, rel game.Relation) error {
g, err := r.LoadState()
if err != nil {
return err
}
hostID, err := g.HostRaceID(hostRace)
if err != nil {
return err
}
opponentID, err := g.OpponentRaceID(opponentRace)
if err != nil {
return err
}
if err := g.UpdateRelation(hostID, opponentID, rel); err != nil {
return err
}
return r.SaveState(g)
}