Location: PHPKode > projects > DarkCity > includes/SystemeDes.php
<?php
/**
 * SystemeDes.php : Gestionaire de Dès
 *
 * Date    : 31/05/2009
 * Auteur  : Philippe Bousquet
 * Version : 1.0
 * Contact : <hide@address.com>
 *
 * Copyright (c) 2008-2009 Philippe & Thierry Bousquet.
 *
 * Ce logiciel est distribué selon les termes de la GNU General Public License v2.
 */

class SystemeDes {

  var $xp_mult;
  
  function SystemeDes($xp_mult) {
    $this->xp_mult = $xp_mult;
  }
  
  function jeter($level, $bonus, $bonus2) {
    return round((rand(1, 5+$level) + $bonus) * ((10 + $bonus2) / 10));
  }

  function jeterN($nombre, $face) {
    $resultats = 0;
    for ($i = 0; $i < $nombre; $i++) {
      $resultat += $this->jeter($face-5, 0, 0);
    }
    return $resultat;
  }

/*  
  function jeterOpposition($jr_level, $jr_bonus, $jr_bonus2, $ad_level, $ad_bonus, $ad_bonus2) {
    $jr_des = $this->jeter($jr_level, $jr_bonus, $jr_bonus2);
    $ad_des = $this->jeter($ad_level, $ad_bonus, $ad_bonus2);
    //$logManager->message("D1 : ".$jr_des." D2 : ".$ad_des);
    return  $jr_des - $ad_des;
  }
*/

  function jeterOpposition($jr_level, $jr_bonus, $jr_bonus2, $ad_level, $ad_bonus, $ad_bonus2) {
    $jr_nbD6 = floor(($jr_level+5) / 6);
    $jr_DN = ($jr_level+5) % 6;
    $ad_nbD6 = floor(($ad_level+5) / 6);
    $ad_DN = ($ad_level+5) % 6;

    $jr_des = round(($this->jeterN($jr_nbD6, 6) + ($jr_DN > 0 ? $this->jeterN(1, $jr_DN) : 0) + $jr_bonus) * ((10 + $jr_bonus2) / 10));
    $ad_des = round(($this->jeterN($ad_nbD6, 6) + ($ad_DN > 0 ? $this->jeterN(1, $ad_DN) : 0) + $ad_bonus) * ((10 + $ad_bonus2) / 10));
    //$logManager->message("D1 : ".$jr_des." D2 : ".$ad_des);
    return  $jr_des - $ad_des;
  }
  
   function toString($jr_level, $jr_bonus) {
    $jr_nbD6 = floor(($jr_level+5) / 6);
    $jr_DN = ($jr_level+5) % 6;
    $des2 = "";
    $bonus = $jr_bonus;
    if ($jr_DN == 1) $bonus++;
    else if ($jr_DN == 2) $des2 = "+1D6/3";
    else if ($jr_DN == 3) $des2 = "+1D6/2";
    else if ($jr_DN == 4) $des2 = "+1D4";
    else if ($jr_DN == 5) $des2 = "+1D10/2";
    return $jr_nbD6."D6".$des2.($bonus>0 ? "+".$bonus : ($bonus<0 ? $bonus : ""));    
   }
   
/**/
  function jeterDifficulte($jr_level, $jr_bonus, $jr_bonus2, $diff) {
    $jr_des = $this->jeter($jr_level, $jr_bonus, $jr_bonus2);
    $ad_des = $this->jeter($diff-5, 0, 0);
    //$logManager->message("D1 : ".$jr_des." D2 : ".$ad_des);
    return  $jr_des - $ad_des;
  }
  
  function calculeXP($reussite, $jr_level, $op_level) {
    $temp = $reussite - (($jr_level - $op_level)/2);
    if ($temp < 1) $temp = 1;
    return  round($temp * $this->xp_mult);
  }

  
}
?>
Return current item: DarkCity