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 UpgradeBuilding(); $event->type = 'UpgradeBuilding'; $event->time = (new \DateTime())->add(\DateInterval::createFromDateString($building->getBuildTime() . ' seconds')); $event->payload = json_encode([ 'type' => $building->type, 'village_id' => $building->villageId, ]); DB::query( 'insert into events (type, time, payload, village_id) VALUES (:type, :time, :payload, :id)', ['type' => $event->type, 'time' => $event->time->format('c'), 'payload' => $event->payload, 'id' => $village->id] ); return new RedirectResponse( Router::generate( 'village.show', ['x' => $request->get('x'), 'y' => $request->get('y')] ) ); } }