Esempio n. 1
0
 /**
  * method update_buildings_queue
  * param &$current_planet
  * param &$current_user
  * return update buildings in the building queue
  */
 public static function update_buildings_queue(&$current_planet, &$current_user)
 {
     if ($current_planet['planet_b_building_id'] != 0) {
         while ($current_planet['planet_b_building_id'] != 0) {
             if ($current_planet['planet_b_building'] <= time()) {
                 UpdateResources_Lib::update_resource($current_user, $current_planet, $current_planet['planet_b_building'], FALSE);
                 if (self::check_building_queue($current_planet, $current_user)) {
                     Developments_Lib::set_first_element($current_planet, $current_user);
                 }
             } else {
                 break;
             }
         }
     }
 }
Esempio n. 2
0
 /**
  * __construct()
  */
 public function __construct()
 {
     $this->_lang = parent::$lang;
     if ($this->is_session_set()) {
         // Get user data and check it
         $this->set_user_data();
         // Check game close
         Functions_Lib::check_server($this->_user_data);
         // Set the changed planet
         $this->set_planet();
         // Get planet data and check it
         $this->set_planet_data();
         // Update resources, ships, defenses & technologies
         UpdateResources_Lib::update_resource($this->_user_data, $this->_planet_data, time());
         // Update buildings queue
         UpdateLib::updateBuildingsQueue($this->_planet_data, $this->_user_data);
     }
 }
