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,128 +1,87 @@
|
|||
<?php
|
||||
if(!defined('INDEX')) { header('Location: ../'); exit; }
|
||||
$titre = 'Bourse';
|
||||
include_once(_FCORE."../game/Class/class.bourse.php");
|
||||
|
||||
define('MAX_ACTION_PAR_JOUR', 5);
|
||||
$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 !");
|
||||
|
||||
erreur('Arrêtez de tester la bourse, on attend le nouveau script !');
|
||||
if ($a == 0) $var = 'metal';
|
||||
elseif ($a == 1) $var = 'cristal';
|
||||
elseif ($a == 2) $var = 'hydrogene';
|
||||
|
||||
/*if (date('G') < 7 && date('G') >= 0 && date('w') != 0 && date('w') != 6 && $queryUser['auth_level'] < 3)
|
||||
erreur('La bourse est actuellement fermée !<br />Réouverture à 7h00', "orange");
|
||||
else*/if ($queryPlanetes[0]['id'] != $planete->id)
|
||||
erreur('Vous devez être sur votre planète mère pour utiliser la bourse.');
|
||||
else {
|
||||
$a = gpc('a');
|
||||
$v = gpc('v');
|
||||
$nb = gpc('a'.$a.$v, 'post');
|
||||
if ($nb < 0) erreur("Vous ne pouvez pas acheter ou vendre un nombre négatif d'action !", "red", "?p=bourse");
|
||||
if (!empty($a) && is_numeric($nb)) {
|
||||
$action = new Bourse($a, $id_user);
|
||||
$poss24 = $action->actionIn24Hours();
|
||||
if ($poss24 + $nb > MAX_ACTION_PAR_JOUR) erreur('Vous ne pouvez pas acheter plus de 5 mêmes actions dans les mêmes 24h.');
|
||||
$ressources = $action->prixAchat($nb);
|
||||
if ($ressources[0] > $planete->metal || $ressources[1] > $planete->cristal) erreur('Vous n\'avez pas assez de ressources pour acheter '.$nb.' actions.');
|
||||
$action->addAction($nb);
|
||||
$planete->metal -= $ressources[0];
|
||||
$planete->cristal -= $ressources[1];
|
||||
$bdd->connexion();
|
||||
$action = $bdd->unique_query("SELECT dispo, graph FROM $table_bourse_ressources WHERE id = $a;");
|
||||
$bdd->deconnexion();
|
||||
|
||||
header('Location: ?p=bourse&d='.$a);
|
||||
exit;
|
||||
}
|
||||
elseif (!empty($v) && is_numeric($nb)) {
|
||||
$action = new Bourse($v, $id_user);
|
||||
$ressources = $action->delAction($nb);
|
||||
$planete->metal += $ressources[0];
|
||||
$planete->cristal += $ressources[1];
|
||||
//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.");
|
||||
|
||||
header('Location: ?p=bourse&d='.$v);
|
||||
exit;
|
||||
}
|
||||
elseif (gpc('e') && $planete->auth_level >= 3) {
|
||||
$e = gpc('e');
|
||||
if (isset($_POST['nomaction']) && isset($_POST['descaction'])) {
|
||||
$nom = gpc('nomaction', 'post');
|
||||
$description = gpc('descaction', 'post');
|
||||
$bdd->connexion();
|
||||
$bdd->escape($nom);
|
||||
$bdd->escape($description);
|
||||
$bdd->escape($e);
|
||||
$bdd->query("UPDATE $table_bourse SET description = '$description', nom = '$nom' WHERE id = $e;");
|
||||
$bdd->deconnexion();
|
||||
}
|
||||
elseif (isset($_POST['prixAM']) && isset($_POST['prixAC'])) {
|
||||
$prixAM = gpc('prixAM', 'post');
|
||||
$prixAC = gpc('prixAC', 'post');
|
||||
$bdd->connexion();
|
||||
$bdd->escape($prixAM);
|
||||
$bdd->escape($prixAC);
|
||||
$bdd->escape($e);
|
||||
$bdd->query("UPDATE $table_bourse SET metal = $prixAM, cristal = $prixAC WHERE id = $e;");
|
||||
$bdd->deconnexion();
|
||||
}
|
||||
elseif (isset($_POST['newsaction'])) {
|
||||
$news = gpc('newsaction', 'post');
|
||||
$time = time();
|
||||
$bdd->connexion();
|
||||
$bdd->escape($news);
|
||||
$bdd->escape($e);
|
||||
$bdd->query("UPDATE $table_bourse SET news = '$news', timeDesc = '$time' WHERE id = $e;");
|
||||
$bdd->deconnexion();
|
||||
}
|
||||
//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 !");
|
||||
|
||||
header('Location: ?p=bourse&d='.$e);
|
||||
exit;
|
||||
}
|
||||
elseif (gpc('c') == "new" && $planete->auth_level >= 3 && is_numeric(gpc('prixAM', 'post')) && is_numeric(gpc('prixAC', 'post'))) {
|
||||
if (isset($_POST['nomaction']) && isset($_POST['descaction'])) {
|
||||
$nom = gpc('nomaction', 'post');
|
||||
$description = gpc('descaction', 'post');
|
||||
$prixAM = gpc('prixAM', 'post');
|
||||
$prixAC = gpc('prixAC', 'post');
|
||||
$news = gpc('newsaction', 'post');
|
||||
$time = time();
|
||||
$bdd->connexion();
|
||||
$bdd->escape($nom);
|
||||
$bdd->escape($description);
|
||||
$bdd->escape($prixAM);
|
||||
$bdd->escape($prixAC);
|
||||
$bdd->escape($news);
|
||||
if (!empty($news)) $bdd->query("INSERT INTO $table_bourse (nom, description, news, timeDesc, metal, cristal) VALUES ('$nom', '$description', '$news', '$time', '$prixAM', '$prixAC');");
|
||||
else $bdd->query("INSERT INTO $table_bourse (nom, description, metal, cristal) VALUES ('$nom', '$description', '$prixAM', '$prixAC');");
|
||||
$bdd->deconnexion();
|
||||
}
|
||||
$prix = ceil(pow($action['dispo'], -0.1) * $nb * 1.07)/10;
|
||||
|
||||
header('Location: ?p=bourse');
|
||||
exit;
|
||||
}
|
||||
elseif ($d = gpc('d')) {
|
||||
$action = new Bourse($d, $id_user);
|
||||
$template->assign('taxeA', $action->taxeA);
|
||||
$template->assign('taxeV', $action->taxeV);
|
||||
$template->assign('poss', $action->action());
|
||||
$template->assign('poss24', $action->actionIn24Hours());
|
||||
$action = null;
|
||||
//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($d);
|
||||
$bourse = $bdd->unique_query("SELECT id, nom, description, news, metal, cristal, (metal/metalAnc-1)*100 AS evolution FROM $table_bourse WHERE id = $d;");
|
||||
$bdd->escape($graph);
|
||||
$bdd->query("UPDATE $table_bourse_ressources SET dispo = dispo - $nb, graph = '$graph' WHERE id = $a;");
|
||||
$bdd->deconnexion();
|
||||
|
||||
if ($bourse) {
|
||||
$page = 'bourseDetails';
|
||||
$template->assign('bourse', $bourse);
|
||||
}
|
||||
else erreur('Cette action n\'existe pas !', "red", '?p=bourse');
|
||||
}
|
||||
else {
|
||||
$bdd->connexion();
|
||||
$infos = $bdd->query("SELECT id, nom, news AS description FROM $table_bourse WHERE news != '' ORDER BY timeDesc DESC LIMIT 7;");
|
||||
$bourse = $bdd->query("SELECT id, nom, metal, cristal, (metal/metalAnc-1)*100 AS evolution FROM $table_bourse;");
|
||||
$bdd->deconnexion();
|
||||
|
||||
$page = 'bourse';
|
||||
$template->assign('bourse', $bourse);
|
||||
$template->assign('infos', $infos);
|
||||
}
|
||||
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 <= 0 || $nb > 99999999) erreur("Nombre de ressources invalide !");
|
||||
|
||||
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 * 0.9)/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