game/pages/chantier_spatial_validation.php

141 lines
4.5 KiB
PHP

<?php
session_start();
$id=$_SESSION['id'];
$galaxy=$_SESSION['galaxy'];
$ss=$_SESSION['ss'];
$pos=$_SESSION['pos'];
$race=$_SESSION['race'];
include_once('common.php');
require('../connectBDD.php');
if (isset($_POST['type'])) $_GET['type'] = $_POST['type'];
elseif (!isset($_GET['type'])) $_GET['type'] = '';
if ($_GET['type'] == 'e' && $labo >= 1 && !ereg('e,', implode(',',$fileVai).',')) {
//$temps_s = '';
//$vai = 'e';
}
else {
// Annulation de la production en chaîne si elle existe
//if (ereg('e,', implode(',',$fileVai).',')) { header('Location: annul_bat.php?bat=e&go='.$_GET['type']); exit; }
if (!isset($_POST['sa'])) exit;
else $sa = abs(floor($_POST['sa']));
if ($_GET['type'] == 1 && $chantier_spatial >= 1 && $reacteur >= 4) {
$metal -= 1000*$sa;
$cristal -= 800*$sa;
$temps_s = ceil(1080/pow(1.25,($chantier_spatial-1)));
$vai = 1;
}
elseif ($_GET['type'] == 2 && $chantier_spatial >= 5 && $reacteur_f >= 2) {
$metal -= 4000*$sa;
$cristal -= 3000*$sa;
$temps_s = ceil(6300/pow(1.25,($chantier_spatial-5)));
$vai = 2;
}
elseif ($_GET['type'] == 3 && $chantier_spatial >= 5 && $reacteur_ff >= 1) {
$metal -= 9000*$sa;
$cristal -= 9000*$sa;
$hydrogene -= 1000*$sa;
$temps_s = ceil(8280/pow(1.25,($chantier_spatial-5)));
$vai = 3;
}
elseif ($_GET['type'] == 4 && $chantier_spatial >= 3 && $reacteur >= 5 && $detection >= 2) {
$metal -= 1000*$sa;
$cristal -= 1200*$sa;
$hydrogene -= 100*$sa;
$temps_s = ceil(1440/pow(1.25,($chantier_spatial-3)));
$vai = 4;
}
elseif ($_GET['type'] == 5 && $chantier_spatial >= 5 && $reacteur_f >= 4 && $blindage >= 5) {
$metal -= 15000*$sa;
$cristal -= 9000*$sa;
$hydrogene -= 1000*$sa;
$temps_s = ceil(7380/pow(1.25,($chantier_spatial-5)));
$vai = 5;
}
elseif ($_GET['type'] == 6 && $chantier_spatial >= 1 && $reacteur >= 4) {
$metal -= 1700*$sa;
$cristal -= 1220*$sa;
$temps_s = ceil(1200/pow(1.25,($chantier_spatial-1)));
$vai = 6;
}
elseif ($_GET['type'] == 7 && $chantier_spatial >= 3 && $reacteur_f >= 3 && $armement >=1) {
$metal -= 5800*$sa;
$cristal -= 1400*$sa;
$temps_s = ceil(4680/pow(1.25,($chantier_spatial-3)));
$vai = 7;
}
elseif ($_GET['type'] == 8 && $chantier_spatial >= 6 && $reacteur_ff >= 2 && $armement >= 3 && $blindage >= 4) {
$metal -= 20000*$sa;
$cristal -= 16000*$sa;
$hydrogene -= 1600*$sa;
$temps_s = ceil(16800/pow(1.25,($chantier_spatial-6)));
$vai = 8;
}
elseif ($_GET['type'] == 9 && $chantier_spatial >= 6 && $reacteur_ff >= 3 && $armement >= 4 && $blindage >= 4) {
$metal -= 26000*$sa;
$cristal -= 16400*$sa;
$hydrogene -= 1600*$sa;
$temps_s = ceil(18060/pow(1.25,($chantier_spatial-6)));
$vai = 9;
}
elseif ($_GET['type'] == 10 && $chantier_spatial >= 8 && $reacteur_ff >= 5 && $armement >=6 && $blindage >= 6) {
$metal -= 60000*$sa;
$cristal -= 40000*$sa;
$hydrogene -= 3000*$sa;
$temps_s = ceil(32400/pow(1.25,($chantier_spatial-8)));
$vai = 10;
}
elseif ($_GET['type'] == 11 && $chantier_spatial >= 12 && $reacteur_ff >= 10 && $armement >= 12 && $blindage >= 12) {
$metal -= 500000*$sa;
$cristal -= 400000*$sa;
$hydrogene -= 250000*$sa;
$temps_s = ceil(117000/pow(1.25,($chantier_spatial-12)));
$vai = 11;
}
elseif ($_GET['type'] == 12 && $chantier_spatial >= 12 && $reacteur_ff >= 10 && $armement >= 12 && $blindage >= 12) {
$metal -= 500000*$sa;
$cristal -= 400000*$sa;
$hydrogene -= 250000*$sa;
$temps_s = ceil(117000/pow(1.25,($chantier_spatial-12)));
$vai = 12;
}
}
if (isset($vai) && $vai != '' && (!empty($nomvaisn[$vai-1]) || $vai == 'e' || (isset($_GET['act']) && $_GET['act'] == 'e'))) {
if ($metal >= 0 && $cristal >= 0 && $hydrogene >= 0) {
for ($c=0 ; $c < $sa ; $c++){
$fileVai = explode(' ',implode(' ',$fileVai).' '.$vai);
}
$vai = implode(' ',$fileVai);
if (count($fileTemps_s) == 0 || count($fileTemps_s) == 1) {
$temps_ss = time();
for ($c=0 ; $c < $sa ; $c++){
$temps_ss .= ' '.$temps_s;
}
$temps_s = $temps_ss;
}
else {
$temps_ss = implode(' ',$fileTemps_s);
for ($c=0 ; $c < $sa ; $c++){
$temps_ss .= ' '.$temps_s;
}
$temps_s = $temps_ss;
}
mysql_query("UPDATE planete SET metal='$metal', cristal='$cristal', hydrogene='$hydrogene', temps_spatial='$temps_s', unit_s='$vai' WHERE id_user='$id' AND galaxie='$galaxy' AND ss='$ss' AND position='$pos'") or die ("erreur sql ".mysql_error());
}
else {
header('Location: chantier_spatial.php?err=3');
exit;
}
}
mysql_close();
$vai = $fileVai[0];
if (isset($_GET['go']) && $_GET['go'] == 1) header('Location: chantier_spatial.php?err=2');
else header('Location: chantier_spatial.php');
?>