Ejemplo n.º 1
0
/**
 * MissionCaseStayAlly @todo description
 *
 * @global array $lang @see common.php
 * @param array $fleetRow @see common.php
 * @return bool true.
 */
function missionCaseStayAlly($fleetRow)
{
    global $lang;
    $readConnection = Nova::getSingleton('core/database_connection_pool')->getConnection('core_read');
    $startPlanet = $readConnection->select(array('name', 'id_owner'))->from($readConnection->getDeprecatedTable('planets'))->where('galaxy =?', $fleetRow['fleet_start_galaxy'])->where('system =?', $fleetRow['fleet_start_system'])->where('planet =?', $fleetRow['fleet_start_planet'])->query()->fetch();
    $endPlanet = $readConnection->select(array('name', 'id_owner'))->from($readConnection->getDeprecatedTable('planets'))->where('galaxy =?', $fleetRow['fleet_end_galaxy'])->where('system =?', $fleetRow['fleet_end_system'])->where('planet =?', $fleetRow['fleet_end_planet'])->query()->fetch();
    $fleetStartLink = GetStartAdressLink($fleetRow, '');
    $fleetEndLink = GetTargetAdressLink($fleetRow, '');
    if ($fleetRow['fleet_mess'] == 0) {
        if ($fleetRow['fleet_end_stay'] <= time()) {
            $readConnection->update($readConnection->getDeprecatedTable('fleets'), array('fleet_mess' => 1), array('fleet_id =?' => $fleetRow['fleet_id']));
        } else {
            if ($fleetRow['fleet_start_time'] <= time()) {
                $message = sprintf($lang['sys_tran_mess_owner'], $endPlanet['name'], $fleetEndLink, $fleetRow['fleet_resource_metal'], $lang['Metal'], $fleetRow['fleet_resource_crystal'], $lang['Crystal'], $fleetRow['fleet_resource_deuterium'], $lang['Deuterium']);
                SendSimpleMessage($startPlanet['id_owner'], '', $fleetRow['fleet_start_time'], 5, $lang['sys_mess_tower'], $lang['sys_mess_transport'], $message);
                $message = sprintf($lang['sys_tran_mess_user'], $startPlanet['name'], $fleetStartLink, $endPlanet['name'], $fleetEndLink, $fleetRow['fleet_resource_metal'], $lang['Metal'], $fleetRow['fleet_resource_crystal'], $lang['Crystal'], $fleetRow['fleet_resource_deuterium'], $lang['Deuterium']);
                SendSimpleMessage($endPlanet['id_owner'], '', $fleetRow['fleet_start_time'], 5, $lang['sys_mess_tower'], $lang['sys_mess_transport'], $message);
            }
        }
    } else {
        if ($fleetRow['fleet_end_time'] <= time()) {
            $message = sprintf($lang['sys_tran_mess_back'], $startPlanet['name'], $fleetStartLink);
            SendSimpleMessage($startPlanet['id_owner'], '', $fleetRow['fleet_end_time'], 5, $lang['sys_mess_tower'], $lang['sys_mess_fleetback'], $message);
            RestoreFleetToPlanet($fleetRow, true);
            $readConnection->delete($readConnection->getDeprecatedTable('fleets'), array('fleet_id =?' => $fleetRow['fleet_id']));
        }
    }
    return true;
}
Ejemplo n.º 2
0
function flt_mission_colonize(&$mission_data)
{
    $fleet_row =& $mission_data['fleet'];
    $src_user_row =& $mission_data['src_user'];
    global $lang;
    $TargetAdress = sprintf($lang['sys_adress_planet'], $fleet_row['fleet_end_galaxy'], $fleet_row['fleet_end_system'], $fleet_row['fleet_end_planet']);
    $fleet_array = sys_unit_str2arr($fleet_row['fleet_array']);
    $TheMessage = $lang['sys_colo_no_colonizer'];
    if ($fleet_array[SHIP_COLONIZER] >= 1) {
        $TheMessage = $lang['sys_colo_notfree'];
        if (!$mission_data['dst_planet'] || empty($mission_data['dst_planet'])) {
            $iPlanetCount = get_player_current_colonies($src_user_row);
            // Can we colonize more planets?
            $TheMessage = $lang['sys_colo_maxcolo'];
            if ($iPlanetCount < get_player_max_colonies($src_user_row)) {
                // Yes, we can colonize
                $TheMessage = $lang['sys_colo_badpos'];
                $NewOwnerPlanet = uni_create_planet($fleet_row['fleet_end_galaxy'], $fleet_row['fleet_end_system'], $fleet_row['fleet_end_planet'], $fleet_row['fleet_owner'], "{$lang['sys_colo_defaultname']} {$iPlanetCount}", false, array('user_row' => $src_user_row));
                if ($NewOwnerPlanet) {
                    $TheMessage = $lang['sys_colo_arrival'] . $TargetAdress . $lang['sys_colo_allisok'];
                    msg_send_simple_message($fleet_row['fleet_owner'], '', $fleet_row['fleet_start_time'], MSG_TYPE_SPY, $lang['sys_colo_mess_from'], $lang['sys_colo_mess_report'], $TheMessage);
                    $fleet_array[SHIP_COLONIZER]--;
                    $fleet_row['fleet_amount']--;
                    $fleet_row['fleet_array'] = sys_unit_arr2str($fleet_array);
                    return RestoreFleetToPlanet($fleet_row, false);
                }
            }
        }
    }
    doquery("UPDATE `{{fleets}}` SET `fleet_mess` = '1' WHERE `fleet_id` = '{$fleet_row['fleet_id']}' LIMIT 1;");
    msg_send_simple_message($fleet_row['fleet_owner'], '', $fleet_row['fleet_start_time'], MSG_TYPE_SPY, $lang['sys_colo_mess_from'], $lang['sys_colo_mess_report'], "{$lang['sys_colo_arrival']}{$TargetAdress}{$TheMessage}");
    return CACHE_FLEET;
}
Ejemplo n.º 3
0
function flt_mission_relocate($mission_data)
{
    $fleet_row = $mission_data['fleet'];
    $destination_planet = $mission_data['dst_planet'];
    if (!$destination_planet || !is_array($destination_planet)) {
        doquery("UPDATE {{fleets}} SET `fleet_mess` = 1 WHERE `fleet_id` = {$fleet_row['fleet_id']} LIMIT 1;");
        return CACHE_FLEET;
    }
    /*
        // flt_mission_relocate
        $TargetAdress         = sprintf ($lang['sys_adress_planet'], $fleet_row['fleet_start_galaxy'], $fleet_row['fleet_start_system'], $fleet_row['fleet_start_planet']);
        $TargetAddedGoods     = sprintf ($lang['sys_stay_mess_goods'],
                          $lang['Metal'], pretty_number($fleet_row['fleet_resource_metal']),
                          $lang['Crystal'], pretty_number($fleet_row['fleet_resource_crystal']),
                          $lang['Deuterium'], pretty_number($fleet_row['fleet_resource_deuterium']));
    
        $TargetMessage        = $lang['sys_stay_mess_back'] ."<a href=\"galaxy.php?mode=3&galaxy=". $fleet_row['fleet_start_galaxy'] ."&system=". $fleet_row['fleet_start_system'] ."\">";
        $TargetMessage       .= $TargetAdress. "</a>". $lang['sys_stay_mess_bend'] ."<br />". $TargetAddedGoods;
    
        SendSimpleMessage ( $fleet_row['fleet_owner'], '', $fleet_row['fleet_end_time'], 5, $lang['sys_mess_qg'], $lang['sys_mess_fleetback'], $TargetMessage);
    */
    global $lang;
    $TargetUserID = $destination_planet['id_owner'];
    $TargetAdress = sprintf($lang['sys_adress_planet'], $fleet_row['fleet_end_galaxy'], $fleet_row['fleet_end_system'], $fleet_row['fleet_end_planet']);
    $TargetAddedGoods = sprintf($lang['sys_stay_mess_goods'], $lang['Metal'], pretty_number($fleet_row['fleet_resource_metal']), $lang['Crystal'], pretty_number($fleet_row['fleet_resource_crystal']), $lang['Deuterium'], pretty_number($fleet_row['fleet_resource_deuterium']));
    $TargetMessage = $lang['sys_stay_mess_start'] . "<a href=\"galaxy.php?mode=3&galaxy=" . $fleet_row['fleet_end_galaxy'] . "&system=" . $fleet_row['fleet_end_system'] . "\">";
    $TargetMessage .= $TargetAdress . "</a>" . $lang['sys_stay_mess_end'] . "<br />" . $TargetAddedGoods;
    msg_send_simple_message($TargetUserID, '', $fleet_row['fleet_start_time'], MSG_TYPE_TRANSPORT, $lang['sys_mess_qg'], $lang['sys_stay_mess_stay'], $TargetMessage);
    return RestoreFleetToPlanet($fleet_row, false);
}
Ejemplo n.º 4
0
/**
 * This file is part of XNova:Legacies
 *
 * @license http://www.gnu.org/licenses/gpl-3.0.txt
 * @see http://www.xnova-ng.org/
 *
 * Copyright (c) 2009-2010, XNova Support Team <http://www.xnova-ng.org>
 * All rights reserved.
 *
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * 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 General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 *
 *                                --> NOTICE <--
 *  This file is part of the core development branch, changing its contents will
 * make you unable to use the automatic updates manager. Please refer to the
 * documentation for further information about customizing XNova.
 *
 */
function MissionCaseStay($FleetRow)
{
    global $lang, $resource;
    if ($FleetRow['fleet_mess'] == 0) {
        if ($FleetRow['fleet_start_time'] <= time()) {
            $QryGetTargetPlanet = "SELECT * FROM {{table}} ";
            $QryGetTargetPlanet .= "WHERE ";
            $QryGetTargetPlanet .= "`galaxy` = '" . $FleetRow['fleet_end_galaxy'] . "' AND ";
            $QryGetTargetPlanet .= "`system` = '" . $FleetRow['fleet_end_system'] . "' AND ";
            $QryGetTargetPlanet .= "`planet` = '" . $FleetRow['fleet_end_planet'] . "' AND ";
            $QryGetTargetPlanet .= "`planet_type` = '" . $FleetRow['fleet_end_type'] . "';";
            $TargetPlanet = doquery($QryGetTargetPlanet, 'planets', true);
            $TargetUserID = $TargetPlanet['id_owner'];
            $TargetAdress = sprintf($lang['sys_adress_planet'], $FleetRow['fleet_end_galaxy'], $FleetRow['fleet_end_system'], $FleetRow['fleet_end_planet']);
            $TargetAddedGoods = sprintf($lang['sys_stay_mess_goods'], $lang['Metal'], pretty_number($FleetRow['fleet_resource_metal']), $lang['Crystal'], pretty_number($FleetRow['fleet_resource_crystal']), $lang['Deuterium'], pretty_number($FleetRow['fleet_resource_deuterium']));
            $TargetMessage = $lang['sys_stay_mess_start'] . "<a href=\"galaxy.php?mode=3&galaxy=" . $FleetRow['fleet_end_galaxy'] . "&system=" . $FleetRow['fleet_end_system'] . "\">";
            $TargetMessage .= $TargetAdress . "</a>" . $lang['sys_stay_mess_end'] . "<br />" . $TargetAddedGoods;
            SendSimpleMessage($TargetUserID, '', $FleetRow['fleet_start_time'], 5, $lang['sys_mess_qg'], $lang['sys_stay_mess_stay'], $TargetMessage);
            RestoreFleetToPlanet($FleetRow, false);
            doquery("DELETE FROM {{table}} WHERE `fleet_id` = '" . $FleetRow["fleet_id"] . "';", 'fleets');
        }
    } else {
        if ($FleetRow['fleet_end_time'] <= time()) {
            $TargetAdress = sprintf($lang['sys_adress_planet'], $FleetRow['fleet_start_galaxy'], $FleetRow['fleet_start_system'], $FleetRow['fleet_start_planet']);
            $TargetAddedGoods = sprintf($lang['sys_stay_mess_goods'], $lang['Metal'], pretty_number($FleetRow['fleet_resource_metal']), $lang['Crystal'], pretty_number($FleetRow['fleet_resource_crystal']), $lang['Deuterium'], pretty_number($FleetRow['fleet_resource_deuterium']));
            $TargetMessage = $lang['sys_stay_mess_back'] . "<a href=\"galaxy.php?mode=3&galaxy=" . $FleetRow['fleet_start_galaxy'] . "&system=" . $FleetRow['fleet_start_system'] . "\">";
            $TargetMessage .= $TargetAdress . "</a>" . $lang['sys_stay_mess_bend'] . "<br />" . $TargetAddedGoods;
            SendSimpleMessage($FleetRow['fleet_owner'], '', $FleetRow['fleet_end_time'], 5, $lang['sys_mess_qg'], $lang['sys_mess_fleetback'], $TargetMessage);
            RestoreFleetToPlanet($FleetRow, true);
            doquery("DELETE FROM {{table}} WHERE `fleet_id` = '" . $FleetRow["fleet_id"] . "';", 'fleets');
        }
    }
}
Ejemplo n.º 5
0
/**
 * flt_mission_transport.php
 *
 * @version 2.0 return cacher result
 * @version 1
 * @copyright 2008 By Chlorel for XNova
 */
function flt_mission_transport(&$mission_data)
{
    $fleet_row =& $mission_data['fleet'];
    $source_planet =& $mission_data['src_planet'];
    $destination_planet =& $mission_data['dst_planet'];
    if (!isset($destination_planet['id']) || !$destination_planet['id_owner']) {
        // doquery("UPDATE {{fleets}} SET `fleet_mess` = 1 WHERE `fleet_id` = {$fleet_row['fleet_id']} LIMIT 1;");
        flt_send_back($fleet_row);
        return CACHE_FLEET;
    }
    global $lang;
    $Message = sprintf($lang['sys_tran_mess_user'], $source_planet['name'], uni_render_coordinates_href($fleet_row, 'fleet_start_', 3, ''), $destination_planet['name'], uni_render_coordinates_href($fleet_row, 'fleet_end_', 3, ''), $fleet_row['fleet_resource_metal'], $lang['Metal'], $fleet_row['fleet_resource_crystal'], $lang['Crystal'], $fleet_row['fleet_resource_deuterium'], $lang['Deuterium']);
    msg_send_simple_message($fleet_row['fleet_target_owner'], '', $fleet_row['fleet_start_time'], MSG_TYPE_TRANSPORT, $lang['sys_mess_tower'], $lang['sys_mess_transport'], $Message);
    if ($fleet_row['fleet_target_owner'] != $fleet_row['fleet_owner']) {
        msg_send_simple_message($fleet_row['fleet_owner'], '', $fleet_row['fleet_start_time'], MSG_TYPE_TRANSPORT, $lang['sys_mess_tower'], $lang['sys_mess_transport'], $Message);
    }
    /*
      $Message = sprintf( $lang['sys_tran_mess_owner'],
                  $TargetName, uni_render_coordinates_href($fleet_row, 'fleet_end_', 3, ''),
                  $fleet_row['fleet_resource_metal'], $lang['Metal'],
                  $fleet_row['fleet_resource_crystal'], $lang['Crystal'],
                  $fleet_row['fleet_resource_deuterium'], $lang['Deuterium'] );
      msg_send_simple_message ( $StartOwner, '', $fleet_row['fleet_start_time'], MSG_TYPE_TRANSPORT, $lang['sys_mess_tower'], $lang['sys_mess_transport'], $Message);
    */
    return RestoreFleetToPlanet($fleet_row, false, true);
}
Ejemplo n.º 6
0
/**
 * flt_mission_transport.php
 *
 * @version 2.0 return cacher result
 * @version 1
 * @copyright 2008 By Chlorel for XNova
 */
function flt_mission_transport($mission_data)
{
    $fleet_row = $mission_data['fleet'];
    $source_planet = $mission_data['src_planet'];
    $destination_planet = $mission_data['dst_planet'];
    if (!$destination_planet || !is_array($destination_planet) || !$destination_planet['id_owner']) {
        doquery("UPDATE {{fleets}} SET `fleet_mess` = 1 WHERE `fleet_id` = {$fleet_row['fleet_id']} LIMIT 1;");
        return CACHE_FLEET;
    }
    /*
      // flt_mission_transport
      $Message = sprintf($lang['sys_tran_mess_back'], $StartName, GetStartAdressLink($fleet_row, ''));
      SendSimpleMessage($StartOwner, '', $fleet_row['fleet_end_time'], 5, $lang['sys_mess_tower'], $lang['sys_mess_fleetback'], $Message);
    */
    global $lang;
    $StartName = $source_planet['name'];
    $StartOwner = $fleet_row['fleet_owner'];
    $TargetName = $destination_planet['name'];
    $TargetOwner = $fleet_row['fleet_target_owner'];
    $Message = sprintf($lang['sys_tran_mess_owner'], $TargetName, uni_render_coordinates_href($fleet_row, 'fleet_end_', 3, ''), $fleet_row['fleet_resource_metal'], $lang['Metal'], $fleet_row['fleet_resource_crystal'], $lang['Crystal'], $fleet_row['fleet_resource_deuterium'], $lang['Deuterium']);
    msg_send_simple_message($StartOwner, '', $fleet_row['fleet_start_time'], MSG_TYPE_TRANSPORT, $lang['sys_mess_tower'], $lang['sys_mess_transport'], $Message);
    if ($TargetOwner != $StartOwner) {
        $Message = sprintf($lang['sys_tran_mess_user'], $StartName, uni_render_coordinates_href($fleet_row, 'fleet_start_', 3, ''), $TargetName, uni_render_coordinates_href($fleet_row, 'fleet_end_', 3, ''), $fleet_row['fleet_resource_metal'], $lang['Metal'], $fleet_row['fleet_resource_crystal'], $lang['Crystal'], $fleet_row['fleet_resource_deuterium'], $lang['Deuterium']);
        msg_send_simple_message($TargetOwner, '', $fleet_row['fleet_start_time'], MSG_TYPE_TRANSPORT, $lang['sys_mess_tower'], $lang['sys_mess_transport'], $Message);
    }
    return RestoreFleetToPlanet($fleet_row, false, true);
}
Ejemplo n.º 7
0
function MissionCaseColonisation($FleetRow)
{
    global $lang, $resource;
    $iPlanetCount = mysql_result(doquery("SELECT count(*) FROM {{table}} WHERE `id_owner` = '" . $FleetRow['fleet_owner'] . "' AND `planet_type` = '1'", 'planets'), 0);
    if ($FleetRow['fleet_mess'] == 0) {
        $iGalaxyPlace = mysql_result(doquery("SELECT count(*) FROM {{table}} WHERE `galaxy` = '" . $FleetRow['fleet_end_galaxy'] . "' AND `system` = '" . $FleetRow['fleet_end_system'] . "' AND `planet` = '" . $FleetRow['fleet_end_planet'] . "';", 'galaxy'), 0);
        $TargetAdress = sprintf($lang['sys_adress_planet'], $FleetRow['fleet_end_galaxy'], $FleetRow['fleet_end_system'], $FleetRow['fleet_end_planet']);
        if ($iGalaxyPlace == 0) {
            if ($iPlanetCount >= MAX_PLAYER_PLANETS) {
                $TheMessage = $lang['sys_colo_arrival'] . $TargetAdress . $lang['sys_colo_maxcolo'] . MAX_PLAYER_PLANETS . $lang['sys_colo_planet'];
                SendSimpleMessage($FleetRow['fleet_owner'], '', $FleetRow['fleet_start_time'], 0, $lang['sys_colo_mess_from'], $lang['sys_colo_mess_report'], $TheMessage);
                doquery("UPDATE {{table}} SET `fleet_mess` = '1' WHERE `fleet_id` = " . $FleetRow["fleet_id"], 'fleets');
            } else {
                $NewOwnerPlanet = CreateOnePlanetRecord($FleetRow['fleet_end_galaxy'], $FleetRow['fleet_end_system'], $FleetRow['fleet_end_planet'], $FleetRow['fleet_owner'], $lang['sys_colo_defaultname'], false);
                if ($NewOwnerPlanet == true) {
                    $TheMessage = $lang['sys_colo_arrival'] . $TargetAdress . $lang['sys_colo_allisok'];
                    SendSimpleMessage($FleetRow['fleet_owner'], '', $FleetRow['fleet_start_time'], 0, $lang['sys_colo_mess_from'], $lang['sys_colo_mess_report'], $TheMessage);
                    if ($FleetRow['fleet_amount'] == 1) {
                        doquery("DELETE FROM {{table}} WHERE fleet_id=" . $FleetRow["fleet_id"], 'fleets');
                    } else {
                        $CurrentFleet = explode(";", $FleetRow['fleet_array']);
                        $NewFleet = "";
                        foreach ($CurrentFleet as $Item => $Group) {
                            if ($Group != '') {
                                $Class = explode(",", $Group);
                                if ($Class[0] == 208) {
                                    if ($Class[1] > 1) {
                                        $NewFleet .= $Class[0] . "," . ($Class[1] - 1) . ";";
                                    }
                                } else {
                                    if ($Class[1] != 0) {
                                        $NewFleet .= $Class[0] . "," . $Class[1] . ";";
                                    }
                                }
                            }
                        }
                        $QryUpdateFleet = "UPDATE {{table}} SET ";
                        $QryUpdateFleet .= "`fleet_array` = '" . $NewFleet . "', ";
                        $QryUpdateFleet .= "`fleet_amount` = `fleet_amount` - 1, ";
                        $QryUpdateFleet .= "`fleet_mess` = '1' ";
                        $QryUpdateFleet .= "WHERE `fleet_id` = '" . $FleetRow["fleet_id"] . "';";
                        doquery($QryUpdateFleet, 'fleets');
                    }
                } else {
                    $TheMessage = $lang['sys_colo_arrival'] . $TargetAdress . $lang['sys_colo_badpos'];
                    SendSimpleMessage($FleetRow['fleet_owner'], '', $FleetRow['fleet_start_time'], 0, $lang['sys_colo_mess_from'], $lang['sys_colo_mess_report'], $TheMessage);
                    doquery("UPDATE {{table}} SET `fleet_mess` = '1' WHERE `fleet_id` = " . $FleetRow["fleet_id"], 'fleets');
                }
            }
        } else {
            $TheMessage = $lang['sys_colo_arrival'] . $TargetAdress . $lang['sys_colo_notfree'];
            SendSimpleMessage($FleetRow['fleet_owner'], '', $FleetRow['fleet_end_time'], 0, $lang['sys_colo_mess_from'], $lang['sys_colo_mess_report'], $TheMessage);
            doquery("UPDATE {{table}} SET `fleet_mess` = '1' WHERE `fleet_id` = " . $FleetRow["fleet_id"], 'fleets');
        }
    } else {
        RestoreFleetToPlanet($FleetRow, true);
        doquery("DELETE FROM {{table}} WHERE fleet_id=" . $FleetRow["fleet_id"], 'fleets');
    }
}
Ejemplo n.º 8
0
/**
 * MissionCaseTransport.php
 *
 * @version 1
 * @copyright 2008 By Chlorel for XNova
 */
