4a503405 |
<?php
define('DEBUG', FALSE);
//a faire en fonction de la variable DEBUG, avec ou sans message d'erreurs de la BDD
define('BD_ADRESSE', 'localhost');
define('BD_USER', 'root');
define('BD_PASS', '');
define('BD_NOM', 'villededragons');
function connectionBDD(){
$bdd = @mysql_connect(BD_ADRESSE,BD_USER,BD_PASS) or exit('erreur de connection...');
@mysql_select_db(BD_NOM)or exit('pb de Base de donn�es...');
}
function check_id($login,$pass){
connectionBDD();
$login = addslashes($login);
$pass = addslashes($pass);
$resultat = mysql_query("SELECT id_login FROM login WHERE login = '".$login."' AND password = '".$pass."'")or exit('Erreur ' . mysql_errno() . ' : ' . mysql_error());
if(mysql_num_rows($resultat) == 0){
$usr_id=-1;
}else{
$tableauReponse = mysql_fetch_assoc($resultat);
$usr_id = $tableauReponse['id_login'];
}
mysql_close();
return $usr_id;
}
function creation_id($login,$pass){
connectionBDD();
$login = addslashes($login);
$pass = addslashes($pass);
$date = date("Y-m-d");
mysql_query("INSERT INTO login(login,password,Date_creation) VALUES('".$login."','".$pass."','".$date."')")or exit('Erreur ' . mysql_errno() . ' : ' . mysql_error());
mysql_close();
}
function creationSorcier(){}
function existe_Log($login){
connectionBDD();
$login = addslashes($login);
$resultat = mysql_query("SELECT id_login FROM login WHERE login = '".$login."'")or exit('Erreur ' . mysql_errno() . ' : ' . mysql_error());
if(mysql_num_rows($resultat) == 0){
$existe = false;
}else{
$existe = true;
}
mysql_close();
return $existe;
}
function check_session(){
if(!session_is_registered("user_id")){
header("location: index.php");
}
}
function check_ChaineDeCaracteres($chaine){
set_magic_quotes_runtime(0);
//1er caractere en majuscule
$chaineMaj = ucfirst($chaine);
//verificatitions des balises HTML
$pos = strpos($chaineMaj,'<');
if($pos !== FALSE){
return(0);
}else{
//test sur la configuration du serveur pour l'utilisation de l'echappement avec les antiSlash
if (get_magic_quotes_gpc() == 1){
return $chaine;
}else{
$chaineBonneGuillemets = addslashes($chaine);
return ($chaineBonneGuillemets);
}
}
}
function HTML_ChaineDeCaracteres($chaine){
return (htmlspecialchars($chaine,ENT_QUOTES));
}
/****************************************************************************************************************/
/************************************** FONCTIONS PROPRES AU JEU **********************************************/
/****************************************************************************************************************/
function ChangementEnergie($nb,$retrait){
if($retrait == 0){
$_SESSION['FatigueActuelle'] += $nb;
if($_SESSION['FatigueActuelle']>$_SESSION['FatigueMax']){
$_SESSION['FatigueActuelle']=$_SESSION['FatigueMax'];
}
}else{
$_SESSION['FatigueActuelle'] -= $nb;
if($_SESSION['FatigueActuelle']<0){
$_SESSION['FatigueActuelle']=0;
header("location: fatigue.php");
}
}
}
function ChangementVie($nb,$retrait){
if($retrait == 0){
$_SESSION['VitActuelleAug'] += $nb;
$_SESSION['VitActuelle'] += $nb;
if($_SESSION['VitActuelleAug']>$_SESSION['VitAug']){
$_SESSION['VitActuelleAug']=$_SESSION['VitAug'];
}
if($_SESSION['VitActuelle']>$_SESSION['Vit']){
$_SESSION['VitActuelle']=$_SESSION['Vit'];
}
}else{
$_SESSION['VitActuelleAug'] -= $nb;
$_SESSION['VitActuelle'] -= $nb;
if($_SESSION['VitActuelle']<0){
$_SESSION['VitActuelle']=0;
}
if($_SESSION['VitActuelleAug']<0){
$_SESSION['VitActuelleAug']=0;
header("location: mort.php");
}
}
}
function ChangementEnergieCombat($nb,$retrait,$lequel){
if($lequel==0){
//on enleve de l'energie a l'ennemi
if($retrait == 0){
$_SESSION['ennemiFatigue'] += $nb;
if($_SESSION['ennemiFatigue']>$_SESSION['ennemiFatigueMax']){
$_SESSION['ennemiFatigue']=$_SESSION['ennemiFatigueMax'];
}
}else{
$_SESSION['ennemiFatigue'] -= $nb;
if($_SESSION['ennemiFatigue']<0){
$_SESSION['ennemiFatigue']=0;
}
}
}else{
//on enleve de l'energie au perso
if($retrait == 0){
$_SESSION['FatigueActuelle'] += $nb;
if($_SESSION['FatigueActuelle']>$_SESSION['FatigueMax']){
$_SESSION['FatigueActuelle']=$_SESSION['FatigueMax'];
}
}else{
$_SESSION['FatigueActuelle'] -= $nb;
if($_SESSION['FatigueActuelle']<0){
$_SESSION['FatigueActuelle']=0;
}
}
}
}
function ChangementPoids($AlimentTresNutritif){
if($AlimentTresNutritif == 0){
$_SESSION['Poids']++;
}elseif($AlimentTresNutritif == 1){
$_SESSION['Poids']--;
}
if($_SESSION['Poids']>5){
$_SESSION['Poids']=5;
}else if($_SESSION['Poids']<1){
$_SESSION['Poids']=1;
}
}
function ChangementOr($combien,$retrait){
if($retrait==0){
$_SESSION['Or'] += $combien;
}else{
$_SESSION['Or'] -= $combien;
}
}
function ChangementVariableHistoire($laquelle,$valeur){
mysql_query("UPDATE histoire SET ".$laquelle."='".$valeur."' WHERE id = '".$_SESSION['id']."'")or exit('Erreur ' . mysqli_errno() . ' : ' . mysqli_error());
}
function ChangementHeureJournee(){
//raz des encas qui font changer de journee
$_SESSION['enCas'] = 1;
//augmentation du compteur de l'heure de la journ�e
$_SESSION['repas']++;
//test pour savoir si on change de journ�e
if($_SESSION['repas']>3){
$_SESSION['repas']=0;
$_SESSION['Age']++;
$_SESSION['couple']=0;
}
}
function SauvegardeHistoire(){
$chaine = check_ChaineDeCaracteres($_SESSION['passeHeroique']);
$req = 'UPDATE sorcier SET passeHeroiqueSorcier = "'.$chaine.'" WHERE id = "'.$_SESSION["id"].'"';
mysql_query($req)or exit('Erreur ' . mysqli_errno() . ' : ' . mysqli_error());
}
function Sauvegarde($endroit){
//remise a zero des compteurs encas et boissons
$_SESSION['biereBu'] = 0;
if($endroit==1){
//ca ne marche que pour le moment ou l'on dort dans la taverne...
ChangementHeureJournee();
}
CalculAugmentationCarac();
//insertion des nouvelles caracteristiques
$req = "UPDATE sorcier SET Niveau = '".$_SESSION['Niveau']."' ,"
."Intelligence = '".$_SESSION['Int']."' ,"
."Vitalite = '".$_SESSION['Vit']."' ,"
."Forc = '".$_SESSION['For']."' ,"
."Charisme = '".$_SESSION['Cha']."' ,"
."Dexterite = '".$_SESSION['Dex']."' ,"
."Sagesse = '".$_SESSION['Sag']."' ,"
."VitActuelle = '".$_SESSION['VitActuelle']."' ,"
."FatigueMax = '".$_SESSION['FatigueMax']."' ,"
."FatigueActuelle = '".$_SESSION['FatigueActuelle']."' ,"
."PiecesOr = '".$_SESSION['Or']."' ,"
."Poids = '".$_SESSION['Poids']."' ,"
."Age = '".$_SESSION['Age']."' ,"
."Dieu = '".$_SESSION['Dieu']."' ,"
."Heure= '".$_SESSION['repas']."' ,"
."N_pomme = '".$_SESSION['N_pomme']."' ,"
."N_viandeSeche = '".$_SESSION['N_viandeSeche']."' ,"
."N_orange = '".$_SESSION['N_orange']."' ,"
."N_pain = '".$_SESSION['N_pain']."' ,"
."N_chocolat = '".$_SESSION['N_chocolat']."' ,"
."N_lait = '".$_SESSION['N_lait']."' ,"
."experience = '".$_SESSION['xp']."' ,"
."experienceMax = '".$_SESSION['xpMax']."'"
." WHERE id = '".$_SESSION['id']."'";
CalculCaractAugmentee(TRUE);
//insertion des nouvelles valeurs de l'histoire
$req2 = "UPDATE histoire SET taverne= '".$_SESSION['taverne']."' ,"
."taverneRumeur= '".$_SESSION['taverneRumeur']."',"
."taverneRat= '".$_SESSION['taverneRat']."' ,"
."arrivee= '".$_SESSION['arrivee']."' ,"
."erudit= '".$_SESSION['erudit']."' ,"
."pretre= '".$_SESSION['pretre']."' ,"
."egliseRumeur= '".$_SESSION['egliseRumeur']."' ,"
."egliseZombis= '".$_SESSION['egliseZombis']."' ,"
."joueurs= '".$_SESSION['joueurs']."' ,"
."nains= '".$_SESSION['nains']."' ,"
."nainsHumeur= '".$_SESSION['nainsHumeur']."' ,"
."nudite= '".$_SESSION['nudite']."' ,"
."couple= '".$_SESSION['couple']."' ,"
."bagueMaisonCouple= '".$_SESSION['bagueMaisonCouple']."' ,"
."tavernier= '".$_SESSION['tavernier']."' ,"
."forgeron= '".$_SESSION['forgeron']."' ,"
."Sauvegarde= '".$endroit."'"
." WHERE id = '".$_SESSION['id']."'";
//insertion des nouveaux ou anciens objets
$req3 = "UPDATE sac SET id_objets1 = '".$_SESSION['objets1']."' ,"
."id_objets2 = '".$_SESSION['objets2']."' ,"
."id_objets3 = '".$_SESSION['objets3']."' ,"
."id_objets4 = '".$_SESSION['objets4']."'"
."WHERE id_sorcier = '".$_SESSION['id']."'";
//insertion des nouveaux ou anciens equipement
$req4 = "UPDATE equipement SET id_tete = '".$_SESSION['tete']."' ,"
."id_mainGauche = '".$_SESSION['mainGauche']."' ,"
."id_mainDroite = '".$_SESSION['mainDroite']."' ,"
."id_corps = '".$_SESSION['corps']."' ,"
."id_mains = '".$_SESSION['mains']."' ,"
."id_jambes = '".$_SESSION['jambes']."' ,"
."id_pieds = '".$_SESSION['pieds']."' ,"
."id_doigt1 = '".$_SESSION['doigt1']."' ,"
."id_doigt2 = '".$_SESSION['doigt2']."' ,"
."Sac = '".$_SESSION['sac']."'"
."WHERE id_sorcier = '".$_SESSION['id']."'";
mysql_query($req)or exit('Erreur ' . mysqli_errno() . ' : ' . mysqli_error());
mysql_query($req2)or exit('Erreur ' . mysqli_errno() . ' : ' . mysqli_error());
mysql_query($req3)or exit('Erreur ' . mysqli_errno() . ' : ' . mysqli_error());
mysql_query($req4)or exit('Erreur ' . mysqli_errno() . ' : ' . mysqli_error());
}
function AfficheBarreDEtat($pageactuelle){
echo "<table border='0' cellspacing='0' cellpadding='0' align='center'>"
."<tr>"
."<td align='center' width= '225'><B>POINTS DE VIE: </B>".$_SESSION['VitActuelleAug']."/".$_SESSION['VitAug']." ";
AfficheImgBarre(0,$_SESSION['VitActuelleAug'],$_SESSION['VitAug']);
echo "</td>"
."<td align='center' width= '225'><B>FATIGUE: </B>".$_SESSION['FatigueActuelle']."/".$_SESSION['FatigueMax']." ";
AfficheImgBarre(1,$_SESSION['FatigueActuelle'],$_SESSION['FatigueMax']);
echo "</td>"
."<td align='center' width='225'><B>OR: </B>".$_SESSION['Or']." pi�ces.<BR>";
if($pageactuelle==0){
echo "<A href=FicheDEtat.php>Fiche De ".$_SESSION['Prenom']."</a>";
}
echo "</td>"
."</tr>"
."</table>";
}
function AfficheImgBarre($QuelleBarre,$Actuel,$Max){
switch($QuelleBarre){
case 0:
$image="images/barreHP.gif";
break;
case 1:
$image="images/barreFatigue.gif";
break;
case 2:
$image="images/barreXp.gif";
break;
}
echo "<table border='0' cellspacing='0' cellpadding='0' align='center'>"
."<tr>";
$nbVie= round((100*$Actuel)/$Max)*2;
echo "<td>"
."<img src=".$image." width='".$nbVie."px' height='9px'>"
."</td>";
$nbMort= (200-$nbVie);
echo "<td>"
."<img src=images/barre.gif width='".$nbMort."px' height='9px'>"
."</td>";
echo "</tr>"
."</table>";
}
function typeAliment($nbAliment){
switch($nbAliment){
case 1:
return("fruit");
break;
case 2:
return("prot�ine");
break;
case 3:
return("agrume");
break;
case 4:
return("feculent");
break;
case 5:
return("gourmandise");
break;
case 6:
return("laitage");
break;
}
}
function CalculAugmentationCarac(){
//mise a zero des augmentation de caracteristiques
$_SESSION['Aug_Int'] = 0;
$_SESSION['Aug_For'] = 0;
$_SESSION['Aug_Vit'] = 0;
$_SESSION['Aug_Cha'] = 0;
$_SESSION['Aug_Dex'] = 0;
$_SESSION['Aug_Sag'] = 0;
//ajout des augmentation des caracteristiques
//sur le corps
$req = "SELECT aug_Int,aug_For,aug_Vit,aug_Cha,aug_Dex,aug_Sag FROM corps WHERE id_corps='".$_SESSION['corps']."'";
$resultat = mysql_query($req)or exit('Erreur ' . mysqli_errno() . ' : ' . mysqli_error());
$tableauReponse=mysqli_fetch_assoc($resultat);
$_SESSION['Aug_Int'] += $tableauReponse['aug_Int'];
$_SESSION['Aug_For'] += $tableauReponse['aug_For'];
$_SESSION['Aug_Vit'] += $tableauReponse['aug_Vit'];
$_SESSION['Aug_Cha'] += $tableauReponse['aug_Cha'];
$_SESSION['Aug_Dex'] += $tableauReponse['aug_Dex'];
$_SESSION['Aug_Sag'] += $tableauReponse['aug_Sag'];
//sur les doigts de la main gauche
$req = "SELECT aug_Int,aug_For,aug_Vit,aug_Cha,aug_Dex,aug_Sag FROM doigt WHERE id_doigt='".$_SESSION['doigt1']."'";
$resultat = mysql_query($req)or exit('Erreur ' . mysqli_errno() . ' : ' . mysqli_error());
$tableauReponse=mysqli_fetch_assoc($resultat);
$_SESSION['Aug_Int'] += $tableauReponse['aug_Int'];
$_SESSION['Aug_For'] += $tableauReponse['aug_For'];
$_SESSION['Aug_Vit'] += $tableauReponse['aug_Vit'];
$_SESSION['Aug_Cha'] += $tableauReponse['aug_Cha'];
$_SESSION['Aug_Dex'] += $tableauReponse['aug_Dex'];
$_SESSION['Aug_Sag'] += $tableauReponse['aug_Sag'];
//sur les doigts de la main droite
$req = "SELECT aug_Int,aug_For,aug_Vit,aug_Cha,aug_Dex,aug_Sag FROM doigt WHERE id_doigt='".$_SESSION['doigt2']."'";
$resultat = mysql_query($req)or exit('Erreur ' . mysqli_errno() . ' : ' . mysqli_error());
$tableauReponse=mysqli_fetch_assoc($resultat);
$_SESSION['Aug_Int'] += $tableauReponse['aug_Int'];
$_SESSION['Aug_For'] += $tableauReponse['aug_For'];
$_SESSION['Aug_Vit'] += $tableauReponse['aug_Vit'];
$_SESSION['Aug_Cha'] += $tableauReponse['aug_Cha'];
$_SESSION['Aug_Dex'] += $tableauReponse['aug_Dex'];
$_SESSION['Aug_Sag'] += $tableauReponse['aug_Sag'];
//sur les jambes
$req = "SELECT aug_Int,aug_For,aug_Vit,aug_Cha,aug_Dex,aug_Sag FROM jambes WHERE id_jambes='".$_SESSION['jambes']."'";
$resultat = mysql_query($req)or exit('Erreur ' . mysqli_errno() . ' : ' . mysqli_error());
$tableauReponse=mysqli_fetch_assoc($resultat);
$_SESSION['Aug_Int'] += $tableauReponse['aug_Int'];
$_SESSION['Aug_For'] += $tableauReponse['aug_For'];
$_SESSION['Aug_Vit'] += $tableauReponse['aug_Vit'];
$_SESSION['Aug_Cha'] += $tableauReponse['aug_Cha'];
$_SESSION['Aug_Dex'] += $tableauReponse['aug_Dex'];
$_SESSION['Aug_Sag'] += $tableauReponse['aug_Sag'];
//sur la main Droite
$req = "SELECT aug_Int,aug_For,aug_Vit,aug_Cha,aug_Dex,aug_Sag FROM maindroite WHERE id_maindroite='".$_SESSION['mainDroite']."'";
$resultat = mysql_query($req)or exit('Erreur ' . mysqli_errno() . ' : ' . mysqli_error());
$tableauReponse=mysqli_fetch_assoc($resultat);
$_SESSION['Aug_Int'] += $tableauReponse['aug_Int'];
$_SESSION['Aug_For'] += $tableauReponse['aug_For'];
$_SESSION['Aug_Vit'] += $tableauReponse['aug_Vit'];
$_SESSION['Aug_Cha'] += $tableauReponse['aug_Cha'];
$_SESSION['Aug_Dex'] += $tableauReponse['aug_Dex'];
$_SESSION['Aug_Sag'] += $tableauReponse['aug_Sag'];
//sur la main gauche
$req = "SELECT aug_Int,aug_For,aug_Vit,aug_Cha,aug_Dex,aug_Sag FROM maingauche WHERE id_maingauche='".$_SESSION['mainGauche']."'";
$resultat = mysql_query($req)or exit('Erreur ' . mysqli_errno() . ' : ' . mysqli_error());
$tableauReponse=mysqli_fetch_assoc($resultat);
$_SESSION['Aug_Int'] += $tableauReponse['aug_Int'];
$_SESSION['Aug_For'] += $tableauReponse['aug_For'];
$_SESSION['Aug_Vit'] += $tableauReponse['aug_Vit'];
$_SESSION['Aug_Cha'] += $tableauReponse['aug_Cha'];
$_SESSION['Aug_Dex'] += $tableauReponse['aug_Dex'];
$_SESSION['Aug_Sag'] += $tableauReponse['aug_Sag'];
//sur les mains
$req = "SELECT aug_Int,aug_For,aug_Vit,aug_Cha,aug_Dex,aug_Sag FROM mains WHERE id_mains='".$_SESSION['mains']."'";
$resultat = mysql_query($req)or exit('Erreur ' . mysqli_errno() . ' : ' . mysqli_error());
$tableauReponse=mysqli_fetch_assoc($resultat);
$_SESSION['Aug_Int'] += $tableauReponse['aug_Int'];
$_SESSION['Aug_For'] += $tableauReponse['aug_For'];
$_SESSION['Aug_Vit'] += $tableauReponse['aug_Vit'];
$_SESSION['Aug_Cha'] += $tableauReponse['aug_Cha'];
$_SESSION['Aug_Dex'] += $tableauReponse['aug_Dex'];
$_SESSION['Aug_Sag'] += $tableauReponse['aug_Sag'];
//sur les pieds
$req = "SELECT aug_Int,aug_For,aug_Vit,aug_Cha,aug_Dex,aug_Sag FROM pieds WHERE id_pieds='".$_SESSION['pieds']."'";
$resultat = mysql_query($req)or exit('Erreur ' . mysqli_errno() . ' : ' . mysqli_error());
$tableauReponse=mysqli_fetch_assoc($resultat);
$_SESSION['Aug_Int'] += $tableauReponse['aug_Int'];
$_SESSION['Aug_For'] += $tableauReponse['aug_For'];
$_SESSION['Aug_Vit'] += $tableauReponse['aug_Vit'];
$_SESSION['Aug_Cha'] += $tableauReponse['aug_Cha'];
$_SESSION['Aug_Dex'] += $tableauReponse['aug_Dex'];
$_SESSION['Aug_Sag'] += $tableauReponse['aug_Sag'];
//sur la tete
$req = "SELECT aug_Int,aug_For,aug_Vit,aug_Cha,aug_Dex,aug_Sag FROM tete WHERE id_tete='".$_SESSION['tete']."'";
$resultat = mysql_query($req)or exit('Erreur ' . mysqli_errno() . ' : ' . mysqli_error());
$tableauReponse=mysqli_fetch_assoc($resultat);
$_SESSION['Aug_Int'] += $tableauReponse['aug_Int'];
$_SESSION['Aug_For'] += $tableauReponse['aug_For'];
$_SESSION['Aug_Vit'] += $tableauReponse['aug_Vit'];
$_SESSION['Aug_Cha'] += $tableauReponse['aug_Cha'];
$_SESSION['Aug_Dex'] += $tableauReponse['aug_Dex'];
$_SESSION['Aug_Sag'] += $tableauReponse['aug_Sag'];
}
function CalculCaractAugmentee($var){
$_SESSION['IntAug'] = $_SESSION['Aug_Int'] + $_SESSION['Int'];
$_SESSION['VitAug'] = $_SESSION['Aug_Vit'] + $_SESSION['Vit'];
$_SESSION['ForAug'] = $_SESSION['Aug_For'] + $_SESSION['For'];
$_SESSION['SagAug'] = $_SESSION['Aug_Sag'] + $_SESSION['Sag'];
$_SESSION['ChaAug'] = $_SESSION['Aug_Cha'] + $_SESSION['Cha'];
$_SESSION['DexAug'] = $_SESSION['Aug_Dex'] + $_SESSION['Dex'];
if($var == TRUE){
$_SESSION['VitActuelleAug'] = $_SESSION['Aug_Vit'] + $_SESSION['VitActuelle'];
}
}
function maxCent($variable){
if ($variable> 100){
return(100);
}else if($variable<1){
return(1);
}else{
return($variable);
}
}
function recuperationNomObjetLaisser($id){
$req = "SELECT nom FROM objets WHERE id_objets='".$id."'";
$sql = mysql_query($req)or exit('Erreur ' . mysqli_errno() . ' : ' . mysqli_error());
$data = mysql_fetch_row($sql);
return $data[0];
}
function ChangementTexteSexe($homme,$femme){
if($_SESSION['Sexe']==1){
return $homme;
}else{
return $femme;
}
}
?>
|