/** * @param int $id * @return App\GameModule\DTO\Village */ public function getVillage($id) { /** @var \stdClass $VData */ $VData = $this->VDataModel->getByWId($id); $village = new App\GameModule\DTO\Village(); $village->setId($id); if ($VData) { /** @var \stdClass $owner */ $owner = $this->userModel->get($VData->owner); $village->setOwner($owner); $village->setActualWood($VData->wood); $village->setActualClay($VData->clay); $village->setActualIron($VData->iron); $village->setActualCrop($VData->crop); $village->setStorage($VData->maxstore); $village->setGranary($VData->maxcrop); $upkeep = $VData->pop + $this->upkeepService->getUpkeep($id); $village->setUpkeep($upkeep); $village->setName($VData->name); $village->setLoyalty($VData->loyalty); $village->setCapital($VData->capital); $village->setType($VData->type); $village->setNatar($VData->natar); $village->setCulturePoints($VData->cp); $village->setPopulation($VData->pop); $FData = $this->FDataModel->getByVref($village->getId())->toArray(); $village->setFData($FData); $village->setProductionWood($this->productionService->getProductionWood($village)); $village->setProductionClay($this->productionService->getProductionClay($village)); $village->setProductionIron($this->productionService->getProductionIron($village)); $village->setProductionCrop($this->productionService->getProductionCrop($village)); $village->setMaxUpkeep($this->productionService->getBaseProductionCrop($village)); } return $village; }
public function actionDefault($id) { if (!$id) { /** @var \stdClass $field */ $field = $this->VDataModel->getByUser($this->presenter->user->getId()); $id = $field->wref; } $this->template->village = $this->villageService->getVillage($id); $this->template->units = $this->unitsModel->get($id); $this->template->unitNames = $this->unitService->getNames(); }
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->village = $this->villageService->getVillage($id); $this->template->setFile(__DIR__ . '/ResourceControl.latte'); $this->template->render(); }
/** * Recalculated in 10 minute cron. */ public function process() { $users = $this->userModel->getAllCulturePoints(); foreach ($users as $user) { $villages = $this->VDataModel->getAllByUser($user->id); $production = 0; foreach ($villages as $village) { $production += $village->cp; } $culturePoints = $user->cp + $production / 6; $this->userModel->update($user->id, ['cp' => $culturePoints]); } }
public function process() { if (!$this->isLocked()) { $time = $this->dateTimeProvider->getDateTime()->format('U'); $ids = $this->VDataModel->getAllIds(); foreach ($ids as $id) { $village = $this->villageService->getVillage($id); $this->productionService->processProduction($village, $time); } $this->buildingService->processBuildings($time); $this->processTraining->process($time); $this->releaseLock(); } }
/** * @param App\GameModule\DTO\Village $village * @param int $time */ public function processProduction($village, $time) { /** @var \stdClass $VData */ $VData = $this->VDataModel->getByWId($village->getId()); if ($time > $VData->lastupdate2) { if ($VData->lastupdate2 === 0) { $lastUpdate = $time; } else { $lastUpdate = $VData->lastupdate2; } $wood = $VData->wood; if ($VData->wood !== $VData->maxstore) { $productionWood = $this->getProductionWood($village); $producedWood = ($time - $lastUpdate) * ($productionWood / 3600); $totalWood = $producedWood + $VData->wood; if ($totalWood < $VData->maxstore) { $wood = $totalWood; } else { $wood = $VData->maxstore; } } $clay = $VData->clay; if ($VData->clay !== $VData->maxstore) { $productionClay = $this->getProductionClay($village); $producedClay = ($time - $lastUpdate) * ($productionClay / 3600); $totalClay = $producedClay + $VData->clay; if ($totalClay < $VData->maxstore) { $clay = $totalClay; } else { $clay = $VData->maxstore; } } $iron = $VData->iron; if ($VData->iron !== $VData->maxstore) { $productionIron = $this->getProductionIron($village); $producedIron = ($time - $lastUpdate) * ($productionIron / 3600); $totalIron = $producedIron + $VData->iron; if ($totalIron < $VData->maxstore) { $iron = $totalIron; } else { $iron = $VData->maxstore; } } $crop = $VData->crop; if ($VData->crop !== $VData->maxcrop) { $productionCrop = $this->getProductionCrop($village); $producedCrop = ($time - $lastUpdate) * ($productionCrop / 3600); $totalCrop = $producedCrop + $VData->crop; if ($totalCrop < $VData->maxcrop) { $crop = $totalCrop; } else { $crop = $VData->maxcrop; } } $this->VDataModel->update($village->getId(), ['wood' => $wood, 'clay' => $clay, 'iron' => $iron, 'crop' => $crop, 'lastupdate2' => $time]); } }
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]; }
public function render() { $id = $this->presenter->getParameter('id'); if (!$id) { /** @var \stdClass $field */ $field = $this->VDataModel->getByUser($this->presenter->user->getId()); $id = $field->wref; } $wref = $this->presenter->getParameter('wref'); if (!$wref) { $wref = $id; } $this->template->villageId = $id; $this->template->wref = $wref; $this->template->unread = $this->MDataModel->countUnread($this->presenter->getUser()->getId()) ? TRUE : FALSE; $this->template->report = $this->NDataModel->countUnread($this->presenter->getUser()->getId()) ? TRUE : FALSE; $this->template->plusActive = $this->userService->hasPlus($this->presenter->getUser()->getId()); $this->template->setFile(__DIR__ . '/HeaderControl.latte'); $this->template->render(); }
/** * Handle all related to create new user. * * @param \stdClass $data */ public function createUser($data) { $user = $this->registerUser($data); /** @var \stdClass $field */ $field = $this->WDataModel->getRandom($data->position); $this->WDataModel->setFieldTaken($field->id); $villageName = $this->villageService->getNewVillageName($user); $vid = $this->VDataModel->addVillageForUser($user, $field, $villageName); $this->FDataModel->addResourceFields($field->fieldtype, $vid); $this->unitsModel->add(['vref' => $vid]); $this->TDataModel->add(['vref' => $vid]); $this->ABDataModel->add(['vref' => $vid]); }
public function build($id, $field, $building, $level) { $village = $this->villageService->getVillage($id); $next = $this->getBuilding($building, $level, $village); if ($this->isThereEnoughResources($next, $village)) { if ($village->getOwner()->tribe === 1) { if ($next->getBuilding() < 5) { if ($time = $this->BDataModel->getLastOuterBuildTime($village->getId())) { $time += $next->getTime(); } else { /** @var int $now */ $now = $this->dateTimeProvider->getDateTime()->format('U'); $time = $next->getTime() + $now; } } elseif ($next->getBuilding() > 4) { if ($time = $this->BDataModel->getLastInnerBuildTime($village->getId())) { $time += $next->getTime(); } else { /** @var int $now */ $now = $this->dateTimeProvider->getDateTime()->format('U'); $time = $next->getTime() + $now; } } else { /** @var int $now */ $now = $this->dateTimeProvider->getDateTime()->format('U'); $time = $next->getTime() + $now; } } else { if ($time = $this->BDataModel->getLastBuildTime($village->getId())) { $time += $next->getTime(); } else { /** @var int $now */ $now = $this->dateTimeProvider->getDateTime()->format('U'); $time = $next->getTime() + $now; } } $this->BDataModel->add(['wid' => $id, 'field' => $field, 'type' => $building, 'timestamp' => $time, 'level' => $level]); $this->VDataModel->update($id, ['wood' => $village->getActualWood() - $next->getWood(), 'clay' => $village->getActualClay() - $next->getClay(), 'iron' => $village->getActualIron() - $next->getIron(), 'crop' => $village->getActualCrop() - $next->getCrop(), 'lastupdate2' => $this->dateTimeProvider->getDateTime()->format('U')]); } }
/** * @param App\GameModule\Controls\Train\TrainControl $form * @param \stdClass $values * @param App\GameModule\DTO\Village $village */ public function train($form, $values, $village) { /** @var App\GameModule\DTO\Unit $unit */ foreach ($form->getUnits() as $unit) { if ($values->{$unit->getId() . 'number'} > 0) { $trainable = $this->getTrainableUnit($village, $unit); if ($trainable > $values->{$unit->getId() . 'number'}) { $amount = $values->{$unit->getId() . 'number'}; } else { $amount = $trainable; } if ($amount == 0) { continue; } $this->VDataModel->update($village->getId(), ['wood' => $village->getActualWood() - $amount * $unit->getWood(), 'clay' => $village->getActualClay() - $amount * $unit->getClay(), 'iron' => $village->getActualIron() - $amount * $unit->getIron(), 'crop' => $village->getActualCrop() - $amount * $unit->getCrop()]); $training = FALSE; if (in_array($unit->getId(), self::INFANTRY)) { $training = $this->trainingModel->getByBuilding($village, App\GameModule\Model\Building\BuildingModel::BARRACKS); } elseif (in_array($unit->getId(), self::CALVARY)) { $training = $this->trainingModel->getByBuilding($village, App\GameModule\Model\Building\BuildingModel::STABLE); } elseif (in_array($unit->getId(), self::RAM) || in_array($unit->getId(), self::CATAPULT)) { $training = $this->trainingModel->getByBuilding($village, App\GameModule\Model\Building\BuildingModel::WORKSHOP); } elseif (in_array($unit->getId(), self::CHIEF) || in_array($unit->getId(), self::EXPANSION)) { $training = $this->trainingModel->getByBuilding($village, App\GameModule\Model\Building\BuildingModel::RESIDENCE); } if ($training) { $last = end($training); $time = $last->timestamp + $last->eachtime * $last->amt; } else { $time = time(); } $this->trainingModel->add(['vref' => $village->getId(), 'unit' => $unit->getId(), 'amt' => $amount, 'timestamp' => $time, 'eachtime' => $unit->getTime(), 'timestamp2' => $time]); } } }