summaryrefslogtreecommitdiff
path: root/src/Model/Village.php
diff options
context:
space:
mode:
Diffstat (limited to 'src/Model/Village.php')
-rw-r--r--src/Model/Village.php35
1 files changed, 24 insertions, 11 deletions
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;
}
}