summaryrefslogtreecommitdiff
path: root/src/Controller/Building.php
diff options
context:
space:
mode:
authorDaniel Weipert <git@mail.dweipert.de>2024-01-02 20:42:01 +0100
committerDaniel Weipert <git@mail.dweipert.de>2024-01-05 12:33:59 +0100
commitb21316248572cb27ed1f504529ad6680a473022e (patch)
treef8a2f81258cae3b1d2429fb7df5a3287954b683a /src/Controller/Building.php
parentf621d95f89ded05a2e916c5ee363bfe75ea37482 (diff)
gemini
Diffstat (limited to 'src/Controller/Building.php')
-rw-r--r--src/Controller/Building.php47
1 files changed, 0 insertions, 47 deletions
diff --git a/src/Controller/Building.php b/src/Controller/Building.php
deleted file mode 100644
index e141113..0000000
--- a/src/Controller/Building.php
+++ /dev/null
@@ -1,47 +0,0 @@
-<?php
-
-namespace App\Controller;
-
-use App\Model\Building as Model;
-use App\Model\Event;
-use App\Model\Event\UpgradeBuilding;
-use App\Model\Village;
-use App\Router;
-use Symfony\Component\HttpFoundation\RedirectResponse;
-use Symfony\Component\HttpFoundation\Request;
-use Symfony\Component\HttpFoundation\Response;
-use Symfony\Component\Routing\Annotation\Route;
-
-class Building
-{
- #[Route(path: '/village/{x}/{y}/building/{type}/level-up', methods: ['POST'])]
- public function levelUp(Request $request): Response
- {
- $village = Village::getByCoordinates($request->get('x'), $request->get('y'));
- $building = Model::getByVillage($village->id, $request->get('type')) ?? Model::getEmpty($village->id, $request->get('type'));
-
- // resources
- foreach ($building->getResourceRequirements() as $resourceType => $resourceValue) {
- $village->{$resourceType} -= $resourceValue;
- }
- $village->updateResources();
-
- // event
- $event = new Event();
- $event->time = (new \DateTime())->add(\DateInterval::createFromDateString(
- $building->getBuildTimeForLevel($building->getEffectiveLevel() + 1) . ' seconds'
- ));
- $event->villageId = $building->villageId;
- $upgradeBuildingEvent = new UpgradeBuilding();
- $upgradeBuildingEvent->event = $event;
- $upgradeBuildingEvent->type = $building->type;
- $upgradeBuildingEvent->dbInsert();
-
- return new RedirectResponse(
- Router::generate(
- 'village.show',
- ['x' => $request->get('x'), 'y' => $request->get('y')]
- )
- );
- }
-}