From e5a243a52b910e35b10b26c06aa8978356b86769 Mon Sep 17 00:00:00 2001 From: Daniel Weipert Date: Sat, 2 Dec 2023 14:14:34 +0100 Subject: login and events --- src/Model/Building.php | 23 ++++++++++++++++++++--- 1 file changed, 20 insertions(+), 3 deletions(-) (limited to 'src/Model/Building.php') diff --git a/src/Model/Building.php b/src/Model/Building.php index 7cae067..eefb4df 100644 --- a/src/Model/Building.php +++ b/src/Model/Building.php @@ -65,13 +65,30 @@ class Building } + public function getEffectiveLevel(): int + { + $upgradeEvents = DB::query( + << $this->villageId, 'type' => $this->type] + )->fetchAll(); + + return $this->level + count($upgradeEvents); + } + public function getBuildTime(): int { - $townHall = Village::getBuilding($this->villageId, 'TownHall'); + return $this->getBuildTimeForLevel($this->level + 1); + } - $nextLevel = $this->level + 1; + public function getBuildTimeForLevel(int $level): int + { + $townHall = Village::getBuilding($this->villageId, 'TownHall'); - return intval($nextLevel * ($nextLevel / $townHall->level) * $_ENV['BASE_BUILDING_BUILD_TIME_FACTOR'] * $this->buildTimeFactor); + return intval($level * ($level / $townHall->level) * $_ENV['BASE_BUILDING_BUILD_TIME_FACTOR'] * $this->buildTimeFactor); } /** -- cgit v1.2.3