Kommunauty
Connexion
Inscription

Bug recyclage


arno Messages : 83

Bonjour,

j'utilise XG pryect , j'ai un bug au niveau du recyclage de ressources,

quand je lance mes recycleurs ,sa atteint bien son objectif et remplie ses soutes des ressoures, sauf que quand le temps du retour est terminé les recycleurs ne se pose pas et pas de message de retour

Donc je vais a la table de flotte et la je vois qu'elle est toujours en vole avec mes ressources,et le temps restant affiché est en négatif.Aussi j'envoi un autre recycleur aux meme coordonnée un fois attein les recycleurs d'avant se pose avec mes ressources ,sauf que l'autre envoyé reste bloqué .

Si quelqu'un m'a bien compris ,je voudrais de l'aide SVP.

je joint la mission recyclage:


<?php
private 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) && ($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"];
}
}
}

$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);

$QryUpdateFleet  = "UPDATE {{table}} SET ";
$QryUpdateFleet .= "`fleet_resource_metal` = `fleet_resource_metal` + '".$RecycledGoods["metal"]."', ";
$QryUpdateFleet .= "`fleet_resource_crystal` = `fleet_resource_crystal` + '".$RecycledGoods["crystal"]."', ";
$QryUpdateFleet .= "`fleet_mess` = '1' ";
$QryUpdateFleet .= "WHERE ";
$QryUpdateFleet .= "`fleet_id` = '".intval($FleetRow['fleet_id'])."' ";
$QryUpdateFleet .= "LIMIT 1;";
doquery( $QryUpdateFleet, 'fleets');
}
}
else
{
if ($FleetRow['fleet_end_time'] <= time())
{
$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);
$this->RestoreFleetToPlanet ( $FleetRow, true );
doquery("DELETE FROM {{table}} WHERE `fleet_id` = '". $FleetRow["fleet_id"] ."';", 'fleets');
}
}
}
?>

SendFleetBack.php


<?php
define('INSIDE'  , true);
define('INSTALL' , false);

$xgp_root = './';
include($xgp_root . 'extension.inc.php');
include($xgp_root . 'common.' . $phpEx);

if ( is_numeric($_POST['fleetid']) )
{
$fleetid  = intval($_POST['fleetid']);
$FleetRow = doquery("SELECT * FROM {{table}} WHERE `fleet_id` = '". $fleetid ."';", 'fleets', TRUE);
$i = 0;

if ($FleetRow['fleet_owner'] == $user['id'])
{
//now we can call back the ships in maintaing position (2).
if ($FleetRow['fleet_mess'] == 0 || $FleetRow['fleet_mess'] == 2)
{
if ($FleetRow['fleet_group'] > 0)
{
$Aks = doquery("SELECT teilnehmer FROM {{table}} WHERE id = '". $FleetRow['fleet_group'] ."';", 'aks', TRUE);
if ($Aks['teilnehmer'] == $FleetRow['fleet_owner'] AND $FleetRow['fleet_mission'] == 1)
{
doquery ("DELETE FROM {{table}} WHERE id ='". $FleetRow['fleet_group'] ."';", 'aks');
doquery ("UPDATE {{table}} SET `fleet_group` = '0' WHERE `fleet_group` = '". $FleetRow['fleet_group'] ."';", 'fleets');
}
if ($FleetRow['fleet_mission'] == 2)
{
doquery ("UPDATE {{table}} SET `fleet_group` = '0' WHERE `fleet_id` = '".  $fleetid ."';", 'fleets');
}
}

$CurrentFlyingTime = time() - $FleetRow['start_time'];

/*** start fix by jstar ***/
//the fleet time duration between 2 planet, it is equal for go and return when maintaining time=0
$fleetLeght = $FleetRow['fleet_start_time'] - $FleetRow['start_time'];
//the return time when you press "call back ships"
$ReturnFlyingTime  =
//if the ships mission is maintaining position and they are already in target pianet
( $FleetRow['fleet_end_stay'] != 0 && $CurrentFlyingTime > $fleetLeght )
//then the return time is the $fleetLeght + the current time in maintaining position
  ? $fleetLeght + time()
// else normal mission
  : $CurrentFlyingTime + time();
/***end fix by jstar***/

$QryUpdateFleet  = "UPDATE {{table}} SET ";
$QryUpdateFleet .= "`fleet_start_time` = '". (time() - 1) ."', ";
$QryUpdateFleet .= "`fleet_end_stay` = '0', ";
$QryUpdateFleet .= "`fleet_end_time` = '". ($ReturnFlyingTime + 1) ."', ";
$QryUpdateFleet .= "`fleet_target_owner` = '". $user['id'] ."', ";
$QryUpdateFleet .= "`fleet_mess` = '1' ";
$QryUpdateFleet .= "WHERE ";
$QryUpdateFleet .= "`fleet_id` = '" . $fleetid . "';";
doquery( $QryUpdateFleet, 'fleets');
}
}
}
header("location:game.php?page=fleet");
?>

FleetAjax.php:


<?php
define('INSIDE'  , true);
define('INSTALL' , false);

$xgp_root = './';
include($xgp_root . 'extension.inc.php');
include($xgp_root . 'common.' . $phpEx);

$UserSpyProbes  = $planetrow['spy_sonde'];
$UserRecycles   = $planetrow['recycler'];
$UserDeuterium  = $planetrow['deuterium'];
$UserMissiles   = $planetrow['interplanetary_misil'];

$fleet          = array();
$speedalls      = array();
$PartialFleet   = false;
$PartialCount   = 0;

foreach ($reslist['fleet'] as $Node => $ShipID)
{
$TName = "ship".$ShipID;
if ($ShipID > 200 && $ShipID < 300 && $_POST[$TName] > 0)
{
if ($_POST[$TName] > $planetrow[$resource[$ShipID]])
{
$fleet['fleetarray'][$ShipID]   = $planetrow[$resource[$ShipID]];
$fleet['fleetlist']            .= $ShipID .",". $planetrow[$resource[$ShipID]] .";";
$fleet['amount']               += $planetrow[$resource[$ShipID]];
$PartialCount                  += $planetrow[$resource[$ShipID]];
$PartialFleet                   = true;
}
else
{
$fleet['fleetarray'][$ShipID]   = $_POST[$TName];
$fleet['fleetlist']            .= $ShipID .",". $_POST[$TName] .";";
$fleet['amount']               += $_POST[$TName];
$speedalls[$ShipID]             = $_POST[$TName];
}
}
}

if ($PartialFleet == true)
{
if ( $PartialCount < 1 )
{
$ResultMessage = "610; ".$lang['fa_not_enough_probes']." |".$CurrentFlyingFleets." ".$UserSpyProbes." ".$UserRecycles." ".$UserMissiles;
die ($ResultMessage);
}
}

$PrNoob      = $game_config['noobprotection'];
$PrNoobTime  = $game_config['noobprotectiontime'];
$PrNoobMulti = $game_config['noobprotectionmulti'];

$galaxy          = intval($_POST['galaxy']);
if ($galaxy > MAX_GALAXY_IN_WORLD || $galaxy < 1)
{
$ResultMessage = "602; ".$lang['fa_galaxy_not_exist']." |".$CurrentFlyingFleets." ".$UserSpyProbes." ".$UserRecycles." ".$UserMissiles;
die ( $ResultMessage );
}

$system = intval($_POST['system']);

if ($system > MAX_SYSTEM_IN_GALAXY || $system < 1)
{
$ResultMessage = "602; ".$lang['fa_system_not_exist']." |".$CurrentFlyingFleets." ".$UserSpyProbes." ".$UserRecycles." ".$UserMissiles;
die ( $ResultMessage );
}

$planet = intval($_POST['planet']);

if ($planet > MAX_PLANET_IN_SYSTEM || $planet < 1)
{
$ResultMessage = "602; ".$lang['fa_planet_not_exist']." |".$CurrentFlyingFleets." ".$UserSpyProbes." ".$UserRecycles." ".$UserMissiles;
die ( $ResultMessage );
}
if ($UserDeuterium < 1)
{
$ResultMessage = "613; ".$lang['fa_not_enough_fuel']." |".$CurrentFlyingFleets." ".$UserSpyProbes." ".$UserRecycles." ".$UserMissiles;
die ( $ResultMessage );
}
$FleetArray = $fleet['fleetarray'];

$CurrentFlyingFleets = doquery("SELECT COUNT(fleet_id) AS `Nbre` FROM {{table}} WHERE `fleet_owner` = '".$user['id']."';", 'fleets', true);
$CurrentFlyingFleets = $CurrentFlyingFleets["Nbre"];

$QrySelectEnemy  = "SELECT * FROM {{table}} ";
$QrySelectEnemy .= "WHERE ";
$QrySelectEnemy .= "`galaxy` = '". $_POST['galaxy'] ."' AND ";
$QrySelectEnemy .= "`system` = '". $_POST['system'] ."' AND ";
$QrySelectEnemy .= "`planet` = '". $_POST['planet'] ."' AND ";
$QrySelectEnemy .= "`planet_type` = '". $_POST['planettype'] ."';";
$TargetRow = doquery( $QrySelectEnemy, 'planets', true);

if ($TargetRow['id_owner'] == '')
$TargetUser = $user;
elseif ($TargetRow['id_owner'] != '')
$TargetUser = doquery("SELECT * FROM {{table}} WHERE `id` = '". $TargetRow['id_owner'] ."';", 'users', true);


$UserPoints    = doquery("SELECT * FROM {{table}} WHERE `stat_type` = '1' AND `stat_code` = '1' AND `id_owner` = '". $user['id'] ."';", 'statpoints', true);
$User2Points   = doquery("SELECT * FROM {{table}} WHERE `stat_type` = '1' AND `stat_code` = '1' AND `id_owner` = '". $TargetUser['id'] ."';", 'statpoints', true);

$CurrentPoints = $UserPoints['total_points'];
$TargetPoints  = $User2Points['total_points'];

$TargetVacat   = $TargetUser['urlaubs_modus'];

if ((($user[$resource[108]] + 1) + ($user['rpg_commandant'] * COMMANDANT)) <= $CurrentFlyingFleets)
{
$ResultMessage = "612; ".$lang['fa_no_more_slots']." |".$CurrentFlyingFleets." ".$UserSpyProbes." ".$UserRecycles." ".$UserMissiles;
die ($ResultMessage);
}

if (!is_array($FleetArray))
{
$ResultMessage = "618; ".$lang['fa_no_recyclers']." |".$CurrentFlyingFleets." ".$UserSpyProbes." ".$UserRecycles." ".$UserMissiles;
die ($ResultMessage);
}

if (!(($_POST["mission"] == 6) OR ($_POST["mission"] == 8)))
{
$ResultMessage = "618; ".$lang['fa_mission_not_available']." |".$CurrentFlyingFleets." ".$UserSpyProbes." ".$UserRecycles." ".$UserMissiles;
die ($ResultMessage);
}

foreach ($FleetArray as $Ships => $Count)
{
if ($Count > $planetrow[$resource[$Ships]])
{
$ResultMessage = "611; ".$lang['fa_no_ships']." |".$CurrentFlyingFleets." ".$UserSpyProbes." ".$UserRecycles." ".$UserMissiles;
die ( $ResultMessage );
}
}

if ($PrNoobTime < 1)
$PrNoobTime = 9999999999999999;

if ($TargetVacat && $_POST['mission'] != 8)
{
$ResultMessage = "605; ".$lang['fa_vacation_mode']." |".$CurrentFlyingFleets." ".$UserSpyProbes." ".$UserRecycles." ".$UserMissiles;
die ($ResultMessage);
}

if($user['urlaubs_modus'])
{
$ResultMessage = "620; ".$lang['fa_vacation_mode_current']." |".$CurrentFlyingFleets." ".$UserSpyProbes." ".$UserRecycles." ".$UserMissiles;
die ($ResultMessage);
}