function MissionCaseTransport($FleetRow)
{
    global $lang;
    $QryStartPlanet = "SELECT * FROM {{table}} ";
    $QryStartPlanet .= "WHERE ";
    $QryStartPlanet .= "`galaxy` = '" . $FleetRow['fleet_start_galaxy'] . "' AND ";
    $QryStartPlanet .= "`system` = '" . $FleetRow['fleet_start_system'] . "' AND ";
    $QryStartPlanet .= "`planet` = '" . $FleetRow['fleet_start_planet'] . "' AND ";
    $QryStartPlanet .= "`planet_type` = '" . $FleetRow['fleet_start_type'] . "';";
    $StartPlanet = doquery($QryStartPlanet, 'planets', true);
    $StartName = $StartPlanet['name'];
    $StartOwner = $StartPlanet['id_owner'];
    $QryTargetPlanet = "SELECT * FROM {{table}} ";
    $QryTargetPlanet .= "WHERE ";
    $QryTargetPlanet .= "`galaxy` = '" . $FleetRow['fleet_end_galaxy'] . "' AND ";
    $QryTargetPlanet .= "`system` = '" . $FleetRow['fleet_end_system'] . "' AND ";
    $QryTargetPlanet .= "`planet` = '" . $FleetRow['fleet_end_planet'] . "' AND ";
    $QryTargetPlanet .= "`planet_type` = '" . $FleetRow['fleet_end_type'] . "';";
    $TargetPlanet = doquery($QryTargetPlanet, 'planets', true);
    $TargetName = $TargetPlanet['name'];
    $TargetOwner = $TargetPlanet['id_owner'];
    if ($FleetRow['fleet_mess'] == 0) {
        if ($FleetRow['fleet_start_time'] < time()) {
            StoreGoodsToPlanet($FleetRow, false);
            $Message = sprintf($lang['sys_tran_mess_owner'], $TargetName, GetTargetAdressLink($FleetRow, ''), $FleetRow['fleet_resource_metal'], $lang['Metal'], $FleetRow['fleet_resource_crystal'], $lang['Crystal'], $FleetRow['fleet_resource_deuterium'], $lang['Deuterium'], $FleetRow['fleet_resource_appolonium'], $lang['Appolonium']);
            SendSimpleMessage($StartOwner, '', $FleetRow['fleet_start_time'], 5, $lang['sys_mess_tower'], $lang['sys_mess_transport'], $Message);
            if ($TargetOwner != $StartOwner) {
                $Message = sprintf($lang['sys_tran_mess_user'], $StartName, GetStartAdressLink($FleetRow, ''), $TargetName, GetTargetAdressLink($FleetRow, ''), $FleetRow['fleet_resource_metal'], $lang['Metal'], $FleetRow['fleet_resource_crystal'], $lang['Crystal'], $FleetRow['fleet_resource_deuterium'], $lang['Deuterium'], $FleetRow['fleet_resource_appolonium'], $lang['Appolonium']);
                SendSimpleMessage($TargetOwner, '', $FleetRow['fleet_start_time'], 5, $lang['sys_mess_tower'], $lang['sys_mess_transport'], $Message);
            }
            $QryUpdateFleet = "UPDATE {{table}} SET ";
            $QryUpdateFleet .= "`fleet_resource_metal` = '0' , ";
            $QryUpdateFleet .= "`fleet_resource_crystal` = '0' , ";
            $QryUpdateFleet .= "`fleet_resource_deuterium` = '0' , ";
            $QryUpdateFleet .= "`fleet_resource_appolonium` = '0' , ";
            $QryUpdateFleet .= "`fleet_mess` = '1' ";
            $QryUpdateFleet .= "WHERE `fleet_id` = '" . $FleetRow['fleet_id'] . "' ";
            $QryUpdateFleet .= "LIMIT 1 ;";
            doquery($QryUpdateFleet, 'fleets');
        }
    } else {
        if ($FleetRow['fleet_end_time'] < time()) {
            $Message = sprintf($lang['sys_tran_mess_back'], $StartName, GetStartAdressLink($FleetRow, ''));
            SendSimpleMessage($StartOwner, '', $FleetRow['fleet_end_time'], 5, $lang['sys_mess_tower'], $lang['sys_mess_fleetback'], $Message);
            RestoreFleetToPlanet($FleetRow, true);
            //Piratenangriff nach Zufallsprinzip
            $zufall = 0;
            $zufall = rand(1, 10);
            if ($zufall == 7) {
                Piratenangriff($FleetRow);
                $zufall = 0;
            }
            // Ende Piratenangriff
            doquery("DELETE FROM {{table}} WHERE fleet_id=" . $FleetRow["fleet_id"], 'fleets');
        }
    }
}
Ejemplo n.º 9
0
function MissionCaseStayAlly($FleetRow)
{
    global $lang;
    $QryStartPlanet = "SELECT name, id_owner FROM {{table}} ";
    $QryStartPlanet .= "WHERE ";
    $QryStartPlanet .= "`galaxy` = '" . $FleetRow['fleet_start_galaxy'] . "' AND ";
    $QryStartPlanet .= "`system` = '" . $FleetRow['fleet_start_system'] . "' AND ";
    $QryStartPlanet .= "`planet` = '" . $FleetRow['fleet_start_planet'] . "';";
    $StartPlanet = doquery($QryStartPlanet, 'planets', true);
    $StartName = $StartPlanet['name'];
    $StartOwner = $StartPlanet['id_owner'];
    $QryTargetPlanet = "SELECT name, id_owner FROM {{table}} ";
    $QryTargetPlanet .= "WHERE ";
    $QryTargetPlanet .= "`galaxy` = '" . $FleetRow['fleet_end_galaxy'] . "' AND ";
    $QryTargetPlanet .= "`system` = '" . $FleetRow['fleet_end_system'] . "' AND ";
    $QryTargetPlanet .= "`planet` = '" . $FleetRow['fleet_end_planet'] . "';";
    $TargetPlanet = doquery($QryTargetPlanet, 'planets', true);
    $TargetName = $TargetPlanet['name'];
    $TargetOwner = $TargetPlanet['id_owner'];
    switch ($FleetRow['fleet_mess']) {
        case '0':
            if ($FleetRow['fleet_start_time'] <= time()) {
                $Message = sprintf($lang['sys_tran_mess_owner'], $TargetName, GetTargetAdressLink($FleetRow, ''), $FleetRow['fleet_resource_metal'], $lang['Metal'], $FleetRow['fleet_resource_crystal'], $lang['Crystal'], $FleetRow['fleet_resource_deuterium'], $lang['Deuterium']);
                SendSimpleMessage($StartOwner, '', $FleetRow['fleet_start_time'], 5, $lang['sys_mess_tower'], $lang['sys_mess_transport'], $Message);
                $Message = sprintf($lang['sys_tran_mess_user'], $StartName, GetStartAdressLink($FleetRow, ''), $TargetName, GetTargetAdressLink($FleetRow, ''), $FleetRow['fleet_resource_metal'], $lang['Metal'], $FleetRow['fleet_resource_crystal'], $lang['Crystal'], $FleetRow['fleet_resource_deuterium'], $lang['Deuterium']);
                SendSimpleMessage($TargetOwner, '', $FleetRow['fleet_start_time'], 5, $lang['sys_mess_tower'], $lang['sys_mess_transport'], $Message);
                $QryUpdateFleet = "UPDATE {{table}} SET ";
                $QryUpdateFleet .= "`fleet_mess` = 1 ";
                $QryUpdateFleet .= "WHERE `fleet_id` = '" . $FleetRow['fleet_id'] . "' ";
                $QryUpdateFleet .= "LIMIT 1 ;";
                doquery($QryUpdateFleet, 'fleets');
            }
            break;
        case '1':
            if ($FleetRow['fleet_end_stay'] <= time()) {
                $QryUpdateFleet = "UPDATE {{table}} SET ";
                $QryUpdateFleet .= "`fleet_mess` = 2 ";
                $QryUpdateFleet .= "WHERE `fleet_id` = '" . $FleetRow['fleet_id'] . "' ";
                $QryUpdateFleet .= "LIMIT 1 ;";
                doquery($QryUpdateFleet, 'fleets');
            }
            break;
        default:
            if ($FleetRow['fleet_end_time'] < time()) {
                $Message = sprintf($lang['sys_tran_mess_back'], $StartName, GetStartAdressLink($FleetRow, ''));
                SendSimpleMessage($StartOwner, '', $FleetRow['fleet_end_time'], 5, $lang['sys_mess_tower'], $lang['sys_mess_fleetback'], $Message);
                RestoreFleetToPlanet($FleetRow, true);
                doquery("DELETE FROM {{table}} WHERE fleet_id=" . $FleetRow["fleet_id"], 'fleets');
            }
            break;
    }
}
Ejemplo n.º 10
0
/**
 * This file is under the GPL liscence, which must be included with the file under distrobution (license.txt)
 * This file was made by Anthony (MadnessRed) [http://madnessred.co.cc/]
 * This file return acs fleets as missioncaseattack will ont return attack fleets.
 * Do not edit this comment block
 */
function MissionCaseACS($FleetRow)
{
    global $phpEx, $pricelist, $lang, $resource, $CombatCaps, $game_config;
    includelang('tech');
    includelang('system');
    if ($FleetRow['fleet_mess'] == 0 && $FleetRow['fleet_start_time'] > time()) {
        //Well... acs in dealt with in misioncaseattack.php, so all we need to do is make the fleet return
        $QryUpdateFleet = "UPDATE {{table}} SET `fleet_mess` = '1' WHERE `fleet_id` = '" . $FleetRow['fleet_id'] . "' LIMIT 1 ;";
        doquery($QryUpdateFleet, 'fleets');
    } elseif ($FleetRow['fleet_end_time'] <= time()) {
        RestoreFleetToPlanet($FleetRow);
        doquery('DELETE FROM {{table}} WHERE `fleet_id`=' . $FleetRow['fleet_id'], 'fleets');
    }
}
Ejemplo n.º 11
0
/**
 * MissionCaseStay.php
 *
 * version 2.0 returns results for new fleet handler
 * @version 1.1
 * @copyright 2008 by Chlorel for XNova
 */
function flt_mission_relocate($mission_data)
{
    $fleet_row =& $mission_data['fleet'];
    $destination_planet =& $mission_data['dst_planet'];
    if (!$destination_planet || !is_array($destination_planet)) {
        // doquery("UPDATE {{fleets}} SET `fleet_mess` = 1 WHERE `fleet_id` = {$fleet_row['fleet_id']} LIMIT 1;");
        flt_send_back($mission_data['fleet']);
        return CACHE_FLEET;
    }
    global $lang;
    $Message = sprintf($lang['sys_tran_mess_user'], $mission_data['src_planet']['name'], uni_render_coordinates_href($fleet_row, 'fleet_start_', 3, ''), $destination_planet['name'], uni_render_coordinates_href($fleet_row, 'fleet_end_', 3, ''), $fleet_row['fleet_resource_metal'], $lang['Metal'], $fleet_row['fleet_resource_crystal'], $lang['Crystal'], $fleet_row['fleet_resource_deuterium'], $lang['Deuterium']) . '<br />' . $lang['sys_relocate_mess_user'];
    foreach (sys_unit_str2arr($fleet_row['fleet_array']) as $ship_id => $ship_count) {
        $Message .= $lang['tech'][$ship_id] . ' - ' . $ship_count . '<br />';
    }
    msg_send_simple_message($fleet_row['fleet_owner'], '', $fleet_row['fleet_start_time'], MSG_TYPE_TRANSPORT, $lang['sys_mess_qg'], $lang['sys_stay_mess_stay'], $Message);
    return RestoreFleetToPlanet($fleet_row, false);
}
Ejemplo n.º 12
0
function flt_mission_colonize($mission_data)
{
    $fleet_row = $mission_data['fleet'];
    $src_user_row = $mission_data['src_user'];
    $destination_planet = $mission_data['dst_planet'];
    global $lang;
    $TargetAdress = sprintf($lang['sys_adress_planet'], $fleet_row['fleet_end_galaxy'], $fleet_row['fleet_end_system'], $fleet_row['fleet_end_planet']);
    $fleet_array = sys_unit_str2arr($fleet_row['fleet_array']);
    $TheMessage = $lang['sys_colo_no_colonizer'];
    if ($fleet_array[SHIP_COLONIZER] >= 1) {
        $TheMessage = $lang['sys_colo_notfree'];
        if (!$destination_planet) {
            $iMaxColo = $src_user_row['colonisation_tech'] + 1;
            $iPlanetCount = doquery("SELECT count(*) as `planet_count` FROM `{{planets}}` WHERE `id_owner` = '{$fleet_row['fleet_owner']}' AND `planet_type` = '1';", '', true);
            $iPlanetCount = $iPlanetCount['planet_count'];
            // Can we colonize more planets?
            $TheMessage = $lang['sys_colo_maxcolo'];
            if ($iPlanetCount < $iMaxColo && $iPlanetCount < $GLOBALS['config']->player_max_colonies + 1) {
                // Yes, we can colonize
                $TheMessage = $lang['sys_colo_badpos'];
                $NewOwnerPlanet = uni_create_planet($fleet_row['fleet_end_galaxy'], $fleet_row['fleet_end_system'], $fleet_row['fleet_end_planet'], $fleet_row['fleet_owner'], "{$lang['sys_colo_defaultname']} ¹{$iPlanetCount}");
                if ($NewOwnerPlanet) {
                    $TheMessage = $lang['sys_colo_arrival'] . $TargetAdress . $lang['sys_colo_allisok'];
                    msg_send_simple_message($fleet_row['fleet_owner'], '', $fleet_row['fleet_start_time'], MSG_TYPE_SPY, $lang['sys_colo_mess_from'], $lang['sys_colo_mess_report'], $TheMessage);
                    $fleet_array[SHIP_COLONIZER]--;
                    $fleet_row['fleet_amount']--;
                    $fleet_row['fleet_array'] = sys_unit_arr2str($fleet_array);
                    if ($fleet_row['fleet_array']) {
                        $GLOBALS['debug']->warning("Sending several type of ships with colonizer leads to resource duplication. Resource duplicate X time where X - number of ship type<br>Fleet: {$fleet_row['fleet_array']}", 'Colonization With Fleet', 304);
                    }
                    return RestoreFleetToPlanet($fleet_row, false);
                }
            }
        }
    }
    doquery("UPDATE `{{fleets}}` SET `fleet_mess` = '1' WHERE `fleet_id` = '{$fleet_row['fleet_id']}' LIMIT 1;");
    msg_send_simple_message($fleet_row['fleet_owner'], '', $fleet_row['fleet_start_time'], MSG_TYPE_SPY, $lang['sys_colo_mess_from'], $lang['sys_colo_mess_report'], "{$lang['sys_colo_arrival']}{$TargetAdress}{$TheMessage}");
    return CACHE_FLEET;
}
Ejemplo n.º 13
0
/**
 * MissionCaseSave.php
 *
 * @version 1 By Chlorel for XNova
 */
