From 801c313f556e15f146b0686b955428312d13ea06 Mon Sep 17 00:00:00 2001 From: Matronator <5470780+matronator@users.noreply.github.com> Date: Sat, 23 Sep 2023 23:50:29 +0200 Subject: [PATCH] fixes --- app/lang/general.cs_CZ.neon | 1 + app/lang/general.en_US.neon | 1 + .../Front/components/UI/Sidebar/Sidebar.latte | 4 +- app/modules/Front/presenters/ApiPresenter.php | 4 +- .../Front/presenters/BuildingsPresenter.php | 485 +++++++++--------- .../Front/presenters/DefaultPresenter.php | 3 - .../Front/presenters/MarketPresenter.php | 5 - 7 files changed, 250 insertions(+), 253 deletions(-) diff --git a/app/lang/general.cs_CZ.neon b/app/lang/general.cs_CZ.neon index 821190c..02dafaf 100755 --- a/app/lang/general.cs_CZ.neon +++ b/app/lang/general.cs_CZ.neon @@ -67,6 +67,7 @@ ui: sidebar: preparing: '(Již brzy)' new: 'NOVÉ' + soon: 'BRZY' player: account: 'Účet' training: 'Trénink' diff --git a/app/lang/general.en_US.neon b/app/lang/general.en_US.neon index ef2b265..d05d3c9 100755 --- a/app/lang/general.en_US.neon +++ b/app/lang/general.en_US.neon @@ -73,6 +73,7 @@ ui: sidebar: preparing: '(Preparing)' new: 'NEW' + soon: 'SOON' player: account: 'Account' inventory: 'Inventory' diff --git a/app/modules/Front/components/UI/Sidebar/Sidebar.latte b/app/modules/Front/components/UI/Sidebar/Sidebar.latte index 8585e90..0ba6729 100644 --- a/app/modules/Front/components/UI/Sidebar/Sidebar.latte +++ b/app/modules/Front/components/UI/Sidebar/Sidebar.latte @@ -13,11 +13,11 @@ {* NEW badge VVV *} {*
  • {_general.ui.sidebar.player.reward} {_general.ui.sidebar.new}
  • *}
  • {_general.ui.sidebar.player.reward}
  • -
  • {_general.ui.sidebar.player.premium} {_general.ui.sidebar.new}
  • +
  • {_general.ui.sidebar.player.premium} {_general.ui.sidebar.soon}
  • {_general.ui.sidebar.player.home}
  • {_general.ui.sidebar.player.account}
  • -
  • {_general.ui.sidebar.player.inventory}
  • +
  • {_general.ui.sidebar.player.inventory} {_general.ui.sidebar.new}
  • {_general.ui.sidebar.player.training}
  • {_general.ui.sidebar.player.rest}
  • diff --git a/app/modules/Front/presenters/ApiPresenter.php b/app/modules/Front/presenters/ApiPresenter.php index 5d4ece4..58b9fe6 100644 --- a/app/modules/Front/presenters/ApiPresenter.php +++ b/app/modules/Front/presenters/ApiPresenter.php @@ -44,9 +44,9 @@ public function actionJob() if ($diff >= 0) { $missionKey = array_search($whatMission, array_column($this->allJobs, 'locale')); $currentMission = $this->allJobs[$missionKey]; - $missionDuration = intval($currentMission['duration'] * 60); + $missionDuration = (int) ($currentMission['duration'] * 60); $s = $diff % 60; - $m = $diff / 60 % 60; + $m = (int) round($diff / 60) % 60; $minutes = $m; $seconds = $s; $timeMax = $missionDuration; diff --git a/app/modules/Front/presenters/BuildingsPresenter.php b/app/modules/Front/presenters/BuildingsPresenter.php index bb8e78d..02667a2 100644 --- a/app/modules/Front/presenters/BuildingsPresenter.php +++ b/app/modules/Front/presenters/BuildingsPresenter.php @@ -11,291 +11,294 @@ final class BuildingsPresenter extends GamePresenter { - public $buildingsRepository; + public $buildingsRepository; private $drugsRepository; - + public function __construct( BuildingsRepository $buildingsRepository, DrugsRepository $drugsRepository - ) - { - parent::__construct(); - $this->buildingsRepository = $buildingsRepository; - $this->drugsRepository = $drugsRepository; - } - - protected function startup() - { - parent::startup(); - } - - public function renderDefault() { - $player = $this->userRepository->getUser($this->user->getIdentity()->id); - $playerLand = $this->buildingsRepository->findPlayerLand($player->id)->fetch(); - $this->template->land = $playerLand; - if (!$playerLand) { - $this->template->emptyLand = $this->buildingsRepository->getLandPrice(); - } else { - $playerBuildings = $this->buildingsRepository->findPlayerBuildings($player->id); - $this->template->playerBuildings = $playerBuildings; - if ($playerBuildings->count() >= 5) { - $fullBuildings = $this->buildingsRepository->findPlayerBuildings($player->id)->where('storage > 0'); - if ($fullBuildings->count() > 0) { - $this->template->collectAll = true; + ) + { + parent::__construct(); + $this->buildingsRepository = $buildingsRepository; + $this->drugsRepository = $drugsRepository; + } + + protected function startup() + { + parent::startup(); + } + + public function renderDefault() { + $player = $this->userRepository->getUser($this->user->getIdentity()->id); + $playerLand = $this->buildingsRepository->findPlayerLand($player->id)->fetch(); + $this->template->land = $playerLand; + if (!$playerLand) { + $this->template->emptyLand = $this->buildingsRepository->getLandPrice(); + } else { + $playerBuildings = $this->buildingsRepository->findPlayerBuildings($player->id); + $this->template->playerBuildings = $playerBuildings; + if ($playerBuildings->count() >= 5) { + $fullBuildings = $this->buildingsRepository->findPlayerBuildings($player->id)->where('storage > 0'); + if ($fullBuildings->count() > 0) { + $this->template->collectAll = true; + } } - } - - $unlockedBuildings = $this->buildingsRepository->findAllUnlocked($player->id)->order('buildings.price DESC'); - $this->template->unlockedBuildings = $unlockedBuildings; - $playerIncome = $this->buildingsRepository->findPlayerIncome($player->id)->fetch(); - $this->template->playerIncome = $playerIncome; - - $drugs = $this->drugsRepository->findAll()->fetchAll(); - $this->template->drugs = $drugs; - $drugsInventory = $this->drugsRepository->findDrugInventory($player->id)->order('drugs_id', 'ASC')->fetchAll(); - $playerDrugs = []; - if (count($drugsInventory) > 0) { - foreach ($drugsInventory as $drug) { - $playerDrugs[$drug->drugs->name] = $drug->quantity; + + $unlockedBuildings = $this->buildingsRepository->findAllUnlocked($player->id)->order('buildings.price DESC'); + $this->template->unlockedBuildings = $unlockedBuildings; + $playerIncome = $this->buildingsRepository->findPlayerIncome($player->id)->fetch(); + $this->template->playerIncome = $playerIncome; + + $drugs = $this->drugsRepository->findAll()->fetchAll(); + $this->template->drugs = $drugs; + $drugsInventory = $this->drugsRepository->findDrugInventory($player->id)->order('drugs_id', 'ASC')->fetchAll(); + $playerDrugs = []; + if (count($drugsInventory) > 0) { + foreach ($drugsInventory as $drug) { + $playerDrugs[$drug->drugs->name] = $drug->quantity; + } + } else { + foreach ($drugs as $drug) { + $playerDrugs[$drug->name] = 0; + } } - } else { - foreach ($drugs as $drug) { - $playerDrugs[$drug->name] = 0; + $this->template->playerDrugs = $playerDrugs; + + $this->template->landUpgradeCost = $this->buildingsRepository->getLandUpgradeCost($playerLand->level); + $this->template->landSlotsNext = $this->buildingsRepository->getLandSlotGain($playerLand->level); + $this->template->landUpgradeTime = round($this->buildingsRepository->getLandUpgradeTime($playerLand->level) / 3600, 0); + $isUpgrading = $playerLand->is_upgrading; + $this->template->isUpgrading = $isUpgrading; + if ($isUpgrading > 0) { + $upgradeUntil = $playerLand->upgrade_end; + $now = new DateTime(); + $diff = $upgradeUntil->getTimestamp() - $now->getTimestamp(); + if ($diff > 0) { + $s = $diff % 60; + $m = $diff / 60 % 60; + $h = $diff / 3600 % 60; + $this->template->hours = $h > 9 ? $h : '0'.$h; + $this->template->minutes = $m > 9 ? $m : '0'.$m; + $this->template->seconds = $s > 9 ? $s : '0'.$s; + $this->template->upgradeUntil = Timezones::getUserTime($upgradeUntil, $this->userPrefs->timezone, $this->userPrefs->dst); + } else { + $this->buildingsRepository->upgradeLand($player->id); + $isUpgrading = 0; + $this->flashMessage('Land upgraded!', 'success'); + $this->redrawControl('playerIncome'); + $this->redrawControl('playerStash'); + $this->redrawControl('buildings'); + $this->redrawControl('land-card'); + $this->redrawControl('sidebar-stats'); + $this->redrawControl('landUpgradeProgress'); + } } - } - $this->template->playerDrugs = $playerDrugs; - - $this->template->landUpgradeCost = $this->buildingsRepository->getLandUpgradeCost($playerLand->level); - $this->template->landSlotsNext = $this->buildingsRepository->getLandSlotGain($playerLand->level); - $this->template->landUpgradeTime = round($this->buildingsRepository->getLandUpgradeTime($playerLand->level) / 3600, 0); - $isUpgrading = $playerLand->is_upgrading; - $this->template->isUpgrading = $isUpgrading; - if ($isUpgrading > 0) { - $upgradeUntil = $playerLand->upgrade_end; - $now = new DateTime(); - $diff = $upgradeUntil->getTimestamp() - $now->getTimestamp(); - if ($diff > 0) { - $s = $diff % 60; - $m = $diff / 60 % 60; - $h = $diff / 3600 % 60; - $this->template->hours = $h > 9 ? $h : '0'.$h; - $this->template->minutes = $m > 9 ? $m : '0'.$m; - $this->template->seconds = $s > 9 ? $s : '0'.$s; - $this->template->upgradeUntil = Timezones::getUserTime($upgradeUntil, $this->userPrefs->timezone, $this->userPrefs->dst); + if (isset($playerIncome->last_collection)) { + $this->template->lastCollection = Timezones::getUserTime($playerIncome->last_collection, $this->userPrefs->timezone, $this->userPrefs->dst); + $updated = $playerIncome->last_collection; + $now = new DateTime(); + $diff = abs($updated->getTimestamp() - $now->getTimestamp()); + if ($diff < 3600) { + $this->template->timeAgo = round($diff / 60) . ' minutes'; + } else if ($diff <= 5400) { + $this->template->timeAgo = round($diff / 3600) . ' hour'; + } else { + $this->template->timeAgo = round($diff / 3600) . ' hours'; + } } else { - $this->buildingsRepository->upgradeLand($player->id); - $isUpgrading = 0; - $this->flashMessage('Land upgraded!', 'success'); + $this->template->noLastCollection = true; + $testIncome = $this->buildingsRepository->findPlayerIncome(1)->fetch(); + $updated = $testIncome->last_collection; + $now = new DateTime(); + $diff = abs($updated->getTimestamp() - $now->getTimestamp()); + if ($diff < 3600) { + $this->template->timeAgo = round($diff / 60) . ' minutes'; + } else if ($diff <= 5400) { + $this->template->timeAgo = round($diff / 3600) . ' hour'; + } else { + $this->template->timeAgo = round($diff / 3600) . ' hours'; + } + } + } + } + + public function renderLands() { + $player = $this->userRepository->getUser($this->user->getIdentity()->id); + $playerLand = $this->buildingsRepository->findPlayerLand($player->id)->fetch(); + $this->template->land = $playerLand; + } + + public function handleUpgradeLand() { + $player = $this->userRepository->getUser($this->user->getIdentity()->id); + $playerLand = $this->buildingsRepository->findPlayerLand($player->id)->fetch(); + if (isset($playerLand->level) && $playerLand->level >= 1 && !$playerLand->is_upgrading) { + $cost = $this->buildingsRepository->getLandUpgradeCost($playerLand->level); + $playerMoney = $player->money; + if ($playerMoney >= $cost) { + $this->buildingsRepository->startLandUpgrade($player->id); + $this->userRepository->addMoney($player->id, -$cost); + $this->flashMessage($this->translate('general.messages.success.landUpgradeStart'), 'success'); $this->redrawControl('playerIncome'); $this->redrawControl('playerStash'); $this->redrawControl('buildings'); $this->redrawControl('land-card'); $this->redrawControl('sidebar-stats'); - $this->redrawControl('landUpgradeProgress'); - } - } - if (isset($playerIncome->last_collection)) { - $this->template->lastCollection = Timezones::getUserTime($playerIncome->last_collection, $this->userPrefs->timezone, $this->userPrefs->dst); - $updated = $playerIncome->last_collection; - $now = new DateTime(); - $diff = abs($updated->getTimestamp() - $now->getTimestamp()); - if ($diff < 3600) { - $this->template->timeAgo = round($diff / 60) . ' minutes'; - } else if ($diff <= 5400) { - $this->template->timeAgo = round($diff / 3600) . ' hour'; } else { - $this->template->timeAgo = round($diff / 3600) . ' hours'; + $this->flashMessage($this->translate('general.messages.danger.notEnoughMoney'), 'danger'); + $this->redrawControl('land-card'); + $this->redrawControl('sidebar-stats'); } } else { - $this->template->noLastCollection = true; - $testIncome = $this->buildingsRepository->findPlayerIncome(1)->fetch(); - $updated = $testIncome->last_collection; - $now = new DateTime(); - $diff = abs($updated->getTimestamp() - $now->getTimestamp()); - if ($diff < 3600) { - $this->template->timeAgo = round($diff / 60) . ' minutes'; - } else if ($diff <= 5400) { - $this->template->timeAgo = round($diff / 3600) . ' hour'; - } else { - $this->template->timeAgo = round($diff / 3600) . ' hours'; - } + $this->redrawControl('sidebar-stats'); + $this->redirect('Buildings:default'); } } - } - - public function renderLands() { - $player = $this->userRepository->getUser($this->user->getIdentity()->id); - $playerLand = $this->buildingsRepository->findPlayerLand($player->id)->fetch(); - $this->template->land = $playerLand; - } - - public function handleUpgradeLand() { - $player = $this->userRepository->getUser($this->user->getIdentity()->id); - $playerLand = $this->buildingsRepository->findPlayerLand($player->id)->fetch(); - if (isset($playerLand->level) && $playerLand->level >= 1 && !$playerLand->is_upgrading) { - $cost = $this->buildingsRepository->getLandUpgradeCost($playerLand->level); + + public function actionBuyLand() { + $player = $this->userRepository->getUser($this->user->getIdentity()->id); + $cost = $this->buildingsRepository->getLandPrice(); $playerMoney = $player->money; - if ($playerMoney >= $cost) { - $this->buildingsRepository->startLandUpgrade($player->id); + if ($playerMoney >= $cost && !$this->buildingsRepository->findPlayerLand($player->id)->fetch()) { + $this->buildingsRepository->buyLand($player->id); $this->userRepository->addMoney($player->id, -$cost); - $this->flashMessage($this->translate('general.messages.success.landUpgradeStart'), 'success'); - $this->redrawControl('playerIncome'); - $this->redrawControl('playerStash'); - $this->redrawControl('buildings'); - $this->redrawControl('land-card'); - $this->redrawControl('sidebar-stats'); + $this->flashMessage($this->translate('general.messages.success.landBought'), 'success'); + $this->redirect('Buildings:default'); } else { $this->flashMessage($this->translate('general.messages.danger.notEnoughMoney'), 'danger'); - $this->redrawControl('land-card'); + $this->redirect('Buildings:default'); } - } else { - $this->redirect('Buildings:default'); - } - } - - public function actionBuyLand() { - $player = $this->userRepository->getUser($this->user->getIdentity()->id); - $cost = $this->buildingsRepository->getLandPrice(); - $playerMoney = $player->money; - if ($playerMoney >= $cost && !$this->buildingsRepository->findPlayerLand($player->id)->fetch()) { - $this->buildingsRepository->buyLand($player->id); - $this->userRepository->addMoney($player->id, -$cost); - $this->flashMessage($this->translate('general.messages.success.landBought'), 'success'); - $this->redirect('Buildings:default'); - } else { - $this->flashMessage($this->translate('general.messages.danger.notEnoughMoney'), 'danger'); - $this->redirect('Buildings:default'); } - } - - public function handleBuyBuilding(int $b) { - $player = $this->userRepository->getUser($this->user->getIdentity()->id); - $building = $this->buildingsRepository->getBuilding($b)->fetch(); - if (!$building) { - $this->flashMessage($this->translate('general.messages.danger.buildingNotFound'), 'danger'); - $this->redirect('Buildings:default'); + + public function handleBuyBuilding(int $b) { + $player = $this->userRepository->getUser($this->user->getIdentity()->id); + $building = $this->buildingsRepository->getBuilding($b)->fetch(); + if (!$building) { + $this->flashMessage($this->translate('general.messages.danger.buildingNotFound'), 'danger'); + $this->redirect('Buildings:default'); + } + if (isset($building->user_id) && $building->user_id === $player->id && $building->level === 0) { + $playerMoney = $player->money; + $cost = $building->buildings->price; + if ($playerMoney >= $cost) { + $this->buildingsRepository->buyBuilding($player->id, $building->buildings_id, $b); + $this->userRepository->addMoney($player->id, -$cost); + $this->flashMessage($this->translate('general.messages.success.buildingBought'), 'success'); + $this->redrawControl('playerIncome'); + $this->redrawControl('playerStash'); + $this->redrawControl('buildings'); + $this->redrawControl('sidebar-stats'); + } else { + $this->flashMessage($this->translate('general.messages.danger.notEnoughMoney'), 'danger'); + $this->redrawControl('sidebar-stats'); + $this->redrawControl('buildings'); + } + } } - if (isset($building->user_id) && $building->user_id === $player->id && $building->level === 0) { - $playerMoney = $player->money; - $cost = $building->buildings->price; - if ($playerMoney >= $cost) { - $this->buildingsRepository->buyBuilding($player->id, $building->buildings_id, $b); - $this->userRepository->addMoney($player->id, -$cost); - $this->flashMessage($this->translate('general.messages.success.buildingBought'), 'success'); - $this->redrawControl('playerIncome'); - $this->redrawControl('playerStash'); - $this->redrawControl('buildings'); - $this->redrawControl('sidebar-stats'); + + public function handleCollect(int $b) { + $player = $this->userRepository->getUser($this->user->getIdentity()->id); + $building = $this->buildingsRepository->getBuilding($b)->fetch(); + if (!$building) { + $this->flashMessage($this->translate('general.messages.danger.buildingNotFound'), 'danger'); + $this->redirect('Buildings:default'); + } + if ($building->user_id === $player->id) { + if ($building->storage > 0) { + $drugId = $building->buildings->drugs_id; + $this->drugsRepository->buyDrugs($player->id, $drugId, $building->storage); + $this->buildingsRepository->getBuilding($building->id)->update([ + 'storage' => 0 + ]); + $this->statisticsRepository->findByUser($player->id)->update([ + 'buildings_collected+=' => 1, + ]); + $this->flashMessage($this->translate('general.messages.success.buildingCollected'), 'success'); + // $this->redirect('Buildings:default'); + $this->redrawControl('playerStash'); + $this->redrawControl('buildings'); + $this->redrawControl('sidebar-stats'); + } else { + // $this->redrawControl('buildings'); + $this->redirect('Buildings:default'); + } } else { - $this->flashMessage($this->translate('general.messages.danger.notEnoughMoney'), 'danger'); - $this->redrawControl('buildings'); + $this->flashMessage($this->translate('general.messages.danger.somethingFishy'), 'danger'); + $this->redirect('Buildings:default'); } } - } - - public function handleCollect(int $b) { - $player = $this->userRepository->getUser($this->user->getIdentity()->id); - $building = $this->buildingsRepository->getBuilding($b)->fetch(); - if (!$building) { - $this->flashMessage($this->translate('general.messages.danger.buildingNotFound'), 'danger'); - $this->redirect('Buildings:default'); - } - if ($building->user_id === $player->id) { - if ($building->storage > 0) { + + public function handleCollectAll() { + $player = $this->userRepository->getUser($this->user->getIdentity()->id); + $buildings = $this->buildingsRepository->findPlayerBuildings($player->id)->where('storage > 0')->where('user_id', $player->id); + $count = 0; + foreach ($buildings as $building) { $drugId = $building->buildings->drugs_id; $this->drugsRepository->buyDrugs($player->id, $drugId, $building->storage); - $this->buildingsRepository->getBuilding($building->id)->update([ - 'storage' => 0 + $building->update(['storage' => 0]); + $count++; + } + if ($count > 0) { + $this->statisticsRepository->findByUser($player->id)->update([ + 'buildings_collected+=' => $count, ]); - $this->statisticsRepository->findByUser($player->id)->update([ - 'buildings_collected+=' => 1, - ]); - $this->flashMessage($this->translate('general.messages.success.buildingCollected'), 'success'); - // $this->redirect('Buildings:default'); + $this->flashMessage($this->translate('general.messages.success.allBuildingCollected'), 'success'); $this->redrawControl('playerStash'); $this->redrawControl('buildings'); $this->redrawControl('sidebar-stats'); - } else { - // $this->redrawControl('buildings'); - $this->redirect('Buildings:default'); } - } else { - $this->flashMessage($this->translate('general.messages.danger.somethingFishy'), 'danger'); - $this->redirect('Buildings:default'); - } - } - - public function handleCollectAll() { - $player = $this->userRepository->getUser($this->user->getIdentity()->id); - $buildings = $this->buildingsRepository->findPlayerBuildings($player->id)->where('storage > 0')->where('user_id', $player->id); - $count = 0; - foreach ($buildings as $building) { - $drugId = $building->buildings->drugs_id; - $this->drugsRepository->buyDrugs($player->id, $drugId, $building->storage); - $building->update(['storage' => 0]); - $count++; } - if ($count > 0) { - $this->statisticsRepository->findByUser($player->id)->update([ - 'buildings_collected+=' => $count, - ]); - $this->flashMessage($this->translate('general.messages.success.allBuildingCollected'), 'success'); - $this->redrawControl('playerStash'); - $this->redrawControl('buildings'); - $this->redrawControl('sidebar-stats'); - } - } - - public function handleUpgrade(int $b) { - $player = $this->userRepository->getUser($this->user->getIdentity()->id); - $building = $this->buildingsRepository->getBuilding($b)->fetch(); - if (isset($building->user_id) && $building->user_id === $player->id) { - $playerMoney = $player->money; - $cost = $this->getUpgradeCost($building->buildings->price, $building->level); - if (!$building->buildings->max_level || $building->level < $building->buildings->max_level) { - if ($playerMoney >= $cost) { - if ($this->buildingsRepository->upgradeBuilding($b, $player->id)) { - $this->userRepository->addMoney($player->id, -$cost); - $this->flashMessage($this->translate('general.messages.success.buildingUpgraded'), 'success'); + + public function handleUpgrade(int $b) { + $player = $this->userRepository->getUser($this->user->getIdentity()->id); + $building = $this->buildingsRepository->getBuilding($b)->fetch(); + if (isset($building->user_id) && $building->user_id === $player->id) { + $playerMoney = $player->money; + $cost = $this->getUpgradeCost($building->buildings->price, $building->level); + if (!$building->buildings->max_level || $building->level < $building->buildings->max_level) { + if ($playerMoney >= $cost) { + if ($this->buildingsRepository->upgradeBuilding($b, $player->id)) { + $this->userRepository->addMoney($player->id, -$cost); + $this->flashMessage($this->translate('general.messages.success.buildingUpgraded'), 'success'); + } else { + $this->flashMessage($this->translate('general.messages.danger.somethingFishy'), 'danger'); + } } else { - $this->flashMessage($this->translate('general.messages.danger.somethingFishy'), 'danger'); + $this->flashMessage($this->translate('general.messages.danger.notEnoughMoney'), 'danger'); } } else { - $this->flashMessage($this->translate('general.messages.danger.notEnoughMoney'), 'danger'); + $this->flashMessage('This building is at maximum level or is not upgradable!', 'danger'); } + $this->redrawControl('playerIncome'); + $this->redrawControl('buildings'); + $this->redrawControl('sidebar-stats'); } else { - $this->flashMessage('This building is at maximum level or is not upgradable!', 'danger'); + $this->redirect('Buildings:default'); } - $this->redrawControl('playerIncome'); - $this->redrawControl('buildings'); - $this->redrawControl('sidebar-stats'); - } else { - $this->redirect('Buildings:default'); } - } - - public function handleDemolish(int $b) { - $building = $this->buildingsRepository->getBuilding($b)->fetch(); - if (!$building) { - $this->flashMessage($this->translate('general.messages.danger.buildingNotFound'), 'danger'); - $this->redirect('Buildings:default'); - } - if ($building->user_id === $this->user->getIdentity()->id) { - if ($this->buildingsRepository->demolishBuilding($b, $this->user->getIdentity()->id)) { - $this->flashMessage('Building demolished!', 'success'); + + public function handleDemolish(int $b) { + $building = $this->buildingsRepository->getBuilding($b)->fetch(); + if (!$building) { + $this->flashMessage($this->translate('general.messages.danger.buildingNotFound'), 'danger'); + $this->redirect('Buildings:default'); + } + if ($building->user_id === $this->user->getIdentity()->id) { + if ($this->buildingsRepository->demolishBuilding($b, $this->user->getIdentity()->id)) { + $this->flashMessage('Building demolished!', 'success'); + } else { + $this->flashMessage('Building not found!', 'danger'); + } + $this->redrawControl('playerIncome'); + $this->redrawControl('buildings'); + $this->redrawControl('sidebar-stats'); } else { - $this->flashMessage('Building not found!', 'danger'); + $this->redirect('Buildings:default'); } - $this->redrawControl('playerIncome'); - $this->redrawControl('buildings'); - $this->redrawControl('sidebar-stats'); - } else { - $this->redirect('Buildings:default'); + } + + public function getUpgradeCost(int $basePrice = 0, int $level = 1): int + { + return (int) round(($basePrice * ($level ** 1.05)) / 2, -1); } } - - public function getUpgradeCost(int $basePrice = 0, int $level = 1): int - { - return (int) round(($basePrice * ($level ** 1.05)) / 2, -1); - } -} diff --git a/app/modules/Front/presenters/DefaultPresenter.php b/app/modules/Front/presenters/DefaultPresenter.php index 8bcc38a..c1fcc07 100755 --- a/app/modules/Front/presenters/DefaultPresenter.php +++ b/app/modules/Front/presenters/DefaultPresenter.php @@ -9,13 +9,10 @@ use Nette\Application\UI\Form; use DateTime; use ActionLocker; -use App\Libs\Notifications; use App\Model\AssaultsRepository; use App\Model\BuildingsRepository; use App\Model\MiscRepository; -use Nette\Database\Table\ActiveRow; use Timezones; -use Tracy\Debugger; /////////////////////// FRONT: DEFAULT PRESENTER /////////////////////// diff --git a/app/modules/Front/presenters/MarketPresenter.php b/app/modules/Front/presenters/MarketPresenter.php index 5f4dd5f..e828a1e 100644 --- a/app/modules/Front/presenters/MarketPresenter.php +++ b/app/modules/Front/presenters/MarketPresenter.php @@ -4,12 +4,7 @@ namespace App\FrontModule\Presenters; -use App\Model; -use App\Model\Entity\PlayerBody; -use App\Model\InventoryRepository; use App\Model\ItemsRepository; -use App\Model\MarketRepository; -use Tracy\Debugger; /////////////////////// FRONT: DEFAULT PRESENTER ///////////////////////