Exemplo n.º 1
0
 public function renderStable()
 {
     $this->units = $this->unitService->getAvailableUnits($this->village, App\GameModule\Model\Building\BuildingModel::STABLE);
     $this->template->units = $this->units;
     $this->template->available = $this->unitService->getTrainableUnits($this->village, $this->units);
     $this->template->current = $this->unitService->getUnits($this->village);
     $queue = $this->trainingModel->getByBuilding($this->village, App\GameModule\Model\Building\BuildingModel::STABLE);
     foreach ($queue as $item) {
         $item->unit = $this->unitFactory->getUnit($item->unit);
     }
     $this->template->queue = $queue;
     $this->template->setFile(__DIR__ . '/Template/Stable.latte');
 }
Exemplo n.º 2
0
 /**
  * @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]);
         }
     }
 }