<?php
/** ********************************************************************************************************************************************
* CLASS OVENTS
*
* @author johan <hide@address.com>
* @version 2006-01-30
* @copyright : free to use, modify...do NOT sell. If you change this file, you'd be very nice to send me your changes :-)
***********************************************************************************************************************************************/
class oevents {
/** ******************************************************************************************************
* Propriétés
********************************************************************************************************/
/** ************
* privées
**************/
private $oEvents; // objet simpleXML contenant le xml des évènements
private $sCurEvent = ''; // chaîne contenant l'évènement courant
private $aTypes = array (
'description'
);
/** ************
* constantes
**************/
const sEventDir = 'events/'; // chemin du répertoire du fichier XML des évènements
/** ******************************************************************************************************
* Constructeur
* @Params mixed fEvent : nom du fichier évènements
********************************************************************************************************/
public function __construct ($fEvent) {
if (file_exists (self::sEventDir.$fEvent)) {
$this -> oEvents = simplexml_load_file (self::sEventDir.$fEvent);
} else {
return false;
}
}
/** ******************************************************************************************************
* Méthode getEvent
* initialise l'évènement courant
* @Params array aPos : tableau des coordonnées courantes sur la map
********************************************************************************************************/
public function getEvent (array $aPos) {
$pos = 'ex'.$aPos['x'].'y'.$aPos['y'];
if (isset ($this -> oEvents -> $pos) && in_array ($this -> oEvents -> $pos -> attributes(), $this -> aTypes)) {
$this -> sCurEvent = (string)$this -> oEvents -> $pos;
}
}
/** ******************************************************************************************************
* Méthode magique __toString
* permet d'afficher l'évènement courant
* @Return string
********************************************************************************************************/
public function __toString () {
return $this -> sCurEvent;
}
/** ******************************************************************************************************
* Méthode getFight
* permet de générer ou non un combat
* @Return bool true | false
********************************************************************************************************/
public function getFight ($nb) {
$rand = mt_rand (1, 10);
if ($rand <= $nb) {
return true;
} else {
return false;
}
}
}