} $player->setAvailableTechnologies($technologies); //END OF COPYPASTA $availableTechnologies = $player->getAvailableTechnologies(); $technologyOK = array_key_exists($techId, $availableTechnologies); $resourcesOK = true; if ($technologyOK) { $technology = $availableTechnologies[$techId]; if ($technology->getProgress() + $percentOrder < 0) { $percentOrder = 0; } elseif ($technology->getProgress() + $percentOrder > 100) { $percentOrder = 100 - $technology->getProgress(); } $technology_resources = $availableTechnologies[$techId]->getCosts(); if ($technology->getIsAge()) { $advanceCosts = $playerConn->getAgeAdvanceCosts($player->getId()); $totalCosts = array(); foreach ($advanceCosts as $index => $advanceCost) { $totalCosts[$index] = $technology_resources[$index] + $advanceCost; } $technology->setCosts($totalCosts); } $technology_resources = $technology->getCosts(); $player_resources = $player->getResources(); $leftResources = array(); for ($i = 0; $i < count($technology_resources); $i++) { $leftResources[$i] = $player_resources[$i] - $technology_resources[$i] * $percentOrder; if ($leftResources[$i] < 0 && $technology_resources[$i] > 0) { $resourcesOK = false; } }