/** * @param App\GameModule\DTO\Village $village * @param int $field * @return array */ public function getAvailable($village, $field) { $available = []; if ($field == 40) { if ($village->getOwner()->tribe === 1) { $available[] = $this->buildingService->getBuilding(BuildingModel::CITY_WALL, 1, $village); return $available; } elseif ($village->getOwner()->tribe === 2) { $available[] = $this->buildingService->getBuilding(BuildingModel::EARTH_WALL, 1, $village); return $available; } elseif ($village->getOwner()->tribe === 3) { $available[] = $this->buildingService->getBuilding(BuildingModel::PALISADE, 1, $village); return $available; } } if ($field == 39) { $available[] = $this->buildingService->getBuilding(BuildingModel::RALLY_POINT, 1, $village); return $available; } $buildings = $this->buildingModel->getAll(); foreach ($buildings as $building => $name) { if ($building < 5) { continue; } if ($this->buildingService->isBuilt($village, $building)) { continue; } if (in_array($building, [BuildingModel::CITY_WALL, BuildingModel::EARTH_WALL, BuildingModel::PALISADE, BuildingModel::RALLY_POINT])) { continue; } if ($village->getNatar() === 0 && $building === BuildingModel::WORLD_WONDER) { continue; } $requirements = $this->buildingModel->getRequirements($building); $passed = FALSE; foreach ($requirements as $requirement) { $built = $this->buildingService->isBuilt($village, $requirement->require_building); if ($built && $requirement->exclude_building === $built->getBuilding()) { $passed = FALSE; break; } if ($built && $built->getLevel() >= $requirement->require_level) { $passed = TRUE; } else { $passed = FALSE; break; } } if (!$requirements || $passed) { $available[] = $this->buildingService->getBuilding($building, 1, $village); } } return $available; }
public function render() { $id = $this->presenter->getParameter('id'); if (!$id) { /** @var \stdClass $field */ $field = $this->VDataModel->getByUser($this->presenter->user->getId()); $id = $field->wref; } $this->template->buildings = $this->BDataModel->getBuildingQueue($id); $this->template->village = $this->villageService->getVillage($id); $this->template->names = $this->buildingModel->getAll(); $this->template->setFile(__DIR__ . '/BuildingControl.latte'); $this->template->render(); }
/** * @param App\GameModule\DTO\Building $building * @param int $field * @param App\GameModule\DTO\Village $village * @return bool */ public function canBuildLevel($building, $field, $village) { if (!$building) { return 'Building is at maximum level'; } $current = $this->getBuilding($village->getFData()['f' . $field . 't'], $village->getFData()['f' . $field], $village); if ($current) { if ($current->getLevel() === $building->getLevel()) { return 'Building is at same level.'; } /** @var \stdClass $maxLevel */ $maxLevel = $this->buildingModel->getBuildingMaxLevel($building->getBuilding()); if ($current->getLevel() === $maxLevel->level) { return 'Building is at maximum level'; } $queue = $this->BDataModel->getBuildingQueue($village->getId()); foreach ($queue as $single) { if ($single->level === $building->getLevel() && $single->type === $building->getBuilding() && $single->field == $field) { return 'Building is already being build.'; } if ($maxLevel->level === $single->level && $single->type === $building->getBuilding() && $single->field == $field) { return 'Building max level under construction'; } } } return TRUE; }
public function actionDefault($id) { if (!$id) { /** @var \stdClass $field */ $field = $this->VDataModel->getByUser($this->presenter->user->getId()); $id = $field->wref; } $this->template->village = $village = $this->villageService->getVillage($id); $this->template->names = $this->buildingModel->getAll(); if ($village->getOwner()->tribe === 1) { $wallId = 31; } elseif ($village->getOwner()->tribe === 2) { $wallId = 32; } else { $wallId = 33; } $this->template->wallId = $wallId; $this->template->wallLevel = $village->getFData()['f' . $wallId]; }
/** * @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); }