get('input'))) { return new Response(statusCode: Status::INPUT, meta: 'Amount'); } $village = Village::getByCoordinates($request->get('x'), $request->get('y')); /**@var Model $unit*/ $unit = new (Model::resolveType($request->get('type')))(); $unit->type = $request->get('type'); $unit->homeVillageId = $village->id; $amount = intval($request->get('input')); if (! Village::canTrain($village, $unit, $amount)) { return new Response( statusCode: Status::REDIRECT_TEMPORARY, meta: "/village/{$village->x}/{$village->y}" ); } // resources foreach (Model::getResourceRequirements($unit, $amount) as $resourceType => $resourceValue) { $village->{$resourceType} -= $resourceValue; } $village->updateResources(); // event $event = new Event(); $event->time = (new \DateTime())->add(\DateInterval::createFromDateString($unit->getBuildTime($amount) . ' seconds')); $event->villageId = $village->id; $trainUnitsEvent = new TrainUnits(); $trainUnitsEvent->event = $event; $trainUnitsEvent->type = $request->get('type'); $trainUnitsEvent->amount = $amount; $trainUnitsEvent->dbInsert(); return new Response( statusCode: Status::REDIRECT_TEMPORARY, meta: "/village/{$village->x}/{$village->y}" ); } }