Exemple #1
0
         }
         $defenderSectors = Sector::getOwnedSectors($staticData->getSectors(), $battle->getDefenderId());
         $maxDistance = Sector::getMaxDistance($defenderSectors);
         $playerId = $battle->getDefenderId();
         require HOME . 'controllers/batch/recalculate_manteinances.php';
     }
     $capitolSectorArr = $sectorConn->getCapitolSector($battle->getAttackerId());
     if (!$capitolSectorArr) {
         if (!$staticData->getSectors()) {
             $sectorsArr = $sectorConn->getAllSectors();
             foreach ($sectorsArr as $sectorArr) {
                 $allSectors[] = new Sector($sectorArr[0], $sectorArr[1], $sectorArr[2], $sectorArr[3], $sectorArr[4], $sectorArr[5], $sectorArr[6], $sectorArr[7], explode(",", $sectorArr[8]), explode(",", $sectorArr[9]), $sectorArr[10]);
             }
             $staticData->setSectors($allSectors);
         }
         $attackerSectors = Sector::getOwnedSectors($staticData->getSectors(), $battle->getAttackerId());
         $maxDistance = Sector::getMaxDistance($attackerSectors);
         $playerId = $battle->getAttackerId();
         require HOME . 'controllers/batch/recalculate_manteinances.php';
     }
 } else {
     //$attacker = $allPlayers[array_shift($aux1)->getOwnerId()];
     //$defender = $allPlayers[array_shift($aux2)->getOwnerId()];
     $battle->setSector($sector);
     $battle->setAttackingDivisions($attackingDivisions);
     $battle->setDefendingDivisions($defendingDivisions);
     $attackDivisions = $battle->getAttackingDivisions();
     $defendDivisions = $battle->getDefendingDivisions();
     $passed = $now - $battle->getLastUpdate();
     $roundsMissed = floor($passed / ($round_time / 1000));
     $remainingTime = $passed % ($round_time / 1000);
$sectorArr = $sectorConn->getSectorByCoordinates($coordinateX, $coordinateY);
$sector = new Sector($sectorArr[0], $sectorArr[1], $sectorArr[2], $sectorArr[3], $sectorArr[4], $sectorArr[5], $sectorArr[6], $sectorArr[7], explode(",", $sectorArr[8]), explode(",", $sectorArr[9]), $sectorArr[10]);
$distanceFromCapitol = $sector->getDistanceFromCapitolSector($playerId, $sectorConn);
if (!$distanceFromCapitol) {
    if (!isset($staticData)) {
        require_once HOME . 'controllers/StaticData/initStaticData.php';
    }
    if (!$staticData->getSectors()) {
        $sectorsArr = $sectorConn->getAllSectors();
        foreach ($sectorsArr as $sectorArr) {
            $allSectors[] = new Sector($sectorArr[0], $sectorArr[1], $sectorArr[2], $sectorArr[3], $sectorArr[4], $sectorArr[5], $sectorArr[6], $sectorArr[7], explode(",", $sectorArr[8]), explode(",", $sectorArr[9]), $sectorArr[10]);
        }
        $staticData->setSectors($allSectors);
    }
    $ownedSectors = Sector::getOwnedSectors($staticData->getSectors(), $playerId);
    $distanceFromCapitol = Sector::getMaxDistance($ownedSectors);
}
if (!isset($allManteinances)) {
    $unitsArr = $unitConn->getAllUnits();
    $allManteinances = array();
    foreach ($unitsArr as $unitArr) {
        $unit = new Unit($unitArr[0], $unitArr[1], $unitArr[2], $unitArr[3], $unitArr[4], $unitArr[5], $unitArr[6], $unitArr[7], $unitArr[8], explode(",", $unitArr[9]), explode(",", $unitArr[10]), explode(",", $unitArr[11]), $unitArr[12], $unitArr[13], $unitArr[14], $unitArr[15]);
        $unitId = $unitArr[0];
        $manteinance = $unit->getEfectiveManteinanceCosts($distanceFromCapitol);
        $allManteinances[$unitId] = $manteinance;
    }
}
$unitQueueArr = $sectorConn->getUnitQueueLists($coordinateX, $coordinateY, $playerId);
$queuedUnits = explode(",", $unitQueueArr[0]);
$queuedTimes = explode(",", $unitQueueArr[1]);
     $trainingTimes = array();
     foreach ($allUnitsArr as $unitArr) {
         $unit = new Unit($unitArr[0], $unitArr[1], $unitArr[2], $unitArr[3], $unitArr[4], $unitArr[5], $unitArr[6], $unitArr[7], $unitArr[8], explode(",", $unitArr[9]), explode(",", $unitArr[10]), explode(",", $unitArr[11]), $unitArr[12], $unitArr[13], $unitArr[14], $unitArr[15]);
         $allUnits[$unit->getId()] = $unit;
     }
 }
 $unit = $allUnits[$unitId];
 $capitolSectorArr = $sectorConn->getCapitolSector($playerId);
 if ($capitolSectorArr) {
     $capitolSector = new Sector($capitolSectorArr[0], $capitolSectorArr[1], $capitolSectorArr[2], $capitolSectorArr[3], $capitolSectorArr[4], $capitolSectorArr[5], $capitolSectorArr[6], $capitolSectorArr[7], explode(",", $capitolSectorArr[8]), explode(",", $capitolSectorArr[9]), $capitolSectorArr[10]);
     $capitolX = $capitolSector->getCoordinateX();
     $capitolY = $capitolSector->getCoordinateY();
     $distanceFromCapitol = $startSector->getDistanceFrom($capitolX, $capitolY);
     //var_dump($distanceFromCapitol);
 } else {
     $ownedSectors = Sector::getOwnedSectors($allSectors, $playerId);
     $distanceFromCapitol = Sector::getMaxDistance($ownedSectors);
 }
 $unitStartCosts = $unit->getEfectiveManteinanceCosts($distanceFromCapitol);
 for ($j = 0; $j < count($unitStartCosts); $j++) {
     $unitStartCosts[$j] = $unitStartCosts[$j] * $quantityList[$i];
 }
 if ($capitolSectorArr) {
     $distanceFromCapitol = $endSector->getDistanceFrom($capitolX, $capitolY);
 }
 $unitEndCosts = $unit->getEfectiveManteinanceCosts($distanceFromCapitol);
 for ($j = 0; $j < count($unitEndCosts); $j++) {
     $unitEndCosts[$j] = $unitEndCosts[$j] * $quantityList[$i];
 }
 $sectorConn->updateSectorCosts($startSectorId, $unitStartCosts, 1, '-');
 if (!$isAttack) {