diff options
author | Daniel Weipert <code@drogueronin.de> | 2023-12-02 14:14:34 +0100 |
---|---|---|
committer | Daniel Weipert <code@drogueronin.de> | 2023-12-02 14:14:34 +0100 |
commit | e5a243a52b910e35b10b26c06aa8978356b86769 (patch) | |
tree | 74ddb82add2f3ea200e9fd11cfedb6c0cace09be /src/Model/Building.php | |
parent | fa9096c0ab521aae45cab6c48a54290d14a221b9 (diff) |
login and events
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); } /** |