diff options
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; |