import java.util.*;
import java.awt.*;

public class Catalog{
	transient private Entite objet=new Entite();
	transient private Entite objet2=new Entite();
	transient int nbrObjets=0;
	transient int cfX=0;
	transient int cfY=0; 
	transient int coY=0;
	
	transient ArrayList bestiaire=new ArrayList();
	transient ArrayList piegesCatalogue=new ArrayList();
	transient ArrayList contenantsCatalogue=new ArrayList();
	transient ArrayList armesCatalogue=new ArrayList();
	transient ArrayList armuresCatalogue=new ArrayList();
	transient ArrayList outilsCatalogue=new ArrayList();
	transient ArrayList comestiblesCatalogue=new ArrayList();
	transient ArrayList ecritMagiqueCatalogue=new ArrayList();
	transient ArrayList sortCatalogue=new ArrayList();
	
	transient ArrayList imagesCat=new ArrayList();
	transient ArrayList imagesCatStr=new ArrayList();
	
	private transient Image imageTile;
	private transient Toolkit toolkit = Toolkit.getDefaultToolkit();
	
	Monde monde;
	
	public Catalog(Monde world){
		monde=world;
		
		creationBestiaire();
		creationPiegesCatalogue();
		creationContenantCatalogue();
		creationArmesCatalogue();
		creationArmuresCatalogue();
		creationOutilCatalogue();
		creationComestibleCatalogue();
		creationEcritMagiqueCatalogue();
		creationSortCatalogue();
		
	}	
	
	////////////////////////////////////////////////////////
	/////////////CATALOGUES/////////////////////////////////
	////////////////////////////////////////////////////////
	public void creationImagesCat(Monde wrld){
		imagesCat.clear();
		imagesCatStr.clear();
		
		//int indexIm=1;
		Entite objet;
		System.out.println("***********CREATION IMAGES***********");
		
		
		
		imagesCat.add(toolkit.getImage("./images/BUGALERT.gif"));
		imagesCatStr.add("./images/BUGALERT.gif");
		
		for(int x=0;x<wrld.tailleGrille;x++){
			for(int y=0;y<wrld.tailleGrille;y++){
				
				if(!wrld.grille[x][y].isEmpty()){
			
		 			for(int i=0;i<wrld.grille[x][y].size();i++){
					
			 			try{
			 					
			 				objet = (Entite)wrld.grille[x][y].get(i);		
		 				
							imageTile=toolkit.getImage(objet.getTileStr());
							
							if(!imagesCat.contains(imageTile)){
								imagesCat.add(imageTile);
								imagesCatStr.add(objet.getTileStr());
								
								//objet.indexImage=imagesCat.size()-1;
								//indexIm++;
							}
							/*
							else{
							 	objet.indexImage=imagesCat.indexOf(imageTile);
							}*/
							
							
							
						}
						catch(NoSuchElementException exc){};
					}
				}
					
			}
		}
		
		System.out.println("NbrImages= "+imagesCat.size());
		
		
	}
	
	////////////////////////////////////////////////////////////////
	////////////////////////////////////////////////////////////////
	////////////////////////////////////////////////////////////////
	////////////////////////////////////////////////////////////////
	////////////////////////////////////////////////////////////////
	////////////////////////////////////////////////////////////////
	////////////////////////////////////////////////////////////////
	////////////////////////////////////////////////////////////////
	////////////////////////////////////////////////////////////////
	public void creationSortCatalogue(){
		sortCatalogue.clear();
		sortCatalogue.add(new Spell("invisibility","Invisibilite","Invisibility","./sons/magic_spell_casting.wav","./images/sorts/1.gif"));
		sortCatalogue.add(new Spell("customteleport","Teleportation Parametrable","Custom Teleportation","./sons/detect.wav","./images/sorts/teleport1.gif"));
		sortCatalogue.add(new Spell("passemuraille","Passe-Muraille","Ectoplasmic Consistency","./sons/gulp.wav","./images/sorts/4.gif"));
		sortCatalogue.add(new Spell("nightvision","Infravision","Infravision","./sons/magic_spell_casting.wav","./images/sorts/infravision.gif"));
		sortCatalogue.add(new Spell("rayonx","RayonX","X-Ray","./sons/magic_spell_casting.wav","./images/sorts/rayonX.gif"));
		sortCatalogue.add(new Spell("fly","Vol","Fly","./sons/magic_spell_casting.wav","./images/sorts/fly.gif"));
		sortCatalogue.add(new Spell("firebolt","Trait de feu","Firebolt","./sons/magic_spell_casting.wav","./images/sorts/fire2.gif"));
	
	}
	
	public void creationEcritMagiqueCatalogue(){
		ecritMagiqueCatalogue.clear();
		ecritMagiqueCatalogue.add(new EcritMagique(0,0,false,"magicscroll","Parchemin","Magic scroll","EcritMagique",true,new String(),new Spell("invisibility","Invisibilite","Invisibility","./sons/magic_spell_casting.wav","./images/sorts/1.gif")));
		ecritMagiqueCatalogue.add(new EcritMagique(0,0,false,"grimoire","Grimoire","Spellbook","EcritMagique",true,new String(),new Spell("invisibility","Invisibilite","Invisibility","./sons/magic_spell_casting.wav","./images/sorts/1.gif")));
	}
	
	
	
