示例#1
0
 /**
  * method build_page
  * param
  * return main method, loads everything
  */
 private function build_page()
 {
     // RUN STATISTICS SCRIPT AND THE SET THE RESULT
     $result = StatisticsLib::make_stats();
     // PREPARE DATA TO PARSE
     $parse = $this->_lang;
     $parse['memory_p'] = str_replace(array("%p", "%m"), $result['memory_peak'], $this->_lang['sb_top_memory']);
     $parse['memory_e'] = str_replace(array("%e", "%m"), $result['end_memory'], $this->_lang['sb_final_memory']);
     $parse['memory_i'] = str_replace(array("%i", "%m"), $result['initial_memory'], $this->_lang['sb_start_memory']);
     $parse['alert'] = AdministrationLib::save_message('ok', str_replace("%t", $result['totaltime'], $this->_lang['sb_stats_update']));
     // UPDATE STATISTICS LAST UPDATE
     FunctionsLib::update_config('stat_last_update', $result['stats_time']);
     // SHOW TEMPLATE
     parent::$page->display(parent::$page->parse_template(parent::$page->get_template('adm/buildstats_view'), $parse));
 }
示例#2
0
 /**
  * method colonize_mission
  * param $fleet_row
  * return the colonization result
  */
 public function colonizeMission($fleet_row)
 {
     if ($fleet_row['fleet_mess'] == 0) {
         $colonization_check = parent::$db->queryFetch("SELECT\n                                                                                                                                    (SELECT COUNT(*)\n                                                                                                                                            FROM " . PLANETS . " AS pc1\n                                                                                                                                            WHERE pc1.`planet_user_id` = '" . $fleet_row['fleet_owner'] . "' AND\n                                                                                                                                                            pc1.`planet_type` = '1' AND\n                                                                                                                                                            pc1.`planet_destroyed` = '0') AS planet_count,\n                                                                                                                                    (SELECT COUNT(*)\n                                                                                                                                            FROM " . PLANETS . " AS pc2\n                                                                                                                                            WHERE pc2.`planet_galaxy` = '" . $fleet_row['fleet_end_galaxy'] . "' AND\n                                                                                                                                                            pc2.`planet_system` = '" . $fleet_row['fleet_end_system'] . "' AND\n                                                                                                                                                            pc2.`planet_planet` = '" . $fleet_row['fleet_end_planet'] . " AND\n                                                                                                                                                            pc2.`planet_type` = 1') AS galaxy_count,\n                                                                                                                                    (SELECT `research_astrophysics`\n                                                                                                                                            FROM " . RESEARCH . "\n                                                                                                                                            WHERE `research_user_id` = '" . $fleet_row['fleet_owner'] . "') AS astro_level");
         // SOME REQUIRED VALUES
         $target_coords = sprintf($this->_lang['sys_adress_planet'], $fleet_row['fleet_end_galaxy'], $fleet_row['fleet_end_system'], $fleet_row['fleet_end_planet']);
         $max_colonies = FleetsLib::get_max_colonies($colonization_check['astro_level']);
         $planet_count = $colonization_check['planet_count'] - 1;
         // THE TOTAL AMOUNT OF PLANETS MINUS 1 (BECAUSE THE MAIN PLANET IT'S NOT CONSIDERED)
         // DIFFERENT TYPES OF MESSAGES
         $message[1] = $this->_lang['sys_colo_arrival'] . $target_coords . $this->_lang['sys_colo_maxcolo'] . ($max_colonies + 1) . $this->_lang['sys_colo_planet'];
         $message[2] = $this->_lang['sys_colo_arrival'] . $target_coords . $this->_lang['sys_colo_allisok'];
         $message[3] = $this->_lang['sys_colo_arrival'] . $target_coords . $this->_lang['sys_colo_notfree'];
         $message[4] = $this->_lang['sys_colo_arrival'] . $target_coords . $this->_lang['sys_colo_astro_level'];
         if ($colonization_check['galaxy_count'] == 0) {
             if ($planet_count >= $max_colonies) {
                 $this->colonize_message($fleet_row['fleet_owner'], $message[1], $fleet_row['fleet_start_time']);
                 parent::return_fleet($fleet_row['fleet_id']);
             } elseif (!$this->position_allowed($fleet_row['fleet_end_planet'], $colonization_check['astro_level'])) {
                 $this->colonize_message($fleet_row['fleet_owner'], $message[4], $fleet_row['fleet_start_time']);
                 parent::return_fleet($fleet_row['fleet_id']);
             } else {
                 if ($this->start_creation($fleet_row)) {
                     $this->colonize_message($fleet_row['fleet_owner'], $message[2], $fleet_row['fleet_start_time']);
                     if ($fleet_row['fleet_amount'] == 1) {
                         parent::$db->query("UPDATE " . USERS_STATISTICS . " AS us SET\n                                                                                                    us.`user_statistic_ships_points` = us.`user_statistic_ships_points` - " . StatisticsLib::calculate_points(208, 1) . "\n                                                                                                    WHERE us.`user_statistic_user_id` = (SELECT p.planet_user_id FROM " . PLANETS . " AS p\n                                                                                                                                                                                    WHERE p.planet_galaxy = '" . $fleet_row['fleet_start_galaxy'] . "' AND\n                                                                                                                                                                                                    p.planet_system = '" . $fleet_row['fleet_start_system'] . "' AND\n                                                                                                                                                                                                    p.planet_planet = '" . $fleet_row['fleet_start_planet'] . "' AND\n                                                                                                                                                                                                    p.planet_type = '" . $fleet_row['fleet_start_type'] . "');");
                         parent::store_resources($fleet_row);
                         parent::remove_fleet($fleet_row['fleet_id']);
                     } else {
                         parent::store_resources($fleet_row);
                         parent::$db->query("UPDATE " . FLEETS . ", " . USERS_STATISTICS . " SET\n                                                                                                    `fleet_array` = '" . $this->build_new_fleet($fleet_row['fleet_array']) . "',\n                                                                                                    `fleet_amount` = `fleet_amount` - 1,\n                                                                                                    `fleet_resource_metal` = '0',\n                                                                                                    `fleet_resource_crystal` = '0',\n                                                                                                    `fleet_resource_deuterium` = '0',\n                                                                                                    `fleet_mess` = '1',\n                                                                                                    `user_statistic_ships_points` = `user_statistic_ships_points` - " . StatisticsLib::calculate_points(208, 1) . "\n                                                                                                    WHERE `fleet_id` = '" . $fleet_row['fleet_id'] . "' AND\n                                                                                                                    `user_statistic_user_id` = (SELECT planet_user_id FROM " . PLANETS . "\n                                                                                                                                                                                    WHERE planet_galaxy = '" . $fleet_row['fleet_start_galaxy'] . "' AND\n                                                                                                                                                                                                    planet_system = '" . $fleet_row['fleet_start_system'] . "' AND\n                                                                                                                                                                                                    planet_planet = '" . $fleet_row['fleet_start_planet'] . "' AND\n                                                                                                                                                                                                    planet_type = '" . $fleet_row['fleet_start_type'] . "');");
                     }
                 } else {
                     $this->colonize_message($fleet_row['fleet_owner'], $message[3], $fleet_row['fleet_end_time']);
                     parent::return_fleet($fleet_row['fleet_id']);
                 }
             }
         } else {
             $this->colonize_message($fleet_row['fleet_owner'], $message[3], $fleet_row['fleet_end_time']);
             parent::return_fleet($fleet_row['fleet_id']);
         }
     }
     if ($fleet_row['fleet_end_time'] < time()) {
         parent::restore_fleet($fleet_row, TRUE);
         parent::remove_fleet($fleet_row['fleet_id']);
     }
 }
