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


public class Activable extends Entite{
	
	
	//private Entite cible=new Entite();
	
	private ArrayList entitesCibleList=new ArrayList();
	
	private String coordMondeCible=new String();
	
	private boolean actifActivable=false;
	private int complexiteActivable=0;
	private boolean casse=false;
	private String modele=new String();//
	private String nom=new String();//
	private String nomE=new String();
	private String typeObjet=new String();//
	private boolean visible=true;//
	private String tileStrON=new String();//
	private String tileStrOFF=new String();//
	
	private String sonActivation=new String();//
	private int poids=1000000;//
	//private String nomEquipement=new String();//
	private int resistanceMat=100;
	private int structureMat=100;
	private int niveau=0;
	
	private boolean onOff=true; //true = on
	
	int cooX=0;
	int cooY=0;
	
	
	
	public Activable(int cx, int cy,ArrayList targetsList,String coordWorldTarget,boolean actifC,int complexiteC,boolean brok,String modeleC,String name,String nameE,String typeObjetC,boolean visibleC,String tileStrONC,String tileStrOFFC,String sndC){
		
		//cible=target;
		
		cooX=cx;
		cooY=cy;
		
		entitesCibleList=targetsList;
		
		coordMondeCible=coordWorldTarget;
		
		actifActivable=actifC;
		complexiteActivable=complexiteC;
		casse=brok;
		modele=modeleC;
		nom=name;
		nomE=nameE;
		typeObjet=typeObjetC;
		visible=visibleC;
		
		tileStrON=tileStrONC;
		tileStrOFF=tileStrOFFC;
		
		sonActivation=sndC;
		
		//nomEquipement=nom;
		
		
	}
	
	
	
	public void effetActivable(Monde monde){
		
		if(getModele().compareTo("levierPorte")==0){
			System.out.println("LEVIER PORTE");
			
			for(int i=0;i<entitesCibleList.size();i++){
				Entite ent=(Entite)entitesCibleList.get(i);
				
				if(!ent.getOuvert()){
					ent.bruit(monde,0,0);
					
					ent.setUnlocked(true);
					ent.setOuvert(true);
				}
				else{
					ent.bruit(monde,0,0);
					
					ent.setUnlocked(false);
					ent.setOuvert(false);
				}
				
			}
			
		}
		
		
		
		
		
		
		if(getModele().compareTo("teleporteurFixe")==0){
			System.out.println("TELEPORTEUR FIXE  "+coordMondeCible);
			
			String [] tstr=coordMondeCible.split("T");
			
			monde.teleportation(tstr);
			
		}
		
		
		
		
	}
	
	public int getCooX(){
		return cooX;
	}
	
	public int getCooY(){
		return cooY;
	}
	
	
	public boolean getActifActivable(){
		return actifActivable;
	}
	
	public void setActifActivable(boolean act){
		actifActivable=act;
	}
	
	public int getComplexiteActivable(){
		return complexiteActivable;
	}
	public void setComplexiteActivable(int complex){
		complexiteActivable=complex;
	}
	
	public int getPoids(){
		
		return poids;
	}
	
	public void setPoids(int pds){
		poids=pds;
	}
	
	/*
	public String getNomDequipement(){
		return nomEquipement;
	}
	
	public void setNomDequipement(String nomEquip){
		nomEquipement=nomEquip;
	}
	*/
	
	public String getNom(){
		return nom;
	}
	
	
	
	public void setCasse(boolean broken){
		casse=broken;
		
	}
	
	
	public boolean getCasse(){
		return casse;
	}
	
	
	
	
	public String getModele(){
		return modele;
	}
	
	
	
	public boolean getVisible(){
		return visible;
	}
	
	public void setVisible(boolean visibility){
		visible=visibility;
	}
	
	
	
	public String getTileStr(){
		if(onOff){return tileStrON;
		}
		else{return tileStrOFF;
			
		}	
	}
	
	public boolean getOnOff(){
		return onOff;
	}
	
	public void setOnOff(boolean o){
		onOff=o;
	}
	
	
	public String getNomE(){
		return nomE;
	}


	public void bruit(Monde monde,int vx,int vy){
		
		
		if(getModele().compareTo("teleporteurFixe")==0){
			vx=monde.perso.getCooX();
			vy=monde.perso.getCooY();
		}
		
		
		float vol=0;
		int px=monde.perso.getCooX();
		int py=monde.perso.getCooY();
		
		int dx=Math.abs(vx-px);
		int dy=Math.abs(vy-py);
		
		if(dx>dy){vol=(float)dx*(-1);
		}
		else{vol=(float)dy*(-1);
		}
		
		vol=Math.round(vol/2);
		
		if(vol<-20){vol=-20;
		}
		
		new ThreadSon(sonActivation,vol).start();
		
	}
	
	
	public int getNiveau(){
		return niveau;
	}
	
	public String getTypeObjet(){
		return typeObjet;
	}
	
	
	public String getSonActivation(){
		return sonActivation;
	}
	
	public int getResistanceMat(){
		return resistanceMat;
	}
	
	public void setResistanceMat(int res){
		resistanceMat=res;
	}
	
	public int getStructureMat(){
		return structureMat;
	}
	
	public void setStructureMat(int struct){
		structureMat=struct;
	}


	

}