function MissionCaseSave($FleetRow)
{
    global $lang;
    $QryStartPlanet = "SELECT * FROM {{table}} ";
    $QryStartPlanet .= "WHERE ";
    $QryStartPlanet .= "`galaxy` = '" . $FleetRow['fleet_start_galaxy'] . "' AND ";
    $QryStartPlanet .= "`system` = '" . $FleetRow['fleet_start_system'] . "' AND ";
    $QryStartPlanet .= "`planet` = '" . $FleetRow['fleet_start_planet'] . "' AND ";
    $QryStartPlanet .= "`planet_type` = '" . $FleetRow['fleet_start_type'] . "';";
    $StartPlanet = doquery($QryStartPlanet, 'planets', true);
    $StartName = $StartPlanet['name'];
    $StartOwner = $StartPlanet['id_owner'];
    $QryTargetPlanet = "SELECT * FROM {{table}} ";
    $QryTargetPlanet .= "WHERE ";
    $QryTargetPlanet .= "`galaxy` = '" . $FleetRow['fleet_end_galaxy'] . "' AND ";
    $QryTargetPlanet .= "`system` = '" . $FleetRow['fleet_end_system'] . "' AND ";
    $QryTargetPlanet .= "`planet` = '" . $FleetRow['fleet_end_planet'] . "' AND ";
    $QryTargetPlanet .= "`planet_type` = '" . $FleetRow['fleet_end_type'] . "';";
    $TargetPlanet = doquery($QryTargetPlanet, 'planets', true);
    $TargetName = $TargetPlanet['name'];
    $TargetOwner = $TargetPlanet['id_owner'];
    if ($FleetRow['fleet_mess'] == 0) {
        if ($FleetRow['fleet_start_time'] < time()) {
            $QryUpdateFleet = "UPDATE {{table}} SET ";
            $QryUpdateFleet .= "`fleet_mess` = '1' ";
            $QryUpdateFleet .= "WHERE `fleet_id` = '" . $FleetRow['fleet_id'] . "' ";
            $QryUpdateFleet .= "LIMIT 1 ;";
            doquery($QryUpdateFleet, 'fleets');
        }
    } else {
        if ($FleetRow['fleet_end_time'] < time()) {
            $Message = sprintf($lang['sys_save_mess_back'], $StartName, GetStartAdressLink($FleetRow, ''));
            SendSimpleMessage($StartOwner, '', $FleetRow['fleet_end_time'], 4, $lang['sys_mess_save'], $lang['sys_mess_fleetback'], $Message);
            RestoreFleetToPlanet($FleetRow, true);
            doquery("DELETE FROM {{table}} WHERE fleet_id=" . $FleetRow["fleet_id"], 'fleets');
        }
    }
}
Ejemplo n.º 14
0
function MissionCaseAttack($FleetRow)
{
    global $phpEx, $xnova_root_path, $pricelist, $lang, $resource, $CombatCaps, $game_config;
    includelang('tech');
    includelang('system');
    if ($FleetRow['fleet_mess'] == 0 && $FleetRow['fleet_start_time'] <= time()) {
        if (!isset($CombatCaps[202]['sd'])) {
            message('<font color=red>' . $lang['sys_no_vars'] . '</font><br />(Error: <font color=red>(!isset($pricelist[202][\'sd\']))</font>. Please report this to an admin.)', $lang['sys_error'], 'fleet.php', 15);
        }
        include $xnova_root_path . "includes/functions/MissionCaseEvoAttack.php";
        $strunitsgesamt = $result['lost']['att'] + $result['lost']['def'];
        $user1lostunits = $result['lost']['att'];
        $user1shotunits = $result['lost']['def'];
        $user2lostunits = $result['lost']['def'];
        $user2shotunits = $result['lost']['att'];
        $strtruemmerfeld = $result['debree']['att'][0] + $result['debree']['def'][0] + $result['debree']['att'][1] + $result['debree']['def'][1] + $result['debree']['att'][2] + $result['debree']['def'][2];
        $strtruemmermetal = $result['debree']['att'][0] + $result['debree']['def'][0];
        $strtruemmercrystal = $result['debree']['att'][1] + $result['debree']['def'][1];
        $strtruemmerappolonium = $result['debree']['att'][2] + $result['debree']['def'][2];
        $FleetDebris = $result['debree']['att'][0] + $result['debree']['def'][0] + $result['debree']['att'][1] + $result['debree']['def'][1] + $result['debree']['att'][2] + $result['debree']['def'][2];
        $StrAttackerUnits = sprintf($lang['sys_attacker_lostunits'], $result['lost']['att']);
        $StrDefenderUnits = sprintf($lang['sys_defender_lostunits'], $result['lost']['def']);
        $StrRuins = sprintf($lang['sys_gcdrunits'], $result['debree']['def'][0] + $result['debree']['att'][0], $lang['Metal'], $result['debree']['def'][1] + $result['debree']['att'][1], $lang['Crystal'], $result['debree']['def'][2] + $result['debree']['att'][2], $lang['Appolonium']);
        $DebrisField = $StrAttackerUnits . "<br />" . $StrDefenderUnits . "<br />" . $StrRuins;
        $MoonChance = $FleetDebris / 100000;
        if ($FleetDebris > 2000000) {
            $MoonChance = 20;
        }
        if ($FleetDebris < 100000) {
            $UserChance = 0;
            $ChanceMoon = "";
        } elseif ($FleetDebris >= 100000) {
            $UserChance = mt_rand(1, 100);
            $ChanceMoon = sprintf($lang['sys_moonproba'], $MoonChance);
        }
        if ($UserChance > 0 && $UserChance <= $MoonChance && $targetGalaxy['id_luna'] == 0) {
            $TargetPlanetName = CreateOneMoonRecord($FleetRow['fleet_end_galaxy'], $FleetRow['fleet_end_system'], $FleetRow['fleet_end_planet'], $TargetUserID, $FleetRow['fleet_start_time'], '', $MoonChance);
            $GottenMoon = sprintf($lang['sys_moonbuilt'], $TargetPlanetName, $FleetRow['fleet_end_galaxy'], $FleetRow['fleet_end_system'], $FleetRow['fleet_end_planet']);
            $GottenMoon .= "<br />";
            //Abfrage der Größe des Trümmerfeldes?
            $QrySelectGalaxy = "SELECT * FROM {{table}} ";
            $QrySelectGalaxy .= "WHERE ";
            $QrySelectGalaxy .= "`galaxy` = '" . $FleetRow['fleet_end_galaxy'] . "' AND ";
            $QrySelectGalaxy .= "`system` = '" . $FleetRow['fleet_end_system'] . "' AND ";
            $QrySelectGalaxy .= "`planet` = '" . $FleetRow['fleet_end_planet'] . "' ";
            $QrySelectGalaxy .= "LIMIT 1;";
            $TargetGalaxy = doquery($QrySelectGalaxy, 'galaxy', true);
            // Trümmerfeld wird gelöscht da der Mond aus den Trümmern entstanden ist!.
            $QryUpdateGalaxy = "UPDATE {{table}} SET ";
            $QryUpdateGalaxy .= "`metal` = `metal` - '" . $TargetGalaxy["metal"] . "', ";
            $QryUpdateGalaxy .= "`crystal` = `crystal` - '" . $TargetGalaxy["crystal"] . "',";
            $QryUpdateGalaxy .= "`appolonium` = `appolonium` - '" . $TargetGalaxy["appolonium"] . "' ";
            $QryUpdateGalaxy .= "WHERE ";
            $QryUpdateGalaxy .= "`galaxy` = '" . $FleetRow['fleet_end_galaxy'] . "' AND ";
            $QryUpdateGalaxy .= "`system` = '" . $FleetRow['fleet_end_system'] . "' AND ";
            $QryUpdateGalaxy .= "`planet` = '" . $FleetRow['fleet_end_planet'] . "' ";
            $QryUpdateGalaxy .= "LIMIT 1;";
            doquery($QryUpdateGalaxy, 'galaxy');
        } elseif ($UserChance = 0 or $UserChance > $MoonChance) {
            $GottenMoon = "";
        }
        $OwnedUser = doquery('SELECT * FROM {{table}} WHERE id=' . $FleetRow['fleet_owner'], 'users', true);
        $formatted_cr = formatCR($result, $steal, $MoonChance, $GottenMoon, $totaltime);
        $raport = $formatted_cr['html'];
        $rid = md5($raport);
        $QryInsertRapport = 'INSERT INTO {{table}} SET ';
        $QryInsertRapport .= '`time` = UNIX_TIMESTAMP(), ';
        foreach ($attackFleets as $fleetID => $attacker) {
            $users2[$attacker['user']['id']] = $attacker['user']['id'];
        }
        foreach ($defense as $fleetID => $defender) {
            $users2[$defender['user']['id']] = $defender['user']['id'];
        }
        $QryInsertRapport .= '`owners` = "' . implode(',', $users2) . '", ';
        $QryInsertRapport .= '`rid` = "' . $rid . '", ';
        $QryInsertRapport .= '`raport` = "' . mysql_real_escape_string($raport) . '"';
        doquery($QryInsertRapport, 'rw') or die("Error inserting CR to database" . mysql_error() . "<br /><br />Trying to execute:" . mysql_query());
        $angreifer = $formatted_cr['angreifer'];
        $dpath = !$user["dpath"] ? DEFAULT_SKINPATH : $user["dpath"];
        $rid = md5($raport);
        $QryInserttopkb = "INSERT INTO {{table}} SET ";
        $QryInserttopkb .= "`time` = UNIX_TIMESTAMP(), ";
        $QryInserttopkb .= "`id_owner1` = '" . $FleetRow['fleet_owner'] . "', ";
        $QryInserttopkb .= "`angreifer` = '" . $angreifer . "', ";
        $QryInserttopkb .= "`id_owner2` = '" . $targetUser['id'] . "', ";
        $QryInserttopkb .= "`defender` = '" . $targetUser['username'] . "', ";
        $QryInserttopkb .= "`gesamtunits` = '" . $strunitsgesamt . "', ";
        $QryInserttopkb .= "`gesamttruemmer` = '" . $strtruemmerfeld . "', ";
        $QryInserttopkb .= "`rid` = '" . $rid . "', ";
        $QryInserttopkb .= "`a_zestrzelona` = '" . $a_zestrzelona . "', ";
        $QryInserttopkb .= "`raport` = '" . mysql_real_escape_string($raport) . "',";
        $QryInserttopkb .= "`fleetresult` = '" . $result['won'] . "';";
        doquery("LOCK TABLE {{table}} WRITE", 'topkb');
        doquery($QryInserttopkb, 'topkb');
        doquery("UNLOCK TABLES", '');
        $user1stat = $FleetRow['fleet_owner'];
        $user2stat = $TargetUserID;
        $raport = '<a href # OnClick=\'f( "rw.php?raport=' . $rid . '", "");\' >';
        $raport .= '<center>';
        if ($result['won'] == "a") {
            $raport .= '<font color=\'green\'>';
        } elseif ($result['won'] == "w") {
            $raport .= '<font color=\'orange\'>';
        } elseif ($result['won'] == "r") {
            $raport .= '<font color=\'red\'>';
        }
        $raport .= $lang['sys_mess_attack_report'] . ' [' . $FleetRow['fleet_end_galaxy'] . ':' . $FleetRow['fleet_end_system'] . ':' . $FleetRow['fleet_end_planet'] . '] </font></a><br /><br />';
        $raport .= '<font color=\'red\'>' . $lang['sys_perte_attaquant'] . ': ' . $result['lost']['att'] . '</font>';
        $raport .= '<font color=\'green\'>   ' . $lang['sys_perte_defenseur'] . ': ' . $result['lost']['def'] . '</font><br />';
        $raport .= $lang['sys_gain'] . ' ' . $lang['Metal'] . ':<font color=\'#adaead\'>' . $steal['metal'] . '</font>   ' . $lang['Crystal'] . ':<font color=\'#ef51ef\'>' . $steal['crystal'] . '</font>   ' . $lang['Deuterium'] . ':<font color=\'#f77542\'>' . $steal['deuterium'] . '</font>   ' . $lang['Appolonium'] . ':<font color=\'#ffa07a\'>' . $steal['appolonium'] . '</font><br />';
        $raport .= $lang['sys_debris'] . ' ' . $lang['Metal'] . ': <font color=\'#adaead\'>' . ($result['debree']['att'][0] + $result['debree']['def'][0]) . '</font>   ' . $lang['Crystal'] . ': <font color=\'#ef51ef\'>' . ($result['debree']['att'][1] + $result['debree']['def'][1]) . '</font>   ' . $lang['Appolonium'] . ': <font color=\'#ef51ef\'>' . ($result['debree']['att'][2] + $result['debree']['def'][2]) . '</font><br /></center>';
        SendSimpleMessage($FleetRow['fleet_owner'], '', $FleetRow['fleet_start_time'], 3, $lang['sys_mess_tower'], $lang['sys_mess_attack_report'], $raport);
        $raport2 = '<a href # OnClick=\'f( "rw.php?raport=' . $rid . '", "");\' >';
        $raport2 .= '<center>';
        if ($result['won'] == "a") {
            $raport2 .= '<font color=\'red\'>';
        } elseif ($result['won'] == "w") {
            $raport2 .= '<font color=\'orange\'>';
        } elseif ($result['won'] == "r") {
            $raport2 .= '<font color=\'green\'>';
        }
        $raport2 .= $lang['sys_mess_attack_report'] . ' [' . $FleetRow['fleet_end_galaxy'] . ':' . $FleetRow['fleet_end_system'] . ':' . $FleetRow['fleet_end_planet'] . '] </font></a><br /><br />';
        foreach ($users2 as $id) {
            if ($id != $FleetRow['fleet_owner'] && $id != 0) {
                SendSimpleMessage($id, '', $FleetRow['fleet_start_time'], 3, $lang['sys_mess_tower'], $lang['sys_mess_attack_report'], $raport2);
            }
        }
        $user1 = doquery("SELECT * FROM {{table}} WHERE `id` = '" . $user1stat . "';", 'users');
        while ($user1data = mysql_fetch_assoc($user1)) {
            $strtruemmermetaluser1 = $strtruemmermetal + $user1data['kbmetal'];
            $strtruemmercrystaluser1 = $strtruemmercrystal + $user1data['kbcrystal'];
            $strtruemmerappoloniumuser1 = $strtruemmerappolonium + $user1data['kbappolonium'];
            $user1lostunits = $user1lostunits + $user1data['lostunits'];
            $user1shotunits = $user1shotunits + $user1data['desunits'];
            $user1wons = $user1data['wons'];
            $user1loos = $user1data['loos'];
            $user1draws = $user1data['draws'];
        }
        $user2 = doquery("SELECT * FROM {{table}} WHERE `id` = '" . $user2stat . "';", 'users');
        while ($user2data = mysql_fetch_assoc($user2)) {
            $strtruemmermetaluser2 = $strtruemmermetal + $user2data['kbmetal'];
            $strtruemmercrystaluser2 = $strtruemmercrystal + $user2data['kbcrystal'];
            $strtruemmerappoloniumuser2 = $strtruemmerappolonium + $user2data['kbappolonium'];
            $user2lostunits = $user2lostunits + $user2data['lostunits'];
            $user2shotunits = $user2shotunits + $user2data['desunits'];
            $user2wons = $user2data['wons'];
            $user2loos = $user2data['loos'];
            $user2draws = $user2data['draws'];
        }
        if ($result['won'] == "a") {
            $user1wons = $user1wons + 1;
            $user2loos = $user2loos + 1;
        } elseif ($result['won'] == "w") {
            $user1draws = $user1draws + 1;
            $user2draws = $user2draws + 1;
        } elseif ($result['won'] == "r") {
            $user1loos = $user1loos + 1;
            $user2wons = $user2wons + 1;
        }
        $QryUpdateuserstat = "UPDATE {{table}} SET ";
        $QryUpdateuserstat .= "`wons` = '" . $user1wons . "', ";
        $QryUpdateuserstat .= "`loos` = '" . $user1loos . "', ";
        $QryUpdateuserstat .= "`draws` = '" . $user1draws . "', ";
        $QryUpdateuserstat .= "`kbmetal` = '" . $strtruemmermetaluser1 . "', ";
        $QryUpdateuserstat .= "`kbcrystal` = '" . $strtruemmercrystaluser1 . "', ";
        $QryUpdateuserstat .= "`kbappolonium` = '" . $strtruemmerappoloniumuser1 . "', ";
        $QryUpdateuserstat .= "`lostunits` = '" . $user1lostunits . "', ";
        $QryUpdateuserstat .= "`desunits` = '" . $user1shotunits . "' ";
        $QryUpdateuserstat .= "WHERE ";
        $QryUpdateuserstat .= "`id` = '" . $FleetRow['fleet_owner'] . "';";
        doquery($QryUpdateuserstat, 'users');
        $QryUpdateuser2stat = "UPDATE {{table}} SET ";
        $QryUpdateuser2stat .= "`wons` = '" . $user2wons . "', ";
        $QryUpdateuser2stat .= "`loos` = '" . $user2loos . "', ";
        $QryUpdateuser2stat .= "`draws` = '" . $user2draws . "', ";
        $QryUpdateuser2stat .= "`kbmetal` = '" . $strtruemmermetaluser2 . "', ";
        $QryUpdateuser2stat .= "`kbcrystal` = '" . $strtruemmercrystaluser2 . "', ";
        $QryUpdateuser2stat .= "`kbappolonium` = '" . $strtruemmerappoloniumuser2 . "', ";
        $QryUpdateuser2stat .= "`lostunits` = '" . $user2lostunits . "', ";
        $QryUpdateuser2stat .= "`desunits` = '" . $user2shotunits . "' ";
        $QryUpdateuser2stat .= "WHERE ";
        $QryUpdateuser2stat .= "`id` = '" . $targetUser['id'] . "';";
        doquery($QryUpdateuser2stat, 'users');
        $CurrentUser = doquery("SELECT * FROM {{table}} WHERE id = " . $FleetRow['fleet_owner'], 'users', true);
        $CurrentUserID = $CurrentUser['id'];
        $AddPoint = $CurrentUser['xpraid'] + 1;
        $QryUpdateOfficier = "UPDATE {{table}} SET ";
        $QryUpdateOfficier .= "`xpraid` = '" . $AddPoint . "' ";
        $QryUpdateOfficier .= "WHERE id = '" . $CurrentUserID . "' ";
        $QryUpdateOfficier .= "LIMIT 1 ;";
        doquery($QryUpdateOfficier, 'users');
        $RaidsTotal = $CurrentUser['raids'] + 1;
        if ($result['won'] == "a") {
            $RaidsWin = $CurrentUser['raidswin'] + 1;
            $QryUpdateRaidsCompteur = "UPDATE {{table}} SET ";
            $QryUpdateRaidsCompteur .= "`raidswin` ='" . $RaidsWin . "', ";
            $QryUpdateRaidsCompteur .= "`raids` ='" . $RaidsTotal . "' ";
            $QryUpdateRaidsCompteur .= "WHERE id = '" . $CurrentUserID . "' ";
            $QryUpdateRaidsCompteur .= "LIMIT 1 ;";
            doquery($QryUpdateRaidsCompteur, 'users');
        } elseif ($result['won'] == "r" || $result['won'] == "w") {
            $RaidsLoose = $CurrentUser['raidsloose'] + 1;
            $QryUpdateRaidsCompteur = "UPDATE {{table}} SET ";
            $QryUpdateRaidsCompteur .= "`raidsloose` ='" . $RaidsLoose . "', ";
            $QryUpdateRaidsCompteur .= "`raids` ='" . $RaidsTotal . "' ";
            $QryUpdateRaidsCompteur .= "WHERE id = '" . $CurrentUserID . "' ";
            $QryUpdateRaidsCompteur .= "LIMIT 1 ;";
            doquery($QryUpdateRaidsCompteur, 'users');
        }
    } elseif ($FleetRow['fleet_end_time'] <= time()) {
        $Message = sprintf($lang['sys_tran_mess_angriffback'], $TargetName, GetTargetAdressLink($FleetRow, ''), pretty_number($FleetRow['fleet_resource_metal']), $lang['Metal'], pretty_number($FleetRow['fleet_resource_crystal']), $lang['Crystal'], pretty_number($FleetRow['fleet_resource_deuterium']), $lang['Deuterium'], pretty_number($FleetRow['fleet_resource_appolonium']), $lang['Appolonium']);
        SendSimpleMessage($FleetRow['fleet_owner'], '', $FleetRow['fleet_end_time'], 3, $lang['sys_mess_tower'], $lang['sys_mess_fleetback'], $Message);
        RestoreFleetToPlanet($FleetRow);
        doquery('DELETE FROM {{table}} WHERE `fleet_id`=' . $FleetRow['fleet_id'], 'fleets');
        //Piratenangriff nach Zufallsprinzip
        $zufall = 0;
        $zufall = rand(1, 10);
        if ($zufall == 7) {
            Piratenangriff($FleetRow);
            $zufall = 0;
        }
        // Ende Piratenangriff
    }
}
Ejemplo n.º 15
0
function MissionCaseColonisation($FleetRow)
{
    global $lang, $resource;
    $iPlanetCount = mysql_result(doquery("SELECT count(*) FROM {{table}} WHERE `id_owner` = '" . $FleetRow['fleet_owner'] . "' AND `planet_type` = '1'", 'planets'), 0);
    if ($FleetRow['fleet_mess'] == 0) {
        // Déjà, sommes nous a l'aller ??
        $iGalaxyPlace = mysql_result(doquery("SELECT count(*) FROM {{table}} WHERE `galaxy` = '" . $FleetRow['fleet_end_galaxy'] . "' AND `system` = '" . $FleetRow['fleet_end_system'] . "' AND `planet` = '" . $FleetRow['fleet_end_planet'] . "';", 'galaxy'), 0);
        $TargetAdress = sprintf($lang['sys_adress_planet'], $FleetRow['fleet_end_galaxy'], $FleetRow['fleet_end_system'], $FleetRow['fleet_end_planet']);
        if ($iGalaxyPlace == 0) {
            // Y a personne qui s'y est mis avant que je ne debarque !
            if ($iPlanetCount >= MAX_PLAYER_PLANETS) {
                $TheMessage = $lang['sys_colo_arrival'] . $TargetAdress . $lang['sys_colo_maxcolo'] . MAX_PLAYER_PLANETS . $lang['sys_colo_planet'];
                SendSimpleMessage($FleetRow['fleet_owner'], '', $FleetRow['fleet_start_time'], 0, $lang['sys_colo_mess_from'], $lang['sys_colo_mess_report'], $TheMessage);
                doquery("UPDATE {{table}} SET `fleet_mess` = '1' WHERE `fleet_id` = " . $FleetRow["fleet_id"], 'fleets');
            } else {
                $NewOwnerPlanet = CreateOnePlanetRecord($FleetRow['fleet_end_galaxy'], $FleetRow['fleet_end_system'], $FleetRow['fleet_end_planet'], $FleetRow['fleet_owner'], $lang['sys_colo_defaultname'], false);
                if ($NewOwnerPlanet == true) {
                    $TheMessage = $lang['sys_colo_arrival'] . $TargetAdress . $lang['sys_colo_allisok'];
                    SendSimpleMessage($FleetRow['fleet_owner'], '', $FleetRow['fleet_start_time'], 0, $lang['sys_colo_mess_from'], $lang['sys_colo_mess_report'], $TheMessage);
                    // Verifier ce que contient fleet_array (et le cas et cheant retirer un element '208'
                    if ($FleetRow['fleet_amount'] == 1) {
                        doquery("DELETE FROM {{table}} WHERE fleet_id=" . $FleetRow["fleet_id"], 'fleets');
                    } else {
                        $CurrentFleet = explode(";", $FleetRow['fleet_array']);
                        $NewFleet = "";
                        foreach ($CurrentFleet as $Item => $Group) {
                            if ($Group != '') {
                                $Class = explode(",", $Group);
                                if ($Class[0] == 208) {
                                    if ($Class[1] > 1) {
                                        $NewFleet .= $Class[0] . "," . ($Class[1] - 1) . ";";
                                    }
                                } else {
                                    if ($Class[1] != 0) {
                                        $NewFleet .= $Class[0] . "," . $Class[1] . ";";
                                    }
                                }
                            }
                        }
                        $QryUpdateFleet = "UPDATE {{table}} SET ";
                        $QryUpdateFleet .= "`fleet_array` = '" . $NewFleet . "', ";
                        $QryUpdateFleet .= "`fleet_amount` = `fleet_amount` - 1, ";
                        $QryUpdateFleet .= "`fleet_mess` = '1' ";
                        $QryUpdateFleet .= "WHERE `fleet_id` = '" . $FleetRow["fleet_id"] . "';";
                        doquery($QryUpdateFleet, 'fleets');
                    }
                } else {
                    $TheMessage = $lang['sys_colo_arrival'] . $TargetAdress . $lang['sys_colo_badpos'];
                    SendSimpleMessage($FleetRow['fleet_owner'], '', $FleetRow['fleet_start_time'], 0, $lang['sys_colo_mess_from'], $lang['sys_colo_mess_report'], $TheMessage);
                    doquery("UPDATE {{table}} SET `fleet_mess` = '1' WHERE `fleet_id` = " . $FleetRow["fleet_id"], 'fleets');
                }
            }
        } else {
            // Pas de bol coiffé sur le poteau !
            $TheMessage = $lang['sys_colo_arrival'] . $TargetAdress . $lang['sys_colo_notfree'];
            SendSimpleMessage($FleetRow['fleet_owner'], '', $FleetRow['fleet_end_time'], 0, $lang['sys_colo_mess_from'], $lang['sys_colo_mess_report'], $TheMessage);
            // Mettre a jour la flotte pour qu'effectivement elle revienne !
            doquery("UPDATE {{table}} SET `fleet_mess` = '1' WHERE `fleet_id` = " . $FleetRow["fleet_id"], 'fleets');
        }
    } else {
        // Retour de flotte
        RestoreFleetToPlanet($FleetRow, true);
        doquery("DELETE FROM {{table}} WHERE fleet_id=" . $FleetRow["fleet_id"], 'fleets');
    }
}
Ejemplo n.º 16
0
function MissionCaseSpy($FleetRow)
{
    global $lang, $resource;
    if ($FleetRow['fleet_start_time'] <= time()) {
        $CurrentUser = doquery("SELECT * FROM {{table}} WHERE `id` = '" . $FleetRow['fleet_owner'] . "';", 'users', true);
        $CurrentUserID = $FleetRow['fleet_owner'];
        $QryGetTargetPlanet = "SELECT * FROM {{table}} ";
        $QryGetTargetPlanet .= "WHERE ";
        $QryGetTargetPlanet .= "`galaxy` = '" . $FleetRow['fleet_end_galaxy'] . "' AND ";
        $QryGetTargetPlanet .= "`system` = '" . $FleetRow['fleet_end_system'] . "' AND ";
        $QryGetTargetPlanet .= "`planet` = '" . $FleetRow['fleet_end_planet'] . "' AND ";
        $QryGetTargetPlanet .= "`planet_type` = '" . $FleetRow['fleet_end_type'] . "';";
        $TargetPlanet = doquery($QryGetTargetPlanet, 'planets', true);
        $TargetUserID = $TargetPlanet['id_owner'];
        $CurrentPlanet = doquery("SELECT * FROM {{table}} WHERE `galaxy` = '" . $FleetRow['fleet_start_galaxy'] . "' AND `system` = '" . $FleetRow['fleet_start_system'] . "' AND `planet` = '" . $FleetRow['fleet_start_planet'] . "';", 'planets', true);
        $CurrentSpyLvl = $CurrentUser['spy_tech'];
        $CurrentEspia = $CurrentUser['rpg_espion'];
        $TargetUser = doquery("SELECT * FROM {{table}} WHERE `id` = '" . $TargetUserID . "';", 'users', true);
        $TargetSpyLvl = $TargetUser['spy_tech'];
        $TargetEspia = $TargetUser['rpg_espion'];
        $fleet = explode(";", $FleetRow['fleet_array']);
        $fquery = "";
        // Planeten aktualisieren und erneut auslesen
        // =============================================================================
        $update = PlanetResourceUpdate($TargetUser, $TargetPlanet, $FleetRow['fleet_end_time']);
        $TargetPlanet = doquery($QryGetTargetPlanet, 'planets', true);
        $TargetUser = doquery("SELECT * FROM {{table}} WHERE `id` = '" . $TargetUserID . "';", 'users', true);
        // =============================================================================
        foreach ($fleet as $a => $b) {
            if ($b != '') {
                $a = explode(",", $b);
                $fquery .= "{$resource[$a[0]]}={$resource[$a[0]]} + {$a[1]}, \n";
                if ($FleetRow['fleet_mess'] != "1") {
                    if ($a[0] == "210") {
                        $LS = $a[1];
                        $QryTargetGalaxy = "SELECT * FROM {{table}} WHERE ";
                        $QryTargetGalaxy .= "`galaxy` = '" . $FleetRow['fleet_end_galaxy'] . "' AND ";
                        $QryTargetGalaxy .= "`system` = '" . $FleetRow['fleet_end_system'] . "' AND ";
                        $QryTargetGalaxy .= "`planet` = '" . $FleetRow['fleet_end_planet'] . "';";
                        $TargetGalaxy = doquery($QryTargetGalaxy, 'galaxy', true);
                        $CristalDebris = $TargetGalaxy['crystal'];
                        $SpyToolDebris = $LS * 300;
                        $MaterialsInfo = SpyTarget($TargetPlanet, 0, $lang['sys_spy_maretials']);
                        $Materials = $MaterialsInfo['String'];
                        $PlanetFleetInfo = SpyTarget($TargetPlanet, 1, $lang['sys_spy_fleet']);
                        $PlanetFleet = $Materials;
                        $PlanetFleet .= $PlanetFleetInfo['String'];
                        $PlanetDefenInfo = SpyTarget($TargetPlanet, 2, $lang['sys_spy_defenses']);
                        $PlanetDefense = $PlanetFleet;
                        $PlanetDefense .= $PlanetDefenInfo['String'];
                        $PlanetBuildInfo = SpyTarget($TargetPlanet, 3, $lang['tech'][0]);
                        $PlanetBuildings = $PlanetDefense;
                        $PlanetBuildings .= $PlanetBuildInfo['String'];
                        $TargetTechnInfo = SpyTarget($TargetUser, 4, $lang['tech'][100]);
                        $TargetTechnos = $PlanetBuildings;
                        $TargetTechnos .= $TargetTechnInfo['String'];
                        // Stehende Flotten
                        $TargetAllyInfo = SpyTarget($TargetPlanet, 5, $lang['sys_spy_stayfleets']);
                        $TargetAllyFleet = $TargetTechnos;
                        $TargetAllyFleet .= $TargetAllyInfo['String'];
                        $TargetForce = $PlanetFleetInfo['Count'] * $LS / 4;
                        if ($TargetForce > 100) {
                            $TargetForce = 100;
                        }
                        $TargetChances = rand(0, $TargetForce);
                        $SpyerChances = rand(0, 100);
                        if ($TargetChances >= $SpyerChances) {
                            $DestProba = "<font color=\"red\">" . $lang['sys_mess_spy_destroyed'] . "</font>";
                            //Wenn die Spiosonden abgeschossen wurden werden sie jetzt in der DB gelöscht.
                            doquery("DELETE FROM {{table}} WHERE `fleet_owner` = '" . $TargetUserID . "' AND  `fleet_mission`=6 AND `fleet_mission`='" . $FleetRow['fleet_id'] . "';", 'fleets');
                        } elseif ($TargetChances < $SpyerChances) {
                            $DestProba = sprintf($lang['sys_mess_spy_lostproba'], $TargetChances);
                        }
                        $AttackLink = "<center>";
                        $AttackLink .= "<a href=\"fleet.php?galaxy=" . $FleetRow['fleet_end_galaxy'] . "&system=" . $FleetRow['fleet_end_system'] . "";
                        $AttackLink .= "&planet=" . $FleetRow['fleet_end_planet'] . "&planettype=" . $FleetRow['fleet_end_type'] . "";
                        $AttackLink .= "&target_mission=1";
                        $AttackLink .= " \">" . $lang['type_mission'][1] . "";
                        $AttackLink .= "</a></center>";
                        $MessageEnd = "<center>" . $DestProba . "</center>";
                        $pT = $TargetSpyLvl + $TargetEspia - ($CurrentSpyLvl + $CurrentEspia);
                        $pW = $CurrentSpyLvl + $CurrentEspia - ($TargetSpyLvl + $TargetEspia);
                        if ($TargetSpyLvl + $TargetEspia > $CurrentSpyLvl + $CurrentEspia) {
                            $ST = $LS - pow($pT, 2);
                        }
                        if ($CurrentSpyLvl + $CurrentEspia > $TargetSpyLvl + $TargetEspia) {
                            $ST = $LS + pow($pW, 2);
                        }
                        if ($TargetSpyLvl == $CurrentSpyLvl) {
                            $ST = $CurrentSpyLvl;
                        }
                        if ($ST <= "1") {
                            $SpyMessage = $Materials . "<br />" . $AttackLink . $MessageEnd;
                        }
                        if ($ST == "2") {
                            $SpyMessage = $PlanetFleet . "<br />" . $AttackLink . $MessageEnd;
                        }
                        if ($ST == "4" or $ST == "3") {
                            $SpyMessage = $PlanetDefense . "<br />" . $AttackLink . $MessageEnd;
                        }
                        if ($ST == "5" or $ST == "6") {
                            $SpyMessage = $PlanetBuildings . "<br />" . $AttackLink . $MessageEnd;
                        }
                        if ($ST >= "7") {
                            $SpyMessage = $TargetAllyFleet . "<br />" . $AttackLink . $MessageEnd;
                        }
                        SendSimpleMessage($CurrentUserID, '', $FleetRow['fleet_start_time'], 0, $lang['sys_mess_qg'], $lang['sys_mess_spy_report'], $SpyMessage);
                        $TargetMessage = $lang['sys_mess_spy_ennemyfleet'] . " " . $CurrentPlanet['name'];
                        $TargetMessage .= "<a href=\"galaxy.php?mode=3&galaxy=" . $CurrentPlanet['galaxy'] . "&system=" . $CurrentPlanet['system'] . "\">";
                        $TargetMessage .= "[" . $CurrentPlanet['galaxy'] . ":" . $CurrentPlanet['system'] . ":" . $CurrentPlanet['planet'] . "]</a> ";
                        $TargetMessage .= $lang['sys_mess_spy_seen_at'] . " " . $TargetPlanet['name'];
                        $TargetMessage .= " [" . $TargetPlanet['galaxy'] . ":" . $TargetPlanet['system'] . ":" . $TargetPlanet['planet'] . "].";
                        SendSimpleMessage($TargetUserID, '', $FleetRow['fleet_start_time'], 0, $lang['sys_mess_spy_control'], $lang['sys_mess_spy_activity'], $TargetMessage);
                    }
                    if ($TargetChances >= $SpyerChances) {
                        $QryUpdateGalaxy = "UPDATE {{table}} SET ";
                        $QryUpdateGalaxy .= "`crystal` = `crystal` + '" . (0 + $SpyToolDebris) . "' ";
                        $QryUpdateGalaxy .= "WHERE `id_planet` = '" . $TargetPlanet['id'] . "';";
                        doquery("DELETE FROM {{table}} WHERE `fleet_id` = " . $FleetRow['fleet_id'], 'fleets');
                        doquery($QryUpdateGalaxy, 'galaxy');
                    } else {
                        doquery("UPDATE {{table}} SET `fleet_mess` = '1' WHERE `fleet_id` = '" . $FleetRow['fleet_id'] . "';", 'fleets');
                    }
                }
            } else {
                // Rueckkehr der Spiosonden
                if ($FleetRow['fleet_end_time'] <= time()) {
                    RestoreFleetToPlanet($FleetRow, true);
                    doquery("DELETE FROM {{table}} WHERE `fleet_id` = " . $FleetRow['fleet_id'], 'fleets');
                }
            }
        }
    }
}
Ejemplo n.º 17
0
function MissionCaseAttack($FleetRow)
{
    global $phpEx, $xnova_root_path, $pricelist, $lang, $resource, $CombatCaps, $game_config;
    includelang('tech');
    includelang('system');
    if ($FleetRow['fleet_mess'] == 0 && $FleetRow['fleet_start_time'] <= time()) {
        if (!isset($CombatCaps[202]['sd'])) {
            message('<font color=red>' . $lang['sys_no_vars'] . '</font><br />(Error: <font color=red>(!isset($pricelist[202][\'sd\']))</font>. Please report this to an admin.)', $lang['sys_error'], 'fleet.php', 15);
        }
        //include toms stuff
        include $xnova_root_path . "includes/functions/MissionCaseEvoAttack.php";
        // FROM HERE THE SCRIPT WAS IMPORTED (not TvdW code anymore)
        $FleetDebris = $result['debree']['att'][0] + $result['debree']['def'][0] + $result['debree']['att'][1] + $result['debree']['def'][1];
        $StrAttackerUnits = sprintf($lang['sys_attacker_lostunits'], $result['lost']['att']);
        $StrDefenderUnits = sprintf($lang['sys_defender_lostunits'], $result['lost']['def']);
        $StrRuins = sprintf($lang['sys_gcdrunits'], $result['debree']['def'][0] + $result['debree']['att'][0], $lang['Metal'], $result['debree']['def'][1] + $result['debree']['att'][1], $lang['Crystal']);
        $DebrisField = $StrAttackerUnits . "<br />" . $StrDefenderUnits . "<br />" . $StrRuins;
        $MoonChance = $FleetDebris / 100000;
        if ($FleetDebris > 2000000) {
            $MoonChance = 20;
        }
        if ($FleetDebris < 100000) {
            $UserChance = 0;
            $ChanceMoon = "";
        } elseif ($FleetDebris >= 100000) {
            $UserChance = mt_rand(1, 100);
            $ChanceMoon = sprintf($lang['sys_moonproba'], $MoonChance);
        }
        if ($UserChance > 0 && $UserChance <= $MoonChance && $targetGalaxy['id_luna'] == 0) {
            $TargetPlanetName = CreateOneMoonRecord($FleetRow['fleet_end_galaxy'], $FleetRow['fleet_end_system'], $FleetRow['fleet_end_planet'], $TargetUserID, $FleetRow['fleet_start_time'], '', $MoonChance);
            $GottenMoon = sprintf($lang['sys_moonbuilt'], $TargetPlanetName, $FleetRow['fleet_end_galaxy'], $FleetRow['fleet_end_system'], $FleetRow['fleet_end_planet']);
            $GottenMoon .= "<br />";
        } elseif ($UserChance = 0 or $UserChance > $MoonChance) {
            $GottenMoon = "";
        }
        //MadnessRed CR Creation.
        $formatted_cr = formatCR($result, $steal, $MoonChance, $GottenMoon, $totaltime);
        $raport = $formatted_cr['html'];
        $rid = md5($raport);
        $QryInsertRapport = 'INSERT INTO {{table}} SET ';
        $QryInsertRapport .= '`time` = UNIX_TIMESTAMP(), ';
        foreach ($attackFleets as $fleetID => $attacker) {
            $users2[$attacker['user']['id']] = $attacker['user']['id'];
        }
        foreach ($defense as $fleetID => $defender) {
            $users2[$defender['user']['id']] = $defender['user']['id'];
        }
        $QryInsertRapport .= '`owners` = "' . implode(',', $users2) . '", ';
        $QryInsertRapport .= '`rid` = "' . $rid . '", ';
        $QryInsertRapport .= '`raport` = "' . mysql_real_escape_string($raport) . '"';
        doquery($QryInsertRapport, 'rw') or die("Error inserting CR to database" . mysql_error() . "<br /><br />Trying to execute:" . mysql_query());
        // Colorize report.
        $raport = '<a href # OnClick=\'f( "rw.php?raport=' . $rid . '", "");\' >';
        $raport .= '<center>';
        if ($result['won'] == "a") {
            $raport .= '<font color=\'green\'>';
        } elseif ($result['won'] == "w") {
            $raport .= '<font color=\'orange\'>';
        } elseif ($result['won'] == "r") {
            $raport .= '<font color=\'red\'>';
        }
        $raport .= $lang['sys_mess_attack_report'] . ' [' . $FleetRow['fleet_end_galaxy'] . ':' . $FleetRow['fleet_end_system'] . ':' . $FleetRow['fleet_end_planet'] . '] </font></a><br /><br />';
        $raport .= '<font color=\'red\'>' . $lang['sys_perte_attaquant'] . ': ' . $result['lost']['att'] . '</font>';
        $raport .= '<font color=\'green\'>   ' . $lang['sys_perte_defenseur'] . ': ' . $result['lost']['def'] . '</font><br />';
        $raport .= $lang['sys_gain'] . ' ' . $lang['Metal'] . ':<font color=\'#adaead\'>' . $steal['metal'] . '</font>   ' . $lang['Crystal'] . ':<font color=\'#ef51ef\'>' . $steal['crystal'] . '</font>   ' . $lang['Deuterium'] . ':<font color=\'#f77542\'>' . $steal['deuterium'] . '</font><br />';
        $raport .= $lang['sys_debris'] . ' ' . $lang['Metal'] . ': <font color=\'#adaead\'>' . ($result['debree']['att'][0] + $result['debree']['def'][0]) . '</font>   ' . $lang['Crystal'] . ': <font color=\'#ef51ef\'>' . ($result['debree']['att'][1] + $result['debree']['def'][1]) . '</font><br /></center>';
        SendSimpleMessage($FleetRow['fleet_owner'], '', $FleetRow['fleet_start_time'], 3, $lang['sys_mess_tower'], $lang['sys_mess_attack_report'], $raport);
        // Coloriize report.
        $raport2 = '<a href # OnClick=\'f( "rw.php?raport=' . $rid . '", "");\' >';
        $raport2 .= '<center>';
        if ($result['won'] == "a") {
            $raport2 .= '<font color=\'red\'>';
        } elseif ($result['won'] == "w") {
            $raport2 .= '<font color=\'orange\'>';
        } elseif ($result['won'] == "r") {
            $raport2 .= '<font color=\'green\'>';
        }
        $raport2 .= $lang['sys_mess_attack_report'] . ' [' . $FleetRow['fleet_end_galaxy'] . ':' . $FleetRow['fleet_end_system'] . ':' . $FleetRow['fleet_end_planet'] . '] </font></a><br /><br />';
        foreach ($users2 as $id) {
            if ($id != $FleetRow['fleet_owner'] && $id != 0) {
                SendSimpleMessage($id, '', $FleetRow['fleet_start_time'], 3, $lang['sys_mess_tower'], $lang['sys_mess_attack_report'], $raport2);
            }
        }
        // Ajout du petit point raideur
        $CurrentUser = doquery("SELECT * FROM {{table}} WHERE id = " . $FleetRow['fleet_owner'], 'users', true);
        $CurrentUserID = $CurrentUser['id'];
        $AddPoint = $CurrentUser['xpraid'] + 1;
        $QryUpdateOfficier = "UPDATE {{table}} SET ";
        $QryUpdateOfficier .= "`xpraid` = '" . $AddPoint . "' ";
        $QryUpdateOfficier .= "WHERE id = '" . $CurrentUserID . "' ";
        $QryUpdateOfficier .= "LIMIT 1 ;";
        doquery($QryUpdateOfficier, 'users');
        // Ajout d'un point au compteur de raids
        $RaidsTotal = $CurrentUser['raids'] + 1;
        if ($result['won'] == "a") {
            $RaidsWin = $CurrentUser['raidswin'] + 1;
            $QryUpdateRaidsCompteur = "UPDATE {{table}} SET ";
            $QryUpdateRaidsCompteur .= "`raidswin` ='" . $RaidsWin . "', ";
            $QryUpdateRaidsCompteur .= "`raids` ='" . $RaidsTotal . "' ";
            $QryUpdateRaidsCompteur .= "WHERE id = '" . $CurrentUserID . "' ";
            $QryUpdateRaidsCompteur .= "LIMIT 1 ;";
            doquery($QryUpdateRaidsCompteur, 'users');
        } elseif ($result['won'] == "r" || $result['won'] == "w") {
            $RaidsLoose = $CurrentUser['raidsloose'] + 1;
            $QryUpdateRaidsCompteur = "UPDATE {{table}} SET ";
            $QryUpdateRaidsCompteur .= "`raidsloose` ='" . $RaidsLoose . "', ";
            $QryUpdateRaidsCompteur .= "`raids` ='" . $RaidsTotal . "' ";
            $QryUpdateRaidsCompteur .= "WHERE id = '" . $CurrentUserID . "' ";
            $QryUpdateRaidsCompteur .= "LIMIT 1 ;";
            doquery($QryUpdateRaidsCompteur, 'users');
        }
    } elseif ($FleetRow['fleet_end_time'] <= time()) {
        $Message = sprintf($lang['sys_tran_mess_angriffback'], $TargetName, GetTargetAdressLink($FleetRow, ''), pretty_number($FleetRow['fleet_resource_metal']), $lang['Metal'], pretty_number($FleetRow['fleet_resource_crystal']), $lang['Crystal'], pretty_number($FleetRow['fleet_resource_deuterium']), $lang['Deuterium']);
        SendSimpleMessage($FleetRow['fleet_owner'], '', $FleetRow['fleet_end_time'], 3, $lang['sys_mess_tower'], $lang['sys_mess_fleetback'], $Message);
        RestoreFleetToPlanet($FleetRow);
        doquery('DELETE FROM {{table}} WHERE `fleet_id`=' . $FleetRow['fleet_id'], 'fleets');
    }
}
Ejemplo n.º 18
0
/**
 * Tis file is part of XNova:Legacies
 *
 * @license http://www.gnu.org/licenses/gpl-3.0.txt
 * @see http://www.xnova-ng.org/
 *
 * Copyright (c) 2009-Present, XNova Support Team <http://www.xnova-ng.org>
 * All rights reserved.
 *
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * 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 General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 *
 *                                --> NOTICE <--
 *  This file is part of the core development branch, changing its contents will
 * make you unable to use the automatic updates manager. Please refer to the
 * documentation for further information about customizing XNova.
 *
 */
