refactor: group uuid instead of index
This commit is contained in:
@@ -5,15 +5,16 @@ import (
|
||||
"slices"
|
||||
"strings"
|
||||
|
||||
"github.com/google/uuid"
|
||||
e "github.com/iliadenisov/galaxy/internal/error"
|
||||
"github.com/iliadenisov/galaxy/internal/model/game"
|
||||
)
|
||||
|
||||
func (c *Cache) shipGroupUpgrade(ri int, groupIndex uint, techInput string, limitShips uint, limitLevel float64) error {
|
||||
func (c *Cache) shipGroupUpgrade(ri int, groupID uuid.UUID, techInput string, limitShips uint, limitLevel float64) error {
|
||||
c.validateRaceIndex(ri)
|
||||
sgi, ok := c.raceShipGroupIndex(ri, groupIndex)
|
||||
sgi, ok := c.raceShipGroupIndex(ri, groupID)
|
||||
if !ok {
|
||||
return e.NewEntityNotExistsError("group #%d", groupIndex)
|
||||
return e.NewEntityNotExistsError("group %s", groupID)
|
||||
}
|
||||
st := c.ShipGroupShipClass(sgi)
|
||||
sg := c.ShipGroup(sgi)
|
||||
@@ -24,7 +25,7 @@ func (c *Cache) shipGroupUpgrade(ri int, groupIndex uint, techInput string, limi
|
||||
|
||||
p := c.MustPlanet(sg.Destination)
|
||||
if p.Owned() && !p.OwnedBy(c.g.Race[ri].ID) {
|
||||
return e.NewEntityNotOwnedError("planet #%d for upgrade group #%d", p.Number, groupIndex)
|
||||
return e.NewEntityNotOwnedError("planet #%d for upgrade group %s", p.Number, groupID)
|
||||
}
|
||||
|
||||
upgradeValidTech := map[string]game.Tech{
|
||||
@@ -117,7 +118,7 @@ func (c *Cache) shipGroupUpgrade(ri int, groupIndex uint, techInput string, limi
|
||||
|
||||
// break group if needed
|
||||
if maxUpgradableShips < sg.Number {
|
||||
nsgi, err := c.breakGroupSafe(ri, groupIndex, maxUpgradableShips)
|
||||
nsgi, err := c.breakGroupSafe(ri, groupID, maxUpgradableShips)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user