Exemple #1
0
function damage_ship($amount, $fig_dam, $s_dam, $from, $target, $target_ship)
{
    global $db_name, $query;
    //set the shields down first off (if needed).
    if ($s_dam > 0) {
        $target_ship['shields'] -= $s_dam;
        if ($target_ship['shields'] < 0) {
            $target_ship['shields'] == 0;
        }
        dbn("update {$db_name}_ships set shields = shields - '{$s_dam}' where ship_id = '{$target_ship['ship_id']}'");
    }
    //take the fighters down next (if needed).
    if ($fig_dam > 0) {
        $target_ship['fighters'] -= $fig_dam;
        if ($target_ship['fighters'] < 0) {
            $target_ship['fighters'] == 0;
        }
        dbn("update {$db_name}_ships set fighters = fighters - '{$fig_dam}' where ship_id = '{$target_ship['ship_id']}'");
    }
    //don't want to hurt the admin now do we?
    if ($target['login_id'] != 1) {
        //only play with the amount distribution if there is no value to amount
        if ($amount > 0) {
            $shield_damage = $amount;
            if ($shield_damage > $target_ship['shields']) {
                $shield_damage = $target_ship['shields'];
            }
            $amount -= $shield_damage;
        }
        if ($amount >= $target_ship['fighters'] || $amount < 0) {
            //destroy ship
            //Minerals go to the system
            if ($from['location'] != 1 && ($target_ship['fuel'] > 0 || $target_ship['metal']) > 0) {
                dbn("update {$db_name}_stars set fuel = fuel + " . round($target_ship[fuel] * (mt_rand(20, 80) / 100)) . ", metal = metal + " . round($target_ship[metal] * (mt_rand(40, 90) / 100)) . " where star_id = {$target_ship['location']}");
            }
            dbn("delete from {$db_name}_ships where ship_id = '{$target_ship['ship_id']}'");
            dbn("update {$db_name}_users set fighters_killed = fighters_killed + '{$target_ship['fighters']}', ships_killed = ships_killed + '1', ships_killed_points = ships_killed_points + '{$target_ship['point_value']}' where login_id = '{$from['login_id']}'");
            dbn("update {$db_name}_users set fighters_lost = fighters_lost + '{$target_ship['fighters']}', ships_lost = ships_lost + '1', ships_lost_points = ships_lost_points + '{$target_ship['point_value']}' where login_id = '{$target['login_id']}'");
            if (eregi($cw['escape'], $target_ship['class_name'])) {
                // escape pod lost
                dbn("update {$db_name}_users set location = '1', ship_id = '1', last_attack = " . time() . ", last_attack_by = '{$from['login_name']}', explored_sys = '1' where login_id = '{$target['login_id']}'");
                wipe_player($target['login_id'], $target['clan_id']);
                return 1;
            } else {
                // normal ship lost
                //don't bother putting an AI into a new ship to command etc.
                if ($target['login_id'] > 5) {
                    if ($target['ship_id'] != $target_ship['ship_id']) {
                        $new_ship_id = $target['ship_id'];
                    } else {
                        db("select ship_id from {$db_name}_ships where login_id = '{$target_ship['login_id']}' LIMIT 1");
                        $other_ship = dbr();
                        if (!empty($other_ship['ship_id'])) {
                            // jump to other ship
                            $new_ship_id = $other_ship['ship_id'];
                        } else {
                            // build the escape pod
                            create_escape_pod($target);
                            return 2;
                        }
                    }
                    // set ships_killed
                    if ($target['login_id'] > 5) {
                        db("select location from {$db_name}_ships where ship_id = '{$new_ship_id}'");
                        $other_ship = dbr();
                    } else {
                        $other_ship['location'] = 1;
                    }
                    dbn("update {$db_name}_users set ship_id = '{$new_ship_id}', location = '{$other_ship['location']}', last_attack =" . time() . ", last_attack_by = '{$from['login_name']}' where login_id = '{$target['login_id']}'");
                }
            }
            return 1;
        } else {
            // ship not destroyed
            dbn("update {$db_name}_users set last_attack = " . time() . ", last_attack_by = '{$from['login_name']}' where login_id = '{$target['login_id']}'");
            dbn("update {$db_name}_ships set fighters = fighters - '{$amount}', shields = shields - '{$shield_damage}' where ship_id = '{$target_ship['ship_id']}'");
            dbn("update {$db_name}_users set fighters_lost = fighters_lost + '{$amount}' where login_id = '{$target['login_id']}'");
            dbn("update {$db_name}_users set fighters_killed = fighters_killed + '{$amount}' where login_id = '{$from['login_id']}'");
            return 0;
        }
    }
    return 0;
}
Exemple #2
0
         $quick_replace_txt .= $st[298];
         //no replacement command ship in the system. Let's try elsewhere
     } else {
         unset($transfer_command);
         db("select ship_id, location from {$db_name}_ships where location != '{$combat_loc}' && login_id = '{$player['login_id']}' order by fighters desc LIMIT 1");
         $transfer_command = dbr(1);
         //new command ship found. let's pop over there.
         if (!empty($transfer_command['ship_id'])) {
             $player['ship_id'] = $transfer_command['ship_id'];
             $player['location'] = $transfer_command['location'];
             $quick_replace_txt .= $st[299] . " //<b>{$player['location']}</b>.";
             unset($transfer_command);
             //no other ships at all! Let's pop the EP out into the universe.
         } elseif ($simulate_attack == 0) {
             //create the EP
             $player = create_escape_pod($player);
             $quick_replace_txt = sprintf($st[1822], $player[location]);
             post_news(sprintf($st[1823], $player[login_name_link]), "ship, attacking, player_status");
         }
     }
 }
 //Lost a ship. time to inform someone.
 if (isset($quick_replace_txt)) {
     //user lost their ship
     if ($user['login_id'] == $player['login_id']) {
         $tech_str .= $quick_replace_txt;
         $user['ship_id'] = $player['ship_id'];
         $reload_ship = 1;
         //another player
     } elseif ($simulate_attack == 0) {
         send_message($player_id, $quick_replace_txt);