32 lines
953 B
Go
32 lines
953 B
Go
package game
|
|
|
|
import (
|
|
"github.com/iliadenisov/galaxy/internal/controller"
|
|
"github.com/iliadenisov/galaxy/internal/model/game"
|
|
)
|
|
|
|
func DeclareWar(configure func(*controller.Param), from, to string) (err error) {
|
|
err = control(configure, func(c *controller.Controller) error {
|
|
return c.ExecuteCommand(func(r controller.Repo, g *game.Game) error {
|
|
return updateRelation(c, from, to, game.RelationWar)
|
|
})
|
|
})
|
|
return
|
|
}
|
|
|
|
func DeclarePeace(configure func(*controller.Param), from, to string) (err error) {
|
|
err = control(configure, func(c *controller.Controller) error {
|
|
return c.ExecuteCommand(func(r controller.Repo, g *game.Game) error {
|
|
return updateRelation(c, from, to, game.RelationPeace)
|
|
})
|
|
})
|
|
return
|
|
}
|
|
|
|
func updateRelation(c *controller.Controller, hostRace, opponentRace string, rel game.Relation) error {
|
|
if err := c.UpdateRelation(hostRace, opponentRace, rel); err != nil {
|
|
return err
|
|
}
|
|
return nil // r.SaveLastState(g)
|
|
}
|