Browse Source

add energy consumption by mines

master
arnaucube 5 years ago
parent
commit
7fddfa16c4
2 changed files with 32 additions and 4 deletions
  1. +19
    -0
      models/calc.go
  2. +13
    -4
      models/planet.go

+ 19
- 0
models/calc.go

@ -59,6 +59,25 @@ func FusionGrowth(ilvl int64, ilvlTech int64, idelta int64) int64 {
return int64(r)
}
func MetalMineEnergyConsumption(ilvl int64) int64 {
lvl := float64(ilvl)
// 10 * lvl * 1.1^lvl
c := 10 * lvl * math.Pow(1.1, lvl)
return int64(c)
}
func CrystalMineEnergyConsumption(ilvl int64) int64 {
lvl := float64(ilvl)
// 10 * lvl * 1.1^lvl
c := 10 * lvl * math.Pow(1.1, lvl)
return int64(c)
}
func DeuteriumMineEnergyConsumption(ilvl int64) int64 {
lvl := float64(ilvl)
// 20 * lvl * 1.1^lvl
c := 10 * lvl * math.Pow(1.1, lvl)
return int64(c)
}
// https://ogame.fandom.com/wiki/Buildings
// https://ogame.fandom.com/wiki/Metal_Mine

+ 13
- 4
models/planet.go

@ -69,20 +69,18 @@ func NewPlanet(db *database.Db, size int64, name string, ownerId bson.ObjectId)
newPlanet.Buildings["metalmine"] = 1
newPlanet.Buildings["crystalmine"] = 1
newPlanet.Buildings["deuteriummine"] = 1
newPlanet.Buildings["energymine"] = 1
// newPlanet.Buildings["energymine"] = 1
err := db.Planets.Insert(newPlanet)
if err != nil {
return nil, err
}
fmt.Println(newPlanet.Resources)
var planet *Planet
err = db.Planets.Find(bson.M{"ownerid": newPlanet.OwnerId}).One(&planet)
if err != nil {
return nil, err
}
fmt.Println(planet.Resources)
return planet, nil
}
@ -229,6 +227,17 @@ func (p *Planet) CheckCurrentBuild() (bool, error) {
// upgrade level of building in planet
p.Buildings[p.CurrentBuild.Building] += 1
// substrate the energy used by the building
var usedEnergy int64
if p.CurrentBuild.Building == "metalmine" {
usedEnergy = MetalMineEnergyConsumption(p.Buildings["metalmine"])
} else if p.CurrentBuild.Building == "crystalmine" {
usedEnergy = CrystalMineEnergyConsumption(p.Buildings["crystalmine"])
} else if p.CurrentBuild.Building == "deuteriummine" {
usedEnergy = DeuteriumMineEnergyConsumption(p.Buildings["deuteriummine"])
}
p.Resources.Energy = p.Resources.Energy - usedEnergy
// build end
p.CurrentBuild.Title = ""
p.CurrentBuild.Building = ""
@ -274,7 +283,7 @@ func (p *Planet) UpgradeBuilding(building string) error {
// add current task to planet
p.CurrentBuild.Building = building
p.CurrentBuild.Title = building + " - Level " + strconv.Itoa(int(p.Buildings[building]))
p.CurrentBuild.Title = building + " - Level " + strconv.Itoa(int(p.Buildings[building])+1)
p.CurrentBuild.Ends = endsTime
p.CurrentBuild.CountDown = p.CurrentBuild.Ends.Unix() - time.Now().Unix()

Loading…
Cancel
Save