public function process($time) { $trainData = $this->trainingModel->getProcessData($time); foreach ($trainData as $single) { if ($single->timestamp2 < $time + $single->eachtime) { $diff = $time - $single->timestamp2; $amount = floor($diff / $single->eachtime); if ($amount > $single->amt) { $amount = $single->amt; } $remaining = $single->amt - $amount; if ($remaining < 1) { $this->trainingModel->delete($single->id); } else { $this->trainingModel->update($single->id, ['amt' => $remaining, 'timestamp2' => $single->timestamp2 + $single->eachtime * $amount]); } /** @var \stdClass $units */ $units = $this->unitsModel->get($single->vref); $unitName = 'u' . $single->unit; if ($units) { $unitAmount = $units['u' . $single->unit] + $amount; $this->unitsModel->update($units['vref'], [$unitName => $unitAmount]); } else { $this->unitsModel->add([$unitName => $amount]); } } } }
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(); }
/** * @param int $id * @param int $wid */ public function actionDetail($id, $wid) { $this->template->id = $id; $village = $this->villageService->getVillage($id); /** @var \stdClass $wdata */ $this->template->wdata = $wdata = $this->WDataModel->get($wid); $this->template->reports = $this->reportService->getLastReportsForUser($wid, $this->user->getId()); $this->template->rallyPoint = $this->buildingService->isBuilt($village, App\GameModule\Model\Building\BuildingModel::RALLY_POINT); if ($wdata->occupied === 1) { $this->template->village = $this->villageService->getVillage($wid); } else { $this->template->village = FALSE; } if ($wdata->oasistype != 0 && $wdata->occupied == 0) { $this->template->units = $this->unitsModel->get($wid); $this->template->unitNames = $this->unitService->getNames(); } else { $this->template->units = []; } }
/** * @param App\GameModule\DTO\Village $village * @return \Dibi\Row|FALSE */ public function getUnits($village) { $unitData = $this->unitsModel->get($village->getId()); return $unitData; }