if($TargetUser['onlinetime'] >= (time()-60 * 60 * 24 * 7))
{
if ($CurrentPoints > ($TargetPoints * $PrNoobMulti) && $TargetRow['id_owner'] != '' && $_POST['mission'] == 6  && $PrNoob == 1  && $TargetPoints < ($PrNoobTime * 1000))
{
$ResultMessage = "603; ".$lang['fa_week_player']." |".$CurrentFlyingFleets." ".$UserSpyProbes." ".$UserRecycles." ".$UserMissiles;
die ( $ResultMessage );
}

if ($TargetPoints > ($CurrentPoints * $PrNoobMulti) && $TargetRow['id_owner'] != '' && $_POST['mission'] == 6  && $PrNoob == 1  && $CurrentPoints < ($PrNoobTime * 1000))
{
$ResultMessage = "604; ".$lang['fa_strong_player']." |".$CurrentFlyingFleets." ".$UserSpyProbes." ".$UserRecycles." ".$UserMissiles;
die ( $ResultMessage );
}
}

if ($TargetRow['id_owner'] == '' && $_POST['mission'] != 8 )
{
$ResultMessage = "601; ".$lang['fa_planet_not_exist']." |".$CurrentFlyingFleets." ".$UserSpyProbes." ".$UserRecycles." ".$UserMissiles;
die ($ResultMessage);
}

if (($TargetRow["id_owner"] == $planetrow["id_owner"]) && ($_POST["mission"] == 6))
{
$ResultMessage = "618; ".$lang['fa_not_spy_yourself']." |".$CurrentFlyingFleets." ".$UserSpyProbes." ".$UserRecycles." ".$UserMissiles;
die ( $ResultMessage );
}

if ($_POST['thisgalaxy'] != $planetrow['galaxy'] |
$_POST['thissystem'] != $planetrow['system'] |
$_POST['thisplanet'] != $planetrow['planet'] |
$_POST['thisplanettype'] != $planetrow['planet_type'])
{
$ResultMessage = "618; ".$lang['fa_not_attack_yourself']." |".$CurrentFlyingFleets." ".$UserSpyProbes." ".$UserRecycles." ".$UserMissiles;
die ($ResultMessage);
}

$Distance    = GetTargetDistance ($_POST['thisgalaxy'], $_POST['galaxy'], $_POST['thissystem'], $_POST['system'], $_POST['thisplanet'], $_POST['planet']);
$speedall    = GetFleetMaxSpeed ($FleetArray, 0, $user);
$SpeedAllMin = min($speedall);
$Duration    = GetMissionDuration ( 10, $SpeedAllMin, $Distance, GetGameSpeedFactor ());

$fleet['fly_time']   = $Duration;
$fleet['start_time'] = $Duration + time();
$fleet['end_time']   = ($Duration * 2) + time();

$FleetShipCount      = 0;
$FleetDBArray        = "";
$FleetSubQRY         = "";
$consumption         = 0;
$SpeedFactor         = GetGameSpeedFactor ();
foreach ($FleetArray as $Ship => $Count)
{
$ShipSpeed        = $pricelist[$Ship]["speed"];
$spd              = 35000 / ($Duration * $SpeedFactor - 10) * sqrt($Distance * 10 / $ShipSpeed);
$basicConsumption = $pricelist[$Ship]["consumption"] * $Count ;
$consumption     += $basicConsumption * $Distance / 35000 * (($spd / 10) + 1) * (($spd / 10) + 1);
$FleetShipCount  += $Count;
$FleetDBArray    .= $Ship .",". $Count .";";
$FleetSubQRY     .= "`".$resource[$Ship] . "` = `" . $resource[$Ship] . "` - " . $Count . " , ";
}
$consumption = round($consumption) + 1;

if ($TargetRow['id_level'] > $user['authlevel'])
{
$Allowed = true;
switch ($_POST['mission'])
{
case 1:
case 2:
case 6:
case 9:
$Allowed = false;
break;
case 3:
case 4:
case 5:
case 7:
case 8:
case 15:
break;
default:
}
if ($Allowed == false)
{
$ResultMessage = "619; ".$lang['fa_action_not_allowed']." |".$CurrentFlyingFleets." ".$UserSpyProbes." ".$UserRecycles." ".$UserMissiles;
die ( $ResultMessage );
}
}

$QryInsertFleet  = "INSERT INTO {{table}} SET ";
$QryInsertFleet .= "`fleet_owner` = '". $user['id'] ."', ";
$QryInsertFleet .= "`fleet_mission` = '". intval($_POST['mission']) ."', ";
$QryInsertFleet .= "`fleet_amount` = '". $FleetShipCount ."', ";
$QryInsertFleet .= "`fleet_array` = '". $FleetDBArray ."', ";
$QryInsertFleet .= "`fleet_start_time` = '". $fleet['start_time']. "', ";
$QryInsertFleet .= "`fleet_start_galaxy` = '". intval($_POST['thisgalaxy']) ."', ";
$QryInsertFleet .= "`fleet_start_system` = '". intval($_POST['thissystem']) ."', ";
$QryInsertFleet .= "`fleet_start_planet` = '". intval($_POST['thisplanet']) ."', ";
$QryInsertFleet .= "`fleet_start_type` = '". intval($_POST['thisplanettype']) ."', ";
$QryInsertFleet .= "`fleet_end_time` = '". $fleet['end_time'] ."', ";
$QryInsertFleet .= "`fleet_end_galaxy` = '". intval($_POST['galaxy']) ."', ";
$QryInsertFleet .= "`fleet_end_system` = '". intval($_POST['system']) ."', ";
$QryInsertFleet .= "`fleet_end_planet` = '". intval($_POST['planet']) ."', ";
$QryInsertFleet .= "`fleet_end_type` = '". intval($_POST['planettype']) ."', ";
$QryInsertFleet .= "`fleet_target_owner` = '". $TargetRow['id_owner'] ."', ";
$QryInsertFleet .= "`start_time` = '" . time() . "';";
doquery( $QryInsertFleet, 'fleets');

$UserDeuterium   -= $consumption;

if($UserDeuterium < 0)
exit();

$QryUpdatePlanet  = "UPDATE {{table}} SET ";
$QryUpdatePlanet .= $FleetSubQRY;
$QryUpdatePlanet .= "`deuterium` = '".$UserDeuterium."' " ;
$QryUpdatePlanet .= "WHERE ";
$QryUpdatePlanet .= "`id` = '". $planetrow['id'] ."';";
doquery( $QryUpdatePlanet, 'planets');

$CurrentFlyingFleets++;

$planetrow = doquery("SELECT * FROM {{table}} WHERE `id` = '". $user['current_planet'] ."';", 'planets', true);
$ResultMessage  = "600; ".$lang['fa_sending']." ". $FleetShipCount  ." ". $lang['tech'][$Ship] ." a ". $_POST['galaxy'] .":". $_POST['system'] .":". $_POST['planet'] ."...|";
$ResultMessage .= $CurrentFlyingFleets ." ".$UserSpyProbes." ".$UserRecycles." ".$UserMissiles;

die ($ResultMessage);
?>

ShowFleet3Page.php