	public void creationBestiaire(){
		bestiaire.clear();
		bestiaire.add(new UndeadCategory(monde,false,"lesser skeleton","Un squelette","A skeleton",true,"Creature",true,"./images/creatures/undead/funkysquelette.gif","./images/creatures/bones.gif","./sons/gravel.wav"));
		bestiaire.add(new UndeadCategory(monde,false,"lesser zombi","Un zombi","A zombi",true,"Creature",true,"./images/creatures/undead/zombie.gif","./images/creatures/corpse.gif","./sons/zombi.wav"));
		bestiaire.add(new UndeadCategory(monde,false,"lesser ghost","Un spectre","A ghost",true,"Creature",true,"./images/creatures/undead/spectrevert.gif","./images/creatures/bones.gif","./sons/ghost.wav"));
		bestiaire.add(new UndeadCategory(monde,false,"undeaddragon","Un dragon mort vivant","An undead dragon",true,"Creature",true,"./images/creatures/undead/undeaddragon.gif","./images/creatures/bones.gif","./sons/demonlord.wav"));
		bestiaire.add(new UndeadCategory(monde,false,"mummy","Une momie","A mummy",true,"Creature",true,"./images/creatures/undead/mummy.gif","./images/creatures/bones.gif","./sons/mummy.wav"));
		
		
		bestiaire.add(new GoblinoidCategory(monde,false,"lesser orc","Un orc","An orc",true,"Creature",true,"./images/creatures/goblinoid/orc1.gif","./images/creatures/corpse.gif","./sons/monster_orcish_snarl.wav"));
		bestiaire.add(new GoblinoidCategory(monde,false,"gobelin","Un gobelin","A goblin",true,"Creature",true,"./images/creatures/goblinoid/orc2.gif","./images/creatures/corpse.gif","./sons/goblin.wav"));
		
		bestiaire.add(new CritterCategory(monde,false,"bat","Une chauve souris","A bat",true,"Creature",true,"./images/creatures/critter/bat.gif","./images/creatures/corpse.gif","./sons/rats.wav"));
		bestiaire.add(new CritterCategory(monde,false,"bug","Un cafard geant","A giant bug",true,"Creature",true,"./images/creatures/critter/cafard.gif","./images/creatures/corpse.gif","./sons/insect.wav"));
		bestiaire.add(new CritterCategory(monde,false,"rat","Un rat","A rat",true,"Creature",true,"./images/creatures/critter/rat2.gif","./images/creatures/corpse.gif","./sons/rats.wav"));
		bestiaire.add(new CritterCategory(monde,false,"giantbat","Une chauve souris geante","A giant bat",true,"Creature",true,"./images/creatures/critter/giantbat.gif","./images/creatures/corpse.gif","./sons/bat.wav"));
		bestiaire.add(new CritterCategory(monde,false,"escargotgeant","Un escargot geant","A giant snail",true,"Creature",true,"./images/creatures/critter/escargot.gif","./images/creatures/corpse.gif","./sons/slime.wav"));
		
		
		
		
		bestiaire.add(new DragonCategory(monde,false,"dragonancientgreen","Un dragon vert ancien","An old green dragon",true,"Creature",true,"./images/creatures/dragon/d10.gif","./images/creatures/corpse.gif","./sons/demonlord.wav"));
		bestiaire.add(new DragonCategory(monde,false,"dragonancientblack","Un dragon noir ancien","An old black dragon",true,"Creature",true,"./images/creatures/dragon/d4.gif","./images/creatures/corpse.gif","./sons/demonlord.wav"));
		bestiaire.add(new DragonCategory(monde,false,"dragonancientlordred","Un seigneur dragon rouge","An old red dragon lord",true,"Creature",true,"./images/creatures/dragon/d1.gif","./images/creatures/corpse.gif","./sons/demonlord.wav"));
		bestiaire.add(new DragonCategory(monde,false,"dragonancientred","Un dragon rouge ancient","An old red dragon",true,"Creature",true,"./images/creatures/dragon/d5.gif","./images/creatures/corpse.gif","./sons/demonlord.wav"));
		
		
		bestiaire.add(new AnimalCategory(monde,false,"evilfrog","Une grenouille geante","A giant frog",true,"Creature",true,"./images/creatures/animal/evilfrog.gif","./images/creatures/corpse.gif","./sons/frog.wav"));
		bestiaire.add(new AnimalCategory(monde,false,"wolf","Un loup","A wolf",true,"Creature",true,"./images/creatures/animal/wolf.gif","./images/creatures/corpse.gif","./sons/wolf.wav"));
		bestiaire.add(new AnimalCategory(monde,false,"warg","Un warg","A warg",true,"Creature",true,"./images/creatures/animal/warg.gif","./images/creatures/corpse.gif","./sons/wolf.wav"));
		
		bestiaire.add(new CthulianCategory(monde,false,"tentaclesphere","Une chose tentaculaire","A tentacles thing",true,"Creature",true,"./images/creatures/cthulian/tentaclesphere.gif","./images/creatures/corpse.gif","./sons/scorpion.wav"));
		bestiaire.add(new CthulianCategory(monde,false,"stellarlarva","Une larve stellaire","A stellar larva",true,"Creature",true,"./images/creatures/cthulian/stellarlarva.gif","./images/creatures/corpse.gif","./sons/stormend.wav"));
		
		bestiaire.add(new DemonCategory(monde,false,"balrog","Un balrog","A balrog",true,"Creature",true,"./images/creatures/demon/balrog.gif","./images/creatures/corpse.gif","./sons/balrog.wav"));
		
		bestiaire.add(new ElementalCategory(monde,false,"smallwaterelemental","Un elementaire d eau","A water elemental",true,"Creature",true,"./images/creatures/elemental/waterelemental.gif","./images/creatures/corpse.gif","./sons/waterel.wav"));
				
		
	}
	