function MissionCaseRecycling($FleetRow)
{
    global $pricelist, $lang;
    if ($FleetRow["fleet_mess"] == "0") {
        if ($FleetRow['fleet_start_time'] <= time()) {
            $QrySelectGalaxy = "SELECT * FROM {{table}} ";
            $QrySelectGalaxy .= "WHERE ";
            $QrySelectGalaxy .= "`galaxy` = '" . $FleetRow['fleet_end_galaxy'] . "' AND ";
            $QrySelectGalaxy .= "`system` = '" . $FleetRow['fleet_end_system'] . "' AND ";
            $QrySelectGalaxy .= "`planet` = '" . $FleetRow['fleet_end_planet'] . "' ";
            $QrySelectGalaxy .= "LIMIT 1;";
            $TargetGalaxy = doquery($QrySelectGalaxy, 'galaxy', true);
            $FleetRecord = explode(";", $FleetRow['fleet_array']);
            $RecyclerCapacity = 0;
            $OtherFleetCapacity = 0;
            foreach ($FleetRecord as $Item => $Group) {
                if ($Group != '') {
                    $Class = explode(",", $Group);
                    if ($Class[0] == 209) {
                        $RecyclerCapacity += $pricelist[$Class[0]]["capacity"] * $Class[1];
                    } else {
                        $OtherFleetCapacity += $pricelist[$Class[0]]["capacity"] * $Class[1];
                    }
                }
            }
            $IncomingFleetGoods = $FleetRow["fleet_resource_metal"] + $FleetRow["fleet_resource_crystal"] + $FleetRow["fleet_resource_deuterium"];
            if ($IncomingFleetGoods > $OtherFleetCapacity) {
                $RecyclerCapacity -= $IncomingFleetGoods - $OtherFleetCapacity;
            }
            if ($TargetGalaxy["metal"] + $TargetGalaxy["crystal"] <= $RecyclerCapacity) {
                $RecycledGoods["metal"] = $TargetGalaxy["metal"];
                $RecycledGoods["crystal"] = $TargetGalaxy["crystal"];
            } else {
                if ($TargetGalaxy["metal"] > $RecyclerCapacity / 2 and $TargetGalaxy["crystal"] > $RecyclerCapacity / 2) {
                    $RecycledGoods["metal"] = $RecyclerCapacity / 2;
                    $RecycledGoods["crystal"] = $RecyclerCapacity / 2;
                } else {
                    if ($TargetGalaxy["metal"] > $TargetGalaxy["crystal"]) {
                        $RecycledGoods["crystal"] = $TargetGalaxy["crystal"];
                        if ($TargetGalaxy["metal"] > $RecyclerCapacity - $RecycledGoods["crystal"]) {
                            $RecycledGoods["metal"] = $RecyclerCapacity - $RecycledGoods["crystal"];
                        } else {
                            $RecycledGoods["metal"] = $TargetGalaxy["metal"];
                        }
                    } else {
                        $RecycledGoods["metal"] = $TargetGalaxy["metal"];
                        if ($TargetGalaxy["crystal"] > $RecyclerCapacity - $RecycledGoods["metal"]) {
                            $RecycledGoods["crystal"] = $RecyclerCapacity - $RecycledGoods["metal"];
                        } else {
                            $RecycledGoods["crystal"] = $TargetGalaxy["crystal"];
                        }
                    }
                }
            }
            $NewCargo['Metal'] = $FleetRow["fleet_resource_metal"] + $RecycledGoods["metal"];
            $NewCargo['Crystal'] = $FleetRow["fleet_resource_crystal"] + $RecycledGoods["crystal"];
            $NewCargo['Deuterium'] = $FleetRow["fleet_resource_deuterium"];
            $QryUpdateGalaxy = "UPDATE {{table}} SET ";
            $QryUpdateGalaxy .= "`metal` = `metal` - '" . $RecycledGoods["metal"] . "', ";
            $QryUpdateGalaxy .= "`crystal` = `crystal` - '" . $RecycledGoods["crystal"] . "' ";
            $QryUpdateGalaxy .= "WHERE ";
            $QryUpdateGalaxy .= "`galaxy` = '" . $FleetRow['fleet_end_galaxy'] . "' AND ";
            $QryUpdateGalaxy .= "`system` = '" . $FleetRow['fleet_end_system'] . "' AND ";
            $QryUpdateGalaxy .= "`planet` = '" . $FleetRow['fleet_end_planet'] . "' ";
            $QryUpdateGalaxy .= "LIMIT 1;";
            doquery($QryUpdateGalaxy, 'galaxy');
            $Message = sprintf($lang['sys_recy_gotten'], pretty_number($RecycledGoods["metal"]), $lang['Metal'], pretty_number($RecycledGoods["crystal"]), $lang['Crystal']);
            SendSimpleMessage($FleetRow['fleet_owner'], '', $FleetRow['fleet_start_time'], 4, $lang['sys_mess_spy_control'], $lang['sys_recy_report'], $Message);
            doquery("UPDATE {{table}} SET `mnl_exploit` = `mnl_exploit` + '1' WHERE `id` = '" . $FleetRow['fleet_owner'] . "'", 'users');
            $QryUpdateFleet = "UPDATE {{table}} SET ";
            $QryUpdateFleet .= "`fleet_resource_metal` = '" . $NewCargo['Metal'] . "', ";
            $QryUpdateFleet .= "`fleet_resource_crystal` = '" . $NewCargo['Crystal'] . "', ";
            $QryUpdateFleet .= "`fleet_resource_deuterium` = '" . $NewCargo['Deuterium'] . "', ";
            $QryUpdateFleet .= "`fleet_mess` = '1' ";
            $QryUpdateFleet .= "WHERE ";
            $QryUpdateFleet .= "`fleet_id` = '" . $FleetRow['fleet_id'] . "' ";
            $QryUpdateFleet .= "LIMIT 1;";
            doquery($QryUpdateFleet, 'fleets');
        }
    } else {
        if ($FleetRow['fleet_end_time'] <= time()) {
            // Mettre le message de retour de flotte
            $Message = sprintf($lang['sys_tran_mess_owner'], $TargetName, GetTargetAdressLink($FleetRow, ''), pretty_number($FleetRow['fleet_resource_metal']), $lang['Metal'], pretty_number($FleetRow['fleet_resource_crystal']), $lang['Crystal'], pretty_number($FleetRow['fleet_resource_deuterium']), $lang['Deuterium']);
            SendSimpleMessage($FleetRow['fleet_owner'], '', $FleetRow['fleet_end_time'], 4, $lang['sys_mess_spy_control'], $lang['sys_mess_fleetback'], $Message);
            RestoreFleetToPlanet($FleetRow, true);
            doquery("DELETE FROM {{table}} WHERE `fleet_id` = '" . $FleetRow["fleet_id"] . "';", 'fleets');
        }
    }
}
Ejemplo n.º 19
0
/**
 * This file is under the GPL liscence, which must be included with the file under distrobution (license.txt)
 * this file was made by Xnova, edited to support Toms combat engine by Anthony (MadnessReD) [http://madnessred.co.cc/]
 * Do not edit this comment block
 */
