Ejemplo n.º 1
0
 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]);
             }
         }
     }
 }
Ejemplo n.º 2
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');
 }
Ejemplo n.º 3
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]);
         }
     }
 }