Esempio n. 3
0
    /**
     * method attack_mission
     * param $fleet_row
     * return the attack result
     */
    public function attack_mission($fleet_row)
    {
        $targetPlanet = parent::$db->query_fetch("SELECT *\r\n\t\t\t\t\t\t\t\t\t\t\t\t\t\tFROM " . PLANETS . " AS p\r\n\t\t\t\t\t\t\t\t\t\t\t\t\t\tINNER JOIN " . BUILDINGS . " AS b ON b.building_planet_id = p.`planet_id`\r\n\t\t\t\t\t\t\t\t\t\t\t\t\t\tINNER JOIN " . SHIPS . " AS s ON s.ship_planet_id = p.`planet_id`\r\n\t\t\t\t\t\t\t\t\t\t\t\t\t\tINNER JOIN " . DEFENSES . " AS d ON d.defense_planet_id = p.`planet_id`\r\n\t\t\t\t\t\t\t\t\t\t\t\t\t\tWHERE `planet_galaxy` = " . (int) $fleet_row['fleet_end_galaxy'] . " AND\r\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t`planet_system` = " . (int) $fleet_row['fleet_end_system'] . " AND\r\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t`planet_type` = " . (int) $fleet_row['fleet_end_type'] . " AND\r\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t`planet_planet` = " . (int) $fleet_row['fleet_end_planet'] . ";");
        if ($fleet_row['fleet_mess'] == 0 && $fleet_row['fleet_start_time'] <= time()) {
            if ($fleet_row['fleet_group'] > 0) {
                parent::$db->query("DELETE FROM " . ACS_FLEETS . "\r\n\t\t\t\t\t\t\t\t\t\tWHERE acs_fleet_id =" . intval($fleet_row['fleet_group']));
                parent::$db->query("UPDATE `" . FLEETS . "` SET\r\n\t\t\t\t\t\t\t\t\t\t`fleet_mess` = '1'\r\n\t\t\t\t\t\t\t\t\t\tWHERE `fleet_group` = " . $fleet_row['fleet_group']);
            } else {
                parent::return_fleet($fleet_row['fleet_id']);
            }
            $targetUser = parent::$db->query_fetch('SELECT u.*,
																r.research_energy_technology,
																pr.premium_officier_geologist,
																pr.premium_officier_engineer
															FROM ' . USERS . ' AS u
															INNER JOIN ' . RESEARCH . ' AS r ON r.research_user_id = u.user_id
															INNER JOIN ' . PREMIUM . ' AS pr ON pr.premium_user_id = u.user_id
															WHERE u.user_id = ' . intval($targetPlanet['planet_user_id']));
            UpdateResources_Lib::update_resource($targetUser, $targetPlanet, time());
            $targetGalaxy = parent::$db->query_fetch('SELECT `planet_id`
														FROM ' . PLANETS . '
														WHERE `planet_galaxy` = ' . intval($fleet_row['fleet_end_galaxy']) . ' AND
																`planet_system` = ' . intval($fleet_row['fleet_end_system']) . ' AND
																`planet_planet` = ' . intval($fleet_row['fleet_end_planet']) . ' AND
																`planet_type` = 3;');
            $targetUser = parent::$db->query_fetch('SELECT 	u.*,
																r.research_weapons_technology,
																r.research_shielding_technology,
																r.research_armour_technology,
																pr.premium_officier_technocrat
														FROM ' . USERS . ' AS u
														INNER JOIN ' . RESEARCH . ' AS r ON r.research_user_id = u.user_id
														INNER JOIN ' . PREMIUM . ' AS pr ON pr.premium_user_id = u.user_id
														WHERE u.user_id = ' . intval($targetPlanet['planet_user_id']));
            $TargetUserID = $targetUser['user_id'];
            $attackFleets = array();
            if ($fleet_row['fleet_group'] != 0) {
                $fleets = parent::$db->query('SELECT *
												FROM ' . FLEETS . '
												WHERE fleet_group=' . $fleet_row['fleet_group']);
                if ($fleets != NULL) {
                    while ($fleet = parent::$db->fetch_assoc($fleets)) {
                        $attackFleets[$fleet['fleet_id']]['fleet'] = $fleet;
                        $attackFleets[$fleet['fleet_id']]['user'] = parent::$db->query_fetch('SELECT 	u.*,
																									r.research_weapons_technology,
																									r.research_shielding_technology,
																									r.research_armour_technology
																							FROM ' . USERS . ' AS u
																							INNER JOIN ' . RESEARCH . ' AS r ON r.research_user_id = u.user_id
																							WHERE user_id=' . intval($fleet_row['fleet_owner']));
                        $attackFleets[$fleet['fleet_id']]['detail'] = array();
                        $temp = explode(';', $fleet['fleet_array']);
                        foreach ($temp as $temp2) {
                            $temp2 = explode(',', $temp2);
                            if ($temp2[0] < 100) {
                                continue;
                            }
                            if (!isset($attackFleets[$fleet['fleet_id']]['detail'][$temp2[0]])) {
                                $attackFleets[$fleet['fleet_id']]['detail'][$temp2[0]] = 0;
                            }
                            $attackFleets[$fleet['fleet_id']]['detail'][$temp2[0]] += $temp2[1];
                        }
                    }
                }
            } else {
                $attackFleets[$fleet_row['fleet_id']]['fleet'] = $fleet_row;
                $attackFleets[$fleet_row['fleet_id']]['user'] = parent::$db->query_fetch('SELECT 	u.*,
																									r.research_weapons_technology,
																									r.research_shielding_technology,
																									r.research_armour_technology
																							FROM ' . USERS . ' AS u
																							INNER JOIN ' . RESEARCH . ' AS r ON r.research_user_id = u.user_id
																							WHERE user_id=' . intval($fleet_row['fleet_owner']));
                $attackFleets[$fleet_row['fleet_id']]['detail'] = array();
                $temp = explode(';', $fleet_row['fleet_array']);
                foreach ($temp as $temp2) {
                    $temp2 = explode(',', $temp2);
                    if ($temp2[0] < 100) {
                        continue;
                    }
                    if (!isset($attackFleets[$fleet_row['fleet_id']]['detail'][$temp2[0]])) {
                        $attackFleets[$fleet_row['fleet_id']]['detail'][$temp2[0]] = 0;
                    }
                    $attackFleets[$fleet_row['fleet_id']]['detail'][$temp2[0]] += $temp2[1];
                }
            }
            $defense = array();
            $def = parent::$db->query_fetch('SELECT *
												FROM ' . FLEETS . '
												WHERE `fleet_end_galaxy` = ' . intval($fleet_row['fleet_end_galaxy']) . ' AND
														`fleet_end_system` = ' . intval($fleet_row['fleet_end_system']) . ' AND
														`fleet_end_type` = ' . intval($fleet_row['fleet_end_type']) . ' AND
														`fleet_end_planet` = ' . intval($fleet_row['fleet_end_planet']) . ' AND
														fleet_start_time<' . time() . ' AND
														fleet_end_stay>=' . time());
            if ($def != NULL) {
                while ($defRow = parent::$db->fetch_assoc($def)) {
                    $defRowDef = explode(';', $defRow['fleet_array']);
                    foreach ($defRowDef as $Element) {
                        $Element = explode(',', $Element);
                        if ($Element[0] < 100) {
                            continue;
                        }
                        if (!isset($defense[$defRow['fleet_id']]['def'][$Element[0]])) {
                            $defense[$defRow['fleet_id']][$Element[0]] = 0;
                        }
                        $defense[$defRow['fleet_id']]['def'][$Element[0]] += $Element[1];
                        $defense[$defRow['fleet_id']]['user'] = parent::$db->query_fetch('SELECT *
																								FROM ' . USERS . '
																								WHERE user_id = ' . intval($defRow['fleet_owner']));
                    }
                }
            }
            $defense[0]['def'] = array();
            $defense[0]['user'] = $targetUser;
            for ($i = 200; $i < 500; $i++) {
                if (isset($this->_resource[$i]) && isset($targetPlanet[$this->_resource[$i]])) {
                    $defense[0]['def'][$i] = $targetPlanet[$this->_resource[$i]];
                }
            }
            $start = microtime(TRUE);
            $result = $this->acs_attack($attackFleets, $defense);
            $totaltime = microtime(TRUE) - $start;
            parent::$db->query("UPDATE " . PLANETS . " SET\r\n\t\t\t\t\t\t\t\t\t`planet_invisible_start_time` = '" . time() . "',\r\n\t\t\t\t\t\t\t\t\t`planet_debris_metal` = `planet_debris_metal` +'" . ($result['debree']['att'][0] + $result['debree']['def'][0]) . "',\r\n\t\t\t\t\t\t\t\t\t`planet_debris_crystal` = `planet_debris_crystal` + '" . ($result['debree']['att'][1] + $result['debree']['def'][1]) . "'\r\n\t\t\t\t\t\t\t\t\tWHERE `planet_galaxy` = '" . $fleet_row['fleet_end_galaxy'] . "' AND\r\n\t\t\t\t\t\t\t\t\t\t\t`planet_system` = '" . $fleet_row['fleet_end_system'] . "' AND\r\n\t\t\t\t\t\t\t\t\t\t\t`planet_planet` = '" . $fleet_row['fleet_end_planet'] . "' AND\r\n\t\t\t\t\t\t\t\t\t\t\t`planet_type` = 1\r\n\t\t\t\t\t\t\t\t\tLIMIT 1;");
            $totalDebree = $result['debree']['def'][0] + $result['debree']['def'][1] + $result['debree']['att'][0] + $result['debree']['att'][1];
            $steal = array('metal' => 0, 'crystal' => 0, 'deuterium' => 0);
            if ($result['won'] == "a") {
                $steal = $this->acs_steal($attackFleets, $targetPlanet);
            }
            foreach ($attackFleets as $fleetID => $attacker) {
                $fleetArray = '';
                $totalCount = 0;
                foreach ($attacker['detail'] as $element => $amount) {
                    if ($amount) {
                        $fleetArray .= $element . ',' . $amount . ';';
                    }
                    $totalCount += $amount;
                }
                if ($totalCount <= 0) {
                    parent::remove_fleet($fleetID);
                } else {
                    parent::$db->query('UPDATE ' . FLEETS . ' SET
											fleet_array="' . substr($fleetArray, 0, -1) . '",
											fleet_amount=' . $totalCount . ',
											fleet_mess=1
											WHERE fleet_id=' . intval($fleetID));
                }
            }
            foreach ($defense as $fleetID => $defender) {
                if ($fleetID != 0) {
                    $fleetArray = '';
                    $totalCount = 0;
                    foreach ($defender['def'] as $element => $amount) {
                        if ($amount) {
                            $fleetArray .= $element . ',' . $amount . ';';
                        }
                        $totalCount += $amount;
                    }
                    if ($totalCount <= 0) {
                        parent::remove_fleet($fleetID);
                    } else {
                        parent::$db->query("UPDATE " . FLEETS . " SET\r\n\t\t\t\t\t\t\t\t\t\t\t\tfleet_array='{$fleetArray}',\r\n\t\t\t\t\t\t\t\t\t\t\t\tfleet_amount='{$totalCount}'\r\n\t\t\t\t\t\t\t\t\t\t\t\tWHERE fleet_id='{$fleetID}'");
                    }
                } else {
                    $fleetArray = '';
                    $totalCount = 0;
                    foreach ($defender['def'] as $element => $amount) {
                        $fleetArray .= '`' . $this->_resource[$element] . '`=' . $amount . ', ';
                    }
                    parent::$db->query("UPDATE " . PLANETS . " AS p\r\n\t\t\t\t\t\t\t\t\t\t\tINNER JOIN " . SHIPS . " AS s ON s.ship_planet_id = p.`planet_id`\r\n\t\t\t\t\t\t\t\t\t\t\tINNER JOIN " . DEFENSES . " AS d ON d.defense_planet_id = p.`planet_id` SET\r\n\t\t\t\t\t\t\t\t\t\t\t{$fleetArray}\r\n\t\t\t\t\t\t\t\t\t\t\t`planet_metal` = `planet_metal` - '" . $steal['metal'] . "',\r\n\t\t\t\t\t\t\t\t\t\t\t`planet_crystal` = `planet_crystal` - '" . $steal['crystal'] . "',\r\n\t\t\t\t\t\t\t\t\t\t\t`planet_deuterium` = `planet_deuterium` - '" . $steal['deuterium'] . "'\r\n\t\t\t\t\t\t\t\t\t\t\tWHERE `planet_galaxy` = '" . $fleet_row['fleet_end_galaxy'] . "' AND\r\n\t\t\t\t\t\t\t\t\t\t\t\t\t`planet_system` = '" . $fleet_row['fleet_end_system'] . "' AND\r\n\t\t\t\t\t\t\t\t\t\t\t\t\t`planet_planet` = '" . $fleet_row['fleet_end_planet'] . "' AND\r\n\t\t\t\t\t\t\t\t\t\t\t\t\t`planet_type` = '" . $fleet_row['fleet_end_type'] . "';");
                }
            }
            $FleetDebris = $result['debree']['att'][0] + $result['debree']['def'][0] + $result['debree']['att'][1] + $result['debree']['def'][1];
            $StrAttackerUnits = sprintf($this->_lang['sys_attacker_lostunits'], $result['lost']['att']);
            $StrDefenderUnits = sprintf($this->_lang['sys_defender_lostunits'], $result['lost']['def']);
            $StrRuins = sprintf($this->_lang['sys_gcdrunits'], $result['debree']['def'][0] + $result['debree']['att'][0], $this->_lang['Metal'], $result['debree']['def'][1] + $result['debree']['att'][1], $this->_lang['Crystal']);
            $DebrisField = $StrAttackerUnits . "<br />" . $StrDefenderUnits . "<br />" . $StrRuins;
            $MoonChance = $FleetDebris / 100000;
            if ($FleetDebris > 2000000) {
                $MoonChance = 20;
                $UserChance = mt_rand(1, 100);
                $ChanceMoon = sprintf($this->_lang['sys_moonproba'], $MoonChance);
            } elseif ($FleetDebris < 100000) {
                $UserChance = 0;
                $ChanceMoon = sprintf($this->_lang['sys_moonproba'], $MoonChance);
            } elseif ($FleetDebris >= 100000) {
                $UserChance = mt_rand(1, 100);
                $ChanceMoon = sprintf($this->_lang['sys_moonproba'], $MoonChance);
            }
            if ($UserChance > 0 && $UserChance <= $MoonChance && $targetGalaxy['id'] == 0) {
                include_once XGP_ROOT . 'application/libraries/Creator_Lib.php';
                $creator = new Creator_Lib();
                $TargetPlanetName = $creator->create_moon($fleet_row['fleet_end_galaxy'], $fleet_row['fleet_end_system'], $fleet_row['fleet_end_planet'], $TargetUserID, $fleet_row['fleet_start_time'], '', $MoonChance);
                $GottenMoon = sprintf($this->_lang['sys_moonbuilt'], $TargetPlanetName, $fleet_row['fleet_end_galaxy'], $fleet_row['fleet_end_system'], $fleet_row['fleet_end_planet']);
                $GottenMoon .= "<br />";
            } elseif ($UserChance = 0 or $UserChance > $MoonChance) {
                $GottenMoon = "";
            }
            $formatted_cr = $this->build_report($result, $steal, $MoonChance, $GottenMoon, $totaltime);
            $raport = $formatted_cr['html'];
            $rid = md5($raport);
            $QryInsertRapport = 'INSERT INTO ' . REPORTS . ' SET ';
            $QryInsertRapport .= '`report_time` = UNIX_TIMESTAMP(), ';
            foreach ($attackFleets as $fleetID => $attacker) {
                $users2[$attacker['user']['user_id']] = $attacker['user']['user_id'];
            }
            foreach ($defense as $fleetID => $defender) {
                $users2[$defender['user']['user_id']] = $defender['user']['user_id'];
            }
            $QryInsertRapport .= '`report_owners` = "' . implode(',', $users2) . '", ';
            $QryInsertRapport .= '`report_rid` = "' . $rid . '", ';
            $QryInsertRapport .= '`report_destroyed` = "' . $formatted_cr['destroyed'] . '", ';
            $QryInsertRapport .= '`report_content` = "' . parent::$db->escape_value($raport) . '"';
            parent::$db->query($QryInsertRapport);
            if ($result['won'] == "a") {
                $style = "green";
            } elseif ($result['won'] == "w") {
                $style = "orange";
            } elseif ($result['won'] == "r") {
                $style = "red";
            }
            $raport = "<a href=\"#\" style=\"color:" . $style . ";\" OnClick=\\'f(\"game.php?page=CombatReport&report=" . $rid . "\", \"\");\\' >" . $this->_lang['sys_mess_attack_report'] . " [" . $fleet_row['fleet_end_galaxy'] . ":" . $fleet_row['fleet_end_system'] . ":" . $fleet_row['fleet_end_planet'] . "]</a>";
            Functions_Lib::send_message($fleet_row['fleet_owner'], '', $fleet_row['fleet_start_time'], 1, $this->_lang['sys_mess_tower'], $raport, '');
            if ($result['won'] == "a") {
                $style = "red";
            } elseif ($result['won'] == "w") {
                $style = "orange";
            } elseif ($result['won'] == "r") {
                $style = "lime";
            }
            $raport2 = "<a href=\"#\" style=\"color:" . $style . ";\" OnClick=\\'f(\"game.php?page=CombatReport&report=" . $rid . "\", \"\");\\' >" . $this->_lang['sys_mess_attack_report'] . " [" . $fleet_row['fleet_end_galaxy'] . ":" . $fleet_row['fleet_end_system'] . ":" . $fleet_row['fleet_end_planet'] . "]</a>";
            foreach ($users2 as $id) {
                if ($id != $fleet_row['fleet_owner'] && $id != 0) {
                    Functions_Lib::send_message($id, '', $fleet_row['fleet_start_time'], 1, $this->_lang['sys_mess_tower'], $raport2, '');
                }
            }
        } elseif ($fleet_row['fleet_end_time'] <= time()) {
            $Message = sprintf($this->_lang['sys_fleet_won'], $targetPlanet['planet_name'], Fleets_Lib::target_link($fleet_row, ''), Format_Lib::pretty_number($fleet_row['fleet_resource_metal']), $this->_lang['Metal'], Format_Lib::pretty_number($fleet_row['fleet_resource_crystal']), $this->_lang['Crystal'], Format_Lib::pretty_number($fleet_row['fleet_resource_deuterium']), $this->_lang['Deuterium']);
            Functions_Lib::send_message($fleet_row['fleet_owner'], '', $fleet_row['fleet_end_time'], 1, $this->_lang['sys_mess_tower'], $this->_lang['sys_mess_fleetback'], $Message);
            parent::restore_fleet($fleet_row);
            parent::remove_fleet($fleet_row['fleet_id']);
        }
    }
Esempio n. 4
0
 /**
  * method make_update
  * param $fleet_row
  * param $galaxy
  * param $system
  * param $planet
  * param $type
  * return make a planet update, required before do other stuff
  */
 protected function make_update($fleet_row, $galaxy, $system, $planet, $type)
 {
     $target_planet = parent::$db->query_fetch("SELECT *\r\n\t\t\t\t\t\t\t\t\t\t\t\t\t\tFROM `" . PLANETS . "` AS p\r\n\t\t\t\t\t\t\t\t\t\t\t\t\t\tLEFT JOIN `" . BUILDINGS . "` AS b ON b.building_planet_id = p.`planet_id`\r\n\t\t\t\t\t\t\t\t\t\t\t\t\t\tLEFT JOIN `" . DEFENSES . "` AS d ON d.defense_planet_id = p.`planet_id`\r\n\t\t\t\t\t\t\t\t\t\t\t\t\t\tLEFT JOIN `" . SHIPS . "` AS s ON s.ship_planet_id = p.`planet_id`\r\n\t\t\t\t\t\t\t\t\t\t\t\t\t\tWHERE `planet_galaxy` = " . $galaxy . " AND\r\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t`planet_system` = " . $system . " AND\r\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t`planet_planet` = " . $planet . " AND\r\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t`planet_type` = " . $type . ";");
     $target_user = parent::$db->query_fetch("SELECT *\r\n\t\t\t\t\t\t\t\t\t\t\t\t\t\tFROM `" . USERS . "` AS u\r\n\t\t\t\t\t\t\t\t\t\t\t\t\t\tINNER JOIN " . RESEARCH . " AS r ON r.research_user_id = u.user_id\r\n\t\t\t\t\t\t\t\t\t\t\t\t\t\tINNER JOIN " . PREMIUM . " AS pr ON pr.premium_user_id = u.user_id\r\n\t\t\t\t\t\t\t\t\t\t\t\t\t\tWHERE u.`user_id` = " . $target_planet['planet_user_id']);
     UpdateResources_Lib::update_resource($target_user, $target_planet, time());
 }