<?php
function ShowFleet3Page($CurrentUser, $CurrentPlanet)
{
global $resource, $pricelist, $reslist, $phpEx, $lang, $xgp_root, $game_config;
include_once($xgp_root . 'includes/functions/IsVacationMode.' . $phpEx);

$parse = $lang;

if (IsVacationMode($CurrentUser))
exit(message($lang['fl_vacation_mode_active'],"game.php?page=overview",2));

$fleet_group_mr = 0;
if($_POST['fleet_group'] > 0)
{
if($_POST['mission'] == 2)
{
$target = "g".$_POST["galaxy"]."s".$_POST["system"]."p".$_POST["planet"]."t".$_POST["planettype"];
if($_POST['acs_target_mr'] == $target)
{
$aks_count_mr = doquery("SELECT * FROM {{table}} WHERE id = '".$_POST['fleet_group']."'",'aks');
if (mysql_num_rows($aks_count_mr) > 0)
$fleet_group_mr = $_POST['fleet_group'];
}
}
}

if(($_POST['fleet_group'] == 0) && ($_POST['mission'] == 2))
$_POST['mission'] = 1;


$TargetPlanet   = doquery("SELECT `id_owner`,`id_level`,`destruyed`,`ally_deposit` FROM {{table}} WHERE `galaxy` = '". $_POST['galaxy'] ."' AND
 `system` = '". $_POST['system'] ."' AND `planet` = '". $_POST['planet'] ."' AND `planet_type` = '". $_POST['planettype'] ."';", 'planets', true);
$MyDBRec        = doquery("SELECT `id`,`onlinetime`,`ally_id`,`urlaubs_modus` FROM {{table}} WHERE `id` = '". $CurrentUser['id']."';", 'users', true);

$protection       = $game_config['noobprotection'];
$protectiontime   = $game_config['noobprotectiontime'];
$protectionmulti = $game_config['noobprotectionmulti'];

if ($protectiontime < 1)
$protectiontime = 9999999999999999;

$fleetarray  = unserialize(base64_decode(str_rot13($_POST["usedfleet"])));

if($TargetPlanet["destruyed"] != 0)
exit(header("Location: game.php?page=fleet"));

if (!is_array($fleetarray))
exit(header("Location: game.php?page=fleet"));

foreach ($fleetarray as $Ship => $Count)
{
if ($Count > $CurrentPlanet[$resource[$Ship]])
exit(header("location:game." . $phpEx . "?page=fleet"));
}

$error              = 0;
$galaxy             = intval($_POST['galaxy']);
$system             = intval($_POST['system']);
$planet             = intval($_POST['planet']);
$planettype         = intval($_POST['planettype']);
$fleetmission       = $_POST['mission'];

if ($planettype != 1 && $planettype != 2 && $planettype != 3)
exit(header("location:game." . $phpEx . "?page=fleet"));

if ($fleetmission == 8)
{
$YourPlanet = false;
$UsedPlanet = false;
$select     = doquery("SELECT * FROM {{table}} WHERE galaxy = '". $galaxy ."' AND system = '". $system ."' AND planet = '". $planet ."'", "planets");
}
else
{
$YourPlanet = false;
$UsedPlanet = false;
$select     = doquery("SELECT * FROM {{table}} WHERE galaxy = '". $galaxy ."' AND system = '". $system ."' AND planet = '". $planet ."' AND planet_type = '". $planettype ."'", "planets");
}

if ($CurrentPlanet['galaxy'] == $galaxy && $CurrentPlanet['system'] == $system &&
$CurrentPlanet['planet'] == $planet && $CurrentPlanet['planet_type'] == $planettype)
exit(header("location:game." . $phpEx . "?page=fleet"));
if ($_POST['mission'] == 11)
{
$maxexpde   = mysql_result(doquery("SELECT COUNT(*) FROM {{table}} WHERE `fleet_owner` = '".$CurrentUser['id']."' AND `fleet_mission` = '11';", 'fleets'),0);

if ($maxexpde != 0)
message ("<font color=\"red\"><b>".$lang['fl_expedition_fleets_limit']."</b></font>", "game." . $phpEx . "?page=fleet", 2);
}
if ($_POST['mission'] != 15)
{
if (mysql_num_rows($select) < 1 && $fleetmission != 7)
exit(header("location:game." . $phpEx . "?page=fleet"));
elseif ($fleetmission == 9 && mysql_num_rows($select) < 1)
exit(header("location:game." . $phpEx . "?page=fleet"));
}
else
{
$MaxExpedition      = $CurrentUser[$resource[124]];

if ($MaxExpedition >= 1)
{
$maxexpde   = doquery("SELECT COUNT(fleet_owner) AS `expedi` FROM {{table}} WHERE
`fleet_owner` = '".$CurrentUser['id']."' AND `fleet_mission` = '15';", 'fleets', true);
$ExpeditionEnCours  = $maxexpde['expedi'];
$EnvoiMaxExpedition = 1 + floor( $MaxExpedition / 3 );
}
else
{
$ExpeditionEnCours = 0;
$EnvoiMaxExpedition = 0;
}

if($EnvoiMaxExpedition == 0 )
message ("<font color=\"red\"><b>".$lang['fl_expedition_tech_required']."</b></font>", "game." . $phpEx . "?page=fleet", 2);
elseif ($ExpeditionEnCours >= $EnvoiMaxExpedition )
message ("<font color=\"red\"><b>".$lang['fl_expedition_fleets_limit']."</b></font>", "game." . $phpEx . "?page=fleet", 2);
}

$select = mysql_fetch_array($select);

if ($select['id_owner'] == $CurrentUser['id'])
{
$YourPlanet = true;
$UsedPlanet = true;
}
elseif (!empty($select['id_owner']))
{
$YourPlanet = false;
$UsedPlanet = true;
}
else
{
$YourPlanet = false;
$UsedPlanet = false;
}

if (empty($fleetmission))
exit(header("location:game." . $phpEx . "?page=fleet"));

if ($TargetPlanet['id_owner'] == '')
$HeDBRec = $MyDBRec;
elseif ($TargetPlanet['id_owner'] != '')
$HeDBRec = doquery("SELECT `id`,`onlinetime`,`ally_id`,`urlaubs_modus` FROM {{table}} WHERE `id` = '". $TargetPlanet['id_owner'] ."';", 'users', true);

$UserPoints    = doquery("SELECT `total_points` FROM {{table}} WHERE `stat_type` = '1' AND `stat_code` = '1' AND `id_owner` = '". $MyDBRec['id'] ."';", 'statpoints', true);
$User2Points   = doquery("SELECT `total_points` FROM {{table}} WHERE `stat_type` = '1' AND `stat_code` = '1' AND `id_owner` = '". $HeDBRec['id'] ."';", 'statpoints', true);

$MyGameLevel  = $UserPoints['total_points'];
$HeGameLevel  = $User2Points['total_points'];

if($HeDBRec['onlinetime'] >= (time()-60 * 60 * 24 * 7))
{
if ($MyGameLevel > ($HeGameLevel * $protectionmulti)
&& $TargetPlanet['id_owner'] != ''
&& ($_POST['mission'] == 1 or $_POST['mission'] == 6 or $_POST['mission'] == 9)
&& $protection == 1
&& $HeGameLevel < ($protectiontime * 1000))
message("<font color=\"lime\"><b>".$lang['fl_week_player']."</b></font>", "game." . $phpEx . "?page=fleet", 2);

if (($MyGameLevel * $protectionmulti) < $HeGameLevel
&& $TargetPlanet['id_owner'] != ''
&& ($_POST['mission'] == 1 or $_POST['mission'] == 5 or $_POST['mission'] == 6 or $_POST['mission'] == 9)
&& $protection == 1
&& $MyGameLevel < ($protectiontime * 1000))
message("<font color=\"red\"><b>".$lang['fl_strong_player']."</b></font>", "game." . $phpEx . "?page=fleet", 2);
}

if ($HeDBRec['urlaubs_modus'] && $_POST['mission'] != 8)
message("<font color=\"lime\"><b>".$lang['fl_in_vacation_player']."</b></font>", "game." . $phpEx . "?page=fleet", 2);

$FlyingFleets = mysql_fetch_assoc(doquery("SELECT COUNT(fleet_id) as Number FROM {{table}} WHERE `fleet_owner`='".intval($CurrentUser['id'])."'", 'fleets'));
$ActualFleets = $FlyingFleets["Number"];

if ((1 + $CurrentUser[$resource[108]]) + ($CurrentUser['rpg_commandant'] * COMMANDANT) <= $ActualFleets)
{
message($lang['fl_no_slots'], "game." . $phpEx . "?page=fleet", 1);
}

if ($_POST['resource1'] + $_POST['resource2'] + $_POST['resource3'] < 1 && $_POST['mission'] == 3)
message("<font color=\"lime\"><b>".$lang['fl_empty_transport']."</b></font>", "game." . $phpEx . "?page=fleet", 1);

if ($_POST['mission'] != 15)
{
if ($TargetPlanet['id_owner'] == '' && $_POST['mission'] < 7)
exit(header("location:game." . $phpEx . "?page=fleet"));

if ($TargetPlanet['id_owner'] != '' && $_POST['mission'] == 7)
message ("<font color=\"red\"><b>".$lang['fl_planet_populed']."</b></font>", "game." . $phpEx . "?page=fleet", 2);

if ($HeDBRec['ally_id'] != $MyDBRec['ally_id'] && $_POST['mission'] == 4)
message ("<font color=\"red\"><b>".$lang['fl_stay_not_on_enemy']."</b></font>", "game." . $phpEx . "?page=fleet", 2);

if ($TargetPlanet['ally_deposit'] < 1 && $HeDBRec != $MyDBRec && $_POST['mission'] == 5)
message ("<font color=\"red\"><b>".$lang['fl_not_ally_deposit']."</b></font>", "game." . $phpEx . "?page=fleet", 2);

if (($TargetPlanet["id_owner"] == $CurrentPlanet["id_owner"]) && (($_POST["mission"] == 1) or ($_POST["mission"] == 6)))
exit(header("location:game." . $phpEx . "?page=fleet"));

if (($TargetPlanet["id_owner"] != $CurrentPlanet["id_owner"]) && ($_POST["mission"] == 4))
message ("<font color=\"red\"><b>".$lang['fl_deploy_only_your_planets']."</b></font>","game." . $phpEx . "?page=fleet", 2);
}

$missiontype = array(
1 => $lang['type_mission'][1],
2 => $lang['type_mission'][2],
3 => $lang['type_mission'][3],
4 => $lang['type_mission'][4],
5 => $lang['type_mission'][5],
6 => $lang['type_mission'][6],
7 => $lang['type_mission'][7],
8 => $lang['type_mission'][8],
9 => $lang['type_mission'][9],
11 => $lang['type_mission'][11],
15 => $lang['type_mission'][15],
);

$speed_possible = array(10, 9, 8, 7, 6, 5, 4, 3, 2, 1);
$AllFleetSpeed  = GetFleetMaxSpeed ($fleetarray, 0, $CurrentUser);
$GenFleetSpeed  = $_POST['speed'];
$SpeedFactor    = $_POST['speedfactor'];
$MaxFleetSpeed  = min($AllFleetSpeed);

if (!in_array($GenFleetSpeed, $speed_possible))
exit(header("location:game." . $phpEx . "?page=fleet"));

if ($MaxFleetSpeed != $_POST['speedallsmin'])
exit(header("location:game." . $phpEx . "?page=fleet"));

if (!$_POST['planettype'])
exit(header("location:game." . $phpEx . "?page=fleet"));

if (!$_POST['galaxy'] || !is_numeric($_POST['galaxy']) || $_POST['galaxy'] > MAX_GALAXY_IN_WORLD || $_POST['galaxy'] < 1)
exit(header("location:game." . $phpEx . "?page=fleet"));

if (!$_POST['system'] || !is_numeric($_POST['system']) || $_POST['system'] > MAX_SYSTEM_IN_GALAXY || $_POST['system'] < 1)
exit(header("location:game." . $phpEx . "?page=fleet"));

if (!$_POST['planet'] || !is_numeric($_POST['planet']) || $_POST['planet'] > (MAX_PLANET_IN_SYSTEM + 1) || $_POST['planet'] < 1)
exit(header("location:game." . $phpEx . "?page=fleet"));

if ($_POST['thisgalaxy'] != $CurrentPlanet['galaxy'] |
$_POST['thissystem'] != $CurrentPlanet['system'] |
$_POST['thisplanet'] != $CurrentPlanet['planet'] |
$_POST['thisplanettype'] != $CurrentPlanet['planet_type'])
exit(header("location:game." . $phpEx . "?page=fleet"));

if (!isset($fleetarray))
exit(header("location:game." . $phpEx . "?page=fleet"));

$distance      = GetTargetDistance($_POST['thisgalaxy'], $_POST['galaxy'], $_POST['thissystem'], $_POST['system'], $_POST['thisplanet'], $_POST['planet']);
$duration      = GetMissionDuration($GenFleetSpeed, $MaxFleetSpeed, $distance, $SpeedFactor);
$consumption   = GetFleetConsumption($fleetarray, $SpeedFactor, $duration, $distance, $MaxFleetSpeed, $CurrentUser);

$fleet['start_time'] = $duration + time();
if ($_POST['mission'] == 15)
{
$StayDuration    = $_POST['expeditiontime'] * 3600;
$StayTime        = $fleet['start_time'] + $_POST['expeditiontime'] * 3600;
}
elseif ($_POST['mission'] == 5)
{
$StayDuration    = $_POST['holdingtime'] * 3600;
$StayTime        = $fleet['start_time'] + $_POST['holdingtime'] * 3600;
}
elseif ($_POST['mission'] == 11)
{
$StayDuration    = 3600;
$StayTime        = $fleet['start_time'] + 3600;
}
else
{
$StayDuration    = 0;
$StayTime        = 0;
}

$fleet['end_time']   = $StayDuration + (2 * $duration) + time();
$FleetStorage        = 0;
$FleetShipCount      = 0;
$fleet_array         = "";
$FleetSubQRY         = "";

foreach ($fleetarray as $Ship => $Count)
{
$FleetStorage    += $pricelist[$Ship]["capacity"] * $Count;
$FleetShipCount  += $Count;
$fleet_array     .= $Ship .",". $Count .";";
$FleetSubQRY     .= "`".$resource[$Ship] . "` = `" . $resource[$Ship] . "` - " . $Count . ", ";
}

$FleetStorage        -= $consumption;
$StorageNeeded        = 0;

$_POST['resource1'] = max(0, (float)trim($_POST['resource1']));
$_POST['resource2'] = max(0, (float)trim($_POST['resource2']));
$_POST['resource3'] = max(0, (float)trim($_POST['resource3']));

if ($_POST['resource1'] < 1)
$TransMetal      = 0;
else
{
$TransMetal      = $_POST['resource1'];
$StorageNeeded  += $TransMetal;
}

if ($_POST['resource2'] < 1)
$TransCrystal    = 0;
else
{
$TransCrystal    = $_POST['resource2'];
$StorageNeeded  += $TransCrystal;
}
if ($_POST['resource3'] < 1)
$TransDeuterium  = 0;
else
{
$TransDeuterium  = $_POST['resource3'];
$StorageNeeded  += $TransDeuterium;
}

$StockMetal      = $CurrentPlanet['metal'];
$StockCrystal    = $CurrentPlanet['crystal'];
$StockDeuterium  = $CurrentPlanet['deuterium'];
$StockDeuterium -= $consumption;

$StockOk         = false;
if ($StockMetal >= $TransMetal)
if ($StockCrystal >= $TransCrystal)
if ($StockDeuterium >= $TransDeuterium)
$StockOk         = true;
if (!$StockOk)
message ("<font color=\"red\"><b>". $lang['fl_no_enought_deuterium'] . pretty_number($consumption) ."</b></font>", "game." . $phpEx . "?page=fleet", 2);

if ( $StorageNeeded > $FleetStorage)
message ("<font color=\"red\"><b>". $lang['fl_no_enought_cargo_capacity'] . pretty_number($StorageNeeded - $FleetStorage) ."</b></font>", "game." . $phpEx . "?page=fleet", 2);

if ($TargetPlanet['id_level'] > $CurrentUser['authlevel'] && $game_config['adm_attack'] == 0)
message($lang['fl_admins_cannot_be_attacked'], "game." . $phpEx . "?page=fleet",2);

if ($fleet_group_mr != 0)
{
$AksStartTime = mysql_fetch_array(doquery("SELECT MAX(`fleet_start_time`) AS Start,
 MAX(`fleet_end_time`) AS End FROM {{table}} WHERE `fleet_group` = '". $fleet_group_mr . "';", 'fleets'));

if ($AksStartTime['Start'] > $fleet['start_time'])
{
$fleet['start_time'] = $AksStartTime['Start'] + 1;
$fleet['end_time'] = $AksStartTime['End'] + 1;
}
else
{
$AksTime = mysql_fetch_array(doquery("SELECT fleet_start_time, fleet_end_time FROM {{table}} WHERE `fleet_group` = '". $fleet_group_mr . "' AND `fleet_mission` = '1';", 'fleets'));

if ($AksTime['fleet_start_time'] < $fleet['start_time'])
{
$QryUpdateFleets = "UPDATE {{table}} SET ";
$QryUpdateFleets .= "`fleet_start_time` = '". $fleet['start_time'] ."', ";
$QryUpdateFleets .= "`fleet_end_time` = '". $fleet['end_time'] ."' ";
$QryUpdateFleets .= "WHERE ";
$QryUpdateFleets .= "`fleet_group` = '". $fleet_group_mr ."' AND ";
$QryUpdateFleets .= "`fleet_mission` = '1';";
doquery($QryUpdateFleets, "fleets");
$SelectFleets = doquery("SELECT * FROM {{table}} WHERE `fleet_group` = '". $fleet_group_mr . "' AND `fleet_mission` = '2' ORDER BY `fleet_id` ASC ;", 'fleets');
$nb = mysql_num_rows($SelectFleets);
$i = 0;
if ($nb > 0)
{
while ($row = mysql_fetch_array($SelectFleets))
{
$i++;
$row['fleet_start_time'] = $fleet['start_time'] + $i;
$row['fleet_end_time'] = $fleet['end_time'] + $i;
$QryUpdateFleets = "UPDATE {{table}} SET ";
$QryUpdateFleets .= "`fleet_start_time` = '". $row['fleet_start_time'] ."', ";
$QryUpdateFleets .= "`fleet_end_time` = '". $row['fleet_end_time'] ."' ";
$QryUpdateFleets .= "WHERE ";
$QryUpdateFleets .= "`fleet_id` = '". $row['fleet_id'] ."';";
doquery($QryUpdateFleets, "fleets");
}
}

$fleet['start_time'] = $fleet['start_time'] + $nb + 1;
$fleet['end_time'] = $fleet['end_time'] + $nb + 1;
}
}
}

$QryInsertFleet  = "INSERT INTO {{table}} SET ";
$QryInsertFleet .= "`fleet_owner` = '". $CurrentUser['id'] ."', ";
$QryInsertFleet .= "`fleet_mission` = '". $_POST['mission'] ."', ";
$QryInsertFleet .= "`fleet_amount` = '". $FleetShipCount ."', ";
$QryInsertFleet .= "`fleet_array` = '". $fleet_array ."', ";
$QryInsertFleet .= "`fleet_start_time` = '". $fleet['start_time'] ."', ";
$QryInsertFleet .= "`fleet_start_galaxy` = '". intval($_POST['thisgalaxy']) ."', ";
$QryInsertFleet .= "`fleet_start_system` = '". intval($_POST['thissystem']) ."', ";
$QryInsertFleet .= "`fleet_start_planet` = '". intval($_POST['thisplanet']) ."', ";
$QryInsertFleet .= "`fleet_start_type` = '". intval($_POST['thisplanettype']) ."', ";
$QryInsertFleet .= "`fleet_end_time` = '". $fleet['end_time'] ."', ";
$QryInsertFleet .= "`fleet_end_stay` = '". $StayTime ."', ";
$QryInsertFleet .= "`fleet_end_galaxy` = '". intval($_POST['galaxy']) ."', ";
$QryInsertFleet .= "`fleet_end_system` = '". intval($_POST['system']) ."', ";
$QryInsertFleet .= "`fleet_end_planet` = '". intval($_POST['planet']) ."', ";
$QryInsertFleet .= "`fleet_end_type` = '". intval($_POST['planettype']) ."', ";
$QryInsertFleet .= "`fleet_resource_metal` = '". $TransMetal ."', ";
$QryInsertFleet .= "`fleet_resource_crystal` = '". $TransCrystal ."', ";
$QryInsertFleet .= "`fleet_resource_deuterium` = '". $TransDeuterium ."', ";
$QryInsertFleet .= "`fleet_target_owner` = '". $TargetPlanet['id_owner'] ."', ";
$QryInsertFleet .= "`fleet_group` = '". $fleet_group_mr ."', ";
$QryInsertFleet .= "`start_time` = '". time() ."';";
doquery( $QryInsertFleet, 'fleets');

$QryUpdatePlanet  = "UPDATE `{{table}}` SET ";
$QryUpdatePlanet .= $FleetSubQRY;
$QryUpdatePlanet .= "`metal` = `metal` - ". $TransMetal .", ";
$QryUpdatePlanet .= "`crystal` = `crystal` - ". $TransCrystal .", ";
$QryUpdatePlanet .= "`deuterium` = `deuterium` - ". ($TransDeuterium + $consumption) ." ";
$QryUpdatePlanet .= "WHERE ";
$QryUpdatePlanet .= "`id` = ". $CurrentPlanet['id'] ." LIMIT 1;";
doquery ($QryUpdatePlanet, "planets");

$parse['mission'] = $missiontype[$_POST['mission']];
$parse['distance'] = pretty_number($distance);
$parse['speedallsmin'] = pretty_number($_POST['speedallsmin']);
$parse['consumption'] = pretty_number($consumption);
$parse['from'] = $_POST['thisgalaxy'] .":". $_POST['thissystem']. ":". $_POST['thisplanet'];
$parse['destination'] = $_POST['galaxy'] .":". $_POST['system'] .":". $_POST['planet'];
$parse['start_time'] = date("M D d H:i:s", $fleet['start_time']);
$parse['end_time'] = date("M D d H:i:s", $fleet['end_time']);

foreach ($fleetarray as $Ship => $Count)
{
$fleet_list .= "</tr><tr height=\"20\">";
$fleet_list .= "<th>". $lang['tech'][$Ship] ."</th>";
$fleet_list .= "<th>". pretty_number($Count) ."</th>";
}

$parse['fleet_list'] = $fleet_list;

display(parsetemplate(gettemplate('fleet/fleet3_table'), $parse), false);
}
?>

-- Contenu de la table

CREATE TABLE IF NOT EXISTS `xxx_fleets` (

`fleet_id` bigint(11) NOT NULL AUTO_INCREMENT,

`fleet_owner` int(11) NOT NULL DEFAULT '0',

`fleet_mission` int(11) NOT NULL DEFAULT '0',

`fleet_amount` bigint(11) NOT NULL DEFAULT '0',

`fleet_array` text CHARACTER SET latin1,

`fleet_start_time` int(11) NOT NULL DEFAULT '0',

`fleet_start_galaxy` int(11) NOT NULL DEFAULT '0',

`fleet_start_system` int(11) NOT NULL DEFAULT '0',

`fleet_start_planet` int(11) NOT NULL DEFAULT '0',

`fleet_start_type` int(11) NOT NULL DEFAULT '0',

`fleet_end_time` int(11) NOT NULL DEFAULT '0',

`fleet_end_stay` int(11) NOT NULL DEFAULT '0',

`fleet_end_galaxy` int(11) NOT NULL DEFAULT '0',

`fleet_end_system` int(11) NOT NULL DEFAULT '0',

`fleet_end_planet` int(11) NOT NULL DEFAULT '0',

`fleet_end_type` int(11) NOT NULL DEFAULT '0',

`fleet_target_obj` int(2) NOT NULL DEFAULT '0',

`fleet_resource_metal` bigint(11) NOT NULL DEFAULT '0',

`fleet_resource_crystal` bigint(11) NOT NULL DEFAULT '0',

`fleet_resource_deuterium` bigint(11) NOT NULL DEFAULT '0',

`fleet_resource_darkmatter` bigint(11) NOT NULL DEFAULT '0',

`fleet_target_owner` int(11) NOT NULL DEFAULT '0',

`fleet_group` varchar(15) NOT NULL DEFAULT '0',

`fleet_mess` int(11) NOT NULL DEFAULT '0',

`start_time` int(11) DEFAULT NULL,

PRIMARY KEY (`fleet_id`)

) ENGINE=MyISAM DEFAULT CHARSET=utf8 AUTO_INCREMENT=72 ;

--

-- Contenu de la table

--

INSERT INTO `xxx_fleets` (`fleet_id`, `fleet_owner`, `fleet_mission`, `fleet_amount`, `fleet_array`, `fleet_start_time`,

`fleet_start_galaxy`, `fleet_start_system`, `fleet_start_planet`, `fleet_start_type`, `fleet_end_time`, `fleet_end_stay`,

`fleet_end_galaxy`, `fleet_end_system`, `fleet_end_planet`, `fleet_end_type`, `fleet_target_obj`, `fleet_resource_metal`,

`fleet_resource_crystal`, `fleet_resource_deuterium`, `fleet_resource_darkmatter`, `fleet_target_owner`, `fleet_group`, `fleet_mess`, `start_time`) VALUES

(49, 1, 8, 798, '209,798;', 1376052327, 1, 1, 1, 1, 1376052683, 0, 1, 2, 9, 2, 0, 7980000, 7980000, 0, 0, 0, '0', 1, 1376051971);

dans la table flotte le temps restant est passé en negatif

jeudi 8 aout 2013 (Dernière édition vendredi 9 aout 2013)

Homer Messages : 1827

j'ai le jeu chargé en local, je regarde ça demain

jeudi 8 aout 2013

arno Messages : 83

Grand merci à toi

jeudi 8 aout 2013

Homer Messages : 1827

je n'ai pas réussi à reproduire le bug, j'ai tester 10x sans soucis

En revanche, en regardant la bdd, j'ai trouver quelques chose de très étrange !!

Toutes les planètes sont sur la table "prefix_"planets, normal, mais y'a une table galaxy ne contient que quelques infos.

Faudrait mettre ces infos dans la table planets ça seraii plus logique

vendredi 9 aout 2013 (Dernière édition vendredi 9 aout 2013)

arno Messages : 83

je pense que c'est normal, car je n'est pas donner la version .

si possible ,je donne le lien (en mp) et voyez par vous.

vendredi 9 aout 2013

Homer Messages : 1827

oui donne ne pm

vendredi 9 aout 2013

arno Messages : 83

C'est fait

vendredi 9 aout 2013 (Dernière édition vendredi 9 aout 2013)

Homer Messages : 1827

C'est sans doute là que ça se joue (oui je sais je t'avais dis que ce n'était pas ce fichier ) :

MissionCaseRecycling.php

			if ($FleetRow['fleet_end_time'] <= time())
{
$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);
$this->RestoreFleetToPlanet ( $FleetRow, true );
doquery("DELETE FROM {{table}} WHERE `fleet_id` = '". $FleetRow["fleet_id"] ."';", 'fleets');
}

Faut vérifier les valeurs et voir pourquoi la ligne $this->RestoreFleetToPlanet ( $FleetRow, true ); ne fonctionne pas

lundi 12 aout 2013

arno Messages : 83

Ok ,en fait après plusieurs tests, je peut dire que si les débris se trouve devant ma planète il n'y a pas bug, mais si c'est sur une longue distance, sa bug, sa recycle, et sa revient mais ne se pose pas et reste en vole.Le pire c'est que sa le fait que pour la mission extraction ,j'ai beau verifier je ne comprend pas ,a moins que flotten.js , je n'y avais pas pensé....

lundi 12 aout 2013

arno Messages : 83

voici toutes les missions et fonctions en rapport. Perso je ne trouve pas et il est impossible de poster une demande de support sur le forum officiel si avec, je ne peut etre aidé ,tant pis et merci pour votre aide.

<?php



if (!defined('INSIDE'))die(header("location:../../"));

class FlyingFleetHandler
{
public static function calculateAKSSteal($attackFleets, $defenderPlanet, $ForSim = false)
{
//Steal-Math by Slaver for 2Moons(http://code.google.com/p/2moons/) based on http://www.owiki.de/Beute
global $pricelist, $db;

$SortFleets = array();

foreach ($attackFleets as $FleetID => $Attacker)
{
foreach($Attacker['detail'] as $Element => $amount)
{
if ($Element != 210) //fix probos capacity in attack by jstar
$SortFleets[$FleetID]        += $pricelist[$Element]['capacity'] * $amount;
}

$SortFleets[$FleetID]            -= $Attacker['fleet']['fleet_resource_metal'] - $Attacker['fleet']['fleet_resource_crystal'] - $Attacker['fleet']['fleet_resource_deuterium'];
}

$Sumcapacity              = array_sum($SortFleets);

// Step 1
$booty['deuterium']       = min($Sumcapacity / 3,  ($defenderPlanet['deuterium'] / 2));
$Sumcapacity             -= $booty['deuterium'];

// Step 2
$booty['crystal']         = min(($Sumcapacity / 2),  ($defenderPlanet['crystal'] / 2));
$Sumcapacity             -= $booty['crystal'];

// Step 3
$booty['metal']           = min(($Sumcapacity ),  ($defenderPlanet['metal'] / 2));
$Sumcapacity             -= $booty['metal'];


// Step 5
$oldMetalBooty            = $booty['crystal'] ;
$booty['crystal']         += min(($Sumcapacity /2 ),  max((($defenderPlanet['crystal']) / 2) - $booty['crystal'], 0));

$Sumcapacity             += $oldMetalBooty - $booty['crystal'] ;

// Step 6
$booty['metal']          += min(($Sumcapacity ),  max(($defenderPlanet['metal'] / 2) - $booty['metal'], 0));

$booty['metal']            = max($booty['metal'] ,0);
$booty['crystal']        = max($booty['crystal'] ,0);
$booty['deuterium']        = max($booty['deuterium'] ,0);

$steal                    = array_map('floor', $booty);

if($ForSim)
return $steal;

$AllCapacity        = array_sum($SortFleets);
$QryUpdateFleet        = "";

foreach($SortFleets as $FleetID => $Capacity)
{
$QryUpdateFleet     = "UPDATE {{table}} SET ";
$QryUpdateFleet .= "`fleet_resource_metal` =  `fleet_resource_metal` + '".floattostring($steal['metal'] * ($Capacity /  $AllCapacity))."', ";
$QryUpdateFleet .= "`fleet_resource_crystal` =  `fleet_resource_crystal` +'".floattostring($steal['crystal'] * ($Capacity  / $AllCapacity))."', ";
$QryUpdateFleet .= "`fleet_resource_deuterium` =  `fleet_resource_deuterium` +'".floattostring($steal['deuterium'] * ($Capacity / $AllCapacity))."' ";
$QryUpdateFleet .= "WHERE fleet_id = '".$FleetID."' ";
$QryUpdateFleet .= "LIMIT 1;";
doquery($QryUpdateFleet, 'fleets');

}

return $steal;
}


private function SpyTarget ($TargetPlanet, $Mode, $TitleString)
{
global $lang, $resource;

$LookAtLoop = true;
if ($Mode == 0)
{
$String  = "<table width=\"440\"><tr><td class=\"c\" colspan=\"5\">";
$String .= $TitleString ." ". $TargetPlanet['name'];
$String .= " <a href=\"game.php?page=galaxy&mode=3&galaxy=". $TargetPlanet["galaxy"] ."&system=". $TargetPlanet["system"]. "\">";
$String .= "[". $TargetPlanet["galaxy"] .":". $TargetPlanet["system"] .":". $TargetPlanet["planet"] ."]</a>";
$String .= " le ". gmdate("d-m-Y H:i:s", time() + 2 * 60 * 60) ."</td>";
$String .= "</tr><tr>";
$String .= "<td width=220>". $lang['Metal']     ."</td><td width=220 align=right>". pretty_number($TargetPlanet['metal'])      ."</td><td> </td>";
$String .= "<td width=220>". $lang['Crystal']   ."</td></td><td width=220 align=right>". pretty_number($TargetPlanet['crystal'])    ."</td>";
$String .= "</tr><tr>";
$String .= "<td width=220>". $lang['Deuterium'] ."</td><td width=220 align=right>". pretty_number($TargetPlanet['deuterium'])  ."</td><td> </td>";
$String .= "<td width=220>". $lang['Energy']    ."</td><td width=220 align=right>". pretty_number($TargetPlanet['energy_max']) ."</td>";
$String .= "</tr>";
$LookAtLoop = false;
}
elseif ($Mode == 1)
{
$ResFrom[0] = 200;
$ResTo[0]   = 299;
$Loops      = 1;
}
elseif ($Mode == 2)
{
$ResFrom[0] = 400;
$ResTo[0]   = 499;
$ResFrom[1] = 500;
$ResTo[1]   = 599;
$Loops      = 2;
}
elseif ($Mode == 3)
{
$ResFrom[0] = 1;
$ResTo[0]   = 99;
$Loops      = 1;
}
elseif ($Mode == 4)
{
$ResFrom[0] = 100;
$ResTo[0]   = 199;
$Loops      = 1;
}

if ($LookAtLoop == true)
{
$String  = "<table width=\"440\" cellspacing=\"1\"><tr><td class=\"c\" colspan=\"". ((2 * SPY_REPORT_ROW) + (SPY_REPORT_ROW - 1))."\">". $TitleString ."</td></tr>";
$Count       = 0;
$CurrentLook = 0;
while ($CurrentLook < $Loops)
{
$row     = 0;
for ($Item = $ResFrom[$CurrentLook]; $Item <= $ResTo[$CurrentLook]; $Item++)
{
if ( $TargetPlanet[$resource[$Item]]> 0)
{
if ($row == 0)
$String  .= "<tr>";

$String  .= "<td align=left>".$lang['tech'][$Item]."</td><td align=right>".$TargetPlanet[$resource[$Item]]."</td>";
if ($row < SPY_REPORT_ROW - 1)
$String  .= "<td> </td>";

$Count   += $TargetPlanet[$resource[$Item]];
$row++;
if ($row == SPY_REPORT_ROW)
{
$String  .= "</tr>";
$row      = 0;
}
}
}

while ($row != 0)
{
$String  .= "<td> </td><td> </td>";
$row++;
if ($row == SPY_REPORT_ROW)
{
$String  .= "</tr>";
$row      = 0;
}
}
$CurrentLook++;
}
}
$String .= "</table>";

$return['String'] = $String;
$return['Count']  = $Count;

return $return;
}

private function RestoreFleetToPlanet ($FleetRow, $Start = true)
{
global $resource;

$FleetRecord         = explode(";", $FleetRow['fleet_array']);
$QryUpdFleet         = "";
foreach ($FleetRecord as $Item => $Group)
{
if ($Group != '')
{
$Class        = explode (",", $Group);
$QryUpdFleet .= "`". $resource[$Class[0]] ."` = `".$resource[$Class[0]]."` + '".$Class[1]."', \n";
}
}

$QryUpdatePlanet   = "UPDATE {{table}} SET ";
if ($QryUpdFleet != "")
$QryUpdatePlanet  .= $QryUpdFleet;

$QryUpdatePlanet  .= "`metal` = `metal` + '". $FleetRow['fleet_resource_metal'] ."', ";
$QryUpdatePlanet  .= "`crystal` = `crystal` + '". $FleetRow['fleet_resource_crystal'] ."', ";
$QryUpdatePlanet  .= "`deuterium` = `deuterium` + '". $FleetRow['fleet_resource_deuterium'] ."' ";
$QryUpdatePlanet  .= "WHERE ";

if ($Start == true)
{
$QryUpdatePlanet  .= "`galaxy` = '". $FleetRow['fleet_start_galaxy'] ."' AND ";
$QryUpdatePlanet  .= "`system` = '". $FleetRow['fleet_start_system'] ."' AND ";
$QryUpdatePlanet  .= "`planet` = '". $FleetRow['fleet_start_planet'] ."' AND ";
$QryUpdatePlanet  .= "`planet_type` = '". $FleetRow['fleet_start_type'] ."' ";
}
else
{
$QryUpdatePlanet  .= "`galaxy` = '". $FleetRow['fleet_end_galaxy'] ."' AND ";
$QryUpdatePlanet  .= "`system` = '". $FleetRow['fleet_end_system'] ."' AND ";
$QryUpdatePlanet  .= "`planet` = '". $FleetRow['fleet_end_planet'] ."' AND ";
$QryUpdatePlanet  .= "`planet_type` = '". $FleetRow['fleet_end_type'] ."' ";
}
$QryUpdatePlanet  .= "LIMIT 1;";
doquery( $QryUpdatePlanet, 'planets');
}

private function StoreGoodsToPlanet ($FleetRow, $Start = false)
{
$QryUpdatePlanet   = "UPDATE {{table}} SET ";
$QryUpdatePlanet  .= "`metal` = `metal` + '". $FleetRow['fleet_resource_metal'] ."', ";
$QryUpdatePlanet  .= "`crystal` = `crystal` + '". $FleetRow['fleet_resource_crystal'] ."', ";
$QryUpdatePlanet  .= "`deuterium` = `deuterium` + '". $FleetRow['fleet_resource_deuterium'] ."' ";
$QryUpdatePlanet  .= "WHERE ";

if ($Start == true)
{
$QryUpdatePlanet  .= "`galaxy` = '". $FleetRow['fleet_start_galaxy'] ."' AND ";
$QryUpdatePlanet  .= "`system` = '". $FleetRow['fleet_start_system'] ."' AND ";
$QryUpdatePlanet  .= "`planet` = '". $FleetRow['fleet_start_planet'] ."' AND ";
$QryUpdatePlanet  .= "`planet_type` = '". $FleetRow['fleet_start_type'] ."' ";
}
else
{
$QryUpdatePlanet  .= "`galaxy` = '". $FleetRow['fleet_end_galaxy'] ."' AND ";
$QryUpdatePlanet  .= "`system` = '". $FleetRow['fleet_end_system'] ."' AND ";
$QryUpdatePlanet  .= "`planet` = '". $FleetRow['fleet_end_planet'] ."' AND ";
$QryUpdatePlanet  .= "`planet_type` = '". $FleetRow['fleet_end_type'] ."' ";
}

$QryUpdatePlanet  .= "LIMIT 1;";
doquery( $QryUpdatePlanet, 'planets');
}

private function raketenangriff($verteidiger_panzerung, $angreifer_waffen, $iraks, $def, $primaerziel = '0')
{
$temp = '';
$temp2 = '';

$def[10] = $iraks;

$metall     = Array(0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0);
$kristall   = Array(0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0);
$deut       = Array(0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0);
$verblieben = Array(0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0);

for($temp = 0; $temp < 11; $temp++)
$verblieben[$temp] = $def[$temp];

$kaputt  = Array(0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0);
$hull = Array();
$hull[0] = 200 * (1 + $verteidiger_panzerung / 10);
$hull[1] = $hull[0];
$hull[2] = 800 * (1 + ($verteidiger_panzerung / 10));
$hull[3] = 3500 * (1 + ($verteidiger_panzerung / 10));
$hull[4] = $hull[2];
$hull[5] = 10000 * (1 + ($verteidiger_panzerung / 10));
$hull[6] = 2000 * (1 + ($verteidiger_panzerung / 10));
$hull[7] = $hull[5];
$hull[8] = 1500 * (1 + ($verteidiger_panzerung / 10));

$metall_cost_tab   = Array( 2, 1.5, 6, 20, 2, 50, 10, 50, 12.5, 8);
$kristall_cost_tab = Array( 0, 0.5, 2, 15, 6, 50, 10, 50,  2.5, 0);
$deut_cost_tab     = Array( 0,   0, 0,  2, 0, 30,  0,  0, 10.0, 2);

$schaden = floor(($def[10] - $def[9]) * (12000 * (1 + ($angreifer_waffen / 10))));
if ($schaden < 0)
$schaden = 0;

switch ($primaerziel)
{
case 0:
$beschussreihenfolge = Array(0, 1, 2, 3, 4, 5, 6, 7, 8);
break;
case 1:
$beschussreihenfolge = Array(1, 0, 2, 3, 4, 5, 6, 7, 8);
break;
case 2:
$beschussreihenfolge = Array(2, 0, 1, 3, 4, 5, 6, 7, 8);
break;
case 3:
$beschussreihenfolge = Array(3, 0, 1, 2, 4, 5, 6, 7, 8);
break;
case 4:
$beschussreihenfolge = Array(4, 0, 1, 2, 3, 5, 6, 7, 8);
break;
case 5:
$beschussreihenfolge = Array(5, 0, 1, 2, 3, 4, 6, 7, 8);
break;
case 6:
$beschussreihenfolge = Array(6, 0, 1, 2, 3, 4, 5, 7, 8);
break;
case 7:
$beschussreihenfolge = Array(7, 0, 1, 2, 3, 4, 5, 6, 8);
break;
case 8:
$beschussreihenfolge = Array(0, 1, 2, 3, 4, 5, 6, 7, 8);
break;
}

$verblieben[10] = 0;
$kaputt[10]    += $def[10];
$metall[10]    += $kaputt[10] * $metall_cost_tab[8];
$kristall[10]      += $kaputt[10] * $kristall_cost_tab[8];
$deut[10]          += $kaputt[10] * $deut_cost_tab[8];
$verblieben[9]      = ($def[9] - $def[10]);

if ($verblieben[9] < 0)
$verblieben[9] = 0;

$kaputt[11]    = $def[9] - $verblieben[9];
$kaputt[9]    += ($def[9] - $verblieben[9]);
$metall[9]    += $kaputt[9] * $metall_cost_tab[9];
$kristall[9]  += $kaputt[9] * $kristall_cost_tab[9];
$deut[9]   += $kaputt[9] * $deut_cost_tab[9];
$metall[11]   += $metall[9];
$kristall[11] += $kristall[9];
$deut[11]     += $deut[9];

for($temp = 0; $temp < 9; $temp++)
{
if ($schaden>= ($hull[$beschussreihenfolge[$temp]] * $def[$beschussreihenfolge[$temp]]))
{
$kaputt[$beschussreihenfolge[$temp]] += $def[$beschussreihenfolge[$temp]];
$verblieben[$beschussreihenfolge[$temp]] = 0;
$schaden -= ($hull[$beschussreihenfolge[$temp]] * $kaputt[$beschussreihenfolge[$temp]]);
}
else
{
$kaputt[$beschussreihenfolge[$temp]] += floor($schaden / $hull[$beschussreihenfolge[$temp]]);
$schaden -= $kaputt[$beschussreihenfolge[$temp]] * $hull[$beschussreihenfolge[$temp]];
$verblieben[$beschussreihenfolge[$temp]] = ($def[$beschussreihenfolge[$temp]] - $kaputt[$beschussreihenfolge[$temp]]);
}

$metall[$beschussreihenfolge[$temp]] += $kaputt[$beschussreihenfolge[$temp]] * $metall_cost_tab[$beschussreihenfolge[$temp]];
$kristall[$beschussreihenfolge[$temp]] += $kaputt[$beschussreihenfolge[$temp]] * $kristall_cost_tab[$beschussreihenfolge[$temp]];
$deut[$beschussreihenfolge[$temp]] += $kaputt[$beschussreihenfolge[$temp]] * $deut_cost_tab[$beschussreihenfolge[$temp]];

$verblieben[11] += $verblieben[$beschussreihenfolge[$temp]];
$kaputt[11] += $kaputt[$beschussreihenfolge[$temp]];
$metall[11] += $metall[$beschussreihenfolge[$temp]];
$kristall[11] += $kristall[$beschussreihenfolge[$temp]];
$deut[11] += $deut[$beschussreihenfolge[$temp]];
}

$return = array();

$return['verbleibt'] = $verblieben;
$return['zerstoert'] = $kaputt;
$return['verluste_metall'] = $metall;
$return['verluste_kristall'] = $kristall;
$return['verluste_deuterium'] = $deut;

return $return;
}

private function MissionCaseAttack ($FleetRow)
{
global $pricelist, $lang, $resource, $CombatCaps, $game_config, $user;

if ($FleetRow['fleet_mess'] == 0 && $FleetRow['fleet_start_time'] <= time())
{
$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 ($FleetRow['fleet_group']> 0)
{
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');
}

$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'];
$attackFleets = array();

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;

$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 .= "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');

$totalDebree = $result['debree']['def'][0] + $result['debree']['def'][1] + $result['debree']['att'][0] + $result['debree']['att'][1];
// mod TOP KB
$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];
$strtruemmermetal    = $result['debree']['att'][0] + $result['debree']['def'][0];
$strtruemmercrystal  = $result['debree']['att'][1] + $result['debree']['def'][1];
            // mod TOP KB

$steal = array('metal' => 0, 'crystal' => 0, 'deuterium' => 0);

if ($result['won'] == "a")
{
$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;

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);

$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 .= 'WHERE fleet_id = '. $FleetRow['fleet_id'] .' ';
$QryUpdateFleet .= 'LIMIT 1 ;';
doquery( $QryUpdateFleet,'fleets');
}

foreach ($attackFleets as $fleetID => $attacker)
{
$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)
{
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.', ';
}

$QryUpdateTarget  = "UPDATE {{table}} SET ";
$QryUpdateTarget .= $fleetArray;
$QryUpdateTarget .= "`metal` = `metal` - '". $steal['metal'] ."', ";
$QryUpdateTarget .= "`crystal` = `crystal` - '". $steal['crystal'] ."', ";
$QryUpdateTarget .= "`deuterium` = `deuterium` - '". $steal['deuterium'] ."' ";
$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');
}
}

$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;
$UserChance = mt_rand(1, 100);
$ChanceMoon = sprintf ($lang['sys_moonproba'], $MoonChance);
}
elseif($FleetDebris < 100000)
{
$UserChance = 0;
$ChanceMoon = sprintf ($lang['sys_moonproba'], $MoonChance);
}
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 = "";
}

