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')] ) ); } }