Version 1.9a

This commit is contained in:
nemunaire 2008-09-20 12:00:00 +02:00
commit d028822d0b
437 changed files with 27543 additions and 81793 deletions

View file

@ -0,0 +1,160 @@
<?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 !!
}
}
?>

806
game/Class/JSON.php Normal file
View file

@ -0,0 +1,806 @@
<?php
/* vim: set expandtab tabstop=4 shiftwidth=4 softtabstop=4: */
/**
* Converts to and from JSON format.
*
* JSON (JavaScript Object Notation) is a lightweight data-interchange
* format. It is easy for humans to read and write. It is easy for machines
* to parse and generate. It is based on a subset of the JavaScript
* Programming Language, Standard ECMA-262 3rd Edition - December 1999.
* This feature can also be found in Python. JSON is a text format that is
* completely language independent but uses conventions that are familiar
* to programmers of the C-family of languages, including C, C++, C#, Java,
* JavaScript, Perl, TCL, and many others. These properties make JSON an
* ideal data-interchange language.
*
* This package provides a simple encoder and decoder for JSON notation. It
* is intended for use with client-side Javascript applications that make
* use of HTTPRequest to perform server communication functions - data can
* be encoded into JSON notation for use in a client-side javascript, or
* decoded from incoming Javascript requests. JSON format is native to
* Javascript, and can be directly eval()'ed with no further parsing
* overhead
*
* All strings should be in ASCII or UTF-8 format!
*
* LICENSE: Redistribution and use in source and binary forms, with or
* without modification, are permitted provided that the following
* conditions are met: Redistributions of source code must retain the
* above copyright notice, this list of conditions and the following
* disclaimer. Redistributions in binary form must reproduce the above
* copyright notice, this list of conditions and the following disclaimer
* in the documentation and/or other materials provided with the
* distribution.
*
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN
* NO EVENT SHALL CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
* BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
* OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
* TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE
* USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
* DAMAGE.
*
* @category
* @package Services_JSON
* @author Michal Migurski <mike-json@teczno.com>
* @author Matt Knapp <mdknapp[at]gmail[dot]com>
* @author Brett Stimmerman <brettstimmerman[at]gmail[dot]com>
* @copyright 2005 Michal Migurski
* @version CVS: $Id: JSON.php,v 1.31 2006/06/28 05:54:17 migurski Exp $
* @license http://www.opensource.org/licenses/bsd-license.php
* @link http://pear.php.net/pepr/pepr-proposal-show.php?id=198
*/
/**
* Marker constant for Services_JSON::decode(), used to flag stack state
*/
define('SERVICES_JSON_SLICE', 1);
/**
* Marker constant for Services_JSON::decode(), used to flag stack state
*/
define('SERVICES_JSON_IN_STR', 2);
/**
* Marker constant for Services_JSON::decode(), used to flag stack state
*/
define('SERVICES_JSON_IN_ARR', 3);
/**
* Marker constant for Services_JSON::decode(), used to flag stack state
*/
define('SERVICES_JSON_IN_OBJ', 4);
/**
* Marker constant for Services_JSON::decode(), used to flag stack state
*/
define('SERVICES_JSON_IN_CMT', 5);
/**
* Behavior switch for Services_JSON::decode()
*/
define('SERVICES_JSON_LOOSE_TYPE', 16);
/**
* Behavior switch for Services_JSON::decode()
*/
define('SERVICES_JSON_SUPPRESS_ERRORS', 32);
/**
* Converts to and from JSON format.
*
* Brief example of use:
*
* <code>
* // create a new instance of Services_JSON
* $json = new Services_JSON();
*
* // convert a complexe value to JSON notation, and send it to the browser
* $value = array('foo', 'bar', array(1, 2, 'baz'), array(3, array(4)));
* $output = $json->encode($value);
*
* print($output);
* // prints: ["foo","bar",[1,2,"baz"],[3,[4]]]
*
* // accept incoming POST data, assumed to be in JSON notation
* $input = file_get_contents('php://input', 1000000);
* $value = $json->decode($input);
* </code>
*/
class Services_JSON
{
/**
* constructs a new JSON instance
*
* @param int $use object behavior flags; combine with boolean-OR
*
* possible values:
* - SERVICES_JSON_LOOSE_TYPE: loose typing.
* "{...}" syntax creates associative arrays
* instead of objects in decode().
* - SERVICES_JSON_SUPPRESS_ERRORS: error suppression.
* Values which can't be encoded (e.g. resources)
* appear as NULL instead of throwing errors.
* By default, a deeply-nested resource will
* bubble up with an error, so all return values
* from encode() should be checked with isError()
*/
function Services_JSON($use = 0)
{
$this->use = $use;
}
/**
* convert a string from one UTF-16 char to one UTF-8 char
*
* Normally should be handled by mb_convert_encoding, but
* provides a slower PHP-only method for installations
* that lack the multibye string extension.
*
* @param string $utf16 UTF-16 character
* @return string UTF-8 character
* @access private
*/
function utf162utf8($utf16)
{
// oh please oh please oh please oh please oh please
if(function_exists('mb_convert_encoding')) {
return mb_convert_encoding($utf16, 'UTF-8', 'UTF-16');
}
$bytes = (ord($utf16{0}) << 8) | ord($utf16{1});
switch(true) {
case ((0x7F & $bytes) == $bytes):
// this case should never be reached, because we are in ASCII range
// see: http://www.cl.cam.ac.uk/~mgk25/unicode.html#utf-8
return chr(0x7F & $bytes);
case (0x07FF & $bytes) == $bytes:
// return a 2-byte UTF-8 character
// see: http://www.cl.cam.ac.uk/~mgk25/unicode.html#utf-8
return chr(0xC0 | (($bytes >> 6) & 0x1F))
. chr(0x80 | ($bytes & 0x3F));
case (0xFFFF & $bytes) == $bytes:
// return a 3-byte UTF-8 character
// see: http://www.cl.cam.ac.uk/~mgk25/unicode.html#utf-8
return chr(0xE0 | (($bytes >> 12) & 0x0F))
. chr(0x80 | (($bytes >> 6) & 0x3F))
. chr(0x80 | ($bytes & 0x3F));
}
// ignoring UTF-32 for now, sorry
return '';
}
/**
* convert a string from one UTF-8 char to one UTF-16 char
*
* Normally should be handled by mb_convert_encoding, but
* provides a slower PHP-only method for installations
* that lack the multibye string extension.
*
* @param string $utf8 UTF-8 character
* @return string UTF-16 character
* @access private
*/
function utf82utf16($utf8)
{
// oh please oh please oh please oh please oh please
if(function_exists('mb_convert_encoding')) {
return mb_convert_encoding($utf8, 'UTF-16', 'UTF-8');
}
switch(strlen($utf8)) {
case 1:
// this case should never be reached, because we are in ASCII range
// see: http://www.cl.cam.ac.uk/~mgk25/unicode.html#utf-8
return $utf8;
case 2:
// return a UTF-16 character from a 2-byte UTF-8 char
// see: http://www.cl.cam.ac.uk/~mgk25/unicode.html#utf-8
return chr(0x07 & (ord($utf8{0}) >> 2))
. chr((0xC0 & (ord($utf8{0}) << 6))
| (0x3F & ord($utf8{1})));
case 3:
// return a UTF-16 character from a 3-byte UTF-8 char
// see: http://www.cl.cam.ac.uk/~mgk25/unicode.html#utf-8
return chr((0xF0 & (ord($utf8{0}) << 4))
| (0x0F & (ord($utf8{1}) >> 2)))
. chr((0xC0 & (ord($utf8{1}) << 6))
| (0x7F & ord($utf8{2})));
}
// ignoring UTF-32 for now, sorry
return '';
}
/**
* encodes an arbitrary variable into JSON format
*
* @param mixed $var any number, boolean, string, array, or object to be encoded.
* see argument 1 to Services_JSON() above for array-parsing behavior.
* if var is a strng, note that encode() always expects it
* to be in ASCII or UTF-8 format!
*
* @return mixed JSON string representation of input var or an error if a problem occurs
* @access public
*/
function encode($var)
{
switch (gettype($var)) {
case 'boolean':
return $var ? 'true' : 'false';
case 'NULL':
return 'null';
case 'integer':
return (int) $var;
case 'double':
case 'float':
return (float) $var;
case 'string':
// STRINGS ARE EXPECTED TO BE IN ASCII OR UTF-8 FORMAT
$ascii = '';
$strlen_var = strlen($var);
/*
* Iterate over every character in the string,
* escaping with a slash or encoding to UTF-8 where necessary
*/
for ($c = 0; $c < $strlen_var; ++$c) {
$ord_var_c = ord($var{$c});
switch (true) {
case $ord_var_c == 0x08:
$ascii .= '\b';
break;
case $ord_var_c == 0x09:
$ascii .= '\t';
break;
case $ord_var_c == 0x0A:
$ascii .= '\n';
break;
case $ord_var_c == 0x0C:
$ascii .= '\f';
break;
case $ord_var_c == 0x0D:
$ascii .= '\r';
break;
case $ord_var_c == 0x22:
case $ord_var_c == 0x2F:
case $ord_var_c == 0x5C:
// double quote, slash, slosh
$ascii .= '\\'.$var{$c};
break;
case (($ord_var_c >= 0x20) && ($ord_var_c <= 0x7F)):
// characters U-00000000 - U-0000007F (same as ASCII)
$ascii .= $var{$c};
break;
case (($ord_var_c & 0xE0) == 0xC0):
// characters U-00000080 - U-000007FF, mask 110XXXXX
// see http://www.cl.cam.ac.uk/~mgk25/unicode.html#utf-8
$char = pack('C*', $ord_var_c, ord($var{$c + 1}));
$c += 1;
$utf16 = $this->utf82utf16($char);
$ascii .= sprintf('\u%04s', bin2hex($utf16));
break;
case (($ord_var_c & 0xF0) == 0xE0):
// characters U-00000800 - U-0000FFFF, mask 1110XXXX
// see http://www.cl.cam.ac.uk/~mgk25/unicode.html#utf-8
$char = pack('C*', $ord_var_c,
ord($var{$c + 1}),
ord($var{$c + 2}));
$c += 2;
$utf16 = $this->utf82utf16($char);
$ascii .= sprintf('\u%04s', bin2hex($utf16));
break;
case (($ord_var_c & 0xF8) == 0xF0):
// characters U-00010000 - U-001FFFFF, mask 11110XXX
// see http://www.cl.cam.ac.uk/~mgk25/unicode.html#utf-8
$char = pack('C*', $ord_var_c,
ord($var{$c + 1}),
ord($var{$c + 2}),
ord($var{$c + 3}));
$c += 3;
$utf16 = $this->utf82utf16($char);
$ascii .= sprintf('\u%04s', bin2hex($utf16));
break;
case (($ord_var_c & 0xFC) == 0xF8):
// characters U-00200000 - U-03FFFFFF, mask 111110XX
// see http://www.cl.cam.ac.uk/~mgk25/unicode.html#utf-8
$char = pack('C*', $ord_var_c,
ord($var{$c + 1}),
ord($var{$c + 2}),
ord($var{$c + 3}),
ord($var{$c + 4}));
$c += 4;
$utf16 = $this->utf82utf16($char);
$ascii .= sprintf('\u%04s', bin2hex($utf16));
break;
case (($ord_var_c & 0xFE) == 0xFC):
// characters U-04000000 - U-7FFFFFFF, mask 1111110X
// see http://www.cl.cam.ac.uk/~mgk25/unicode.html#utf-8
$char = pack('C*', $ord_var_c,
ord($var{$c + 1}),
ord($var{$c + 2}),
ord($var{$c + 3}),
ord($var{$c + 4}),
ord($var{$c + 5}));
$c += 5;
$utf16 = $this->utf82utf16($char);
$ascii .= sprintf('\u%04s', bin2hex($utf16));
break;
}
}
return '"'.$ascii.'"';
case 'array':
/*
* As per JSON spec if any array key is not an integer
* we must treat the the whole array as an object. We
* also try to catch a sparsely populated associative
* array with numeric keys here because some JS engines
* will create an array with empty indexes up to
* max_index which can cause memory issues and because
* the keys, which may be relevant, will be remapped
* otherwise.
*
* As per the ECMA and JSON specification an object may
* have any string as a property. Unfortunately due to
* a hole in the ECMA specification if the key is a
* ECMA reserved word or starts with a digit the
* parameter is only accessible using ECMAScript's
* bracket notation.
*/
// treat as a JSON object
if (is_array($var) && count($var) && (array_keys($var) !== range(0, sizeof($var) - 1))) {
$properties = array_map(array($this, 'name_value'),
array_keys($var),
array_values($var));
foreach($properties as $property) {
if(Services_JSON::isError($property)) {
return $property;
}
}
return '{' . join(',', $properties) . '}';
}
// treat it like a regular array
$elements = array_map(array($this, 'encode'), $var);
foreach($elements as $element) {
if(Services_JSON::isError($element)) {
return $element;
}
}
return '[' . join(',', $elements) . ']';
case 'object':
$vars = get_object_vars($var);
$properties = array_map(array($this, 'name_value'),
array_keys($vars),
array_values($vars));
foreach($properties as $property) {
if(Services_JSON::isError($property)) {
return $property;
}
}
return '{' . join(',', $properties) . '}';
default:
return ($this->use & SERVICES_JSON_SUPPRESS_ERRORS)
? 'null'
: new Services_JSON_Error(gettype($var)." can not be encoded as JSON string");
}
}
/**
* array-walking function for use in generating JSON-formatted name-value pairs
*
* @param string $name name of key to use
* @param mixed $value reference to an array element to be encoded
*
* @return string JSON-formatted name-value pair, like '"name":value'
* @access private
*/
function name_value($name, $value)
{
$encoded_value = $this->encode($value);
if(Services_JSON::isError($encoded_value)) {
return $encoded_value;
}
return $this->encode(strval($name)) . ':' . $encoded_value;
}
/**
* reduce a string by removing leading and trailing comments and whitespace
*
* @param $str string string value to strip of comments and whitespace
*
* @return string string value stripped of comments and whitespace
* @access private
*/
function reduce_string($str)
{
$str = preg_replace(array(
// eliminate single line comments in '// ...' form
'#^\s*//(.+)$#m',
// eliminate multi-line comments in '/* ... */' form, at start of string
'#^\s*/\*(.+)\*/#Us',
// eliminate multi-line comments in '/* ... */' form, at end of string
'#/\*(.+)\*/\s*$#Us'
), '', $str);
// eliminate extraneous space
return trim($str);
}
/**
* decodes a JSON string into appropriate variable
*
* @param string $str JSON-formatted string
*
* @return mixed number, boolean, string, array, or object
* corresponding to given JSON input string.
* See argument 1 to Services_JSON() above for object-output behavior.
* Note that decode() always returns strings
* in ASCII or UTF-8 format!
* @access public
*/
function decode($str)
{
$str = $this->reduce_string($str);
switch (strtolower($str)) {
case 'true':
return true;
case 'false':
return false;
case 'null':
return null;
default:
$m = array();
if (is_numeric($str)) {
// Lookie-loo, it's a number
// This would work on its own, but I'm trying to be
// good about returning integers where appropriate:
// return (float)$str;
// Return float or int, as appropriate
return ((float)$str == (integer)$str)
? (integer)$str
: (float)$str;
} elseif (preg_match('/^("|\').*(\1)$/s', $str, $m) && $m[1] == $m[2]) {
// STRINGS RETURNED IN UTF-8 FORMAT
$delim = substr($str, 0, 1);
$chrs = substr($str, 1, -1);
$utf8 = '';
$strlen_chrs = strlen($chrs);
for ($c = 0; $c < $strlen_chrs; ++$c) {
$substr_chrs_c_2 = substr($chrs, $c, 2);
$ord_chrs_c = ord($chrs{$c});
switch (true) {
case $substr_chrs_c_2 == '\b':
$utf8 .= chr(0x08);
++$c;
break;
case $substr_chrs_c_2 == '\t':
$utf8 .= chr(0x09);
++$c;
break;
case $substr_chrs_c_2 == '\n':
$utf8 .= chr(0x0A);
++$c;
break;
case $substr_chrs_c_2 == '\f':
$utf8 .= chr(0x0C);
++$c;
break;
case $substr_chrs_c_2 == '\r':
$utf8 .= chr(0x0D);
++$c;
break;
case $substr_chrs_c_2 == '\\"':
case $substr_chrs_c_2 == '\\\'':
case $substr_chrs_c_2 == '\\\\':
case $substr_chrs_c_2 == '\\/':
if (($delim == '"' && $substr_chrs_c_2 != '\\\'') ||
($delim == "'" && $substr_chrs_c_2 != '\\"')) {
$utf8 .= $chrs{++$c};
}
break;
case preg_match('/\\\u[0-9A-F]{4}/i', substr($chrs, $c, 6)):
// single, escaped unicode character
$utf16 = chr(hexdec(substr($chrs, ($c + 2), 2)))
. chr(hexdec(substr($chrs, ($c + 4), 2)));
$utf8 .= $this->utf162utf8($utf16);
$c += 5;
break;
case ($ord_chrs_c >= 0x20) && ($ord_chrs_c <= 0x7F):
$utf8 .= $chrs{$c};
break;
case ($ord_chrs_c & 0xE0) == 0xC0:
// characters U-00000080 - U-000007FF, mask 110XXXXX
//see http://www.cl.cam.ac.uk/~mgk25/unicode.html#utf-8
$utf8 .= substr($chrs, $c, 2);
++$c;
break;
case ($ord_chrs_c & 0xF0) == 0xE0:
// characters U-00000800 - U-0000FFFF, mask 1110XXXX
// see http://www.cl.cam.ac.uk/~mgk25/unicode.html#utf-8
$utf8 .= substr($chrs, $c, 3);
$c += 2;
break;
case ($ord_chrs_c & 0xF8) == 0xF0:
// characters U-00010000 - U-001FFFFF, mask 11110XXX
// see http://www.cl.cam.ac.uk/~mgk25/unicode.html#utf-8
$utf8 .= substr($chrs, $c, 4);
$c += 3;
break;
case ($ord_chrs_c & 0xFC) == 0xF8:
// characters U-00200000 - U-03FFFFFF, mask 111110XX
// see http://www.cl.cam.ac.uk/~mgk25/unicode.html#utf-8
$utf8 .= substr($chrs, $c, 5);
$c += 4;
break;
case ($ord_chrs_c & 0xFE) == 0xFC:
// characters U-04000000 - U-7FFFFFFF, mask 1111110X
// see http://www.cl.cam.ac.uk/~mgk25/unicode.html#utf-8
$utf8 .= substr($chrs, $c, 6);
$c += 5;
break;
}
}
return $utf8;
} elseif (preg_match('/^\[.*\]$/s', $str) || preg_match('/^\{.*\}$/s', $str)) {
// array, or object notation
if ($str{0} == '[') {
$stk = array(SERVICES_JSON_IN_ARR);
$arr = array();
} else {
if ($this->use & SERVICES_JSON_LOOSE_TYPE) {
$stk = array(SERVICES_JSON_IN_OBJ);
$obj = array();
} else {
$stk = array(SERVICES_JSON_IN_OBJ);
$obj = new stdClass();
}
}
array_push($stk, array('what' => SERVICES_JSON_SLICE,
'where' => 0,
'delim' => false));
$chrs = substr($str, 1, -1);
$chrs = $this->reduce_string($chrs);
if ($chrs == '') {
if (reset($stk) == SERVICES_JSON_IN_ARR) {
return $arr;
} else {
return $obj;
}
}
//print("\nparsing {$chrs}\n");
$strlen_chrs = strlen($chrs);
for ($c = 0; $c <= $strlen_chrs; ++$c) {
$top = end($stk);
$substr_chrs_c_2 = substr($chrs, $c, 2);
if (($c == $strlen_chrs) || (($chrs{$c} == ',') && ($top['what'] == SERVICES_JSON_SLICE))) {
// found a comma that is not inside a string, array, etc.,
// OR we've reached the end of the character list
$slice = substr($chrs, $top['where'], ($c - $top['where']));
array_push($stk, array('what' => SERVICES_JSON_SLICE, 'where' => ($c + 1), 'delim' => false));
//print("Found split at {$c}: ".substr($chrs, $top['where'], (1 + $c - $top['where']))."\n");
if (reset($stk) == SERVICES_JSON_IN_ARR) {
// we are in an array, so just push an element onto the stack
array_push($arr, $this->decode($slice));
} elseif (reset($stk) == SERVICES_JSON_IN_OBJ) {
// we are in an object, so figure
// out the property name and set an
// element in an associative array,
// for now
$parts = array();
if (preg_match('/^\s*(["\'].*[^\\\]["\'])\s*:\s*(\S.*),?$/Uis', $slice, $parts)) {
// "name":value pair
$key = $this->decode($parts[1]);
$val = $this->decode($parts[2]);
if ($this->use & SERVICES_JSON_LOOSE_TYPE) {
$obj[$key] = $val;
} else {
$obj->$key = $val;
}
} elseif (preg_match('/^\s*(\w+)\s*:\s*(\S.*),?$/Uis', $slice, $parts)) {
// name:value pair, where name is unquoted
$key = $parts[1];
$val = $this->decode($parts[2]);
if ($this->use & SERVICES_JSON_LOOSE_TYPE) {
$obj[$key] = $val;
} else {
$obj->$key = $val;
}
}
}
} elseif ((($chrs{$c} == '"') || ($chrs{$c} == "'")) && ($top['what'] != SERVICES_JSON_IN_STR)) {
// found a quote, and we are not inside a string
array_push($stk, array('what' => SERVICES_JSON_IN_STR, 'where' => $c, 'delim' => $chrs{$c}));
//print("Found start of string at {$c}\n");
} elseif (($chrs{$c} == $top['delim']) &&
($top['what'] == SERVICES_JSON_IN_STR) &&
((strlen(substr($chrs, 0, $c)) - strlen(rtrim(substr($chrs, 0, $c), '\\'))) % 2 != 1)) {
// found a quote, we're in a string, and it's not escaped
// we know that it's not escaped becase there is _not_ an
// odd number of backslashes at the end of the string so far
array_pop($stk);
//print("Found end of string at {$c}: ".substr($chrs, $top['where'], (1 + 1 + $c - $top['where']))."\n");
} elseif (($chrs{$c} == '[') &&
in_array($top['what'], array(SERVICES_JSON_SLICE, SERVICES_JSON_IN_ARR, SERVICES_JSON_IN_OBJ))) {
// found a left-bracket, and we are in an array, object, or slice
array_push($stk, array('what' => SERVICES_JSON_IN_ARR, 'where' => $c, 'delim' => false));
//print("Found start of array at {$c}\n");
} elseif (($chrs{$c} == ']') && ($top['what'] == SERVICES_JSON_IN_ARR)) {
// found a right-bracket, and we're in an array
array_pop($stk);
//print("Found end of array at {$c}: ".substr($chrs, $top['where'], (1 + $c - $top['where']))."\n");
} elseif (($chrs{$c} == '{') &&
in_array($top['what'], array(SERVICES_JSON_SLICE, SERVICES_JSON_IN_ARR, SERVICES_JSON_IN_OBJ))) {
// found a left-brace, and we are in an array, object, or slice
array_push($stk, array('what' => SERVICES_JSON_IN_OBJ, 'where' => $c, 'delim' => false));
//print("Found start of object at {$c}\n");
} elseif (($chrs{$c} == '}') && ($top['what'] == SERVICES_JSON_IN_OBJ)) {
// found a right-brace, and we're in an object
array_pop($stk);
//print("Found end of object at {$c}: ".substr($chrs, $top['where'], (1 + $c - $top['where']))."\n");
} elseif (($substr_chrs_c_2 == '/*') &&
in_array($top['what'], array(SERVICES_JSON_SLICE, SERVICES_JSON_IN_ARR, SERVICES_JSON_IN_OBJ))) {
// found a comment start, and we are in an array, object, or slice
array_push($stk, array('what' => SERVICES_JSON_IN_CMT, 'where' => $c, 'delim' => false));
$c++;
//print("Found start of comment at {$c}\n");
} elseif (($substr_chrs_c_2 == '*/') && ($top['what'] == SERVICES_JSON_IN_CMT)) {
// found a comment end, and we're in one now
array_pop($stk);
$c++;
for ($i = $top['where']; $i <= $c; ++$i)
$chrs = substr_replace($chrs, ' ', $i, 1);
//print("Found end of comment at {$c}: ".substr($chrs, $top['where'], (1 + $c - $top['where']))."\n");
}
}
if (reset($stk) == SERVICES_JSON_IN_ARR) {
return $arr;
} elseif (reset($stk) == SERVICES_JSON_IN_OBJ) {
return $obj;
}
}
}
}
/**
* @todo Ultimately, this should just call PEAR::isError()
*/
function isError($data, $code = null)
{
if (class_exists('pear')) {
return PEAR::isError($data, $code);
} elseif (is_object($data) && (get_class($data) == 'services_json_error' ||
is_subclass_of($data, 'services_json_error'))) {
return true;
}
return false;
}
}
if (class_exists('PEAR_Error')) {
class Services_JSON_Error extends PEAR_Error
{
function Services_JSON_Error($message = 'unknown error', $code = null,
$mode = null, $options = null, $userinfo = null)
{
parent::PEAR_Error($message, $code, $mode, $options, $userinfo);
}
}
} else {
/**
* @todo Ultimately, this class shall be descended from PEAR_Error
*/
class Services_JSON_Error
{
function Services_JSON_Error($message = 'unknown error', $code = null,
$mode = null, $options = null, $userinfo = null)
{
}
}
}
?>