$formatted_cr = formatCR($result,$steal,$MoonChance,$GottenMoon,$totaltime);
$raport = $formatted_cr['html'];

$formatted_crx = formatCRx($result,$steal,$MoonChance,$GottenMoon,$totaltime);
$raportx = $formatted_crx['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'];
}
// mod TOP KB
$angreifer     = $attackFleets;
$defender      = $defense;
$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());
$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` = '". $attacker['user']['username'] ."', ";
$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( $raportx ) ."',";
$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( "CombatReport.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'] .': '. number_format($result['lost']['att'], 0, ',', '.') .'</font>';
$raport .= '<font color=\'green\'>   '. $lang['sys_perte_defenseur'] .': '. number_format($result['lost']['def'], 0, ',', '.') .'</font><br>' ;
$raport .= $lang['sys_gain'] .' '. $lang['Metal'] .':<font color=\'#adaead\'>'. number_format($steal['metal'], 0, ',', '.') .'</font>   '. $lang['Crystal'] .':<font color=\'#ef51ef\'>'. number_format($steal['crystal'], 0, ',', '.') .'</font>   '. $lang['Deuterium'] .':<font color=\'#f77542\'>'. number_format($steal['deuterium'], 0, ',', '.') .'</font><br>';
$raport .= $lang['sys_debris'] .' '. $lang['Metal'] .': <font color=\'#adaead\'>'. number_format($result['debree']['att'][0]+$result['debree']['def'][0], 0, ',', '.') .'</font>   '. $lang['Crystal'] .': <font color=\'#ef51ef\'>'. number_format($result['debree']['att'][1]+$result['debree']['def'][1], 0, ',', '.') .'</font><br></center>';

SendSimpleMessage ( $FleetRow['fleet_owner'], '', $FleetRow['fleet_start_time'], 3, $lang['sys_mess_tower'], $lang['sys_mess_attack_report'], $raport );
// Updaten Spieler Datenbank
      $user1   = doquery("SELECT * FROM {{table}} WHERE `id` = '". $user1stat ."';", 'users');
      while($user1data = mysql_fetch_assoc($user1))
       {
             $strtruemmermetaluser1    = $strtruemmermetal + $user1data['kbmetal'];
             $strtruemmercrystaluser1  = $strtruemmercrystal + $user1data['kbcrystal'];
             $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'];
             $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;
}

//Update Angreifer Truemerfeld, Kampfergebniss und Units
   $userstat   = doquery("SELECT * FROM {{table}} WHERE `id` = '". $user1stat ."';", 'users');
   while($userwrite = mysql_fetch_assoc($userstat))
{
                    $QryUpdateuserstat  = "UPDATE {{table}} SET ";
                    $QryUpdateuserstat .= "`wons` = '". $user1wons ."', ";
                    $QryUpdateuserstat .= "`loos` = '". $user1loos ."', ";
                    $QryUpdateuserstat .= "`draws` = '". $user1draws  ."', ";
                    $QryUpdateuserstat .= "`kbmetal` = '". $strtruemmermetaluser1 ."', ";
                    $QryUpdateuserstat .= "`kbcrystal` = '". $strtruemmercrystaluser1 ."', ";
                    $QryUpdateuserstat .= "`lostunits` = '". $user1lostunits ."', ";
                    $QryUpdateuserstat .= "`desunits` = '". $user1shotunits ."' ";
                    $QryUpdateuserstat .= "WHERE ";
                    $QryUpdateuserstat .= "`id` = '". $user1stat ."';";
                    doquery ( $QryUpdateuserstat , 'users');
//Update Verteidiger Truemerfeld, Kampfergebniss und Units
                    $QryUpdateuserstat  = "UPDATE {{table}} SET ";
                    $QryUpdateuserstat .= "`wons` = '". $user2wons ."', ";
                    $QryUpdateuserstat .= "`loos` = '". $user2loos ."', ";
                    $QryUpdateuserstat .= "`draws` = '". $user2draws  ."', ";
                    $QryUpdateuserstat .= "`kbmetal` = '". $strtruemmermetaluser2 ."', ";
                    $QryUpdateuserstat .= "`kbcrystal` = '". $strtruemmercrystaluser2 ."', ";
                    $QryUpdateuserstat .= "`lostunits` = '". $user2lostunits ."', ";
                    $QryUpdateuserstat .= "`desunits` = '". $user2shotunits ."' ";
                    $QryUpdateuserstat .= "WHERE ";
                    $QryUpdateuserstat .= "`id` = '". $user2stat ."';";
                    doquery ( $QryUpdateuserstat , 'users');
}
// Ende schreiben in datenbank
$raport2  = '<a href # OnClick=\'f( "CombatReport.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 );
}
}
}
elseif ($FleetRow['fleet_end_time'] <= time())
{
$Message         = sprintf( $lang['sys_fleet_won'],
$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);
$this->RestoreFleetToPlanet($FleetRow);
doquery ('DELETE FROM {{table}} WHERE `fleet_id`='.$FleetRow['fleet_id'],'fleets');
}
}

private function MissionCaseACS($FleetRow)
{
global $pricelist, $lang, $resource, $CombatCaps, $game_config;

if ($FleetRow['fleet_mess'] == 0 && $FleetRow['fleet_start_time'] > time())
{
$QryUpdateFleet  = "UPDATE {{table}} SET `fleet_mess` = '1' WHERE `fleet_id` = '". intval($FleetRow['fleet_id']) ."' LIMIT 1 ;";
doquery( $QryUpdateFleet, 'fleets');
}
elseif ($FleetRow['fleet_end_time'] <= time())
{
$this->RestoreFleetToPlanet($FleetRow);
doquery ('DELETE FROM {{table}} WHERE `fleet_id`='.intval($FleetRow['fleet_id']),'fleets');
}
}

private 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())
{
$this->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'] );

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'] );
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_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);
$this->RestoreFleetToPlanet ( $FleetRow, true );
doquery("DELETE FROM {{table}} WHERE fleet_id=" . $FleetRow["fleet_id"], 'fleets');
}
}
}

private 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=\"game.php?page=galaxy&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);
$this->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=\"game.php?page=galaxy&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);
$this->RestoreFleetToPlanet ( $FleetRow, true );
doquery("DELETE FROM {{table}} WHERE `fleet_id` = '". $FleetRow["fleet_id"] ."';", 'fleets');
}
}
}

private function MissionCaseStayAlly($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'] ."';";
$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'] ."';";
$TargetPlanet     = doquery( $QryTargetPlanet, 'planets', true);
$TargetName       = $TargetPlanet['name'];
$TargetOwner      = $TargetPlanet['id_owner'];

if ($FleetRow['fleet_mess'] == 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` = 2 ";
$QryUpdateFleet .= "WHERE `fleet_id` = '". $FleetRow['fleet_id'] ."' ";
$QryUpdateFleet .= "LIMIT 1 ;";
doquery( $QryUpdateFleet, 'fleets');

}
elseif($FleetRow['fleet_end_stay'] <= 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_tran_mess_back'], $StartName, GetStartAdressLink($FleetRow, ''));
SendSimpleMessage ( $StartOwner, '', $FleetRow['fleet_end_time'], 5, $lang['sys_mess_tower'], $lang['sys_mess_fleetback'], $Message);
$this->RestoreFleetToPlanet ( $FleetRow, true );
doquery("DELETE FROM {{table}} WHERE fleet_id=" . $FleetRow["fleet_id"], 'fleets');
}
}
}

