Open alican22 opened 4 months ago
Hi @alican22,
Thanks for the bug report. I checked the current code and it seems we are indeed missing a check for the energy cost.
The existing checks look like this now:
app/Http/Controllers/Abstracts/AbstractBuildingsController line 92:
// Get object
$object = $objects->getObjectByMachineName($object_machine_name);
// Get current level of building
$current_level = $this->planet->getObjectLevel($object_machine_name);
// Check requirements of this building
$requirements_met = $objects->objectRequirementsMet($object_machine_name, $this->planet, $player);
// Check if the current planet has enough resources to build this building.
$enough_resources = $this->planet->hasResources($objects->getObjectPrice($object_machine_name, $this->planet));
The planet->hasResources() method which checks if the current planet has enough resources seems to be missing an energy requirement check:
/**
* Checks if this planet has equal or more than the requested resources.
*
* @param Resources $resources
* Array with resources to check.
*
* @return bool
*/
public function hasResources(Resources $resources): bool
{
if (!empty($resources->metal->get()) && $this->metal()->get() < $resources->metal->get()) {
return false;
}
if (!empty($resources->crystal->get()) && $this->crystal()->get() < $resources->crystal->get()) {
return false;
}
if (!empty($resources->deuterium->get()) && $this->deuterium()->get() < $resources->deuterium->get()) {
return false;
}
return true;
}
I'm not fully sure, but as far as I know the energy requirements works a little different than the normal resources. Normal resources (metal,crystal,deuterium) are deducted from the planet. But energy is more of a "check" if the total production energy production of the planet is at least X. So in your screenshot where it requires 1,6K energy it should not look at your current balance "-59" but rather it should look at the actual "current production" which is visible in the tooltip:
I'm not entirely sure, but I think this is more or less how it should work.
I check on the real Ogame and you are right, the check in on the total production and energy and not the current balance:
duplicate #174
Normally, I need to have at least 1.6K Energy to upgrade Space Dock.
But I can upgrade successfully with -59 Energy (minus)