	public void creationPiegesCatalogue(){
		piegesCatalogue.clear();
		piegesCatalogue.add(new Piege(monde,true,0,0,true,0,false,"explosivetrap","Mine","Exploding trap","Piege",false,"./images/pieges/piegeskull.gif","./sons/explosion.wav"));
		piegesCatalogue.add(new Piege(monde,true,0,0,true,0,false,"teleporttrap","Teleporteur","Teleport trap","Piege",false,"./images/pieges/piegeteleport.gif","./sons/teleport.wav"));
		piegesCatalogue.add(new Piege(monde,true,0,0,true,0,false,"piketrap","Piege a pieux","Impaling trap","Piege",false,"./images/pieges/piketrap.gif","./sons/hit_pierce.wav"));
		piegesCatalogue.add(new Piege(monde,true,0,0,true,0,false,"trou","Un trou","A hole","Piege",false,"./images/pieges/trou.gif","./sons/fall_down_level.wav"));
		
		
	}
	
	public void creationContenantCatalogue(){
		contenantsCatalogue.clear();
		contenantsCatalogue.add(new Contenant(this,monde,true,true,false,0,false,false,"coffrestandard","Un coffre","A chest",true,"./images/contenant/coffrestandardferme.gif","./images/contenant/coffrestandardouvert.gif","./sons/oldedoor_open.wav","./sons/oldedoor_close.wav"));
		contenantsCatalogue.add(new Contenant(this,monde,true,false,true,0,true,false,"alchemytable","Table Alchimie","An Alchemy table",true,"./images/mobiliers/tableAlchimie.gif","./images/mobiliers/tableAlchimie.gif","./sons/door_open.wav","./sons/door_close.wav"));
		
	}
	
	public void creationArmesCatalogue(){
		armesCatalogue.clear();
		armesCatalogue.add(new Arme(false,"longsword","Une epee longue","Longsword",0,"Objet",true,"./images/weapons/longSword.gif"));
		armesCatalogue.add(new Arme(false,"dagger","Une dague","Dagger",0,"Objet",true,"./images/weapons/tinydagger.gif"));
		armesCatalogue.add(new Arme(false,"battleaxe","Hache de guerre","Battleaxe",0,"Objet",true,"./images/weapons/battleaxe.gif"));
		armesCatalogue.add(new Arme(false,"flail","Fleau","Flail",0,"Objet",true,"./images/weapons/flail.gif"));
		armesCatalogue.add(new Arme(false,"warhammer","Marteau de guerre","Warhammer",0,"Objet",true,"./images/weapons/hammer.gif"));
		armesCatalogue.add(new Arme(false,"mace","Masse d arme","Mace",0,"Objet",true,"./images/weapons/mace.gif"));
		armesCatalogue.add(new Arme(false,"polearm","Arme d hast","Polearm",0,"Objet",true,"./images/weapons/polearm.gif"));
		armesCatalogue.add(new Arme(false,"quarterstaff","Baton","Quarterstaff",0,"Objet",true,"./images/weapons/quarterstaff.gif"));
		armesCatalogue.add(new Arme(false,"shortaxe","Hache courte","Shortaxe",0,"Objet",true,"./images/weapons/shortaxe.gif"));
		armesCatalogue.add(new Arme(false,"shortsword","Epee courte","Shortsword",0,"Objet",true,"./images/weapons/shortsword.gif"));
	}
	
	public void creationArmuresCatalogue(){
		armuresCatalogue.clear();
		armuresCatalogue.add(new Armure(false,"softleather","Armure de cuir","Soft leather armor",0,"Objet",true,"./images/armors/leatherArmor.gif"));
		armuresCatalogue.add(new Armure(false,"hardleather","Armure de cuir bouilli","Hard leather armor",0,"Objet",true,"./images/armors/hardleather.gif"));
		armuresCatalogue.add(new Armure(false,"mail","Cotte de mailles","Mail armor",0,"Objet",true,"./images/armors/mail.gif"));
		armuresCatalogue.add(new Armure(false,"plate","Armure de plaques","Plate Armor",0,"Objet",true,"./images/armors/plate.gif"));
	}
	
	
	public void creationOutilCatalogue(){
		outilsCatalogue.clear();
		outilsCatalogue.add(new Outil(false,"pickingtools","Outils de crochetage","Picking tools",0,"Objet",true,"./images/outils/pickingtools.gif"));
		outilsCatalogue.add(new Outil(false,"pioche","Pioche","Pick",0,"Objet",true,"./images/outils/pioche.gif"));
		outilsCatalogue.add(new Outil(false,"chandelier","Un chandelier","Candlestick",0,"Objet",true,"./images/outils/chandelier.gif"));
		outilsCatalogue.add(new Outil(false,"torche","Une torche","Torch",0,"Objet",true,"./images/outils/torche.gif"));
		outilsCatalogue.add(new Outil(false,"lanterne","Une lanterne","Lantern",0,"Objet",true,"./images/outils/lanterne.gif"));
		outilsCatalogue.add(new Outil(false,"oilflask","Flasque d huile","Oil flask",0,"Objet",true,"./images/outils/oilflask.gif"));
		outilsCatalogue.add(new Outil(false,"pelle","Une pelle","Shovel",0,"Objet",true,"./images/outils/pelle.gif"));
		
		
	}
	
