Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improvement for Sendfleet #66

Open
wants to merge 1 commit into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 9 additions & 1 deletion handlers.go
Original file line number Diff line number Diff line change
Expand Up @@ -773,6 +773,7 @@ func SendFleetHandler(c echo.Context) error {
var unionID int64
payload := Resources{}
speed := HundredPercent
ensure := false
for key, values := range c.Request().PostForm {
switch key {
case "ships":
Expand Down Expand Up @@ -852,10 +853,17 @@ func SendFleetHandler(c echo.Context) error {
return c.JSON(http.StatusBadRequest, ErrorResp(400, "invalid deuterium"))
}
payload.Deuterium = deuterium
case "ensure":
ensure, _ = strconv.ParseBool(values[0])
}
}

fleet, err := bot.SendFleet(CelestialID(planetID), ships, speed, where, mission, payload, duration, unionID)
var fleet interface{}
if ensure {
fleet, err = bot.EnsureFleet(CelestialID(planetID), ships, speed, where, mission, payload, duration, unionID)
} else {
fleet, err = bot.SendFleet(CelestialID(planetID), ships, speed, where, mission, payload, duration, unionID)
}
if err != nil &&
(err == ErrInvalidPlanetID ||
err == ErrNoShipSelected ||
Expand Down
11 changes: 10 additions & 1 deletion ogame.go
Original file line number Diff line number Diff line change
Expand Up @@ -2790,6 +2790,11 @@ type CheckTargetResponse struct {
Type int `json:"type"`
Name string `json:"name"`
} `json:"targetPlanet"`
Errors *struct {
Message string `json:"message"`
Error int `json:"error"`

} `json:"errors"`
TargetOk bool `json:"targetOk"`
Components []interface{} `json:"components"`
}
Expand Down Expand Up @@ -2935,6 +2940,10 @@ func (b *OGame) sendFleetV7(celestialID CelestialID, ships []Quantifiable, speed
}

if !checkRes.TargetOk {
if len(checkRes.Errors.Message) > 0 {
return Fleet{}, errors.New(checkRes.Errors.Message)
}

return Fleet{}, errors.New("target is not ok")
}

Expand Down Expand Up @@ -3330,7 +3339,7 @@ func (b *OGame) sendFleetV6(celestialID CelestialID, ships []Quantifiable, speed
// EspionageReportType type of espionage report (action or report)
type EspionageReportType int

// Action message received when an enemy is seen naer your planet
// Action message received when an enemy is seen near your planet
const Action EspionageReportType = 0

// Report message received when you spied on someone
Expand Down