private 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'] + ($CurrentUser['rpg_espion'] * ESPION);
$TargetUser          = doquery("SELECT * FROM {{table}} WHERE `id` = '".$TargetUserID."';", 'users', true);
$TargetSpyLvl        = $TargetUser['spy_tech'] + ($TargetUser['rpg_espion'] * ESPION);
$fleet               = explode(";", $FleetRow['fleet_array']);
$fquery              = "";
//include('../functions/PlanetResourceUpdate.php');
//PlanetResourceUpdate ( $TargetUser, $TargetPlanet, time() );

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    = $this->SpyTarget ( $TargetPlanet, 0, $lang['sys_spy_maretials'] );
$Materials        = $MaterialsInfo['String'];

$PlanetFleetInfo  = $this->SpyTarget ( $TargetPlanet, 1, $lang['sys_spy_fleet'] );
$PlanetFleet      = $Materials;
$PlanetFleet     .= $PlanetFleetInfo['String'];

$PlanetDefenInfo  = $this->SpyTarget ( $TargetPlanet, 2, $lang['sys_spy_defenses'] );
$PlanetDefense    = $PlanetFleet;
$PlanetDefense   .= $PlanetDefenInfo['String'];

$PlanetBuildInfo  = $this->SpyTarget ( $TargetPlanet, 3, $lang['tech'][0] );
$PlanetBuildings  = $PlanetDefense;
$PlanetBuildings .= $PlanetBuildInfo['String'];

