"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 "
";/**/ if ($base->nom == "Munitions") { $percent = rand (1, 100); $base->nom = ($percent < 21 ? "Billes" : ($percent < 51 ? "Carreaux" : "Flèches")." (50)"); } $nom = $base->nom." ".$property["nom"]; foreach ($properties as $value) { /*print_r($value); echo "
";/**/ $nom .= " ".$value[0]; //echo $nom." : ".$value[1]."
"; $property["mod"]+=$value[1]; } //echo "
"; $valeur = $base->valeur + ($property["mod"] * $property["mod"] * 2000); } return array(" ".utf8_decode($nom), $valeur); } function getArmor($type, $xml) { $percent = rand (1,100); $base_type = $xml->xpath("/objets/armures/base/*/*[@min<='".$percent."' and @max>='".$percent."']"); //print_r($base_type); echo "
"; $base = $base_type[rand(0,1)]; $base_type = $base->xpath("parent::*"); $base_type = $base_type[0]->getName(); //echo $base_type."
"; $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 = getArmorProperties($type, $base, $base_type, $xml, $properties); } while($property["mod"]==0); if ($property["mod"]<0) { //Armure spécifique $percent = rand (1, 100); $spec = $base->xpath("/objets/armures/spec/".$base_type."/*/".$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 "
";/**/ $nom = $base->nom." ".$property["nom"]; foreach ($properties as $value) { $nom .= " ".$value[0]; $base->valeur+=$value[1]; $property["mod"]+=$value[2]; } $valeur = $base->valeur + ($property["mod"] * $property["mod"] * 1000); } return array(" ".utf8_decode($nom), $valeur); } function getWeaponProperties($type, $base, $base_type, $xml, $properties = array()) { $percent = rand(1, 100); //echo $type." ".$base_type." ".$percent."
"; $prop = $xml->xpath("/objets/armes/prop/".$base_type."/property/".$type."[@min<='".$percent."' and @max>='".$percent."']/parent::*"); //print_r($prop[0]); echo "
"; if ($prop[0]->mod == 0) { $properties = getWeaponProperties($type, $base, $base_type, $xml, $properties); $properties = getWeaponProperties($type, $base, $base_type, $xml, $properties); } else { $pos = strpos($prop[0]->nom, "%kill"); if ($pos !== false) { $percent = rand(1, 100); $kills = $xml->xpath("/objets/armes/kill/enemy[@min<='".$percent."' and @max>='".$percent."']"); //print_r($kills); echo "
"; $prop[0]->nom = str_replace("%kill", $kills[0], $prop[0]->nom); } $nom = $prop[0]->nom; $replay = false; foreach ($properties as $vector) if ($vector[0]==$nom) $replay=true; if ($replay) $properties[] = getWeaponProperties($type, $base, $base_type, $xml, $properties); else $properties[] = array($prop[0]->nom, $prop[0]->mod); } //print_r ($prop); echo "
"; //print_r ($base); echo "
"; return $properties; } function getArmorProperties($type, $base, $base_type, $xml, $properties = array()) { $percent = rand(1, 100); //echo $type." ".$base_type." ".$percent."
"; $prop = $xml->xpath("/objets/armures/prop/".$base_type."/property/".$type."[@min<='".$percent."' and @max>='".$percent."']/parent::*"); //print_r($prop[0]); echo "
"; if ($prop[0]->mod == 0 && $prop[0]->valeur == 0) { $properties = getArmorProperties($type, $base, $base_type, $xml, $properties); $properties = getArmorProperties($type, $base, $base_type, $xml, $properties); } else { $nom = $prop[0]->nom; $replay = false; foreach ($properties as $vector) if ($vector[0]==$nom) $replay=true; if ($replay) $properties[] = getArmorProperties($type, $base, $base_type, $xml, $properties); else $properties[] = array($nom, $prop[0]->valeur, $prop[0]->mod); } //print_r ($prop); echo "
"; //print_r ($base); echo "
"; return $properties; } function checkProperties() { $output = ""; $xml = simplexml_load_file('xml/obm.xml'); $obm = array("melee", "ranged"); $types = array("faible", "intermediaire", "puissant"); foreach ($obm as $o) { foreach ($types as $t) { for ($i=1; $i<=100; $i++) { $c = $xml->xpath("/objets/armes/prop/".$o."/property/".$t."[@min<='".$i."' and @max>='".$i."']/parent::*"); if (count($c)!=1) $output .= $o." ".$t." N°".$i." contient ".count($c)." entrée(s)
"; echo ($o." ".$t." N°".$i." : ".$c[0]->nom."
"); } } } return $output; } function checkMagical() { $output = ""; $xml = simplexml_load_file('xml/obm.xml'); $obm = array("anneaux", "baguettes", "potions"); $obm2 = array("bâtons", "sceptres"); $types = array("faible", "intermediaire", "puissant"); $types2 = array("intermediaire", "puissant"); foreach ($obm as $o) { foreach ($types as $t) { for ($i=1; $i<=100; $i++) { $c = $xml->xpath("/objets/".$o."/*/".$t."[@min<='".$i."' and @max>='".$i."']/parent::*"); if (count($c)!=1) $output .= $o." ".$t." N°".$i." contient ".count($c)." entrée(s)
"; echo ($o." ".$t." N°".$i." : ".$c[0]->nom."
"); } } } foreach ($obm2 as $o) { foreach ($types2 as $t) { for ($i=1; $i<=100; $i++) { $c = $xml->xpath("/objets/".$o."/*/".$t."[@min<='".$i."' and @max>='".$i."']/parent::*"); if (count($c)!=1) $output .= $o." ".$t." N°".$i." contient ".count($c)." entrée(s)
"; echo ($o." ".$t." N°".$i." : ".$c[0]->nom."
"); } } } return $output; }