diff --git a/app/Http/Controllers/Abstracts/AbstractBuildingsController.php b/app/Http/Controllers/Abstracts/AbstractBuildingsController.php index 617b6fba..5a84b4e9 100644 --- a/app/Http/Controllers/Abstracts/AbstractBuildingsController.php +++ b/app/Http/Controllers/Abstracts/AbstractBuildingsController.php @@ -82,6 +82,9 @@ public function index(Request $request, PlayerService $player): View $build_active = $build_full_queue->getCurrentlyBuildingFromQueue(); $build_queue = $build_full_queue->getQueuedFromQueue(); + // Research Lab upgrading is disallowed when researching is ongoing + $research_in_progress = $player->isResearching(); + $buildings = []; foreach ($this->objects as $key_row => $objects_row) { $buildings[$key_row] = []; @@ -93,9 +96,10 @@ public function index(Request $request, PlayerService $player): View // Get current level of building $current_level = $this->planet->getObjectLevel($object_machine_name); + $next_level = $current_level + 1; // Check requirements of this building - $requirements_met = ObjectService::objectRequirementsMet($object_machine_name, $this->planet, $player); + $requirements_met = ObjectService::objectRequirementsMetWithQueue($object_machine_name, $next_level, $this->planet, $player); // Check if the current planet has enough resources to build this building. $enough_resources = $this->planet->hasResources(ObjectService::getObjectPrice($object_machine_name, $this->planet)); @@ -113,6 +117,7 @@ public function index(Request $request, PlayerService $player): View $view_model->requirements_met = $requirements_met; $view_model->enough_resources = $enough_resources; $view_model->currently_building = ($build_active !== null && $build_active->object->machine_name === $object->machine_name); + $view_model->research_in_progress = $research_in_progress; $buildings[$key_row][$object->id] = $view_model; } diff --git a/app/Http/Controllers/Abstracts/AbstractUnitsController.php b/app/Http/Controllers/Abstracts/AbstractUnitsController.php index aebb79f9..eebd421e 100644 --- a/app/Http/Controllers/Abstracts/AbstractUnitsController.php +++ b/app/Http/Controllers/Abstracts/AbstractUnitsController.php @@ -93,7 +93,7 @@ public function index(Request $request, PlayerService $player): View $amount = $planet->getObjectAmount($object->machine_name); // Check requirements of this building - $requirements_met = ObjectService::objectRequirementsMet($object->machine_name, $planet, $player, 0, false); + $requirements_met = ObjectService::objectRequirementsMet($object->machine_name, $planet, $player); // Check if the current planet has enough resources to build this building. $enough_resources = $planet->hasResources(ObjectService::getObjectPrice($object->machine_name, $planet)); diff --git a/app/Http/Controllers/ResearchController.php b/app/Http/Controllers/ResearchController.php index 329f08c9..10c36591 100644 --- a/app/Http/Controllers/ResearchController.php +++ b/app/Http/Controllers/ResearchController.php @@ -11,7 +11,7 @@ use OGame\Services\PlanetService; use OGame\Services\PlayerService; use OGame\Services\ResearchQueueService; -use OGame\ViewModels\BuildingViewModel; +use OGame\ViewModels\ResearchViewModel; class ResearchController extends OGameController { @@ -38,6 +38,7 @@ public function __construct(ResearchQueueService $queue) { $this->route_view_index = 'research.index'; $this->queue = $queue; + parent::__construct(); } @@ -63,10 +64,13 @@ public function index(PlayerService $player): View $count = 0; - // Parse build queue for this planet + // Parse research queue for this planet $research_full_queue = $this->queue->retrieveQueue($planet); - $build_active = $research_full_queue->getCurrentlyBuildingFromQueue(); - $build_queue = $research_full_queue->getQueuedFromQueue(); + $research_active = $research_full_queue->getCurrentlyBuildingFromQueue(); + $research_queue = $research_full_queue->getQueuedFromQueue(); + + // Researching is disallowed when Research Lab is upgrading + $research_lab_upgrading = $player->isBuildingObject('research_lab'); $research = []; foreach ($screen_objects as $key_row => $objects_row) { @@ -75,22 +79,24 @@ public function index(PlayerService $player): View $object = ObjectService::getResearchObjectByMachineName($object_machine_name); - // Get current level of building + // Get current level of technology $current_level = $player->getResearchLevel($object->machine_name); + $next_level = $current_level + 1; - // Check requirements of this building - $requirements_met = ObjectService::objectRequirementsMet($object->machine_name, $planet, $player); + // Check requirements of this technology + $requirements_met = ObjectService::objectRequirementsMetWithQueue($object->machine_name, $next_level, $planet, $player); - // Check if the current planet has enough resources to build this building. + // Check if the current planet has enough resources to research this technology. $enough_resources = $planet->hasResources(ObjectService::getObjectPrice($object->machine_name, $planet)); - $view_model = new BuildingViewModel(); + $view_model = new ResearchViewModel(); $view_model->object = $object; $view_model->current_level = $current_level; $view_model->requirements_met = $requirements_met; $view_model->count = $count; $view_model->enough_resources = $enough_resources; - $view_model->currently_building = (!empty($build_active) && $build_active->object->machine_name == $object->machine_name); + $view_model->currently_building = (!empty($research_active) && $research_active->object->machine_name === $object->machine_name); + $view_model->research_lab_upgrading = $research_lab_upgrading; $research[$key_row][$object->id] = $view_model; } @@ -106,9 +112,10 @@ public function index(PlayerService $player): View 'planet_id' => $planet->getPlanetId(), 'planet_name' => $planet->getPlanetName(), 'research' => $research, - 'build_active' => $build_active, - 'build_queue' => $build_queue, + 'build_active' => $research_active, + 'build_queue' => $research_queue, 'build_queue_max' => $build_queue_max, + 'research_lab_upgrading' => $research_lab_upgrading, ]); } diff --git a/app/Http/Traits/ObjectAjaxTrait.php b/app/Http/Traits/ObjectAjaxTrait.php index f015af2b..83b3e154 100644 --- a/app/Http/Traits/ObjectAjaxTrait.php +++ b/app/Http/Traits/ObjectAjaxTrait.php @@ -42,7 +42,7 @@ public function ajaxHandler(Request $request, PlayerService $player): JsonRespon $next_level = $current_level + 1; // Check requirements of this object - $requirements_met = ObjectService::objectRequirementsMet($object->machine_name, $planet, $player); + $requirements_met = ObjectService::objectRequirementsMetWithQueue($object->machine_name, $next_level, $planet, $player); $price = ObjectService::getObjectPrice($object->machine_name, $planet); @@ -52,11 +52,16 @@ public function ajaxHandler(Request $request, PlayerService $player): JsonRespon // Switch $production_time = ''; $production_datetime = ''; + $research_lab_upgrading = false; + $research_in_progress = false; switch ($object->type) { case GameObjectType::Building: case GameObjectType::Station: $production_time = AppUtil::formatTimeDuration($planet->getBuildingConstructionTime($object->machine_name)); $production_datetime = AppUtil::formatDateTimeDuration($planet->getBuildingConstructionTime($object->machine_name)); + + // Research Lab upgrading is disallowed when research is in progress + $research_in_progress = $player->isResearching(); break; case GameObjectType::Ship: case GameObjectType::Defense: @@ -66,6 +71,9 @@ public function ajaxHandler(Request $request, PlayerService $player): JsonRespon case GameObjectType::Research: $production_time = AppUtil::formatTimeDuration($planet->getTechnologyResearchTime($object->machine_name)); $production_datetime = AppUtil::formatDateTimeDuration($planet->getTechnologyResearchTime($object->machine_name)); + + // Researching is disallowed when Research Lab is upgrading + $research_lab_upgrading = $player->isBuildingObject('research_lab'); break; default: // Unknown object type, throw error. @@ -153,6 +161,8 @@ public function ajaxHandler(Request $request, PlayerService $player): JsonRespon 'max_storage' => $max_storage, 'max_build_amount' => $max_build_amount, 'current_amount' => $current_amount, + 'research_lab_upgrading' => $research_lab_upgrading, + 'research_in_progress' => $research_in_progress, ]); return response()->json([ diff --git a/app/Services/BuildingQueueService.php b/app/Services/BuildingQueueService.php index 2693dddc..b325d4b1 100644 --- a/app/Services/BuildingQueueService.php +++ b/app/Services/BuildingQueueService.php @@ -77,13 +77,6 @@ public function add(PlanetService $planet, int $building_id): void // Check if user satisfies requirements to build this object. $building = ObjectService::getObjectById($building_id); - // Check if user satisfies requirements to build this object. - // TODO: refactor throw exception into a more user-friendly message. - $requirements_met = ObjectService::objectRequirementsMet($building->machine_name, $planet, $planet->getPlayer()); - if (!$requirements_met) { - throw new Exception('Requirements not met to build this object.'); - } - // @TODO: add checks that current logged in user is owner of planet // and is able to add this object to the building queue. $current_level = $planet->getObjectLevel($building->machine_name); @@ -93,6 +86,13 @@ public function add(PlanetService $planet, int $building_id): void $amount = $this->activeBuildingQueueItemCount($planet, $building->id); $next_level = $current_level + $amount + 1; + // Check if user satisfies requirements to build this object. + // TODO: refactor throw exception into a more user-friendly message. + $requirements_met = ObjectService::objectRequirementsMetWithQueue($building->machine_name, $next_level, $planet, $planet->getPlayer()); + if (!$requirements_met) { + throw new Exception('Requirements not met to build this object.'); + } + $queue = new BuildingQueue(); $queue->planet_id = $planet->getPlanetId(); $queue->object_id = $building->id; @@ -216,6 +216,14 @@ public function start(PlanetService $planet, int $time_start = 0): void continue; } + // Sanity check: check if the Research Lab is tried to upgrade when research is in progress + if ($object->machine_name === 'research_lab' && $planet->getPlayer()->isResearching()) { + // Error, cancel build queue item. + $this->cancel($planet, $queue_item->id, $queue_item->object_id); + + continue; + } + // Sanity check: check if the planet has enough resources. If not, // then cancel build request. if (!$planet->hasResources($price)) { @@ -227,7 +235,7 @@ public function start(PlanetService $planet, int $time_start = 0): void // Sanity check: check if the building requirements are still met. If not, // then cancel build request. - if (!ObjectService::objectRequirementsMet($object->machine_name, $planet, $planet->getPlayer(), $queue_item->object_level_target, false)) { + if (!ObjectService::objectRequirementsWithLevelsMet($object->machine_name, $queue_item->object_level_target, $planet, $planet->getPlayer())) { $this->cancel($planet, $queue_item->id, $queue_item->object_id); continue; @@ -341,7 +349,7 @@ public function cancelItemMissingRequirements(PlanetService $planet): void foreach ($build_queue_items as $build_queue_item) { $object = ObjectService::getObjectById($build_queue_item->object_id); - if (!ObjectService::objectRequirementsMet($object->machine_name, $planet, $planet->getPlayer(), $build_queue_item->object_level_target)) { + if (!ObjectService::objectRequirementsMetWithQueue($object->machine_name, $build_queue_item->object_level_target, $planet, $planet->getPlayer())) { $this->cancel($planet, $build_queue_item->id, $object->id); break; } diff --git a/app/Services/ObjectService.php b/app/Services/ObjectService.php index 07123421..599ff025 100644 --- a/app/Services/ObjectService.php +++ b/app/Services/ObjectService.php @@ -11,6 +11,7 @@ use OGame\GameObjects\Models\BuildingObject; use OGame\GameObjects\Models\DefenseObject; use OGame\GameObjects\Models\Enums\GameObjectType; +use OGame\GameObjects\Models\Fields\GameObjectRequirement; use OGame\GameObjects\Models\ResearchObject; use OGame\GameObjects\Models\ShipObject; use OGame\GameObjects\Models\StationObject; @@ -329,50 +330,68 @@ public static function getBuildingObjectsWithStorage(): array * @param string $machine_name * @param PlanetService $planet * @param PlayerService $player - * @param int $level - * @param bool $queued * @return bool */ - public static function objectRequirementsMet(string $machine_name, PlanetService $planet, PlayerService $player, int $level = 0, bool $queued = true): bool + public static function objectRequirementsMet(string $machine_name, PlanetService $planet, PlayerService $player): bool + { + $object = self::getObjectByMachineName($machine_name); + return count(self::filterCompletedRequirements($object->requirements, $planet, $player)) === 0; + } + + /** + * Check if object requirements are met (for building it) with previous levels completed. + * + * @param string $machine_name + * @param PlanetService $planet + * @param PlayerService $player + * @param int $target_level + * @return bool + */ + public static function objectRequirementsWithLevelsMet(string $machine_name, int $target_level, PlanetService $planet, PlayerService $player): bool { try { $object = self::getObjectByMachineName($machine_name); - // Check required prior levels - if ($level) { - if (!self::objectLevelsMet($object, $planet, $player, $level, $queued)) { + // Check that the object's previous level exists. + if ($target_level) { + if (!self::hasPreviousLevels($target_level, $object, $planet, $player)) { return false; } } + } catch (Exception $e) { + return false; + } - foreach ($object->requirements as $requirement) { - // Load required object and check if requirements are met. - $object_required = self::getObjectByMachineName($requirement->object_machine_name); - $check_queue = $queued; + return count(self::filterCompletedRequirements($object->requirements, $planet, $player)) === 0; + } - // Skip queue check for research lab as it must be present for research objects - if ($object_required->machine_name === 'research_lab') { - $check_queue = false; - } + /** + * Check if object requirements are met (for building it) with existing and queued items. + * + * @param string $machine_name + * @param PlanetService $planet + * @param PlayerService $player + * @param int $target_level + * @return bool + */ + public static function objectRequirementsMetWithQueue(string $machine_name, int $target_level, PlanetService $planet, PlayerService $player): bool + { + $object = self::getObjectByMachineName($machine_name); - if ($object_required->type === GameObjectType::Research) { - // Check if requirements are met with existing technology or with research items in build queue. - if ($player->getResearchLevel($object_required->machine_name) < $requirement->level && (!$check_queue || !$player->isResearchingTech($requirement->object_machine_name, $requirement->level))) { - return false; - } - } else { - // Check if requirements are met with existing buildings or with buildings in build queue. - // Building queue is checked only for building queue objects, not for unit queue objects. - if ($planet->getObjectLevel($object_required->machine_name) < $requirement->level && (!$check_queue || !$planet->isBuildingObject($requirement->object_machine_name, $requirement->level))) { - return false; - } - } - } - } catch (Exception $e) { + // Check object's previous levels against queued objects + if (!self::hasPreviousLevelsInQueue($target_level, $object, $planet, $player)) { return false; } - return true; + // Check object's requirements against built objects + $missingRequirements = self::filterCompletedRequirements($object->requirements, $planet, $player); + + if (count($missingRequirements) === 0) { + return true; + } + + // Check object's requirements against queued objects + return count(self::filterQueuedRequirements($missingRequirements, $planet, $player)) === 0; } /** @@ -508,17 +527,87 @@ public static function getObjectRawPrice(string $machine_name, int $level = 0): } /** - * Check if object prior level requirements are met (for building it). - * Prior levels can be already built or in queues + * Filter out completed requirements. + * + * @param array $requirements + * @param PlanetService $planet + * @param PlayerService $player + * @return array + */ + private static function filterCompletedRequirements(array $requirements, PlanetService $planet, PlayerService $player): array + { + return array_filter($requirements, function ($requirement) use ($planet, $player) { + try { + $object = self::getObjectByMachineName($requirement->object_machine_name); + + if ($object->type === GameObjectType::Research) { + // Check if requirements are met with existing technology. + if ($player->getResearchLevel($requirement->object_machine_name) < $requirement->level) { + return true; + } + } else { + // Check if requirements are met with existing buildings. + if ($planet->getObjectLevel($requirement->object_machine_name) < $requirement->level) { + return true; + } + } + + return false; + } catch (Exception $e) { + return true; + } + }); + } + + /** + * Filter out queued requirements. * + * @param array $requirements + * @param PlanetService $planet + * @param PlayerService $player + * @return array + */ + private static function filterQueuedRequirements(array $requirements, PlanetService $planet, PlayerService $player): array + { + return array_filter($requirements, function ($requirement) use ($planet, $player) { + try { + $object = self::getObjectByMachineName($requirement->object_machine_name); + + // Skip the queue check for the research lab, as it must be present for research objects. + if ($requirement->object_machine_name === 'research_lab') { + return ($planet->getObjectLevel('research_lab') !== $requirement->level); + } + + if ($object->type === GameObjectType::Research) { + // Check if the requirements are met by the items in the research queue. + if (!$player->isResearchingTech($requirement->object_machine_name, $requirement->level)) { + return true; + } + } else { + // Check if the requirements are met by the items in the building queue. + // The building queue is checked only for building queue objects, not for unit queue objects. + if (!$planet->isBuildingObject($requirement->object_machine_name, $requirement->level)) { + return true; + } + } + + return false; + } catch (Exception $e) { + return true; + } + }); + } + + /** + * Check if object previous level requirements are met (for building it). + * + * @param int $target_level * @param GameObject $object * @param PlanetService $planet * @param PlayerService $player - * @param int $level - * @param bool $queued * @return bool */ - private static function objectLevelsMet(GameObject $object, PlanetService $planet, PlayerService $player, int $level, bool $queued): bool + private static function hasPreviousLevels(int $target_level, GameObject $object, PlanetService $planet, PlayerService $player): bool { $current_level = 0; @@ -528,19 +617,35 @@ private static function objectLevelsMet(GameObject $object, PlanetService $plane $current_level = $planet->getObjectLevel($object->machine_name); } - // Check if target level is next level - if ($current_level + 1 === $level) { + // Check if target level is current or next level + if ($current_level === $target_level || $current_level + 1 === $target_level) { return true; } - // Check if items in queues should be included or not - if (!$queued) { - // There are prior levels, but queue should not be included - return false; - } + return false; + } + /** + * Check if object previous level requirements are met (for building it). + * + * @param int $target_level + * @param GameObject $object + * @param PlanetService $planet + * @param PlayerService $player + * @return bool + */ + private static function hasPreviousLevelsInQueue(int $target_level, GameObject $object, PlanetService $planet, PlayerService $player): bool + { // Check prior levels from queues - for ($i = $current_level + 1; $i < $level; $i++) { + $current_level = 0; + + if ($object->type === GameObjectType::Research) { + $current_level = $planet->getPlayer()->getResearchLevel($object->machine_name); + } else { + $current_level = $planet->getObjectLevel($object->machine_name); + } + + for ($i = $current_level + 1; $i < $target_level; $i++) { if (!$planet->isBuildingObject($object->machine_name, $i) && !$player->isResearchingTech($object->machine_name, $i)) { return false; } diff --git a/app/Services/PlayerService.php b/app/Services/PlayerService.php index 0f734296..1583f072 100644 --- a/app/Services/PlayerService.php +++ b/app/Services/PlayerService.php @@ -511,6 +511,28 @@ public function getResearchArray(): array return $array; } + /** + * Get is the player researching any tech or not + * + * @return bool + */ + public function isResearching(): bool + { + $research_queue = resolve('OGame\Services\ResearchQueueService'); + return (bool) $research_queue->activeResearchQueueItemCount($this); + } + + /** + * Get is the player researching the tech or not + * + * @return bool + */ + public function isResearchingTech(string $machine_name, int $level): bool + { + $research_queue = resolve('OGame\Services\ResearchQueueService'); + return $research_queue->objectInResearchQueue($this, $machine_name, $level); + } + /** * Get the maximum amount of planets that this player can have based on research levels. * @@ -566,13 +588,19 @@ public function delete(): void } /** - * Get is the player researching the tech or not + * Get is the player building the object or not * * @return bool */ - public function isResearchingTech(string $machine_name, int $level): bool + public function isBuildingObject(string $machine_name): bool { - $research_queue = resolve('OGame\Services\ResearchQueueService'); - return $research_queue->objectInResearchQueue($this, $machine_name, $level); + foreach ($this->planets->all() as $planet) { + $object_level = $planet->getObjectLevel($machine_name); + if ($planet->isBuildingObject($machine_name, $object_level + 1)) { + return true; + } + } + + return false; } } diff --git a/app/Services/ResearchQueueService.php b/app/Services/ResearchQueueService.php index 14bc1b17..9968035d 100644 --- a/app/Services/ResearchQueueService.php +++ b/app/Services/ResearchQueueService.php @@ -116,22 +116,22 @@ public function add(PlayerService $player, PlanetService $planet, int $research_ $object = ObjectService::getResearchObjectById($research_object_id); - // Check if user satisifes requirements to research this object. - // TODO: refactor throw exception into a more user-friendly message. - $requirements_met = ObjectService::objectRequirementsMet($object->machine_name, $planet, $planet->getPlayer()); - if (!$requirements_met) { - throw new Exception('Requirements not met to build this object.'); - } - // @TODO: add checks that current logged in user is owner of planet // and is able to add this object to the research queue. $current_level = $player->getResearchLevel($object->machine_name); // Check to see how many other items of this technology there are already // in the queue, because if so then the level needs to be higher than that. - $amount = $this->activeBuildingQueueItemCount($player, $research_object_id); + $amount = $this->activeResearchQueueItemCount($player, $research_object_id); $next_level = $current_level + $amount + 1; + // Check if user satisifes requirements to research this object. + // TODO: refactor throw exception into a more user-friendly message. + $requirements_met = ObjectService::objectRequirementsMetWithQueue($object->machine_name, $next_level, $planet, $planet->getPlayer()); + if (!$requirements_met) { + throw new Exception('Requirements not met to build this object.'); + } + $queue = new $this->model(); $queue->planet_id = $planet->getPlanetId(); $queue->object_id = $research_object_id; @@ -147,6 +147,10 @@ public function add(PlayerService $player, PlanetService $planet, int $research_ /** * Retrieve current research queue for a planet. * + * @TODO this function is not retrieving the queue for a planet + * like the comment says, instead the queue is retrieved for a player. + * Bug or incorrect comment? + * * @param PlanetService $planet * @return ResearchQueueListViewModel * @throws Exception @@ -193,25 +197,26 @@ public function retrieveQueue(PlanetService $planet): ResearchQueueListViewModel } /** - * Get the amount of already existing queue items for a particular - * building. + * Get the amount of player active research queue items. * * @param PlayerService $player - * @param int $building_id + * @param int $tech_id * @return int */ - public function activeBuildingQueueItemCount(PlayerService $player, int $building_id): int + public function activeResearchQueueItemCount(PlayerService $player, int $tech_id = 0): int { // Fetch queue items from model - return $this->model + return $this->model::query() ->join('planets', 'research_queues.planet_id', '=', 'planets.id') ->join('users', 'planets.user_id', '=', 'users.id') ->where([ ['users.id', $player->getId()], - ['research_queues.object_id', $building_id], ['research_queues.processed', 0], ['research_queues.canceled', 0], ]) + ->when($tech_id, function ($q) use ($tech_id) { + return $q->where('research_queues.object_id', '=', $tech_id); + }) ->count(); } @@ -264,6 +269,14 @@ public function start(PlayerService $player, int $time_start = 0): void break; } + // Sanity check: check if the Research Lab is being upgraded + if ($player->isBuildingObject('research_lab')) { + // Error, cancel research queue item. + $this->cancel($player, $queue_item->id, $queue_item->object_id); + + continue; + } + // Sanity check: check if the target level as stored in the database // is 1 higher than the current level. If not, then it means something // is wrong. @@ -286,7 +299,7 @@ public function start(PlayerService $player, int $time_start = 0): void // Sanity check: check if the researching requirements are still met. If not, // then cancel research request. - if (!ObjectService::objectRequirementsMet($object->machine_name, $planet, $player, $queue_item->object_level_target, false)) { + if (!ObjectService::objectRequirementsWithLevelsMet($object->machine_name, $queue_item->object_level_target, $planet, $player)) { $this->cancel($player, $queue_item->id, $queue_item->object_id); continue; @@ -427,7 +440,7 @@ public function cancelItemMissingRequirements(PlayerService $player, PlanetServi foreach ($research_queue_items as $research_queue_item) { $object = ObjectService::getObjectById($research_queue_item->object_id); - if (!ObjectService::objectRequirementsMet($object->machine_name, $planet, $player, $research_queue_item->object_level_target)) { + if (!ObjectService::objectRequirementsMetWithQueue($object->machine_name, $research_queue_item->object_level_target, $planet, $player)) { $this->cancel($player, $research_queue_item->id, $object->id); break; } diff --git a/app/Services/UnitQueueService.php b/app/Services/UnitQueueService.php index b4dce52f..547dcb0f 100644 --- a/app/Services/UnitQueueService.php +++ b/app/Services/UnitQueueService.php @@ -150,7 +150,7 @@ public function add(PlanetService $planet, int $object_id, int $requested_build_ $object = ObjectService::getUnitObjectById($object_id); // Check if user satisifes requirements to build this object. - $requirements_met = ObjectService::objectRequirementsMet($object->machine_name, $planet, $planet->getPlayer(), 0, false); + $requirements_met = ObjectService::objectRequirementsMet($object->machine_name, $planet, $planet->getPlayer()); // Sanity check: check if the planet has enough resources to build // the amount requested. If not, then adjust the ordered amount. diff --git a/app/ViewModels/BuildingViewModel.php b/app/ViewModels/BuildingViewModel.php index 22e78c73..7ad6abaf 100644 --- a/app/ViewModels/BuildingViewModel.php +++ b/app/ViewModels/BuildingViewModel.php @@ -2,14 +2,7 @@ namespace OGame\ViewModels; -use OGame\GameObjects\Models\Abstracts\GameObject; - -class BuildingViewModel +class BuildingViewModel extends QueueViewModel { - public GameObject $object; - public int $current_level; - public bool $requirements_met; - public int $count; - public bool $enough_resources; - public bool $currently_building; + public bool $research_in_progress; } diff --git a/app/ViewModels/QueueViewModel.php b/app/ViewModels/QueueViewModel.php new file mode 100644 index 00000000..60492d65 --- /dev/null +++ b/app/ViewModels/QueueViewModel.php @@ -0,0 +1,15 @@ +