Exemplo n.º 1
0
if (!isset($sectorConn)) {
    $sectorConn = new SectorDAO();
}
if (!isset($buildingConn)) {
    $buildingConn = new BuildingDAO();
}
$sectorsArr = $sectorConn->getAllSectors();
foreach ($sectorsArr as $sectorArr) {
    $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]);
    $allSectors[] = $sector;
}
$allSectors = Sector::indexByCoordinate($allSectors);
$suitableSectors = array();
$origins = array();
$minDistance = 3;
$suitableSectors = array_diff_key($allSectors, Sector::getForbidden($allSectors));
if (count($suitableSectors) > 0) {
    $sector = $suitableSectors[array_rand($suitableSectors)];
    $rs = $sectorConn->updateSector($sector->getId(), $playerId, $playerId, 0);
    $startCoordinates = $sector->getCoordinateX() . "," . $sector->getCoordinateY();
    //Create Command center and capitol in initial sector
    $now = $_SERVER['REQUEST_TIME'];
    $sectorConn->insertBuilding(0, $sector->getId(), 0);
    $buildingConn->updateBuilding(1, 0, $sector->getId());
    $sectorConn->insertBuilding(1, $sector->getId(), 0);
    $buildingConn->updateBuilding(1, 1, $sector->getId());
    $sectorConn->updateSectorCosts($sector->getId(), array(0, 0, 5, 5, 0), 0);
    $inserted = true;
} else {
    $inserted = false;
}
Exemplo n.º 2
0
    $sectorBuildings[] = $sectorBuildingArr[1];
}
$resourcesOK = true;
if (!$percent) {
    $building_resources = $available_buildings[$buildingId]->getProductionCost();
    $player_resources = $player->getResources();
    $leftResources = array();
    for ($i = 0; $i < count($building_resources); $i++) {
        $leftResources[$i] = $player_resources[$i] - $building_resources[$i];
        if ($leftResources[$i] < 0 && $building_resources[$i] > 0) {
            $resourcesOK = false;
        }
    }
}
if (!$resourcesOK) {
    die("0;");
}
if ($sectorOK && $buildingOK && $resourcesOK) {
    if (in_array($buildingId, $sectorBuildings)) {
        $buildingConn->updateBuilding(0, $buildingId, $sectorId);
    } else {
        $buildingConn->insertBuilding($buildingId, $sectorId, $_SERVER['REQUEST_TIME']);
    }
    //$unitList = $unitId;
    //$timeList = $available_buildings[$buildingId]->getTime();
    if (!$percent) {
        $playerConn->updatePlayerResources($player->getId(), implode(",", $leftResources), $_SERVER['REQUEST_TIME']);
        $_SESSION['player']->setResources($leftResources);
    }
    echo $buildingId . ";" . $available_buildings[$buildingId]->getTime() . ";" . implode(",", $building_resources) . ";" . $percent;
}