summaryrefslogtreecommitdiff
path: root/src/Model/Village.php
diff options
context:
space:
mode:
authorDaniel Weipert <code@drogueronin.de>2023-11-29 09:35:27 +0100
committerDaniel Weipert <code@drogueronin.de>2023-11-29 09:35:27 +0100
commit3afcaef927391db23fe23c6c8c26b8960e8dae32 (patch)
tree143b9f6df9e8c795c8c6ed901bffdc7119f40df1 /src/Model/Village.php
parentc4ce3e884a6aa527bcc138771617215cf03265a4 (diff)
intermediate commit
Diffstat (limited to 'src/Model/Village.php')
-rw-r--r--src/Model/Village.php46
1 files changed, 39 insertions, 7 deletions
diff --git a/src/Model/Village.php b/src/Model/Village.php
index b1ab19e..6c80ed0 100644
--- a/src/Model/Village.php
+++ b/src/Model/Village.php
@@ -80,10 +80,21 @@ class Village
/* DB - Relations */
- public static function getBuildings(int $villageId): array
+ public static function getBuildings(int $villageId, bool $withEmpty = false): array
{
$buildings = DB::fetch(Building::class, 'select * from village_buildings where village_id=:id', ['id' => $villageId]);
+ if ($withEmpty) {
+ $nonBuiltBuildings = array_diff(
+ ['TownHall', 'Embassy', 'Marketplace', 'Storage', 'WoodCutter', 'ClayPit', 'IronMine', 'Farm'],
+ array_column($buildings, 'type'),
+ );
+
+ foreach ($nonBuiltBuildings as $type) {
+ $buildings[] = Building::getEmpty($villageId, $type);
+ }
+ }
+
return array_map(function (Building $building) {
return $building->cast();
}, $buildings);
@@ -121,30 +132,51 @@ class Village
public const FETCH_UNIT_SUPPORT_AT_HOME = 3;
public const FETCH_UNIT_RESIDENCE = 4;
+ public const RETURN_UNIT_EXISTING = 1;
+ public const RETURN_UNIT_ALL = 2;
+ public const RETURN_UNIT_TRAINABLE = 3;
+
public static function getUnit(string $unitType, int $flag): ?Unit
{
}
/**
- * @param int $flag
+ * @param int $fetchFlag
*
* @return array<int, Unit>
*/
- public static function getUnits(int $villageId, $flag = Village::FETCH_UNIT_ALL): array
+ public static function getUnits(int $villageId, int $fetchFlag = Village::FETCH_UNIT_ALL, int $returnFlag = Village::RETURN_UNIT_EXISTING): array
{
- if ($flag == Village::FETCH_UNIT_HOME_AT_HOME) {
+ if ($fetchFlag == Village::FETCH_UNIT_HOME_AT_HOME) {
$units = DB::fetch(Unit::class, 'select * from village_units where home_village_id=:id and residence_village_id=:id', ['id' => $villageId]);
}
- else if ($flag == Village::FETCH_UNIT_HOME_AT_SUPPORT) {
+ else if ($fetchFlag == Village::FETCH_UNIT_HOME_AT_SUPPORT) {
$units = DB::fetch(Unit::class, 'select * from village_units where home_village_id=:id and residence_village_id!=:id', ['id' => $villageId]);
}
- else if ($flag == Village::FETCH_UNIT_SUPPORT_AT_HOME) {
+ else if ($fetchFlag == Village::FETCH_UNIT_SUPPORT_AT_HOME) {
$units = DB::fetch(Unit::class, 'select * from village_units where home_village_id!=:id and residence_village_id=:id', ['id' => $villageId]);
}
- else if ($flag == Village::FETCH_UNIT_RESIDENCE) {
+ else if ($fetchFlag == Village::FETCH_UNIT_RESIDENCE) {
$units = DB::fetch(Unit::class, 'select * from village_units where residence_village_id=:id', ['id' => $villageId]);
}
+ if ($returnFlag == Village::RETURN_UNIT_ALL || $returnFlag == Village::RETURN_UNIT_TRAINABLE) {
+ $nonExistingUnits = array_diff(
+ ['WoodCutter', 'PitWorker', 'Miner', 'Farmer', 'Merchant', 'Diplomat'],
+ array_column($units, 'type'),
+ );
+
+ foreach ($nonExistingUnits as $type) {
+ $units[] = Unit::getEmpty($villageId, $type);
+ }
+
+ if ($returnFlag == Village::RETURN_UNIT_TRAINABLE) {
+ $units = array_filter($units, function (Unit $unit) {
+ return !! $unit->cast()->getBuilding();
+ });
+ }
+ }
+
return array_map(function (Unit $unit) {
return $unit->cast();
}, $units);