Skip to content

Commit

Permalink
Merge branch 'release/42.7.0'
Browse files Browse the repository at this point in the history
  • Loading branch information
alaingilbert committed Jan 26, 2021
2 parents e466844 + 8329fc5 commit 65a2495
Show file tree
Hide file tree
Showing 19 changed files with 483 additions and 89 deletions.
8 changes: 6 additions & 2 deletions baseShip.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,15 @@ type BaseShip struct {
}

// GetCargoCapacity returns ship cargo capacity
func (b BaseShip) GetCargoCapacity(techs Researches, probeRaids, isCollector bool) int64 {
func (b BaseShip) GetCargoCapacity(techs Researches, probeRaids, isCollector, isPioneers bool) int64 {
if b.GetID() == EspionageProbeID && !probeRaids {
return 0
}
cargo := b.BaseCargoCapacity + int64(float64(b.BaseCargoCapacity*techs.HyperspaceTechnology)*0.05)
hyperspaceBonus := 0.05
if isPioneers {
hyperspaceBonus = 0.02
}
cargo := b.BaseCargoCapacity + int64(float64(b.BaseCargoCapacity*techs.HyperspaceTechnology)*hyperspaceBonus)
if isCollector && (b.ID == SmallCargoID || b.ID == LargeCargoID) {
cargo += int64(float64(b.BaseCargoCapacity) * 0.25)
}
Expand Down
2 changes: 1 addition & 1 deletion colonyShip_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,6 @@ func TestColonyShip_GetSpeed(t *testing.T) {

func TestColony_GetCargoCapacity(t *testing.T) {
cs := newColonyShip()
assert.Equal(t, int64(10500), cs.GetCargoCapacity(Researches{HyperspaceTechnology: 8}, false, false))
assert.Equal(t, int64(10500), cs.GetCargoCapacity(Researches{HyperspaceTechnology: 8}, false, false, false))

}
4 changes: 2 additions & 2 deletions cruiser_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@ func TestCruiser_RapidfireAgainst(t *testing.T) {

func TestCruiser_GetCargoCapacity(t *testing.T) {
c := newCruiser()
assert.Equal(t, int64(800), c.GetCargoCapacity(Researches{HyperspaceTechnology: 0}, false, false))
assert.Equal(t, int64(1120), c.GetCargoCapacity(Researches{HyperspaceTechnology: 8}, false, false))
assert.Equal(t, int64(800), c.GetCargoCapacity(Researches{HyperspaceTechnology: 0}, false, false, false))
assert.Equal(t, int64(1120), c.GetCargoCapacity(Researches{HyperspaceTechnology: 8}, false, false, false))
}

func TestCruiser_GetFuelConsumption(t *testing.T) {
Expand Down
5 changes: 5 additions & 0 deletions extractor_v6.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,11 @@ func NewExtractorV6() *ExtractorV6 {
return &ExtractorV6{}
}

// ExtractDestroyRockets ...
func (e ExtractorV6) ExtractDestroyRockets(pageHTML []byte) (abm, ipm int64, token string, err error) {
panic("implement me")
}

// ExtractCancelFleetToken ...
func (e ExtractorV6) ExtractCancelFleetToken(pageHTML []byte, fleetID FleetID) (string, error) {
panic("implement me")
Expand Down
11 changes: 11 additions & 0 deletions extractor_v71.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,17 @@ func (e ExtractorV71) ExtractEspionageReportFromDoc(doc *goquery.Document, locat
return extractEspionageReportFromDocV71(doc, location)
}

// ExtractDestroyRockets ...
func (e ExtractorV71) ExtractDestroyRockets(pageHTML []byte) (abm, ipm int64, token string, err error) {
doc, _ := goquery.NewDocumentFromReader(bytes.NewReader(pageHTML))
return e.ExtractDestroyRocketsFromDoc(doc)
}

// ExtractDestroyRocketsFromDoc ...
func (e ExtractorV71) ExtractDestroyRocketsFromDoc(doc *goquery.Document) (abm, ipm int64, token string, err error) {
return extractDestroyRocketsFromDocV71(doc)
}

// ExtractIPM ...
func (e ExtractorV71) ExtractIPM(pageHTML []byte) (duration int64, max int64, token string) {
doc, _ := goquery.NewDocumentFromReader(bytes.NewReader(pageHTML))
Expand Down
2 changes: 1 addition & 1 deletion extracts_v6.go
Original file line number Diff line number Diff line change
Expand Up @@ -1258,7 +1258,7 @@ func extractServerTimeFromDocV6(doc *goquery.Document) (time.Time, error) {

u1 := time.Now().UTC().Unix()
u2 := serverTime.Unix()
n := int(math.Round(float64(u2-u1)/15)) * 15
n := int(math.Round(float64(u2-u1)/900)) * 900 // u2-u1 should be close to 0, round to nearest 15min difference

serverTime = serverTime.Add(time.Duration(-n) * time.Second).In(time.FixedZone("OGT", n))

Expand Down
14 changes: 14 additions & 0 deletions extracts_v71.go
Original file line number Diff line number Diff line change
Expand Up @@ -513,6 +513,20 @@ func extractEspionageReportFromDocV71(doc *goquery.Document, location *time.Loca
return report, nil
}

func extractDestroyRocketsFromDocV71(doc *goquery.Document) (abm, ipm int64, token string, err error) {
scriptTxt := doc.Find("script").Text()
r := regexp.MustCompile(`missileToken = "([^"]+)"`)
m := r.FindStringSubmatch(scriptTxt)
if len(m) != 2 {
err = errors.New("failed to find missile token")
return
}
token = m[1]
abm, _ = strconv.ParseInt(doc.Find("table tr").Eq(1).Find("td").Eq(1).Text(), 10, 64)
ipm, _ = strconv.ParseInt(doc.Find("table tr").Eq(2).Find("td").Eq(1).Text(), 10, 64)
return
}

func extractIPMFromDocV71(doc *goquery.Document) (duration, max int64, token string) {
durationFloat, _ := strconv.ParseFloat(doc.Find("span#timer").AttrOr("data-duration", "0"), 64)
duration = int64(math.Ceil(durationFloat))
Expand Down
2 changes: 1 addition & 1 deletion fleetBuilder.go
Original file line number Diff line number Diff line change
Expand Up @@ -215,7 +215,7 @@ func (f *FleetBuilder) sendNow(tx Prioritizable) error {
if f.resources.Metal == -1 || f.resources.Crystal == -1 || f.resources.Deuterium == -1 {
// Calculate cargo
techs := tx.GetResearch()
cargoCapacity := f.ships.Cargo(techs, f.b.GetServer().Settings.EspionageProbeRaids == 1, f.b.CharacterClass() == Collector)
cargoCapacity := f.ships.Cargo(techs, f.b.GetServer().Settings.EspionageProbeRaids == 1, f.b.CharacterClass() == Collector, f.b.IsPioneers())
if f.minimumDeuterium <= 0 {
planetResources, _ = tx.GetResources(f.origin.GetID())
}
Expand Down
8 changes: 8 additions & 0 deletions id.go
Original file line number Diff line number Diff line change
Expand Up @@ -251,6 +251,14 @@ func (o ID) IsShip() bool {
o == PathfinderID
}

// IsFlyableShip returns either or not the id is a ship that can fly
func (o ID) IsFlyableShip() bool {
if o == SolarSatelliteID || o == CrawlerID {
return false
}
return o.IsShip()
}

// IsCombatShip ...
func (o ID) IsCombatShip() bool {
return o == LightFighterID ||
Expand Down
12 changes: 9 additions & 3 deletions interfaces.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package ogame

import (
"crypto/tls"
"net/http"
"net/url"
"time"
Expand Down Expand Up @@ -57,6 +58,7 @@ type Prioritizable interface {
Highscore(category, typ, page int64) (Highscore, error)
IsUnderAttack() (bool, error)
Login() error
LoginWithBearerToken(token string) (bool, error)
LoginWithExistingCookies() (bool, error)
Logout()
OfferBuyMarketplace(itemID interface{}, quantity, priceType, price, priceRange int64, celestialID CelestialID) error
Expand Down Expand Up @@ -95,6 +97,7 @@ type Prioritizable interface {
GetResourceSettings(PlanetID) (ResourceSettings, error)
GetResourcesProductions(PlanetID) (Resources, error)
GetResourcesProductionsLight(ResourcesBuildings, Researches, ResourceSettings, Temperature) Resources
DestroyRockets(PlanetID, int64, int64) error
SendIPM(PlanetID, Coordinate, int64, ID) (int64, error)
SetResourceSettings(PlanetID, ResourceSettings) error

Expand All @@ -111,6 +114,7 @@ type Wrapper interface {
AddAccount(number int, lang string) (NewAccount, error)
BytesDownloaded() int64
BytesUploaded() int64
IsPioneers() bool
CharacterClass() CharacterClass
Disable()
Distance(origin, destination Coordinate) int64
Expand All @@ -123,6 +127,7 @@ type Wrapper interface {
GetCachedPlayer() UserInfos
GetCachedPreferences() Preferences
GetClient() *OGameClient
SetClient(*OGameClient)
GetExtractor() Extractor
GetLanguage() string
GetNbSystems() int64
Expand All @@ -149,7 +154,7 @@ type Wrapper interface {
OnStateChange(clb func(locked bool, actor string))
Quiet(bool)
ReconnectChat() bool
RegisterAuctioneerCallback(func([]byte))
RegisterAuctioneerCallback(func(interface{}))
RegisterChatCallback(func(ChatMsg))
RegisterHTMLInterceptor(func(method, url string, params, payload url.Values, pageHTML []byte))
RegisterWSCallback(string, func([]byte))
Expand All @@ -158,7 +163,7 @@ type Wrapper interface {
ServerVersion() string
SetLoginWrapper(func(func() (bool, error)) error)
SetOGameCredentials(username, password, otpSecret string)
SetProxy(proxyAddress, username, password, proxyType string, loginOnly bool) error
SetProxy(proxyAddress, username, password, proxyType string, loginOnly bool, config *tls.Config) error
SetUserAgent(newUserAgent string)
WithPriority(priority int) Prioritizable
}
Expand Down Expand Up @@ -203,7 +208,7 @@ type DefenderObj interface {
// Ship interface implemented by all ships units
type Ship interface {
DefenderObj
GetCargoCapacity(techs Researches, probeRaids, isCollector bool) int64
GetCargoCapacity(techs Researches, probeRaids, isCollector, isPioneers bool) int64
GetSpeed(techs Researches, isCollector, isGeneral bool) int64
GetFuelConsumption(techs Researches, fleetDeutSaveFactor float64, isGeneral bool) int64
}
Expand Down Expand Up @@ -255,6 +260,7 @@ type Extractor interface {
ExtractCelestial(pageHTML []byte, b *OGame, v interface{}) (Celestial, error)
ExtractServerTime(pageHTML []byte) (time.Time, error)
ExtractFleetsFromEventList(pageHTML []byte) []Fleet
ExtractDestroyRockets(pageHTML []byte) (abm, ipm int64, token string, err error)
ExtractIPM(pageHTML []byte) (duration, max int64, token string)
ExtractFleets(pageHTML []byte) (res []Fleet)
ExtractSlots(pageHTML []byte) Slots
Expand Down
6 changes: 3 additions & 3 deletions largeCargo_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ func TestLargeCargo_GetSpeed(t *testing.T) {

func TestLargeCargo_GetCargoCapacity(t *testing.T) {
lc := newLargeCargo()
assert.Equal(t, int64(35000), lc.GetCargoCapacity(Researches{HyperspaceTechnology: 8}, false, false))
assert.Equal(t, int64(37500), lc.GetCargoCapacity(Researches{HyperspaceTechnology: 10}, false, false))
assert.Equal(t, int64(43750), lc.GetCargoCapacity(Researches{HyperspaceTechnology: 10}, false, true))
assert.Equal(t, int64(35000), lc.GetCargoCapacity(Researches{HyperspaceTechnology: 8}, false, false, false))
assert.Equal(t, int64(37500), lc.GetCargoCapacity(Researches{HyperspaceTechnology: 10}, false, false, false))
assert.Equal(t, int64(43750), lc.GetCargoCapacity(Researches{HyperspaceTechnology: 10}, false, true, false))
}
Loading

0 comments on commit 65a2495

Please sign in to comment.