Version 0.10a
This commit is contained in:
parent
b9c240c781
commit
e391f66774
201 changed files with 5182 additions and 8158 deletions
278
Class/class.combat.php
Normal file
278
Class/class.combat.php
Normal file
|
|
@ -0,0 +1,278 @@
|
|||
<?php
|
||||
/***************************************************************************
|
||||
* class.combat.php
|
||||
* -------------------
|
||||
* begin : Samedi 26 janvier 2008
|
||||
* email : nemunaire@gmail.com
|
||||
*
|
||||
*
|
||||
***************************************************************************/
|
||||
|
||||
class Combat {
|
||||
var $refflotte = 0;
|
||||
var $ATvais = array();
|
||||
var $ENvais = array();
|
||||
var $ENdef = array();
|
||||
var $Ntour = 0;
|
||||
var $ATtactique = 0;
|
||||
var $ENtactique = 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) {
|
||||
include('includes/vars.php');
|
||||
//Génération des vaisseaux attaquants
|
||||
for ($i=1 ; $i<=12 ; $i++) {
|
||||
if ($flotteAT['vaisseau'.$i] >= 1) {
|
||||
$this->ATvais[] = array($i, $flotteAT['vaisseau'.$i], array(array($nomvais_pv[$i-1], $flotteAT['vaisseau'.$i])), array(array($nomvais_bc[$i-1], $flotteAT['vaisseau'.$i])));
|
||||
}
|
||||
}
|
||||
|
||||
//Génération des vaisseaux défenseurs
|
||||
for ($i=1 ; $i<=12 ; $i++) {
|
||||
if ($flotteEN['vaisseau_'.$i] >= 1) {
|
||||
$this->ENvais[] = array($i, $flotteEN['vaisseau_'.$i], array(array($nomvais_pv[$i-1], $flotteEN['vaisseau_'.$i])), array(array($nomvais_bc[$i-1], $flotteEN['vaisseau_'.$i])));
|
||||
}
|
||||
}
|
||||
|
||||
//Génération des défenses défenseurs
|
||||
for ($i=1 ; $i<=5 ; $i++) {
|
||||
if ($defEN['def_'.$i] >= 1) {
|
||||
$this->ENdef[] = array($i, $defEN['def_'.$i], array(array($nomvais_pv[$i-1], $defEN['def_'.$i])), array(array($nomvais_bc[$i-1], $defEN['def_'.$i])));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 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
|
||||
*
|
||||
* @return float pourcentage non utilisé
|
||||
* @access public
|
||||
*/
|
||||
function regenereBC($pourcentage, $attaquant, $retour = false) {
|
||||
include('includes/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];
|
||||
$ajout = $maxbc*$pourcentage/100;
|
||||
$norm += $maxbc * $this->ATvais[$i][1];
|
||||
|
||||
$cntbc = count($this->ATvais[$i][3]);
|
||||
for ($j=0 ; $j<$cntbc ; $j++) {
|
||||
if ($this->ATvais[$i][3][$j][0] < $maxbc) {
|
||||
$this->ATvais[$i][3][$j][0] += $ajout;
|
||||
}
|
||||
else $enplus += $ajout * $this->ATvais[$i][3][$j][1];
|
||||
if ($this->ATvais[$i][3][$j][0] > $maxbc) {
|
||||
$enplus += ($this->ATvais[$i][3][$j][0] - $maxbc)*$this->ATvais[$i][3][$j][1];
|
||||
$this->ATvais[$i][3][$j][0] = $maxbc;
|
||||
}
|
||||
}
|
||||
}
|
||||
if ($retour) {
|
||||
if($enplus/$norm == 1) return true;
|
||||
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];
|
||||
$ajout = $maxbc*$pourcentage/100;
|
||||
$norm += $maxbc * $this->ENvais[$i][1];
|
||||
|
||||
$cntbc = count($this->ENvais[$i][3]);
|
||||
for ($j=0 ; $j<$cntbc ; $j++) {
|
||||
if ($this->ENvais[$i][3][$j][0] < $maxbc) {
|
||||
$this->ENvais[$i][3][$j][0] += $ajout;
|
||||
}
|
||||
else $enplus += $ajout * $this->ENvais[$i][3][$j][1];
|
||||
if ($this->ENvais[$i][3][$j][0] > $maxbc) {
|
||||
$enplus += ($this->ENvais[$i][3][$j][0] - $maxbc)*$this->ENvais[$i][3][$j][1];
|
||||
$this->ENvais[$i][3][$j][0] = $maxbc;
|
||||
}
|
||||
}
|
||||
}
|
||||
$return = $enplus/$norm;
|
||||
|
||||
//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];
|
||||
$ajout = $maxbc*$pourcentage/100;
|
||||
$norm += $maxbc * $this->ENdef[$i][1];
|
||||
|
||||
$cntbc = count($this->ENdef[$i][3]);
|
||||
for ($j=0 ; $j<$cntbc ; $j++) {
|
||||
if ($this->ENdef[$i][3][$j][0] < $maxbc) {
|
||||
$this->ENdef[$i][3][$j][0] += $ajout;
|
||||
}
|
||||
else $enplus += $ajout * $this->ENdef[$i][3][$j][1];
|
||||
if ($this->ENdef[$i][3][$j][0] > $maxbc) {
|
||||
$enplus += ($this->ENdef[$i][3][$j][0] - $maxbc)*$this->ENdef[$i][3][$j][1];
|
||||
$this->ENdef[$i][3][$j][0] = $maxbc;
|
||||
}
|
||||
}
|
||||
}
|
||||
$return += $enplus/$norm;
|
||||
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
|
||||
*
|
||||
* @return int points disponibles
|
||||
* @access public
|
||||
*/
|
||||
function calcAttaque($pourcentage, $attaquant) {
|
||||
include('includes/vars.php');
|
||||
if ($attaquant) {
|
||||
$puissance = 0;
|
||||
$count = count($this->ATvais);
|
||||
for ($i=0 ; $i<$count ; $i++) {
|
||||
$maxat = $nomvais_at[$this->ATvais[$i][0]-1];
|
||||
$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];
|
||||
$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];
|
||||
$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) {
|
||||
if ($attaquant) {
|
||||
while($points > 0) {
|
||||
// Calcul du nombre de vaisseaux et défenses à attaquer
|
||||
$nbvais = 0;
|
||||
$nb = count($this->ENvais);
|
||||
for ($i=0 ; $i<$nb ; $i++) {
|
||||
$nbvais += $this->ENvais[$i][1];
|
||||
}
|
||||
$nb = count($this->ENdef);
|
||||
for ($i=0 ; $i<$nb ; $i++) {
|
||||
$nbvais += $this->ENdef[$i][1];
|
||||
}
|
||||
|
||||
//S'il ne reste plus de vaisseaux et de défenses, on arrête la boucle
|
||||
if ($nbvais < 0 || $points < 0) break;
|
||||
|
||||
//Calcul du nombre de points qui sera enlevé par vaisseau ou défense
|
||||
$ppv = $points / $nbvais;
|
||||
|
||||
//On lance l'attaque
|
||||
$nb = count($this->ENvais);
|
||||
for ($i=0 ; $i<$nb ; $i++) {
|
||||
$persage = 0; //Initialisation du nombre de point restant pour attaquer les PV
|
||||
$nbpersage = 0; //Initialisation du nombre de vaisseaux affectuer par le persage
|
||||
$nbj = count($this->ENvais[$i][3]); //Nombre de vaisseaux dans le groupe
|
||||
|
||||
//Attaque des boucliers
|
||||
for ($j=0 ; $j<$nbj ; $j++) {
|
||||
$this->ENvais[$i][3][$j][0] -= $ppv;
|
||||
if ($this->ENvais[$i][3][$j][0] <= 0) {
|
||||
$persage += abs($this->ENvais[$i][3][$j][0]);
|
||||
$nbpersage += $this->ENvais[$i][3][$j][1];
|
||||
$this->ENvais[$i][3][$j][0] = 0;
|
||||
}
|
||||
}
|
||||
|
||||
//Attaque des PV
|
||||
while($persage > 0) {
|
||||
$j = count($this->ENvais[$i][2])-1; //Nombre de vaisseaux dans le groupe
|
||||
if ($this->ENvais[$i][2][$j][0] * $this->ENvais[$i][2][$j][1] < $persage * $nbpersage) { //Si il y a suffisament de point de persage pour détruire tous les vaisseaux de cette ligne
|
||||
//On efface les vaisseaux du nombre total
|
||||
$nbvais -= $this->ENvais[$i][2][$j][1];
|
||||
$this->ENvais[$i][1] -= $this->ENvais[$i][2][$j][1];
|
||||
|
||||
//On efface le groupe
|
||||
unset($this->ENvais[$i][2][$j]);
|
||||
|
||||
//S'il ne reste aucun vaisseaux du type, on le supprime
|
||||
if ($j == 0 || $this->ENvais[$i][1] == 0) {
|
||||
unset($this->ENvais[$i]);
|
||||
$persage = 0;
|
||||
}
|
||||
}
|
||||
else { //Attaque vaisseau par vaisseau dans le groupe
|
||||
$nbmod = floor(($this->ENvais[$i][2][$j][0] * $this->ENvais[$i][2][$j][1])/($persage * $nbpersage));
|
||||
$this->ENvais[$i][1] -= $nbmod;
|
||||
$nbvais -= $nbmod;
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
?>
|
||||
Loading…
Add table
Add a link
Reference in a new issue