	public void creationComestibleCatalogue(){
		comestiblesCatalogue.clear();
		comestiblesCatalogue.add(new Nourriture(false,"mushroom","champignon","mushroom","Comestible",true,"./images/comestible/champivert.gif"));
		comestiblesCatalogue.add(new Nourriture(false,"ration","ration","ration","Comestible",true,"./images/comestible/ration1.gif"));
		comestiblesCatalogue.add(new Nourriture(false,"potiron","potiron","pumpkin","Comestible",true,"./images/comestible/potiron.gif"));
		
		
		comestiblesCatalogue.add(new Boisson(false,"lesserhealingpotion","potion","potion","Comestible",true,"./images/comestible/potionrouge.gif"));
		comestiblesCatalogue.add(new Boisson(false,"mediumhealingpotion","potion","potion","Comestible",true,"./images/comestible/potionrouge.gif"));
		comestiblesCatalogue.add(new Boisson(false,"majorhealingpotion","potion","potion","Comestible",true,"./images/comestible/potionrouge.gif"));
		comestiblesCatalogue.add(new Boisson(false,"lesserpoison","potion","potion","Comestible",true,"./images/comestible/potionjaune.gif"));
		comestiblesCatalogue.add(new Boisson(false,"mediumpoison","potion","potion","Comestible",true,"./images/comestible/potionjaune.gif"));
		comestiblesCatalogue.add(new Boisson(false,"majorpoison","potion","potion","Comestible",true,"./images/comestible/potionjaune.gif"));
		comestiblesCatalogue.add(new Boisson(false,"speedpotion","potion","potion","Comestible",true,"./images/comestible/potionviolette.gif"));
		comestiblesCatalogue.add(new Boisson(false,"slowpotion","potion","potion","Comestible",true,"./images/comestible/potionrose.gif"));
		comestiblesCatalogue.add(new Boisson(false,"fountain","Fontaine","Fountain","Comestible",true,"./images/comestible/fountain.gif"));
	
	}
	
	
	
	
	/*
	bestiaire
	piegesCatalogue
	contenantsCatalogue
	armesCatalogue
	armuresCatalogue
	outilsCatalogue
	comestiblesCatalogue
	ecritMagiqueCatalogue
	sortCatalogue
	*/
	//////////////////////////////////////////////////////////////////
	//DIFFICULTES = (int)(Math.random()*monde.ipp()*20)+1
	//BONUS = (int)(Math.random()*(monde.ipp()-3))+1
	
	public int rDiff(Monde monde){
		
		return (int)(Math.random()*monde.ipp()*20)+1;
		
	}
	
	public int rBonus(Monde monde){
		return (int)(Math.random()*(monde.ipp()-3))+1;
	}
	
	//////////////////////////////////////////////////////////////////
	//////GENERATEURS/////////////////////////////////////////////////
	//////////////////////////////////////////////////////////////////
	
	////////////////////////////
	//PIEGES
	public void genePiege(ArrayList grille[][],int proba,int nbrObjetsMax,int coorX,int coorY, int etendueX, int etendueY){
		
		
		if((int)(Math.abs(Math.random()*100)+1)>proba){
			nbrObjets=(int)(Math.abs(Math.random()*nbrObjetsMax));
		
			while(nbrObjets!=0){
			
				int xp=(int)(Math.abs(Math.random()*etendueX)+1);
				int yp=(int)(Math.abs(Math.random()*etendueY)+1);
				cfX=coorX+1;
				cfY=coorY+1;
				coY=coorY+1;
				
				
				objet= (Entite) piegesCatalogue.get((int)(Math.abs(Math.random()*piegesCatalogue.size())));
				
				grille[coorX+xp][coorY+yp].add(new Piege(monde,true,0,0,true,0,false,objet.getModele(),objet.getNom(),objet.getNomE(),"Piege",false,objet.getTileStr(),objet.getSonActivation()));
				
				
				nbrObjets--;
			}
			
		}
	
		
	}
	
	////////////////////////////
	//CONTENANTS
	
