package ei.game.scene.weapons;

import java.util.ArrayList;

import ei.engine.scene.Entity;
import ei.engine.scene.Node;

/**
 * The WeaponHandler class handles weapons.
 * @author Jesper Lundin
 *
 */
public class WeaponHandler {
	private Node weaponNode;
	private ArrayList<Weapon> weapons;
	private static WeaponHandler instance;

	/**
	 * Created a weaponhandler.
	 *
	 */
	public WeaponHandler() {
		weapons = new ArrayList<Weapon>();
		weaponNode = new Node("weapon");
		
	}
	public boolean addWeapon(Weapon w){
		if(!weapons.contains(w)){
			weapons.add(w);
			weaponNode.add(w.getNode());
			return true;
		}
		return false;
	}
	
	/**
	 * Removes a player from the handler
	 * @param p The player to remove
	 * @return true if succesful else false
	 */
	public boolean removeWeapon(Weapon w){
		if(weapons.contains(w)){
			weapons.remove(w);
			weaponNode.remove(w.getNode());
			return true;
		}
		return false;
	}
	/**
	 * Updates all the weapons.
	 *
	 */
	public void update(){
		for(int i=0; i<weapons.size() ;i++){
			weapons.get(i).update();
		}
	}
	/**
	 * return the current weaponNode.
	 * @return
	 */
	public Entity getNode() {
		return weaponNode;
	}
	
	/**
	 * Returns the instance of this class
	 * 
	 * @return The instance
	 */
	public static WeaponHandler getInstance(){
		if(instance == null){
			instance = new WeaponHandler();
		}
		return instance;
	}


}



