package data.scripts.world.corvus;

import com.fs.starfarer.api.Global;
import com.fs.starfarer.api.campaign.CampaignFleetAPI;
import com.fs.starfarer.api.campaign.FleetAssignment;
import com.fs.starfarer.api.campaign.LocationAPI;
import com.fs.starfarer.api.campaign.SectorAPI;
import com.fs.starfarer.api.campaign.SectorEntityToken;
import com.fs.starfarer.api.campaign.StarSystemAPI;

import data.scripts.world.BaseSpawnPoint;

public class AlienSpawnPoint extends BaseSpawnPoint {

	private final SectorEntityToken station;

	public AlienSpawnPoint(SectorAPI sector, LocationAPI location, 
							float daysInterval, int maxFleets, SectorEntityToken anchor,
							SectorEntityToken station) {
		super(sector, location, daysInterval, maxFleets, anchor);
		
		this.station = station;
	}

	
	@Override
	public CampaignFleetAPI spawnFleet() {
	
		String type=null;
		float r=(float) Math.random();
		float m=(float) Math.random();
		if(r>0.5f)
		{
			if(m>0.8f)
			{
				type = "attack";
			}
			else if(m>0.6f)
			{
				type = "intercept";
			}
			else
			{
				type = "defense";
			}
		}
		else
		{
			if(m>0.5f)
			{
				type = "scout1";
			}
			else
			{
				type = "scout2";
			}
		}
		
		CampaignFleetAPI fleet = getSector().createFleet("alien", type);
		getLocation().spawnFleet(getAnchor(), 0, 0, fleet);
		
		if (type.equals("scout1") || type.equals("scout2")) 
		{
			fleet.addAssignment(FleetAssignment.PATROL_SYSTEM, null, 60);
			fleet.addAssignment(FleetAssignment.GO_TO_LOCATION_AND_DESPAWN, getAnchor(), 1000);
		} 
		else if(type.equals("attack") || type.equals("intercept"))
		{
			fleet.addAssignment(FleetAssignment.ATTACK_LOCATION, station, 50);
		}
		else
		{
			fleet.addAssignment(FleetAssignment.DEFEND_LOCATION, getAnchor(), 30);
		}
		
		return fleet;
	}
	
}