/** * method check_storage * param $amount * param $force * return amount of resource production */ public function check_storage($amount, $force = NULL) { if (!is_array($amount)) { throw new Exception("Must be array", 1); } $hangar = array('metal' => 22, 'crystal' => 23, 'deuterium' => 24); $check = array(); foreach ($hangar as $k => $v) { if ($amount[$k] == 0) { unset($amount[$k]); } if (array_key_exists($k, $amount)) { if ($this->_current_planet[$k] + $amount[$k] >= ProductionLib::maxStorable($this->_current_planet[$this->_resource[$v]])) { $check[$k] = FALSE; } else { $check[$k] = TRUE; } } else { $check[$k] = TRUE; } } if ($check['metal'] === true && $check['crystal'] === true && $check['deuterium'] === true) { return FALSE; } else { if (is_null($force)) { foreach ($hangar as $k => $v) { if ($check[$k] === false) { return sprintf($this->_lang['tr_full_storage'], strtolower($this->_lang['info'][$v]['name'])); } else { continue; } } } else { return $check; } } }
/** * method build_page * param * return main method, loads everything */ private function build_page() { $parse = $this->_lang; $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'); $game_energy_basic_income = FunctionsLib::read_config('energy_basic_income'); $game_resource_multiplier = FunctionsLib::read_config('resource_multiplier'); if ($this->_current_planet['planet_type'] == 3) { $game_metal_basic_income = 0; $game_crystal_basic_income = 0; $game_deuterium_basic_income = 0; } $this->_current_planet['planet_metal_max'] = ProductionLib::maxStorable($this->_current_planet[$this->_resource[22]]); $this->_current_planet['planet_crystal_max'] = ProductionLib::maxStorable($this->_current_planet[$this->_resource[23]]); $this->_current_planet['planet_deuterium_max'] = ProductionLib::maxStorable($this->_current_planet[$this->_resource[24]]); $parse['production_level'] = 100; $post_porcent = ProductionLib::maxProduction($this->_current_planet['planet_energy_max'], $this->_current_planet['planet_energy_used']); $parse['resource_row'] = ''; $this->_current_planet['planet_metal_perhour'] = 0; $this->_current_planet['planet_crystal_perhour'] = 0; $this->_current_planet['planet_deuterium_perhour'] = 0; $this->_current_planet['planet_energy_max'] = 0; $this->_current_planet['planet_energy_used'] = 0; $BuildTemp = $this->_current_planet['planet_temp_max']; $ResourcesRowTPL = parent::$page->get_template('resources/resources_row'); foreach ($this->_reslist['prod'] as $ProdID) { if ($this->_current_planet[$this->_resource[$ProdID]] > 0 && isset($this->_prod_grid[$ProdID])) { $BuildLevelFactor = $this->_current_planet['planet_' . $this->_resource[$ProdID] . '_porcent']; $BuildLevel = $this->_current_planet[$this->_resource[$ProdID]]; $BuildEnergy = $this->_current_user['research_energy_technology']; // BOOST $geologe_boost = 1 + 1 * (OfficiersLib::isOfficierActive($this->_current_user['premium_officier_geologist']) ? GEOLOGUE : 0); $engineer_boost = 1 + 1 * (OfficiersLib::isOfficierActive($this->_current_user['premium_officier_engineer']) ? ENGINEER_ENERGY : 0); // PRODUCTION FORMULAS $metal_prod = eval($this->_prod_grid[$ProdID]['formule']['metal']); $crystal_prod = eval($this->_prod_grid[$ProdID]['formule']['crystal']); $deuterium_prod = eval($this->_prod_grid[$ProdID]['formule']['deuterium']); $energy_prod = eval($this->_prod_grid[$ProdID]['formule']['energy']); // PRODUCTION $metal = ProductionLib::productionAmount($metal_prod, $geologe_boost); $crystal = ProductionLib::productionAmount($crystal_prod, $geologe_boost); $deuterium = ProductionLib::productionAmount($deuterium_prod, $geologe_boost); if ($ProdID >= 4) { $energy = ProductionLib::productionAmount($energy_prod, $engineer_boost, TRUE); } else { $energy = ProductionLib::productionAmount($energy_prod, 1, TRUE); } if ($energy > 0) { $this->_current_planet['planet_energy_max'] += $energy; } else { $this->_current_planet['planet_energy_used'] += $energy; } $this->_current_planet['planet_metal_perhour'] += $metal; $this->_current_planet['planet_crystal_perhour'] += $crystal; $this->_current_planet['planet_deuterium_perhour'] += $deuterium; $metal = ProductionLib::currentProduction($metal, $post_porcent); $crystal = ProductionLib::currentProduction($crystal, $post_porcent); $deuterium = ProductionLib::currentProduction($deuterium, $post_porcent); $energy = ProductionLib::currentProduction($energy, $post_porcent); $Field = 'planet_' . $this->_resource[$ProdID] . '_porcent'; $CurrRow = array(); $CurrRow['name'] = $this->_resource[$ProdID]; $CurrRow['porcent'] = $this->_current_planet[$Field]; $CurrRow['option'] = $this->build_options($CurrRow['porcent']); $CurrRow['type'] = $this->_lang['tech'][$ProdID]; $CurrRow['level'] = $ProdID > 200 ? $this->_lang['rs_amount'] : $this->_lang['rs_lvl']; $CurrRow['level_type'] = $this->_current_planet[$this->_resource[$ProdID]]; $CurrRow['metal_type'] = FormatLib::pretty_number($metal); $CurrRow['crystal_type'] = FormatLib::pretty_number($crystal); $CurrRow['deuterium_type'] = FormatLib::pretty_number($deuterium); $CurrRow['energy_type'] = FormatLib::pretty_number($energy); $CurrRow['metal_type'] = FormatLib::color_number($CurrRow['metal_type']); $CurrRow['crystal_type'] = FormatLib::color_number($CurrRow['crystal_type']); $CurrRow['deuterium_type'] = FormatLib::color_number($CurrRow['deuterium_type']); $CurrRow['energy_type'] = FormatLib::color_number($CurrRow['energy_type']); $parse['resource_row'] .= parent::$page->parse_template($ResourcesRowTPL, $CurrRow); } } $parse['Production_of_resources_in_the_planet'] = str_replace('%s', $this->_current_planet['planet_name'], $this->_lang['rs_production_on_planet']); $parse['production_level'] = $this->prod_level($this->_current_planet['planet_energy_used'], $this->_current_planet['planet_energy_max']); $parse['metal_basic_income'] = $game_metal_basic_income; $parse['crystal_basic_income'] = $game_crystal_basic_income; $parse['deuterium_basic_income'] = $game_deuterium_basic_income; $parse['energy_basic_income'] = $game_energy_basic_income; $parse['planet_metal_max'] = $this->resource_color($this->_current_planet['planet_metal'], $this->_current_planet['planet_metal_max']); $parse['planet_crystal_max'] = $this->resource_color($this->_current_planet['planet_crystal'], $this->_current_planet['planet_crystal_max']); $parse['planet_deuterium_max'] = $this->resource_color($this->_current_planet['planet_deuterium'], $this->_current_planet['planet_deuterium_max']); $parse['metal_total'] = FormatLib::color_number(FormatLib::pretty_number(floor($this->_current_planet['planet_metal_perhour'] * 0.01 * $parse['production_level'] + $parse['metal_basic_income']))); $parse['crystal_total'] = FormatLib::color_number(FormatLib::pretty_number(floor($this->_current_planet['planet_crystal_perhour'] * 0.01 * $parse['production_level'] + $parse['crystal_basic_income']))); $parse['deuterium_total'] = FormatLib::color_number(FormatLib::pretty_number(floor($this->_current_planet['planet_deuterium_perhour'] * 0.01 * $parse['production_level'] + $parse['deuterium_basic_income']))); $parse['energy_total'] = FormatLib::color_number(FormatLib::pretty_number(floor($this->_current_planet['planet_energy_max'] + $parse['energy_basic_income'] + $this->_current_planet['planet_energy_used']))); $parse['daily_metal'] = $this->calculate_daily($this->_current_planet['planet_metal_perhour'], $parse['production_level'], $parse['metal_basic_income']); $parse['weekly_metal'] = $this->calculate_weekly($this->_current_planet['planet_metal_perhour'], $parse['production_level'], $parse['metal_basic_income']); $parse['daily_crystal'] = $this->calculate_daily($this->_current_planet['planet_crystal_perhour'], $parse['production_level'], $parse['crystal_basic_income']); $parse['weekly_crystal'] = $this->calculate_weekly($this->_current_planet['planet_crystal_perhour'], $parse['production_level'], $parse['crystal_basic_income']); $parse['daily_deuterium'] = $this->calculate_daily($this->_current_planet['planet_deuterium_perhour'], $parse['production_level'], $parse['deuterium_basic_income']); $parse['weekly_deuterium'] = $this->calculate_weekly($this->_current_planet['planet_deuterium_perhour'], $parse['production_level'], $parse['deuterium_basic_income']); $parse['daily_metal'] = FormatLib::color_number(FormatLib::pretty_number($parse['daily_metal'])); $parse['weekly_metal'] = FormatLib::color_number(FormatLib::pretty_number($parse['weekly_metal'])); $parse['daily_crystal'] = FormatLib::color_number(FormatLib::pretty_number($parse['daily_crystal'])); $parse['weekly_crystal'] = FormatLib::color_number(FormatLib::pretty_number($parse['weekly_crystal'])); $parse['daily_deuterium'] = FormatLib::color_number(FormatLib::pretty_number($parse['daily_deuterium'])); $parse['weekly_deuterium'] = FormatLib::color_number(FormatLib::pretty_number($parse['weekly_deuterium'])); $ValidList['percent'] = array(0, 10, 20, 30, 40, 50, 60, 70, 80, 90, 100); $SubQry = ''; if ($_POST && !parent::$users->is_on_vacations($this->_current_user)) { foreach ($_POST as $Field => $Value) { $FieldName = 'planet_' . $Field . '_porcent'; if (isset($this->_current_planet[$FieldName])) { if (!in_array($Value, $ValidList['percent'])) { FunctionsLib::redirect('game.php?page=resourceSettings'); } $Value = $Value / 10; $this->_current_planet[$FieldName] = $Value; $SubQry .= ", `" . $FieldName . "` = '" . $Value . "'"; } } parent::$db->query("UPDATE " . PLANETS . " SET\n\t\t\t\t\t\t\t\t\t`planet_id` = '" . $this->_current_planet['planet_id'] . "'\n\t\t\t\t\t\t\t\t\t{$SubQry}\n\t\t\t\t\t\t\t\t\tWHERE `planet_id` = '" . $this->_current_planet['planet_id'] . "';"); FunctionsLib::redirect('game.php?page=resourceSettings'); } parent::$page->display(parent::$page->parse_template(parent::$page->get_template('resources/resources'), $parse)); }
/** * checkStorage * * @param array $amount Amount * @param boolean $force Force, ignore storage size * * @return boolean */ public function checkStorage($amount, $force = null) { if (!is_array($amount)) { throw new Exception("Must be array", 1); } $hangar = array('metal' => 22, 'crystal' => 23, 'deuterium' => 24); $check = array(); foreach ($hangar as $k => $v) { if (!emtpy($amount[$k])) { if ($this->current_planet["planet_" . $k] + $amount[$k] >= ProductionLib::maxStorable($this->current_planet[$this->resource[$v]])) { $check[$k] = false; } else { $check[$k] = true; } } else { $check[$k] = true; } } if ($check['metal'] === true && $check['crystal'] === true && $check['deuterium'] === true) { return false; } else { if (is_null($force)) { foreach ($hangar as $k => $v) { if ($check[$k] === false) { return sprintf($this->langs['tr_full_storage'], strtolower($this->langs['info'][$v]['name'])); } else { continue; } } } else { return $check; } } }
/** * 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'] . "';"); } }
/** * method storage_table * param * return builds the storage table */ private function storage_table($template) { $CurrentBuildtLvl = $this->_current_planet[$this->_resource[$this->_element_id]]; $BuildStartLvl = max(1, $CurrentBuildtLvl - 2); $Table = ""; $ProdFirst = 0; $ActualProd = ProductionLib::maxStorable($CurrentBuildtLvl); for ($BuildLevel = $BuildStartLvl; $BuildLevel < $BuildStartLvl + 15; ++$BuildLevel) { $Prod = ProductionLib::maxStorable($BuildLevel); $bloc['build_lvl'] = $CurrentBuildtLvl == $BuildLevel ? "<font color=\"#ff0000\">" . $BuildLevel . "</font>" : $BuildLevel; $bloc['build_prod'] = FormatLib::pretty_number($Prod); $bloc['build_prod_diff'] = FormatLib::color_number(FormatLib::pretty_number($Prod - $ActualProd)); if ($ProdFirst == 0) { $ProdFirst = floor($Prod); } $Table .= parent::$page->parse_template($template, $bloc); } return $Table; }