public function ParseAndSaveWorldMap($world_response, $descriptor)
 {
     $log_seq = 0;
     $func_args = func_get_args();
     $func_args[0] = 'Removed Hex Array. See WS Request Log.';
     $func_log_id = DataLoadLogDAO::startFunction($this->db, $this->data_load_id, __CLASS__, __FUNCTION__, $func_args);
     DataLoadLogDAO::logEvent2($this->db, $func_log_id, $log_seq++, 'INFO', $descriptor);
     // Get the Hexes section of the world response
     $success = $world_response['responses'][0]['return_value']['success'];
     if ($success != 1) {
         $reason = $world_response['responses'][0]['return_value']['reason'];
         DataLoadLogDAO::completeFunction($this->db, $func_log_id, "Error Getting Map Data: {$reason}", 1);
         // Even though this is technically a failure, we return true because we don't want to retry this request
         return true;
     }
     $world = $world_response['responses'][0]['return_value']['hexes'];
     $hex_count = 0;
     // Sometimes this happens but I'm not sure why... so I created a return code to try again...
     if (empty($world)) {
         DataLoadLogDAO::completeFunction($this->db, $func_log_id, 'No Hexes Found', 1);
         echo "No hexes found.\r\n";
         return false;
     }
     // Parse and store each Hex
     foreach ($world as $key => $hex_arr) {
         $hex_count++;
         // Take the array and create the Hex object
         $hex = Hex::FromJson($hex_arr);
         $hex->data_load_id = $this->data_load_id;
         // Set the world ID
         $hex->world_id = $this->auth->world_id;
         // Recalculate the x coordinate.  Not sure why they store the data this way.
         $hex->hex_x = (int) self::convertToMapCoordinate($hex->hex_x, $hex->hex_y);
         // Check if this hex already exists so we know whether we're inserting or updating
         $hex_exists = WorldMapDAO::checkHexExists($this->db, $hex->world_id, $hex->hex_x, $hex->hex_y);
         if ($hex->building_id) {
             $hex->building_id = BuildingDAO::getLocalIdFromGameId($this->db, $hex->building_id);
         }
         // Determine whether we should use the player ID or NPC ID
         if (isset($hex->player_id)) {
             $game_player_id = $hex->player_id;
         } else {
             if (isset($hex->npc_player_id)) {
                 $game_player_id = $hex->npc_player_id;
             } else {
                 $game_player_id = null;
             }
         }
         // Get the local Player ID from our database
         $player_id = PlayerDAO::getLocalIdFromGameId($this->db, $game_player_id);
         // Start building a new player record
         $player = new Player();
         // Set the local Player ID if we found one
         if ($player_id) {
             $player->id = $player_id;
         }
         // Set the world ID and game player ID
         $player->world_id = $hex->world_id;
         $player->game_player_id = $game_player_id;
         // Initialize flags to NULL
         $hex->is_sb = null;
         $hex->is_npc = null;
         // Handle Alliance Base as a special case
         if ($hex->is_guild_town_center === 1) {
             $hex->town_name = $hex->guild_name;
             $hex->player_name = $hex->guild_name;
             $hex->player_level = $hex->guild_town_phase;
             $hex->building_id = 15;
         }
         // If this is a town tile then we have additional information, so let's process it
         if (isset($hex->town_name) || in_array($hex->building_id, array(14))) {
             $hex->command_center = true;
             // Set base properties
             $hex->is_sb = ($hex->town_radius == 2 and $hex->building_id == 1) ? 1 : 0;
             $hex->is_npc = $hex->town_name === 'Renegade Outpost' ? 1 : 0;
             // Set the player's name and level
             $player->player_name = $hex->player_name;
             $player->level = $hex->player_level;
             $player->data_load_id = $this->data_load_id;
             // Calculate the end of the player's bubble
             if ($hex->immune_until_ts > 0) {
                 $player->immune_until = date('Y-m-d H:i:s', $hex->immune_until_ts);
             } else {
                 $player->immune_until = null;
             }
             // If this player is in a guild, process that information
             if (isset($hex->guild_id)) {
                 // Get the local Guild ID from our database
                 $guild_id = GuildDAO::getLocalIdFromGameId($this->db, $hex->guild_id);
                 // If we didn't find this guild, then start building the record.
                 // Otherwise, don't bother because this information won't change frequently.
                 if (!$guild_id) {
                     $guild = new Guild();
                     $guild->world_id = $hex->world_id;
                     $guild->game_guild_id = $hex->guild_id;
                     $guild->guild_name = $hex->guild_name;
                     $guild->data_load_id = $this->data_load_id;
                     // Insert the guild record into our database and keep the new local ID for later
                     $guild_id = GuildDAO::insertGuild($this->db, $guild);
                     if ($this->db->hasError()) {
                         echo 'Error inserting Guild: ';
                         print_r($this->db->getError());
                         $log_msg = print_r($guild, true) . "\r\n\r\n" . print_r($this->db->getError(), true);
                         DataLoadLogDAO::logEvent2($this->db, $func_log_id, $log_seq++, 'ERROR', "Error inserting Guild [{$guild->guild_name}] into World [{$guild->world_id}]", $log_msg, 1);
                         echo "\r\n";
                     }
                 }
                 // Set the player's guild
                 $player->guild_id = $guild_id;
             }
         }
         // If this player didn't already exist in our database, create it.  Otherwise, update it.
         if (!$player_id) {
             if ($game_player_id) {
                 //DataLoadLogDAO::logEvent2($this->db, $func_log_id, $log_seq++, 'DEBUG', "Inserting Player [{$player->player_name}] into World [{$player->world_id}]", var_export($player, true));
                 $player_id = PlayerDAO::insertPlayer($this->db, $player);
                 if ($this->db->hasError()) {
                     echo 'Error inserting Player: ';
                     print_r($this->db->getError());
                     echo "\r\n";
                     $log_msg = print_r($player, true) . "\r\n\r\n" . print_r($this->db->getError(), true);
                     DataLoadLogDAO::logEvent2($this->db, $func_log_id, $log_seq++, 'ERROR', "Error inserting Player [{$player->player_name}] into World [{$player->world_id}]", $log_msg, 1);
                 }
             }
         } else {
             if ($player->player_name) {
                 //DataLoadLogDAO::logEvent2($this->db, $func_log_id, $log_seq++, 'DEBUG', "Updating Player [{$player->player_name}] in World [{$player->world_id}]", var_export($player, true));
                 // Update the player, but exclude battle points, power, and the number of bases because these aren't available in this case
                 $updateCount = PlayerDAO::updatePlayer($this->db, $player, array('battle_points', 'glory_points', 'bases'));
                 if ($this->db->hasError()) {
                     echo 'Error updating Player: ';
                     print_r($this->db->getError());
                     echo "\r\n";
                     $log_msg = var_export($player, true) . "\r\n\r\n" . print_r($this->db->getError(), true);
                     DataLoadLogDAO::logEvent2($this->db, $func_log_id, $log_seq++, 'ERROR', "Error updating Player [{$player->player_name}] in World [{$player->world_id}]", $log_msg, 1);
                 }
             }
         }
         // Set the player ID on the hex tile to the local database ID
         if (isset($hex->player_id) || isset($hex->npc_player_id)) {
             $hex->player_id = $player_id;
         }
         // Insert or update the hex record
         if ($hex_exists == false) {
             $hex_id = WorldMapDAO::insertHex($this->db, $hex);
             if ($this->db->hasError()) {
                 echo 'Error inserting Hex: ';
                 print_r($this->db->getError());
                 echo "\r\n";
                 $log_msg = var_export($hex, true) . "\r\n\r\n" . print_r($this->db->getError(), true);
                 DataLoadLogDAO::logEvent2($this->db, $func_log_id, $log_seq++, 'ERROR', "Error inserting hex into World {$hex->world_id}, X: {$hex->hex_x}, Y: {$hex->hex_y}", $log_msg);
             }
         } else {
             $hex_id = WorldMapDAO::updateHex($this->db, $hex);
             if ($this->db->hasError()) {
                 echo 'Error updating Hex: ';
                 print_r($this->db->getError());
                 echo "\r\n";
                 $log_msg = var_export($hex, true) . "\r\n\r\n" . print_r($this->db->getError(), true);
                 DataLoadLogDAO::logEvent2($this->db, $func_log_id, $log_seq++, 'ERROR', "Error updating hex in World {$hex->world_id}, X: {$hex->hex_x}, Y: {$hex->hex_y}", $log_msg, 1);
             }
         }
     }
     DataLoadLogDAO::completeFunction($this->db, $func_log_id, "Created {$hex_count} Hexes");
     echo "Created {$hex_count} Hexes\r\n";
     return true;
 }
