forked from halo-battle/game
Version 1.9g
This commit is contained in:
parent
d028822d0b
commit
4c9814a99c
800 changed files with 237325 additions and 1949 deletions
|
|
@ -1,160 +0,0 @@
|
|||
<?php
|
||||
/**
|
||||
* Classe Bourse par Pierre-Olivier MERCIER
|
||||
* Dernière édition le 21 Juillet 2008
|
||||
* Copyright Halo-Battle Tous droits réservés
|
||||
*/
|
||||
class Bourse{
|
||||
var $bd;
|
||||
|
||||
var $id;
|
||||
var $nom;
|
||||
var $taxeA = 1.1;
|
||||
var $achatM;
|
||||
var $achatC;
|
||||
var $taxeV = 1;
|
||||
var $venteM;
|
||||
var $venteC;
|
||||
var $actionsUser;
|
||||
var $user;
|
||||
|
||||
/**
|
||||
* Constructor
|
||||
*
|
||||
* @param String $nom Nom de l'action
|
||||
* @param int $user ID du joueur à charger automatiquement
|
||||
*
|
||||
* @access protected
|
||||
*/
|
||||
function Bourse($nom = "", $user = 0){
|
||||
global $var___db, $config;
|
||||
$db = new bdd();
|
||||
$db->connexion();
|
||||
$this->bd = $db;
|
||||
|
||||
if (!empty($nom)) {
|
||||
$this->loadAction($nom);
|
||||
if (!empty($user)) $this->loadUser($user);
|
||||
}
|
||||
}
|
||||
|
||||
function loadAction($nom, $type = "nom"){
|
||||
global $table_bourse;
|
||||
$act = $this->bd->unique_query("SELECT * FROM $table_bourse WHERE $type = '$nom';");
|
||||
$this->id = $act['id'];
|
||||
$this->nom = $act['nom'];
|
||||
$this->achatM = $act['achatM'];
|
||||
$this->achatC = $act['achatC'];
|
||||
$this->venteM = $act['venteM'];
|
||||
$this->venteC = $act['venteC'];
|
||||
}
|
||||
|
||||
function loadUser($user, $type = "id"){
|
||||
global $table_user;
|
||||
$act = $this->bd->unique_query("SELECT id, bourse FROM $table_user WHERE $type = '$user';");
|
||||
$this->user = $act['id'];
|
||||
$this->traitUser($act['bourse']);
|
||||
}
|
||||
|
||||
function traitUser($start){
|
||||
$end = array();
|
||||
$start = explode(';', $start);
|
||||
$cnt = count($start);
|
||||
for($i = 0; $i < $cnt; $i++){
|
||||
$tmp = explode(':', $start[$i]);
|
||||
$end[$tmp[0]] = explode(',', $tmp[1]);
|
||||
}
|
||||
$this->actionsUser = $end;
|
||||
}
|
||||
|
||||
function addAction($nb){
|
||||
$ret = array(floor($this->achatM * $nb * $this->taxeA), floor($this->achatC * $nb * $this->taxeA));
|
||||
|
||||
$this->achatM *= pow(1.1, $nb);
|
||||
$this->achatC *= pow(1.1, $nb);
|
||||
$this->venteM *= pow(1.1, $nb);
|
||||
$this->venteC *= pow(1.1, $nb);
|
||||
|
||||
for($i = 0; $i < $nb; $i++){
|
||||
$this->actionsUser[$this->id][] = time();
|
||||
}
|
||||
|
||||
return $ret;
|
||||
}
|
||||
|
||||
function delAction($nb){
|
||||
if ($this->action() < $nb) $nb = $this->action();
|
||||
|
||||
$ret = array(floor($this->venteM * $nb / $this->taxeV), floor($this->venteC * $nb / $this->taxeV));
|
||||
|
||||
$this->achatM /= pow(1.1, $nb);
|
||||
$this->achatC /= pow(1.1, $nb);
|
||||
$this->venteM /= pow(1.1, $nb);
|
||||
$this->venteC /= pow(1.1, $nb);
|
||||
|
||||
for($i = 0; $i < $nb; $i++){
|
||||
unset($this->actionsUser[$this->id][$i]);
|
||||
}
|
||||
|
||||
return $ret;
|
||||
}
|
||||
|
||||
function actionIn24Hours(){
|
||||
$nb = 0;
|
||||
$cnt = count($this->actionsUser[$this->id]);
|
||||
for($i = 0; $i < $cnt; $i++){
|
||||
if ($this->actionsUser[$this->id][$i] > time() - 86400) $nb++;
|
||||
}
|
||||
return $nb;
|
||||
}
|
||||
|
||||
function action(){
|
||||
return count($this->actionsUser[$this->id]);
|
||||
}
|
||||
|
||||
function maj(){
|
||||
$this->majBourse();
|
||||
$this->majUser();
|
||||
$this->fileSave();
|
||||
}
|
||||
|
||||
function majBourse(){
|
||||
global $table_bourse;
|
||||
|
||||
$this->bd->query("UPDATE $table_bourse SET nom = '".$this->nom."', achatM = '".$this->achatM."', achatC = '".$this->achatC."', venteM = '".$this->venteM."', venteC = '".$this->venteC."' WHERE id = ".$this->id.";");
|
||||
}
|
||||
|
||||
function majUser(){
|
||||
global $table_user;
|
||||
|
||||
$champ = '';
|
||||
foreach($this->actionsUser as $key => $cell) {
|
||||
if (empty($champ)) $champ .= $key.':'.implode(',', $cell);
|
||||
else $champ .= ';'.$key.':'.implode(',', $cell);
|
||||
}
|
||||
|
||||
$this->bd->query("UPDATE $table_user SET bourse = '$champ' WHERE id = ".$this->user.";");
|
||||
}
|
||||
|
||||
|
||||
function fileSave(){
|
||||
$fichier = fopen(_FCORE."hb_game/bourse/".$this->id.".".strftime('%Y%m%d').".bourse",'a+');
|
||||
fwrite($fichier, time().';'.$this->achatM.';'.$this->achatC.';'.$this->venteM.';'.$this->venteC);
|
||||
fclose($fichier);
|
||||
}
|
||||
|
||||
|
||||
function newGroupe($nom, $achatM, $achatC, $description = ""){
|
||||
global $table_bourse;
|
||||
|
||||
$venteM = floor($achatM * pow(1.1, 5));
|
||||
$venteC = floor($achatC * pow(1.1, 5));
|
||||
|
||||
$this->bd->query("INSERT INTO $table_bourse (nom, achatM, achatC, venteM, venteC, description) VALUES('$nom', '$achatM', '$achatC', '$venteM', '$venteC', '$description');");
|
||||
}
|
||||
|
||||
function editGroupe($description){
|
||||
//TODO toute cette fonction !!
|
||||
}
|
||||
}
|
||||
?>
|
||||
144
game/Class/class.alliance.php
Normal file
144
game/Class/class.alliance.php
Normal file
|
|
@ -0,0 +1,144 @@
|
|||
<?php
|
||||
/***************************************************************************
|
||||
* class.alliance.php
|
||||
* --------------------
|
||||
* begin : Vendredi 10 octobre 2008
|
||||
* update : Samedi 11 octobre 2008
|
||||
* email : nemunaire@gmail.com
|
||||
*
|
||||
*
|
||||
***************************************************************************/
|
||||
class Alliance extends File{
|
||||
var $id,
|
||||
$race,
|
||||
$fondateur,
|
||||
$sante,
|
||||
$nom,
|
||||
$tag,
|
||||
$galaxie,
|
||||
$ss,
|
||||
$nom_asteroide,
|
||||
$image_asteroide,
|
||||
$debris_met,
|
||||
$debris_cri,
|
||||
$credits,
|
||||
$metal,
|
||||
$cristal,
|
||||
$hydrogene,
|
||||
$file_abat,
|
||||
$file_vais,
|
||||
$alli_batiments = array(),
|
||||
$vaisseaux = array(),
|
||||
$modif = array();
|
||||
|
||||
/**
|
||||
* Constructeur
|
||||
* @param int $id id de l'alliance à importer
|
||||
*
|
||||
* @return void
|
||||
* @access public
|
||||
*/
|
||||
function Alliance($id = 0){
|
||||
if (!empty($id)) {
|
||||
global $var___db, $config, $table_alliances;
|
||||
global $alli_batimentVAR, $nomvaisnVAR;
|
||||
$bdd = new bdd();
|
||||
$bdd->connexion();
|
||||
$bdd->escape($id);
|
||||
$alli = $bdd->unique_query("SELECT * FROM $table_alliances WHERE id = $id;");
|
||||
$bdd->deconnexion();
|
||||
if (!empty($alli)) {
|
||||
$this->id = $alli["id"];
|
||||
$this->race = $alli["race"];
|
||||
$this->fondateur = $alli["fondateur"];
|
||||
$this->sante = $alli["sante"];
|
||||
$this->nom = $alli["nom"];
|
||||
$this->tag = $alli["tag"];
|
||||
$this->galaxie = $alli["galaxie"];
|
||||
$this->ss = $alli["ss"];
|
||||
$this->nom_asteroide = $alli["nom_asteroide"];
|
||||
$this->image_asteroide = $alli["image_asteroide"];
|
||||
$this->debris_met = $alli["debris_met"];
|
||||
$this->debris_cri = $alli["debris_cri"];
|
||||
$this->credits = $alli["credits"];
|
||||
$this->metal = $alli["metal"];
|
||||
$this->cristal = $alli["cristal"];
|
||||
$this->hydrogene = $alli["hydrogene"];
|
||||
|
||||
foreach($alli_batimentVAR as $bat){
|
||||
$this->alli_batiments[] = $alli[$bat];
|
||||
}
|
||||
$this->file_bat = unserialize($alli["file_bat"]);
|
||||
|
||||
foreach($nomvaisnVAR as $vais){
|
||||
$this->vaisseaux[] = $plan[$vais];
|
||||
}
|
||||
$this->file_vais = unserialize($alli["file_vais"]);
|
||||
|
||||
$this->actualiser();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Actualise les ressources de la planète en fonction de la production et termine les files d'attentes.
|
||||
*
|
||||
* @return void
|
||||
* @access public
|
||||
*/
|
||||
function actualiser($actuFile = true){
|
||||
//Actualisation des files d'attentes
|
||||
if ($actuFile) {
|
||||
$this->file_pret("alli_batiments");
|
||||
$this->file_pret("vaisseaux");
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Destructeur
|
||||
*
|
||||
* @return void
|
||||
* @access public
|
||||
*/
|
||||
function __destruct(){
|
||||
global $var___db, $config, $table_alliances;
|
||||
$nb = count($this->modif);
|
||||
$out = array();
|
||||
$bdd = new bdd();
|
||||
$bdd->connexion();
|
||||
for($i = 0; $i < $nb; $i++){
|
||||
if (!is_array($this->{$this->modif[$i]})) {
|
||||
$bdd->escape($this->{$this->modif[$i]});
|
||||
if (is_int($this->{$this->modif[$i]}) || is_float($this->{$this->modif[$i]})) $out[] .= $this->modif[$i]." = ".$this->{$this->modif[$i]};
|
||||
else $out[] .= $this->modif[$i]." = '".$this->{$this->modif[$i]}."'";
|
||||
}
|
||||
else {
|
||||
if (ereg('file', $this->modif[$i])) {
|
||||
$prep = serialize($this->{$this->modif[$i]});
|
||||
$bdd->escape($prep);
|
||||
$out[] .= $this->modif[$i]." = '$prep'";
|
||||
}
|
||||
else {
|
||||
if ($this->modif[$i] == "batiments") $calc = "batiment";
|
||||
elseif ($this->modif[$i] == "alli_batiments") $calc = "alli_batiment";
|
||||
elseif ($this->modif[$i] == "technologies") $calc = "technolo";
|
||||
elseif ($this->modif[$i] == "casernes")$calc = "casernen";
|
||||
elseif ($this->modif[$i] == "terrestres") $calc = "nomterrn";
|
||||
elseif ($this->modif[$i] == "vaisseaux") $calc = "nomvaisn";
|
||||
elseif ($this->modif[$i] == "coeff_bat") $calc = "coeff";
|
||||
|
||||
if (!isset(${$calc.'VAR'})) global ${$calc.'VAR'};
|
||||
|
||||
$nombr = count(${$calc.'VAR'});
|
||||
for($j = 0; $j < $nombr; $j++){
|
||||
$bdd->escape($this->{$this->modif[$i]}[$j]);
|
||||
$out[] .= ${$calc.'VAR'}[$j]." = ".$this->{$this->modif[$i]}[$j]."";
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
if (!empty($out)) $plan = $bdd->unique_query("UPDATE $table_alliances SET ".implode(', ', $out)." WHERE id = ".$this->id.";");
|
||||
$bdd->deconnexion();
|
||||
}
|
||||
}
|
||||
?>
|
||||
|
|
@ -44,10 +44,13 @@ class Bourse{
|
|||
global $table_bourse;
|
||||
$this->bd->escape($nom);
|
||||
$act = $this->bd->unique_query("SELECT * FROM $table_bourse WHERE $type = '$nom';");
|
||||
$this->id = $act['id'];
|
||||
$this->nom = $act['nom'];
|
||||
$this->metal = $act['metal'];
|
||||
$this->cristal = $act['cristal'];
|
||||
if ($act) {
|
||||
$this->id = $act['id'];
|
||||
$this->nom = $act['nom'];
|
||||
$this->metal = $act['metal'];
|
||||
$this->cristal = $act['cristal'];
|
||||
}
|
||||
else erreur('Impossible de trouver cette action !', "red", '?p=bourse');
|
||||
}
|
||||
|
||||
function loadUser($user, $type = "id"){
|
||||
|
|
|
|||
360
game/Class/class.file.php
Normal file
360
game/Class/class.file.php
Normal file
|
|
@ -0,0 +1,360 @@
|
|||
<?php
|
||||
/***************************************************************************
|
||||
* class.file.php
|
||||
* ----------------
|
||||
* begin : Samedi 11 octobre 2008
|
||||
* update : Samedi 11 octobre 2008
|
||||
* email : nemunaire@gmail.com
|
||||
*
|
||||
*
|
||||
***************************************************************************/
|
||||
class File{
|
||||
/**
|
||||
* Ajoute $nombre objets $objet dans la file $file
|
||||
* @param int $file Nom de la file d'attente
|
||||
* @param int $objet Id de l'objet à ajouter
|
||||
* @param int $nombre = 1 Nombre d'objet $objet à ajouter à la file
|
||||
*
|
||||
* @return int Numéro de l'erreur
|
||||
* @access public
|
||||
*/
|
||||
function file_addObjet($file, $objet, $nombre = 1){
|
||||
$planete = $this;
|
||||
switch($file){
|
||||
case "alli_batiments": $court = "abat"; $calc = "alli_batiment"; global ${$calc.'LIMIT'}; $exist = $this->file_exist($objet, "file_".$court); break;
|
||||
case "batiments": $court = "bat"; $calc = "batiment"; $exist = $this->file_exist($objet, "file_".$court); break;
|
||||
case "technologies": $court = "tech"; $calc = "technolo"; $exist = $this->file_exist($objet, "file_".$court); break;
|
||||
case "casernes": $court = "cas"; $calc = "casernen"; $exist = false; break;
|
||||
case "terrestres": $court = "ter"; $calc = "nomterrn"; $exist = false; break;
|
||||
case "vaisseaux": $court = "vais"; $calc = "nomvaisn"; $exist = false; break;
|
||||
default: return 1;
|
||||
}
|
||||
|
||||
//On vérifie la taille maximale de la file d'attente
|
||||
if (!empty($this->technologies['techno_inge'])) {
|
||||
if (($this->technologies['techno_inge'] & 131072) == 131072) $max = 5;
|
||||
elseif (($this->technologies['techno_inge'] & 65536) == 65536) $max = 4;
|
||||
elseif (($this->technologies['techno_inge'] & 32768) == 32768) $max = 3;
|
||||
else $max = 2;
|
||||
}
|
||||
else $max = 3;
|
||||
|
||||
if ($file == "technologies") {
|
||||
global ${$file.'CALC'};
|
||||
|
||||
$file_tech = $nombre;
|
||||
$nombre = 1;
|
||||
|
||||
if (empty($technologiesCALC[$file_tech][$objet])) return 1;
|
||||
|
||||
//Vérification des conditions de recherche
|
||||
if (!(($this->technologies[$file_tech] & $technologiesCALC[$file_tech][$objet][1]) == $technologiesCALC[$file_tech][$objet][1] && !($this->technologies[$file_tech] & $technologiesCALC[$file_tech][$objet][0] && $this->technologies[$file_tech] != 0))) return 1;
|
||||
}
|
||||
else {
|
||||
global ${$calc}, ${$calc.'CALC'}, ${$calc.'TECH'};
|
||||
|
||||
//Vérification des conditions de construction
|
||||
if (empty(${$calc}[$objet]) || !requestDeblok(${$calc.'TECH'}[$objet], $this)) return 1;
|
||||
|
||||
//Vérification que l'on ait pas dépassé le nombre maximal de niveau
|
||||
if (!empty(${$calc.'LIMIT'}[$objet]) && ${$file}[$objet] >= ${$calc.'LIMIT'}[$objet]) return 1;
|
||||
|
||||
//Calcul du prochain niveau de l'objet
|
||||
$n = $this->{$file}[$objet] + 1;
|
||||
}
|
||||
|
||||
//Vérification qu'il n'y ait pas déjà une instance de l'objet déjà en construction
|
||||
if ($exist) return 2;
|
||||
|
||||
//Vérification que le nombre ne soit pas négatif
|
||||
if ($nombre < 0) return 5;
|
||||
|
||||
//Actualisation du temps s'il n'y a pas d'objet en file
|
||||
if (count($this->{"file_".$court}) < 2) $this->{"file_".$court}[0] = time();
|
||||
|
||||
|
||||
if ($file == "alli_batiments" || $file == "batiments") {
|
||||
eval(${$calc.'CALC'}[$objet][0]);
|
||||
eval(${$calc.'CALC'}[$objet][1]);
|
||||
eval(${$calc.'CALC'}[$objet][2]);
|
||||
$d = 0;
|
||||
}
|
||||
elseif ($file == "technologies") {
|
||||
$a = $b = $c = 0;
|
||||
$d = $technologiesCALC[$file_tech][$objet][2];
|
||||
}
|
||||
else {
|
||||
$a = ${$calc.'CALC'}[$objet][0];
|
||||
$b = ${$calc.'CALC'}[$objet][1];
|
||||
$c = ${$calc.'CALC'}[$objet][2];
|
||||
$d = 0;
|
||||
}
|
||||
|
||||
//On applique les bonus politiques aux temps et coûts
|
||||
if (isset($this->politique) && $this->politique == 1 && ($file == "casernes" || $file == "terrestres" || $file == "vaisseaux")) {
|
||||
$a *= 0.9;
|
||||
$b *= 0.9;
|
||||
$c *= 0.9;
|
||||
}
|
||||
|
||||
//Vérification du nombre maximum d'entraînement possible de cette unité sur cette planète
|
||||
if ($nombre > 1) {
|
||||
if ($a) $nombre = min(floor($this->metal/$a), $nombre);
|
||||
if ($b) $nombre = min(floor($this->cristal/$b), $nombre);
|
||||
if ($c) $nombre = min(floor($this->hydrogene/$c), $nombre);
|
||||
if ($d) $nombre = min(floor($this->credits/$d), $nombre);
|
||||
}
|
||||
|
||||
//Vérification des ressources de la planète
|
||||
if ($this->metal < $a * $nombre) return 3;
|
||||
elseif ($this->cristal < $b * $nombre) return 3;
|
||||
elseif ($this->hydrogene < $c * $nombre) return 3;
|
||||
elseif ($this->credits < $d * $nombre) return 3;
|
||||
else {
|
||||
//Génération de la file d'attente
|
||||
$nb = count($this->{"file_".$court});
|
||||
|
||||
//Si le dernier objet est identique à celui que l'on veut construire
|
||||
if ($file == "technologies" && $max <= count($this->{"file_".$court})) return 4; //Vérification de la taille de la file d'attente
|
||||
elseif ($file == "technologies") $this->{"file_".$court}[] = array($objet, $file_tech);
|
||||
elseif ($nb > 1 && $objet == $this->{"file_".$court}[$nb-1][0]) {
|
||||
$this->{"file_".$court}[$nb-1][1] += $nombre;
|
||||
}
|
||||
elseif ($max <= count($this->{"file_".$court})) return 4; //Vérification de la taille de la file d'attente
|
||||
else $this->{"file_".$court}[] = array($objet, $nombre);
|
||||
|
||||
//Mise à jour des ressources de la planète en conséquence à la construction
|
||||
$this->metal -= $a * $nombre;
|
||||
$this->cristal -= $b * $nombre;
|
||||
$this->hydrogene -= $c * $nombre;
|
||||
$this->credits -= $d * $nombre;
|
||||
|
||||
if (!in_array("file_".$court, $this->modif)) $this->modif[] = "file_".$court;
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
function file_delObjet($file, $objet, $nombre = 1, $w = 99) {
|
||||
$planete = $this;
|
||||
switch($file){
|
||||
case "alli_batiments": $court = "abat"; $calc = "alli_batiment"; $exist = $this->file_exist($objet, "file_".$court); break;
|
||||
case "batiments": $court = "bat"; $calc = "batiment"; $exist = $this->file_exist($objet, "file_".$court); break;
|
||||
case "technologies": $court = "tech"; $calc = "technolo"; $exist = true; break;
|
||||
case "casernes": $court = "cas"; $calc = "casernen"; $exist = $this->file_exist($objet, "file_".$court); break;
|
||||
case "terrestres": $court = "ter"; $calc = "nomterrn"; $exist = $this->file_exist($objet, "file_".$court); break;
|
||||
case "vaisseaux": $court = "vais"; $calc = "nomvaisn"; $exist = $this->file_exist($objet, "file_".$court); break;
|
||||
default: return false;
|
||||
}
|
||||
|
||||
//Si l'objet n'est pas dans la file d'attente, on annule la suite
|
||||
if (!$exist) return 0;
|
||||
|
||||
if ($w == 99) $w = count($this->{"file_".$court})-1;
|
||||
|
||||
//On gère les files de type arbre
|
||||
if ($file == "technologies") {
|
||||
if (isset($this->{"file_".$court}[$objet])) {
|
||||
global ${$file.'CALC'};
|
||||
//On réinitialise le temps si c'est la première
|
||||
if ($objet == 1) $this->{"file_".$court}[0] = time();
|
||||
|
||||
$i = $objet;
|
||||
$filearbre = $this->{"file_".$court}[$objet+1][1];
|
||||
$objet = $this->{"file_".$court}[$objet+1][0];
|
||||
|
||||
if (!$this->file_exist($objet, $filearbre)) return 0;
|
||||
|
||||
unset($this->{"file_".$court}[$i+1]);
|
||||
$this->{"file_".$court} = array_merge($this->{"file_".$court});
|
||||
}
|
||||
}
|
||||
else {
|
||||
global ${$calc}, ${$calc.'CALC'};
|
||||
|
||||
for($i = $w; $i > 0; $i--) {
|
||||
if($this->{"file_".$court}[$i][0] == $objet){
|
||||
$nombre = min(abs($nombre), $this->{"file_".$court}[$i][1]);
|
||||
|
||||
if($this->{"file_".$court}[$i][1] <= $nombre) {
|
||||
unset($this->{"file_".$court}[$i]);
|
||||
$this->{"file_".$court} = array_merge($this->{"file_".$court});
|
||||
}
|
||||
else $this->{"file_".$court}[$i][1] -= $nombre;
|
||||
|
||||
if ($i == 1) $this->{"file_".$court}[0] = time();
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
//Calcul du prochain niveau de l'objet
|
||||
$n = $this->{$file}[$objet] + 1;
|
||||
}
|
||||
|
||||
if (!in_array("file_".$court, $this->modif)) $this->modif[] = "file_".$court;
|
||||
|
||||
if ($file == "batiments") {
|
||||
eval(${$calc.'CALC'}[$objet][0]);
|
||||
eval(${$calc.'CALC'}[$objet][1]);
|
||||
eval(${$calc.'CALC'}[$objet][2]);
|
||||
$d = 0;
|
||||
}
|
||||
elseif ($file == "technologies") {
|
||||
$a = $b = $c = 0;
|
||||
$d = $technologiesCALC[$filearbre][$objet][2];
|
||||
}
|
||||
else {
|
||||
$a = ${$calc.'CALC'}[$objet][0];
|
||||
$b = ${$calc.'CALC'}[$objet][1];
|
||||
$c = ${$calc.'CALC'}[$objet][2];
|
||||
$d = 0;
|
||||
}
|
||||
|
||||
//On applique les bonus politiques aux temps et coûts
|
||||
if (isset($this->politique) && $this->politique == 1 && ($file == "casernes" || $file == "terrestres" || $file == "vaisseaux")) {
|
||||
$a *= 0.9;
|
||||
$b *= 0.9;
|
||||
$c *= 0.9;
|
||||
}
|
||||
|
||||
//Mise à jour des ressources de la planète en conséquence à la construction
|
||||
$this->metal += $a * $nombre;
|
||||
$this->cristal += $b * $nombre;
|
||||
$this->hydrogene += $c * $nombre;
|
||||
$this->credits += $d * $nombre;
|
||||
|
||||
return $nombre;
|
||||
}
|
||||
|
||||
/**
|
||||
* Vérifie l'existance dans la file $file d'attente de $objet
|
||||
* @param int $objet ID à vérifier
|
||||
* @param string $file Nom de la file d'attente
|
||||
*
|
||||
* @return boolean
|
||||
* @access public
|
||||
*/
|
||||
function file_exist($objet, $file){
|
||||
//On traite le cas d'une file type arbre
|
||||
if (is_numeric($file)) {
|
||||
foreach($this->file_tech as $key => $bout){
|
||||
if ($key == 0) continue;
|
||||
if($objet == $bout[0] && $file == $bout[1]) return true;
|
||||
}
|
||||
}
|
||||
else {
|
||||
if (count($this->$file) <= 1) return false;
|
||||
foreach($this->$file as $key => $bout){
|
||||
if ($key == 0) continue;
|
||||
if($objet == $bout[0]) return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Actualise la file $file en terminant les constructions/entraînements.
|
||||
* @param string $file Nom de la file d'attente
|
||||
*
|
||||
* @return boolean
|
||||
* @access public
|
||||
*/
|
||||
function file_pret($file){
|
||||
$nanite = 0;
|
||||
$planete = $this;
|
||||
switch($file){
|
||||
case "alli_batiments": $court = "abat"; $calc = "alli_batiment"; $exist = $this->file_exist($objet, "file_".$court); break;
|
||||
case "batiments": $court = "bat"; $calc = "batiment"; break;
|
||||
case "technologies": $court = "tech"; $calc = "technolo"; break;
|
||||
case "casernes": $court = "cas"; $calc = "casernen"; break;
|
||||
case "terrestres": $court = "ter"; $calc = "nomterrn"; break;
|
||||
case "vaisseaux": $court = "vais"; $calc = "nomvaisn"; break;
|
||||
default: return false;
|
||||
}
|
||||
|
||||
if (empty($this->{"file_".$court}[0])) return false;
|
||||
|
||||
//Calcul du temps écoulé depuis le dernier entrainement validé
|
||||
$tps = time() - $this->{"file_".$court}[0];
|
||||
|
||||
if ($file == "technologies") {
|
||||
global ${$file.'CALC'};
|
||||
|
||||
foreach($this->{"file_".$court} as $key => $bout) {
|
||||
if ($key == 0) continue;
|
||||
|
||||
//Récupération du temps de recherche
|
||||
$sec = $technologiesCALC[$bout[1]][$bout[0]][3] / (1 + $planete->batiments[6] * 0.005);
|
||||
|
||||
//On applique les bonus politiques aux temps et coûts
|
||||
if (isset($this->politique) && $this->politique == 1 && ($file == "casernes" || $file == "terrestres" || $file == "vaisseaux")) {
|
||||
$sec *= 0.9;
|
||||
}
|
||||
|
||||
//Accélération du temps de construction
|
||||
$sec /= VITESSE;
|
||||
|
||||
if ($sec < $tps) {
|
||||
$this->{$file}[$bout[1]] += $technologiesCALC[$bout[1]][$bout[0]][0];
|
||||
$this->{"file_".$court}[0] += $sec;
|
||||
unset($this->{"file_".$court}[$key]); //CAUSE DE PROBLEME POSSIBLE !
|
||||
$this->{"file_".$court} = array_merge($this->{"file_".$court});
|
||||
|
||||
if (!in_array($file, $this->modifUser)) $this->modifUser[] = $file;
|
||||
if (!in_array("file_".$court, $this->modif)) $this->modif[] = "file_".$court;
|
||||
}
|
||||
else break;
|
||||
}
|
||||
if (in_array("file_".$court, $this->modif)) $this->actualiser(false);
|
||||
}
|
||||
else {
|
||||
global ${$calc}, ${$calc.'CALC'};
|
||||
|
||||
foreach($this->{"file_".$court} as $key => $bout) {
|
||||
if ($key == 0) continue;
|
||||
|
||||
$n = $this->{$file}[$bout[0]] + 1; //Extraction du niveau en cours
|
||||
eval(${$calc.'CALC'}[$bout[0]][3]); //Récupération du temps de construction
|
||||
|
||||
//var_dump($bout[0], $n);
|
||||
|
||||
//Accélération du temps de construction
|
||||
$sec = floor($sec/VITESSE);
|
||||
|
||||
if ($sec * $bout[1] < $tps) {
|
||||
//S'il s'agit d'un silo, on sauvegarde le temps pour utilisation par le script de production
|
||||
if ($file == "batiments" && $bout[0] == 10) $timestamp_lastSilo = $this->{"file_".$court}[0];
|
||||
if ($file == "batiments" && $bout[0] == 0) $timestamp_mineM = $this->{"file_".$court}[0];
|
||||
if ($file == "batiments" && $bout[0] == 1) $timestamp_mineC = $this->{"file_".$court}[0];
|
||||
if ($file == "batiments" && $bout[0] == 2) $timestamp_mineH = $this->{"file_".$court}[0];
|
||||
$this->{$file}[$bout[0]] += $bout[1];
|
||||
$this->{"file_".$court}[0] += $bout[1] * $sec;
|
||||
$tps -= $bout[1] * $sec;
|
||||
unset($this->{"file_".$court}[$key]);
|
||||
|
||||
if (!in_array($file, $this->modif)) $this->modif[] = $file;
|
||||
if (!in_array("file_".$court, $this->modif)) $this->modif[] = "file_".$court;
|
||||
}
|
||||
elseif ($sec < time() - $this->{"file_".$court}[0]) {
|
||||
//TODO Trouver plus simple que la ligne en dessous
|
||||
for($j=0 ; $j * $sec < $tps ; $j++) {}
|
||||
$j--;
|
||||
$this->{"file_".$court}[$key][1] -= $j;
|
||||
$this->{$file}[$bout[0]] += $j;
|
||||
$this->{"file_".$court}[0] += $j * $sec;
|
||||
$tps -= $j * $sec;
|
||||
|
||||
if (!in_array($file, $this->modif)) $this->modif[] = $file;
|
||||
if (!in_array("file_".$court, $this->modif)) $this->modif[] = "file_".$court;
|
||||
|
||||
//Comme la première attente n'est pas terminée, on stoppe la vérification
|
||||
break;
|
||||
}
|
||||
else break;
|
||||
}
|
||||
//On actualise seulement s'il y a eu une modification de faite
|
||||
if (in_array($file, $this->modif)) $this->actualiser(false);
|
||||
$this->{"file_".$court} = array_merge($this->{"file_".$court});
|
||||
}
|
||||
}
|
||||
}
|
||||
?>
|
||||
281
game/Class/class.flotte.php
Normal file
281
game/Class/class.flotte.php
Normal file
|
|
@ -0,0 +1,281 @@
|
|||
<?php
|
||||
/***************************************************************************
|
||||
* class.flotte.php
|
||||
* ------------------
|
||||
* begin : Samedi 20 septembre 2008
|
||||
* update : Samedi 20 septembre 2008
|
||||
* email : nemunaire@gmail.com
|
||||
*
|
||||
*
|
||||
***************************************************************************/
|
||||
class Flotte{
|
||||
var $id_flotte,
|
||||
$nom,
|
||||
$start_planete,
|
||||
$start_time,
|
||||
$end_planete,
|
||||
$end_time,
|
||||
$ret_planete,
|
||||
$ret_time,
|
||||
$vaisseaux = array(),
|
||||
$tactique = 0,
|
||||
$mission,
|
||||
$vitesse,
|
||||
$statut = 0,
|
||||
$last,
|
||||
$contenu = array(0,0,0),
|
||||
$contenuMax = 0,
|
||||
$modifFlotte = array();
|
||||
|
||||
/**
|
||||
* Constructeur
|
||||
* @param int $id id de la flotte à importer
|
||||
*
|
||||
* @return void
|
||||
* @access public
|
||||
*/
|
||||
function Flotte($id = 0){
|
||||
if (!empty($id)) {
|
||||
global $var___db, $config, $table_flottes;
|
||||
global $nomvaisnVAR, $ressoVAR;
|
||||
$bdd = new bdd();
|
||||
$bdd->connexion();
|
||||
$bdd->escape($id);
|
||||
$flotte = $bdd->unique_query("SELECT * FROM $table_flottes WHERE id = $id;");
|
||||
$bdd->query("UPDATE $table_flottes SET last = ".time()." WHERE id = $id;"); //Obtention d'un vérrou de 10 seconde sur la flotte
|
||||
$bdd->deconnexion();
|
||||
if (!empty($flotte)) {
|
||||
$this->id_flotte = $flotte["id"];
|
||||
$this->nom = $flotte["nom"];
|
||||
$this->start_planete = $flotte["start_planete"];
|
||||
$this->start_time = $flotte["start_time"];
|
||||
$this->end_planete = $flotte["end_planete"];
|
||||
$this->end_time = $flotte["end_time"];
|
||||
$this->ret_planete = $flotte["ret_planete"];
|
||||
$this->ret_time = $flotte["ret_time"];
|
||||
$this->tactique = $flotte["tactique"];
|
||||
$this->mission = $flotte["mission"];
|
||||
$this->statut = $flotte["statut"];
|
||||
$this->last = $flotte["last"];
|
||||
|
||||
foreach($nomvaisnVAR as $vais){
|
||||
$this->vaisseaux[] = $flotte[$vais];
|
||||
}
|
||||
|
||||
foreach($ressoVAR as $contenu){
|
||||
$this->contenu[] = $flotte[$contenu];
|
||||
}
|
||||
|
||||
$this->calculer();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
function calculer(){
|
||||
global $nomvais_rs;
|
||||
|
||||
//Calcul de la capacité maximale d'embarquement de la flotte
|
||||
foreach($this->vaisseaux as $key => $vais){
|
||||
$this->contenuMax += $nomvais_rs[$key] * $vais;
|
||||
}
|
||||
}
|
||||
|
||||
function load_planete(){
|
||||
if (is_numeric($this->start_planete) && !empty($this->start_planete)) {
|
||||
$this->start_planete = new Planete($this->start_planete);
|
||||
}
|
||||
if (is_numeric($this->end_planete) && !empty($this->end_planete)) {
|
||||
$this->end_planete = new Planete($this->end_planete);
|
||||
}
|
||||
if (is_numeric($this->ret_planete) && !empty($this->ret_planete)) {
|
||||
$this->ret_planete = new Planete($this->ret_planete);
|
||||
}
|
||||
}
|
||||
|
||||
function calc_deplacement($start_galaxie, $start_systeme, $start_position, $end_galaxie, $end_systeme, $end_position, $vitesse, $returnArray = false, $returnConso = false){
|
||||
//Si la planète de départ n'est pas chargée, on charge les planètes
|
||||
if (is_numeric($this->start_planete)) $this->load_planete();
|
||||
global $config, $nomvais_vitesseP, $nomvais_vitesseS, $nomvais_vitesseG, $nomvais_rs;
|
||||
$this->vitesse = $vitesse;
|
||||
|
||||
//Calcul de la longueur du déplacement
|
||||
$diff_galaxie = abs($start_galaxie - $end_galaxie);
|
||||
$diff_systeme = abs($start_systeme - $end_systeme);
|
||||
$diff_position = abs($start_position - $end_position);
|
||||
|
||||
$diff_centre_position_start = abs(ceil($config['nb_amas']/2) - $start_position);
|
||||
$diff_centre_systeme_start = abs(ceil($config['nb_systeme']/2) - $start_systeme);
|
||||
|
||||
$diff_centre_position_end = abs(ceil($config['nb_amas']/2) - $end_position);
|
||||
$diff_centre_systeme_end = abs(ceil($config['nb_systeme']/2) - $end_systeme);
|
||||
|
||||
//Calcul du temps de déplacement pour chaque vaisseau
|
||||
$temps = array(); $conso = array(0, 0, 0);
|
||||
foreach($this->vaisseaux as $key => $vais){
|
||||
//S'il n'y a pas de vaisseaux de ce type, on ne calcul pas leur vitesse
|
||||
if ($vais == 0) continue;
|
||||
|
||||
//Calcul du temps de déplacement entre planètes
|
||||
if ($start_systeme == $end_systeme && $start_galaxie == $end_galaxie) {
|
||||
$temps[0][$key] = (10/$nomvais_vitesseP[$key]) * (1 + 0.1 * $diff_position);
|
||||
$temps[1][$key] = $temps[2][$key] = 0;
|
||||
}
|
||||
//Calcul du temps de déplacement entre système
|
||||
elseif ($start_galaxie == $end_galaxie) {
|
||||
$temps[0][$key] = (10/$nomvais_vitesseP[$key]) * (1 + 0.1 * ($diff_centre_position_start + $diff_centre_position_end));
|
||||
$temps[1][$key] = (20/$nomvais_vitesseS[$key]) * (2 + 1 * $diff_systeme);
|
||||
$temps[2][$key] = 0;
|
||||
}
|
||||
//Calcul du temps de déplacement entre galaxies
|
||||
else {
|
||||
$temps[0][$key] = (10/$nomvais_vitesseP[$key]) * (1 + 0.1 * ($diff_centre_position_start + $diff_centre_position_end));
|
||||
$temps[1][$key] = (20/$nomvais_vitesseS[$key]) * (2 + 1 * ($diff_centre_systeme_start + $diff_centre_systeme_end));
|
||||
$temps[2][$key] = (50/$nomvais_vitesseG[$key]) * (2 + 1.5 * $diff_galaxie);
|
||||
}
|
||||
|
||||
//Calcul du bonus pour le réacteur à combustion
|
||||
$techR = $this->start_planete->technologies[1];
|
||||
if ($techR & 56) $bonus = 0.7;
|
||||
elseif ($techR & 24) $bonus = 0.8;
|
||||
elseif ($techR & 8) $bonus = 0.9;
|
||||
else $bonus = 1;
|
||||
$temps[0][$key] *= $bonus * 1/$vitesse;
|
||||
$conso[0] += $vais * $temps[0][$key] * $bonus / exp($vitesse/5);
|
||||
|
||||
//Calcul du bonus pour le réacteur à fusion
|
||||
$techR = $this->start_planete->technologies[1];
|
||||
if ($techR & 448) $bonus = 0.7;
|
||||
elseif ($techR & 192) $bonus = 0.8;
|
||||
elseif ($techR & 64) $bonus = 0.9;
|
||||
else $bonus = 1;
|
||||
$temps[1][$key] *= $bonus * 1/$vitesse;
|
||||
$conso[1] += $vais * $temps[1][$key] * $bonus / exp($vitesse/7.5);
|
||||
|
||||
//Calcul du bonus pour le réacteur à fusion de type II
|
||||
$techR = $this->start_planete->technologies[1];
|
||||
if ($techR & 3584) $bonus = 0.7;
|
||||
elseif ($techR & 1536) $bonus = 0.8;
|
||||
elseif ($techR & 512) $bonus = 0.9;
|
||||
else $bonus = 1;
|
||||
$temps[2][$key] *= $bonus * 1/$vitesse;
|
||||
$conso[2] += $vais * $temps[2][$key] * $bonus / exp($vitesse/10);
|
||||
}
|
||||
|
||||
//Si les chasseurs peuvent rentrer dans les cales des vaisseaux, on les enlèves
|
||||
if ($this->contenuMax - ($this->contenu[0] + $this->contenu[1] + $this->contenu[2]) - ($this->vaisseaux[4] * $nomvais_rs[4] + $this->vaisseaux[5] * $nomvais_rs[5]) >= ($this->vaisseaux[4] + $this->vaisseaux[5]) * 200) {
|
||||
$temps[2][4] = $temps[2][5] = $temps[1][4] = $temps[1][5] = $temps[0][4] = $temps[0][5] = 0;
|
||||
}
|
||||
|
||||
//On calcul le temps de déplacement maximal
|
||||
if ($returnArray) return $temps;
|
||||
elseif ($returnConso) return array(max($temps[0]) + max($temps[1]) + max($temps[2]), ceil($conso[0]+$conso[1]+$conso[2]));
|
||||
else return (max($temps[0]) + max($temps[1]) + max($temps[2]));
|
||||
}
|
||||
|
||||
function check_mission(){
|
||||
//On vérifie qu'un calcul ne soit pas déjà en cours
|
||||
if ($this->last >= time() - 10) return false;
|
||||
elseif ($this->start_time + $this->end_time < time()) return false;
|
||||
elseif ($this->statut == 1 && ($this->ret_time > time() || $this->start_time + $this->end_time * 2 >= time())) return $this->retourner();
|
||||
|
||||
switch($this->mission){
|
||||
case 0:
|
||||
case 5:
|
||||
return $this->stationner();
|
||||
break;
|
||||
case 1:
|
||||
return $this->transporter();
|
||||
break;
|
||||
case 2:
|
||||
return $this->coloniser();
|
||||
break;
|
||||
case 3:
|
||||
return $this->espionner();
|
||||
break;
|
||||
case 4:
|
||||
return $this->attaquer();
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
function rappeler(){
|
||||
if ($this->start_time + $this->end_time >= time()) return false;
|
||||
else {
|
||||
$this->end_time = time() - $this->start_time + 10;
|
||||
$this->mission = 5;
|
||||
if (!in_array('mission', $this->modifFlotte)) $this->modifFlotte[] = 'mission';
|
||||
if (!in_array('end_time', $this->modifFlotte)) $this->modifFlotte[] = 'end_time';
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
function retourner(){
|
||||
//Si la planète de départ n'est pas chargée, on charge les planètes
|
||||
if (is_numeric($this->start_planete)) $this->load_planete();
|
||||
|
||||
//Si on a demandé une planète particulière au retour
|
||||
if (!empty($this->ret_time) && !empty($this->ret_planete) && !is_numeric($this->ret_planete)) {
|
||||
foreach($this->vaisseaux as $key => $vais){
|
||||
$this->ret_planete->vaisseaux[$key] += $vais;
|
||||
}
|
||||
}
|
||||
//Si le retour se fait sur la planète source
|
||||
else {
|
||||
foreach($this->vaisseaux as $key => $vais){
|
||||
$this->start_planete->vaisseaux[$key] += $vais;
|
||||
}
|
||||
}
|
||||
$this->modifFlotte = "DELETE";
|
||||
}
|
||||
|
||||
/**
|
||||
* Destructeur
|
||||
*
|
||||
* @return void
|
||||
* @access public
|
||||
*/
|
||||
function __destruct(){
|
||||
global $var___db, $config, $table_flottes;
|
||||
$nb = count($this->modifFlotte);
|
||||
$out = array();
|
||||
$bdd = new bdd();
|
||||
$bdd->connexion();
|
||||
if ($this->modifFlotte === "DELETE") $bdd->query("DELETE FROM $table_flottes WHERE id = ".$this->id_flotte.";");
|
||||
else {
|
||||
for($i = 0; $i < $nb; $i++){
|
||||
if (!is_array($this->{$this->modifFlotte[$i]})) {
|
||||
$bdd->escape($this->{$this->modifFlotte[$i]});
|
||||
if (is_int($this->{$this->modifFlotte[$i]}) || is_float($this->{$this->modifFlotte[$i]})) $out[] .= $this->modifFlotte[$i]." = ".$this->{$this->modifFlotte[$i]};
|
||||
else $out[] .= $this->modifFlotte[$i]." = '".$this->{$this->modifFlotte[$i]}."'";
|
||||
}
|
||||
else {
|
||||
if ($this->modifFlotte[$i] == "contenu") $calc = "resso";
|
||||
elseif ($this->modifFlotte[$i] == "vaisseaux") $calc = "nomvaisn";
|
||||
|
||||
if (!isset(${$calc.'VAR'})) global ${$calc.'VAR'};
|
||||
|
||||
$nombr = count(${$calc.'VAR'});
|
||||
for($j = 0; $j < $nombr; $j++){
|
||||
$bdd->escape($this->{$this->modifFlotte[$i]}[$j]);
|
||||
$out[] = ${$calc.'VAR'}[$j]." = ".$this->{$this->modifFlotte[$i]}[$j];
|
||||
}
|
||||
}
|
||||
}
|
||||
if (empty($id_flotte)) {
|
||||
$out1 = ''; $out2 = '';
|
||||
global $nomvaisnVAR;
|
||||
foreach ($this->vaisseaux as $key => $vais){
|
||||
$out1 .= ', '.${$calc.'VAR'}[$key];
|
||||
$out2 .= ', '.$vais;
|
||||
}
|
||||
$sql = "INSERT INTO $table_flottes (id_user, mission, start_time, start_planete, end_time, end_planete, vitesse, contenu_metal, contenu_cristal, contenu_hydrogene, tactique, nom$out1) VALUES ('".$start_planete->id_user."', '".$this->mission."', '".$this->start_time."', '".$start_planete->id."', '".$this->end_time."', '".$this->end_planete."', '".$this->vitesse."', '".$this->contenu[0]."', '".$this->contenu[1]."', '".$this->contenu[2]."', '".$this->tactique."', '".$this->nom."'$out2);";
|
||||
var_dump($sql);
|
||||
//$bdd->query($sql);
|
||||
}
|
||||
elseif (!empty($out)) $bdd->query("UPDATE $table_flottes SET ".implode(', ', $out).", last = 0 WHERE id = ".$this->id_flotte.";");
|
||||
else $bdd->query("UPDATE $table_flottes SET last = 0 WHERE id = ".$this->id_flotte.";");
|
||||
}
|
||||
$bdd->deconnexion();
|
||||
}
|
||||
}
|
||||
?>
|
||||
|
|
@ -1,110 +0,0 @@
|
|||
<?php
|
||||
class gererFile {
|
||||
var $file = array();
|
||||
var $chaine = false;
|
||||
var $timestamp = 0;
|
||||
var $type = '';
|
||||
var $limite = 0;
|
||||
|
||||
function gererFile($limite, $file, $type) {
|
||||
$this->limite = $limite;
|
||||
$this->type = $type;
|
||||
|
||||
if (!empty($file)) {
|
||||
$file = explode(';', $file);
|
||||
$timestamp = $file[0];
|
||||
unset($file[0]);
|
||||
$file = array_merge($file);
|
||||
$cnt = count($file);
|
||||
for($i = 0; $i < $cnt; $i++){
|
||||
$file[$i] = explode(',', $file[$i]);
|
||||
}
|
||||
$this->file = $file;
|
||||
}
|
||||
else $this->timestamp = time();
|
||||
}
|
||||
|
||||
function addObjet($objet,$nombre,$temps) {
|
||||
$this->file = array_merge($this->file);
|
||||
$nbF = count($this->file);
|
||||
if ($nbF >= $this->limite) return false;
|
||||
$this->chaine = false;
|
||||
if($nbF == 0) $this->timestamp = time();
|
||||
if($nbF > 0 && $this->file[$nbF-1][0] == $objet) $this->file[$nbF-1][1] += $nombre;
|
||||
else $this->file[] = array($objet, $nombre, $temps);
|
||||
return true;
|
||||
}
|
||||
|
||||
function existe($objet) {
|
||||
$this->file = array_merge($this->file);
|
||||
$nbF=count($this->file);
|
||||
for ($i=0 ; $i<$nbF ; $i++){
|
||||
if($objet == $this->file[$i][0]) return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
function delobjet($objet, $nombre=1) {
|
||||
$this->file = array_merge($this->file);
|
||||
for($i = count($this->file)-1; $i >= 0; $i--) {
|
||||
if($this->file[$i][0] == $objet){
|
||||
$nombre = min($nombre, $this->file[$i][1]);
|
||||
$this->file[$i][1] -= $nombre;
|
||||
if($this->file[$i][1] <= 0) {
|
||||
unset($this->file[$i]);
|
||||
$this->file = array_merge($this->file);
|
||||
}
|
||||
break;
|
||||
}
|
||||
if ($i == 1) $this->timestamp = time();
|
||||
}
|
||||
return $nombre;
|
||||
}
|
||||
|
||||
function pret() {
|
||||
$this->file = array_merge($this->file);
|
||||
$out = array();
|
||||
$nbF = count($this->file);
|
||||
if ($nbF == 1 && $this->chaine) {
|
||||
$nb = floor((time()-$this->timestamp)/$this->file[0][2]);
|
||||
if ($nb > 0) {
|
||||
$out[] = array($this->file[0][0], $nb);
|
||||
$this->timestamp += $nb * $this->file[0][2];
|
||||
}
|
||||
}
|
||||
elseif ($nbF != 0) {
|
||||
$this->file = array_merge($this->file);
|
||||
for($i=0 ; $i<$nbF ; $i++){
|
||||
$tps = time() - $this->timestamp;
|
||||
if($this->file[$i][1] * $this->file[$i][2] < $tps) {
|
||||
$out[] = array($this->file[$i][0], $this->file[$i][1]);
|
||||
$this->timestamp += $this->file[$i][1] * $this->file[$i][2];
|
||||
unset($this->file[$i]);
|
||||
}
|
||||
elseif ($this->file[$i][2] < $tps) {
|
||||
for($j=0 ; $j*$this->file[$i][2]<$tps ; $j++) {}
|
||||
$j--;
|
||||
$out[] = array($this->file[$i][0], $j);
|
||||
$this->timestamp += $j * $this->file[$i][2];
|
||||
$this->file[$i][1] -= $j;
|
||||
break;
|
||||
}
|
||||
else {
|
||||
return $out;
|
||||
}
|
||||
}
|
||||
$this->file = array_merge($this->file);
|
||||
}
|
||||
return $out;
|
||||
}
|
||||
|
||||
function export(){
|
||||
$nbF = count($this->file);
|
||||
$out = '';
|
||||
for($i=0;$i<$nbF;$i++){
|
||||
$out .= implode(',',$this->file[$i]).';';
|
||||
}
|
||||
return $out;
|
||||
}
|
||||
}
|
||||
?>
|
||||
|
|
@ -23,8 +23,13 @@ class Planete extends User{
|
|||
$metal,
|
||||
$cristal,
|
||||
$hydrogene,
|
||||
$population,
|
||||
$alert_ressources = array(false, false, false),
|
||||
$timestamp,
|
||||
$timestamp_lastSilo,
|
||||
$timestamp_lastMineM,
|
||||
$timestamp_lastMineC,
|
||||
$timestamp_lastMineH,
|
||||
$energie,
|
||||
$energieConso,
|
||||
$file_tech,
|
||||
|
|
@ -61,7 +66,8 @@ class Planete extends User{
|
|||
$this->galaxie = $plan["galaxie"];
|
||||
$this->ss = $plan["ss"];
|
||||
$this->position = $plan["position"];
|
||||
$this->isolement = $plan["isolement"];
|
||||
if (!empty($plan["isolement"])) $this->isolement = unserialize($plan["isolement"]);
|
||||
else $this->isolement = array();
|
||||
$this->nom_planete = $plan["nom_planete"];
|
||||
$this->image = $plan["image"];
|
||||
$this->cases = $plan["cases"];
|
||||
|
|
@ -70,31 +76,38 @@ class Planete extends User{
|
|||
$this->metal = $plan["metal"];
|
||||
$this->cristal = $plan["cristal"];
|
||||
$this->hydrogene = $plan["hydrogene"];
|
||||
$this->population = $plan["population"];
|
||||
$this->timestamp = $plan["timestamp"];
|
||||
|
||||
foreach($batimentVAR as $bat){
|
||||
$this->batiments[] = $plan[$bat];
|
||||
}
|
||||
$this->file_bat = explode(';', $plan["file_bat"]);
|
||||
if (!empty($plan["file_bat"])) $this->file_bat = unserialize($plan["file_bat"]);
|
||||
else $this->file_bat = array();
|
||||
|
||||
$this->coeff_bat = array($plan["coeff_mine_m"], $plan["coeff_mine_c"], $plan["coeff_mine_h"], $plan["coeff_centrale_s"], $plan["coeff_centrale_f"]);
|
||||
for($i = 0; $i < 5; $i++){
|
||||
if ($this->coeff_bat[$i] > 1) $this->coeff_bat[$i] = 1;
|
||||
elseif ($this->coeff_bat[$i] < 0) $this->coeff_bat[$i] = 0;
|
||||
}
|
||||
|
||||
$this->file_tech = explode(';', $plan["file_tech"]);
|
||||
if (!empty($plan["file_tech"])) $this->file_tech = unserialize($plan["file_tech"]);
|
||||
else $this->file_tech = array();
|
||||
foreach($casernenVAR as $cas){
|
||||
$this->casernes[] = $plan[$cas];
|
||||
}
|
||||
$this->file_cas = explode(';', $plan["file_cas"]);
|
||||
if (!empty($plan["file_cas"])) $this->file_cas = unserialize($plan["file_cas"]);
|
||||
else $this->file_cas = array();
|
||||
foreach($nomterrnVAR as $ter){
|
||||
$this->terrestres[] = $plan[$ter];
|
||||
}
|
||||
$this->file_ter = explode(';', $plan["file_ter"]);
|
||||
if (!empty($plan["file_ter"])) $this->file_ter = unserialize($plan["file_ter"]);
|
||||
else $this->file_ter = array();
|
||||
foreach($nomvaisnVAR as $vais){
|
||||
$this->vaisseaux[] = $plan[$vais];
|
||||
}
|
||||
$this->file_vais = explode(';', $plan["file_vais"]);
|
||||
if (!empty($plan["file_vais"])) $this->file_vais = unserialize($plan["file_vais"]);
|
||||
else $this->file_vais = array();
|
||||
|
||||
$this->actualiser();
|
||||
}
|
||||
|
|
@ -108,29 +121,6 @@ class Planete extends User{
|
|||
* @access public
|
||||
*/
|
||||
function actualiser($actuFile = true){
|
||||
//Calcul de la capacité de stockage maximale
|
||||
$cap = pow(2, $this->batiments[10]) * 100000;
|
||||
|
||||
//Calcul du temps écoulé depuis la dernière mise à jour de la planète
|
||||
$temps_ecoule = time() - $this->timestamp;
|
||||
$ressources = $this->production($temps_ecoule);
|
||||
if ($this->metal + $ressources[0] < $cap) $this->metal += $ressources[0];
|
||||
else {
|
||||
$this->alert_ressources[0] = true;
|
||||
$this->metal = $cap;
|
||||
}
|
||||
if ($this->cristal + $ressources[1] < $cap) $this->cristal += $ressources[1];
|
||||
else {
|
||||
$this->alert_ressources[1] = true;
|
||||
$this->cristal = $cap;
|
||||
}
|
||||
if ($this->hydrogene + $ressources[2] < $cap) $this->hydrogene += $ressources[2];
|
||||
else {
|
||||
$this->alert_ressources[2] = true;
|
||||
$this->hydrogene = $cap;
|
||||
}
|
||||
$this->timestamp = time();
|
||||
|
||||
//Actualisation des files d'attentes
|
||||
if ($actuFile) {
|
||||
$this->file_pret("batiments");
|
||||
|
|
@ -140,6 +130,65 @@ class Planete extends User{
|
|||
$this->file_pret("vaisseaux");
|
||||
}
|
||||
|
||||
//Calcul de la capacité de stockage maximale
|
||||
if (!empty($timestamp_lastSilo)) {
|
||||
$cap = pow(2, $this->batiments[10]-1) * 100000;
|
||||
$capnouv = pow(2, $this->batiments[10]) * 100000;
|
||||
}
|
||||
else $cap = pow(2, $this->batiments[10]) * 100000;
|
||||
|
||||
//Calcul du temps écoulé depuis la dernière mise à jour de la planète
|
||||
$temps_ecoule = time() - $this->timestamp;
|
||||
$ressources = $this->production($temps_ecoule);
|
||||
if ($this->metal + $ressources[0] < $cap) $this->metal += $ressources[0];
|
||||
else {
|
||||
//Si les capacité de stockage ont changé depuis la dernière actualisation
|
||||
if (isset($capnouv)) {
|
||||
$ressources = $this->production(time() - $this->timestamp_lastSilo);
|
||||
if ($this->metal + $ressources[0] < $capnouv) $this->metal += $ressources[0];
|
||||
}
|
||||
else {
|
||||
$this->alert_ressources[0] = true;
|
||||
$this->metal = $cap;
|
||||
}
|
||||
}
|
||||
if ($this->cristal + $ressources[1] < $cap) $this->cristal += $ressources[1];
|
||||
else {
|
||||
//Si les capacité de stockage ont changé depuis la dernière actualisation
|
||||
if (isset($capnouv)) {
|
||||
$ressources = $this->production(time() - $this->timestamp_lastSilo);
|
||||
if ($this->cristal + $ressources[1] < $capnouv) $this->cristal += $ressources[1];
|
||||
}
|
||||
else {
|
||||
$this->alert_ressources[1] = true;
|
||||
$this->cristal = $cap;
|
||||
}
|
||||
}
|
||||
if ($this->hydrogene + $ressources[2] < $cap) $this->hydrogene += $ressources[2];
|
||||
else {
|
||||
//Si les capacité de stockage ont changé depuis la dernière actualisation
|
||||
if (isset($capnouv)) {
|
||||
$ressources = $this->production(time() - $this->timestamp_lastSilo);
|
||||
if ($this->hydrogene + $ressources[2] < $capnouv) $this->hydrogene += $ressources[2];
|
||||
}
|
||||
else {
|
||||
$this->alert_ressources[2] = true;
|
||||
$this->hydrogene = $cap;
|
||||
}
|
||||
}
|
||||
|
||||
if (date('zya') != date('zya', $this->timestamp)) {
|
||||
//Si la population est à 0, on ajoute des habitants
|
||||
if ($this->population <= 0) $this->population = 1000;
|
||||
|
||||
$this->population = $this->population * 1.0153^max(1, floor((time()-$this->timestamp)/86400));
|
||||
$this->credits += $this->population/100*exp(0.01)*25;
|
||||
$this->modif[] = 'population';
|
||||
}
|
||||
|
||||
$this->timestamp = time();
|
||||
|
||||
|
||||
//Calcul du nombre de cases restantes
|
||||
$this->casesRest = $this->cases;
|
||||
foreach($this->batiments as $bat){
|
||||
|
|
@ -154,7 +203,6 @@ class Planete extends User{
|
|||
* @access public
|
||||
*/
|
||||
function isolement(){
|
||||
$isolement = explode(' ', $this->isolement);
|
||||
$return = false;
|
||||
|
||||
if (time() > $isolement[0]) {
|
||||
|
|
@ -191,7 +239,11 @@ class Planete extends User{
|
|||
}
|
||||
}
|
||||
|
||||
$this->isolement = implode(' ', $isolement);
|
||||
//On applique les bonus politiques aux productions
|
||||
if (isset($this->politique) && $this->politique == 1) {
|
||||
$sec *= 0.9;
|
||||
}
|
||||
|
||||
if (!in_array('isolement', $this->modif)) $this->modif[] = 'isolement';
|
||||
return $return;
|
||||
}
|
||||
|
|
@ -205,7 +257,7 @@ class Planete extends User{
|
|||
*/
|
||||
function production($temps_ecoule, $retarray = false){
|
||||
//Accélération de la production
|
||||
$temps_ecoule *= 10;
|
||||
$temps_ecoule *= VITESSE;
|
||||
|
||||
//Calcul de la consomation d'énergie
|
||||
if ($this->batiments[0] > 0) $energie_m = ceil(exp(0.28*$this->batiments[0])*10); else $energie_m = 0;
|
||||
|
|
@ -231,7 +283,7 @@ class Planete extends User{
|
|||
for($i = 0; $i < 3; $i++){
|
||||
$Ncoeff[$i] = $coeff * $this->coeff_bat[$i];
|
||||
if ($Ncoeff[$i] > 1) $Ncoeff[$i] = 1;
|
||||
if ($Ncoeff[$i] < $this->coeff_bat[$i]) {
|
||||
if ($Ncoeff[$i] < $this->coeff_bat[$i] && $this->batiments[$i] != 0) {
|
||||
$this->coeff_bat[$i] = $Ncoeff[$i];
|
||||
if (!in_array('coeff_bat', $this->modif)) $this->modif[] = 'coeff_bat';
|
||||
}
|
||||
|
|
@ -251,207 +303,34 @@ class Planete extends User{
|
|||
if ($this->batiments[2] <= 0) $prod_hy = 0;
|
||||
else $prod_hy = ((ceil(pow(1.1, $this->batiments[2]) * 14 * ($this->batiments[2] + 0.7)) / 3600) * $temps_ecoule) * $this->coeff_bat[2] * 1.5 - $conso_h;
|
||||
|
||||
//Augmentation de la production en fonction des technologies
|
||||
if ($this->technologies[0] & 4) {
|
||||
$prod_met *= 1.15;
|
||||
$prod_cri *= 1.15;
|
||||
$prod_hy *= 1.15;
|
||||
}
|
||||
elseif ($this->technologies[0] & 2) {
|
||||
$prod_met *= 1.10;
|
||||
$prod_cri *= 1.10;
|
||||
$prod_hy *= 1.10;
|
||||
}
|
||||
elseif ($this->technologies[0] & 1) {
|
||||
$prod_met *= 1.05;
|
||||
$prod_cri *= 1.05;
|
||||
$prod_hy *= 1.05;
|
||||
}
|
||||
|
||||
//Augmentation de la production en fonction de la politique
|
||||
if ($this->politique == 2) {
|
||||
$prod_met *= 1.10;
|
||||
$prod_cri *= 1.10;
|
||||
$prod_hy *= 1.10;
|
||||
}
|
||||
|
||||
if ($retarray) return array(array(ceil($this->coeff_bat[0]*100), ceil($this->coeff_bat[1]*100), ceil($this->coeff_bat[2]*100), ceil($this->coeff_bat[3]*100), ceil($this->coeff_bat[4]*100)), array($prod_met, $prod_cri, $prod_hy + $conso_h, $energie_s*$this->coeff_bat[3], $energie_f*$this->coeff_bat[4]), array($energie_m*$this->coeff_bat[0], $energie_c*$this->coeff_bat[1], $energie_h*$this->coeff_bat[2], $conso_h, ($energie_s*$this->coeff_bat[3] + $energie_f*$this->coeff_bat[4])-($energie_m*$this->coeff_bat[0] + $energie_c*$this->coeff_bat[1] + $energie_h*$this->coeff_bat[2])));
|
||||
else return array($prod_met, $prod_cri, $prod_hy);
|
||||
}
|
||||
|
||||
/**
|
||||
* Calcul les ressources produites en fonction de $temps_ecoule
|
||||
* @param int $file Nom de la file d'attente
|
||||
* @param int $objet Id de l'objet à ajouter
|
||||
* @param int $nombre = 1 Nombre d'objet $objet à ajouter à la file
|
||||
*
|
||||
* @return int Numéro de l'erreur
|
||||
* @access public
|
||||
*/
|
||||
function file_addObjet($file, $objet, $nombre = 1){
|
||||
$planete = $this;
|
||||
switch($file){
|
||||
case "batiments": $court = "bat"; $calc = "batiment"; $exist = $this->file_exist($objet, "file_".$court); break;
|
||||
case "technologies": $court = "tech"; $calc = "technolo"; $exist = $this->file_exist($objet, "file_".$court); break;
|
||||
case "casernes": $court = "cas"; $calc = "casernen"; $exist = false; break;
|
||||
case "terrestres": $court = "ter"; $calc = "nomterrn"; $exist = false; break;
|
||||
case "vaisseaux": $court = "vais"; $calc = "nomvaisn"; $exist = false; break;
|
||||
default: return 1;
|
||||
}
|
||||
global ${$calc}, ${$calc.'CALC'}, ${$calc.'TECH'};
|
||||
|
||||
//Vérification des conditions de construction
|
||||
if (empty(${$calc}[$objet]) || !requestDeblok(${$calc.'TECH'}[$objet], $this)) return 1;
|
||||
//Vérification qu'il n'y ait pas déjà une instance de l'objet déjà en construction
|
||||
if ($exist) return 2;
|
||||
|
||||
//Actualisation du temps s'il n'y a pas d'objet en file
|
||||
if (count($this->{"file_".$court}) < 2) $this->{"file_".$court}[0] = time();
|
||||
|
||||
//Calcul du prochain niveau de l'objet
|
||||
$n = $this->{$file}[$objet] + 1;
|
||||
|
||||
if ($file == "batiments" || $file == "technologies") {
|
||||
eval(${$calc.'CALC'}[$objet][0]);
|
||||
eval(${$calc.'CALC'}[$objet][1]);
|
||||
eval(${$calc.'CALC'}[$objet][2]);
|
||||
}
|
||||
else {
|
||||
$a = ${$calc.'CALC'}[$objet][0];
|
||||
$b = ${$calc.'CALC'}[$objet][1];
|
||||
$c = ${$calc.'CALC'}[$objet][2];
|
||||
}
|
||||
|
||||
//Vérification des ressources de la planète
|
||||
if ($this->metal < $a * $nombre) return 3;
|
||||
elseif ($this->cristal < $b * $nombre) return 3;
|
||||
elseif ($this->hydrogene < $c * $nombre) return 3;
|
||||
else {
|
||||
//Mise à jour des ressources de la planète en conséquence à la construction
|
||||
$this->metal -= $a * $nombre;
|
||||
$this->cristal -= $b * $nombre;
|
||||
$this->hydrogene -= $c * $nombre;
|
||||
|
||||
//Génération de la file d'attente
|
||||
$nb = count($this->{"file_".$court});
|
||||
|
||||
//Si le dernier objet est identique à celui que l'on veut construire
|
||||
if (ereg($objet.',', $this->{"file_".$court}[$nb-1])) {
|
||||
$last = explode(',', $this->{"file_".$court}[$nb-1]);
|
||||
$last[1] += $nombre;
|
||||
$this->{"file_".$court}[$nb-1] = implode(',', $last);
|
||||
}
|
||||
else $this->{"file_".$court}[] = $objet.','.$nombre;
|
||||
if (!in_array("file_".$court, $this->modif)) $this->modif[] = "file_".$court;
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
function file_delObjet($file, $objet, $nombre = 1, $w = 99) {
|
||||
$planete = $this;
|
||||
switch($file){
|
||||
case "batiments": $court = "bat"; $calc = "batiment"; $exist = $this->file_exist($objet, "file_".$court); break;
|
||||
case "technologies": $court = "tech"; $calc = "technolo"; $exist = $this->file_exist($objet, "file_".$court); break;
|
||||
case "casernes": $court = "cas"; $calc = "casernen"; $exist = $this->file_exist($objet, "file_".$court); break;
|
||||
case "terrestres": $court = "ter"; $calc = "nomterrn"; $exist = $this->file_exist($objet, "file_".$court); break;
|
||||
case "vaisseaux": $court = "vais"; $calc = "nomvaisn"; $exist = $this->file_exist($objet, "file_".$court); break;
|
||||
default: return false;
|
||||
}
|
||||
global ${$calc}, ${$calc.'CALC'};
|
||||
|
||||
//Si l'objet n'est pas dans la file d'attente, on annule la suite
|
||||
if (!$exist) return 0;
|
||||
|
||||
if ($w == 99) $w = count($this->{"file_".$court})-1;
|
||||
|
||||
for($i = $w; $i > 0; $i--) {
|
||||
$last = explode(',', $this->{"file_".$court}[$i]);
|
||||
if($last[0] == $objet){
|
||||
$nombre = min($nombre, $last[1]);
|
||||
|
||||
if($last[1] <= $nombre) {
|
||||
unset($this->{"file_".$court}[$i]);
|
||||
$this->{"file_".$court} = array_merge($this->{"file_".$court});
|
||||
}
|
||||
else $this->{"file_".$court}[$i] = $objet.','.($last[1]-$nombre);
|
||||
|
||||
if ($i == 1) $this->{"file_".$court}[0] = time();
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (!in_array("file_".$court, $this->modif)) $this->modif[] = "file_".$court;
|
||||
|
||||
//Calcul du prochain niveau de l'objet
|
||||
$n = $this->{$file}[$objet] + 1;
|
||||
|
||||
if ($file == "batiments" || $file == "technologies") {
|
||||
eval(${$calc.'CALC'}[$objet][0]);
|
||||
eval(${$calc.'CALC'}[$objet][1]);
|
||||
eval(${$calc.'CALC'}[$objet][2]);
|
||||
}
|
||||
else {
|
||||
$a = ${$calc.'CALC'}[$objet][0];
|
||||
$b = ${$calc.'CALC'}[$objet][1];
|
||||
$c = ${$calc.'CALC'}[$objet][2];
|
||||
}
|
||||
|
||||
//Mise à jour des ressources de la planète en conséquence à la construction
|
||||
$this->metal += $a * $nombre;
|
||||
$this->cristal += $b * $nombre;
|
||||
$this->hydrogene += $c * $nombre;
|
||||
|
||||
return $nombre;
|
||||
}
|
||||
|
||||
/**
|
||||
* Vérifie l'existance dans la file $file d'attente de $i
|
||||
* @param int $i ID à vérifier
|
||||
* @param string $file Nom de la file d'attente
|
||||
*
|
||||
* @return boolean
|
||||
* @access public
|
||||
*/
|
||||
function file_exist($objet, $file){
|
||||
if (count($this->$file) <= 1) return false;
|
||||
foreach($this->$file as $bout){
|
||||
$bout = explode(',', $bout);
|
||||
if($objet == $bout[0]) return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Actualise la file $file en terminant les constructions/entraînements.
|
||||
* @param string $file Nom de la file d'attente
|
||||
*
|
||||
* @return boolean
|
||||
* @access public
|
||||
*/
|
||||
function file_pret($file){
|
||||
$nanite = 0;
|
||||
$planete = $this;
|
||||
switch($file){
|
||||
case "batiments": $court = "bat"; $calc = "batiment"; break;
|
||||
case "technologies": $court = "tech"; $calc = "technolo"; break;
|
||||
case "casernes": $court = "cas"; $calc = "casernen"; break;
|
||||
case "terrestres": $court = "ter"; $calc = "nomterrn"; break;
|
||||
case "vaisseaux": $court = "vais"; $calc = "nomvaisn"; break;
|
||||
default: return false;
|
||||
}
|
||||
global ${$calc}, ${$calc.'CALC'};
|
||||
|
||||
$nb = count($this->{"file_".$court});
|
||||
for($i = 1; $i < $nb; $i++){
|
||||
$obj = explode(',', $this->{"file_".$court}[$i]);
|
||||
$n = $this->{$file}[$obj[0]] + 1;
|
||||
eval(${$calc.'CALC'}[$obj[0]][3]);
|
||||
$tps = time() - $this->{"file_".$court}[0];
|
||||
|
||||
//Accélération du temps de construction
|
||||
$sec /= 10;
|
||||
|
||||
if ($sec * $obj[1] < $tps) {
|
||||
$this->{$file}[$obj[0]] += $obj[1];
|
||||
unset($this->{"file_".$court}[$i]);
|
||||
$this->{"file_".$court} = array_merge($this->{"file_".$court});
|
||||
$this->{"file_".$court}[0] += $obj[1] * $sec;
|
||||
|
||||
if (!in_array($file, $this->modif)) $this->modif[] = $file;
|
||||
if (!in_array("file_".$court, $this->modif)) $this->modif[] = "file_".$court;
|
||||
}
|
||||
elseif ($sec < time() - $this->{"file_".$court}[0]) {
|
||||
for($j=0 ; $j * $sec < $tps ; $j++) {}
|
||||
$j--;
|
||||
$this->{"file_".$court}[$i] = $obj[0].','.($obj[1]-$j);
|
||||
$this->{$file}[$obj[0]] += $j;
|
||||
$this->{"file_".$court}[0] += $j * $sec;
|
||||
|
||||
if (!in_array($file, $this->modif)) $this->modif[] = $file;
|
||||
if (!in_array("file_".$court, $this->modif)) $this->modif[] = "file_".$court;
|
||||
}
|
||||
else {
|
||||
$this->actualiser(false);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Destructeur
|
||||
*
|
||||
|
|
@ -472,8 +351,8 @@ class Planete extends User{
|
|||
else $out[] .= $this->modif[$i]." = '".$this->{$this->modif[$i]}."'";
|
||||
}
|
||||
else {
|
||||
if (ereg('file', $this->modif[$i])) {
|
||||
$prep = implode(';', $this->{$this->modif[$i]});
|
||||
if (is_array($this->{$this->modif[$i]}) && $this->modif[$i] != "coeff_bat" && $this->modif[$i] != "vaisseaux" && $this->modif[$i] != "terrestres" && $this->modif[$i] != "casernes" && $this->modif[$i] != "technologies" && $this->modif[$i] != "batiments") {
|
||||
$prep = serialize($this->{$this->modif[$i]});
|
||||
$bdd->escape($prep);
|
||||
$out[] .= $this->modif[$i]." = '$prep'";
|
||||
}
|
||||
|
|
@ -495,7 +374,7 @@ class Planete extends User{
|
|||
}
|
||||
}
|
||||
}
|
||||
if (!empty($out)) $plan = $bdd->unique_query("UPDATE $table_planete SET ".implode(', ', $out)." WHERE id = ".$this->id.";");
|
||||
if (!empty($out)) $plan = $bdd->query("UPDATE $table_planete SET ".implode(', ', $out)." WHERE id = ".$this->id.";");
|
||||
$bdd->deconnexion();
|
||||
parent::__destruct();
|
||||
}
|
||||
|
|
|
|||
|
|
@ -8,21 +8,28 @@
|
|||
*
|
||||
*
|
||||
***************************************************************************/
|
||||
class User{
|
||||
class User extends File{
|
||||
var $id_user,
|
||||
$pseudo,
|
||||
$auth_level,
|
||||
$race,
|
||||
$id_alliance,
|
||||
$id_grade_alliance,
|
||||
$mv,
|
||||
$mail,
|
||||
$envoyerMail,
|
||||
$last_visite,
|
||||
$points,
|
||||
$place_points,
|
||||
$technologies = array(),
|
||||
$credits,
|
||||
$politique,
|
||||
$politique_lastchange,
|
||||
$destinationsFavoris,
|
||||
$amis,
|
||||
$amis = array(),
|
||||
$combatAT_tactique,
|
||||
$combatDE_tactique,
|
||||
$modifUser = array();
|
||||
$modifUser = array("credits");
|
||||
|
||||
/**
|
||||
* Constructeur
|
||||
|
|
@ -34,7 +41,7 @@ class User{
|
|||
function User($id = 0){
|
||||
if (!empty($id)) {
|
||||
global $var___db, $config, $table_user;
|
||||
global $technoloVAR;
|
||||
global $technologiesVAR;
|
||||
$bdd = new bdd();
|
||||
$bdd->connexion();
|
||||
$bdd->escape($id);
|
||||
|
|
@ -45,18 +52,29 @@ class User{
|
|||
$this->pseudo = $user["pseudo"];
|
||||
$this->auth_level = $user["auth_level"];
|
||||
$this->race = $user["race"];
|
||||
$this->mv = $user["mv"];
|
||||
$this->id_alliance = $user["id_alliance"];
|
||||
$this->id_grade_alliance = $user["id_grade_alliance"];
|
||||
$this->mail = $user["mail"];
|
||||
$this->envoyerMail = $user["envoyerMail"];
|
||||
$this->destinationsFavoris = $user["destinationsFavoris"];
|
||||
$this->last_visite = $user["last_visite"];
|
||||
$this->points = $user["points"];
|
||||
$this->place_points = $user["place_points"];
|
||||
$this->credits = $user["credits"];
|
||||
$this->politique = $user["politique"];
|
||||
$this->politique_lastchange = $user["politique_lastchange"];
|
||||
if (!empty($user["amis"])) $this->amis = unserialize($user["amis"]);
|
||||
else $this->amis = array();
|
||||
if (!empty($user["destinationsFavoris"])) $this->destinationsFavoris = unserialize($user["destinationsFavoris"]);
|
||||
else $this->destinationsFavoris = array();
|
||||
$this->combatAT_tactique = $user["combatAT_tactique"];
|
||||
$this->combatDE_tactique = $user["combatDE_tactique"];
|
||||
|
||||
foreach($technoloVAR as $tech){
|
||||
foreach($technologiesVAR as $tech){
|
||||
$this->technologies[] = $user[$tech];
|
||||
}
|
||||
}
|
||||
else die('Erreur #01 : Utilisateur recherché introuvable dans la base de données. Contactez le support technique ('.$config['mail_support'].') au plus vite en précisant le code d\'erreur.');
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -86,7 +104,7 @@ class User{
|
|||
}
|
||||
else {
|
||||
if ($this->modifUser[$i] == "batiments") $calc = "batiment";
|
||||
elseif ($this->modifUser[$i] == "technologies") $calc = "technolo";
|
||||
elseif ($this->modifUser[$i] == "technologies") $calc = "technologies";
|
||||
elseif ($this->modifUser[$i] == "casernes")$calc = "casernen";
|
||||
elseif ($this->modifUser[$i] == "terrestres") $calc = "nomterrn";
|
||||
elseif ($this->modifUser[$i] == "vaisseaux") $calc = "nomvaisn";
|
||||
|
|
@ -101,7 +119,7 @@ class User{
|
|||
}
|
||||
}
|
||||
}
|
||||
if (!empty($out)) $plan = $bdd->unique_query("UPDATE $table_user SET ".implode(', ', $out)." WHERE id = ".$this->id_user.";");
|
||||
if (!empty($out)) $plan = $bdd->query("UPDATE $table_user SET ".implode(', ', $out)." WHERE id = ".$this->id_user.";");
|
||||
$bdd->deconnexion();
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,118 +0,0 @@
|
|||
<?php
|
||||
class gererFile {
|
||||
var $file = array();
|
||||
var $chaine = false;
|
||||
var $timestamp = 0;
|
||||
var $type = '';
|
||||
var $limite = 0;
|
||||
|
||||
function gererFile($limite, $file, $type) {
|
||||
$this->limite = $limite;
|
||||
$this->type = $type;
|
||||
|
||||
if (!empty($file)) {
|
||||
$file = explode(';', $file);
|
||||
$timestamp = $file[0];
|
||||
unset($file[0]);
|
||||
$file = array_merge($file);
|
||||
$cnt = count($file);
|
||||
for($i = 0; $i < $cnt; $i++){
|
||||
$file[$i] = explode(',', $file[$i]);
|
||||
}
|
||||
$this->file = $file;
|
||||
}
|
||||
else $this->timestamp = time();
|
||||
}
|
||||
|
||||
function addObjet($objet,$nombre,$temps) {
|
||||
$this->file = array_merge($this->file);
|
||||
$nbF = count($this->file);
|
||||
if ($nbF >= $this->limite) return false;
|
||||
$this->chaine = false;
|
||||
if($nbF == 0) $this->timestamp = time();
|
||||
if($nbF > 0 && $this->file[$nbF-1][0] == $objet) $this->file[$nbF-1][1] += $nombre;
|
||||
else $this->file[] = array($objet, $nombre, $temps);
|
||||
return true;
|
||||
}
|
||||
|
||||
function existe($objet) {
|
||||
$this->file = array_merge($this->file);
|
||||
$nbF=count($this->file);
|
||||
for ($i=0 ; $i<$nbF ; $i++){
|
||||
if($objet == $this->file[$i][0]) return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
function delobjet($objet, $nombre=1) {
|
||||
$this->file = array_merge($this->file);
|
||||
for($i = count($this->file)-1; $i >= 0; $i--) {
|
||||
if($this->file[$i][0] == $objet){
|
||||
$nombre = min($nombre, $this->file[$i][1]);
|
||||
$this->file[$i][1] -= $nombre;
|
||||
if($this->file[$i][1] <= 0) {
|
||||
unset($this->file[$i]);
|
||||
$this->file = array_merge($this->file);
|
||||
}
|
||||
break;
|
||||
}
|
||||
if ($i == 1) $this->timestamp = time();
|
||||
}
|
||||
return $nombre;
|
||||
}
|
||||
|
||||
function pret() {
|
||||
global $queryUser, $queryPlanete;
|
||||
include(_FCORE."hb_game/vars.php");
|
||||
|
||||
$this->file = array_merge($this->file);
|
||||
$out = array();
|
||||
$nbF = count($this->file);
|
||||
if ($nbF == 1 && $this->chaine) {
|
||||
eval(${$this->type.'CALC'}[$this->file[0][0]][3]);
|
||||
$this->file[0][2] = $sec;
|
||||
|
||||
$nb = floor((time()-$this->timestamp)/$this->file[0][2]);
|
||||
if ($nb > 0) {
|
||||
$out[] = array($this->file[0][0], $nb);
|
||||
$this->timestamp += $nb * $this->file[0][2];
|
||||
}
|
||||
}
|
||||
elseif ($nbF != 0) {
|
||||
$this->file = array_merge($this->file);
|
||||
for($i=0 ; $i<$nbF ; $i++){
|
||||
print ${$this->type.'CALC'}[$this->file[$i][0]][3];
|
||||
eval(${$this->type.'CALC'}[$this->file[$i][0]][3]);
|
||||
$this->file[$i][2] = $sec;
|
||||
|
||||
$tps = time() - $this->timestamp;
|
||||
if($this->file[$i][1] * $this->file[$i][2] < $tps) {
|
||||
$out[] = array($this->file[$i][0], $this->file[$i][1]);
|
||||
$this->timestamp += $this->file[$i][1] * $this->file[$i][2];
|
||||
unset($this->file[$i]);
|
||||
}
|
||||
elseif ($this->file[$i][2] < $tps) {
|
||||
for($j=0 ; $j*$this->file[$i][2]<$tps ; $j++) {}
|
||||
$j--;
|
||||
$out[] = array($this->file[$i][0], $j);
|
||||
$this->timestamp += $j * $this->file[$i][2];
|
||||
$this->file[$i][1] -= $j;
|
||||
break;
|
||||
}
|
||||
else break;
|
||||
}
|
||||
$this->file = array_merge($this->file);
|
||||
}
|
||||
return $out;
|
||||
}
|
||||
|
||||
function export(){
|
||||
$nbF = count($this->file);
|
||||
$out = '';
|
||||
for($i=0;$i<$nbF;$i++){
|
||||
$out .= implode(',',$this->file[$i]).';';
|
||||
}
|
||||
return $out;
|
||||
}
|
||||
}
|
||||
?>
|
||||
Loading…
Add table
Add a link
Reference in a new issue