/** * @param App\GameModule\DTO\Village $village * @return int */ public function getBaseProductionCrop($village) { $production = 0; $FData = $village->getFData(); $grainMill = FALSE; $bakery = FALSE; $cropFields = []; // Step 1 find fields for ($i = 1; $i <= 38; $i++) { if ($FData['f' . $i . 't'] === App\GameModule\Model\Building\BuildingModel::CROPLAND) { $cropFields[] = $FData['f' . $i]; } if ($FData['f' . $i . 't'] === App\GameModule\Model\Building\BuildingModel::GRAIN_MILL) { $grainMill = $FData['f' . $i]; } if ($FData['f' . $i . 't'] === App\GameModule\Model\Building\BuildingModel::BAKERY) { $bakery = $FData['f' . $i]; } } // Step 2 calculate raw production foreach ($cropFields as $level) { /** @var \stdClass $cropland */ $cropland = $this->buildingModel->getBuildingLevel(4, $level); $production += $cropland->production; } // Step 3 apply oasis $production = $production * (1 + 0.25 * $this->ODataModel->countByUserVillage($village->getOwner()->id, $village->getId(), App\FrontModule\Model\OData\ODataModel::MODE_CROP) + 0.5 * $this->ODataModel->countByUserVillage($village->getOwner()->id, $village->getId(), App\FrontModule\Model\OData\ODataModel::MODE_CROP_BIG)); // Step 4 apply grainMill and bakery if ($grainMill) { /** @var \stdClass $grainMill */ $grainMill = $this->buildingModel->getBuildingLevel(App\GameModule\Model\Building\BuildingModel::GRAIN_MILL, $grainMill); $production = $production * ($grainMill->attribute / 100 + 1); } if ($bakery) { /** @var \stdClass $bakery */ $bakery = $this->buildingModel->getBuildingLevel(App\GameModule\Model\Building\BuildingModel::BAKERY, $bakery); $production = $production * ($bakery->attribute / 100 + 1); } // Step 5 apply bonus production if ($village->getOwner()->b4 === 1) { $production = $production * 1.25; } // Step 6 apply speed $production = $production * $this->speed; return round($production); }
/** * @param App\GameModule\DTO\Village $village * @param int $building * @return App\GameModule\DTO\Building|bool */ public function isBuilt($village, $building) { for ($i = 19; $i <= 40; $i++) { if ($village->getFData()['f' . $i . 't'] === $building) { return $this->getBuilding($building, $village->getFData()['f' . $i], $village); } } return FALSE; }