From 09caff2b2a06d1f8ac8203567035a21c612165f9 Mon Sep 17 00:00:00 2001 From: Daniel Weipert Date: Thu, 11 Jan 2024 13:15:02 +0100 Subject: send resources --- src/gemini/Controller/Village.php | 44 +++++++++++++++++++++++++++++---------- 1 file changed, 33 insertions(+), 11 deletions(-) (limited to 'src/gemini/Controller/Village.php') diff --git a/src/gemini/Controller/Village.php b/src/gemini/Controller/Village.php index 70aa899..81a599a 100644 --- a/src/gemini/Controller/Village.php +++ b/src/gemini/Controller/Village.php @@ -6,12 +6,14 @@ use App\DB; use App\Guard; use App\Model\Event; use App\Model\Event\SendResources; +use App\Model\Event\SendResourcesCarriers; use App\Model\Event\SendUnits; use App\Model\Event\TrainUnits; use App\Model\Event\UpgradeBuilding; use App\Model\Unit; -use App\Model\Unit\Merchant; +use App\Model\Unit\MailCarrier; use App\Model\Village as Model; +use App\Support\ResourceType; use App\View; use GeminiFoundation\Request; use GeminiFoundation\Response; @@ -113,6 +115,26 @@ class Village $events['SendResources'][] = DB::convertToModel(SendResources::class, $row);; } + $eventsResourcesCarriersSendOwn = DB::query( + << $village->id] + )->fetchAll(); + + $eventsResourcesCarriersSendOther = DB::query( + << $village->id] + )->fetchAll(); + + foreach ([...$eventsResourcesCarriersSendOwn, ...$eventsResourcesCarriersSendOther] as $row) { + $events['SendResourcesCarriers'][] = DB::convertToModel(SendResourcesCarriers::class, $row);; + } + $buildings = []; foreach (Model::getBuildings($village->id, true) as $building) { $buildings[$building->type] = $building; @@ -124,7 +146,7 @@ class Village 'events' => $events, 'buildings' => $buildings, 'villages' => DB::fetch(Model::class, "select * from villages where id!=:id", ['id' => $village->id]), - 'marketplace' => $village->getBuilding($village->id, 'Marketplace'), + 'postOffice' => $village->getBuilding($village->id, 'PostOffice'), ])); } @@ -147,7 +169,7 @@ class Village $input = intval($request->get('input')); // calculate to max 100% - $allTypes = ['wood', 'clay', 'iron', 'food']; + $allTypes = ResourceType::asProperties(); $allOtherTypes = array_diff($allTypes, [$type]); $storageConfig = $village->getStorageConfig($village->id); @@ -199,7 +221,7 @@ class Village if (empty($selectedResourceType)) { return new Response(body: View::render('send-resources/01-resource-types.twig', [ 'village' => $village, - 'marketplace' => $village->getBuilding($village->id, 'Marketplace'), + 'postOffice' => $village->getBuilding($village->id, 'PostOffice'), ])); } @@ -208,7 +230,7 @@ class Village 'village' => $village, 'villages' => DB::fetch(Model::class, "select * from villages where id!=:id", ['id' => $village->id]), 'selectedResourceType' => $selectedResourceType, - 'marketplace' => $village->getBuilding($village->id, 'Marketplace'), + 'postOffice' => $village->getBuilding($village->id, 'PostOffice'), ])); } $selectedVillage = Model::getByCoordinates($request->get('selectedVillageX'), $request->get('selectedVillageY')); @@ -218,13 +240,13 @@ class Village return new Response(statusCode: Status::INPUT, meta: 'Amount'); } - $resourceCapabilities = Merchant::getResourceCapabilities($village); - $necessaryMerchants = ceil($amount / $resourceCapabilities); - $merchants = DB::fetch(Merchant::class, 'select sum(amount) from village_units where type=:type and residence_village_id=:villageId and is_traveling=false', ['villageId' => $this->source, 'type' => 'Merchant'])[0]['amount'] ?? 0; - if ($merchants === 0) { + $resourceCapabilities = MailCarrier::getResourceCapabilities($village); + $necessaryMailCarriers = ceil($amount / $resourceCapabilities); + $mailCarriers = DB::fetch(MailCarrier::class, 'select sum(amount) as amount from village_units where type=:type and residence_village_id=:villageId and is_traveling=false', ['villageId' => $village->id, 'type' => 'MailCarrier'])[0]->amount ?? 0; + if ($mailCarriers === 0 || $amount > $resourceCapabilities) { return new Response( statusCode: Status::REDIRECT_TEMPORARY, - meta: "/village/{$village->x}/{$village->y}/type/$selectedResourceType/village/{$selectedVillage->x}/{$selectedVillage->y}" + meta: "/village/{$village->x}/{$village->y}/send-resources/type/$selectedResourceType" ); } @@ -234,7 +256,7 @@ class Village $event = new Event(); $event->time = (new \DateTime())->add( \DateInterval::createFromDateString( - Unit::getTravelTime(new Merchant(), Model::getDistance($village->x, $village->y, $destination->x, $destination->y)) + Unit::getTravelTime(new MailCarrier(), Model::getDistance($village->x, $village->y, $destination->x, $destination->y)) . ' seconds' ) ); -- cgit v1.2.3