function MissionCaseAttack($FleetRow)
{
    global $phpEx, $xnova_root_path, $pricelist, $lang, $resource, $CombatCaps, $game_config;
    //IPMORTANT!!! XNOVA 0.8? or SP1?
    /*
    		If you are using X-Nova 0.8 you must change "$xnova_root_path" to "$ugamela_root_path".
    		
    		/* Below is the origional global, may need to pull some stuff across */
    //global $user, $phpEx, $ugamela_root_path, $pricelist, $lang, $resource, $CombatCaps;
    includelang('tech');
    includelang('system');
    doquery("UPDATE {{table}} SET `small_protection_shield` =1 WHERE `small_protection_shield` >1;", 'planets') or die("Sorting Dome Cheaters:<br />" . mysql_error());
    doquery("UPDATE {{table}} SET `big_protection_shield` =1 WHERE `big_protection_shield` >1;", 'planets') or die("Sorting Dome Cheaters:<br />" . mysql_error());
    /*
    doquery ("UPDATE {{table}} SET `sm_grav_dome` =1 WHERE `sm_grav_dome` >1;", 'planets')
    	or die("Sorting Dome Cheaters:<br />".mysql_error());
    doquery ("UPDATE {{table}} SET `xl_grav_dome` =1 WHERE `xl_grav_dome` >1;", 'planets')
    	or die("Sorting Dome Cheaters:<br />".mysql_error());
    */
    if ($FleetRow['fleet_mess'] == 0 && $FleetRow['fleet_start_time'] <= time()) {
        if (!isset($CombatCaps[202]['sd'])) {
            message('<font color=red>' . $lang['sys_no_vars'] . '</font><br />(Error: <font color=red>(!isset($pricelist[202][\'sd\']))</font>. Please report this to an admin.)', $lang['sys_error'], 'fleet.php', 15);
        }
        //include toms stuff
        include $xnova_root_path . "includes/functions/MissionCaseEvoAttack.php";
        // FROM HERE THE SCRIPT WAS IMPORTED (not TvdW code anymore)
        $FleetDebris = $result['debree']['att'][0] + $result['debree']['def'][0] + $result['debree']['att'][1] + $result['debree']['def'][1];
        $StrAttackerUnits = sprintf($lang['sys_attacker_lostunits'], $result['lost']['att']);
        $StrDefenderUnits = sprintf($lang['sys_defender_lostunits'], $result['lost']['def']);
        $StrRuins = sprintf($lang['sys_gcdrunits'], $result['debree']['def'][0] + $result['debree']['att'][0], $lang['Metal'], $result['debree']['def'][1] + $result['debree']['att'][1], $lang['Crystal']);
        $DebrisField = $StrAttackerUnits . "<br />" . $StrDefenderUnits . "<br />" . $StrRuins;
        $MoonChance = $FleetDebris / 10000000;
        if ($FleetDebris > 35000000) {
            $MoonChance = 35;
        }
        if ($FleetDebris < 10000000) {
            $UserChance = 0;
            $ChanceMoon = "";
        } elseif ($FleetDebris >= 10000000) {
            $UserChance = mt_rand(1, 100);
            $ChanceMoon = sprintf($lang['sys_moonproba'], $MoonChance);
        }
        if ($UserChance > 0 && $UserChance <= $MoonChance && $galenemyrow['id_luna'] == 0) {
            $TargetPlanetName = CreateOneMoonRecord($FleetRow['fleet_end_galaxy'], $FleetRow['fleet_end_system'], $FleetRow['fleet_end_planet'], $TargetUserID, $FleetRow['fleet_start_time'], '', $MoonChance);
            $GottenMoon = sprintf($lang['sys_moonbuilt'], $TargetPlanetName, $FleetRow['fleet_end_galaxy'], $FleetRow['fleet_end_system'], $FleetRow['fleet_end_planet']);
            $GottenMoon .= "<br />";
        } elseif ($UserChance = 0 or $UserChance > $MoonChance) {
            $GottenMoon = "";
        }
        //Start of Raid Points ((Anthony))
        /*
        $att_id = $CurrentUserID;
        $def_id = $TargetUserID;
        $att_dam = $zlom["atakujacy"];
        $def_dam = $zlom["wrog"];
        
        if($def_dam > $att_dam){
        	$att_pts = round(sqrt($def_dam / (pow($att_dam, 2) + 1)));
        	if ($att_pts > 10){
        		$att_pts == 10;
        	}
        	$def_pts = 0;
        	$raid_pts_mess = "The Attacker won ".$att_pts." points";
        }elseif($def_dam < $att_dam){
        	$att_pts = 0;
        	$def_pts = round(sqrt($att_dam / (pow($def_dam, 2) + 1)));
        	if ($def_pts > 10){
        		$def_pts == 10;
        	}
        	$raid_pts_mess = "The Defender won ".$def_pts." points";
        }else{
        	$att_pts = 0;
        	$def_pts = 0;
        }
        
        doquery("UPDATE {{table}} SET `lvl_raid` = `lvl_raid` + '".$att_pts."' WHERE `id` = '".$att_id."' ;", 'users');	
        doquery("UPDATE {{table}} SET `lvl_raid` = `lvl_raid` + '".$def_pts."' WHERE `id` = '".$def_id."' ;", 'users');
        
        doquery("UPDATE {{table}} SET `xpraid` = `xpraid` + '".$def_dam."' WHERE `id` = '".$att_id."' ;", 'users');	
        doquery("UPDATE {{table}} SET `xpraid` = `xpraid` + '".$att_dam."' WHERE `id` = '".$def_id."' ;", 'users');
        doquery("UPDATE {{table}} SET `xploss` = `xploss` + '".$att_dam."' WHERE `id` = '".$att_id."' ;", 'users');	
        doquery("UPDATE {{table}} SET `xploss` = `xploss` + '".$def_dam."' WHERE `id` = '".$def_id."' ;", 'users');
        */
        //End of Raid Points
        //MadnessRed CR Creation.
        $formatted_cr = formatCR($result, $steal, $MoonChance, $GottenMoon, $totaltime);
        $raport = $formatted_cr['html'];
        $rid = md5($raport);
        $QryInsertRapport = 'INSERT INTO {{table}} SET ';
        $QryInsertRapport .= '`time` = UNIX_TIMESTAMP(), ';
        foreach ($attackFleets as $fleetID => $attacker) {
            $users2[$attacker['user']['id']] = $attacker['user']['id'];
        }
        foreach ($defense as $fleetID => $defender) {
            $users2[$defender['user']['id']] = $defender['user']['id'];
        }
        $QryInsertRapport .= '`owners` = "' . implode(',', $users2) . '", ';
        $QryInsertRapport .= '`rid` = "' . $rid . '", ';
        $QryInsertRapport .= '`raport` = "' . mysql_real_escape_string($raport) . '"';
        doquery($QryInsertRapport, 'rw') or die("Error inserting CR to database" . mysql_error() . "<br /><br />Trying to execute:" . mysql_query());
        // Colorize report.
        $raport = '<a href # OnClick=\'f( "rw.php?raport=' . $rid . '", "");\' >';
        $raport .= '<center>';
        if ($result['won'] == 1) {
            $raport .= '<font color=\'green\'>';
        } elseif ($result['won'] == 0) {
            $raport .= '<font color=\'orange\'>';
        } elseif ($result['won'] == 2) {
            $raport .= '<font color=\'red\'>';
        }
        $raport .= $lang['sys_mess_attack_report'] . ' [' . $FleetRow['fleet_end_galaxy'] . ':' . $FleetRow['fleet_end_system'] . ':' . $FleetRow['fleet_end_planet'] . '] </font></a><br /><br />';
        $raport .= '<font color=\'red\'>' . $lang['sys_perte_attaquant'] . ': ' . $result['lost']['att'] . '</font>';
        $raport .= '<font color=\'green\'>   ' . $lang['sys_perte_defenseur'] . ': ' . $result['lost']['def'] . '</font><br />';
        $raport .= $lang['sys_gain'] . ' ' . $lang['Metal'] . ':<font color=\'#adaead\'>' . $steal['metal'] . '</font>   ' . $lang['Crystal'] . ':<font color=\'#ef51ef\'>' . $steal['crystal'] . '</font>   ' . $lang['Deuterium'] . ':<font color=\'#f77542\'>' . $steal['deuterium'] . '</font><br />';
        $raport .= $lang['sys_debris'] . ' ' . $lang['Metal'] . ': <font color=\'#adaead\'>' . ($result['debree']['att'][0] + $result['debree']['def'][0]) . '</font>   ' . $lang['Crystal'] . ': <font color=\'#ef51ef\'>' . ($result['debree']['att'][1] + $result['debree']['def'][1]) . '</font><br /></center>';
        SendSimpleMessage($FleetRow['fleet_owner'], '', $FleetRow['fleet_start_time'], 3, $lang['sys_mess_tower'], $lang['sys_mess_attack_report'], $raport);
        // Coloriize report.
        $raport2 = '<a href # OnClick=\'f( "rw.php?raport=' . $rid . '", "");\' >';
        $raport2 .= '<center>';
        if ($result['won'] == 1) {
            $raport2 .= '<font color=\'green\'>';
        } elseif ($result['won'] == 0) {
            $raport2 .= '<font color=\'orange\'>';
        } elseif ($result['won'] == 2) {
            $raport2 .= '<font color=\'red\'>';
        }
        $raport2 .= $lang['sys_mess_attack_report'] . ' [' . $FleetRow['fleet_end_galaxy'] . ':' . $FleetRow['fleet_end_system'] . ':' . $FleetRow['fleet_end_planet'] . '] </font></a><br /><br />';
        foreach ($users2 as $id) {
            if ($id != $FleetRow['fleet_owner'] && $id != 0) {
                SendSimpleMessage($id, '', $FleetRow['fleet_start_time'], 3, $lang['sys_mess_tower'], $lang['sys_mess_attack_report'], $raport2);
            }
        }
        // Ajout du petit point raideur
        $AddPoint = $CurrentUser['xpraid'] + 1;
        $QryUpdateOfficier = "UPDATE {{table}} SET ";
        $QryUpdateOfficier .= "`xpraid` = '" . $AddPoint . "' ";
        $QryUpdateOfficier .= "WHERE id = '" . $CurrentUserID . "' ";
        $QryUpdateOfficier .= "LIMIT 1 ;";
        doquery($QryUpdateOfficier, 'users');
        // Ajout d'un point au compteur de raids
        $RaidsTotal = $CurrentUser['raids'] + 1;
        if ($FleetResult == "a") {
            $RaidsWin = $CurrentUser['raidswin'] + 1;
            $QryUpdateRaidsCompteur = "UPDATE {{table}} SET ";
            $QryUpdateRaidsCompteur .= "`raidswin` ='" . $RaidsWin . "', ";
            $QryUpdateRaidsCompteur .= "`raids` ='" . $RaidsTotal . "' ";
            $QryUpdateRaidsCompteur .= "WHERE id = '" . $CurrentUserID . "' ";
            $QryUpdateRaidsCompteur .= "LIMIT 1 ;";
            doquery($QryUpdateRaidsCompteur, 'users');
        } elseif ($FleetResult == "r" || $FleetResult == "w") {
            $RaidsLoose = $CurrentUser['raidsloose'] + 1;
            $QryUpdateRaidsCompteur = "UPDATE {{table}} SET ";
            $QryUpdateRaidsCompteur .= "`raidsloose` ='" . $RaidsLoose . "', ";
            $QryUpdateRaidsCompteur .= "`raids` ='" . $RaidsTotal . "' ";
            $QryUpdateRaidsCompteur .= "WHERE id = '" . $CurrentUserID . "' ";
            $QryUpdateRaidsCompteur .= "LIMIT 1 ;";
            doquery($QryUpdateRaidsCompteur, 'users');
        }
    } elseif ($FleetRow['fleet_end_time'] <= time()) {
        RestoreFleetToPlanet($FleetRow);
        doquery('DELETE FROM {{table}} WHERE `fleet_id`=' . $FleetRow['fleet_id'], 'fleets');
    }
}
Ejemplo n.º 20
0
function flt_cache_fleet($fleet_row, &$flt_user_cache, &$flt_planet_cache, &$flt_fleet_cache, &$flt_event_cache, $cache_mode)
{
    global $sn_data;
    $time_now = $GLOBALS['time_now'];
    // Empty $fleet_row - no chance to know anything about it. By design it should never triggered but let it be
    if (!$fleet_row) {
        return false;
    }
    // $fleet_row is not an array - may be ONLY fleet ID. Getting $fleet_row from DB by ID
    if (!is_array($fleet_row)) {
        $fleet_row_id = $fleet_row;
        // Checking if it is cached
        if (isset($flt_fleet_cache[$fleet_row_id])) {
            $fleet_row = $flt_fleet_cache[$fleet_row_id];
        } else {
            $fleet_row = doquery("SELECT * FROM {{fleets}} WHERE `fleet_id` = '{$fleet_row_id}' LIMIT 1 FOR UPDATE;", '', true);
        }
    } else {
        $fleet_row_id = $fleet_row['fleet_id'];
    }
    // $fleet_row is false - not existing DB record
    if (!$fleet_row) {
        $flt_fleet_cache[$fleet_row_id] = $fleet_row;
        return false;
    }
    if ($fleet_row['fleet_mess'] != 0) {
        // Fleet is returning to source
        if ($fleet_row['fleet_end_time'] <= $time_now) {
            // Fleet is arrived
            // Restoring fleet to planet
            RestoreFleetToPlanet($fleet_row, true);
            // Tagging record for fleet as not existing in DB
            $flt_fleet_cache[$fleet_row['fleet_id']] = false;
            // Removing fleet source planet record from cache
            unset($flt_planet_cache[flt_planet_hash($fleet_row, 'fleet_start_')]);
            // Changed data will be recached later
        }
        return false;
    } elseif ($fleet_row['fleet_start_time'] > $time_now || $fleet_row['fleet_end_stay'] && $fleet_row['fleet_end_stay'] > $time_now) {
        return false;
    }
    if (!isset($flt_fleet_cache[$fleet_row_id])) {
        $flt_fleet_cache[$fleet_row_id] = $fleet_row;
    }
    if ($fleet_row['fleet_mission'] == MT_RECYCLE || $fleet_row['fleet_mission'] == MT_COLONIZE) {
        $fleet_row['fleet_end_type'] = PT_PLANET;
    } elseif ($fleet_row['fleet_mission'] == MT_DESTROY) {
        $fleet_row['fleet_end_type'] = PT_MOON;
    }
    // On CACHE_EVENT we will cache only fleet to reduce row lock rate
    if (($cache_mode & CACHE_EVENT) == CACHE_EVENT) {
        $flt_event_cache[] = array('fleet_id' => $fleet_row['fleet_id'], 'fleet_time' => $fleet_row['fleet_time'], 'src_planet_hash' => flt_planet_hash($fleet_row, 'fleet_start_'), 'src_user_id' => $fleet_row['fleet_owner'], 'dst_planet_hash' => flt_planet_hash($fleet_row, 'fleet_end_'), 'dst_user_id' => $fleet_row['fleet_target_owner']);
    } else {
        $mission_data = $sn_data['groups']['missions'][$fleet_row['fleet_mission']];
        // А здесь надо проверять, какие нужны данные и кэшировать только их
        $source = array('planet_hash' => '', 'user_id' => 0);
        if ($mission_data['src_planet']) {
            flt_cache_planet(array('galaxy' => $fleet_row['fleet_start_galaxy'], 'system' => $fleet_row['fleet_start_system'], 'planet' => $fleet_row['fleet_start_planet'], 'planet_type' => $fleet_row['fleet_start_type']), $flt_user_cache, $flt_planet_cache);
        } elseif ($mission_data['src_user']) {
            flt_cache_user($fleet_row['fleet_owner'], $flt_user_cache);
        }
        $destination = array('planet_hash' => '', 'user_id' => 0);
        if ($mission_data['dst_planet']) {
            $destination = flt_cache_planet(array('galaxy' => $fleet_row['fleet_end_galaxy'], 'system' => $fleet_row['fleet_end_system'], 'planet' => $fleet_row['fleet_end_planet'], 'planet_type' => $fleet_row['fleet_end_type']), $flt_user_cache, $flt_planet_cache);
        } elseif ($mission_data['dst_user']) {
            flt_cache_user($fleet_row['fleet_target_owner'], $flt_user_cache);
        }
    }
    return true;
}
Ejemplo n.º 21
0
/**
* MissionCaseDestruction.php
* @Licence GNU (GPL)
* @version 2.2
* @copyright 2009 
* @Team Space Beginner
*/
function MissionCaseDestruction($FleetRow)
{
    global $phpEx, $xnova_root_path, $pricelist, $lang, $resource, $CombatCaps, $game_config, $user;
    includeLang('system');
    if ($FleetRow['fleet_mess'] == 0 && $FleetRow['fleet_start_time'] <= time()) {
        if (!isset($CombatCaps[202]['sd'])) {
            message('<font color=red>' . $lang['sys_no_vars'] . '</font><br />(Error: <font color=red>(!isset($pricelist[202][\'sd\']))</font>. Please report this to an admin.)', $lang['sys_error'], 'fleet.php', 15);
        }
        $targetPlanet = doquery("SELECT * FROM {{table}} WHERE `galaxy` = " . $FleetRow['fleet_end_galaxy'] . " AND `system` = " . $FleetRow['fleet_end_system'] . " AND `planet_type` = " . $FleetRow['fleet_end_type'] . " AND `planet` = " . $FleetRow['fleet_end_planet'] . ";", 'planets', true);
        // if (!isset($targetPlanet['id'])) {
        if ($FleetRow['fleet_group'] > 0) {
            //MadnessRed Code
            doquery("DELETE FROM {{table}} WHERE id =" . $FleetRow['fleet_group'], 'aks');
            doquery("UPDATE {{table}} SET fleet_mess=1 WHERE fleet_group=" . $FleetRow['fleet_group'], 'fleets');
        } else {
            doquery("UPDATE {{table}} SET fleet_mess=1 WHERE fleet_id=" . $FleetRow['fleet_id'], 'fleets');
        }
        // return;
        //}
        // Mise à jour de la cible ...
        // On recharge les infos qui viennent d'être mises à jour
        $targetGalaxy = doquery('SELECT * FROM {{table}} WHERE `galaxy` = ' . $FleetRow['fleet_end_galaxy'] . ' AND `system` = ' . $FleetRow['fleet_end_system'] . ' AND `planet` = ' . $FleetRow['fleet_end_planet'] . ';', 'galaxy', true);
        $targetUser = doquery('SELECT * FROM {{table}} WHERE id=' . $targetPlanet['id_owner'], 'users', true);
        $TargetUserID = $targetUser['id'];
        PlanetResourceUpdate($targetUser, $targetPlanet, time());
        // AG : Mettre toutes les flottes dans un tableau
        $attackFleets = array();
        // De forme : attackFleets[id] = array('fleet' => $FleetRow, 'user' => $user);
        if ($FleetRow['fleet_group'] != 0) {
            $fleets = doquery('SELECT * FROM {{table}} WHERE fleet_group=' . $FleetRow['fleet_group'], 'fleets');
            while ($fleet = mysql_fetch_assoc($fleets)) {
                $attackFleets[$fleet['fleet_id']]['fleet'] = $fleet;
                $attackFleets[$fleet['fleet_id']]['user'] = doquery('SELECT * FROM {{table}} WHERE id =' . $fleet['fleet_owner'], 'users', true);
                $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[$FleetRow['fleet_id']]['fleet'] = $FleetRow;
            $attackFleets[$FleetRow['fleet_id']]['user'] = doquery('SELECT * FROM {{table}} WHERE id=' . $FleetRow['fleet_owner'], 'users', true);
            $attackFleets[$FleetRow['fleet_id']]['detail'] = array();
            $temp = explode(';', $FleetRow['fleet_array']);
            foreach ($temp as $temp2) {
                $temp2 = explode(',', $temp2);
                if ($temp2[0] < 100) {
                    continue;
                }
                if (!isset($attackFleets[$FleetRow['fleet_id']]['detail'][$temp2[0]])) {
                    $attackFleets[$FleetRow['fleet_id']]['detail'][$temp2[0]] = 0;
                }
                $attackFleets[$FleetRow['fleet_id']]['detail'][$temp2[0]] += $temp2[1];
            }
        }
        $defense = array();
        $def = doquery('SELECT * FROM {{table}} WHERE `fleet_end_galaxy` = ' . $FleetRow['fleet_end_galaxy'] . ' AND `fleet_end_system` = ' . $FleetRow['fleet_end_system'] . ' AND `fleet_end_type` = ' . $FleetRow['fleet_end_type'] . ' AND `fleet_end_planet` = ' . $FleetRow['fleet_end_planet'] . ' AND fleet_start_time<' . time() . ' AND fleet_end_stay>=' . time(), 'fleets');
        while ($defRow = mysql_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'] = doquery('SELECT * FROM {{table}} WHERE id=' . $defRow['fleet_owner'], 'users', true);
            }
        }
        $defense[0]['def'] = array();
        $defense[0]['user'] = $targetUser;
        for ($i = 200; $i < 500; $i++) {
            if (isset($resource[$i]) && isset($targetPlanet[$resource[$i]])) {
                $defense[0]['def'][$i] = $targetPlanet[$resource[$i]];
            }
        }
        $start = microtime(true);
        $result = calculateAttack($attackFleets, $defense);
        $totaltime = microtime(true) - $start;
        // Mise a jour du champ de ruine devant la planete attaquée
        $QryUpdateGalaxy = "UPDATE {{table}} SET ";
        $QryUpdateGalaxy .= "`metal` = `metal` +'" . ($result['debree']['att'][0] + $result['debree']['def'][0]) . "', ";
        $QryUpdateGalaxy .= "`crystal` = `crystal` + '" . ($result['debree']['att'][1] + $result['debree']['def'][1]) . "', ";
        $QryUpdateGalaxy .= "`appolonium` = `appolonium` + '" . ($result['debree']['att'][2] + $result['debree']['def'][2]) . "' ";
        $QryUpdateGalaxy .= "WHERE ";
        $QryUpdateGalaxy .= "`galaxy` = '" . $FleetRow['fleet_end_galaxy'] . "' AND ";
        $QryUpdateGalaxy .= "`system` = '" . $FleetRow['fleet_end_system'] . "' AND ";
        $QryUpdateGalaxy .= "`planet` = '" . $FleetRow['fleet_end_planet'] . "' ";
        $QryUpdateGalaxy .= "LIMIT 1;";
        doquery($QryUpdateGalaxy, 'galaxy');
        //         Mise à jour du CDR en table galaxy
        //        doquery('UPDATE {{table}} SET metal=metal+'.($result['debree']['att'][0]+$result['debree']['def'][0]).' , crystal=crystal+'.($result['debree']['att'][1]+$result['debree']['def'][1]).' WHERE `galaxy` = '. $FleetRow['fleet_end_galaxy'] .' AND `system` = '. $FleetRow['fleet_end_system'] .' AND `planet` = '. $FleetRow['fleet_end_planet'],'galaxy');
        $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, 'appolonium' => 0);
        switch ($result['won']) {
            case "a":
                // Calculons la capacité de transpor du restant de flotte après combat
                $max_resources = 0;
                foreach ($attackFleets[$FleetRow['fleet_id']]['detail'] as $Element => $amount) {
                    $max_resources += $pricelist[$Element]['capacity'] * $amount;
                }
                if ($max_resources > 0) {
                    $metal = $targetPlanet['metal'] / 2;
                    $crystal = $targetPlanet['crystal'] / 2;
                    $deuter = $targetPlanet['deuterium'] / 2;
                    $appolonium = $targetPlanet['appolonium'] / 2;
                    if ($appolonium > $max_resources / 4) {
                        $steal['appolonium'] = $max_resources / 4;
                        $max_resources -= $steal['appolonium'];
                    } else {
                        $steal['appolonium'] = $appolonium;
                        $max_resources -= $steal['appolonium'];
                    }
                    if ($deuter > $max_resources / 3) {
                        $steal['deuterium'] = $max_resources / 3;
                        $max_resources -= $steal['deuterium'];
                    } else {
                        $steal['deuterium'] = $deuter;
                        $max_resources -= $steal['deuterium'];
                    }
                    if ($crystal > $max_resources / 2) {
                        $steal['crystal'] = $max_resources / 2;
                        $max_resources -= $steal['crystal'];
                    } else {
                        $steal['crystal'] = $crystal;
                        $max_resources -= $steal['crystal'];
                    }
                    if ($metal > $max_resources) {
                        $steal['metal'] = $max_resources;
                        $max_resources = $max_resources - $steal['metal'];
                    } else {
                        $steal['metal'] = $metal;
                        $max_resources -= $steal['metal'];
                    }
                }
                $steal = array_map('round', $steal);
                // Mise à jour de la flotte après pillage
                $QryUpdateFleet = 'UPDATE {{table}} SET ';
                $QryUpdateFleet .= '`fleet_resource_metal` = `fleet_resource_metal` + ' . $steal['metal'] . ', ';
                $QryUpdateFleet .= '`fleet_resource_crystal` = `fleet_resource_crystal` +' . $steal['crystal'] . ', ';
                $QryUpdateFleet .= '`fleet_resource_deuterium` = `fleet_resource_deuterium` +' . $steal['deuterium'] . ', ';
                $QryUpdateFleet .= '`fleet_resource_appolonium` = `fleet_resource_appolonium` +' . $steal['appolonium'] . ' ';
                $QryUpdateFleet .= 'WHERE fleet_id = ' . $FleetRow['fleet_id'] . ' ';
                $QryUpdateFleet .= 'LIMIT 1 ;';
                doquery($QryUpdateFleet, 'fleets');
                // Mise à jour flotte et planètes
                foreach ($attackFleets as $fleetID => $attacker) {
                    // Flottes attaquantes
                    $fleetArray = '';
                    $totalCount = 0;
                    foreach ($attacker['detail'] as $element => $amount) {
                        if ($amount) {
                            $fleetArray .= $element . ',' . $amount . ';';
                        }
                        $totalCount += $amount;
                    }
                    if ($totalCount <= 0) {
                        doquery('DELETE FROM {{table}} WHERE `fleet_id`=' . $fleetID, 'fleets');
                    } else {
                        doquery('UPDATE {{table}} SET fleet_array="' . substr($fleetArray, 0, -1) . '", fleet_amount=' . $totalCount . ', fleet_mess=1 WHERE fleet_id=' . $fleetID, 'fleets');
                    }
                }
                foreach ($defense as $fleetID => $defender) {
                    // Flottes et Défenses de la cible
                    if ($fleetID != 0) {
                        $fleetArray = '';
                        $totalCount = 0;
                        foreach ($defender['def'] as $element => $amount) {
                            if ($amount) {
                                $fleetArray .= $element . ',' . $amount . ';';
                            }
                            $totalCount += $amount;
                        }
                        if ($totalCount <= 0) {
                            doquery('DELETE FROM {{table}} WHERE `fleet_id`=' . $fleetID, 'fleets');
                        } else {
                            doquery('UPDATE {{table}} SET fleet_array="' . $fleetArray . '", fleet_amount=' . $totalCount . ', fleet_mess=1 WHERE fleet_id=' . $fleetID, 'fleets');
                        }
                    } else {
                        $fleetArray = '';
                        $totalCount = 0;
                        foreach ($defender['def'] as $element => $amount) {
                            $fleetArray .= '`' . $resource[$element] . '`=' . $amount . ', ';
                        }
                        // Mise a jour de l'enregistrement de la planete attaquée
                        $QryUpdateTarget = "UPDATE {{table}} SET ";
                        $QryUpdateTarget .= $fleetArray;
                        $QryUpdateTarget .= "`metal` = `metal` - '" . $steal['metal'] . "', ";
                        $QryUpdateTarget .= "`crystal` = `crystal` - '" . $steal['crystal'] . "', ";
                        $QryUpdateTarget .= "`deuterium` = `deuterium` - '" . $steal['deuterium'] . "', ";
                        $QryUpdateTarget .= "`appolonium` = `appolonium` - '" . $steal['appolonium'] . "' ";
                        $QryUpdateTarget .= "WHERE ";
                        $QryUpdateTarget .= "`galaxy` = '" . $FleetRow['fleet_end_galaxy'] . "' AND ";
                        $QryUpdateTarget .= "`system` = '" . $FleetRow['fleet_end_system'] . "' AND ";
                        $QryUpdateTarget .= "`planet` = '" . $FleetRow['fleet_end_planet'] . "' AND ";
                        $QryUpdateTarget .= "`planet_type` = '" . $FleetRow['fleet_end_type'] . "' ";
                        $QryUpdateTarget .= "LIMIT 1;";
                        doquery($QryUpdateTarget, 'planets');
                    }
                }
                //Mondzerstörungswarscheinlichkeitsberechnung gemäß Owiki
                $destructionl1 = 100 - sqrt($targetPlanet['diameter']);
                if ($attackFleets[$FleetRow['fleet_id']]['detail'][218] > 0) {
                    $destructionl21 = $destructionl1 * round(sqrt($attackFleets[$FleetRow['fleet_id']]['detail'][218] / MAX_ST));
                    $destructionl2 = $destructionl21 / 1;
                } else {
                    $destructionl21 = $destructionl1 * round(sqrt($attackFleets[$FleetRow['fleet_id']]['detail'][214] / MAX_RIP));
                    $destructionl2 = $destructionl21 / 1;
                }
                if ($destructionl2 > 100) {
                    $chance = '100';
                } elseif ($destructionl2 < 0) {
                    $chance = '0';
                } else {
                    $chance = round($destructionl2);
                    // En pourcentage
                }
                $tirage = mt_rand(0, 100);
                $probalune = sprintf($lang['sys_destruc_lune'], $chance);
                if ($tirage <= $chance) {
                    //destruction de la lune dabord dans la liste des planetes puis dans la liste des lunes et enfin dans la galaxie
                    doquery("DELETE FROM {{table}} WHERE `id` = '" . $targetPlanet['id'] . "';", 'planets');
                    //$Qrydestructionlune .= ";";
                    $Qrydestructionlune = "DELETE FROM {{table}} ";
                    $Qrydestructionlune .= "WHERE ";
                    $Qrydestructionlune .= "`galaxy` = '" . $FleetRow['fleet_end_galaxy'] . "' AND ";
                    $Qrydestructionlune .= "`system` = '" . $FleetRow['fleet_end_system'] . "' AND ";
                    $Qrydestructionlune .= "`lunapos` = '" . $FleetRow['fleet_end_planet'] . "' ";
                    $Qrydestructionlune .= "LIMIT 1 ;";
                    doquery($Qrydestructionlune, 'lunas');
                    //$Qrydestructionlune2 .= ";";
                    $Qrydestructionlune2 = "UPDATE {{table}} SET ";
                    $Qrydestructionlune2 .= "`id_luna` = '0' ";
                    $Qrydestructionlune2 .= "WHERE ";
                    $Qrydestructionlune2 .= "`galaxy` = '" . $FleetRow['fleet_end_galaxy'] . "' AND ";
                    $Qrydestructionlune2 .= "`system` = '" . $FleetRow['fleet_end_system'] . "' AND ";
                    $Qrydestructionlune2 .= "`planet` = '" . $FleetRow['fleet_end_planet'] . "' ";
                    $Qrydestructionlune2 .= "LIMIT 1 ;";
                    doquery($Qrydestructionlune2, 'galaxy');
                    //la lune est detruite, alors on redirige les flottes sur la planete
                    $QryFleetsFrom = doquery("SELECT * FROM {{table}} WHERE   \n\t\t\t\t`fleet_start_galaxy` = '" . $FleetRow['fleet_end_galaxy'] . "' AND\n\t\t\t\t`fleet_start_system` = '" . $FleetRow['fleet_end_system'] . "' AND\n\t\t\t\t`fleet_start_planet` = '" . $FleetRow['fleet_end_planet'] . "' AND\n\t\t\t\t`fleet_start_type` = '3';", 'fleets');
                    while ($FromMoonFleets = mysql_fetch_array($QryFleetsFrom)) {
                        doquery("UPDATE {{table}} SET `fleet_start_type` = '1' WHERE `fleet_id` = '" . $FromMoonFleets['fleet_id'] . "';", 'fleets');
                    }
                    $QryFleetsTo = doquery("SELECT * FROM {{table}} WHERE   \n\t\t\t\t`fleet_end_galaxy` = '" . $FleetRow['fleet_end_galaxy'] . "' AND\n\t\t\t\t`fleet_end_system` = '" . $FleetRow['fleet_end_system'] . "' AND\n\t\t\t\t`fleet_end_planet` = '" . $FleetRow['fleet_end_planet'] . "' AND\n\t\t\t\t`fleet_end_type` = '3';", 'fleets');
                    while ($ToMoonFleets = mysql_fetch_array($QryFleetsTo)) {
                        doquery("UPDATE {{table}} SET `fleet_end_type` = '1' WHERE `fleet_id` = '" . $ToMoonFleets['fleet_id'] . "';", 'fleets');
                    }
                    // Mond Explodiert!?Wo bleiben die Trümmer vom Mond
                    $metallmond = 0;
                    $kristallmond = 0;
                    $appolonium = 0;
                    // Berechnung des Trümmerfeldes
                    $metallmond = round($targetPlanet['diameter'] * 625);
                    $kristallmond = round($targetPlanet['diameter'] * 625);
                    // Berechnung Appollonium
                    $zuwert = mt_rand(100, 300);
                    $appolonium = round($targetPlanet['diameter'] * $zuwert);
                    // Trümmerfeld go's Galaxy
                    $QryUpdateGalaxy = "UPDATE {{table}} SET ";
                    $QryUpdateGalaxy .= "`metal` = `metal` + '" . $metallmond . "', ";
                    $QryUpdateGalaxy .= "`crystal` = `crystal` + '" . $kristallmond . "', ";
                    $QryUpdateGalaxy .= "`appolonium` = `appolonium` + '" . $appolonium . "' ";
                    $QryUpdateGalaxy .= "WHERE ";
                    $QryUpdateGalaxy .= "`galaxy` = '" . $FleetRow['fleet_end_galaxy'] . "' AND ";
                    $QryUpdateGalaxy .= "`system` = '" . $FleetRow['fleet_end_system'] . "' AND ";
                    $QryUpdateGalaxy .= "`planet` = '" . $FleetRow['fleet_end_planet'] . "' ";
                    $QryUpdateGalaxy .= "LIMIT 1;";
                    doquery($QryUpdateGalaxy, 'galaxy');
                    //maintenant on va verifier si la vue du joueur n est pas calee sur la lune qui est detruite
                    if ($targetUser['current_planet'] == $targetPlanet['id']) {
                        $QryPlanet = "SELECT * FROM {{table}} ";
                        $QryPlanet .= "WHERE ";
                        $QryPlanet .= "`galaxy` = '" . $FleetRow['fleet_end_galaxy'] . "' AND ";
                        $QryPlanet .= "`system` = '" . $FleetRow['fleet_end_system'] . "' AND ";
                        $QryPlanet .= "`planet` = '" . $FleetRow['fleet_end_planet'] . "' AND ";
                        $QryPlanet .= "`planet_type` = '1';";
                        $Planet = doquery($QryPlanet, 'planets', true);
                        $IDPlanet = $Planet['id'];
                        $Qryvue = "UPDATE {{table}} SET ";
                        $Qryvue .= "`current_planet` = '" . $IDPlanet . "' ";
                        $Qryvue .= "WHERE ";
                        $Qryvue .= "`id` = '" . $targetUserID . "' ";
                        $Qryvue .= ";";
                        doquery($Qryvue, 'users');
                    }
                    $destext .= sprintf($lang['sys_destruc_mess'], $DepName, $FleetRow['fleet_start_galaxy'], $FleetRow['fleet_start_system'], $FleetRow['fleet_start_planet'], $FleetRow['fleet_end_galaxy'], $FleetRow['fleet_end_system'], $FleetRow['fleet_end_planet']) . "<br />";
                    $destext .= sprintf($lang['sys_destruc_lune'], $chance) . "<br />";
                    $destext .= $lang['sys_debris'] . " " . $lang['Metal'] . ":<font color=\"#adaead\">" . ($result['debree']['att'][0] + $result['debree']['def'][0] + $metallmond) . "</font>   " . $lang['Crystal'] . ":<font color=\"#ef51ef\">" . ($result['debree']['att'][1] + $result['debree']['def'][1] + $kristallmond) . "</font>" . $lang['Appolonium'] . ":<font color=\"#40e0d0\">" . ($result['debree']['att'][2] + $result['debree']['def'][2] + $appolonium) . "</font><br />";
                    $destext .= $lang['sys_destruc_mess1'] . "<br />";
                    $destext .= $lang['sys_destruc_reussi'] . "<br />";
                    $destructionrip = sqrt($targetPlanet['diameter']) / 2;
                    $chance2 = round($destructionrip);
                    $tirage2 = mt_rand(0, 100);
                    $destext .= sprintf($lang['sys_destruc_rip'], $chance2) . "<br />";
                    if ($tirage2 <= $chance2) {
                        //Rips gehen in das Tf
                        $tftsmet = 0;
                        $tftscrist = 0;
                        if ($attackFleets[$FleetRow['fleet_id']]['detail'][218] > 0 and $attackFleets[$FleetRow['fleet_id']]['detail'][214] = 0) {
                            $tftsmet = round($attackFleets[$FleetRow['fleet_id']]['detail'][218] * $pricelist['218']['metal']) * ($game_config['Fleet_Cdr'] / 100);
                            $tftscrist = round($attackFleets[$FleetRow['fleet_id']]['detail'][218] * $pricelist['218']['crystal']) * ($game_config['Fleet_Cdr'] / 100);
                            $tftsappo = round($attackFleets[$FleetRow['fleet_id']]['detail'][218] * $pricelist['218']['appolonium']) * ($game_config['Fleet_Cdr'] / 100);
                        } else {
                            $tftsmet = round($attackFleets[$FleetRow['fleet_id']]['detail'][214] * $pricelist['214']['metal']) * ($game_config['Fleet_Cdr'] / 100);
                            $tftscrist = round($attackFleets[$FleetRow['fleet_id']]['detail'][214] * $pricelist['214']['crystal']) * ($game_config['Fleet_Cdr'] / 100);
                        }
                        // Trümmerfeld go's Galaxy
                        $QryUpdateGalaxy = "UPDATE {{table}} SET ";
                        $QryUpdateGalaxy .= "`metal` = `metal` +'" . $tftsmet . "', ";
                        $QryUpdateGalaxy .= "`crystal` = `crystal` + '" . $tftscrist . "', ";
                        $QryUpdateGalaxy .= "`appolonium` = `appolonium` + '" . $tftsappo . "' ";
                        $QryUpdateGalaxy .= "WHERE ";
                        $QryUpdateGalaxy .= "`galaxy` = '" . $FleetRow['fleet_end_galaxy'] . "' AND ";
                        $QryUpdateGalaxy .= "`system` = '" . $FleetRow['fleet_end_system'] . "' AND ";
                        $QryUpdateGalaxy .= "`planet` = '" . $FleetRow['fleet_end_planet'] . "' ";
                        $QryUpdateGalaxy .= "LIMIT 1;";
                        doquery($QryUpdateGalaxy, 'galaxy');
                        //Rips in das Tf Ende
                        $destext .= $lang['sys_destruc_echec'] . " <br />";
                        $destext .= $lang['sys_debris'] . " " . $lang['Metal'] . ":<font color=\"#adaead\">" . ($result['debree']['att'][0] + $result['debree']['def'][0] + $tftsmet) . "</font>   " . $lang['Crystal'] . ":<font color=\"#ef51ef\">" . ($result['debree']['att'][1] + $result['debree']['def'][1] + $tftscrist) . "</font>" . $lang['Appolonium'] . ":<font color=\"#40e0d0\">" . ($result['debree']['att'][2] + $result['debree']['def'][2] + $tftsappo) . "</font><br />";
                        doquery("DELETE FROM {{table}} WHERE `fleet_id` = '" . $FleetRow["fleet_id"] . "';", 'fleets');
                    }
                    // Falls Mondzerstörung Abgeblockt wird
                } else {
                    $destructionrip = sqrt($targetPlanet['diameter']) / 2;
                    $chance2 = round($destructionrip);
                    $tirage2 = mt_rand(0, 100);
                    $destext .= sprintf($lang['sys_destruc_mess'], $DepName, $FleetRow['fleet_start_galaxy'], $FleetRow['fleet_start_system'], $FleetRow['fleet_start_planet'], $FleetRow['fleet_end_galaxy'], $FleetRow['fleet_end_system'], $FleetRow['fleet_end_planet']) . "<br />";
                    $destext .= $lang['sys_destruc_mess1'] . "<br />";
                    $destext .= sprintf($lang['sys_destruc_lune'], $chance) . "<br />";
                    $destext .= sprintf($lang['sys_destruc_rip'], $chance2) . "<br />";
                    if ($tirage2 <= $chance2) {
                        //Rips gehen in das Tf
                        $tftsmet = 0;
                        $tftscrist = 0;
                        if ($attackFleets[$FleetRow['fleet_id']]['detail'][218] > 0 and $attackFleets[$FleetRow['fleet_id']]['detail'][214] = 0) {
                            $tftsmet = round($attackFleets[$FleetRow['fleet_id']]['detail'][218] * $pricelist['218']['metal']) * ($game_config['Fleet_Cdr'] / 100);
                            $tftscrist = round($attackFleets[$FleetRow['fleet_id']]['detail'][218] * $pricelist['218']['crystal']) * ($game_config['Fleet_Cdr'] / 100);
                            $tftsappo = round($attackFleets[$FleetRow['fleet_id']]['detail'][218] * $pricelist['218']['appolonium']) * ($game_config['Fleet_Cdr'] / 100);
                        } else {
                            $tftsmet = round($attackFleets[$FleetRow['fleet_id']]['detail'][214] * $pricelist['214']['metal']) * ($game_config['Fleet_Cdr'] / 100);
                            $tftscrist = round($attackFleets[$FleetRow['fleet_id']]['detail'][214] * $pricelist['214']['crystal']) * ($game_config['Fleet_Cdr'] / 100);
                        }
                        // Trümmerfeld go's Galaxy
                        $QryUpdateGalaxy = "UPDATE {{table}} SET ";
                        $QryUpdateGalaxy .= "`metal` = `metal` +'" . $tftsmet . "', ";
                        $QryUpdateGalaxy .= "`crystal` = `crystal` + '" . $tftscrist . "', ";
                        $QryUpdateGalaxy .= "`appolonium` = `appolonium` + '" . $tftsappo . "' ";
                        $QryUpdateGalaxy .= "WHERE ";
                        $QryUpdateGalaxy .= "`galaxy` = '" . $FleetRow['fleet_end_galaxy'] . "' AND ";
                        $QryUpdateGalaxy .= "`system` = '" . $FleetRow['fleet_end_system'] . "' AND ";
                        $QryUpdateGalaxy .= "`planet` = '" . $FleetRow['fleet_end_planet'] . "' ";
                        $QryUpdateGalaxy .= "LIMIT 1;";
                        doquery($QryUpdateGalaxy, 'galaxy');
                        //Rips in das Tf Ende
                        $destext .= $lang['sys_destruc_echec'] . " <br />";
                        $destext .= $lang['sys_debris'] . " " . $lang['Metal'] . ":<font color=\"#adaead\">" . ($result['debree']['att'][0] + $result['debree']['def'][0] + $tftsmet) . "</font>   " . $lang['Crystal'] . ":<font color=\"#ef51ef\">" . ($result['debree']['att'][1] + $result['debree']['def'][1] + $tftscrist) . "</font>" . $lang['Appolonium'] . ":<font color=\"#ef51ef\">" . ($result['debree']['att'][2] + $result['debree']['def'][2] + $tftsappo) . "</font><br />";
                        doquery("DELETE FROM {{table}} WHERE `fleet_id` = '" . $FleetRow["fleet_id"] . "';", 'fleets');
                    } else {
                        $destext .= $lang['sys_destruc_stop'] . "<br />";
                    }
                }
                break;
            case "r":
                $destext .= sprintf($lang['sys_destruc_mess'], $DepName, $FleetRow['fleet_start_galaxy'], $FleetRow['fleet_start_system'], $FleetRow['fleet_start_planet'], $FleetRow['fleet_end_galaxy'], $FleetRow['fleet_end_system'], $FleetRow['fleet_end_planet']) . "<br />";
                $destext .= $lang['sys_destruc_stop'] . "<br />";
                doquery("DELETE FROM {{table}} WHERE `fleet_id` = '" . $FleetRow["fleet_id"] . "';", 'fleets');
                break;
            case "w":
                $destext .= sprintf($lang['sys_destruc_mess'], $DepName, $FleetRow['fleet_start_galaxy'], $FleetRow['fleet_start_system'], $FleetRow['fleet_start_planet'], $FleetRow['fleet_end_galaxy'], $FleetRow['fleet_end_system'], $FleetRow['fleet_end_planet']) . "<br />";
                $destext .= $lang['sys_destruc_stop'] . "<br />";
                break;
            default:
                break;
        }
        //Ende Mondzerstörung
        $strunitsgesamt = $result['lost']['att'] + $result['lost']['def'];
        $user1lostunits = $result['lost']['att'];
        $user1shotunits = $result['lost']['def'];
        $user2lostunits = $result['lost']['def'];
        $user2shotunits = $result['lost']['att'];
        $strtruemmerfeld = $result['debree']['att'][0] + $result['debree']['def'][0] + $result['debree']['att'][1] + $result['debree']['def'][1] + $result['debree']['att'][2] + $result['debree']['def'][2];
        $strtruemmermetal = $result['debree']['att'][0] + $result['debree']['def'][0];
        $strtruemmercrystal = $result['debree']['att'][1] + $result['debree']['def'][1];
        $strtruemmerappolonium = $result['debree']['att'][2] + $result['debree']['def'][2];
        $FleetDebris = $result['debree']['att'][0] + $result['debree']['def'][0] + $result['debree']['att'][1] + $result['debree']['def'][1] + $result['debree']['att'][2] + $result['debree']['def'][2];
        $StrAttackerUnits = sprintf($lang['sys_attacker_lostunits'], $result['lost']['att']);
        $StrDefenderUnits = sprintf($lang['sys_defender_lostunits'], $result['lost']['def']);
        $StrRuins = sprintf($lang['sys_gcdrunits'], $result['debree']['def'][0] + $result['debree']['att'][0], $lang['Metal'], $result['debree']['def'][1] + $result['debree']['att'][1], $lang['Crystal'], $result['debree']['def'][2] + $result['debree']['att'][2], $lang['Appolonium']);
        $DebrisField = $StrAttackerUnits . "<br />" . $StrDefenderUnits . "<br />" . $StrRuins;
        // Monderstellung
        $MoonChance = $FleetDebris / 100000;
        if ($FleetDebris > 2000000) {
            $MoonChance = 20;
        }
        if ($FleetDebris < 100000) {
            $UserChance = 0;
            $ChanceMoon = "";
        } elseif ($FleetDebris >= 100000) {
            $UserChance = mt_rand(1, 100);
            $ChanceMoon = sprintf($lang['sys_moonproba'], $MoonChance);
        }
        // Mond ja
        if ($UserChance > 0 && $UserChance <= $MoonChance && $targetGalaxy['id_luna'] == 0) {
            $TargetPlanetName = CreateOneMoonRecord($FleetRow['fleet_end_galaxy'], $FleetRow['fleet_end_system'], $FleetRow['fleet_end_planet'], $TargetUserID, $FleetRow['fleet_start_time'], '', $MoonChance);
            $GottenMoon = sprintf($lang['sys_moonbuilt'], $TargetPlanetName, $FleetRow['fleet_end_galaxy'], $FleetRow['fleet_end_system'], $FleetRow['fleet_end_planet']);
            $GottenMoon .= "<br />";
            //Warum gibt es ein Trümmerfeld wenn der Mond doch daraus ensteht???
            //Abfrage der Größe des Trümmerfeldes?
            $QrySelectGalaxy = "SELECT * FROM {{table}} ";
            $QrySelectGalaxy .= "WHERE ";
            $QrySelectGalaxy .= "`galaxy` = '" . $FleetRow['fleet_end_galaxy'] . "' AND ";
            $QrySelectGalaxy .= "`system` = '" . $FleetRow['fleet_end_system'] . "' AND ";
            $QrySelectGalaxy .= "`planet` = '" . $FleetRow['fleet_end_planet'] . "' ";
            $QrySelectGalaxy .= "LIMIT 1;";
            $TargetGalaxy = doquery($QrySelectGalaxy, 'galaxy', true);
            // Trümmerfeld wird gelöscht da der Mond aus den Trümmern entstanden ist!.
            $QryUpdateGalaxy = "UPDATE {{table}} SET ";
            $QryUpdateGalaxy .= "`metal` = `metal` - '" . $TargetGalaxy["metal"] . "', ";
            $QryUpdateGalaxy .= "`crystal` = `crystal` - '" . $TargetGalaxy["crystal"] . "', ";
            $QryUpdateGalaxy .= "`appolonium` = `appolonium` - '" . $TargetGalaxy["appolonium"] . "' ";
            $QryUpdateGalaxy .= "WHERE ";
            $QryUpdateGalaxy .= "`galaxy` = '" . $FleetRow['fleet_end_galaxy'] . "' AND ";
            $QryUpdateGalaxy .= "`system` = '" . $FleetRow['fleet_end_system'] . "' AND ";
            $QryUpdateGalaxy .= "`planet` = '" . $FleetRow['fleet_end_planet'] . "' ";
            $QryUpdateGalaxy .= "LIMIT 1;";
            doquery($QryUpdateGalaxy, 'galaxy');
            // Mond nein
        } elseif ($UserChance = 0 or $UserChance > $MoonChance) {
            $GottenMoon = "";
        }
        $OwnedUser = doquery('SELECT * FROM {{table}} WHERE id=' . $FleetRow['fleet_owner'], 'users', true);
        $formatted_cr = formatCRM($result, $steal, $MoonChance, $GottenMoon, $totaltime, $destext);
        $raport = $formatted_cr['html'];
        $rid = md5($raport);
        $QryInsertRapport = 'INSERT INTO {{table}} SET ';
        $QryInsertRapport .= '`time` = UNIX_TIMESTAMP(), ';
        foreach ($attackFleets as $fleetID => $attacker) {
            $users2[$attacker['user']['id']] = $attacker['user']['id'];
        }
        foreach ($defense as $fleetID => $defender) {
            $users2[$defender['user']['id']] = $defender['user']['id'];
        }
        $QryInsertRapport .= '`owners` = "' . implode(',', $users2) . '", ';
        $QryInsertRapport .= '`rid` = "' . $rid . '", ';
        $QryInsertRapport .= '`raport` = "' . mysql_real_escape_string($raport) . '"';
        doquery($QryInsertRapport, 'rw') or die("Error inserting CR to database" . mysql_error() . "<br /><br />Trying to execute:" . mysql_query());
        $angreifer = $formatted_cr['angreifer'];
        $dpath = !$user["dpath"] ? DEFAULT_SKINPATH : $user["dpath"];
        $rid = md5($raport);
        $QryInserttopkb = "INSERT INTO {{table}} SET ";
        $QryInserttopkb .= "`time` = UNIX_TIMESTAMP(), ";
        $QryInserttopkb .= "`id_owner1` = '" . $FleetRow['fleet_owner'] . "', ";
        $QryInserttopkb .= "`angreifer` = '" . $angreifer . "', ";
        $QryInserttopkb .= "`id_owner2` = '" . $targetUser['id'] . "', ";
        $QryInserttopkb .= "`defender` = '" . $targetUser['username'] . "', ";
        $QryInserttopkb .= "`gesamtunits` = '" . $strunitsgesamt . "', ";
        $QryInserttopkb .= "`gesamttruemmer` = '" . $strtruemmerfeld . "', ";
        $QryInserttopkb .= "`rid` = '" . $rid . "', ";
        $QryInserttopkb .= "`a_zestrzelona` = '" . $a_zestrzelona . "', ";
        $QryInserttopkb .= "`raport` = '" . mysql_real_escape_string($raport) . "',";
        $QryInserttopkb .= "`fleetresult` = '" . $result['won'] . "';";
        doquery("LOCK TABLE {{table}} WRITE", 'topkb');
        doquery($QryInserttopkb, 'topkb');
        doquery("UNLOCK TABLES", '');
        $user1stat = $FleetRow['fleet_owner'];
        $user2stat = $TargetUserID;
        $raport = '<a href # OnClick=\'f( "rw.php?raport=' . $rid . '", "");\' >';
        $raport .= '<center>';
        if ($result['won'] == "a") {
            $raport .= '<font color=\'green\'>';
        } elseif ($result['won'] == "w") {
            $raport .= '<font color=\'orange\'>';
        } elseif ($result['won'] == "r") {
            $raport .= '<font color=\'red\'>';
        }
        $raport .= $lang['sys_mess_destruc_report'] . " [" . $FleetRow['fleet_end_galaxy'] . ":" . $FleetRow['fleet_end_system'] . ":" . $FleetRow['fleet_end_planet'] . "] </font></a><br /><br />";
        $raport .= "<font color=\"red\">" . $lang['sys_perte_attaquant'] . ": " . $result['lost']['att'] . "</font>";
        $raport .= "<font color=\"green\">   " . $lang['sys_perte_defenseur'] . ": " . $result['lost']['def'] . "</font><br />";
        $raport .= $lang['sys_debris'] . " " . $lang['Metal'] . ":<font color=\"#adaead\">" . ($result['debree']['att'][0] + $result['debree']['def'][0] + $metallmond) . "</font>   " . $lang['Crystal'] . ":<font color=\"#ef51ef\">" . ($result['debree']['att'][1] + $result['debree']['def'][1] + $kristallmond) . "</font>" . $lang['Appolonium'] . ":<font color=\"#40e0d0\">" . ($result['debree']['att'][2] + $result['debree']['def'][2] + $appolonium) . "</font><br />";
        SendSimpleMessage($FleetRow['fleet_owner'], '', $FleetRow['fleet_start_time'], 3, $lang['sys_mess_tower'], $lang['sys_mess_destruc_report'], $raport);
        $raport2 = "<a href # OnClick=\"f( 'rw.php?raport=" . $rid . "', '');\" >";
        $raport2 .= "<center>";
        if ($result['won'] == "a") {
            $raport2 .= '<font color=\'red\'>';
        } elseif ($result['won'] == "w") {
            $raport2 .= '<font color=\'orange\'>';
        } elseif ($result['won'] == "r") {
            $raport2 .= '<font color=\'green\'>';
        }
        $raport2 .= $lang['sys_mess_destruc_report'] . " [" . $FleetRow['fleet_end_galaxy'] . ":" . $FleetRow['fleet_end_system'] . ":" . $FleetRow['fleet_end_planet'] . "] </font></a><br /><br />";
        foreach ($users2 as $id) {
            if ($id != $FleetRow['fleet_owner'] && $id != 0) {
                SendSimpleMessage($id, '', $FleetRow['fleet_start_time'], 3, $lang['sys_mess_tower'], $lang['sys_mess_attack_report'], $raport2);
            }
        }
        $user1 = doquery("SELECT * FROM {{table}} WHERE `id` = '" . $user1stat . "';", 'users');
        while ($user1data = mysql_fetch_assoc($user1)) {
            $strtruemmermetaluser1 = $strtruemmermetal + $user1data['kbmetal'];
            $strtruemmercrystaluser1 = $strtruemmercrystal + $user1data['kbcrystal'];
            $strtruemmerappoloniumuser1 = $strtruemmerappolonium + $user1data['kbappolonium'];
            $user1lostunits = $user1lostunits + $user1data['lostunits'];
            $user1shotunits = $user1shotunits + $user1data['desunits'];
            $user1wons = $user1data['wons'];
            $user1loos = $user1data['loos'];
            $user1draws = $user1data['draws'];
        }
        $user2 = doquery("SELECT * FROM {{table}} WHERE `id` = '" . $user2stat . "';", 'users');
        while ($user2data = mysql_fetch_assoc($user2)) {
            $strtruemmermetaluser2 = $strtruemmermetal + $user2data['kbmetal'];
            $strtruemmercrystaluser2 = $strtruemmercrystal + $user2data['kbcrystal'];
            $strtruemmerappoloniumuser2 = $strtruemmerappolonium + $user2data['kbappolonium'];
            $user2lostunits = $user2lostunits + $user2data['lostunits'];
            $user2shotunits = $user2shotunits + $user2data['desunits'];
            $user2wons = $user2data['wons'];
            $user2loos = $user2data['loos'];
            $user2draws = $user2data['draws'];
        }
        if ($result['won'] == "a") {
            $user1wons = $user1wons + 1;
            $user2loos = $user2loos + 1;
        } elseif ($result['won'] == "w") {
            $user1draws = $user1draws + 1;
            $user2draws = $user2draws + 1;
        } elseif ($result['won'] == "r") {
            $user1loos = $user1loos + 1;
            $user2wons = $user2wons + 1;
        }
        $QryUpdateuserstat = "UPDATE {{table}} SET ";
        $QryUpdateuserstat .= "`wons` = '" . $user1wons . "', ";
        $QryUpdateuserstat .= "`loos` = '" . $user1loos . "', ";
        $QryUpdateuserstat .= "`draws` = '" . $user1draws . "', ";
        $QryUpdateuserstat .= "`kbmetal` = '" . $strtruemmermetaluser1 . "', ";
        $QryUpdateuserstat .= "`kbcrystal` = '" . $strtruemmercrystaluser1 . "', ";
        $QryUpdateuserstat .= "`kbappolonium` = '" . $strtruemmerappoloniumuser1 . "', ";
        $QryUpdateuserstat .= "`lostunits` = '" . $user1lostunits . "', ";
        $QryUpdateuserstat .= "`desunits` = '" . $user1shotunits . "' ";
        $QryUpdateuserstat .= "WHERE ";
        $QryUpdateuserstat .= "`id` = '" . $FleetRow['fleet_owner'] . "';";
        doquery($QryUpdateuserstat, 'users');
        $QryUpdateuser2stat = "UPDATE {{table}} SET ";
        $QryUpdateuser2stat .= "`wons` = '" . $user2wons . "', ";
        $QryUpdateuser2stat .= "`loos` = '" . $user2loos . "', ";
        $QryUpdateuser2stat .= "`draws` = '" . $user2draws . "', ";
        $QryUpdateuser2stat .= "`kbmetal` = '" . $strtruemmermetaluser2 . "', ";
        $QryUpdateuser2stat .= "`kbcrystal` = '" . $strtruemmercrystaluser2 . "', ";
        $QryUpdateuser2stat .= "`kbappolonium` = '" . $strtruemmerappoloniumuser2 . "', ";
        $QryUpdateuser2stat .= "`lostunits` = '" . $user2lostunits . "', ";
        $QryUpdateuser2stat .= "`desunits` = '" . $user2shotunits . "' ";
        $QryUpdateuser2stat .= "WHERE ";
        $QryUpdateuser2stat .= "`id` = '" . $targetUser['id'] . "';";
        doquery($QryUpdateuser2stat, 'users');
        $CurrentUser = doquery("SELECT * FROM {{table}} WHERE id = " . $FleetRow['fleet_owner'], 'users', true);
        $CurrentUserID = $CurrentUser['id'];
        $AddPoint = $CurrentUser['xpraid'] + 1;
        $QryUpdateOfficier = "UPDATE {{table}} SET ";
        $QryUpdateOfficier .= "`xpraid` = '" . $AddPoint . "' ";
        $QryUpdateOfficier .= "WHERE id = '" . $CurrentUserID . "' ";
        $QryUpdateOfficier .= "LIMIT 1 ;";
        doquery($QryUpdateOfficier, 'users');
        $RaidsTotal = $CurrentUser['raids'] + 1;
        if ($result['won'] == "a") {
            $RaidsWin = $CurrentUser['raidswin'] + 1;
            $QryUpdateRaidsCompteur = "UPDATE {{table}} SET ";
            $QryUpdateRaidsCompteur .= "`raidswin` ='" . $RaidsWin . "', ";
            $QryUpdateRaidsCompteur .= "`raids` ='" . $RaidsTotal . "' ";
            $QryUpdateRaidsCompteur .= "WHERE id = '" . $CurrentUserID . "' ";
            $QryUpdateRaidsCompteur .= "LIMIT 1 ;";
            doquery($QryUpdateRaidsCompteur, 'users');
        } elseif ($result['won'] == "r" || $result['won'] == "w") {
            $RaidsLoose = $CurrentUser['raidsloose'] + 1;
            $QryUpdateRaidsCompteur = "UPDATE {{table}} SET ";
            $QryUpdateRaidsCompteur .= "`raidsloose` ='" . $RaidsLoose . "', ";
            $QryUpdateRaidsCompteur .= "`raids` ='" . $RaidsTotal . "' ";
            $QryUpdateRaidsCompteur .= "WHERE id = '" . $CurrentUserID . "' ";
            $QryUpdateRaidsCompteur .= "LIMIT 1 ;";
            doquery($QryUpdateRaidsCompteur, 'users');
        }
    } elseif ($FleetRow['fleet_end_time'] <= time()) {
        $Message = sprintf($lang['sys_tran_mess_angriffback'], $TargetName, GetTargetAdressLink($FleetRow, ''), pretty_number($FleetRow['fleet_resource_metal']), $lang['Metal'], pretty_number($FleetRow['fleet_resource_crystal']), $lang['Crystal'], pretty_number($FleetRow['fleet_resource_deuterium']), $lang['Deuterium'], pretty_number($FleetRow['fleet_resource_appolonium']), $lang['Appolonium']);
        SendSimpleMessage($FleetRow['fleet_owner'], '', $FleetRow['fleet_end_time'], 3, $lang['sys_mess_tower'], $lang['sys_mess_fleetback'], $Message);
        RestoreFleetToPlanet($FleetRow);
        doquery('DELETE FROM {{table}} WHERE `fleet_id`=' . $FleetRow['fleet_id'], 'fleets');
    }
}
function flt_flying_fleet_handler($skip_fleet_update = false)
{
    /*
    [*] Нужно ли заворачивать ВСЕ в одну транзакцию?
          С одной стороны - да, что бы данные были гарантированно на момент снапшота
          С другой стороны - нет, потому что при большой активности это все будет блокировать слишком много рядов, да и таймаут будет большой для ожидания всего разлоченного
          Стоит завернуть каждую миссию отдельно? Это сильно увеличит количество запросов, зато так же сильно снизит количество блокировок.
        Resume: НЕТ! Надо оставить все в одной транзакции! Так можно будет поддерживать consistency кэша. Там буквально сантисекунды блокировки
    [*] Убрать кэшированние данных о пользователях и планета. Офигенно освободит память - проследить!
          НЕТ! Считать, скольким флотам нужна будет инфа и кэшировать только то, что используется больше раза!
          Заодно можно будет исключить перересчет очередей/ресурсов - сильно ускорит дело!
          Особенно будет актуально, когда все бонусы будут в одной таблице
          Ну и никто не заставляет как сейчас брать ВСЕ из таблицы - только по полям. Гемор, но не сильный - сделать запрос по группам sn_data
          И писать в БД только один раз результат
    [*] Нужно ли на этом этапе знать полную информацию о флотах?
          Заблокировать флоты можно и неполным запросом. Блокировка флотов - это не страшно. Ну, не пройдет одна-две отмены - так никто и не гарантировал реалтайма!
          С одной стороны - да, уменьшит количество запросов
          С другой стооны - расход памяти
          Все равно надо будет знать полную инфу о флоте в момент обработки
    [*] Сделать тестовую БД для расчетов
    [*] Но не раньше, чем переписать все миссии
    */
    global $config, $debug;
    if ($config->game_disable != GAME_DISABLE_NONE || $skip_fleet_update) {
        return;
    }
    sn_db_transaction_start();
    if ($config->db_loadItem('game_disable') != GAME_DISABLE_NONE || SN_TIME_NOW - strtotime($config->db_loadItem('fleet_update_last')) <= $config->fleet_update_interval) {
        sn_db_transaction_rollback();
        return;
    }
    // Watchdog timer
    if ($config->db_loadItem('fleet_update_lock')) {
        if (SN_TIME_NOW - strtotime($config->fleet_update_lock) <= mt_rand(240, 300)) {
            sn_db_transaction_rollback();
            return;
        } else {
            $debug->warning('Flying fleet handler was locked too long - watchdog unlocked', 'FFH Error', 504);
        }
    }
    $config->db_saveItem('fleet_update_lock', SN_TIME_SQL);
    $config->db_saveItem('fleet_update_last', SN_TIME_SQL);
    sn_db_transaction_commit();
    //log_file('Начинаем обсчёт флотов');
    //log_file('Обсчёт ракет');
    sn_db_transaction_start();
    coe_o_missile_calculate();
    sn_db_transaction_commit();
    $fleet_list = array();
    $fleet_event_list = array();
    $missions_used = array();
    sn_db_transaction_start();
    //log_file('Запрос на флоты');
    $_fleets = doquery("SELECT * FROM `{{fleets}}` WHERE\n    (`fleet_start_time` <= " . SN_TIME_NOW . " AND `fleet_mess` = 0)\n    OR (`fleet_end_stay` <= " . SN_TIME_NOW . " AND fleet_end_stay > 0 AND `fleet_mess` = 0)\n    OR (`fleet_end_time` <= " . SN_TIME_NOW . ")\n  FOR UPDATE;");
    //log_file('Выборка флотов');
    while ($fleet_row = db_fetch($_fleets)) {
        set_time_limit(15);
        // Унифицировать код с темплейтным разбором эвентов на планете!
        $fleet_list[$fleet_row['fleet_id']] = $fleet_row;
        $missions_used[$fleet_row['fleet_mission']] = 1;
        if ($fleet_row['fleet_start_time'] <= SN_TIME_NOW && $fleet_row['fleet_mess'] == 0) {
            $fleet_event_list[] = array('fleet_row' => &$fleet_list[$fleet_row['fleet_id']], 'fleet_time' => $fleet_list[$fleet_row['fleet_id']]['fleet_start_time'], 'fleet_event' => EVENT_FLT_ARRIVE);
        }
        if ($fleet_row['fleet_end_stay'] > 0 && $fleet_row['fleet_end_stay'] <= SN_TIME_NOW && $fleet_row['fleet_mess'] == 0) {
            $fleet_event_list[] = array('fleet_row' => &$fleet_list[$fleet_row['fleet_id']], 'fleet_time' => $fleet_list[$fleet_row['fleet_id']]['fleet_end_stay'], 'fleet_event' => EVENT_FLT_ACOMPLISH);
        }
        if ($fleet_row['fleet_end_time'] <= SN_TIME_NOW) {
            $fleet_event_list[] = array('fleet_row' => &$fleet_list[$fleet_row['fleet_id']], 'fleet_time' => $fleet_list[$fleet_row['fleet_id']]['fleet_end_time'], 'fleet_event' => EVENT_FLT_RETURN);
        }
    }
    sn_db_transaction_commit();
    //log_file('Сортировка и подгрузка модулей');
    uasort($fleet_event_list, 'flt_flyingFleetsSort');
    unset($_fleets);
    // TODO: Грузить только используемые модули из $missions_used
    $mission_files = array(MT_ATTACK => 'flt_mission_attack', MT_AKS => 'flt_mission_attack', MT_DESTROY => 'flt_mission_attack', MT_TRANSPORT => 'flt_mission_transport', MT_RELOCATE => 'flt_mission_relocate', MT_HOLD => 'flt_mission_hold', MT_SPY => 'flt_mission_spy', MT_COLONIZE => 'flt_mission_colonize', MT_RECYCLE => 'flt_mission_recycle', MT_EXPLORE => 'flt_mission_explore');
    foreach ($missions_used as $mission_id => $cork) {
        require_once SN_ROOT_PHYSICAL . "includes/includes/{$mission_files[$mission_id]}" . DOT_PHP_EX;
    }
    //log_file('Обработка миссий');
    $sn_groups_mission = sn_get_groups('missions');
    foreach ($fleet_event_list as $fleet_event) {
        // TODO: Указатель тут потом сделать
        // TODO: СЕЙЧАС НАДО ПРОВЕРЯТЬ ПО БАЗЕ - А ЖИВОЙ ЛИ ФЛОТ?!
        $fleet_row = $fleet_event['fleet_row'];
        if (!$fleet_row) {
            // Fleet was destroyed in course of previous actions
            continue;
        }
        //log_file('Миссия');
        // TODO Обернуть всё в транзакции. Начинать надо заранее, блокируя все таблицы внутренним локом SELECT 1 FROM {{users}}
        sn_db_transaction_start();
        $config->db_saveItem('fleet_update_last', SN_TIME_SQL);
        $mission_data = $sn_groups_mission[$fleet_row['fleet_mission']];
        // Формируем запрос, блокирующий сразу все нужные записи
        db_flying_fleet_lock($mission_data, $fleet_row);
        $fleet_row = doquery("SELECT * FROM {{fleets}} WHERE fleet_id = {$fleet_row['fleet_id']} FOR UPDATE", true);
        if (!$fleet_row || empty($fleet_row)) {
            // Fleet was destroyed in course of previous actions
            sn_db_transaction_commit();
            continue;
        }
        if ($fleet_event['fleet_event'] == EVENT_FLT_RETURN) {
            // Fleet returns to planet
            RestoreFleetToPlanet($fleet_row, true, false, true);
            sn_db_transaction_commit();
            continue;
        }
        if ($fleet_event['fleet_event'] == EVENT_FLT_ARRIVE && $fleet_row['fleet_mess'] != 0) {
            // При событии EVENT_FLT_ARRIVE флот всегда должен иметь fleet_mess == 0
            // В противном случае это означает, что флот уже был обработан ранее - например, при САБе
            sn_db_transaction_commit();
            continue;
        }
        // TODO: Здесь тоже указатели
        // TODO: Кэширование
        // TODO: Выбирать только нужные поля
        // шпионаж не дает нормальный ID fleet_end_planet_id 'dst_planet'
        $mission_data = array('fleet' => &$fleet_row, 'dst_user' => $mission_data['dst_user'] || $mission_data['dst_planet'] ? db_user_by_id($fleet_row['fleet_target_owner'], true) : null, 'dst_planet' => $mission_data['dst_planet'] ? db_planet_by_vector($fleet_row, 'fleet_end_', true, '`id`, `id_owner`, `name`') : null, 'src_user' => $mission_data['src_user'] || $mission_data['src_planet'] ? db_user_by_id($fleet_row['fleet_owner'], true) : null, 'src_planet' => $mission_data['src_planet'] ? db_planet_by_vector($fleet_row, 'fleet_start_', true, '`id`, `id_owner`, `name`') : null, 'fleet_event' => $fleet_event['fleet_event']);
        if ($mission_data['dst_planet']) {
            // $mission_data['dst_planet'] = sys_o_get_updated($mission_data['dst_user'], $mission_data['dst_planet']['id'], $fleet_row['fleet_start_time']);
            if ($mission_data['dst_planet']['id_owner']) {
                $mission_data['dst_planet'] = sys_o_get_updated($mission_data['dst_planet']['id_owner'], $mission_data['dst_planet']['id'], $fleet_row['fleet_start_time']);
            }
            $mission_data['dst_user'] = $mission_data['dst_user'] ? $mission_data['dst_planet']['user'] : null;
            $mission_data['dst_planet'] = $mission_data['dst_planet']['planet'];
        }
        switch ($fleet_row['fleet_mission']) {
            // Для боевых атак нужно обновлять по САБу и по холду - таки надо возвращать данные из обработчика миссий!
            case MT_AKS:
            case MT_ATTACK:
            case MT_DESTROY:
                $attack_result = flt_mission_attack($mission_data);
                $mission_result = CACHE_COMBAT;
                break;
                /*
                case MT_DESTROY:
                  $attack_result = flt_mission_destroy($mission_data);
                  $mission_result = CACHE_COMBAT;
                break;
                */
            /*
            case MT_DESTROY:
              $attack_result = flt_mission_destroy($mission_data);
              $mission_result = CACHE_COMBAT;
            break;
            */
            case MT_TRANSPORT:
                $mission_result = flt_mission_transport($mission_data);
                break;
            case MT_HOLD:
                $mission_result = flt_mission_hold($mission_data);
                break;
            case MT_RELOCATE:
                $mission_result = flt_mission_relocate($mission_data);
                break;
            case MT_EXPLORE:
                $mission_result = flt_mission_explore($mission_data);
                break;
            case MT_RECYCLE:
                $mission_result = flt_mission_recycle($mission_data);
                break;
            case MT_COLONIZE:
                $mission_result = flt_mission_colonize($mission_data);
                break;
            case MT_SPY:
                $mission_result = flt_mission_spy($mission_data);
                break;
            case MT_MISSILE:
                // Missiles !!
                break;
                //      default:
                //        doquery("DELETE FROM `{{fleets}}` WHERE `fleet_id` = '{$fleet_row['fleet_id']}' LIMIT 1;");
                //      break;
        }
        sn_db_transaction_commit();
    }
    sn_db_transaction_start();
    $config->db_saveItem('fleet_update_last', SN_TIME_SQL);
    $config->db_saveItem('fleet_update_lock', '');
    sn_db_transaction_commit();
    //  log_file('Закончили обсчёт флотов');
}
Ejemplo n.º 23
0
/**
 * MissionCaseExpedition.php
 *
 * @version 1.0
 * @copyright 2008 By Chlorel for XNova
 *
 */
