"faible", "intermediaire", "puissant");
$type = $types[$type];
$query = "/objets/";
$percent = rand(1, 100);
$xml = simplexml_load_file('xml/obm.xml');
$cats = $xml->xpath("/objets/*/".$type."[@min<='".$percent."' and @max>='".$percent."']/parent::*");
//$cats = $xml->xpath("/objets/anneaux");
$percent = rand(1, 100);
$cat = "";
switch ($cats[0]->getName()) {
case "armes": $item = getWeapon($type, $xml); break;
case "armures": $item = getArmor($type, $xml); break;
case "parchemins": $item = getScroll($type, $xml); break;
case "objets_merveilleux": $query .= $cats[0]->getName()."/*/" . $type . "/parent::*";
$item = ($xml->xpath($query));
$item = array($item[rand(0, count($item)-1)]);
//$item[0]->nom = "".$item[0]->nom."";
$item = array(@sprintf(' %s%s', utf8_decode($cat), utf8_decode($item[0]->nom)), @sprintf('%s', $item[0]->valeur));
break;
default: $query .= $cats[0]->getName()."/*/" . $type . "/parent::*";
$item = ($xml->xpath($query));
$item = array($item[rand(0, count($item)-1)]);
$cat = $item[0]->getName()." ";
$pos = strpos($item[0]->nom, "%opt");
if ($pos !== false) {
$opts = $item[0]->options->option;
//echo $opts[rand(1, count($opts))-1]."
";
$item[0]->nom = str_replace("%opt", $opts[rand(1, count($opts))-1], $item[0]->nom);
}
$item = array(@sprintf(' %s%s', utf8_decode($cat), utf8_decode($item[0]->nom)), @sprintf('%s', $item[0]->valeur));/**/
}
return $item;
}
function getScroll($type, $xml)
{
$type_sort = (rand(1, 100) > 70 ? "divin" : "profane");
$nbr = ($type == "faible" ? rand(1, 3) : ($type == "puissant" ? rand(1, 6) : rand(1, 4)));
$valeur = 0;
$nom = " Parchemin ".$type_sort." (";
for ($i=0; $i<$nbr; $i++) {
$percent = rand(1, 100);
$lvl = 0;
switch ($type) {
case "faible": switch ($percent) {
case ($percent < 6): $lvl = 0; break;
case ($percent < 51): $lvl = 1; break;
case ($percent < 96): $lvl = 2; break;
default: $lvl = 3;
}break;
case "intermediaire": switch ($percent) {
case ($percent < 6): $lvl = 2; break;
case ($percent < 66): $lvl = 3; break;
case ($percent < 96): $lvl = 4; break;
default: $lvl = 5;
}break;
default: switch ($percent) {
case ($percent < 6): $lvl = 4; break;
case ($percent < 51): $lvl = 5; break;
case ($percent < 71): $lvl = 6; break;
case ($percent < 86): $lvl = 7; break;
case ($percent < 96): $lvl = 8; break;
default: $lvl = 9;
}
}
$item = $xml->xpath("/objets/Sorts/".$type_sort."/lvl".$lvl."/*");
if (count($item) > 0) {
$id = rand(1, count($item))-1;
$nom .= ($i==0 ? "" : ", ").$item[$id]->nom." (".$lvl.")";
$valeur += $item[$id]->valeur;
} else {
$nom .= ($i==0 ? "" : ", ")."Un sort (".$lvl.")";
}
}
return array(utf8_decode($nom).")", $valeur);
}
function getWeapon($type, $xml)
{
$base_type = rand(1, 100);
$percent = rand(1, 100);
$base_type = $xml->xpath("/objets/armes/base/*[@min<='".$base_type."' and @max>='".$base_type."']/*[@min<='".$percent."' and @max>='".$percent."']");
$base = $base_type[0];
$base_type = ($base[0]->dist ? "ranged" : "melee");
$properties = array();
do {
$percent = rand(1, 100);
switch ($type) {
case "faible": switch ($percent) {
case ($percent < 71): $property = array("nom"=>"+1", "mod"=>1); break;
case ($percent < 86): $property = array("nom"=>"+2", "mod"=>2); break;
case ($percent < 91): $property = array("nom"=>"*", "mod"=>-1); break;
default: $property = array("nom"=>"*", "mod"=>0);
}break;
case "intermediaire": switch ($percent) {
case ($percent < 11): $property = array("nom"=>"+1", "mod"=>1); break;
case ($percent < 30): $property = array("nom"=>"+2", "mod"=>2); break;
case ($percent < 59): $property = array("nom"=>"+3", "mod"=>3); break;
case ($percent < 63): $property = array("nom"=>"+4", "mod"=>4); break;
case ($percent < 69): $property = array("nom"=>"*", "mod"=>-1); break;
default: $property = array("nom"=>"*", "mod"=>0);
}break;
default: switch ($percent) {
case ($percent < 21): $property = array("nom"=>"+3", "mod"=>3); break;
case ($percent < 39): $property = array("nom"=>"+4", "mod"=>4); break;
case ($percent < 50): $property = array("nom"=>"+5", "mod"=>5); break;
case ($percent < 64): $property = array("nom"=>"*", "mod"=>-1); break;
default: $property = array("nom"=>"*", "mod"=>0);
}
}
if ($property["mod"]==0) {
$properties = getWeaponProperties($type, $base, $base_type, $xml, $properties);
}
} while ($property["mod"]==0);
if ($property["mod"]<0) {
//Arme spécifique
$percent = rand(1, 100);
$spec = $base->xpath("/objets/armes/spec/arme/".$type."[@min<='".$percent."' and @max>='".$percent."']/parent::*");
$nom = $spec[0]->nom;
$valeur = $spec[0]->valeur;
} else {
/*print_r($base);
print_r($property);*/
/*print_r($properties);
echo "