package sfs2x.extensions.games.spacewar2.game.core;

import java.util.HashMap;

import com.smartfoxserver.v2.entities.data.ISFSObject;


public class Starship extends GameItem
{
	public double rotation;		// Current rotation angle (radians)
	public int rotatingDir;		// Set to +1 if ship is currently rotating counterclockwise, -1 if clockwise and 0 if not rotating
	public boolean thrust;
	
	private int shield;
	
	HashMap<String, Weapon> weapons;
	
	public Starship(int ownerId, ISFSObject settings)
	{
		super(ownerId, settings);
		
		shield = settings.getInt("maxShield");
		weapons = new HashMap<String, Weapon>();
	}
	
	public double getMaxSpeed()
	{
		double setting = (double) settings.getInt("maxSpeed");
		
		// Speed is converted from pixels/sec to pixels/ms
		return setting / 1000;
	}
	
	public double getRotationSpeed()
	{
		double setting = (double) settings.getInt("rotationSpeed");
		
		// Rotation speed is converted from degrees/sec to radians/ms
		return (setting * Math.PI / 180) / 1000;
	}
	
	public double getThrustAcceleration()
	{
		double setting = (double) settings.getInt("thrustAccel");
		
		// Thrust acceleration is converted from pixels/sec2 to pixels/ms2
		return setting / 1000000;
	}
	
	public int getShield()
	{
		return shield;
	}
	
	public void decreaseShield(int value)
	{
		shield -= value;
		
		if (shield < 0)
			shield = 0;
	}
	
	public void initWeapon(String model, int maxShots)
	{
		weapons.put(model, new Weapon(maxShots));
	}
	
	public Weapon getWeapon(String model)
	{
		return weapons.get(model);
	}
}
