示例#1
0
 /**
  * @param App\GameModule\DTO\Building $building
  * @param App\GameModule\DTO\Village $village
  * @return bool
  */
 public function isThereEnoughResources($building, $village)
 {
     if ($building->getWood() < $village->getActualWood() && $building->getClay() < $village->getActualClay() && $building->getIron() < $village->getActualIron() && $building->getCrop() < $village->getActualCrop()) {
         return TRUE;
     }
     $woodNeeded = $building->getWood() - $village->getActualWood();
     \Tracy\Debugger::barDump($village);
     if ($woodNeeded > 0) {
         $time = round($woodNeeded / ($village->getProductionWood() / 3600));
     } else {
         $time = 0;
     }
     $clayNeeded = $building->getClay() - $village->getActualClay();
     if ($clayNeeded > 0) {
         $timeClay = round($clayNeeded / ($village->getProductionClay() / 3600));
         if ($timeClay > $time) {
             $time = $timeClay;
         }
     }
     $ironNeeded = $building->getIron() - $village->getActualIron();
     if ($ironNeeded > 0) {
         $timeIron = round($ironNeeded / ($village->getProductionIron() / 3600));
         if ($timeIron > $time) {
             $time = $timeIron;
         }
     }
     $cropNeeded = $building->getCrop() - $village->getProductionCrop();
     if ($cropNeeded > 0) {
         $timeCrop = round($cropNeeded / ($village->getProductionCrop() / 3600));
         if ($timeCrop > $time) {
             $time = $timeCrop;
         }
     }
     return time() + $time;
 }
示例#2
0
 /**
  * @param App\GameModule\DTO\Village $village
  * @param App\GameModule\DTO\Unit $unit
  * @return int
  */
 public function getTrainableUnit($village, $unit)
 {
     $wood = floor($village->getActualWood() / $unit->getWood());
     $clay = floor($village->getActualClay() / $unit->getClay());
     $iron = floor($village->getActualIron() / $unit->getIron());
     $crop = floor($village->getActualCrop() / $unit->getCrop());
     return min($wood, $clay, $iron, $crop);
 }