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/Model/Village.php | 35 ++++++++++++++++++++++++----------- 1 file changed, 24 insertions(+), 11 deletions(-) (limited to 'src/Model/Village.php') diff --git a/src/Model/Village.php b/src/Model/Village.php index 019d9ba..03a57b7 100644 --- a/src/Model/Village.php +++ b/src/Model/Village.php @@ -3,7 +3,7 @@ namespace App\Model; use App\DB; -use App\Model\Building\Marketplace; +use App\Model\Building\PostOffice; use App\Model\Building\Storage; use App\Model\Village\StorageConfig; @@ -56,13 +56,13 @@ class Village public static function canSendResources(Village $village): bool { - $marketplace = Village::getBuilding($village->id, 'Marketplace'); - if (! $marketplace) { + $postOffice = Village::getBuilding($village->id, 'PostOffice'); + if (! $postOffice) { return false; } - $merchants = Village::getUnit($village, $marketplace->unitType, Village::FETCH_UNIT_RESIDENCE, Village::RETURN_UNIT_EXISTING); - if (! $merchants || $merchants->amount === 0) { + $mailCarriers = Village::getUnit($village, $postOffice->unitType, Village::FETCH_UNIT_RESIDENCE, Village::RETURN_UNIT_EXISTING); + if (! $mailCarriers || $mailCarriers->amount === 0) { return false; } @@ -89,9 +89,9 @@ class Village ); } - public static function getDistance(int $x, int $y, int $dx, int $dy): int + public static function getDistance(int $x1, int $y1, int $x2, int $y2): int { - return abs($x - $dx) + abs($y - $dy); + return abs($x1 - $x2) + abs($y1 - $y2); } /* DB - Relations */ @@ -102,7 +102,7 @@ class Village if ($withEmpty) { $nonBuiltBuildings = array_diff( - ['TownHall', 'Embassy', 'Marketplace', 'Storage', 'WoodCutter', 'ClayPit', 'IronMine', 'Farm'], + ['TownHall', 'Embassy', 'PostOffice', 'Storage', 'WoodCutter', 'ClayPit', 'IronMine', 'Farm'], array_column($buildings, 'type'), ); @@ -190,7 +190,7 @@ class Village if ($returnFlag == Village::RETURN_UNIT_ALL || $returnFlag == Village::RETURN_UNIT_TRAINABLE) { $nonExistingUnits = array_diff( - ['WoodCutter', 'PitWorker', 'Miner', 'Farmer', 'Merchant', 'Diplomat'], + ['WoodCutter', 'PitWorker', 'Miner', 'Farmer', 'MailCarrier', 'Diplomat'], array_column($units, 'type'), ); @@ -206,12 +206,25 @@ class Village } else if ($returnFlag == Village::RETURN_UNIT_EXISTING) { $units = array_filter($units, function (Unit $unit) { - return ! $unit->isTraveling; + return ! $unit->isTraveling && $unit->amount > 0; }); } - return array_map(function (Unit $unit) { + // cast + $units = array_map(function (Unit $unit) { return $unit->cast(); }, $units); + + // filter out empty traveling rows + $units = array_filter($units, function (Unit $unit) { + if ($unit->isTraveling && $unit->amount === 0) { + return false; + } + + return true; + }); + + + return $units; } } -- cgit v1.2.3