$TargetTechnInfo  = $this->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 = "<font color=\"red\">".$lang['sys_mess_spy_destroyed']."</font>";
elseif ($TargetChances < $SpyerChances)
$DestProba = sprintf( $lang['sys_mess_spy_lostproba'], $TargetChances);

$AttackLink = "<center>";
$AttackLink .= "<a href=\"game.php?page=fleet&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=\"game.php?page=galaxy&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');
}
}
else
{
if ($FleetRow['fleet_end_time'] <= time())
{
$this->RestoreFleetToPlanet ( $FleetRow, true );
doquery("DELETE FROM {{table}} WHERE `fleet_id` = ". $FleetRow["fleet_id"], 'fleets');
}
}
}
}
}
/*
private 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) && ($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"];
}
}
}

$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);

$QryUpdateFleet  = "UPDATE {{table}} SET ";
$QryUpdateFleet .= "`fleet_resource_metal` = `fleet_resource_metal` + '".$RecycledGoods["metal"]."', ";
$QryUpdateFleet .= "`fleet_resource_crystal` = `fleet_resource_crystal` + '".$RecycledGoods["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())
{
$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);
$this->RestoreFleetToPlanet ( $FleetRow, true );
doquery("DELETE FROM {{table}} WHERE `fleet_id` = '". $FleetRow["fleet_id"] ."';", 'fleets');
}
}
}*/
private 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) && ($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"];
}
}
}

