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/Unit.php | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) (limited to 'src/Model/Unit.php') diff --git a/src/Model/Unit.php b/src/Model/Unit.php index 206f5dd..d121aa7 100644 --- a/src/Model/Unit.php +++ b/src/Model/Unit.php @@ -4,6 +4,7 @@ namespace App\Model; use App\DB; use App\Model; +use App\Support\ResourceType; class Unit { @@ -20,8 +21,13 @@ class Unit public string $updatedAt; public string $buildingType; + + public int $buildTimeFactor; + public int $travelTime; + public int $populationDemandFactor; + public array $resourceRequirementsBase = []; public array $resourceRequirementsFactor = []; @@ -30,6 +36,7 @@ class Unit { $unit = new Unit(); $unit->type = $unitType; + $unit->isTraveling = false; $unit->homeVillageId = $villageId; $unit->amount = 0; @@ -45,9 +52,10 @@ class Unit return -1; } - return intval(($_ENV['BASE_UNIT_BUILD_TIME_FACTOR'] / ($building->level ?: 1)) * $amount); + return intval((($_ENV['BASE_UNIT_BUILD_TIME_FACTOR'] * $this->buildTimeFactor) / ($building->level ?: 1)) * $amount); } + public static function getTravelTime(Unit $unit, int $distance): int { return self::getTravelTimePerCell($unit) * $distance; @@ -77,7 +85,7 @@ class Unit )->fetchColumn(); $resourceRequirements = []; - foreach (['wood', 'clay', 'iron', 'food'] as $resourceType) { + foreach (ResourceType::asProperties() as $resourceType) { $base = $unit->resourceRequirementsBase[$resourceType]; $factor = $unit->resourceRequirementsFactor[$resourceType]; @@ -101,6 +109,7 @@ class Unit return $resourceRequirements; } + public function getPopulationDemand(): int { return $this->getPopulationDemandForAmount($this->amount); -- cgit v1.2.3