Correctifs sur la page de préparation d'envoie des flotte
All checks were successful
continuous-integration/drone/push Build is passing

This commit is contained in:
Nigel Sheldon 2021-01-03 18:43:43 +01:00 committed by Gitea
parent 52e4266218
commit c56099e3b0
8 changed files with 125 additions and 58 deletions

View File

@ -1,16 +1,20 @@
<?php
define("INDEX", 1);
define("DEBUG", false);
$chrono_start = microtime();
$onyx = @file_get_contents('./.onyx') or die("Configuration introuvable.");
define("_FCORE", trim($onyx));
require(_FCORE."../game/Class/JSON.php");
require_once(_FCORE."common.php");
require_once(trim(file_get_contents('./.onyx')));
require_once("common.php"); //Chargement de tout le nécessaire pour le jeu
require_once("function.php");
require_once("Class/JSON.php");
require_once("Class/flotte.php");
require_once("Class/planete.php");
if (isset($sess) && isset($sess->values['connected']) && $sess->values['connected'] && !empty($sess->values['id']) && !empty($sess->level) && !empty($sess->values['idPlan'])) {
if (isset($SESS) && isset($SESS->values['connected']) && $SESS->values['connected'] && !empty($SESS->values['id']) && !empty($SESS->level) && !empty($SESS->values['idPlan'])) {
$idPrep = gpc("cds_temp", "post");
$json = new Services_JSON();
$nbtrajet = 2;
if (empty($config['flottes']) && $sess->level <= 1) {
if (empty($config['flottes']) && $SESS->level <= 1) {
$datas = array(
'root' => array(
'destination' => '<input class="dest" type="text" id="amas" name="amas" maxlength="2" value="'.gpc('galaxie', 'post').'" />:<input class="dest" type="text" id="ss" name="ss" maxlength="2" value="'.gpc('ss', 'post').'" />:<input class="dest" type="text" id="plan" name="pos" maxlength="2" value="'.gpc('pos', 'post').'" />',
@ -28,8 +32,7 @@ if (isset($sess) && isset($sess->values['connected']) && $sess->values['connecte
$destin = gpc('fav_dest', 'post');
$chapeau = new bdd();
$chapeau->connexion();
$idPlan = $sess->values['idPlan'];
$idPlan = $SESS->values['idPlan'];
$queryPlanete = $chapeau->unique_query("SELECT * FROM $table_planete WHERE id = '$idPlan'");
if (!empty($destin)) {
$chapeau->escape($destin);
@ -45,18 +48,11 @@ if (isset($sess) && isset($sess->values['connected']) && $sess->values['connecte
$start_ss = $queryPlanete['ss'];
$start_position = $queryPlanete['position'];
$met = gpc('met', 'post');
$cri = gpc('cri', 'post');
$hyd = gpc('hyd', 'post');
if (!empty($sess->values['flcontenu']) && $met+$cri+$hyd >= 0 && $met >= 0 && $cri >= 0 && $hyd >= 0) {
$places = $sess->values['flcontenu'] - ($met+$cri+$hyd);
} else {
$places = 'inconnu';
}
if (empty($sess->values['fltime']) || $sess->values['fltime'] + 600 < time() || empty($sess->values['flnbvais']) || empty($sess->values['flvitesse']) && isset($sess->values['auth_level'])) {
if (empty($SESS->values["prepFlottes"][$idPrep]['time']) ||
$SESS->values["prepFlottes"][$idPrep]['time'] + 1200 < time() ||
empty($SESS->values["prepFlottes"][$idPrep]['nbVaisseaux']) ||
empty($SESS->values["prepFlottes"][$idPrep]['vitesse']) &&
isset($SESS->values['auth_level'])) {
$datas = array(
'root' => array(
'destination' => $destinRapid,
@ -64,7 +60,7 @@ if (isset($sess) && isset($sess->values['connected']) && $sess->values['connecte
'deblok' => '<b>Une erreur est survenue lors de la création de la flotte. Veuillez recommencer</b>',
'conso' => '-',
'tactique' => '',
'places' => separerNombres($places)
'places' => '',
)
);
} elseif (empty($_POST['nom']) || preg_replace('@[^a-zA-Z0-9_ ]@i', '', $_POST['nom']) != $_POST['nom']) {
@ -75,10 +71,10 @@ if (isset($sess) && isset($sess->values['connected']) && $sess->values['connecte
'deblok' => '<b>Nom de la flotte incorrect !</b>',
'conso' => '-',
'tactique' => '',
'places' => separerNombres($places)
'places' => '',
)
);
} elseif ($_POST['galaxie'] > MAX_AMAS || $_POST['ss'] > MAX_SYSTEME || $_POST['pos'] > MAX_PLANETE || $_POST['galaxie'] < 0 || $_POST['ss'] < 1 || $_POST['pos'] < 1 || ($_POST['galaxie'] < 1 && $sess->values['auth_level'] < 6)) {
} elseif ($_POST['galaxie'] > $VAR['nb_amas'] || $_POST['ss'] > $VAR['nb_systeme'] || $_POST['pos'] > $VAR['nb_planete'] || $_POST['galaxie'] < 0 || $_POST['ss'] < 1 || $_POST['pos'] < 1 || ($_POST['galaxie'] < 1 && $SESS->values['auth_level'] < 6)) {
$datas = array(
'root' => array(
'destination' => $destinRapid,
@ -86,23 +82,37 @@ if (isset($sess) && isset($sess->values['connected']) && $sess->values['connecte
'deblok' => '<b>Corrigez la destination !</b>',
'conso' => '-',
'tactique' => '',
'places' => separerNombres($places)
'places' => '',
)
);
} else {
$_POST['vitesse'] /= 100;
$temps = vais_tempsDeplacement($start_galaxie, $start_ss, $start_position, $_POST['galaxie'], $_POST['ss'], $_POST['pos'], $sess->values['flvitesse'], $_POST['vitesse'], $sess->values['flpreparation'], $sess->values['flchauffe']);
$planete = new planete($idPlan);
$flotte = new flotte();
$temps = $flotte->calc_deplacement($planete, $_POST['galaxie'], $_POST['ss'], $_POST['pos'], $_POST['vitesse'], $SESS->values["prepFlottes"][$idPrep]['vaisseaux'], 1000);
if ($temps <= 0) {
$temps = 454;
}
$conso = vais_conso($temps, $sess->values['flnbvais'])*$_POST['vitesse']/45;
$places -= ceil($conso*$nbtrajet);
$conso = $flotte->calc_deplacement($planete, $_POST['galaxie'], $_POST['ss'], $_POST['pos'], $_POST['vitesse'], $SESS->values["prepFlottes"][$idPrep]['vaisseaux'], 1000, false, true);
// $conso renvoi le temps ET la conso dans un array
$conso = intval($conso[1]);
$met = intval(gpc('met', 'post'));
$cri = intval(gpc('cri', 'post'));
$hyd = intval(gpc('hyd', 'post'));
$places = $flotte->calcStockage($SESS->values["prepFlottes"][$idPrep]['vaisseaux'], $planete);
$places -= ceil($conso * $nbtrajet);
if (($met+$cri+$hyd) > 0) {
$places -= ($met+$cri+$hyd);
}
$tactique = '';
if ($_POST['mission'] == '1') {
$tactique = '<label for="selecttactique">Tactique d\'attaque :</label><select id="selecttactique" name="tactique">';
//On récupère le niveau actuel de la technologie Commandement militaire
$id_user = $sess->values['id'];
$table = $config['db_prefix'].'user';
$id_user = $SESS->values['id'];
global $table_user;
$table = $table_user;
$queryUser = $chapeau->unique_query("SELECT * FROM $table WHERE id = '$id_user'");
$lvltechno = $queryUser['tactique'];
$tactiquedef = $queryUser['combatAT_tactique'];
@ -113,9 +123,9 @@ if (isset($sess) && isset($sess->values['connected']) && $sess->values['connecte
'destination' => $destinRapid,
'temps' => affTemp(floor($temps)),
'deblok' => '<b>Vous ne pouvez pas attaquer sans un minimum de connaissances militaires !</b>',
'conso' => separerNombres(ceil($conso*$nbtrajet)),
'conso' => ceil($conso*$nbtrajet),
'tactique' => '',
'places' => separerNombres($places)
'places' => $places
)
);
header("X-JSON: ".$json->encode($datas));
@ -131,17 +141,16 @@ if (isset($sess) && isset($sess->values['connected']) && $sess->values['connecte
}
$tactique .= '</select><br />';
}
$cds = sha1('flotte'.$conso.'ß10'.time().'|HB;'.rand(10, 99).$temps);
$sess->values['flcds'] = $cds;
$sess->put();
$SESS->values['flcds'] = $idPrep;
$SESS->put();
$datas = array(
'root' => array(
'destination' => $destinRapid,
'temps' => affTemp(floor($temps)),
'deblok' => '<input type="hidden" name="cds" value="'.$cds.'" /><input type="submit" value="GO" class="submit" />',
'conso' => separerNombres(ceil($conso*2)),
'deblok' => '<input type="hidden" name="cds" value="'.$idPrep.'" /><input type="submit" value="GO" class="submit" />',
'conso' => ceil($conso*2),
'tactique' => $tactique,
'places' => separerNombres($places)
'places' => $places
)
);
}

View File

@ -91,11 +91,26 @@ window.onload = function(){
function tempsFlotte() {
document.getElementById('deblok').innerHTML = '...';
var url_string = (window.location.href).toLowerCase();
var url = new URL(url_string);
var cds = url.searchParams.get("c");
new Ajax.Request(
'ajax_flotte.php',
{
method: 'post',
parameters: {fav_dest: document.getElementById('fav_dest').value, nom: document.getElementById('nom').value, mission: document.getElementById('mission').value, met: document.getElementById('metal').value, cri: document.getElementById('cristal').value, hyd: document.getElementById('hydrogene').value, galaxie: document.getElementById('amas').value, ss: document.getElementById('ss').value, pos: document.getElementById('plan').value, vitesse: document.getElementById('vitesse').value},
parameters: {
cds_temp: cds,
fav_dest: document.getElementById('fav_dest').value,
nom: document.getElementById('nom').value,
mission: document.getElementById('mission').value,
met: document.getElementById('metal').value,
cri: document.getElementById('cristal').value,
hyd: document.getElementById('hydrogene').value,
galaxie: document.getElementById('amas').value,
ss: document.getElementById('ss').value,
pos: document.getElementById('plan').value,
vitesse: document.getElementById('vitesse').value
},
onSuccess: function(transport, json) {
document.getElementById('destination').innerHTML = json.root.destination;
document.getElementById('temps').innerHTML = json.root.temps;

View File

@ -734,7 +734,7 @@ class dSpatial implements Donnees
}
public static function tailleCales($id)
public static function tailleCales($id, surface $planete)
{
if ($planete->race == "humain") {
switch ($id) {
@ -781,7 +781,7 @@ class dSpatial implements Donnees
$vitesse = 15000;
break;
default:
trigger_error("Vaisseau ".$id." introuvable dans les données", E_USER_ERROR);
$vitesse = 0;
}
} else {
switch ($id) {
@ -837,7 +837,7 @@ class dSpatial implements Donnees
$vitesse = 20000000;
break;
default:
trigger_error("Vaisseau ".$id." introuvable dans les données", E_USER_ERROR);
$vitesse = 0;
}
}
@ -846,7 +846,7 @@ class dSpatial implements Donnees
}
public static function vitesseP($id)
public static function vitesseP($id, surface $planete)
{
if ($planete->race == "humain") {
switch ($id) {
@ -957,7 +957,7 @@ class dSpatial implements Donnees
return $vitesse;
}
public static function vitesseS($id)
public static function vitesseS($id, surface $planete)
{
if ($planete->race == "humain") {
switch ($id) {
@ -1068,7 +1068,7 @@ class dSpatial implements Donnees
return $vitesse;
}
public static function vitesseG($id)
public static function vitesseG($id, surface $planete)
{
if ($planete->race == "humain") {
switch ($id) {

View File

@ -88,12 +88,13 @@ class Flotte
public function calculer()
{
global $planete;
$this->nb_vais = 0;
//Calcul de la capacité maximale d'embarquement de la flotte
foreach ($this->vaisseaux as $key => $vais) {
$this->nb_vais += $vais;
$this->contenuMax += dSpatial::tailleCales($key) * $vais;
$this->contenuMax += dSpatial::tailleCales($key, $planete) * $vais;
}
}
@ -265,20 +266,20 @@ class Flotte
//Calcul du temps de déplacement entre planètes
if ($start_planete->ss == $end_systeme && $start_planete->galaxie == $end_galaxie) {
$temps[0][$key] = (1000/dSpatial::vitesseP($key)) * (1 + 0.1 * $diff_position);
$temps[0][$key] = (1000/dSpatial::vitesseP($key, $start_planete)) * (1 + 0.1 * $diff_position);
$temps[1][$key] = $temps[2][$key] = 0;
}
//Calcul du temps de déplacement entre système
elseif ($start_planete->galaxie == $end_galaxie) {
$temps[0][$key] = (1000/dSpatial::vitesseP($key)) * (1 + 0.1 * ($diff_centre_position_start + $diff_centre_position_end));
$temps[1][$key] = (2000/dSpatial::vitesseS($key)) * (2 + 1 * $diff_systeme);
$temps[0][$key] = (1000/dSpatial::vitesseP($key, $start_planete)) * (1 + 0.1 * ($diff_centre_position_start + $diff_centre_position_end));
$temps[1][$key] = (2000/dSpatial::vitesseS($key, $start_planete)) * (2 + 1 * $diff_systeme);
$temps[2][$key] = 0;
}
//Calcul du temps de déplacement entre galaxies
else {
$temps[0][$key] = (1000/dSpatial::vitesseP($key)) * (1 + 0.1 * ($diff_centre_position_start + $diff_centre_position_end));
$temps[1][$key] = (2000/dSpatial::vitesseS($key)) * (2 + 1 * ($diff_centre_systeme_start + $diff_centre_systeme_end));
$temps[2][$key] = (5000/dSpatial::vitesseG($key)) * (2 + 1.5 * $diff_galaxie);
$temps[0][$key] = (1000/dSpatial::vitesseP($key, $start_planete)) * (1 + 0.1 * ($diff_centre_position_start + $diff_centre_position_end));
$temps[1][$key] = (2000/dSpatial::vitesseS($key, $start_planete)) * (2 + 1 * ($diff_centre_systeme_start + $diff_centre_systeme_end));
$temps[2][$key] = (5000/dSpatial::vitesseG($key, $start_planete)) * (2 + 1.5 * $diff_galaxie);
}
//Calcul du bonus pour le réacteur à combustion
@ -332,7 +333,7 @@ class Flotte
}
//Si les chasseurs peuvent rentrer dans les cales des vaisseaux, on les enlèves
if ($contenuDispo - ceil($conso[0]+$conso[1]+$conso[2]) - ($vaisseaux[4] * dSpatial::tailleCales(4) + $vaisseaux[5] * dSpatial::tailleCales(5)) >= ($vaisseaux[4] + $vaisseaux[5]) * 200) {
if ($contenuDispo - ceil($conso[0]+$conso[1]+$conso[2]) - ($vaisseaux[4] * dSpatial::tailleCales(4, $start_planete) + $vaisseaux[5] * dSpatial::tailleCales(5, $start_planete)) >= ($vaisseaux[4] + $vaisseaux[5]) * 200) {
$temps[2][4] = $temps[2][5] = $temps[1][4] = $temps[1][5] = $temps[0][4] = $temps[0][5] = 0;
}
@ -347,6 +348,21 @@ class Flotte
}
public function calcStockage($vaisseaux, surface $planete)
{
global $LANG;
$contenuMax = 0;
foreach ($vaisseaux as $key => $vais) {
if (!isset($LANG[$planete->race]["vaisseaux"]["noms_sing"][$key])) {
continue;
}
$contenuMax += dSpatial::tailleCales($key, $planete) * $vais;
}
return $contenuMax;
}
public function check_mission()
{
//On vérifie qu'un calcul ne soit pas déjà en cours

View File

@ -5,7 +5,29 @@ if (!defined('INDEX')) {
}
$bdd->reconnexion();
$flottes = $bdd->query("SELECT id FROM $table_flottes WHERE (id_user = ".$planete->id_user." OR end_planete = ".$planete->id." OR id_alliance = ".$planete->id_alliance." OR end_planete = ".$planete->id_alliance.") AND (start_time + end_time) <= ".time()." AND last < ".(time()-10).";");
$sql = "";
if ($planete->id_user != null) {
$sql = "id_user = " . $planete->id_user . " ";
}
if ($planete->id != null) {
if ($sql != "") {
$sql .= " OR ";
}
$sql .= "end_planete = " . $planete->id . " ";
}
if ($planete->id_alliance != null) {
if ($sql != "") {
$sql .= " OR ";
}
$sql .= "id_alliance = " . $planete->id_alliance . " ";
}
if ($planete->id_alliance != null) {
if ($sql != "") {
$sql .= " OR ";
}
$sql .= "end_planete = " . $planete->id_alliance . " ";
}
$flottes = $bdd->query("SELECT id FROM $table_flottes WHERE (" . $sql . ") AND (start_time + end_time) <= ".time()." AND last < ".(time()-10).";");
$bdd->deconnexion();
if (!empty($flottes)) {

View File

@ -7,6 +7,10 @@ if (!defined('INDEX')) {
//Génération d'un ID unique pour identifier la flotte durant sa création
$idPrep = random();
//Supression des précédentes flottes, sinon il y a un risque de remplir le champs de BDD qui sauvegarde les flottes
$SESS->values["prepFlottes"] = null;
$SESS->values["prepFlottes"] = array();
//Création du tableau de session
$SESS->values["prepFlottes"][$idPrep] = array();
@ -41,6 +45,7 @@ $SESS->values["prepFlottes"][$idPrep]['nbVaisseaux'] = $nombreVaisseau;
$SESS->values['forceFlotte'] = false;
$SESS->values["prepFlottes"][$idPrep]['time'] = time();
$SESS->values["prepFlottes"][$idPrep]['statut'] = 1;
$SESS->values["prepFlottes"][$idPrep]['vitesse'] = 100; // vitesse par défaut: 100%
$SESS->put();
unset($nombreVaisseau, $key, $vaisseau, $v);

View File

@ -45,8 +45,8 @@ if ($onglet == "rapports") {
}
$bdd->reconnexion();
$data = $bdd->query("SELECT * FROM $table_mail WHERE destinataire = ".$planete->id_user." AND expediteur = false AND vu != 's' ORDER BY id DESC;");
$bdd->query("UPDATE $table_mail SET vu = 0 WHERE destinataire = ".$planete->id_user." AND expediteur = false AND vu != 's';");
$data = $bdd->query("SELECT * FROM $table_mail WHERE destinataire = ".$planete->id_user." AND expediteur IS NULL AND vu != 's' ORDER BY id DESC;");
$bdd->query("UPDATE $table_mail SET vu = 0 WHERE destinataire = ".$planete->id_user." AND expediteur IS NULL AND vu != 's';");
$bdd->deconnexion();
$template->assign('messages', $data);

View File

@ -23,7 +23,7 @@
</fieldset>
<h2>Envoyer</h2>
<noscript><span style="color: #FF0000; font-weight: bolder;">Le JavaScript est nécessaire pour envoyer une flotte.</span><br /></noscript>
<input type="submit" value="GO" class="submit" /><input type="hidden" name="cds" value="{$idPrep}" /><br />
<input type="hidden" name="cds" value="{$idPrep}" /><br />
Temps de déplacement : <span id="temps">-</span><br />
Consomation : <span id="conso">-</span><br />
<span id="deblok"><b>Compl&egrave;tez les champs ci-dessus</b></span>