import java.util.*;


public class EcritMagique extends Entite{
	
	
	boolean dejaConnu=false;
	
	private Entite objet=new Entite();
	
	int niveau=0;
	
	private String nom=new String();
	//private String nomEquipement=new String();
	
	private String modele=new String();
	private boolean casse=false;
	
	private String typeObjet=new String();
	private boolean visible=true;
	private String tileStr=new String();
	private int poids=0;
	
	private int resistanceMat=0;
	private int structureMat=0;
	
	
	private String nomE=new String();
	
	//private Spell sort=new Spell(null,null,null,null,null);
	private Spell sort=new Spell(new String(),new String(),new String(),new String(),new String());
	
	private int coordX=0;
	private int coordY=0;
	
	
	
	///////
	private String trueName=new String();
	private String trueNameE=new String();
	private boolean identified=false;
	
	public String getTrueName(){
		return trueName;		
	}
	public String getTrueNameE(){
		return trueNameE;
	}
	public boolean getIdentified(){
		return identified;
	}
	public void setIdentified(boolean si){
		identified=si;
	}
	public void setTrueNames(String tn,String tnE){
		trueName=tn;
		trueNameE=tnE;
	}
	/////////////
	
	
	
	
	
	
	public EcritMagique(int coX,int coY,boolean brok,String modeleC,String name,String nameE,String typeObjetC,boolean visibleC,String tileStrC,Spell sortC){
		
		coordX=coX;
		coordY=coY;
		
		modele=modeleC;
		nom=name;
		nomE=nameE;
		casse=brok;
		typeObjet=typeObjetC;
		visible=visibleC;
		tileStr=tileStrC;
		
		//nomEquipement=nom;
		sort=sortC;
		
		niveau=sort.getNiveau();
		
		if(modele.compareTo("grimoire")==0){
			
			resistanceMat=200;
			structureMat=300;
			poids=2;
			
			trueName="Grimoire de "+sort.getNom();
			trueNameE="SpellBook of "+sort.getNomE();
		}
		
		if(modele.compareTo("magicscroll")==0){
			
			resistanceMat=100;
			structureMat=150;
			poids=1;
			
			trueName="Parchemin de "+sort.getNom();
			trueNameE="Magic Scroll of "+sort.getNomE();
		}
		
		
	}
	
	
	
	
	//////////////////////////////////////////
	public void effetEcritMagique(Monde monde, Entite user,boolean dansEquip){
		
		if(modele.compareTo("grimoire")==0){
			dejaConnu=false;
			
			if(!monde.perso.getMemSorts().isEmpty()){
			
				for(Enumeration en = monde.perso.getMemSorts().elements();en.hasMoreElements();){
	                
	 				try{
	 					objet=(Entite) en.nextElement();
	 					
	 					if(objet.getModele().compareTo(sort.getModele())==0){
	 						dejaConnu=true;
	 					}
	 					
	 				}
	 				catch(NoSuchElementException exc){};
	 				
	 			}
			
			}
			
			
			if(!dejaConnu){
				if(monde.perso.getMagieLvl()>=sort.getNiveau()){
				
					monde.message("Vous apprenez "+sort.getNom(),false);
					monde.message("You learn "+sort.getNomE(),true);
					monde.perso.getMemSorts().add(sort);
					
					this.setIdentified(true);
				}
				else{
					monde.message("Ce sort est trop complexe pour vous. Vous devez améliorer votre connaissance de la magie",false);
					monde.message("This spell is too hard to learn now. You must improve your Magic Skill",true);
					
				}
			}
			else{
				monde.message("Vous connaissez déjà "+sort.getNom(),false);
				monde.message("You already know "+sort.getNom(),true);
			}
				
		}
		
		
		
		
		
		if(modele.compareTo("magicscroll")==0){
			sort.effetSort(monde,user);
			
			if(dansEquip){
				
				monde.perso.remove(this);
			}else{monde.grille[coordX][coordY].remove(this);}	
				
		}
	}
	
	
	
	public int getNiveau(){
		return niveau;
	}
	
	
	public Spell getSort(){
		return sort;
	}
	
	public int getCooX(){
		return coordX;
	}
	
	public int getCooY(){
		return coordY;
	}
	
	public void setCooX(int cooX){
		coordX=cooX;
	}
	
	public void setCooY(int cooY){
		coordY=cooY;
	}
	
	
	
	public String getNomE(){
		return nomE;
	}
	
	/*
	public String getNomDequipement(){
		return nomEquipement;
	}
	
	public void setNomDequipement(String nomEquip){
		nomEquipement=nomEquip;
	}*/
	
	public int getPoids(){
		return poids;
	}
	
	public void setPoids(int pds){
		poids=pds;
	}
	
	public String getNom(){
		return nom;
	}
	
	public void setCasse(boolean broken){
		casse=broken;
	}
	public boolean getCasse(){
		return casse;
	}
	
	
	public int getResistanceMat(){
		return resistanceMat;
	}
	
	public void setResistanceMat(int res){
		resistanceMat=res;
	}
	
	public int getStructureMat(){
		return structureMat;
	}
	
	public void setStructureMat(int struct){
		structureMat=struct;
	}
	
	public String getModele(){
		return modele;
	}
	
	
	
	
	public boolean getVisible(){
		return visible;
	}
	
	public void setVisible(boolean visibility){
		visible=visibility;
	}
	
	
	
	
	public String getTileStr(){
		
		if(getCasse()==true){
			return "./images/walls/rocks.gif";
		}
		else{
			return tileStr;
		}
	}
	
	public String getTypeObjet(){
		return typeObjet;
	}
	

}