// This program is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the // GNU Affero General Public License for more details. // // You should have received a copy of the GNU Affero General Public License // along with this program. If not, see <http://www.gnu.org/licenses/>. // // File: attack.php include "config/config.php"; updatecookie(); if (checklogin()) { die; } $sql_manager = new manage_table(); $ship_manager = new manage_ship(); $player_manager = new manage_player(); $title = $l_att_title; include "header.php"; ?> <div class="tablecell content both-border"> <div class="pad"> <?php bigtitle(); // Kami Multi Browser Window Attack Fix if (array_key_exists('ship_selected', $_SESSION) == false || $_SESSION['ship_selected'] != $ship_id) { echo "You need to Click on the ship first.<BR><BR>"; TEXT_GOTOMAIN(); ?> </div></div> <?php
public function process_xenobes() { global $db_prefix; $sql_manager = new manage_table(); $ship_manager = new manage_ship(); $chance_xenobe_does_somthing = 20; $count_xenobes = 0; $count_xenobes_sentinal = 0; $count_xenobes_sentinal_attacking = 0; $count_xenobes_roam = 0; $count_xenobes_roam_attacking = 0; $count_xenobes_roamandtrade = 0; $count_xenobes_roamandtrade_attacking = 0; $count_xenobes_roamandhunt = 0; $count_xenobes_roamandhunt_attacking = 0; $count_xenobes_roamandhunt_hunting = 0; /*First we want to lock the tables*/ $tables_to_lock_array = array('xenobe', 'ships', 'sector_defence', 'player_logs', 'security_logs'); $tables_to_read_array = array('zones', 'universe', 'links'); if ($sql_manager->lock_table($tables_to_lock_array, $tables_to_read_array)) { /*Now the table is locked, we can have some fun with the xenobes*/ echo "<b>SCHEDULE - XENOBE<b><br/>"; /*Cycle through all the xenobes and do somthing with them*/ $join_query = "SELECT * FROM " . $db_prefix . "ships JOIN " . $db_prefix . "xenobe WHERE email=xenobe_id and active='Y' and ship_destroyed='N' ORDER BY ship_id;"; $xenobe_pilots = $sql_manager->process_query($join_query); if ($xenobe_pilots) { foreach ($xenobe_pilots as $row) { /*Xenobe is alive at the beginning of this function*/ $xenobeisdead = 'N'; /*Refresh the Xenobe, but make it pay for its own upgrades out of the credits it has onboard!*/ $this->regenerate_xenobe($row['ship_id'], $xenobeisdead); /*Do somthing with each Xenobe Pilot*/ $count_xenobes++; if (mt_rand(1, 100) > $chance_xenobe_does_somthing) { ############################################################################################# # ORDERS = 0 = SENTINAL # ############################################################################################# if ($row['orders'] == 0) { echo "<b>Sentinal<b><br/>"; $count_xenobes_sentinal++; $target_found = $this->check_for_target($row['ship_id'], $row['sector'], $row['email']); if ($target_found) { /*Load target Data*/ $target_data = $sql_manager->playerinfo($target_found, ""); if ($row['aggression'] == 0) { /*Do nothing*/ } else { if ($row['aggression'] == 1) { if ($row['ship_fighters'] > $target_data['ship_fighters']) { /*Xenobe has more fighters then the target ship... launch an attack*/ $count_xenobes_sentinal_attacking++; # LAUNCH ATTACK # echo $ship_manager->attack_target_ship($target_found, $row['ship_id']); $xenobeisdead = $sql_manager->check_player_alive($row['ship_id']); if ($xenobeisdead == 'Y') { /*Xenobe dead, skip to the next xenobe*/ continue; } } } else { if ($row['aggression'] == 2) { /*Xenobe has decided the target shouldnt be alive, attacks without any care for its own ship*/ $count_xenobes_sentinal_attacking++; # LAUNCH ATTACK # echo $ship_manager->attack_target_ship($target_found, $row['ship_id']); $xenobeisdead = $sql_manager->check_player_alive($row['ship_id']); if ($xenobeisdead == 'Y') { /*Xenobe dead, skip to the next xenobe*/ continue; } } } } } } else { if ($row['orders'] == 1) { echo "<b>Roam<b><br/>"; $this->move_xenobe($row['ship_id'], $row['aggression'], $row['turns']); $count_xenobes_roam++; } else { if ($row['orders'] == 2) { echo "<b>Roam And Trade<b><br/>"; $count_xenobes_roamandtrade++; } else { if ($row['orders'] == 3) { echo "<b>Roam And Hunt<b><br/>"; $count_xenobes_roamandhunt++; } } } } ############################################################################################# # END ORDERS # ############################################################################################# } } } else { /*No Xenobes Found, they're either all dead or somthing has gone wrong!*/ } } else { /*Somthing went wrong*/ echo "boo boo"; } /*Now unlock the tables*/ $sql_manager = new manage_table(); if ($sql_manager->unlock_table()) { /*Now we have finished, unlock the tables.*/ echo "<b>Unlocked</b><br/>"; } else { /*Somthing went wrong*/ echo "bo bo version 2"; } }
public function sector_defence_challange($sector, $id) { global $db_prefix; global $torp_dmg_rate; global $level_factor; $sql_manager = new manage_table(); $player_manager = new manage_player(); $ship_manager = new manage_ship(); $manage_log = new manage_log(); /*load player information*/ $player_data = $sql_manager->playerinfo($id, ""); /*Load sector information - Team defences are removed from the quantities, so if there are any left, it must be hostile, take the apropriate action*/ $total_sector_mines = $sql_manager->sector_defence_quantities($sector, 'M', $id, "investigate"); $total_sector_fighters = $sql_manager->sector_defence_quantities($sector, 'F', $id, "investigate"); $total_sector_fighters = (int) $total_sector_fighters; $total_sector_mines = (int) $total_sector_mines; if ($total_sector_fighters > 0 || $total_sector_mines > 0 || $total_sector_fighters > 0 && $total_sector_mines > 0) { ##Hostile defences detected!## /*Mark player as in combat*/ if ($sql_manager->ship_in_sector_defence_combat($sector, $id)) { ##Log this## /*Log player engaging sector defences*/ } else { ##log this## /*Failed to update ship and set to in combat*/ } ##YOU HAVE ENGAGED THE SECTOR DEFENCES## $sector_defence_fighters = $total_sector_fighters; $playerbeams = $ship_manager->number_beams($player_data['beams']); if ($playerbeams > $player_data['ship_energy']) { /*Player Beams Armed*/ $playerbeams = $player_data['ship_energy']; } $player_data['ship_energy'] = $player_data['ship_energy'] - $playerbeams; $playershields = $ship_manager->number_shields($player_data['shields']); if ($playershields > $player_data['ship_energy']) { /*Player Shields Raised*/ $playershields = $player_data['ship_energy']; } $playertorpnum = round(pow($level_factor, $player_data['torp_launchers'])) * 2; if ($playertorpnum > $player_data['torps']) { /*Torpedos places in firing tubes*/ $playertorpnum = $player_data['torps']; } /*Torpedo warheads armed*/ $playertorpdmg = $torp_dmg_rate * $playertorpnum; /*polerize the armour plating*/ $playerarmor = $player_data['armor_pts']; /*pilots to fighter bays*/ $playerfighters = $player_data['ship_fighters']; /*fetch amount of sector mines in minefield*/ $sector_defence_minefield = $total_sector_mines; if ($sector_defence_minefield > 1) { /*change of getting through minefield*/ $roll = mt_rand(1, $sector_defence_minefield); } else { $roll = 1; } /*total mines which are attracted to the hull of the players ship*/ $sector_defence_minefield = $sector_defence_minefield - $roll; /*prepare mine deflectors for launch*/ $playerminedeflect = $player_data['dev_minedeflector']; /*Where are the fighters? inside or outside the fighter formation?*/ $fighter_or_mines_first = mt_rand(1, 100); if ($fighter_or_mines_first > 50) { /*Engages the fighters first*/ $fighter_results = $this->sector_fighter_engaged($playerbeams, $sector_defence_fighters, $playertorpdmg, $playerarmor, $playerfighters, $playershields, $id); $playerbeams = $fighter_results[0]; $sector_defence_fighters = $fighter_results[1]; $playertorpdmg = $fighter_results[2]; $playerarmor = $fighter_results[3]; $playerfighters = $fighter_results[4]; $playershields = $fighter_results[5]; if ($playerarmor > 0) { if ($playerminedeflect >= $roll) { /*do nothing... players fought off the fighters, and found a hole in minefield*/ /*ship is in sector \o/*/ if ($sql_manager->ship_in_sector_defence_combat("", $id)) { ### ## ## Update Sector Information ## ### $sql_manager->manage_sector_defences($sector, $sector_defence_fighters, $sector_defence_minefield, $id); ### ## ## Update Player Stats ## ### /*Leftover torpedoes?*/ $y = $playertorpdmg / $torp_dmg_rate; $torpedoes_left = $y; /*Leftover energy?*/ $t = $playershields + $playerbeams; $energy_left = $player_data['ship_energy'] - $t; if ($energy_left < 0) { $energy_left = 0; } $updated_stats = array('cleared_defences' => ' ', 'ship_energy' => $energy_left, 'dev_minedeflector' => $playerminedeflect, 'armor_pts' => $playerarmor, 'ship_fighters' => $playerfighters, 'torps' => $torpedoes_left); if ($sql_manager->updatePlayer($id, "ships", $updated_stats)) { ##Log this## /*Log player got passed sector defences*/ return true; } else { ##Log this## /*Log player failed to update their stats*/ return false; } } else { ##log this## /*Failed to update ship setting got into sector - fail entire move*/ return false; } } else { $minefield_results = $this->sector_minefield_engaged($playerminedeflect, $playershields, $playerarmor, $sector_defence_minefield, $id); $playerminedeflect = $minefield_results[0]; $playershields = $minefield_results[1]; $playerarmor = $minefield_results[2]; $sector_defence_minefield = $minefield_results[3]; if ($playerarmor > 0) { /*ship is in sector \o/*/ if ($sql_manager->ship_in_sector_defence_combat("", $id)) { ### ## ## Update Sector Information ## ### $sql_manager->manage_sector_defences($sector, $sector_defence_fighters, $sector_defence_minefield, $id); ### ## ## Update Player Stats ## ### /*Leftover torpedoes?*/ $y = $playertorpdmg / $torp_dmg_rate; $torpedoes_left = $y; /*Leftover energy?*/ $t = $playershields + $playerbeams; $energy_left = $player_data['ship_energy'] - $t; if ($energy_left < 0) { $energy_left = 0; } $updated_stats = array('cleared_defences' => ' ', 'ship_energy' => $energy_left, 'dev_minedeflector' => $playerminedeflect, 'armor_pts' => $playerarmor, 'ship_fighters' => $playerfighters, 'torps' => $torpedoes_left); if ($sql_manager->updatePlayer($id, "ships", $updated_stats)) { ##Log this## /*Log player got passed sector defences*/ return true; } else { ##Log this## /*Log player failed to update their stats*/ return false; } } else { ##log this## /*Failed to update ship setting got into sector - fail entire move*/ return false; } } else { ### ## ## Update Sector Information ## ### $sql_manager->manage_sector_defences($sector, $sector_defence_fighters, $sector_defence_minefield, $id); //ship destroyed! return false; } } } else { echo "player died"; ### ## ## Update Sector Information ## ### $sql_manager->manage_sector_defences($sector, $sector_defence_fighters, $sector_defence_minefield, $id); echo "passed function"; //ship destroyed! return false; } } else { /*Engages the minefield first*/ if ($playerminedeflect >= $roll) { /*do nothing... hole in minefield sucessfully found. Now lets go and get those fighters...*/ } else { $minefield_results = $this->sector_minefield_engaged($playerminedeflect, $playershields, $playerarmor, $sector_defence_minefield, $id); $playerminedeflect = $minefield_results[0]; $playershields = $minefield_results[1]; $playerarmor = $minefield_results[2]; $sector_defence_minefield = $minefield_results[3]; } if ($playerarmor > 0) { $fighter_results = $this->sector_fighter_engaged($playerbeams, $sector_defence_fighters, $playertorpdmg, $playerarmor, $playerfighters, $playershields, $id); $playerbeams = $fighter_results[0]; $sector_defence_fighters = $fighter_results[1]; $playertorpdmg = $fighter_results[2]; $playerarmor = $fighter_results[3]; $playerfighters = $fighter_results[4]; $playershields = $fighter_results[5]; if ($playerarmor > 0) { /*ship is in sector \o/*/ if ($sql_manager->ship_in_sector_defence_combat("", $id)) { ### ## ## Update Sector Information ## ### $sql_manager->manage_sector_defences($sector, $sector_defence_fighters, $sector_defence_minefield, $id); ### ## ## Update Player Stats ## ### /*Leftover torpedoes?*/ $y = $playertorpdmg / $torp_dmg_rate; $torpedoes_left = $y; /*Leftover energy?*/ $t = $playershields + $playerbeams; $energy_left = $player_data['ship_energy'] - $t; if ($energy_left < 0) { $energy_left = 0; } $updated_stats = array('cleared_defences' => ' ', 'ship_energy' => $energy_left, 'dev_minedeflector' => $playerminedeflect, 'armor_pts' => $playerarmor, 'ship_fighters' => $playerfighters, 'torps' => $torpedoes_left); if ($sql_manager->updatePlayer($id, "ships", $updated_stats)) { ##Log this## /*Log player got passed sector defences*/ return true; } else { ##Log this## /*Log player failed to update their stats*/ return false; } } else { ##log this## /*Failed to update ship setting got into sector - fail entire move*/ return false; } } else { ### ## ## Update Sector Information ## ### $sql_manager->manage_sector_defences($sector, $sector_defence_fighters, $sector_defence_minefield, $id); //ship destroyed! return false; } } else { ### ## ## Update Sector Information ## ### $sql_manager->manage_sector_defences($sector, $sector_defence_fighters, $sector_defence_minefield, $id); //ship destroyed! return false; } } } else { /*NO sector defences, or sector defences belong to self or friend. Player in sector.*/ return true; } }