From e4351601a7ced91bf5a2c516a38db714d43e6ecf Mon Sep 17 00:00:00 2001 From: Daniel Weipert Date: Mon, 8 Jan 2024 22:28:02 +0100 Subject: send resources + adminer css --- src/Model/Village.php | 30 +++++++++++++++++++++++++++++- 1 file changed, 29 insertions(+), 1 deletion(-) (limited to 'src/Model/Village.php') diff --git a/src/Model/Village.php b/src/Model/Village.php index c6709a6..019d9ba 100644 --- a/src/Model/Village.php +++ b/src/Model/Village.php @@ -3,6 +3,7 @@ namespace App\Model; use App\DB; +use App\Model\Building\Marketplace; use App\Model\Building\Storage; use App\Model\Village\StorageConfig; @@ -53,6 +54,21 @@ class Village return true; } + public static function canSendResources(Village $village): bool + { + $marketplace = Village::getBuilding($village->id, 'Marketplace'); + if (! $marketplace) { + return false; + } + + $merchants = Village::getUnit($village, $marketplace->unitType, Village::FETCH_UNIT_RESIDENCE, Village::RETURN_UNIT_EXISTING); + if (! $merchants || $merchants->amount === 0) { + return false; + } + + return true; + } + /* DB - Actions */ public static function get(int $id): ?Village @@ -136,8 +152,20 @@ class Village public const RETURN_UNIT_ALL = 2; public const RETURN_UNIT_TRAINABLE = 3; - public static function getUnit(string $unitType, int $flag): ?Unit + public static function getUnit(Village $village, string $unitType, int $fetchFlag = Village::FETCH_UNIT_RESIDENCE, int $returnFlag = Village::RETURN_UNIT_EXISTING): ?Unit { + if ($fetchFlag == Village::FETCH_UNIT_RESIDENCE) { + $query = 'select * from village_units where residence_village_id=:id and type=:type and is_traveling=false'; + } + + $results = DB::fetch(Unit::class, $query, ['id' => $village->id, 'type' => $unitType]); + if (isset($results[0])) { + $unit = $results[0]->cast(); + } else { + return null; + } + + return $unit; } /** -- cgit v1.2.3