} $sectorBuildingsArr = $sectorConn->getSectorBuildings($sector->getId()); $sectorBuildings = array(); foreach ($sectorBuildingsArr as $sectorBuildingArr) { $buildingClass = $sectorBuildingArr[1]; $building = clone $allBuildings[$buildingClass]; $building->setLevel($sectorBuildingArr[3]); $building->setDateStarted($sectorBuildingArr[4]); $building->setDateStopped($sectorBuildingArr[5]); $sectorBuildings[$building->getId()] = $building; } $sector->setBuildings($sectorBuildings); $isCapitol = isset($sectorBuildings[0]) && $sectorBuildings[0]->getLevel(); if ($isCapitol) { $sector->setIsCapitol(true); if ($sector->getOwner() == $sessionPlayer->getId()) { $_SESSION['capitolSector'] = $sector; } } if ($sectorArr[5] == $sessionPlayer->getId()) { array_push($owned_sectors, $sector); } $allSectors[$sector->getCoordinateX() . "," . $sector->getCoordinateY()] = $sector; $x = $sector->getCoordinateX(); $y = $sector->getCoordinateY(); if ($x >= 0 && $x <= $MAP_WIDTH - 1 + $originX && $y >= 0 && $y <= $MAP_HEIGHT - 1 + $originY && $x >= $originX && $y >= $originY) { array_push($visibleSectors, $sector); } } $sessionPlayer->setSectors($owned_sectors); $sessionPlayer->setVisibleSectors($visibleSectors);
<?php $allUnits = $staticData->getUnits(); $allPlayers = $staticData->getPlayers(); $allBuildings = $staticData->getBuildings(); $coordinateX = $_POST['coordinateX']; $coordinateY = $_POST['coordinateY']; $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])); $battleArr = $battleConn->getBattleBySectorId($sector->getId()); $battle = new Battle($battleArr[0], 0, 0, $battleArr[2], $battleArr[3], $battleArr[4], $battleArr[5]); $attackingDivisions = array(); $defendingDivisions = array(); $sectorNameString = $sector->getName() . "(" . $sector->getCoordinateX() . "," . $sector->getCoordinateY() . ")"; $isPlayerDefending = $battle->getDefenderId() == $player->getId(); $owner = $sector->getOwner(); if (empty($owner)) { $defendingPlayer = new Player(); } else { $defendingPlayer = $allPlayers[$sector->getOwner()]; } $isPlayerInvolved = true; $divisionsArr = $divisionConn->getDivisionsBySector($sector->getId()); foreach ($divisionsArr as $divisionArr) { $quantity = $divisionArr[4]; $ownerId = $divisionArr[1]; if ($battle->getDefenderId() != $ownerId && $player->getId() != $battle->getDefenderId() && $player->getId() != $ownerId) { $isPlayerInvolved = false; $attackingPlayer = $allPlayers[$ownerId]; break; }