diff options
author | Daniel Weipert <code@drogueronin.de> | 2023-11-29 09:35:27 +0100 |
---|---|---|
committer | Daniel Weipert <code@drogueronin.de> | 2023-11-29 09:35:27 +0100 |
commit | 3afcaef927391db23fe23c6c8c26b8960e8dae32 (patch) | |
tree | 143b9f6df9e8c795c8c6ed901bffdc7119f40df1 /src/Model/Unit.php | |
parent | c4ce3e884a6aa527bcc138771617215cf03265a4 (diff) |
intermediate commit
Diffstat (limited to 'src/Model/Unit.php')
-rw-r--r-- | src/Model/Unit.php | 30 |
1 files changed, 28 insertions, 2 deletions
diff --git a/src/Model/Unit.php b/src/Model/Unit.php index 621651c..d563682 100644 --- a/src/Model/Unit.php +++ b/src/Model/Unit.php @@ -25,9 +25,26 @@ class Unit public array $resourceRequirements = []; + public static function getEmpty(int $villageId, string $unitType): Unit + { + $unit = new Unit(); + $unit->type = $unitType; + $unit->homeVillageId = $villageId; + $unit->amount = 0; + + return $unit->cast(); + } + + public function getBuildTime(int $amount): int { - return intval(($_ENV['BASE_UNIT_BUILD_TIME_FACTOR'] / ($this->getBuilding()->level ?: 1)) * $amount); + $building = $this->getBuilding(); + + if (! $building) { + return -1; + } + + return intval(($_ENV['BASE_UNIT_BUILD_TIME_FACTOR'] / ($building->level ?: 1)) * $amount); } public static function getTravelTime(Unit $unit, int $distance): int @@ -63,7 +80,16 @@ class Unit function ($resourceRequirement) use ($amount, $currentAmount, $building) { $r = 0; for ($i = 0; $i <= $amount; $i++) { - $r += ceil((pow($_ENV['BASE_UNIT_RESOURCE_REQUIREMENT_BASE'], $currentAmount + 1) * $resourceRequirement * $_ENV['BASE_UNIT_RESOURCE_REQUIREMENT_FACTOR']) / ($building->level ?? 1)); + $r += ceil( + ( + pow( + $_ENV['BASE_UNIT_RESOURCE_REQUIREMENT_BASE'], + $currentAmount + 1 + ) + * $resourceRequirement * $_ENV['BASE_UNIT_RESOURCE_REQUIREMENT_FACTOR'] + ) + / ($building->level ?? 1) + ); } return $r; |