Skip to content

Commit

Permalink
Extract ACS info
Browse files Browse the repository at this point in the history
  • Loading branch information
alaingilbert committed Aug 22, 2022
1 parent 87d8908 commit 3c006f7
Show file tree
Hide file tree
Showing 5 changed files with 53 additions and 13 deletions.
3 changes: 2 additions & 1 deletion pkg/extractor/extractor.go
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,7 @@ type FleetDispatchExtractorBytes interface {
type FleetDispatchExtractorDoc interface {
FleetsExtractorBytes
ExtractFleet1ShipsFromDoc(doc *goquery.Document) (s ogame.ShipsInfos)
ExtractFleetDispatchACSFromDoc(doc *goquery.Document) []ogame.ACSValues
}

type FleetDispatchExtractorBytesDoc interface {
Expand Down Expand Up @@ -463,7 +464,7 @@ type Extractor interface {
PremiumExtractorBytes
TraderAuctioneerExtractorBytes
TraderImportExportExtractorBytes

TraderImportExportExtractorDoc

ExtractCoord(v string) (coord ogame.Coordinate)
Expand Down
5 changes: 5 additions & 0 deletions pkg/extractor/v6/extractor.go
Original file line number Diff line number Diff line change
Expand Up @@ -474,6 +474,11 @@ func (e *Extractor) ExtractFleet1ShipsFromDoc(doc *goquery.Document) (s ogame.Sh
return extractFleet1ShipsFromDoc(doc)
}

// ExtractFleetDispatchACSFromDoc ...
func (e *Extractor) ExtractFleetDispatchACSFromDoc(doc *goquery.Document) []ogame.ACSValues {
return extractFleetDispatchACSFromDoc(doc)
}

// ExtractEspionageReportMessageIDsFromDoc ...
func (e *Extractor) ExtractEspionageReportMessageIDsFromDoc(doc *goquery.Document) ([]ogame.EspionageReportSummary, int64) {
return extractEspionageReportMessageIDsFromDoc(doc)
Expand Down
13 changes: 13 additions & 0 deletions pkg/extractor/v6/extracts.go
Original file line number Diff line number Diff line change
Expand Up @@ -568,6 +568,19 @@ func extractFleet1ShipsFromDoc(doc *goquery.Document) (s ogame.ShipsInfos) {
return
}

func extractFleetDispatchACSFromDoc(doc *goquery.Document) []ogame.ACSValues {
out := make([]ogame.ACSValues, 0)
doc.Find("select[name=acsValues] option").Each(func(i int, s *goquery.Selection) {
acsValues := s.AttrOr("value", "")
m := regexp.MustCompile(`\d+#\d+#\d+#\d+#.*#(\d+)`).FindStringSubmatch(acsValues)
if len(m) == 2 {
optUnionID := utils.DoParseI64(m[1])
out = append(out, ogame.ACSValues{ACSValues: acsValues, Union: optUnionID})
}
})
return out
}

func extractEspionageReportMessageIDsFromDoc(doc *goquery.Document) ([]ogame.EspionageReportSummary, int64) {
msgs := make([]ogame.EspionageReportSummary, 0)
nbPage := utils.DoParseI64(doc.Find("ul.pagination li").Last().AttrOr("data-page", "1"))
Expand Down
5 changes: 5 additions & 0 deletions pkg/ogame/ogame.go
Original file line number Diff line number Diff line change
Expand Up @@ -249,3 +249,8 @@ type Preferences struct {
Account bool
}
}

type ACSValues struct {
ACSValues string
Union int64
}
40 changes: 28 additions & 12 deletions pkg/wrapper/ogame.go
Original file line number Diff line number Diff line change
Expand Up @@ -3384,19 +3384,16 @@ func (b *OGame) sendFleet(celestialID ogame.CelestialID, ships []ogame.Quantifia

if unionID != 0 {
found := false
fleet1Doc.Find("select[name=acsValues] option").Each(func(i int, s *goquery.Selection) {
acsValues := s.AttrOr("value", "")
m := regexp.MustCompile(`\d+#\d+#\d+#\d+#.*#(\d+)`).FindStringSubmatch(acsValues)
if len(m) == 2 {
optUnionID := utils.DoParseI64(m[1])
if unionID == optUnionID {
found = true
payload.Add("acsValues", acsValues)
payload.Add("union", m[1])
mission = ogame.GroupedAttack
}
acsArr := b.extractor.ExtractFleetDispatchACSFromDoc(fleet1Doc)
for _, acs := range acsArr {
if unionID == acs.Union {
found = true
payload.Add("acsValues", acs.ACSValues)
payload.Add("union", utils.FI64(acs.Union))
mission = ogame.GroupedAttack
break
}
})
}
if !found {
return ogame.Fleet{}, ogame.ErrUnionNotFound
}
Expand Down Expand Up @@ -4740,3 +4737,22 @@ func (b *OGame) OfferSellMarketplace(itemID any, quantity, priceType, price, pri
func (b *OGame) OfferBuyMarketplace(itemID any, quantity, priceType, price, priceRange int64, celestialID ogame.CelestialID) error {
return b.WithPriority(taskRunner.Normal).OfferBuyMarketplace(itemID, quantity, priceType, price, priceRange, celestialID)
}

type IGetCoordinate interface {
GetCoordinate() ogame.Coordinate
}

func ConvertToCoordinate(v any) (out ogame.Coordinate) {
if celestial, ok := v.(IGetCoordinate); ok {
out = celestial.GetCoordinate()
} else if coord, ok := v.(ogame.Coordinate); ok {
out = coord
} else if coordStr, ok := v.(string); ok {
coord, err := ogame.ParseCoord(coordStr)
if err != nil {
return
}
out = coord
}
return
}

0 comments on commit 3c006f7

Please sign in to comment.