/** * @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 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]); } } }