Esempio n. 2
0
        require_once_model('Unit');
        require_once_model('Building');
        require_once_model('Technology');
        require_once_model('Sector');
        require_once_model('Player');
        require_once_model('Resource');
        require_once_model('StaticData');
        require_once_model('ProductionMod');
        require_once_model('BattleMod');
    }
}
//session_start();
$staticData = StaticData::singleton();
$termConn = new TermDAO();
$unitConn = new UnitDAO();
$buildingConn = new BuildingDAO();
$technologyConn = new TechnologyDAO();
$playerConn = new PlayerDAO();
$resourceConn = new ResourceDAO();
$productionModConn = new ProductionModDAO();
$battleModConn = new BattleModDAO();
Term::setLang($_SESSION['language']);
$termsArr = $termConn->getAllTerms($_SESSION['language']);
foreach ($termsArr as $termArr) {
    $term = new Term($termArr[0], $termArr[1]);
    $terms[$termArr[0]] = $term;
}
$battleModsArr = $battleModConn->getAllBattleMods();
foreach ($battleModsArr as $battleModArr) {
    $battleModName = $terms[$battleModArr[1]];
    $battleMod = new BattleMod($battleModArr[0], $battleModName, $battleModArr[2], $battleModArr[3], $battleModArr[4], $battleModArr[5]);
Esempio n. 3
0
<?php

require_once '../../lib/inclusion.php';
require_once '../../config/paths.php';
require '../../config/map.cfg.php';
require_once_model('Sector');
require_once_model('Building');
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());
Esempio n. 4
0
<?php

require_once '../../lib/inclusion.php';
require_once_model('Player');
require_once_model('Building');
require_once_model('Sector');
session_start();
$sectorConn = new SectorDAO();
$buildingConn = new BuildingDAO();
$playerConn = new PlayerDAO();
$player = $_SESSION['player'];
$action = $_POST['action'];
$buildingId = $_POST['buildingId'];
$sectorId = $_POST['sectorId'];
$pausing = $_POST['pausing'];
$playerSectors = array();
foreach ($player->getSectors() as $playerSector) {
    $sector_id = $playerSector->getId();
    $playerSectors[] = $sector_id;
    if ($sector_id == $sectorId) {
        $coordinateX = $playerSector->getCoordinateX();
        $coordinateY = $playerSector->getCoordinateY();
    }
}
$sectorOK = in_array($sectorId, $playerSectors);
$buildingOK = array_key_exists($buildingId, $player->getAvailableBuildings());
if ($pausing && $sectorOK && $buildingOK) {
    $success = $buildingConn->pauseBuilding($sectorId, $buildingId);
    //if ($success)
    echo "1;" . $coordinateX . ";" . $coordinateY;
    die;