function MissionCaseExpedition($FleetRow)
{
    global $lang, $resource, $pricelist, $CombatCaps, $pirat;
    $FleetOwner = $FleetRow['fleet_owner'];
    $MessSender = $lang['sys_mess_qg'];
    $MessTitle = $lang['sys_expe_report'];
    $Hasard = 0;
    if ($FleetRow['fleet_mess'] == 0) {
        // Flotte en vol aller
        if ($FleetRow['fleet_end_stay'] < time()) {
            // La Flotte vient de finir son exploration
            // Table de ratio de points par type de vaisseau
            $PointsFlotte = array(202 => 1.0, 203 => 1.5, 204 => 0.5, 205 => 1.5, 206 => 2.0, 207 => 2.5, 208 => 0.5, 209 => 1.0, 210 => 0.01, 211 => 3.0, 212 => 0.0, 213 => 3.5, 214 => 5.0, 215 => 3.2, 216 => 6.5, 217 => 1.5, 218 => 8.5, 219 => 1.5);
            // Table de ratio de gains en nombre par type de vaisseau
            $RatioGain = array(202 => 0.2, 203 => 0.2, 204 => 0.2, 205 => 1.0, 206 => 0.5, 207 => 0.825, 208 => 1.5, 209 => 1.1, 210 => 1.1, 211 => 1.0625, 212 => 0.0, 213 => 0.0625, 214 => 0.03125, 215 => 0.0625, 216 => 0.03125, 217 => 0.03125, 218 => 0.01, 219 => 0.03125);
            // Größe des Laderaums
            $CapacityMaxLow = array(1 => 50000, 2 => 100000, 3 => 200000, 4 => 400000, 5 => 800000, 6 => 1600000, 7 => 3200000, 8 => 6400000, 9 => 12800000, 10 => 25600000, 11 => 51200000, 12 => 102400000, 13 => 204800000, 14 => 409600000, 15 => 819200000);
            $FleetStayDuration = ($FleetRow['fleet_end_stay'] - $FleetRow['fleet_start_time']) / 3600;
            // Initialisation du contenu de la Flotte
            $farray = explode(";", $FleetRow['fleet_array']);
            foreach ($farray as $Item => $Group) {
                if ($Group != '') {
                    $Class = explode(",", $Group);
                    $TypeVaisseau = $Class[0];
                    $NbreVaisseau = $Class[1];
                    $LaFlotte[$TypeVaisseau] = $NbreVaisseau;
                    //On calcul les ressources maximum qui peuvent être récupéré
                    $FleetCapacity += $pricelist[$TypeVaisseau]['capacity'];
                    // Maintenant on calcul en points toute la flotte
                    $FleetPoints += $NbreVaisseau * $PointsFlotte[$TypeVaisseau];
                }
            }
            // Espace deja occupé dans les soutes si ce devait etre le cas
            $FleetUsedCapacity = $FleetRow['fleet_resource_metal'] + $FleetRow['fleet_resource_crystal'] + $FleetRow['fleet_resource_deuterium'] + $FleetRow['fleet_resource_appolonium'];
            $FleetCapacity -= $FleetUsedCapacity;
            //On récupère le nombre total de vaisseaux
            $FleetCount = $FleetRow['fleet_amount'];
            // Bon on les mange comment ces explorateurs ???
            $Hasard = rand(1, 11);
            $MessSender = $lang['sys_mess_qg'] . "(" . $Hasard . ")";
            if ($Hasard == 1) {
                // Pas de bol, on les mange tout crus
                $Hasard += 1;
                $LostAmount = ($Hasard * 33 + 1) / 100;
                // Message pour annoncer la bonne mauvaise nouvelle
                if ($LostAmount == 100) {
                    // Supprimer effectivement la flotte
                    SendSimpleMessage($FleetOwner, '', $FleetRow['fleet_end_stay'], 15, $MessSender, $MessTitle, $lang['sys_expe_blackholl_2']);
                    doquery("DELETE FROM {{table}} WHERE `fleet_id` = " . $FleetRow["fleet_id"], 'fleets');
                } else {
                    foreach ($LaFlotte as $Ship => $Count) {
                        $LostShips[$Ship] = intval($Count * $LostAmount);
                        $NewFleetArray .= $Ship . "," . ($Count - $LostShips[$Ship]) . ";";
                    }
                    $QryUpdateFleet = "UPDATE {{table}} SET ";
                    $QryUpdateFleet .= "`fleet_array` = '" . $NewFleetArray . "', ";
                    $QryUpdateFleet .= "`fleet_mess` = '1'  ";
                    $QryUpdateFleet .= "WHERE ";
                    $QryUpdateFleet .= "`fleet_id` = '" . $FleetRow["fleet_id"] . "';";
                    doquery($QryUpdateFleet, 'fleets');
                    SendSimpleMessage($FleetOwner, '', $FleetRow['fleet_end_stay'], 15, $MessSender, $MessTitle, $lang['sys_expe_blackholl_1']);
                }
            } elseif ($Hasard == 2) {
                // Ah un tour pour rien
                doquery("UPDATE {{table}} SET `fleet_mess` = '1' WHERE `fleet_id` = " . $FleetRow["fleet_id"], 'fleets');
                SendSimpleMessage($FleetOwner, '', $FleetRow['fleet_end_stay'], 15, $MessSender, $MessTitle, $lang['sys_expe_nothing_1']);
            } elseif ($Hasard == 3 or $Hasard == 4 or $Hasard == 5) {
                // Gains de ressources
                $i = rand(1, 15);
                if ($FleetCapacity <= $CapacityMaxLow[$i]) {
                    $MinCapacity = $CapacityMaxLow[$i] - $CapacityMaxLow[$i - 1];
                    $MaxCapacity = $CapacityMaxLow[$i];
                    $FoundGoods = rand($MinCapacity, $MaxCapacity);
                    $FoundMetal = intval($FoundGoods / 2);
                    $FoundCrist = intval($FoundGoods / 4);
                    $FoundDeute = intval($FoundGoods / 6);
                    $FoundAppolo = intval($FoundGoods / 8);
                    $QryUpdateFleet = "UPDATE {{table}} SET ";
                    $QryUpdateFleet .= "`fleet_resource_metal` = `fleet_resource_metal` + '" . $FoundMetal . "', ";
                    $QryUpdateFleet .= "`fleet_resource_crystal` = `fleet_resource_crystal` + '" . $FoundCrist . "', ";
                    $QryUpdateFleet .= "`fleet_resource_deuterium` = `fleet_resource_deuterium` + '" . $FoundDeute . "', ";
                    $QryUpdateFleet .= "`fleet_resource_appolonium` = `fleet_resource_appolonium` + '" . $FoundAppolo . "', ";
                    $QryUpdateFleet .= "`fleet_mess` = '1'  ";
                    $QryUpdateFleet .= "WHERE ";
                    $QryUpdateFleet .= "`fleet_id` = '" . $FleetRow["fleet_id"] . "';";
                    doquery($QryUpdateFleet, 'fleets');
                    $Message = sprintf($lang['sys_expe_found_goods'], pretty_number($FoundMetal), $lang['Metal'], pretty_number($FoundCrist), $lang['Crystal'], pretty_number($FoundDeute), $lang['Deuterium'], pretty_number($FoundAppolo), $lang['Appolonium']);
                    SendSimpleMessage($FleetOwner, '', $FleetRow['fleet_end_stay'], 15, $MessSender, $MessTitle, $Message);
                }
            } elseif ($Hasard == 6 or $Hasard == 7 or $Hasard == 8) {
                if ($FleetRow['fleet_owner'] != in_array($user['id'], $pirat)) {
                    shuffle($pirat);
                    $owner = doquery('SELECT * FROM {{table}} WHERE id=' . $pirat[0], 'users', true);
                    $fleetarray = array();
                    $flugzeit = 900;
                    $start_time = time() + $flugzeit;
                    $end_time = $start_time + $flugzeit;
                    $amount = 16000;
                    $fleetarray = array('203,8000;202,2000;206,5000;207,1000;', '214,100;215,10000;207,5900;', '204,5000;215,5000;205,5000;207,1000;', '217,10000;215,5000;218,1000;', '211,10000;213,5000;216,1000;', '211,1000;213,10000;216,5000;', '203,16000;', '202,16000;', '218,16000;', '214,10000;216,4000;218,1000;');
                    shuffle($fleetarray);
                    $QryInsertFleet = "INSERT INTO {{table}} SET ";
                    $QryInsertFleet .= "`fleet_owner` = '" . $pirat[0] . "', ";
                    $QryInsertFleet .= "`fleet_mission` = '1', ";
                    $QryInsertFleet .= "`fleet_amount` = '" . $amount . "', ";
                    $QryInsertFleet .= "`fleet_array` = '" . $fleetarray[0] . "', ";
                    $QryInsertFleet .= "`fleet_end_stay` = '0', ";
                    $QryInsertFleet .= "`fleet_start_time` = '" . $start_time . "', ";
                    $QryInsertFleet .= "`fleet_start_galaxy` = '" . $owner['galaxy'] . "', ";
                    $QryInsertFleet .= "`fleet_start_system` = '" . $owner['system'] . "', ";
                    $QryInsertFleet .= "`fleet_start_planet` = '" . $owner['planet'] . "', ";
                    $QryInsertFleet .= "`fleet_start_type` = '1', ";
                    $QryInsertFleet .= "`fleet_end_time` = '" . $end_time . "', ";
                    $QryInsertFleet .= "`fleet_end_galaxy` = '" . $FleetRow['fleet_start_galaxy'] . "', ";
                    $QryInsertFleet .= "`fleet_end_system` = '" . $FleetRow['fleet_start_system'] . "', ";
                    $QryInsertFleet .= "`fleet_end_planet` = '" . $FleetRow['fleet_start_planet'] . "', ";
                    $QryInsertFleet .= "`fleet_end_type` = '" . $FleetRow['fleet_start_type'] . "', ";
                    $QryInsertFleet .= "`fleet_resource_metal` = '0', ";
                    $QryInsertFleet .= "`fleet_resource_crystal` = '0', ";
                    $QryInsertFleet .= "`fleet_resource_deuterium` = '0', ";
                    $QryInsertFleet .= "`fleet_resource_appolonium` = '0', ";
                    $QryInsertFleet .= "`fleet_target_owner` = '" . $FleetRow['fleet_owner'] . "', ";
                    $QryInsertFleet .= "`fleet_group` = '0', ";
                    $QryinsertFleet .= "`fleet_mess` = '1' ";
                    $QryInsertFleet .= "`start_time` = '" . time() . "';";
                    doquery($QryInsertFleet, 'fleets');
                    doquery("UPDATE {{table}} SET `fleet_mess` = '1' WHERE `fleet_id` = " . $FleetRow["fleet_id"], 'fleets');
                    SendSimpleMessage($FleetOwner, '', $FleetRow['fleet_end_stay'], 15, $MessSender, $MessTitle, $lang['sys_expe_found_pirat']);
                    $Hasard = 0;
                }
            } elseif ($Hasard == 9) {
                // Ah un tour pour rien
                doquery("UPDATE {{table}} SET `fleet_mess` = '1' WHERE `fleet_id` = " . $FleetRow["fleet_id"], 'fleets');
                SendSimpleMessage($FleetOwner, '', $FleetRow['fleet_end_stay'], 15, $MessSender, $MessTitle, $lang['sys_expe_nothing_2']);
            } elseif ($Hasard == 10 or $Hasard == 11) {
                // Gain de vaisseaux
                $FoundChance = $FleetPoints / $FleetCount;
                $FoundShip = array();
                for ($Ship >= 202; $Ship <= 219; $Ship++) {
                    if ($LaFlotte[$Ship] != 0) {
                        $FoundShip[$Ship] = round($LaFlotte[$Ship] * $RatioGain[$Ship]);
                        if ($FoundShip[$Ship] > 0) {
                            $LaFlotte[$Ship] += $FoundShip[$Ship];
                        }
                    }
                }
                $NewFleetArray = "";
                $FoundShipMess = "";
                foreach ($LaFlotte as $Ship => $Count) {
                    if ($Count >= 0) {
                        $NewFleetArray .= $Ship . "," . $Count . ";";
                    }
                }
                foreach ($FoundShip as $Ship => $Count) {
                    if ($Count != 0) {
                        $FoundShipMess .= $Count . " " . $lang['tech'][$Ship] . ",";
                    }
                }
                $QryUpdateFleet = "UPDATE {{table}} SET ";
                $QryUpdateFleet .= "`fleet_array` = '" . $NewFleetArray . "', ";
                $QryUpdateFleet .= "`fleet_mess` = '1'  ";
                $QryUpdateFleet .= "WHERE ";
                $QryUpdateFleet .= "`fleet_id` = '" . $FleetRow["fleet_id"] . "';";
                doquery($QryUpdateFleet, 'fleets');
                $Message = $lang['sys_expe_found_ships'] . $FoundShipMess . "";
                SendSimpleMessage($FleetOwner, '', $FleetRow['fleet_end_stay'], 15, $MessSender, $MessTitle, $Message);
            }
        }
    } else {
        // La Flotte est de retour a quai
        if ($FleetRow['fleet_end_time'] <= time()) {
            // Reintegration de ce qui se ballade avec la flotte
            $farray = explode(";", $FleetRow['fleet_array']);
            foreach ($farray as $Item => $Group) {
                if ($Group != '') {
                    $Class = explode(",", $Group);
                    $FleetAutoQuery .= "`" . $resource[$Class[0]] . "` = `" . $resource[$Class[0]] . "` + " . $Class[1] . ", ";
                }
            }
            // Message pour annoncer le retour de flotte
            SendSimpleMessage($FleetOwner, '', $FleetRow['fleet_end_time'], 15, $MessSender, $MessTitle, $lang['sys_expe_back_home']);
            RestoreFleetToPlanet($FleetRow, true);
            // Suppression de la flotte
            doquery("DELETE FROM {{table}} WHERE `fleet_id` = " . $FleetRow["fleet_id"], 'fleets');
        }
    }
}
Ejemplo n.º 24
0
function MissionCaseSpy($FleetRow)
{
    global $lang, $resource;
    if ($FleetRow['fleet_start_time'] <= time()) {
        $CurrentUser = doquery("SELECT * FROM {{table}} WHERE `id` = '" . $FleetRow['fleet_owner'] . "';", 'users', true);
        $CurrentUserID = $FleetRow['fleet_owner'];
        $QryGetTargetPlanet = "SELECT * FROM {{table}} ";
        $QryGetTargetPlanet .= "WHERE ";
        $QryGetTargetPlanet .= "`galaxy` = '" . $FleetRow['fleet_end_galaxy'] . "' AND ";
        $QryGetTargetPlanet .= "`system` = '" . $FleetRow['fleet_end_system'] . "' AND ";
        $QryGetTargetPlanet .= "`planet` = '" . $FleetRow['fleet_end_planet'] . "' AND ";
        $QryGetTargetPlanet .= "`planet_type` = '" . $FleetRow['fleet_end_type'] . "';";
        $TargetPlanet = doquery($QryGetTargetPlanet, 'planets', true);
        $TargetUserID = $TargetPlanet['id_owner'];
        $CurrentPlanet = doquery("SELECT * FROM {{table}} WHERE `galaxy` = '" . $FleetRow['fleet_start_galaxy'] . "' AND `system` = '" . $FleetRow['fleet_start_system'] . "' AND `planet` = '" . $FleetRow['fleet_start_planet'] . "';", 'planets', true);
        $CurrentSpyLvl = $CurrentUser['spy_tech'];
        $TargetUser = doquery("SELECT * FROM {{table}} WHERE `id` = '" . $TargetUserID . "';", 'users', true);
        $TargetSpyLvl = $TargetUser['spy_tech'];
        $fleet = explode(";", $FleetRow['fleet_array']);
        $fquery = "";
        foreach ($fleet as $a => $b) {
            if ($b != '') {
                $a = explode(",", $b);
                $fquery .= "{$resource[$a[0]]}={$resource[$a[0]]} + {$a[1]}, \n";
                if ($FleetRow["fleet_mess"] != "1") {
                    if ($a[0] == "210") {
                        $LS = $a[1];
                        $QryTargetGalaxy = "SELECT * FROM {{table}} WHERE ";
                        $QryTargetGalaxy .= "`galaxy` = '" . $FleetRow['fleet_end_galaxy'] . "' AND ";
                        $QryTargetGalaxy .= "`system` = '" . $FleetRow['fleet_end_system'] . "' AND ";
                        $QryTargetGalaxy .= "`planet` = '" . $FleetRow['fleet_end_planet'] . "';";
                        $TargetGalaxy = doquery($QryTargetGalaxy, 'galaxy', true);
                        $CristalDebris = $TargetGalaxy['crystal'];
                        //$SpyToolDebris    = $LS * 300;
                        $SpyToolDebris = $LS * 10;
                        //减少撞击的渣土
                        $MaterialsInfo = SpyTarget($TargetPlanet, 0, $lang['sys_spy_maretials']);
                        $Materials = $MaterialsInfo['String'];
                        $PlanetFleetInfo = SpyTarget($TargetPlanet, 1, $lang['sys_spy_fleet']);
                        $PlanetFleet = $Materials;
                        $PlanetFleet .= $PlanetFleetInfo['String'];
                        $PlanetDefenInfo = SpyTarget($TargetPlanet, 2, $lang['sys_spy_defenses']);
                        $PlanetDefense = $PlanetFleet;
                        $PlanetDefense .= $PlanetDefenInfo['String'];
                        $PlanetBuildInfo = SpyTarget($TargetPlanet, 3, $lang['tech'][0]);
                        $PlanetBuildings = $PlanetDefense;
                        $PlanetBuildings .= $PlanetBuildInfo['String'];
                        $TargetTechnInfo = SpyTarget($TargetUser, 4, $lang['tech'][100]);
                        $TargetTechnos = $PlanetBuildings;
                        $TargetTechnos .= $TargetTechnInfo['String'];
                        $TargetForce = $PlanetFleetInfo['Count'] * $LS / 4;
                        if ($TargetForce > 100) {
                            $TargetForce = 100;
                        }
                        $TargetChances = rand(0, $TargetForce);
                        $SpyerChances = rand(0, 100);
                        if ($TargetChances >= $SpyerChances) {
                            $DestProba = sprintf($lang['sys_mess_spy_lostproba'], $TargetChances);
                        } elseif ($TargetChances < $SpyerChances) {
                            $DestProba = "<font color=\"red\">" . $lang['sys_mess_spy_destroyed'] . "</font>";
                        }
                        $AttackLink = "<center>";
                        $AttackLink .= "<a href=\"fleet.php?galaxy=" . $FleetRow['fleet_end_galaxy'] . "&system=" . $FleetRow['fleet_end_system'] . "";
                        $AttackLink .= "&planet=" . $FleetRow['fleet_end_planet'] . "";
                        $AttackLink .= "&target_mission=1";
                        $AttackLink .= " \">" . $lang['type_mission'][1] . "";
                        $AttackLink .= "</a></center>";
                        $MessageEnd = "<center>" . $DestProba . "</center>";
                        $pT = $TargetSpyLvl - $CurrentSpyLvl;
                        $pW = $CurrentSpyLvl - $TargetSpyLvl;
                        if ($TargetSpyLvl > $CurrentSpyLvl) {
                            $ST = $LS - pow($pT, 2);
                        }
                        if ($CurrentSpyLvl > $TargetSpyLvl) {
                            $ST = $LS + pow($pW, 2);
                        }
                        if ($TargetSpyLvl == $CurrentSpyLvl) {
                            $ST = $CurrentSpyLvl;
                        }
                        if ($ST <= "1") {
                            $SpyMessage = $Materials . "<br />" . $AttackLink . $MessageEnd;
                        }
                        if ($ST == "2") {
                            $SpyMessage = $PlanetFleet . "<br />" . $AttackLink . $MessageEnd;
                        }
                        if ($ST == "4" or $ST == "3") {
                            $SpyMessage = $PlanetDefense . "<br />" . $AttackLink . $MessageEnd;
                        }
                        if ($ST == "5" or $ST == "6") {
                            $SpyMessage = $PlanetBuildings . "<br />" . $AttackLink . $MessageEnd;
                        }
                        if ($ST >= "7") {
                            $SpyMessage = $TargetTechnos . "<br />" . $AttackLink . $MessageEnd;
                        }
                        SendSimpleMessage($CurrentUserID, '', $FleetRow['fleet_start_time'], 0, $lang['sys_mess_qg'], $lang['sys_mess_spy_report'], $SpyMessage);
                        $TargetMessage = $lang['sys_mess_spy_ennemyfleet'] . " " . $CurrentPlanet['name'];
                        $TargetMessage .= "<a href=\"galaxy.php?mode=3&galaxy=" . $CurrentPlanet["galaxy"] . "&system=" . $CurrentPlanet["system"] . "\">";
                        $TargetMessage .= "[" . $CurrentPlanet["galaxy"] . ":" . $CurrentPlanet["system"] . ":" . $CurrentPlanet["planet"] . "]</a> ";
                        $TargetMessage .= $lang['sys_mess_spy_seen_at'] . " " . $TargetPlanet['name'];
                        $TargetMessage .= " [" . $TargetPlanet["galaxy"] . ":" . $TargetPlanet["system"] . ":" . $TargetPlanet["planet"] . "].";
                        SendSimpleMessage($TargetUserID, '', $FleetRow['fleet_start_time'], 0, $lang['sys_mess_spy_control'], $lang['sys_mess_spy_activity'], $TargetMessage);
                    }
                    if ($TargetChances >= $SpyerChances) {
                        $QryUpdateGalaxy = "UPDATE {{table}} SET ";
                        $QryUpdateGalaxy .= "`crystal` = `crystal` + '" . (0 + $SpyToolDebris) . "' ";
                        $QryUpdateGalaxy .= "WHERE `id_planet` = '" . $TargetPlanet['id'] . "';";
                        doquery($QryUpdateGalaxy, 'galaxy');
                        //卫星碎片产生的废墟
                        doquery("DELETE FROM {{table}} WHERE `fleet_id` = '" . $FleetRow["fleet_id"] . "';", 'fleets');
                    } else {
                        doquery("UPDATE {{table}} SET `fleet_mess` = '1' WHERE `fleet_id` = '" . $FleetRow["fleet_id"] . "';", 'fleets');
                        $FleetRow['fleet_array'] = "";
                        //清空间谍卫星,可能存在BUG,如果是一支混合舰队?
                    }
                }
            } else {
                //舰队返回
                if ($FleetRow['fleet_end_time'] <= time()) {
                    RestoreFleetToPlanet($FleetRow, true);
                    doquery("DELETE FROM {{table}} WHERE `fleet_id` = " . $FleetRow["fleet_id"], 'fleets');
                }
            }
        }
    }
}
Ejemplo n.º 25
0
/**
 * MissionCaseRecycling.php
 *
 * @version 1.0
 * @copyright 2008 By Chlorel for XNova
 */