	public void geneContenant(ArrayList grille[][],int proba,int nbrObjetsMax,int coorX,int coorY, int etendueX, int etendueY){
		
		if((int)(Math.abs(Math.random()*100)+1)>proba){
			nbrObjets=(int)(Math.abs(Math.random()*nbrObjetsMax));
		
			while(nbrObjets!=0){
			
				int xp=(int)(Math.abs(Math.random()*etendueX)+1);
				int yp=(int)(Math.abs(Math.random()*etendueY)+1);
				cfX=coorX+1;
				cfY=coorY+1;
				coY=coorY+1;
				
				objet= (Entite) contenantsCatalogue.get((int)(Math.abs(Math.random()*contenantsCatalogue.size())));
				
				grille[coorX+xp][coorY+yp].add(new Contenant(this,monde,true,true,false,0,false,false,objet.getModele(),objet.getNom(),objet.getNomE(),true,objet.getTileFerme(),objet.getTileOuvert(),objet.getSonOuverture(),objet.getSonFermeture()));			

				System.out.println(objet.getNom()+" en "+(coorX+xp)+" "+(coorY+yp));
				
				nbrObjets--;
			}
			
			
		}
	
		
	}
	
	////////////////////////////
	//ECRITS MAGIQUES
	public void geneEcritMagique(ArrayList grille[][],int proba,int nbrObjetsMax,int coorX,int coorY, int etendueX, int etendueY){
		if((int)(Math.abs(Math.random()*100)+1)>proba){
			nbrObjets=(int)(Math.abs(Math.random()*nbrObjetsMax));
			String tileStr=new String();
			while(nbrObjets!=0){
			
				int xp=(int)(Math.abs(Math.random()*etendueX)+1);
				int yp=(int)(Math.abs(Math.random()*etendueY)+1);
				cfX=coorX+1;
				cfY=coorY+1;
				coY=coorY+1;
				
				objet= (Entite) ecritMagiqueCatalogue.get((int)(Math.abs(Math.random()*ecritMagiqueCatalogue.size())));
				objet2= (Entite) sortCatalogue.get((int)(Math.abs(Math.random()*sortCatalogue.size())));
				
				if(objet.getModele().compareTo("magicscroll")==0){
					tileStr="./images/ecritsmagiques/scroll"+new Integer((int)(Math.abs(Math.random()*2))+1).toString()+".gif";
				}
				else{
					tileStr="./images/ecritsmagiques/grim"+new Integer((int)(Math.abs(Math.random()*30))+1).toString()+".gif";
				}
				
				grille[coorX+xp][coorY+yp].add(new EcritMagique(coorX+xp,coorY+yp,false,objet.getModele(),objet.getNom(),objet.getNomE(),"EcritMagique",true,tileStr,(Spell)objet2));			

				System.out.println(objet.getNom()+" en "+(coorX+xp)+" "+(coorY+yp));
				
				nbrObjets--;
			}
			
			
		}
	
	}
	
	////////////////////////////
	//ARMES
	public void geneArme(ArrayList grille[][],int proba,int nbrObjetsMax,int coorX,int coorY, int etendueX, int etendueY){
		if((int)(Math.abs(Math.random()*100)+1)>proba){
			nbrObjets=(int)(Math.abs(Math.random()*nbrObjetsMax));
		
			while(nbrObjets!=0){
			
				int xp=(int)(Math.abs(Math.random()*etendueX)+1);
				int yp=(int)(Math.abs(Math.random()*etendueY)+1);
				cfX=coorX+1;
				cfY=coorY+1;
				coY=coorY+1;
				
				
				objet= (Entite) armesCatalogue.get((int)(Math.abs(Math.random()*armesCatalogue.size())));
				
				
				
				//int bonusM=(int)(Math.abs(Math.random()*(perso.getNiveau()*10))-(perso.getNiveau()*5));
				
				int bonusM=rBonus(monde);
				
				if(bonusM<0){bonusM=0;
				}
				
				grille[coorX+xp][coorY+yp].add(new Arme(false,objet.getModele(),objet.getNom(),objet.getNomE(),bonusM,"Objet",true,objet.getTileStr()));
			
				
				System.out.println(objet.getModele()+" en "+(coorX+xp)+" "+(coorY+yp));
				
				nbrObjets--;
			}
			
		}
		
	}
	
	////////////////////////////
	//ARMURE
	public void geneArmure(ArrayList grille[][],int proba,int nbrObjetsMax,int coorX,int coorY, int etendueX, int etendueY){
		if((int)(Math.abs(Math.random()*100)+1)>proba){
			nbrObjets=(int)(Math.abs(Math.random()*nbrObjetsMax));
		
			while(nbrObjets!=0){
			
				int xp=(int)(Math.abs(Math.random()*etendueX)+1);
				int yp=(int)(Math.abs(Math.random()*etendueY)+1);
				cfX=coorX+1;
				cfY=coorY+1;
				coY=coorY+1;
				
				
				objet= (Entite) armuresCatalogue.get((int)(Math.abs(Math.random()*armuresCatalogue.size())));
				
				//int bonusM=(int)(Math.abs(Math.random()*(perso.getNiveau()*10))-(perso.getNiveau()*5));
				int bonusM=rBonus(monde);
				
				if(bonusM<0){bonusM=0;
				}
												
				grille[coorX+xp][coorY+yp].add(new Armure(false,objet.getModele(),objet.getNom(),objet.getNomE(),bonusM,"Objet",true,objet.getTileStr()));
			
				
				System.out.println(objet.getModele()+" en "+(coorX+xp)+" "+(coorY+yp));
				
				nbrObjets--;
			}
			
			
		}
		
	}
	