示例#3
0
 /**
  * checkBuildingQueue
  *
  * @param array $current_planet Current planet
  * @param array $current_user   Current user
  *
  * @return boolean
  */
 private static function checkBuildingQueue(&$current_planet, &$current_user)
 {
     $resource = parent::$objects->getObjects();
     $ret_value = false;
     if ($current_planet['planet_b_building_id'] != 0) {
         $current_queue = $current_planet['planet_b_building_id'];
         if ($current_queue != 0) {
             $queue_array = explode(";", $current_queue);
         }
         $build_array = explode(",", $queue_array[0]);
         $build_end_time = floor($build_array[3]);
         $build_mode = $build_array[4];
         $element = $build_array[0];
         array_shift($queue_array);
         if ($build_mode == 'destroy') {
             $for_destroy = true;
         } else {
             $for_destroy = false;
         }
         if ($build_end_time <= time()) {
             $needed = DevelopmentsLib::development_price($current_user, $current_planet, $element, true, $for_destroy);
             $units = $needed['metal'] + $needed['crystal'] + $needed['deuterium'];
             $current = (int) $current_planet['planet_field_current'];
             $max = (int) $current_planet['planet_field_max'];
             if ($current_planet['planet_type'] == 3) {
                 if ($element == 41) {
                     $current += 1;
                     $max += FIELDS_BY_MOONBASIS_LEVEL;
                     $current_planet[$resource[$element]]++;
                 } elseif ($element != 0) {
                     if ($for_destroy == false) {
                         $current += 1;
                         $current_planet[$resource[$element]]++;
                     } else {
                         $current -= 1;
                         $current_planet[$resource[$element]]--;
                     }
                 }
             } elseif ($current_planet['planet_type'] == 1) {
                 if ($for_destroy == false) {
                     $current += 1;
                     $current_planet[$resource[$element]]++;
                 } else {
                     $current -= 1;
                     $current_planet[$resource[$element]]--;
                 }
             }
             if (count($queue_array) == 0) {
                 $new_queue = 0;
             } else {
                 $new_queue = implode(';', $queue_array);
             }
             $current_planet['planet_b_building'] = 0;
             $current_planet['planet_b_building_id'] = $new_queue;
             $current_planet['planet_field_current'] = $current;
             $current_planet['planet_field_max'] = $max;
             $current_planet['building_points'] = StatisticsLib::calculate_points($element, $current_planet[$resource[$element]]);
             parent::$db->query("UPDATE " . PLANETS . " AS p\n                    INNER JOIN " . USERS_STATISTICS . " AS s ON s.user_statistic_user_id = p.planet_user_id\n                    INNER JOIN " . BUILDINGS . " AS b ON b.building_planet_id = p.`planet_id` SET\n                    `" . $resource[$element] . "` = '" . $current_planet[$resource[$element]] . "',\n                    `user_statistic_buildings_points` = `user_statistic_buildings_points` + '" . $current_planet['building_points'] . "',\n                    `planet_b_building` = '" . $current_planet['planet_b_building'] . "',\n                    `planet_b_building_id` = '" . $current_planet['planet_b_building_id'] . "',\n                    `planet_field_current` = '" . $current_planet['planet_field_current'] . "',\n                    `planet_field_max` = '" . $current_planet['planet_field_max'] . "'\n                    WHERE `planet_id` = '" . $current_planet['planet_id'] . "';");
             $ret_value = true;
         } else {
             $ret_value = false;
         }
     } else {
         $current_planet['planet_b_building'] = 0;
         $current_planet['planet_b_building_id'] = 0;
         parent::$db->query("UPDATE " . PLANETS . " SET\n                `planet_b_building` = '" . $current_planet['planet_b_building'] . "',\n                `planet_b_building_id` = '" . $current_planet['planet_b_building_id'] . "'\n                WHERE `planet_id` = '" . $current_planet['planet_id'] . "';");
         $ret_value = false;
     }
     return $ret_value;
 }
 /**
  * updateResources
  *
  * @param array   $current_user   Current user
  * @param array   $current_planet Current planet
  * @param int     $UpdateTime     Update time
  * @param boolean $Simul          Simulation
  *
  * @return void
  */
 public static function updateResources(&$current_user, &$current_planet, $UpdateTime, $Simul = false)
 {
     $resource = parent::$objects->getObjects();
     $ProdGrid = parent::$objects->getProduction();
     $reslist = parent::$objects->getObjectsList();
     $game_resource_multiplier = FunctionsLib::read_config('resource_multiplier');
     $game_metal_basic_income = FunctionsLib::read_config('metal_basic_income');
     $game_crystal_basic_income = FunctionsLib::read_config('crystal_basic_income');
     $game_deuterium_basic_income = FunctionsLib::read_config('deuterium_basic_income');
     $current_planet['planet_metal_max'] = ProductionLib::maxStorable($current_planet[$resource[22]]);
     $current_planet['planet_crystal_max'] = ProductionLib::maxStorable($current_planet[$resource[23]]);
     $current_planet['planet_deuterium_max'] = ProductionLib::maxStorable($current_planet[$resource[24]]);
     $MaxMetalStorage = $current_planet['planet_metal_max'];
     $MaxCristalStorage = $current_planet['planet_crystal_max'];
     $MaxDeuteriumStorage = $current_planet['planet_deuterium_max'];
     $Caps = array();
     $BuildTemp = $current_planet['planet_temp_max'];
     $sub_query = '';
     $parse['production_level'] = 100;
     $post_porcent = ProductionLib::maxProduction($current_planet['planet_energy_max'], $current_planet['planet_energy_used']);
     $Caps['planet_metal_perhour'] = 0;
     $Caps['planet_crystal_perhour'] = 0;
     $Caps['planet_deuterium_perhour'] = 0;
     $Caps['planet_energy_max'] = 0;
     $Caps['planet_energy_used'] = 0;
     foreach ($ProdGrid as $ProdID => $formula) {
         $BuildLevelFactor = $current_planet['planet_' . $resource[$ProdID] . '_porcent'];
         $BuildLevel = $current_planet[$resource[$ProdID]];
         $BuildEnergy = $current_user['research_energy_technology'];
         // BOOST
         $geologe_boost = 1 + 1 * (OfficiersLib::isOfficierActive($current_user['premium_officier_geologist']) ? GEOLOGUE : 0);
         $engineer_boost = 1 + 1 * (OfficiersLib::isOfficierActive($current_user['premium_officier_engineer']) ? ENGINEER_ENERGY : 0);
         // PRODUCTION FORMULAS
         $metal_prod = eval($ProdGrid[$ProdID]['formule']['metal']);
         $crystal_prod = eval($ProdGrid[$ProdID]['formule']['crystal']);
         $deuterium_prod = eval($ProdGrid[$ProdID]['formule']['deuterium']);
         $energy_prod = eval($ProdGrid[$ProdID]['formule']['energy']);
         // PRODUCTION
         $Caps['planet_metal_perhour'] += ProductionLib::currentProduction(ProductionLib::productionAmount($metal_prod, $geologe_boost), $post_porcent);
         $Caps['planet_crystal_perhour'] += ProductionLib::currentProduction(ProductionLib::productionAmount($crystal_prod, $geologe_boost), $post_porcent);
         $Caps['planet_deuterium_perhour'] += ProductionLib::currentProduction(ProductionLib::productionAmount($deuterium_prod, $geologe_boost), $post_porcent);
         if ($ProdID >= 4) {
             if ($ProdID == 12 && $current_planet['planet_deuterium'] == 0) {
                 continue;
             }
             $Caps['planet_energy_max'] += ProductionLib::productionAmount($energy_prod, $engineer_boost, true);
         } else {
             $Caps['planet_energy_used'] += ProductionLib::productionAmount($energy_prod, 1, true);
         }
     }
     if ($current_planet['planet_type'] == 3) {
         $game_metal_basic_income = 0;
         $game_crystal_basic_income = 0;
         $game_deuterium_basic_income = 0;
         $current_planet['planet_metal_perhour'] = 0;
         $current_planet['planet_crystal_perhour'] = 0;
         $current_planet['planet_deuterium_perhour'] = 0;
         $current_planet['planet_energy_used'] = 0;
         $current_planet['planet_energy_max'] = 0;
     } else {
         $current_planet['planet_metal_perhour'] = $Caps['planet_metal_perhour'];
         $current_planet['planet_crystal_perhour'] = $Caps['planet_crystal_perhour'];
         $current_planet['planet_deuterium_perhour'] = $Caps['planet_deuterium_perhour'];
         $current_planet['planet_energy_used'] = $Caps['planet_energy_used'];
         $current_planet['planet_energy_max'] = $Caps['planet_energy_max'];
     }
     $ProductionTime = $UpdateTime - $current_planet['planet_last_update'];
     $current_planet['planet_last_update'] = $UpdateTime;
     if ($current_planet['planet_energy_max'] == 0) {
         $current_planet['planet_metal_perhour'] = $game_metal_basic_income;
         $current_planet['planet_crystal_perhour'] = $game_crystal_basic_income;
         $current_planet['planet_deuterium_perhour'] = $game_deuterium_basic_income;
         $production_level = 100;
     } elseif ($current_planet['planet_energy_max'] >= $current_planet['planet_energy_used']) {
         $production_level = 100;
     } else {
         $production_level = floor($current_planet['planet_energy_max'] / $current_planet['planet_energy_used'] * 100);
     }
     if ($production_level > 100) {
         $production_level = 100;
     } elseif ($production_level < 0) {
         $production_level = 0;
     }
     if ($current_planet['planet_metal'] <= $MaxMetalStorage) {
         $MetalProduction = $ProductionTime * ($current_planet['planet_metal_perhour'] / 3600) * (0.01 * $production_level);
         $MetalBaseProduc = $ProductionTime * ($game_metal_basic_income / 3600);
         $MetalTheorical = $current_planet['planet_metal'] + $MetalProduction + $MetalBaseProduc;
         if ($MetalTheorical <= $MaxMetalStorage) {
             $current_planet['planet_metal'] = $MetalTheorical;
         } else {
             $current_planet['planet_metal'] = $MaxMetalStorage;
         }
     }
     if ($current_planet['planet_crystal'] <= $MaxCristalStorage) {
         $CristalProduction = $ProductionTime * ($current_planet['planet_crystal_perhour'] / 3600) * (0.01 * $production_level);
         $CristalBaseProduc = $ProductionTime * ($game_crystal_basic_income / 3600);
         $CristalTheorical = $current_planet['planet_crystal'] + $CristalProduction + $CristalBaseProduc;
         if ($CristalTheorical <= $MaxCristalStorage) {
             $current_planet['planet_crystal'] = $CristalTheorical;
         } else {
             $current_planet['planet_crystal'] = $MaxCristalStorage;
         }
     }
     if ($current_planet['planet_deuterium'] <= $MaxDeuteriumStorage) {
         $DeuteriumProduction = $ProductionTime * ($current_planet['planet_deuterium_perhour'] / 3600) * (0.01 * $production_level);
         $DeuteriumBaseProduc = $ProductionTime * ($game_deuterium_basic_income / 3600);
         $DeuteriumTheorical = $current_planet['planet_deuterium'] + $DeuteriumProduction + $DeuteriumBaseProduc;
         if ($DeuteriumTheorical <= $MaxDeuteriumStorage) {
             $current_planet['planet_deuterium'] = $DeuteriumTheorical;
         } else {
             $current_planet['planet_deuterium'] = $MaxDeuteriumStorage;
         }
     }
     if ($current_planet['planet_metal'] < 0) {
         $current_planet['planet_metal'] = 0;
     }
     if ($current_planet['planet_crystal'] < 0) {
         $current_planet['planet_crystal'] = 0;
     }
     if ($current_planet['planet_deuterium'] < 0) {
         $current_planet['planet_deuterium'] = 0;
     }
     if ($Simul == false) {
         // SHIPS AND DEFENSES UPDATE
         $builded = self::buildingQueue($current_user, $current_planet, $ProductionTime);
         $ship_points = 0;
         $defense_points = 0;
         if ($builded != '') {
             foreach ($builded as $element => $count) {
                 if ($element != '') {
                     // POINTS
                     switch ($element) {
                         case $element >= 202 && $element <= 215:
                             $ship_points += StatisticsLib::calculate_points($element, $count) * $count;
                             break;
                         case $element >= 401 && $element <= 503:
                             $defense_points += StatisticsLib::calculate_points($element, $count) * $count;
                             break;
                         default:
                             break;
                     }
                     $sub_query .= "`" . $resource[$element] . "` = '" . $current_planet[$resource[$element]] . "', ";
                 }
             }
         }
         // RESEARCH UPDATE
         if ($current_planet['planet_b_tech'] <= time() && $current_planet['planet_b_tech_id'] != 0) {
             $current_user['research_points'] = StatisticsLib::calculate_points($current_planet['planet_b_tech_id'], $current_user[$resource[$current_planet['planet_b_tech_id']]], 'tech');
             $current_user[$resource[$current_planet['planet_b_tech_id']]]++;
             $tech_query = "`planet_b_tech` = '0',";
             $tech_query .= "`planet_b_tech_id` = '0',";
             $tech_query .= "`" . $resource[$current_planet['planet_b_tech_id']] . "` = '" . $current_user[$resource[$current_planet['planet_b_tech_id']]] . "',";
             $tech_query .= "`user_statistic_technology_points` = `user_statistic_technology_points` + '" . $current_user['research_points'] . "',";
             $tech_query .= "`research_current_research` = '0',";
         } else {
             $tech_query = "";
         }
         parent::$db->query("UPDATE " . PLANETS . " AS p\n                INNER JOIN " . USERS_STATISTICS . " AS us ON us.user_statistic_user_id = p.planet_user_id\n                INNER JOIN " . DEFENSES . " AS d ON d.defense_planet_id = p.`planet_id`\n                INNER JOIN " . SHIPS . " AS s ON s.ship_planet_id = p.`planet_id`\n                INNER JOIN " . RESEARCH . " AS r ON r.research_user_id = p.planet_user_id SET\n                `planet_metal` = '" . $current_planet['planet_metal'] . "',\n                `planet_crystal` = '" . $current_planet['planet_crystal'] . "',\n                `planet_deuterium` = '" . $current_planet['planet_deuterium'] . "',\n                `planet_last_update` = '" . $current_planet['planet_last_update'] . "',\n                `planet_b_hangar_id` = '" . $current_planet['planet_b_hangar_id'] . "',\n                `planet_metal_perhour` = '" . $current_planet['planet_metal_perhour'] . "',\n                `planet_crystal_perhour` = '" . $current_planet['planet_crystal_perhour'] . "',\n                `planet_deuterium_perhour` = '" . $current_planet['planet_deuterium_perhour'] . "',\n                `planet_energy_used` = '" . $current_planet['planet_energy_used'] . "',\n                `planet_energy_max` = '" . $current_planet['planet_energy_max'] . "',\n                `user_statistic_ships_points` = `user_statistic_ships_points` + '" . $ship_points . "',\n                `user_statistic_defenses_points` = `user_statistic_defenses_points`  + '" . $defense_points . "',\n                {$sub_query}\n                {$tech_query}\n                `planet_b_hangar` = '" . $current_planet['planet_b_hangar'] . "'\n                WHERE `planet_id` = '" . $current_planet['planet_id'] . "';");
     }
 }