Skip to content

Commit

Permalink
* extend GetTechs for lfBuildings
Browse files Browse the repository at this point in the history
  • Loading branch information
faunX authored and faunX committed Sep 15, 2022
1 parent 562f683 commit 8c963f5
Show file tree
Hide file tree
Showing 11 changed files with 60 additions and 28 deletions.
2 changes: 1 addition & 1 deletion pkg/extractor/extractor.go
Original file line number Diff line number Diff line change
Expand Up @@ -356,7 +356,7 @@ type TraderImportExportExtractorDoc interface {

// FetchTechsExtractorBytes ajax page fetchTechs
type FetchTechsExtractorBytes interface {
ExtractTechs(pageHTML []byte) (ogame.ResourcesBuildings, ogame.Facilities, ogame.ShipsInfos, ogame.DefensesInfos, ogame.Researches, error)
ExtractTechs(pageHTML []byte) (ogame.ResourcesBuildings, ogame.Facilities, ogame.ShipsInfos, ogame.DefensesInfos, ogame.Researches, ogame.LfBuildings, error)
}

type ResourcesSettingsExtractorBytes interface {
Expand Down
2 changes: 1 addition & 1 deletion pkg/extractor/v6/extractor.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ func (e *Extractor) ExtractPremiumToken(pageHTML []byte, days int64) (string, er
}

// ExtractTechs ...
func (e *Extractor) ExtractTechs(pageHTML []byte) (ogame.ResourcesBuildings, ogame.Facilities, ogame.ShipsInfos, ogame.DefensesInfos, ogame.Researches, error) {
func (e *Extractor) ExtractTechs(pageHTML []byte) (ogame.ResourcesBuildings, ogame.Facilities, ogame.ShipsInfos, ogame.DefensesInfos, ogame.Researches, ogame.LfBuildings, error) {
panic("implement me")
}

Expand Down
5 changes: 3 additions & 2 deletions pkg/extractor/v71/extractor.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,10 @@ package v71

import (
"bytes"

"github.com/PuerkitoBio/goquery"
"github.com/alaingilbert/clockwork"
"github.com/alaingilbert/ogame/pkg/extractor/v7"
v7 "github.com/alaingilbert/ogame/pkg/extractor/v7"
"github.com/alaingilbert/ogame/pkg/ogame"
)

Expand Down Expand Up @@ -46,7 +47,7 @@ func (e *Extractor) ExtractResourcesDetails(pageHTML []byte) (out ogame.Resource
}

// ExtractTechs ...
func (e *Extractor) ExtractTechs(pageHTML []byte) (ogame.ResourcesBuildings, ogame.Facilities, ogame.ShipsInfos, ogame.DefensesInfos, ogame.Researches, error) {
func (e *Extractor) ExtractTechs(pageHTML []byte) (ogame.ResourcesBuildings, ogame.Facilities, ogame.ShipsInfos, ogame.DefensesInfos, ogame.Researches, ogame.LfBuildings, error) {
return extractTechs(pageHTML)
}

Expand Down
41 changes: 35 additions & 6 deletions pkg/extractor/v71/extracts.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,17 @@ import (
"encoding/json"
"errors"
"fmt"
"github.com/alaingilbert/ogame/pkg/extractor/v6"
"github.com/alaingilbert/ogame/pkg/extractor/v7"
"github.com/alaingilbert/ogame/pkg/ogame"
"github.com/alaingilbert/ogame/pkg/utils"
"math"
"regexp"
"strconv"
"strings"
"time"

v6 "github.com/alaingilbert/ogame/pkg/extractor/v6"
v7 "github.com/alaingilbert/ogame/pkg/extractor/v7"
"github.com/alaingilbert/ogame/pkg/ogame"
"github.com/alaingilbert/ogame/pkg/utils"

"github.com/PuerkitoBio/goquery"
"github.com/alaingilbert/clockwork"
"golang.org/x/net/html"
Expand Down Expand Up @@ -249,13 +250,27 @@ type planetTechsResp struct {
Num408 int64 `json:"408"`
Num502 int64 `json:"502"`
Num503 int64 `json:"503"`

// LFbuildings
Num11101 int64 `json:"11101"`
Num11102 int64 `json:"11102"`
Num11103 int64 `json:"11103"`
Num11104 int64 `json:"11104"`
Num11105 int64 `json:"11105"`
Num11106 int64 `json:"11106"`
Num11107 int64 `json:"11107"`
Num11108 int64 `json:"11108"`
Num11109 int64 `json:"11109"`
Num11110 int64 `json:"11110"`
Num11111 int64 `json:"11111"`
Num11112 int64 `json:"11112"`
}

func extractTechs(pageHTML []byte) (supplies ogame.ResourcesBuildings, facilities ogame.Facilities, shipsInfos ogame.ShipsInfos, defenses ogame.DefensesInfos, researches ogame.Researches, err error) {
func extractTechs(pageHTML []byte) (supplies ogame.ResourcesBuildings, facilities ogame.Facilities, shipsInfos ogame.ShipsInfos, defenses ogame.DefensesInfos, researches ogame.Researches, lfBuildings ogame.LfBuildings, err error) {
var res planetTechsResp
if err = json.Unmarshal(pageHTML, &res); err != nil {
if v6.IsLogged(pageHTML) {
return supplies, facilities, shipsInfos, defenses, researches, ogame.ErrInvalidPlanetID
return supplies, facilities, shipsInfos, defenses, researches, lfBuildings, ogame.ErrInvalidPlanetID
}
return
}
Expand Down Expand Up @@ -332,6 +347,20 @@ func extractTechs(pageHTML []byte) (supplies ogame.ResourcesBuildings, facilitie
ShieldingTechnology: res.Num110,
ArmourTechnology: res.Num111,
}
lfBuildings = ogame.LfBuildings{
ResidentialSector: res.Num11101,
BiosphereFarm: res.Num11102,
ResearchCentre: res.Num11103,
AcademyOfSciences: res.Num11104,
NeuroCalibrationCentre: res.Num11105,
HighEnergySmelting: res.Num11106,
FoodSilo: res.Num11107,
FusionPoweredProduction: res.Num11108,
Skyscraper: res.Num11109,
BiotechLab: res.Num11110,
Metropolis: res.Num11111,
PlanetaryShield: res.Num11112,
}
return
}

Expand Down
2 changes: 1 addition & 1 deletion pkg/parser/fetchTechsAjaxPage.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,6 @@ package parser

import "github.com/alaingilbert/ogame/pkg/ogame"

func (p FetchTechsAjaxPage) ExtractTechs() (ogame.ResourcesBuildings, ogame.Facilities, ogame.ShipsInfos, ogame.DefensesInfos, ogame.Researches, error) {
func (p FetchTechsAjaxPage) ExtractTechs() (ogame.ResourcesBuildings, ogame.Facilities, ogame.ShipsInfos, ogame.DefensesInfos, ogame.Researches, ogame.LfBuildings, error) {
return p.e.ExtractTechs(p.content)
}
20 changes: 11 additions & 9 deletions pkg/wrapper/handlers.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,13 @@ import (
"encoding/base64"
"errors"
"fmt"
"github.com/alaingilbert/ogame/pkg/ogame"
"github.com/alaingilbert/ogame/pkg/utils"
echo "github.com/labstack/echo/v4"
"net/http"
"net/url"
"strings"

"github.com/alaingilbert/ogame/pkg/ogame"
"github.com/alaingilbert/ogame/pkg/utils"
echo "github.com/labstack/echo/v4"
)

// APIResp ...
Expand Down Expand Up @@ -1294,16 +1295,17 @@ func TechsHandler(c echo.Context) error {
if err != nil {
return c.JSON(http.StatusBadRequest, ErrorResp(400, "invalid celestial id"))
}
supplies, facilities, ships, defenses, researches, err := bot.GetTechs(ogame.CelestialID(celestialID))
supplies, facilities, ships, defenses, researches, lfbuildings, err := bot.GetTechs(ogame.CelestialID(celestialID))
if err != nil {
return c.JSON(http.StatusBadRequest, ErrorResp(400, err.Error()))
}
return c.JSON(http.StatusOK, SuccessResp(map[string]any{
"supplies": supplies,
"facilities": facilities,
"ships": ships,
"defenses": defenses,
"researches": researches,
"supplies": supplies,
"facilities": facilities,
"ships": ships,
"defenses": defenses,
"researches": researches,
"lfbuildings": lfbuildings,
}))
}

Expand Down
4 changes: 2 additions & 2 deletions pkg/wrapper/interfaces.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ type Celestial interface {
SendFleet([]ogame.Quantifiable, ogame.Speed, ogame.Coordinate, ogame.MissionID, ogame.Resources, int64, int64) (ogame.Fleet, error)
TearDown(buildingID ogame.ID) error
GetLfBuildings(...Option) (ogame.LfBuildings, error)
GetTechs() (ogame.ResourcesBuildings, ogame.Facilities, ogame.ShipsInfos, ogame.DefensesInfos, ogame.Researches, error)
GetTechs() (ogame.ResourcesBuildings, ogame.Facilities, ogame.ShipsInfos, ogame.DefensesInfos, ogame.Researches, ogame.LfBuildings, error)
}

// Prioritizable list of all actions that needs to communicate with ogame server.
Expand Down Expand Up @@ -125,7 +125,7 @@ type Prioritizable interface {
GetResourcesBuildings(ogame.CelestialID, ...Option) (ogame.ResourcesBuildings, error)
GetResourcesDetails(ogame.CelestialID) (ogame.ResourcesDetails, error)
GetShips(ogame.CelestialID, ...Option) (ogame.ShipsInfos, error)
GetTechs(celestialID ogame.CelestialID) (ogame.ResourcesBuildings, ogame.Facilities, ogame.ShipsInfos, ogame.DefensesInfos, ogame.Researches, error)
GetTechs(celestialID ogame.CelestialID) (ogame.ResourcesBuildings, ogame.Facilities, ogame.ShipsInfos, ogame.DefensesInfos, ogame.Researches, ogame.LfBuildings, error)
SendFleet(celestialID ogame.CelestialID, ships []ogame.Quantifiable, speed ogame.Speed, where ogame.Coordinate, mission ogame.MissionID, resources ogame.Resources, holdingTime, unionID int64) (ogame.Fleet, error)
TearDown(celestialID ogame.CelestialID, id ogame.ID) error
GetLfBuildings(ogame.CelestialID, ...Option) (ogame.LfBuildings, error)
Expand Down
2 changes: 1 addition & 1 deletion pkg/wrapper/moon.go
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,6 @@ func (m Moon) GetLfBuildings(options ...Option) (ogame.LfBuildings, error) {
}

// GetTechs gets (ogame.ResourcesBuildings, ogame.Facilities, ogame.ShipsInfos, ogame.DefensesInfos, ogame.Researches)
func (m Moon) GetTechs() (ogame.ResourcesBuildings, ogame.Facilities, ogame.ShipsInfos, ogame.DefensesInfos, ogame.Researches, error) {
func (m Moon) GetTechs() (ogame.ResourcesBuildings, ogame.Facilities, ogame.ShipsInfos, ogame.DefensesInfos, ogame.Researches, ogame.LfBuildings, error) {
return m.ogame.GetTechs(m.ID.Celestial())
}
6 changes: 3 additions & 3 deletions pkg/wrapper/ogame.go
Original file line number Diff line number Diff line change
Expand Up @@ -2915,11 +2915,11 @@ func (b *OGame) getFacilities(celestialID ogame.CelestialID, options ...Option)
return page.ExtractFacilities()
}

func (b *OGame) getTechs(celestialID ogame.CelestialID) (ogame.ResourcesBuildings, ogame.Facilities, ogame.ShipsInfos, ogame.DefensesInfos, ogame.Researches, error) {
func (b *OGame) getTechs(celestialID ogame.CelestialID) (ogame.ResourcesBuildings, ogame.Facilities, ogame.ShipsInfos, ogame.DefensesInfos, ogame.Researches, ogame.LfBuildings, error) {
vals := url.Values{"page": {FetchTechsName}}
page, err := getAjaxPage[parser.FetchTechsAjaxPage](b, vals, ChangePlanet(celestialID))
if err != nil {
return ogame.ResourcesBuildings{}, ogame.Facilities{}, ogame.ShipsInfos{}, ogame.DefensesInfos{}, ogame.Researches{}, err
return ogame.ResourcesBuildings{}, ogame.Facilities{}, ogame.ShipsInfos{}, ogame.DefensesInfos{}, ogame.Researches{}, ogame.LfBuildings{}, err
}
return page.ExtractTechs()
}
Expand Down Expand Up @@ -4544,7 +4544,7 @@ func (b *OGame) GetResourcesDetails(celestialID ogame.CelestialID) (ogame.Resour
}

// GetTechs gets a celestial supplies/facilities/ships/researches
func (b *OGame) GetTechs(celestialID ogame.CelestialID) (ogame.ResourcesBuildings, ogame.Facilities, ogame.ShipsInfos, ogame.DefensesInfos, ogame.Researches, error) {
func (b *OGame) GetTechs(celestialID ogame.CelestialID) (ogame.ResourcesBuildings, ogame.Facilities, ogame.ShipsInfos, ogame.DefensesInfos, ogame.Researches, ogame.LfBuildings, error) {
return b.WithPriority(taskRunner.Normal).GetTechs(celestialID)
}

Expand Down
2 changes: 1 addition & 1 deletion pkg/wrapper/planet.go
Original file line number Diff line number Diff line change
Expand Up @@ -159,6 +159,6 @@ func (p Planet) GetLfBuildings(options ...Option) (ogame.LfBuildings, error) {
}

// GetTechs gets (ogame.ResourcesBuildings, ogame.Facilities, ogame.ShipsInfos, ogame.DefensesInfos, ogame.Researches)
func (p Planet) GetTechs() (ogame.ResourcesBuildings, ogame.Facilities, ogame.ShipsInfos, ogame.DefensesInfos, ogame.Researches, error) {
func (p Planet) GetTechs() (ogame.ResourcesBuildings, ogame.Facilities, ogame.ShipsInfos, ogame.DefensesInfos, ogame.Researches, ogame.LfBuildings, error) {
return p.ogame.GetTechs(p.ID.Celestial())
}
2 changes: 1 addition & 1 deletion pkg/wrapper/prioritize.go
Original file line number Diff line number Diff line change
Expand Up @@ -426,7 +426,7 @@ func (b *Prioritize) GetResourcesDetails(celestialID ogame.CelestialID) (ogame.R
}

// GetTechs gets a celestial supplies/facilities/ships/researches
func (b *Prioritize) GetTechs(celestialID ogame.CelestialID) (ogame.ResourcesBuildings, ogame.Facilities, ogame.ShipsInfos, ogame.DefensesInfos, ogame.Researches, error) {
func (b *Prioritize) GetTechs(celestialID ogame.CelestialID) (ogame.ResourcesBuildings, ogame.Facilities, ogame.ShipsInfos, ogame.DefensesInfos, ogame.Researches, ogame.LfBuildings, error) {
b.begin("GetTechs")
defer b.done()
return b.bot.getTechs(celestialID)
Expand Down

0 comments on commit 8c963f5

Please sign in to comment.