187
game/Class/class.bourse.php Normal file
View file

@ -0,0 +1,187 @@
<?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 $taxeV = 1.5;
var $metal;
var $cristal;
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, "id");
if (!empty($user)) $this->loadUser($user);
}
}
function __destruct(){
$this->bd->deconnexion();
}
function loadAction($nom, $type = "nom"){
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'];
}
function loadUser($user, $type = "id"){
global $table_user;
$this->bd->escape($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]);
if (!empty($tmp[1])) $end[$tmp[0]] = explode(',', $tmp[1]);
else $end[$tmp[0]] = array();
}
$this->actionsUser = $end;
}
function prixAchat($nb){
return array(floor($this->metal * $nb * $this->taxeA), floor($this->cristal * $nb * $this->taxeA));
}
function prixVente($nb){
if ($this->action() < $nb) $nb = $this->action();
return array(floor($this->metal * $nb / $this->taxeV), floor($this->cristal * $nb / $this->taxeV));
}
function addAction($nb){
$ret = array(floor($this->metal * $nb * $this->taxeA), floor($this->cristal * $nb * $this->taxeA));
$this->metal *= pow(1.1, $nb);
$this->cristal *= pow(1.1, $nb);
for($i = 0; $i < $nb; $i++){
$this->actionsUser[$this->id][] = time();
}
$this->maj();
return $ret;
}
function delAction($nb){
if ($this->action() < $nb) $nb = $this->action();
$ret = array(floor($this->metal * $nb / $this->taxeV), floor($this->cristal * $nb / $this->taxeV));
$this->metal /= pow(1.1, $nb);
$this->cristal /= pow(1.1, $nb);
for($i = 0; $i < $nb; $i++){
unset($this->actionsUser[$this->id][$i]);
}
$this->maj();
return $ret;
}
function actionIn24Hours(){
$nb = 0;
if (isset($this->actionsUser[$this->id])) {
$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(){
if (isset($this->actionsUser[$this->id])) return count($this->actionsUser[$this->id]);
else return 0;
}
function maj(){
$this->majBourse();
$this->majUser();
$this->fileSave();
}
function majBourse(){
global $table_bourse;
$this->bd->query("UPDATE $table_bourse SET nom = '".$this->nom."', metal = '".$this->metal."', cristal = '".$this->cristal."' WHERE id = ".$this->id.";");
}
function majUser(){
global $table_user;
$champ = '';
foreach($this->actionsUser as $key => $cell) {
if (count($cell) > 0) {
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 delUser($id = ""){
if (!empty($id)) $this->loadUser($id);
$champ = '';
foreach($this->actionsUser as $key => $cell) {
$cnt = count($cell);
if ($cnt > 0) {
$this->loadAction($key, "id");
$this->delAction($cnt);
}
}
}
function fileSave(){
$fichier = fopen(_FCORE."../game/cache/bourse/".$this->id.".".strftime('%Y%m%d').".bourse",'a+');
fwrite($fichier, time().';'.$this->metal.';'.$this->cristal."\n");
fclose($fichier);
}
function newGroupe($nom, $metal, $cristal, $description = ""){
global $table_bourse;
$this->bd->query("INSERT INTO $table_bourse (nom, metal, cristal, description) VALUES('$nom', '$metal', '$cristal', '$description');");
}
function editGroupe($description){
//TODO toute cette fonction !!
}
}
?>

505
game/Class/class.combat.php Normal file
View file

@ -0,0 +1,505 @@
<?php
/***************************************************************************
* class.combat.php
* -------------------
* begin : Samedi 26 janvier 2008
* update : Mercredi 4 juin 2008
* email : nemunaire@gmail.com
*
*
***************************************************************************/
class Combat {
var $refflotte = 0;
var $ATvais = array();
var $ENvais = array();
var $ENres = array('metal' => 0, 'cristal' => 0, 'hydrogene' => 0);
var $ENdef = array();
var $Ntour = 0;
var $ATtactique = 0;
var $ENtactique = 0;
var $timestamp = 0;
var $vaisContenu = 0;
var $vaisContenuM = 0;
var $vaisContenuC = 0;
var $vaisContenuH = 0;
var $pillage = array(0, 0, 0);
var $debriM = 0;
var $debriC = 0;
/**
* Constructeur
* @param array $flotteAT tableau SQL des vaisseaux envoyés par l'attaquant
* @param array $flotteEN tableau SQL de la planète du défenseur
* @param array $defEN tableau SQL de la planète du défenseur
*
* @return void
* @access public
*/
function Combat($flotteAT, $flotteEN, $defEN, $tableTechno = array(0, 0)) {
include(_FCORE."hb_game/vars.php");
//Génération des vaisseaux attaquants
for ($i=1 ; $i<=12 ; $i++) {
if ($flotteAT['vaisseau_'.$i] >= 1) {
//Création des groupes
$nbvais = $flotteAT['vaisseau_'.$i];
$nbgroupes = floor(sqrt(ceil($nbvais/10)));
$nbvaispgroupe = floor($nbvais/$nbgroupes);
$nbrest = $nbvais - $nbvaispgroupe * $nbgroupes;
if (isset($groupe)) unset($groupe);
$groupe = array();
for ($j=0 ; $j < $nbgroupes ; $j++) {
if ($j == 0) $groupe[] = array($nbvaispgroupe + $nbrest, $nomvais_bc[$i-1] * (1 + $tableTechno[0]/10), $nomvais_pv[$i-1]);
else $groupe[] = array($nbvaispgroupe, $nomvais_bc[$i-1] * (1 + $tableTechno[0]/10), $nomvais_pv[$i-1]);
}
$this->ATvais[] = array($i, $flotteAT['vaisseau_'.$i], $nbgroupes, $groupe, $nomvais_initiative[$i-1]);
}
}
//Définition d'autres variables de la classe concernant la flotte
$this->refflotte = $flotteAT['id'];
$this->vaisContenu = $flotteAT['contenu_max'];
$this->vaisContenuM = $flotteAT['contenu_metal'];
$this->vaisContenuC = $flotteAT['contenu_cristal'];
$this->vaisContenuH = $flotteAT['contenu_hydrogene'];
$this->timestamp = $flotteAT['start_time'] + $flotteAT['end_time'];
//Génération des vaisseaux défenseurs
for ($i=1 ; $i<=12 ; $i++) {
if ($flotteEN['vaisseau_'.$i] >= 1) {
//Création des groupes
$nbvais = $flotteEN['vaisseau_'.$i];
$nbgroupes = floor(sqrt(ceil($nbvais/10)));
$nbvaispgroupe = floor($nbvais/$nbgroupes);
$nbrest = $nbvais - $nbvaispgroupe * $nbgroupes;
if (isset($groupe)) unset($groupe);
$groupe = array();
for ($j=0 ; $j < $nbgroupes ; $j++) {
if ($j == 0) $groupe[] = array($nbvaispgroupe + $nbrest, $nomvais_bc[$i-1] * (1 + $tableTechno[1]/10), $nomvais_pv[$i-1]);
else $groupe[] = array($nbvaispgroupe, $nomvais_bc[$i-1] * (1 + $tableTechno[1]/10), $nomvais_pv[$i-1]);
}
$this->ENvais[] = array($i, $flotteEN['vaisseau_'.$i], $nbgroupes, $groupe, $nomvais_initiative[$i-1]);
}
}
//Génération des défenses défenseurs
for ($i=1 ; $i<=5 ; $i++) {
if ($defEN['def_'.$i] >= 1) {
//Création des groupes
$nbvais = $defEN['def_'.$i];
$nbgroupes = floor(sqrt(ceil($nbvais/10)));
$nbvaispgroupe = floor($nbvais/$nbgroupes);
$nbrest = $nbvais - $nbvaispgroupe * $nbgroupes;
if (isset($groupe)) unset($groupe);
$groupe = array();
for ($j=0 ; $j < $nbgroupes ; $j++) {
if ($j == 0) $groupe[] = array($nbvaispgroupe + $nbrest, $defense_bc[$i-1] * (1 + $tableTechno[1]/10), $defense_pv[$i-1]);
else $groupe[] = array($nbvaispgroupe, $defense_bc[$i-1] * (1 + $tableTechno[1]/10), $defense_pv[$i-1]);
}
$this->ENdef[] = array($i, $defEN['def_'.$i], $nbgroupes, $groupe, $defense_initiative[$i-1]);
}
}
}
/**
* Change la tactique de l'attaquant
* @param int $tactique numéro de la tactique choisie
*
* @return void
* @access public
*/
function changerTactiqueAT($tactique) {
$this->ATtactique = ceil($tactique);
}
/**
* Change la tactique du défenseur
* @param int $tactique numéro de la tactique choisie
*
* @return void
* @access public
*/
function changerTactiqueEN($tactique) {
$this->ENtactique = ceil($tactique);
}
/**
* Régénére les boucliers
* @param int $pourcentage pourcentage de régénération
* @param bool $attaquant régénére le bouclier de l'attaquant si true, sinon régénrére celui du défenseur
* @param bool $retour si true, renvoie true ou false si !le pourcentage a été consommé ou non, si false, retrourne ne nombre de pourcentage restant
* @param int $blindage niveau de la technologie blindage du joueur
*
* @return float pourcentage non utilisé
* @access public
*/
function regenereBC($pourcentage, $attaquant, $retour = false, $blindage = 0) {
include(_FCORE."hb_game/vars.php");
if ($attaquant) {
$count = count($this->ATvais);
$enplus = 0;
$norm = 0;
for ($i=0 ; $i<$count ; $i++) {
$type = $this->ATvais[$i][0]-1;
$maxbc = $nomvais_bc[$type] * (1 + $blindage/10);
$ajout = $maxbc*$pourcentage/100;
$cntbc = count($this->ATvais[$i][3]);
for ($j=0 ; $j<$cntbc ; $j++) {
$norm += $maxbc * $this->ATvais[$i][3][$j][0];
if ($this->ATvais[$i][3][$j][1] < $maxbc) {
$this->ATvais[$i][3][$j][1] += $ajout;
}
else $enplus += $ajout * $this->ATvais[$i][3][$j][0];
if ($this->ATvais[$i][3][$j][1] > $maxbc) {
$enplus += ($this->ATvais[$i][3][$j][1] - $maxbc)*$this->ATvais[$i][3][$j][0];
$this->ATvais[$i][3][$j][1] = $maxbc;
}
}
}
if ($retour) {
if($norm != 0 && $enplus/$norm == 1) return $pourcentage;
else return false;
}
else return $enplus/$norm;
}
else {
$count = count($this->ENvais);
$enplus = 0;
$norm = 0;
for ($i=0 ; $i<$count ; $i++) {
$type = $this->ENvais[$i][0]-1;
$maxbc = $nomvais_bc[$type] * (1 + $blindage/10);
$ajout = $maxbc*$pourcentage/100;
$cntbc = count($this->ENvais[$i][3]);
for ($j=0 ; $j<$cntbc ; $j++) {
$norm += $maxbc * $this->ENvais[$i][3][$j][0];
if ($this->ENvais[$i][3][$j][1] < $maxbc) {
$this->ENvais[$i][3][$j][1] += $ajout;
}
else $enplus += $ajout * $this->ENvais[$i][3][$j][0];
if ($this->ENvais[$i][3][$j][1] > $maxbc) {
$enplus += ($this->ENvais[$i][3][$j][1] - $maxbc)*$this->ENvais[$i][3][$j][0];
$this->ENvais[$i][3][$j][1] = $maxbc;
}
}
}
if ($norm != 0) $return = $enplus/$norm;
else $return = 0;
//Défenses
$count = count($this->ENdef);
$enplus = 0;
$norm = 0;
for ($i=0 ; $i<$count ; $i++) {
$type = $this->ENdef[$i][0]-1;
$maxbc = $defense_bc[$type] * (1 + $blindage/10);
$ajout = $maxbc*$pourcentage/100;
$cntbc = count($this->ENdef[$i][3]);
for ($j=0 ; $j<$cntbc ; $j++) {
$norm += $maxbc * $this->ENdef[$i][3][$j][0];
if ($this->ENdef[$i][3][$j][1] < $maxbc) {
$this->ENdef[$i][3][$j][1] += $ajout;
}
else $enplus += $ajout * $this->ENdef[$i][3][$j][0];
if ($this->ENdef[$i][3][$j][1] > $maxbc) {
$enplus += ($this->ENdef[$i][3][$j][1] - $maxbc)*$this->ENdef[$i][3][$j][0];
$this->ENdef[$i][3][$j][1] = $maxbc;
}
}
}
if ($norm != 0) $return = $enplus/$norm;
else $return = 0;
if ($retour) {
if($norm != 0 && $enplus/$norm == 1) return $pourcentage;
else return false;
}
else return $return/2;
}
}
/**
* Calcul la puissance d'attaque disponible
* @param int $pourcentage pourcentage de régénération
* @param bool $attaquant calcul les points de l'attaquant si true, sinon calcul pour le défenseur
* @param int $armement niveau de la technologie armement du joueur
* @param bool $method true pour utiliser la mèthode classique, false pour utiliser la méthode d'Apocalypse Joe
*
* @return int points disponibles
* @access public
*/
function calcAttaque($pourcentage, $attaquant, $armement = 0, $method = false) {
include(_FCORE."hb_game/vars.php");
if ($method) {
if ($attaquant) {
$puissance = 0;
$count = count($this->ATvais);
for ($i=0 ; $i<$count ; $i++) {
$maxat = $nomvais_at[$this->ATvais[$i][0]-1] * (1 + $armement/10);
$puissance += $maxat * $pourcentage/100 * $this->ATvais[$i][1];
}
return $puissance;
}
else {
$puissance = 0;
$count = count($this->ENvais);
for ($i=0 ; $i<$count ; $i++) {
$maxat = $nomvais_at[$this->ENvais[$i][0]-1] * (1 + $armement/10);
$puissance += $maxat * $pourcentage/100 * $this->ENvais[$i][1];
}
//Défenses
$count = count($this->ENdef);
for ($i=0 ; $i<$count ; $i++) {
$maxat = $defense_at[$this->ENdef[$i][0]-1] * (1 + $armement/10);
$puissance += $maxat * $pourcentage/100 * $this->ENdef[$i][1];
}
return $puissance;
}
}
else {
if ($attaquant) {
//Calcul du pourcentage de chaque vaisseau adverse
$vaisEff = array();
$nbvais = 0;
$countj = count($this->ENvais);
$countd = count($this->ENdef);
for ($i=0 ; $i<$countj ; $i++) {
$nbvais += $this->ENvais[$i][1];
}
for ($i=0 ; $i<$countj ; $i++) {
$vaisEff[$this->ENvais[$i][0]] = $this->ENvais[$i][1]/$nbvais;
}
$puissance = 0;
$count = count($this->ATvais);
for ($i=0 ; $i<$count ; $i++) {
if ($this->ATvais[$i][4] > $this->Ntour) continue;
$bonus = 0;
for ($j=0 ; $j<$countj ; $j++) {
$bonus += $nomvais_rf[$this->ATvais[$i][0]-1][$this->ENvais[$i][0]-1] * $vaisEff[$this->ENvais[$i][0]];
}
for ($j=0 ; $j<$countd ; $j++) {
$bonus += 1/$countd;
}
$maxat = $nomvais_at[$this->ATvais[$i][0]-1] * (1 + $armement/10);
$puissance += $maxat * $pourcentage/100 * $this->ATvais[$i][1] * $bonus;
}
return $puissance;
}
else {
//Calcul du pourcentage de chaque vaisseau adverse
$vaisEff = array();
$nbvais = 0;
$countj = count($this->ATvais);
for ($i=0 ; $i<$countj ; $i++) {
$nbvais += $this->ATvais[$i][1];
}
for ($i=0 ; $i<$countj ; $i++) {
$vaisEff[$this->ATvais[$i][0]] = $this->ATvais[$i][1]/$nbvais;
}
$puissance = 0;
$count = count($this->ENvais);
for ($i=0 ; $i<$count ; $i++) {
if ($this->ENvais[$i][4] > $this->Ntour) continue;
$bonus = 0;
for ($j=0 ; $j<$countj ; $j++) {
$bonus += $nomvais_rf[$this->ENvais[$i][0]-1][$this->ATvais[$i][0]-1] * $vaisEff[$this->ATvais[$i][0]];
}
$maxat = $nomvais_at[$this->ENvais[$i][0]-1] * (1 + $armement/10);
$puissance += $maxat * $pourcentage/100 * $this->ENvais[$i][1] * $bonus;
}
//Défenses
$count = count($this->ENdef);
for ($i=0 ; $i<$count ; $i++) {
if ($this->ENdef[$i][4] > $this->Ntour) continue;
$maxat = $defense_at[$this->ENdef[$i][0]-1] * (1 + $armement/10);
$puissance += $maxat * $pourcentage/100 * $this->ENdef[$i][1];
}
return $puissance;
}
}
}
/**
* Attaque les vaisseaux adverses
* @param int $points points d'attaque disponible pour l'attaque
* @param bool $attaquant attaque le défenseur si true, sinon attaque l'attaquant
*
* @return void
* @access public
*/
function attaquerVais($points, $attaquant) {
include(_FCORE."hb_game/vars.php");
if ($attaquant) {
while($points > 0) {
// Calcul du nombre de vaisseaux et défenses à attaquer
$nbvais = 0;
$nbgroupes = 0;
$nb = count($this->ENvais);
for ($i=0 ; $i<$nb ; $i++) {
$nbvais += $this->ENvais[$i][1];
$nbgroupes += $this->ENvais[$i][2];
}
$nb = count($this->ENdef);
for ($i=0 ; $i<$nb ; $i++) {
$nbvais += $this->ENdef[$i][1];
$nbgroupes += $this->ENdef[$i][2];
}
//S'il ne reste plus de vaisseaux et de défenses, on arrête la boucle
if ($nbvais <= 0 || $nbgroupes <= 0 || $points <= 0) break;
//Calcul du nombre de points qui sera enlevé par vaisseau ou défense
$ppv = $points / $nbvais;
$points = 0;
//On lance l'attaque contre les vaisseaux
for ($j=0 ; $j<$nbgroupes ; $j++){
$k = rand(0, count($this->ENvais)-1);
$l = rand(0, count($this->ENvais[$k][3])-1);
$this->ENvais[$k][3][$l][1] -= $ppv;
if ($this->ENvais[$k][3][$l][1] < 0) {
$this->ENvais[$k][3][$l][2] -= abs($this->ENvais[$k][3][$l][1]);
$this->ENvais[$k][3][$l][1] = 0;
if ($this->ENvais[$k][3][$l][2] <= 0) {
$this->debriM += $this->ENvais[$k][3][$l][0] * $nomvais_md[$this->ENvais[$k][0]];
$this->debriC += $this->ENvais[$k][3][$l][0] * $nomvais_cd[$this->ENvais[$k][0]];
$this->ENvais[$k][1] -= $this->ENvais[$k][3][$l][0];
$this->ENvais[$k][2] --;
array_splice($this->ENvais[$k][3], $l, 1);
if (!count($this->ENvais[$k][3])) {
array_splice($this->ENvais, $k, 1);
}
}
}
}
//On lance l'attaque contre les défenses
for ($j=0 ; $j<$nbgroupes ; $j++){
$k = rand(0, count($this->ENdef)-1);
$l = rand(0, count($this->ENdef[$k][3])-1);
$this->ENdef[$k][3][$l][1] -= $ppv;
if ($this->ENdef[$k][3][$l][1] < 0) {
$this->ENdef[$k][3][$l][2] -= abs($this->ENdef[$k][3][$l][1]);
$this->ENdef[$k][3][$l][1] = 0;
if ($this->ENdef[$k][3][$l][2] <= 0) {
$this->debriM += $this->ENdef[$k][3][$l][0] * $nomvais_md[$this->ENdef[$k][0]];
$this->debriC += $this->ENdef[$k][3][$l][0] * $nomvais_cd[$this->ENdef[$k][0]];
$this->ENdef[$k][1] -= $this->ENdef[$k][3][$l][0];
$this->ENdef[$k][2] --;
array_splice($this->ENdef[$k][3], $l, 1);
if (!count($this->ENdef[$k][3])) {
array_splice($this->ENdef, $k, 1);
}
}
}
}
}
return count($this->ENvais) + count($this->ENdef);
}
else {
while($points > 0) {
// Calcul du nombre de vaisseaux et défenses à attaquer
$nbvais = 0;
$nbgroupes = 0;
$nb = count($this->ATvais);
for ($i=0 ; $i<$nb ; $i++) {
$nbvais += $this->ATvais[$i][1];
$nbgroupes += $this->ATvais[$i][2];
}
//S'il ne reste plus de vaisseaux et de défenses, on arrête la boucle
if ($nbvais <= 0 || $nbgroupes <= 0 || $points <= 0) break;
//Calcul du nombre de points qui sera enlevé par vaisseau ou défense
$ppv = $points / $nbvais;
$points = 0;
//On lance l'attaque
for ($j=0 ; $j<$nbgroupes ; $j++){
$k = rand(0, count($this->ATvais)-1);
$l = rand(0, count($this->ATvais[$k][3])-1);
$this->ATvais[$k][3][$l][1] -= $ppv;
if ($this->ATvais[$k][3][$l][1] < 0) {
$this->ATvais[$k][3][$l][2] -= abs($this->ATvais[$k][3][$l][1]);
$this->ATvais[$k][3][$l][1] = 0;
if ($this->ATvais[$k][3][$l][2] <= 0) {
$this->debriM += $this->ATvais[$k][3][$l][0] * $nomvais_md[$this->ATvais[$k][0]];
$this->debriC += $this->ATvais[$k][3][$l][0] * $nomvais_cd[$this->ATvais[$k][0]];
$this->ATvais[$k][1] -= $this->ATvais[$k][3][$l][0];
$this->ATvais[$k][2] --;
array_splice($this->ATvais[$k][3], $l, 1);
if (!count($this->ATvais[$k][3])) {
array_splice($this->ATvais, $k, 1);
}
}
}
}
}
return count($this->ATvais);
}
}
function exportAT($pillage = false){
include(_FCORE."hb_game/vars.php");
$nb = count($this->ATvais);
$nbvais = 0; $vaisContenu = 0; $vaisseau_1 = 0; $vaisseau_2 = 0; $vaisseau_3 = 0; $vaisseau_4 = 0; $vaisseau_5 = 0; $vaisseau_6 = 0; $vaisseau_7 = 0; $vaisseau_8 = 0; $vaisseau_9 = 0; $vaisseau_10 = 0; $vaisseau_11 = 0; $vaisseau_12 = 0;
for($i=0 ; $i<$nb ; $i++) {
${'vaisseau_'.$this->ATvais[$i][0]} += $this->ATvais[$i][1];
$nbvais += $this->ATvais[$i][1];
$this->vaisContenu += $nomvais_rs[$this->ATvais[$i][0]-1];
}
$sommeCont = $this->vaisContenuM + $this->vaisContenuC + $this->vaisContenuH;
if ($sommeCont > $this->vaisContenu) {
$retirer = $sommeCont/$this->vaisContenu;
$this->vaisContenuM = floor($this->vaisContenuM/$retirer);
$this->vaisContenuC = floor($this->vaisContenuC/$retirer);
$this->vaisContenuH = floor($this->vaisContenuH/$retirer);
}
if ($pillage) {
$ressplus = pillage($this->ENres['metal'], $this->ENres['cristal'], $this->ENres['hydrogene'], $this->vaisContenu - $this->vaisContenuM - $this->vaisContenuC - $this->vaisContenuH);
$this->vaisContenuM += $ressplus[0];
$this->vaisContenuC += $ressplus[1];
$this->vaisContenuH += $ressplus[2];
$this->pillage = array($ressplus[0], $ressplus[1], $ressplus[2]);
}
return 'nb_vais = \''.$nbvais.'\', contenu_max = \''.$this->vaisContenu.'\', contenu_metal = \''.$this->vaisContenuM.'\', contenu_cristal = \''.$this->vaisContenuC.'\', contenu_hydrogene = \''.$this->vaisContenuH.'\', vaisseau_1 = \''.$vaisseau_1.'\', vaisseau_2 = \''.$vaisseau_2.'\', vaisseau_3 = \''.$vaisseau_3.'\', vaisseau_4 = \''.$vaisseau_4.'\', vaisseau_5 = \''.$vaisseau_5.'\', vaisseau_6 = \''.$vaisseau_6.'\', vaisseau_7 = \''.$vaisseau_7.'\', vaisseau_8 = \''.$vaisseau_8.'\', vaisseau_9 = \''.$vaisseau_9.'\', vaisseau_10 = \''.$vaisseau_10.'\', vaisseau_11 = \''.$vaisseau_11.'\', vaisseau_12 = \''.$vaisseau_12.'\'';
}
function pillageSimul($metal, $cristal, $hydrogene){
$ressplus = pillage($metal, $cristal, $hydrogene, 999999);
$this->pillage = array($ressplus[0], $ressplus[1], $ressplus[2]);
}
function exportEN(){
$nb = count($this->ENvais);
$vaisseau_1 = 0; $vaisseau_2 = 0; $vaisseau_3 = 0; $vaisseau_4 = 0; $vaisseau_5 = 0; $vaisseau_6 = 0; $vaisseau_7 = 0; $vaisseau_8 = 0; $vaisseau_9 = 0; $vaisseau_10 = 0; $vaisseau_11 = 0; $vaisseau_12 = 0;
for($i=0 ; $i<$nb ; $i++) {
${'vaisseau_'.$this->ENvais[$i][0]} += $this->ENvais[$i][1];
}
$nb = count($this->ENdef);
$def_1 = 0; $def_2 = 0; $def_3 = 0; $def_4 = 0; $def_5 = 0;
for($i=0 ; $i<$nb ; $i++) {
${'def_'.$this->ENdef[$i][0]} += $this->ENdef[$i][1];
}
return 'vaisseau_1 = \''.$vaisseau_1.'\', vaisseau_2 = \''.$vaisseau_2.'\', vaisseau_3 = \''.$vaisseau_3.'\', vaisseau_4 = \''.$vaisseau_4.'\', vaisseau_5 = \''.$vaisseau_5.'\', vaisseau_6 = \''.$vaisseau_6.'\', vaisseau_7 = \''.$vaisseau_7.'\', vaisseau_8 = \''.$vaisseau_8.'\', vaisseau_9 = \''.$vaisseau_9.'\', vaisseau_10 = \''.$vaisseau_10.'\', vaisseau_11 = \''.$vaisseau_11.'\', vaisseau_12 = \''.$vaisseau_12.'\', def_1 = \''.$def_1.'\', def_2 = \''.$def_2.'\', def_3 = \''.$def_3.'\', def_4 = \''.$def_4.'\', def_5 = \''.$def_5.'\'';
}
}
?>

View file

@ -0,0 +1,110 @@
<?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;
}
}
?>

File diff suppressed because it is too large Load diff

View file

@ -0,0 +1,503 @@
<?php
/***************************************************************************
* class.planete.php
* -------------------
* begin : Jeudi 21 août 2008
* update : Dimanche 7 septembre 2008
* email : nemunaire@gmail.com
*
*
***************************************************************************/
class Planete extends User{
var $id,
$galaxie,
$ss,
$position,
$isolement,
$nom_planete,
$image,
$cases,
$casesRest,
$debris_met,
$debris_cri,
$metal,
$cristal,
$hydrogene,
$alert_ressources = array(false, false, false),
$timestamp,
$energie,
$energieConso,
$file_tech,
$file_bat,
$file_cas,
$file_ter,
$file_vais,
$coeff_bat = array(),
$batiments = array(),
$casernes = array(),
$terrestres = array(),
$vaisseaux = array(),
$modif = array('metal', 'cristal', 'hydrogene', 'timestamp');
/**
* Constructeur
* @param int $id id de la planète à importer
*
* @return void
* @access public
*/
function Planete($id = 0){
if (!empty($id)) {
global $var___db, $config, $table_planete;
global $batimentVAR, $casernenVAR, $nomterrnVAR, $nomvaisnVAR;
$bdd = new bdd();
$bdd->connexion();
$bdd->escape($id);
$plan = $bdd->unique_query("SELECT * FROM $table_planete WHERE id = $id;");
$bdd->deconnexion();
if (!empty($plan)) {
$this->id = $plan["id"];
parent::User($plan["id_user"]);
$this->galaxie = $plan["galaxie"];
$this->ss = $plan["ss"];
$this->position = $plan["position"];
$this->isolement = $plan["isolement"];
$this->nom_planete = $plan["nom_planete"];
$this->image = $plan["image"];
$this->cases = $plan["cases"];
$this->debris_met = $plan["debris_met"];
$this->debris_cri = $plan["debris_cri"];
$this->metal = $plan["metal"];
$this->cristal = $plan["cristal"];
$this->hydrogene = $plan["hydrogene"];
$this->timestamp = $plan["timestamp"];
foreach($batimentVAR as $bat){
$this->batiments[] = $plan[$bat];
}
$this->file_bat = explode(';', $plan["file_bat"]);
$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"]);
foreach($casernenVAR as $cas){
$this->casernes[] = $plan[$cas];
}
$this->file_cas = explode(';', $plan["file_cas"]);
foreach($nomterrnVAR as $ter){
$this->terrestres[] = $plan[$ter];
}
$this->file_ter = explode(';', $plan["file_ter"]);
foreach($nomvaisnVAR as $vais){
$this->vaisseaux[] = $plan[$vais];
}
$this->file_vais = explode(';', $plan["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){
//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");
$this->file_pret("technologies");
$this->file_pret("casernes");
$this->file_pret("terrestres");
$this->file_pret("vaisseaux");
}
//Calcul du nombre de cases restantes
$this->casesRest = $this->cases;
foreach($this->batiments as $bat){
$this->casesRest -= $bat;
}
}
/**
* Vérifie si la planète est isolée ou non
*
* @return boolean
* @access public
*/
function isolement(){
$isolement = explode(' ', $this->isolement);
$return = false;
if (time() > $isolement[0]) {
if (!isset($isolement[1]) || (time() > $isolement[1] && date('dmY') != date('dmY', $isolement[0]))) {
$nbPlan = count($queryPlanetes);
$numP = 0;
for ($i=0 ; $i<$nbPlan ; $i++) {
if ($queryPlanetes[$i]['id'] == $queryPlanete['id']) $numP = $i;
}
if ($numP > 10) {
switch($numP){
case 11: $tps = 2; break;
case 12: $tps = 4; break;
case 13: $tps = 6; break;
case 14: $tps = 8; break;
case 15: $tps = 12; break;
case 16: $tps = 16; break;
case 17: $tps = 20; break;
default: $tps = 24;
}
$debut = mktime(rand(0, 24-$tps), 0, 0, date('n'), date('j'), date('Y'));
$fin = $debut + $tps * 3600;
$bdd->connexion();
$bdd->query("UPDATE $table_planete SET isolement = '$debut $fin' WHERE id = '$idPlan';");
$bdd->deconnexion();
$isolement[0] = $debut;
if (time() > $isolement[0]) $isolement[1] = $fin;
}
}
$p = gpc('p');
if (isset($isolement[1]) && time() < $isolement[1]) {
$return = true;
}
}
$this->isolement = implode(' ', $isolement);
if (!in_array('isolement', $this->modif)) $this->modif[] = 'isolement';
return $return;
}
/**
* Calcul les ressources produites en fonction de $temps_ecoule
* @param int $temps_ecoule Temps écoulé depuis la dernière actualisation
*
* @return array
* @access public
*/
function production($temps_ecoule, $retarray = false){
//Accélération de la production
$temps_ecoule *= 10;
//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;
if ($this->batiments[1] > 0) $energie_c = ceil(exp(0.28*$this->batiments[1])*10); else $energie_c = 0;
if ($this->batiments[2] > 0) $energie_h = ceil(exp(0.2849*$this->batiments[2])*13); else $energie_h = 0;
if ($this->batiments[3] > 0) $energie_s = ceil(exp(0.28*$this->batiments[3])*22); else $energie_s = 0;
if ($this->batiments[4] > 0) $energie_f = ceil(exp(0.297*$this->batiments[4])*25); else $energie_f = 0;
//Calcul de la consomation d'énergie
$this->energieConso = $energie_m * $this->coeff_bat[0] + $energie_c * $this->coeff_bat[1] + $energie_h * $this->coeff_bat[2];
$nrjmx = $energie_m + $energie_c + $energie_h;
//Calcul de la production d'énergie
$this->energie = $energie_s * $this->coeff_bat[3] + $energie_f * $this->coeff_bat[4];
if ($this->energieConso == 0) $coeff = 0;
else $coeff = $this->energie / $this->energieConso;
if ($coeff < 0) $coeff = 0;
elseif ($coeff > 1) $coeff = 1;
$Ncoeff = array();
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]) {
$this->coeff_bat[$i] = $Ncoeff[$i];
if (!in_array('coeff_bat', $this->modif)) $this->modif[] = 'coeff_bat';
}
}
//Calcul de la consomation d'hydrogène
if ($this->batiments[4] > 0) $conso_h = ((ceil(pow(1.34,($this->batiments[4]-1))*9)/3600)*$temps_ecoule) * $this->coeff_bat[4];
else $conso_h = 0;
//Calcul des production de ressources
if ($this->batiments[0] <= 0 || $this->batiments[3] <= 0) $prod_met = 0.011 * $temps_ecoule;
else $prod_met = ((ceil(pow(1.1, $this->batiments[0]) * 35 * $this->batiments[0]) / 3600) * $temps_ecoule) * $this->coeff_bat[0] * 1.5;
if ($this->batiments[1] <= 0 || $this->batiments[3] <= 0) $prod_cri = 0.0055 * $temps_ecoule;
else $prod_cri = ((ceil(pow(1.1, $this->batiments[1]) * 23 * $this->batiments[1]) / 3600) * $temps_ecoule) * $this->coeff_bat[1] * 1.5;
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;
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
*
* @return void
* @access public
*/
function __destruct(){
global $var___db, $config, $table_planete;
$nb = count($this->modif);
$out = array();
$bdd = new bdd();
$bdd->connexion();
for($i = 0; $i < $nb; $i++){
if ($this->modif[$i] == 'technologies') $this->modifUser[] = $this->modif[$i];
elseif (!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 = implode(';', $this->{$this->modif[$i]});
$bdd->escape($prep);
$out[] .= $this->modif[$i]." = '$prep'";
}
else {
if ($this->modif[$i] == "batiments") $calc = "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_planete SET ".implode(', ', $out)." WHERE id = ".$this->id.";");
$bdd->deconnexion();
parent::__destruct();
}
}
?>

View file

@ -0,0 +1,357 @@
<?php
/**
* Class Rapport
*
* Génération et envoie de rapport de mission de flotte
*
*/
class Rapport{
var $table = 'mail';
var $type = 0;
var $var = array();
var $utilA = 0;
var $utilB = 0;
var $timestamp = 0;
var $basededonnes;
/**
* Constructor
* @access protected
*/
function Rapport($type, $utilA, $utilB, $time){
global $table_mail;
$this->table = $table_mail;
$this->type = $type;
$this->utilA = $utilA;
$this->utilB = $utilB;
$this->timestamp = $time;
$this->basededonnes = new bdd();
}
function addInfo($info, $id){
$this->var[$id] = $info;
}
function send(){
if ($this->type == '1') $this->sendCombat();
elseif ($this->type == '2') $this->sendTransport();
elseif ($this->type == '3') $this->sendColonisation();
elseif ($this->type == '4') $this->sendRecyclage();
elseif ($this->type == '5') $this->sendEspionnage();
elseif ($this->type == '6') $this->sendAlliance();
elseif ($this->type == '7') $this->sendAlliance2();
}
function sendEspionnage(){
global $config;
include_once(_FCORE."../game/function.php");
$titreA = 'Rapport d\'espionnage de '.$this->var[0]['nom_planete'].' ['.$this->var[0]['galaxie'].':'.$this->var[0]['ss'].':'.$this->var[0]['position'].']';
$rapportA = '<b>Espionnage de '.trouvNom($this->utilB).' sur '.$this->var[0]['nom_planete'].'['.$this->var[0]['galaxie'].':'.$this->var[0]['ss'].':'.$this->var[0]['position'].']</b><br /><br />';
$race = trouvInfo($this->utilB, 'race');
$auth_level = 0;
include(_FCORE."../game/noms.php");
include(_FCORE."../game/vars.php");
if (isset($this->var[1]) && $this->var[1] == false) $rapportA .= '<i>Nos sondes n\'ont pas pu récolter d\'information sur cette planète.</i>';
else {
$rapportA .= '<table style="margin: auto;"><tr><th colspan="2">Ressources sur la planète :</th></tr><tr><td>Métal :</td><td>'.$this->var[0]['metal'].'</td></tr><tr><td>Cristal :</td><td>'.$this->var[0]['cristal'].'</td></tr><tr><td>Hydrogène :</td><td>'.$this->var[0]['hydrogene'].'</td></tr></table><br />';
if (isset($this->var[1]) && $this->var[1] == true) {
$rapportA .= '<table style="margin: auto;"><tr><th>Nombre</th><th>Vaisseaux</th></tr>';
$nbvais = count($nomvaisn);
for($i=1 ; $i<$nbvais ; $i++) {
if ($this->var[0]['vaisseau_'.$i] >= 1) $rapportA .= '<tr><td>'.$this->var[0]['vaisseau_'.$i].'</td><td>'.$nomvaisn[$i-1].'</td></tr>';
}
$rapportA .= '</table><br />';
}
if (isset($this->var[2]) && $this->var[2] == true) {
$rapportA .= '<table style="margin: auto;"><tr><th>Nombre</th><th>Défenses</th></tr>';
$nbdef = count($nomterrn) - 7;
for($i=1 ; $i<$nbdef ; $i++) {
if ($this->var[0]['def_'.$i] >= 1) $rapportA .= '<tr><td>'.$this->var[0]['def_'.$i].'</td><td>'.$nomterrn[$i+7].'</td></tr>';
}
$rapportA .= '</table><br />';
}
if (isset($this->var[3]) && $this->var[3] == true) {
$rapportA .= '<table style="margin: auto;"><tr><th>Niveau</th><th>Batiment</th></tr>';
$nbbat = count($batiment);
for($i=1 ; $i<$nbbat ; $i++) {
if ($this->var[0][$batimentVAR[$i-1]] >= 1) $rapportA .= '<tr><td>'.$this->var[0][$batimentVAR[$i-1]].'</td><td>'.$batiment[$i-1].'</td></tr>';
}
$rapportA .= '</table><br />';
}
if (isset($this->var[4]) && is_array($this->var[4])) {
$rapportA .= '<table style="margin: auto;"><tr><th>Niveau</th><th>Technologie</th></tr>';
$nbtec = count($technolo);
for($i=1 ; $i<$nbtec ; $i++) {
if ($this->var[4][$technoloVAR[$i-1]] >= 1) $rapportA .= '<tr><td>'.$this->var[4][$technoloVAR[$i-1]].'</td><td>'.$technolo[$i-1].'</td></tr>';
}
$rapportA .= '</table><br />';
}
if (isset($this->var[5]) && is_array($this->var[5])) {
//ISOLEMENT
}
}
$titreB = 'Rapport de contre-espionnage';
$rapportB = 'Nous venons d\'apprendre que notre planète : '.$this->var[0]['nom_planete'].'['.$this->var[0]['galaxie'].':'.$this->var[0]['ss'].':'.$this->var[0]['position'].'] a été la cible d\'un espionnage de la part de '.trouvNom($this->utilA);
$temps = $this->timestamp;
$db = new bdd();
$db->connexion();
$db->escape($titreA);
$db->escape($titreB);
$db->escape($rapportA);
$db->escape($rapportB);
$db->query("INSERT INTO ".$this->table." (destinataire, sujet, contenu, temps) VALUES(".$this->utilA.", '$titreA', '$rapportA', '$temps')");
$db->query("INSERT INTO ".$this->table." (destinataire, sujet, contenu, temps) VALUES(".$this->utilB.", '$titreB', '$rapportB', '$temps')");
$db->deconnexion();
}
function sendTransport(){
global $config;
include_once(_FCORE."../game/function.php");
$titre = 'Transport vers '.$this->var[0]['nom_planete'].' ['.$this->var[0]['galaxie'].':'.$this->var[0]['ss'].':'.$this->var[0]['position'].']';
$race = trouvInfo($this->utilA, 'race');
include(_FCORE."../game/noms.php");
$rapportA = 'Vos vaisseaux ont déposé '.$this->var[1][0].' de '.$ressourc[0].', '.$this->var[1][1].' de '.$ressourc[1].' et '.$this->var[1][2].' d\''.$ressourc[2].' sur '.$this->var[0]['nom_planete'].'['.$this->var[0]['galaxie'].':'.$this->var[0]['ss'].':'.$this->var[0]['position'].']</b><br /><br />';
$race = trouvInfo($this->utilB, 'race');
include(_FCORE."../game/noms.php");
$rapportB = 'Les vaisseaux de '.trouvNom($this->utilA).' ont déposé '.$this->var[1][0].' de '.$ressourc[0].', '.$this->var[1][1].' de '.$ressourc[1].' et '.$this->var[1][2].' d\''.$ressourc[2].' sur '.$this->var[0]['nom_planete'].'['.$this->var[0]['galaxie'].':'.$this->var[0]['ss'].':'.$this->var[0]['position'].']</b><br /><br />';
$temps = $this->timestamp;
$db = new bdd();
$db->connexion();
$db->escape($titre);
$db->escape($rapportA);
$db->escape($rapportB);
$db->query("INSERT INTO ".$this->table." (destinataire, sujet, contenu, temps) VALUES(".$this->utilA.", '$titre', '$rapportA', '$temps')");
if ($this->utilA != $this->utilB) $db->query("INSERT INTO ".$this->table." (destinataire, sujet, contenu, temps) VALUES(".$this->utilB.", '$titre', '$rapportB', '$temps')");
$db->deconnexion();
}
function sendColonisation(){
include_once(_FCORE."../game/function.php");
$titre = 'Colonisation de ['.$this->var[0][0].':'.$this->var[0][1].':'.$this->var[0][2].']';
if ($this->var[1]) $rapport = 'Votre vaisseau a atteint la planète ['.$this->var[0][0].':'.$this->var[0][1].':'.$this->var[0][2].'] et commence la colonisation.';
else $rapport = 'Nous n\'avons pas pu coloniser la planète ['.$this->var[0][0].':'.$this->var[0][1].':'.$this->var[0][2].'] car lorsque nous sommes arrivé sur place, elle était déjà colonisée.';
$temps = $this->timestamp;
$db = new bdd();
$db->connexion();
$db->escape($titre);
$db->escape($rapport);
$db->query("INSERT INTO ".$this->table." (destinataire, sujet, contenu, temps) VALUES(".$this->utilA.", '$titre', '$rapport', '$temps')");
$db->deconnexion();
}
function sendRecyclage(){
include_once(_FCORE."../game/function.php");
$titre = 'Recyclage de '.$this->var[0]['nom_planete'].' ['.$this->var[0]['galaxie'].':'.$this->var[0]['ss'].':'.$this->var[0]['position'].']';
$rapport = 'Vos vaisseaux récoltent '.$this->var[1][0].' de '.$ressourc[0].' et '.$this->var[1][1].' de '.$ressourc[1].' sur '.$this->var[0]['nom_planete'].'['.$this->var[0]['galaxie'].':'.$this->var[0]['ss'].':'.$this->var[0]['position'].']</b><br /><br />';
$temps = $this->timestamp;
$db = new bdd();
$db->connexion();
$db->escape($titre);
$db->escape($rapport);
$db->query("INSERT INTO ".$this->table." (destinataire, sujet, contenu, temps) VALUES(".$this->utilA.", '$titre', '$rapport', '$temps')");
$db->deconnexion();
}
function sendCombat(){
include(_FCORE."../game/vars.php");
include_once(_FCORE."../game/function.php");
require_once(SMARTY_DIR."Smarty.class.php");
$rapportA = new Smarty();
$rapportB = new Smarty();
$rapportA->template_dir = _FCORE.'templates/templates/';
$rapportA->compile_dir = _FCORE.'templates/templates_c/';
$rapportA->config_dir = _FCORE.'templates/configs/';
$rapportA->cache_dir = _FCORE.'templates/cache/';
$rapportB->template_dir = _FCORE.'templates/templates/';
$rapportB->compile_dir = _FCORE.'templates/templates_c/';
$rapportB->config_dir = _FCORE.'templates/configs/';
$rapportB->cache_dir = _FCORE.'templates/cache/';
$this->var[4]['pseudo'] = trouvNom($this->var[4]['id_user']);
$this->var[5]['pseudo'] = trouvNom($this->var[5]['id_user']);
$rapportA->assign('tour', $this->var[3]);
$rapportA->assign('EN', $this->var[4]);
$rapportA->assign('flotte', $this->var[5]);
$rapportA->assign('vaisseaux1', $this->var[0]);
$rapportA->assign('vaisseaux2', $this->var[1]);
$rapportA->assign('defenses1', $this->var[2]);
$rapportA->assign('vaisseaux3', $this->var[7]);
$rapportA->assign('vaisseaux4', $this->var[8]);
$rapportA->assign('defenses2', $this->var[9]);
$rapportA->assign('termine', $this->var[6][0]);
$rapportA->assign('attaquantG', $this->var[6][1]);
$rapportA->assign('pillage', $this->var[11]);
$rapportA->assign('vaisBC', $nomvais_bc);
$rapportA->assign('vaisPV', $nomvais_pv);
$rapportA->assign('defBC', $defense_bc);
$rapportA->assign('defPV', $defense_pv);
$rapportA->assign('nextTour', $this->var[10]);
$race = trouvInfo($this->utilA, 'race');
include(_FCORE."../game/noms.php");
$rapportA->assign('ressources', $ressourc);
$rapportA->assign('nomvaisAT', $nomvaisa);
$race = trouvInfo($this->var[4]['id_user'], 'race');
include(_FCORE."../game/noms.php");
$rapportA->assign('nomvaisEN', $nomvaisa);
array_splice($nomterra, 0, 8);
$rapportA->assign('nomdefEN', $nomterra);
$rapportA = $rapportA->fetch('game/ATrapport_combat.tpl');
$rapportB->assign('tour', $this->var[3]);
$rapportB->assign('EN', $this->var[4]);
$rapportB->assign('flotte', $this->var[5]);
$rapportB->assign('vaisseaux1', $this->var[0]);
$rapportB->assign('vaisseaux2', $this->var[1]);
$rapportB->assign('defenses1', $this->var[2]);
$rapportB->assign('vaisseaux3', $this->var[7]);
$rapportB->assign('vaisseaux4', $this->var[8]);
$rapportB->assign('defenses2', $this->var[9]);
$rapportB->assign('termine', $this->var[6][0]);
$rapportB->assign('attaquantG', $this->var[6][1]);
$rapportB->assign('matchnul', $this->var[6][2]);
$rapportB->assign('pillage', $this->var[11]);
$rapportB->assign('vaisBC', $nomvais_bc);
$rapportB->assign('vaisPV', $nomvais_pv);
$rapportB->assign('defBC', $defense_bc);
$rapportB->assign('defPV', $defense_pv);
$rapportB->assign('nextTour', $this->var[10]);
$race = trouvInfo($this->utilA, 'race');
include(_FCORE."../game/noms.php");
$rapportB->assign('ressources', $ressourc);
$rapportB->assign('nomvaisAT', $nomvaisa);
$race = trouvInfo($this->var[4]['id_user'], 'race');
include(_FCORE."../game/noms.php");
$rapportB->assign('nomvaisEN', $nomvaisa);
array_splice($nomterra, 0, 8);
$rapportB->assign('nomdefEN', $nomterra);
$rapportB = $rapportB->fetch('game/ENrapport_combat.tpl');
$titreA = 'Combat contre '.$this->var[4]['pseudo'];
$titreB = 'Combat contre '.$this->var[5]['pseudo'];
$temps = $this->timestamp;
$db = new bdd();
$db->connexion();
$db->escape($titreA);
$db->escape($titreB);
$db->escape($rapportA);
$db->escape($rapportB);
$db->query("INSERT INTO ".$this->table." (destinataire, sujet, contenu, temps) VALUES(".$this->utilA.", '$titreA', '$rapportA', '$temps')");
$db->query("INSERT INTO ".$this->table." (destinataire, sujet, contenu, temps) VALUES(".$this->utilB."', '$titreB', '$rapportB', '$temps')");
$db->deconnexion();
}
function show(){
include(_FCORE."../game/vars.php");
include_once(_FCORE."../game/function.php");
require_once(SMARTY_DIR."Smarty.class.php");
$rapportA = new Smarty();
$rapportA->template_dir = _FCORE.'templates/templates/';
$rapportA->compile_dir = _FCORE.'templates/templates_c/';
$rapportA->config_dir = _FCORE.'templates/configs/';
$rapportA->cache_dir = _FCORE.'templates/cache/';
$rapportA->assign('tour', $this->var[3]);
$rapportA->assign('EN', $this->var[4]);
$rapportA->assign('flotte', $this->var[5]);
$rapportA->assign('vaisseaux1', $this->var[0]);
$rapportA->assign('vaisseaux2', $this->var[1]);
$rapportA->assign('defenses1', $this->var[2]);
$rapportA->assign('vaisseaux3', $this->var[7]);
$rapportA->assign('vaisseaux4', $this->var[8]);
$rapportA->assign('defenses2', $this->var[9]);
$rapportA->assign('termine', $this->var[6][0]);
$rapportA->assign('attaquantG', $this->var[6][1]);
$rapportA->assign('pillage', $this->var[11]);
$rapportA->assign('debris', $this->var[12]);
$rapportA->assign('infoPLUS', $this->var[14]);
//$rapportA->assign('infoPLUS2', $this->var[15]);
$rapportA->assign('page', 'simulation');
$rapportA->assign('enligne', $this->var[13][0]);
$rapportA->assign('infos', $this->var[13][1]);
$rapportA->assign('nbinfos', $this->var[13][2]);
$rapportA->assign('count', $this->var[13][3]);
$rapportA->assign('version', $this->var[13][4]);
$rapportA->assign('tpsdejeu', $this->var[13][5]);
$rapportA->assign('vaisBC', $nomvais_bc);
$rapportA->assign('vaisPV', $nomvais_pv);
$rapportA->assign('defBC', $defense_bc);
$rapportA->assign('defPV', $defense_pv);
$rapportA->assign('nextTour', $this->var[10]);
$race = trouvInfo($this->utilA, 'race');
include(_FCORE."../game/noms.php");
$rapportA->assign('ressources', $ressourc);
$rapportA->assign('nomvaisAT', $nomvaisa);
$rapportA->assign('nomvaisEN', $nomvaisa);
array_splice($nomterra, 0, 8);
$rapportA->assign('nomdefEN', $nomterra);
$rapportA->assign('race', $race);
return $rapportA->fetch('game/SIMrapport_combat.tpl');
return $rapportA;
}
function sendAlliance(){
include_once(_FCORE."../game/function.php");
$titreA = 'Déclaration officielle de votre alliance !';
$rapportA = 'Félicitations, votre alliance a recueilli suffisament de signature, sa déclaration est maintenant officielle !<br /><br />Vous pouvez dès maintenant administrer votre alliance en vous rendant sur la page Alliance.';
$temps = $this->timestamp;
$db = new bdd();
$db->connexion();
$db->escape($titreA);
$db->escape($rapportA);
$db->query("INSERT INTO ".$this->table." (destinataire, sujet, contenu, temps) VALUES(".$this->utilA.", '$titreA', '$rapportA', '$temps')");
$db->deconnexion();
}
function sendAlliance2(){
include_once(_FCORE."../game/function.php");
$titreA = 'Fondation de votre alliance !';
$rapportA = 'Pour terminer la création de votre alliance, trouvez 4 joueurs de cette galaxie sans alliance pour leur faire signer votre traité de fondation d\'alliance.<br /><br />Lien de signature : <a href="?p=alliances&amp;q=signer&amp;i='.$this->var[0].'">http://'.$_SERVER['HTTP_HOST'].'/?p=alliances&amp;q=signer&amp;i='.$this->var[0].'</a>';
$temps = $this->timestamp;
$db = new bdd();
$db->connexion();
$db->escape($titreA);
$db->escape($rapportA);
$db->query("INSERT INTO ".$this->table." (destinataire, sujet, contenu, temps) VALUES(".$this->utilA.", '$titreA', '$rapportA', '$temps')");
$db->deconnexion();
}
}
?>

1039
game/Class/class.smtp.php Normal file

File diff suppressed because it is too large Load diff

108
game/Class/class.user.php Normal file
View file

@ -0,0 +1,108 @@
<?php
/***************************************************************************
* class.user.php
* ----------------
* begin : Dimanche 7 septembre 2008
* update : Dimanche 7 septembre 2008
* email : nemunaire@gmail.com
*
*
***************************************************************************/
class User{
var $id_user,
$pseudo,
$auth_level,
$race,
$id_alliance,
$id_grade_alliance,
$mail,
$envoyerMail,
$technologies = array(),
$destinationsFavoris,
$amis,
$combatAT_tactique,
$combatDE_tactique,
$modifUser = array();
/**
* Constructeur
* @param int $id id de la planète à importer
*
* @return void
* @access public
*/
function User($id = 0){
if (!empty($id)) {
global $var___db, $config, $table_user;
global $technoloVAR;
$bdd = new bdd();
$bdd->connexion();
$bdd->escape($id);
$user = $bdd->unique_query("SELECT * FROM $table_user WHERE id = $id;");
$bdd->deconnexion();
if (!empty($user)) {
$this->id_user = $user["id"];
$this->pseudo = $user["pseudo"];
$this->auth_level = $user["auth_level"];
$this->race = $user["race"];
$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->combatAT_tactique = $user["combatAT_tactique"];
$this->combatDE_tactique = $user["combatDE_tactique"];
foreach($technoloVAR as $tech){
$this->technologies[] = $user[$tech];
}
}
}
}
/**
* Destructeur
*
* @return void
* @access public
*/
function __destruct(){
global $var___db, $config, $table_user;
$nb = count($this->modifUser);
$out = array();
$bdd = new bdd();
$bdd->connexion();
for($i = 0; $i < $nb; $i++){
if (!is_array($this->{$this->modifUser[$i]})) {
$bdd->escape($this->{$this->modifUser[$i]});
if (is_int($this->{$this->modifUser[$i]}) || is_float($this->{$this->modifUser[$i]})) $out[] .= $this->modifUser[$i]." = ".$this->{$this->modifUser[$i]};
else $out[] .= $this->modifUser[$i]." = '".$this->{$this->modifUser[$i]}."'";
}
else {
if (ereg('file', $this->modifUser[$i])) {
$prep = implode(';', $this->{$this->modifUser[$i]});
$bdd->escape($prep);
$out[] .= $this->modifUser[$i]." = '$prep'";
}
else {
if ($this->modifUser[$i] == "batiments") $calc = "batiment";
elseif ($this->modifUser[$i] == "technologies") $calc = "technolo";
elseif ($this->modifUser[$i] == "casernes")$calc = "casernen";
elseif ($this->modifUser[$i] == "terrestres") $calc = "nomterrn";
elseif ($this->modifUser[$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->modifUser[$i]}[$j]);
$out[] .= ${$calc.'VAR'}[$j]." = ".$this->{$this->modifUser[$i]}[$j];
}
}
}
}
if (!empty($out)) $plan = $bdd->unique_query("UPDATE $table_user SET ".implode(', ', $out)." WHERE id = ".$this->id_user.";");
$bdd->deconnexion();
}
}
?>

View file

@ -0,0 +1,118 @@
<?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;
}
}
?>

View file

@ -0,0 +1,23 @@
<?php
/**
* PHPMailer language file.
* English Version
*/
$PHPMAILER_LANG = array();
$PHPMAILER_LANG["provide_address"] = 'You must provide at least one ' .
'recipient email address.';
$PHPMAILER_LANG["mailer_not_supported"] = ' mailer is not supported.';
$PHPMAILER_LANG["execute"] = 'Could not execute: ';
$PHPMAILER_LANG["instantiate"] = 'Could not instantiate mail function.';
$PHPMAILER_LANG["authenticate"] = 'SMTP Error: Could not authenticate.';
$PHPMAILER_LANG["from_failed"] = 'The following From address failed: ';
$PHPMAILER_LANG["recipients_failed"] = 'Erreur SMTP: The following ' .
'recipients failed: ';
$PHPMAILER_LANG["data_not_accepted"] = 'Erreur SMTP: Données non acceptées.';
$PHPMAILER_LANG["connect_host"] = 'Erreur SMTP: Impossible de se connecter au serveur de mail.';
$PHPMAILER_LANG["file_access"] = 'Accès au fichier impossible: ';
$PHPMAILER_LANG["file_open"] = 'File Error: Ne peut ouvrir le fichier: ';
$PHPMAILER_LANG["encoding"] = 'Type d\'encodage inconnu : ';
?>