	////////////////////////////
	//OUTIL
	public void geneOutil(ArrayList grille[][],int proba,int nbrObjetsMax,int coorX,int coorY, int etendueX, int etendueY){
		if((int)(Math.abs(Math.random()*100)+1)>proba){
			nbrObjets=(int)(Math.abs(Math.random()*nbrObjetsMax));
		
			while(nbrObjets!=0){
			
				int xp=(int)(Math.abs(Math.random()*etendueX)+1);
				int yp=(int)(Math.abs(Math.random()*etendueY)+1);
				cfX=coorX+1;
				cfY=coorY+1;
				coY=coorY+1;
				
				
				objet= (Entite) outilsCatalogue.get((int)(Math.abs(Math.random()*outilsCatalogue.size())));
				
				//int bonusM=(int)(Math.abs(Math.random()*(perso.getNiveau()*10))-(perso.getNiveau()*5));
				int bonusM=rBonus(monde);
				
				if(bonusM<0){bonusM=0;
				}
				
				
				Outil outil=new Outil(false,objet.getModele(),objet.getNom(),objet.getNomE(),bonusM,"Objet",true,objet.getTileStr());
				
				
				if(objet.getPeutEclairer()){
					
					if((int)(Math.abs(Math.random()*2))>0){
						outil.setAlume(true);
						//outil.setNomDequipement("@"+outil.getNomDequipement());
					}
					
				}								
				grille[coorX+xp][coorY+yp].add(outil);
				
				System.out.println(objet.getModele()+" en "+(coorX+xp)+" "+(coorY+yp));
				
				nbrObjets--;
			}
			
		}
		
		
	}
	
	
	////////////////////////////
	//COMESTIBLE
	public void geneComestible(ArrayList grille[][],int proba,int nbrObjetsMax,int coorX,int coorY, int etendueX, int etendueY){
		
		if((int)(Math.abs(Math.random()*100)+1)>proba){
			nbrObjets=(int)(Math.abs(Math.random()*nbrObjetsMax));
			String tileStr=new String();
			while(nbrObjets!=0){
			
				int xp=(int)(Math.abs(Math.random()*etendueX)+1);
				int yp=(int)(Math.abs(Math.random()*etendueY)+1);
				cfX=coorX+1;
				cfY=coorY+1;
				coY=coorY+1;
				
				
				objet= (Entite) comestiblesCatalogue.get((int)(Math.abs(Math.random()*comestiblesCatalogue.size())));
				
				
				if((objet.getClass().getName()).compareTo("Nourriture")==0){
				
					if(objet.getNom().compareTo("champignon")==0){
						tileStr="./images/comestible/champi"+new Integer((int)(Math.abs(Math.random()*5))+1).toString()+".gif";
					}
					
					if(objet.getNom().compareTo("ration")==0){
						tileStr="./images/comestible/ration"+new Integer((int)(Math.abs(Math.random()*3))+1).toString()+".gif";
					}
					
					if(objet.getNom().compareTo("potiron")==0){
						tileStr="./images/comestible/potiron.gif";
					}
					
					grille[coorX+xp][coorY+yp].add(new Nourriture(false,objet.getModele(),objet.getNom(),objet.getNomE(),"Comestible",true,tileStr));
				}
				
				
				
				if((objet.getClass().getName()).compareTo("Boisson")==0){
					
					tileStr="./images/comestible/potion"+new Integer((int)(Math.abs(Math.random()*4))+1).toString()+".gif";
					
					if(objet.getModele().compareTo("fountain")==0){
						tileStr="./images/comestible/fountain.gif";
					}
				
					grille[coorX+xp][coorY+yp].add(new Boisson(false,objet.getModele(),objet.getNom(),objet.getNomE(),"Comestible",true,tileStr));
				}
				
				
				
				System.out.println(objet.getModele()+" en "+(coorX+xp)+" "+(coorY+yp));
				
				nbrObjets--;
			}
			
			
		}
	
	}
	
