forked from halo-battle/game
Version 1.12
This commit is contained in:
parent
2a066a7498
commit
de31cd3e9a
1373 changed files with 156282 additions and 45238 deletions
|
|
@ -1,5 +1,87 @@
|
|||
<?php
|
||||
if(!defined('INDEX')) { header('Location: ../'); exit; }
|
||||
$titre = 'Marché';
|
||||
$titre = 'Bourse';
|
||||
|
||||
$a = gpc('a');
|
||||
$v = gpc('v');
|
||||
if(is_numeric($a) && is_numeric(gpc('a'.$a, 'post'))){
|
||||
$nb = gpc('a'.$a, 'post');
|
||||
if ($nb <= 0 || $nb > 99999999) erreur("Nombre de ressources invalide !");
|
||||
|
||||
if ($a == 0) $var = 'metal';
|
||||
elseif ($a == 1) $var = 'cristal';
|
||||
elseif ($a == 2) $var = 'hydrogene';
|
||||
|
||||
$bdd->connexion();
|
||||
$action = $bdd->unique_query("SELECT dispo, graph FROM $table_bourse_ressources WHERE id = $a;");
|
||||
$bdd->deconnexion();
|
||||
|
||||
//On vérifie que la bourse ait suffisament de ressources à distribuer :
|
||||
if ($action['dispo'] <= $nb) erreur("Il n'y a pas assez de ressources dans la galaxie pour que vous puissiez en acheter autant.");
|
||||
|
||||
//On vérifie qu'il reste suffisamment de place dans les silos du joueur
|
||||
if ($planete->cap < $planete->$var + $nb) $nb = $planete->cap - $planete->$var;
|
||||
if ($nb <= 0) erreur("Vous n'avez pas assez de place pour stocker ces ressources !");
|
||||
|
||||
$prix = ceil(pow($action['dispo'], -0.1) * $nb * 2.20)/10;
|
||||
|
||||
//On vérifie que le joueur ait assez de crédits pour acheter
|
||||
if ($prix <= $planete->credits) {
|
||||
$planete->credits -= $prix;
|
||||
$planete->$var += $nb;
|
||||
|
||||
if (empty($action['graph'])) $action['graph'] = array();
|
||||
else $action['graph'] = unserialize($action['graph']);
|
||||
$action['graph'][date('w')] = $action['dispo'];
|
||||
$graph = serialize($action['graph']);
|
||||
|
||||
$bdd->connexion();
|
||||
$bdd->escape($graph);
|
||||
$bdd->query("UPDATE $table_bourse_ressources SET dispo = dispo - $nb, graph = '$graph' WHERE id = $a;");
|
||||
$bdd->deconnexion();
|
||||
}
|
||||
else erreur("Vous n'avez pas assez de crédits pour faire cet achat !");
|
||||
}
|
||||
elseif(is_numeric($v) && is_numeric(gpc('a'.$v, 'post'))){
|
||||
$nb = gpc('a'.$v, 'post');
|
||||
if ($nb <= 1000 || $nb > 99999999) erreur("Nombre de ressources invalide !<br />Vous pouvez vendre au minimum 1000 ressources !");
|
||||
|
||||
if ($v == 0) $var = 'metal';
|
||||
elseif ($v == 1) $var = 'cristal';
|
||||
elseif ($v == 2) $var = 'hydrogene';
|
||||
|
||||
//On vérifie que le joueur ait assez de ressources pour vendre, sinon, on ajuste à son maximum
|
||||
if ($nb > $planete->$var) $nb = $planete->$var;
|
||||
|
||||
$bdd->connexion();
|
||||
$action = $bdd->unique_query("SELECT dispo, graph FROM $table_bourse_ressources WHERE id = $v;");
|
||||
$bdd->deconnexion();
|
||||
|
||||
$prix = ceil(pow($action['dispo'], -0.1) * $nb * 1.8)/10;
|
||||
$planete->credits += $prix;
|
||||
$planete->$var -= $nb;
|
||||
|
||||
if (empty($action['graph'])) $action['graph'] = array();
|
||||
else $action['graph'] = unserialize($action['graph']);
|
||||
$action['graph'][date('w')] = $action['dispo'];
|
||||
$graph = serialize($action['graph']);
|
||||
|
||||
$bdd->connexion();
|
||||
$bdd->escape($graph);
|
||||
$bdd->query("UPDATE $table_bourse_ressources SET dispo = dispo + $nb, graph = '$graph' WHERE id = $v;");
|
||||
$bdd->deconnexion();
|
||||
}
|
||||
|
||||
$bdd->connexion();
|
||||
$bourse = $bdd->query("SELECT id, dispo FROM $table_bourse_ressources;");
|
||||
$bdd->deconnexion();
|
||||
|
||||
foreach($bourse as $key => $action){
|
||||
$bourse[$key]['prix'] = pow($action['dispo'], -0.1) * 200;
|
||||
$bourse[$key]['prixV'] = $bourse[$key]['prix'] * 0.9;
|
||||
$bourse[$key]['prixA'] = $bourse[$key]['prix'] * 1.07;
|
||||
}
|
||||
|
||||
$page = 'bourse_ressources';
|
||||
$template->assign('bourse', $bourse);
|
||||
?>
|
||||
Loading…
Add table
Add a link
Reference in a new issue