示例#1
0
 /**
  * @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;
 }
示例#2
0
 /**
  * @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]);
     }
 }