function MissionCaseRecycling($FleetRow)
{
    global $pricelist, $lang;
    if ($FleetRow["fleet_mess"] == 0) {
        if ($FleetRow['fleet_start_time'] <= time()) {
            $QrySelectGalaxy = "SELECT * FROM {{table}} ";
            $QrySelectGalaxy .= "WHERE ";
            $QrySelectGalaxy .= "`galaxy` = '" . $FleetRow['fleet_end_galaxy'] . "' AND ";
            $QrySelectGalaxy .= "`system` = '" . $FleetRow['fleet_end_system'] . "' AND ";
            $QrySelectGalaxy .= "`planet` = '" . $FleetRow['fleet_end_planet'] . "' ";
            $QrySelectGalaxy .= "LIMIT 1;";
            $TargetGalaxy = doquery($QrySelectGalaxy, 'galaxy', true);
            $FleetRecord = explode(";", $FleetRow['fleet_array']);
            $RecyclerCapacity = 0;
            $OtherFleetCapacity = 0;
            foreach ($FleetRecord as $Item => $Group) {
                if ($Group != '') {
                    $Class = explode(",", $Group);
                    if ($Class[0] == 209) {
                        $RecyclerCapacity += $pricelist[$Class[0]]["capacity"] * $Class[1];
                    } else {
                        $OtherFleetCapacity += $pricelist[$Class[0]]["capacity"] * $Class[1];
                    }
                }
                if ($Group != '') {
                    $Class = explode(",", $Group);
                    if ($Class[0] == 219) {
                        $RecyclerCapacity += $pricelist[$Class[0]]["capacity"] * $Class[1];
                    } else {
                        $OtherFleetCapacity += $pricelist[$Class[0]]["capacity"] * $Class[1];
                    }
                }
            }
            $IncomingFleetGoods = $FleetRow["fleet_resource_metal"] + $FleetRow["fleet_resource_crystal"] + $FleetRow["fleet_resource_deuterium"];
            if ($IncomingFleetGoods > $OtherFleetCapacity) {
                $RecyclerCapacity -= $IncomingFleetGoods - $OtherFleetCapacity;
            }
            if ($TargetGalaxy["metal"] + $TargetGalaxy["crystal"] <= $RecyclerCapacity) {
                $RecycledGoods["metal"] = $TargetGalaxy["metal"];
                $RecycledGoods["crystal"] = $TargetGalaxy["crystal"];
            } else {
                if ($TargetGalaxy["metal"] > $RecyclerCapacity / 2 and $TargetGalaxy["crystal"] > $RecyclerCapacity / 2) {
                    $RecycledGoods["metal"] = $RecyclerCapacity / 2;
                    $RecycledGoods["crystal"] = $RecyclerCapacity / 2;
                } else {
                    if ($TargetGalaxy["metal"] > $TargetGalaxy["crystal"]) {
                        $RecycledGoods["crystal"] = $TargetGalaxy["crystal"];
                        if ($TargetGalaxy["metal"] > $RecyclerCapacity - $RecycledGoods["crystal"]) {
                            $RecycledGoods["metal"] = $RecyclerCapacity - $RecycledGoods["crystal"];
                        } else {
                            $RecycledGoods["metal"] = $TargetGalaxy["metal"];
                        }
                    } else {
                        $RecycledGoods["metal"] = $TargetGalaxy["metal"];
                        if ($TargetGalaxy["crystal"] > $RecyclerCapacity - $RecycledGoods["metal"]) {
                            $RecycledGoods["crystal"] = $RecyclerCapacity - $RecycledGoods["metal"];
                        } else {
                            $RecycledGoods["crystal"] = $TargetGalaxy["crystal"];
                        }
                    }
                }
            }
            /*
            //Script Auto Reload
                              $page .= '<script type="text/javascript">
            
            	              var zeit = new Date();
            	              var ende = zeit.getTime();
            	              ende = ende + 100;
            
            	              function countdown() {
            
            		          var zeit2 = new Date();
            		          var jetzt = zeit2.getTime();
            
            		          if(jetzt >= ende) {
            
                  window.location.href="fleet.php";
            
            		            }
            
            	              }
            
            	             setInterval(countdown, 3000);
            
                           </script>';
                        //Script Auto Reload Ende
            */
            $NewCargo['Metal'] = $FleetRow["fleet_resource_metal"] + $RecycledGoods["metal"];
            $NewCargo['Crystal'] = $FleetRow["fleet_resource_crystal"] + $RecycledGoods["crystal"];
            $QryUpdateGalaxy = "UPDATE {{table}} SET ";
            $QryUpdateGalaxy .= "`metal` = `metal` - '" . $RecycledGoods["metal"] . "', ";
            $QryUpdateGalaxy .= "`crystal` = `crystal` - '" . $RecycledGoods["crystal"] . "' ";
            $QryUpdateGalaxy .= "WHERE ";
            $QryUpdateGalaxy .= "`galaxy` = '" . $FleetRow['fleet_end_galaxy'] . "' AND ";
            $QryUpdateGalaxy .= "`system` = '" . $FleetRow['fleet_end_system'] . "' AND ";
            $QryUpdateGalaxy .= "`planet` = '" . $FleetRow['fleet_end_planet'] . "' ";
            $QryUpdateGalaxy .= "LIMIT 1;";
            doquery($QryUpdateGalaxy, 'galaxy');
            $Message = sprintf($lang['sys_recy_gotten'], pretty_number($RecycledGoods["metal"]), $lang['Metal'], pretty_number($RecycledGoods["crystal"]), $lang['Crystal']);
            SendSimpleMessage($FleetRow['fleet_owner'], '', $FleetRow['fleet_start_time'], 4, $lang['sys_mess_tower'], $lang['sys_recy_report'], $Message);
            $QryUpdateFleet = "UPDATE {{table}} SET ";
            $QryUpdateFleet .= "`fleet_resource_metal` = '" . $NewCargo['Metal'] . "', ";
            $QryUpdateFleet .= "`fleet_resource_crystal` = '" . $NewCargo['Crystal'] . "', ";
            $QryUpdateFleet .= "`fleet_mess` = '1' ";
            $QryUpdateFleet .= "WHERE ";
            $QryUpdateFleet .= "`fleet_id` = '" . $FleetRow['fleet_id'] . "' ";
            $QryUpdateFleet .= "LIMIT 1;";
            doquery($QryUpdateFleet, 'fleets');
        }
    } else {
        if ($FleetRow['fleet_end_time'] <= time()) {
            // Mettre le message de retour de flotte
            $Message = sprintf($lang['sys_tran_mess_recback'], $TargetName, GetTargetAdressLink($FleetRow, ''), pretty_number($FleetRow['fleet_resource_metal']), $lang['Metal'], pretty_number($FleetRow['fleet_resource_crystal']), $lang['Crystal']);
            SendSimpleMessage($FleetRow['fleet_owner'], '', $FleetRow['fleet_end_time'], 4, $lang['sys_mess_tower'], $lang['sys_mess_fleetback'], $Message);
            RestoreFleetToPlanet($FleetRow, true);
            doquery("DELETE FROM {{table}} WHERE `fleet_id` = '" . $FleetRow["fleet_id"] . "';", 'fleets');
        }
    }
}