	////////////////////////////
	//CREATURE
	public void geneCreature(ArrayList grille[][],int proba,int nbrObjetsMax,int coorX,int coorY, int etendueX, int etendueY){
		
		if((int)(Math.abs(Math.random()*100)+1)>proba){ //il y a t'il des creatures ?
			
			int typeMonstre=0;
			nbrObjets=(int)(Math.abs(Math.random()*nbrObjetsMax));
			//nbrObjets=(int)(Math.abs(Math.random()*4)+1); //combien en y a t'il ?
		
			while(nbrObjets!=0){
			
				int xp=(int)(Math.abs(Math.random()*etendueX)+1); // a quel endroit ?
				int yp=(int)(Math.abs(Math.random()*etendueY)+1);
				cfX=coorX+1;
				cfY=coorY+1;
				coY=coorY+1;
				
				boolean p=false;;
				
				
				
				ArrayList selection=new ArrayList();
				
				for(int x=0;x<bestiaire.size()&&!p;x++){
					
					 objet= (Entite) bestiaire.get(x);
					 if(objet.getNiveau()<=monde.perso.getNiveau()+5 && objet.getNiveau()>monde.perso.getNiveau()-5){
					 	selection.add(objet);
					 }
				}
				
				
				objet= (Entite) selection.get((int)(Math.abs(Math.random()*selection.size())));
				
				if((objet.getClass().getName()).compareTo("UndeadCategory")==0){
					
						UndeadCategory creature=new UndeadCategory(monde,false,objet.getEspece(),objet.getNom(),objet.getNomE(),true,"Creature",true,objet.getTileStrVivant(),objet.getTileStrMort(),objet.getCri());
						creature.setCooX(coorX+xp);
						creature.setCooY(coorY+yp);
						grille[coorX+xp][coorY+yp].add(creature);
						System.out.println(objet.getHostilite()+"Class "+objet.getClass().getName()+" Model "+objet.getEspece()+" Niveau "+objet.getNiveau()+" en "+(coorX+xp)+" / "+(coorY+yp));
						p=true;
					
equiperCreatureArme(creature);
equiperCreatureArmure(creature);
equiperCreatureOutil(creature);					
					
				}
				
				if((objet.getClass().getName()).compareTo("GoblinoidCategory")==0){
					
						
						GoblinoidCategory creature=new GoblinoidCategory(monde,false,objet.getEspece(),objet.getNom(),objet.getNomE(),true,"Creature",true,objet.getTileStrVivant(),objet.getTileStrMort(),objet.getCri());
						creature.setCooX(coorX+xp);
						creature.setCooY(coorY+yp);
						grille[coorX+xp][coorY+yp].add(creature);
						System.out.println(objet.getHostilite()+" Class "+objet.getClass().getName()+" Model "+objet.getEspece()+" Niveau "+objet.getNiveau()+" en "+(coorX+xp)+" / "+(coorY+yp));
						p=true;
equiperCreatureArme(creature);
equiperCreatureArmure(creature);
equiperCreatureOutil(creature);					
					
				}
				
				
				if((objet.getClass().getName()).compareTo("CritterCategory")==0){
					
						
						CritterCategory creature=new CritterCategory(monde,false,objet.getEspece(),objet.getNom(),objet.getNomE(),true,"Creature",true,objet.getTileStrVivant(),objet.getTileStrMort(),objet.getCri());
						creature.setCooX(coorX+xp);
						creature.setCooY(coorY+yp);
						grille[coorX+xp][coorY+yp].add(creature);
						System.out.println(objet.getHostilite()+" Class "+objet.getClass().getName()+" Model "+objet.getEspece()+" Niveau "+objet.getNiveau()+" en "+(coorX+xp)+" / "+(coorY+yp));
						p=true;
//equiperCreature(creature);					
					
				}
				
				if((objet.getClass().getName()).compareTo("DragonCategory")==0){
					
						
						DragonCategory creature=new DragonCategory(monde,false,objet.getEspece(),objet.getNom(),objet.getNomE(),true,"Creature",true,objet.getTileStrVivant(),objet.getTileStrMort(),objet.getCri());
						creature.setCooX(coorX+xp);
						creature.setCooY(coorY+yp);
						grille[coorX+xp][coorY+yp].add(creature);
						System.out.println(objet.getHostilite()+" Class "+objet.getClass().getName()+" Model "+objet.getEspece()+" Niveau "+objet.getNiveau()+" en "+(coorX+xp)+" / "+(coorY+yp));
						p=true;
					
//equiperCreature(creature);					
				}
				
				
				
				if((objet.getClass().getName()).compareTo("AnimalCategory")==0){
					
						
						AnimalCategory creature=new AnimalCategory(monde,false,objet.getEspece(),objet.getNom(),objet.getNomE(),true,"Creature",true,objet.getTileStrVivant(),objet.getTileStrMort(),objet.getCri());
						creature.setCooX(coorX+xp);
						creature.setCooY(coorY+yp);
						grille[coorX+xp][coorY+yp].add(creature);
						System.out.println(objet.getHostilite()+" Class "+objet.getClass().getName()+" Model "+objet.getEspece()+" Niveau "+objet.getNiveau()+" en "+(coorX+xp)+" / "+(coorY+yp));
						p=true;
//equiperCreature(creature);					
					
				}
				
				
				if((objet.getClass().getName()).compareTo("CthulianCategory")==0){
					
						
						CthulianCategory creature=new CthulianCategory(monde,false,objet.getEspece(),objet.getNom(),objet.getNomE(),true,"Creature",true,objet.getTileStrVivant(),objet.getTileStrMort(),objet.getCri());
						creature.setCooX(coorX+xp);
						creature.setCooY(coorY+yp);
						grille[coorX+xp][coorY+yp].add(creature);
						System.out.println(objet.getHostilite()+" Class "+objet.getClass().getName()+" Model "+objet.getEspece()+" Niveau "+objet.getNiveau()+" en "+(coorX+xp)+" / "+(coorY+yp));
						p=true;
//equiperCreature(creature);					
					
				}
				
				if((objet.getClass().getName()).compareTo("DemonCategory")==0){
					
						
						DemonCategory creature=new DemonCategory(monde,false,objet.getEspece(),objet.getNom(),objet.getNomE(),true,"Creature",true,objet.getTileStrVivant(),objet.getTileStrMort(),objet.getCri());
						creature.setCooX(coorX+xp);
						creature.setCooY(coorY+yp);
						grille[coorX+xp][coorY+yp].add(creature);
						System.out.println(objet.getHostilite()+" Class "+objet.getClass().getName()+" Model "+objet.getEspece()+" Niveau "+objet.getNiveau()+" en "+(coorX+xp)+" / "+(coorY+yp));
						p=true;
equiperCreatureArme(creature);
equiperCreatureArmure(creature);
equiperCreatureOutil(creature);					
					
				}
				
				if((objet.getClass().getName()).compareTo("ElementalCategory")==0){
					
						
						ElementalCategory creature=new ElementalCategory(monde,false,objet.getEspece(),objet.getNom(),objet.getNomE(),true,"Creature",true,objet.getTileStrVivant(),objet.getTileStrMort(),objet.getCri());
						creature.setCooX(coorX+xp);
						creature.setCooY(coorY+yp);
						grille[coorX+xp][coorY+yp].add(creature);
						System.out.println(objet.getHostilite()+" Class "+objet.getClass().getName()+" Model "+objet.getEspece()+" Niveau "+objet.getNiveau()+" en "+(coorX+xp)+" / "+(coorY+yp));
						p=true;
					
equiperCreatureArme(creature);
equiperCreatureArmure(creature);
equiperCreatureOutil(creature);
					
				}
				
				nbrObjets--;
			}
			
			
			
			
			
		}
		
	
	}
	
	
	
