package data.scripts.world.corvus;

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 HegeSpawnPoint extends BaseSpawnPoint 
{

	private final SectorEntityToken station;

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

	@Override
	protected CampaignFleetAPI spawnFleet() 
	{
		//if ((float) Math.random() < 0.5f) return null;
		String type = null;
		float r = (float) Math.random();
		float p = 1.00f - r;
		
		//       p   0.00f
		if      (p < 0.250f) type = "patrol1";          // 25%
		else if (p < 0.500f) type = "patrol"; // 25%
		else if (p < 0.700f) type = "assault";    // 20%
		else if (p < 0.875f) type = "systemDefense";     // 17.5%
		else  /* p < 1.000f*/type = "capitalfleet";     // 12.5%
		
		
		CampaignFleetAPI fleet = getSector().createFleet("hegemony", type);
		getLocation().spawnFleet(getAnchor(), 0, 0, fleet);
    
		StarSystemAPI system = getSector().getStarSystem("Corvus");

		if(type.equals("patrol1") || type.equals("patrol2"))
		{
			fleet.addAssignment(FleetAssignment.PATROL_SYSTEM, null, 60);
			fleet.addAssignment(FleetAssignment.GO_TO_LOCATION_AND_DESPAWN, getAnchor(), 1000);
		}
		else
			fleet.addAssignment(FleetAssignment.ATTACK_LOCATION, station, 50);

		return fleet;
	}

}