$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);

$QryUpdateFleet  = "UPDATE {{table}} SET ";
$QryUpdateFleet .= "`fleet_resource_metal` = `fleet_resource_metal` + '".$RecycledGoods["metal"]."', ";
$QryUpdateFleet .= "`fleet_resource_crystal` = `fleet_resource_crystal` + '".$RecycledGoods["crystal"]."', ";
$QryUpdateFleet .= "`fleet_mess` = '1' ";
$QryUpdateFleet .= "WHERE ";
$QryUpdateFleet .= "`fleet_id` = '".intval($FleetRow['fleet_id'])."' ";
$QryUpdateFleet .= "LIMIT 1;";
doquery( $QryUpdateFleet, 'fleets');
}
}
else
{
if ($FleetRow['fleet_end_time'] <= time())
{
$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);
$this->RestoreFleetToPlanet ( $FleetRow, true );
doquery("DELETE FROM {{table}} WHERE `fleet_id` = '". $FleetRow["fleet_id"] ."';", 'fleets');
}
}
}

private function MissionCaseColonisation($FleetRow)
{
global $lang, $resource;

$iPlanetCount = mysql_result(doquery ("SELECT count(*) FROM {{table}} WHERE `id_owner` = '". $FleetRow['fleet_owner'] ."' AND `planet_type` = '1' AND `destruyed` = '0'", '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');
}
}
elseif ($FleetRow['fleet_end_time'] < time())
{
$this->RestoreFleetToPlanet ( $FleetRow, true );
doquery("DELETE FROM {{table}} WHERE fleet_id=" . $FleetRow["fleet_id"], 'fleets');
}
}

private function MissionCaseDestruction($FleetRow)
{
global $user, $phpEx, $pricelist, $lang, $resource, $CombatCaps;

    includeLang('INGAME');
if ($FleetRow['fleet_mess'] == 0 && $FleetRow['fleet_start_time'] <= time())
{
$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);
$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'];
$attackFleets = array();

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;

$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 .= "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');

foreach ($attackFleets as $fleetID => $attacker)
{
$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)
{
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.', ';
}

$QryUpdateTarget  = "UPDATE {{table}} SET ";
$QryUpdateTarget .= $fleetArray;
$QryUpdateTarget .= "`metal` = `metal` - '". $steal['metal'] ."', ";
$QryUpdateTarget .= "`crystal` = `crystal` - '". $steal['crystal'] ."', ";
$QryUpdateTarget .= "`deuterium` = `deuterium` - '". $steal['deuterium'] ."' ";
$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');
}
}

$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;
$steal   = array('metal' => 0, 'crystal' => 0, 'deuterium' => 0);
switch ($result['won']) {
case "a":
$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;
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);

$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 .= 'WHERE fleet_id = '. $FleetRow['fleet_id'] .' ';
$QryUpdateFleet .= 'LIMIT 1 ;';
doquery( $QryUpdateFleet,'fleets' );

$QryUpdateTarget  = "UPDATE {{table}} SET ";
$QryUpdateTarget .= $fleetArray;
$QryUpdateTarget .= "`metal` = `metal` - '". $steal['metal'] ."', ";
$QryUpdateTarget .= "`crystal` = `crystal` - '". $steal['crystal'] ."', ";
$QryUpdateTarget .= "`deuterium` = `deuterium` - '". $steal['deuterium'] ."' ";
$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');
$destructionl2 = (100-sqrt($targetPlanet['diameter']))*sqrt($attackFleets[$FleetRow['fleet_id']]['detail'][214]);
// Formel für min. Anzahl an Todessternen. Hat jmd. ne gute Formel?
// $mints = (pow((1 / (1-sqrt($targetPlanet['diameter']) / 100)),2))*10;
// $destructionl2 = max($destructionl1,$mints);
if ($destructionl2> 100) {
$chance = '100';
} elseif ($destructionl2 < 0) {
$chance = '0';
}
$tirage = mt_rand(0, 100);
if($tirage <= $chance)   {
doquery("DELETE FROM {{table}} WHERE `id` = '". $targetPlanet['id'] ."';", 'planets');
$Qrydestructionlune  = "UPDATE {{table}} SET ";
$Qrydestructionlune .= "`destruyed` = '1' ";
$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  = "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');
$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_destruc_mess1'];
$destext .= $lang['sys_destruc_reussi'];
        $destructionrip = sqrt($TargetPlanet['diameter'])/2;
$chance2  = round($destructionrip);                 
$tirage2  = mt_rand(0, 100);
$probarip = sprintf ($lang['sys_destruc_rip'], $chance2);
if($tirage2 <= $chance2) {
$destext .= $lang['sys_destruc_echec'];
doquery("DELETE FROM {{table}} WHERE `fleet_id` = '". $FleetRow["fleet_id"] ."';", 'fleets');
}
} else {
        $destructionrip = sqrt($TargetPlanet['diameter'])/2;
$chance2  = round($destructionrip);                 
$tirage2  = mt_rand(0, 100);
$probarip = sprintf ($lang['sys_destruc_rip'], $chance2);
$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'];
$destext .= sprintf ($lang['sys_destruc_lune'], $chance) ."<br>";
if($tirage2 <= $chance2) {
$destext .= $lang['sys_destruc_echec'];
doquery("DELETE FROM {{table}} WHERE `fleet_id` = '". $FleetRow["fleet_id"] ."';", 'fleets');
} else {
$destext .= $lang['sys_destruc_stop'];
}
}
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;
}

$QryUpdateTarget  = "UPDATE {{table}} SET ";
$QryUpdateTarget .= $TargetPlanetUpd;
$QryUpdateTarget .= "`metal` = `metal` - '". $steal['metal'] ."', ";
$QryUpdateTarget .= "`crystal` = `crystal` - '". $steal['crystal'] ."', ";
$QryUpdateTarget .= "`deuterium` = `deuterium` - '". $steal['deuter'] ."' ";
$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');

$QryUpdateGalaxy  = "UPDATE {{table}} SET ";
$QryUpdateGalaxy .= "`metal` = `metal` + '". $zlom['metal'] ."', ";
$QryUpdateGalaxy .= "`crystal` = `crystal` + '". $zlom['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');

$MoonChance       = 0;
$GottenMoon   = "";
$formatted_cr   = formatCR($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());

$raport  = '<a href # OnClick=\'f( "CombatReport.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]) ."</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 );


$raport2  = "<a href # OnClick=\"f( 'CombatReport.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>";

SendSimpleMessage ( $TargetUserID, '', $FleetRow['fleet_start_time'], 3, $lang['sys_mess_tower'], $lang['sys_mess_destruc_report'], $raport2 );
    } elseif ($FleetRow['fleet_end_time'] <= time()) {
$fquery = "";
$Message = sprintf( $lang['sys_fleet_won'], $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);
$this->RestoreFleetToPlanet($FleetRow);
doquery ('DELETE FROM {{table}} WHERE `fleet_id`='.$FleetRow['fleet_id'],'fleets');
}

}

