$villages, ])); } #[Route(path: '/village/{x}/{y}', methods: ['GET'])] public function show(Request $request): Response { $village = Model::getByCoordinates($request->get('x'), $request->get('y')); $events = []; $eventsBuilding = DB::query( << $village->id, 'type' => 'UpgradeBuilding'] )->fetchAll(); foreach ($eventsBuilding as $row) { $events[$row['type']][] = [ 'event' => DB::convertToModel(UpgradeBuilding::class, $row), 'data' => json_decode($row['payload']), ]; } $eventsUnits = DB::query( << 'TrainUnits', 'id' => $village->id] )->fetchAll(); foreach ($eventsUnits as $row) { $events[$row['type']][] = [ 'event' => DB::convertToModel(TrainUnits::class, $row), 'data' => json_decode($row['payload'], true), ]; } $eventsUnitsSendOwn = DB::query( << 'SendUnits', 'id' => $village->id] )->fetchAll(); $eventsUnitsSendOther = DB::query( <<>'destination')::bigint=:id and (payload->>'cancel') is null SQL, ['type' => 'SendUnits', 'id' => $village->id] )->fetchAll(); foreach ([...$eventsUnitsSendOwn, ...$eventsUnitsSendOther] as $row) { $events[$row['type']][] = [ 'event' => DB::convertToModel(SendUnits::class, $row), 'data' => json_decode($row['payload'], true), ]; } $buildings = []; foreach (Model::getBuildings($village->id, true) as $building) { $buildings[$building->type] = $building; } return new Response(View::render('village.twig', [ 'village' => $village, 'events' => $events, 'buildings' => $buildings, 'villages' => DB::fetch(Model::class, "select * from villages where id!=:id", ['id' => $village->id]), ])); } #[Route(path: '/village/{x}/{y}/storage/config', methods: ['POST'])] public function storageConfig(Request $request): Response { $village = Model::getByCoordinates($request->get('x'), $request->get('y')); // calculate to max 100% $wood = intval($request->get('wood')); $clay = intval($request->get('clay')); $iron = intval($request->get('iron')); $food = intval($request->get('food')); $total = $wood + $clay + $iron + $food; $woodPercent = $wood / $total; $clayPercent = $clay / $total; $ironPercent = $iron / $total; $foodPercent = $food / $total; $wood = round($woodPercent * 100); $clay = round($clayPercent * 100); $iron = round($ironPercent * 100); $food = round($foodPercent * 100); $newTotal = $wood+$clay+$iron+$food; $food += (100 - $newTotal); DB::query( << $wood, 'clay' => $clay, 'iron' => $iron, 'food' => $food, 'id' => $village->id] ); return new RedirectResponse( Router::generate( 'village.show', ['x' => $request->get('x'), 'y' => $request->get('y')] ) ); } }