diff options
Diffstat (limited to 'src/Model/Building.php')
-rw-r--r-- | src/Model/Building.php | 23 |
1 files changed, 20 insertions, 3 deletions
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( + <<<SQL + select * from events_upgrade_building + inner join events on events.id = events_upgrade_building.event_id + where events.village_id=:villageId and events_upgrade_building.type=:type + SQL, + ['villageId' => $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); } /** |