private function MissionCaseMIP ($FleetRow)
{
global $user, $phpEx, $pricelist, $lang, $resource, $CombatCaps;

if ($FleetRow['fleet_start_time'] <= time())
{
if ($FleetRow['fleet_mess'] == 0)
{
if (!isset($CombatCaps[202]['sd']))
header("location:game." . $phpEx . "?page=fleet");

$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'] . "';";
$planet = doquery($QryTargetPlanet, 'planets', true);

$QrySelect  = "SELECT defence_tech,military_tech FROM {{table}} ";
$QrySelect .= "WHERE ";
$QrySelect .= "`id` = '".$FleetRow['fleet_owner']."';";
$UserFleet = doquery( $QrySelect, 'users',true);

$verteidiger = $UserFleet["defence_tech"];
$angreifer = $UserFleet["military_tech"];

$ids = array(
0 => 401,
1 => 402,
2 => 403,
3 => 404,
4 => 405,
5 => 406,
6 => 407,
7 => 408,
8 => 502,
9 => 503,
10 => 409);

$def =   array(
0 => $planet['misil_launcher'],
1 => $planet['small_laser'],
2 => $planet['big_laser'],
3 => $planet['gauss_canyon'],
4 => $planet['ionic_canyon'],
5 => $planet['buster_canyon'],
6 => $planet['small_protection_shield'],
7 => $planet['big_protection_shield'],
8 => $planet['interceptor_misil'],
9 => $planet['interplanetary_misil'],
10 => $planet['planet_protector']);

$DefenseLabel =   array(0 => $lang['tech'][401],
1 => $lang['tech'][402],
2 => $lang['tech'][403],
3 => $lang['tech'][404],
4 => $lang['tech'][405],
5 => $lang['tech'][406],
6 => $lang['tech'][407],
7 => $lang['tech'][408],
8 => $lang['tech'][502],
9 => $lang['tech'][503],
10 => $lang['tech'][409]);

$message = '';

if ($planet['interceptor_misil']>= $FleetRow['fleet_amount'])
{
$message = 'Tus misiles de intersepción destruyeron los misiles interplanetarios<br>';
$x = $resource[$ids[8]];
doquery("UPDATE {{table}} SET " . $x . " = " . $x . "-" . $FleetRow['fleet_amount'] . " WHERE id = " . $planet['id'], 'planets');
}
else
{
if ($planet['interceptor_misil']> 0)
{
$x = $resource[$ids[8]];
doquery("UPDATE {{table}} SET " . $x . " = '0'  WHERE id = " . $planet['id'], 'planets');
$message = $planet['interceptor_misil'] . "interplanetario misiles fueron destruidos por misiles interceptores.<br>";
$irak = $this->raketenangriff($verteidiger, $angreifer, $FleetRow['fleet_amount']-$planet['interceptor_misil'], $def, $FleetRow['fleet_target_obj']);
}

$irak = $this->raketenangriff($verteidiger, $angreifer, $FleetRow['fleet_amount'], $def, $FleetRow['fleet_target_obj']);

foreach ($irak['zerstoert'] as $id => $anzahl)
{
if ($id < 10)
{
if ($id != 8)
$message .= $DefenseLabel[$id] . " (- " . $anzahl . ")<br>";

$x = $resource[$ids[$id]];
$x1 = $x ."-". $anzahl;
doquery("UPDATE {{table}} SET " . $x . " = " . $x1 . " WHERE id = " . $planet['id'], 'planets');
}
}
}
$UserPlanet = doquery("SELECT name FROM {{table}} WHERE id = '" . $FleetRow['fleet_owner'] . "'", 'planets',true);
$name = $UserPlanet['name'];
$name_deffer = $QryTargetPlanet['name'];
$message_vorlage   = 'Un ataque con misiles (' .$FleetRow['fleet_amount']. ') de ' .$name. ' ';
$message_vorlage   .= 'al planeta ' .$name_deffer.'<br><br>';

if (empty($message))
$message = "Tu planeta no tenia defensa!";

doquery("INSERT INTO {{table}} SET
`message_owner`='" . $FleetRow['fleet_target_owner'] . "',
`message_sender`='".$UserPlanet['id']."',
`message_time`=UNIX_TIMESTAMP(),
`message_type`='3',
`message_from`='Torre de Control',
`message_subject`='Ataque con misiles',
`message_text`='" . $message_vorlage . $message . "'" , 'messages');
doquery("INSERT INTO {{table}} SET
`message_owner`='" . $UserPlanet['id'] . "',
`message_sender`='".$FleetRow['fleet_target_owner']."',
`message_time`=UNIX_TIMESTAMP(),
`message_type`='3',
`message_from`='Torre de Control',
`message_subject`='Ataque con misiles',
`message_text`='" . $message_vorlage . $message . "'" , 'messages');

doquery("DELETE FROM {{table}} WHERE fleet_id = '" . $FleetRow['fleet_id'] . "'", 'fleets');
}
}
$FleetRow['fleet_start_time'] <= time();
}

private function MissionCaseExpedition($FleetRow)
{
global $lang, $resource, $pricelist;

$FleetOwner = $FleetRow['fleet_owner'];
$MessSender = $lang['sys_mess_qg'];
$MessTitle  = $lang['sys_expe_report'];

if ($FleetRow['fleet_mess'] == 0)
{
if ($FleetRow['fleet_end_stay'] < time())
{
$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.0,
217 => 1.7,
218 => 7.0,
219 => 1.3,
);

$RatioGain = array (
202 => 0.1,
203 => 0.1,
204 => 0.1,
205 => 0.5,
206 => 0.25,
207 => 0.125,
208 => 0.5,
209 => 0.1,
210 => 0.1,
211 => 0.0625,
212 => 0.0,
213 => 0.0625,
214 => 0.03125,
215 => 0.0625,
216 => 0.03125,
217 => 0.09,
218 => 0.01025,
219 => 0.09,
);

$FleetStayDuration = ($FleetRow['fleet_end_stay'] - $FleetRow['fleet_start_time']) / 3600;
$farray = explode(";", $FleetRow['fleet_array']);

foreach ($farray as $Item => $Group)
{
if ($Group != '')
{
$Class = explode (",", $Group);
$TypeVaisseau = $Class[0];
$NbreVaisseau = $Class[1];
$LaFlotte[$TypeVaisseau] = $NbreVaisseau;
$FleetCapacity    += $pricelist[$TypeVaisseau]['capacity'];
$FleetPoints       += ($NbreVaisseau * $PointsFlotte[$TypeVaisseau]);
}
}

$FleetUsedCapacity  = $FleetRow['fleet_resource_metal'] + $FleetRow['fleet_resource_crystal'] + $FleetRow['fleet_resource_deuterium'] + $FleetRow['fleet_resource_darkmatter'];
$FleetCapacity     -= $FleetUsedCapacity;
$FleetCount = $FleetRow['fleet_amount'];
$Hasard = rand(0, 10);
$MessSender = $lang['sys_mess_qg']. "(".$Hasard.")";

if ($Hasard < 3)
{
$Hasard     += 1;
$LostAmount  = (($Hasard * 33) + 1) / 100;

if ($LostAmount == 100)
{
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 == 3)
{
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>= 4 && $Hasard < 7)
{
if ($FleetCapacity> 5000)
{
$MinCapacity = $FleetCapacity - 5000;
$MaxCapacity = $FleetCapacity;
$FoundGoods  = rand($MinCapacity, $MaxCapacity);
$FoundMetal  = intval($FoundGoods / 2);
$FoundCrist  = intval($FoundGoods / 4);
$FoundDeute  = intval($FoundGoods / 6);
$FoundDark   = rand(1, 486);

$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_darkmatter` = `fleet_resource_darkmatter` + '". $FoundDark ."', ";
$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($FoundDark), $lang['Darkmatter']);

SendSimpleMessage ( $FleetOwner, '', $FleetRow['fleet_end_stay'], 15, $MessSender, $MessTitle, $Message );
}
}
elseif ($Hasard == 7)
{
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>= 8 && $Hasard < 11)
{
$FoundChance = $FleetPoints / $FleetCount;
for ($Ship = 202; $Ship < 220; $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
{
if ($FleetRow['fleet_end_time'] < time())
{
$farray = explode(";", $FleetRow['fleet_array']);
foreach ($farray as $Item => $Group)
{
if ($Group != '')
{
$Class = explode (",", $Group);
$FleetAutoQuery .= "`". $resource[$Class[0]]. "` = `". $resource[$Class[0]] ."` + ". $Class[1] .", ";
}
}
$QryUpdatePlanet  = "UPDATE {{table}} SET ";
$QryUpdatePlanet .= $FleetAutoQuery;
$QryUpdatePlanet .= "`metal` = `metal` + ". $FleetRow['fleet_resource_metal'] .", ";
$QryUpdatePlanet .= "`crystal` = `crystal` + ". $FleetRow['fleet_resource_crystal'] .", ";
$QryUpdatePlanet .= "`deuterium` = `deuterium` + ". $FleetRow['fleet_resource_deuterium'] ." ";
$QryUpdatePlanet .= "WHERE ";
$QryUpdatePlanet .= "`galaxy` = '". $FleetRow['fleet_start_galaxy'] ."' AND ";
$QryUpdatePlanet .= "`system` = '". $FleetRow['fleet_start_system'] ."' AND ";
$QryUpdatePlanet .= "`planet` = '". $FleetRow['fleet_start_planet'] ."' AND ";
$QryUpdatePlanet .= "`planet_type` = '". $FleetRow['fleet_start_type'] ."' ";
$QryUpdatePlanet .= "LIMIT 1 ;";
doquery( $QryUpdatePlanet, 'planets');

doquery("UPDATE `{{table}}` SET `darkmatter` = `darkmatter` + '".$FleetRow['fleet_resource_darkmatter']."' WHERE `id` =".$FleetRow['fleet_owner']." LIMIT 1 ;", 'users');
doquery ("DELETE FROM {{table}} WHERE `fleet_id` = ". $FleetRow["fleet_id"], 'fleets');

SendSimpleMessage ( $FleetOwner, '', $FleetRow['fleet_end_time'], 15, $MessSender, $MessTitle, $lang['sys_expe_back_home'] );
}
}
}

private function MissionFoundDM($FleetRow)
{
if ($FleetRow['fleet_mess'] == 0 && $FleetRow['fleet_end_stay'] < time())
{
$chance = rand(1, 100);
if($chance> 30)
{
$FoundDark = rand(52, 523);
$QryUpdatePlanet  = "UPDATE {{table}} SET ";
$QryUpdatePlanet .= "`metal` = `metal` + ". $FleetRow['fleet_resource_metal'] .", ";
$QryUpdatePlanet .= "`crystal` = `crystal` + ". $FleetRow['fleet_resource_crystal'] .", ";
$QryUpdatePlanet .= "`deuterium` = `deuterium` + ". $FleetRow['fleet_resource_deuterium'] ." ";
$QryUpdatePlanet .= "WHERE ";
$QryUpdatePlanet .= "`galaxy` = '". $FleetRow['fleet_start_galaxy'] ."' AND ";
$QryUpdatePlanet .= "`system` = '". $FleetRow['fleet_start_system'] ."' AND ";
$QryUpdatePlanet .= "`planet` = '". $FleetRow['fleet_start_planet'] ."' AND ";
$QryUpdatePlanet .= "`planet_type` = '3' ";
$QryUpdatePlanet .= "LIMIT 1 ;";
doquery($QryUpdatePlanet, 'planets');
doquery("UPDATE `{{table}}` SET `darkmatter` = `darkmatter` + '".$FoundDark ."' WHERE `id` =".$FleetRow['fleet_owner']." LIMIT 1 ;", 'users');
doquery("DELETE FROM {{table}} WHERE `fleet_id` = ". $FleetRow["fleet_id"], 'fleets');
$Message = sprintf($lang['sys_expe_found_goods'], 0, $lang['Metal'], 0, $lang['Crystal'], 0, $lang['Deuterium'], pretty_number($FoundDark), $lang['Darkmatter']);
SendSimpleMessage ( $FleetRow['fleet_owner'], '', $FleetRow['fleet_end_stay'], 15, $MessSender, $MessTitle, $Message );
}else{
SendSimpleMessage ( $FleetRow['fleet_owner'], '', $FleetRow['fleet_end_stay'], 15, $MessSender, $MessTitle, $lang['sys_expe_nothing_1'] );
}
}
else
{
if ($FleetRow['fleet_end_time'] < time())
{
$this->RestoreFleetToPlanet ( $FleetRow, true );

doquery("UPDATE `{{table}}` SET `darkmatter` = `darkmatter` + '".$FleetRow['fleet_resource_darkmatter']."' WHERE `id` =".$FleetRow['fleet_owner']." LIMIT 1 ;", 'users');
doquery ("DELETE FROM {{table}} WHERE `fleet_id` = ". $FleetRow["fleet_id"], 'fleets');

SendSimpleMessage ( $FleetRow['fleet_owner'], '', $FleetRow['fleet_end_time'], 15, $MessSender, $MessTitle, $lang['sys_expe_back_home'] );
}
}
}
    public function FlyingFleetHandler (&$planet)
    {

    global $resource;

    doquery("LOCK TABLE {{table}}aks WRITE, {{table}}lunas WRITE, {{table}}rw WRITE, {{table}}errors WRITE, {{table}}messages WRITE, {{table}}fleets WRITE,  {{table}}planets WRITE, {{table}}galaxy WRITE ,{{table}}users WRITE", "");

    $QryFleet   = "SELECT * FROM {{table}} ";
    $QryFleet  .= "WHERE (";
    $QryFleet  .= "( ";
    $QryFleet  .= "`fleet_start_galaxy` = ". $planet['galaxy']      ." AND ";
    $QryFleet  .= "`fleet_start_system` = ". $planet['system']      ." AND ";
    $QryFleet  .= "`fleet_start_planet` = ". $planet['planet']      ." AND ";
    $QryFleet  .= "`fleet_start_type` = ".   $planet['planet_type'] ." ";
    $QryFleet  .= ") OR ( ";
    $QryFleet  .= "`fleet_end_galaxy` = ".   $planet['galaxy']      ." AND ";
    $QryFleet  .= "`fleet_end_system` = ".   $planet['system']      ." AND ";
    $QryFleet  .= "`fleet_end_planet` = ".   $planet['planet']      ." ) AND ";
    $QryFleet  .= "`fleet_end_type`= ".      $planet['planet_type'] ." ) AND ";
    $QryFleet  .= "( `fleet_start_time` < '". time() ."' OR `fleet_end_time` < '". time() ."' );";
    $fleetquery = doquery( $QryFleet, 'fleets' );
        while ($CurrentFleet = mysql_fetch_array($fleetquery))
        {
            switch ($CurrentFleet["fleet_mission"])
            {
                case 1:
                    $this->MissionCaseAttack($CurrentFleet);
                break;

                case 2:
                    $this->MissionCaseACS($CurrentFleet);
                break;

                case 3:
                    $this->MissionCaseTransport($CurrentFleet);
                break;

                case 4:
                    $this->MissionCaseStay($CurrentFleet);
                break;

                case 5:
                    $this->MissionCaseStayAlly($CurrentFleet);
                break;

                case 6:
                    $this->MissionCaseSpy($CurrentFleet);
                break;

                case 7:
                    $this->MissionCaseColonisation($CurrentFleet);
                break;

                case 8:
                    $this->MissionCaseRecycling($CurrentFleet);
                break;

                case 9:
                    $this->MissionCaseDestruction($CurrentFleet);
                break;

                case 10:
                    $this->MissionCaseMIP($CurrentFleet);
                break;

case 11:
$this->MissionFoundDM($CurrentFleet);
break;

                case 15:
                    $this->MissionCaseExpedition($CurrentFleet);
                break;

                default:
                    doquery("DELETE FROM {{table}} WHERE `fleet_id` = '". $CurrentFleet['fleet_id'] ."';", 'fleets');
                break;

}
}

    doquery("UNLOCK TABLES", "");  

}
}
?>
lundi 12 aout 2013

Page suivante »