mirror of
https://github.com/arnaucube/gogame.git
synced 2026-02-06 19:16:40 +01:00
add energy consumption by mines
This commit is contained in:
@@ -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
|
||||
|
||||
@@ -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()
|
||||
|
||||
|
||||
Reference in New Issue
Block a user