	////////////////////////////////////////////////////////
	////////////////////////////////////////////////////////
	////////////////////////////////////////////////////////
	//EQUIPER UNE CREATURE
	public void equiperCreatureArme(Creature creature){
		
		if(creature.getIntelligence()>2 ){
			Arme arme=(Arme)gene1_Arme(80,creature.getNiveau());
			if(arme!=null && (creature.getForce()*2)>=arme.getPoids()){
				creature.getEquipementVect().add(arme);
				creature.setArmeEquipe(arme);
			}
			
		}
		
		
	}
	public void equiperCreatureArmure(Creature creature){
		
		if(creature.getIntelligence()>2){
			Armure armure=(Armure)gene1_Armure(80,creature.getNiveau());
			if(armure!=null && (creature.getForce()*3)>=armure.getPoids()){
				creature.getEquipementVect().add(armure);
				creature.setArmureEquipe(armure);
			}
		}
		
		
	}
	public void equiperCreatureOutil(Creature creature){
		
		if(creature.getIntelligence()>4){
			Outil outil=(Outil)gene1_Outil(50,creature.getNiveau());
			if(outil!=null){
				creature.getEquipementVect().add(outil);
				
			}
		}
	}
	
	/////////////////////////////////////////////////////////
	/////////////////////////////////////////////////////////
	/////////////////////////////////////////////////////////
	/////////////////////////////////////////////////////////
	//////////////GENERATEURS A L'UNITE//////////////////////
	/////////////////////////////////////////////////////////
	/////////////////////////////////////////////////////////
	/////////////////////////////////////////////////////////
	/////////////////////////////////////////////////////////
	public int rBonusCreature(int niveau){
		return (int)(Math.random()*(ippCreature(niveau)-3))+1;
	}
	public int ippCreature(int niveau){
		return Math.round((niveau-1)/4)+5;	
	}
	
	////////////////////////////
	//ARMES
	public Entite gene1_Arme(int proba, int niveau){
		if((int)(Math.abs(Math.random()*100)+1)>proba){
			
			objet= (Entite) armesCatalogue.get((int)(Math.abs(Math.random()*armesCatalogue.size())));
				
			int bonusM=rBonusCreature(niveau);
				
			if(bonusM<0){bonusM=0;}
				
			Arme arme=new Arme(false,objet.getModele(),objet.getNom(),objet.getNomE(),bonusM,"Objet",true,objet.getTileStr());
			return arme;
		}
		else{
			return null;
		}
	}
	
	//ARMURE
	public Entite gene1_Armure(int proba, int niveau){
		if((int)(Math.abs(Math.random()*100)+1)>proba){
			
			objet= (Entite) armuresCatalogue.get((int)(Math.abs(Math.random()*armuresCatalogue.size())));
			
			int bonusM=rBonusCreature(niveau);
			
			if(bonusM<0){bonusM=0;
			}
											
			Armure armure=new Armure(false,objet.getModele(),objet.getNom(),objet.getNomE(),bonusM,"Objet",true,objet.getTileStr());
			return armure;
		}
		else{
			return null;
		}
	}
	
	//OUTIL
	public Entite gene1_Outil(int proba, int niveau){
		if((int)(Math.abs(Math.random()*100)+1)>proba){
			
			objet= (Entite) outilsCatalogue.get((int)(Math.abs(Math.random()*outilsCatalogue.size())));
			
			int bonusM=rBonusCreature(niveau);
			
			if(bonusM<0){bonusM=0;
			}
			
			Outil outil=new Outil(false,objet.getModele(),objet.getNom(),objet.getNomE(),bonusM,"Objet",true,objet.getTileStr());
			
			if(objet.getPeutEclairer()){
				if((int)(Math.abs(Math.random()*2))>0){
					outil.setAlume(true);
				}
			}								
			
			return outil;
		}
		else{
			return null;
		}
	}
	
	
	
}