package data.scripts.world;

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;

public class TradeSpawnPoint extends BaseSpawnPoint {

	public TradeSpawnPoint(SectorAPI sector, LocationAPI location, 
							float daysInterval, int maxFleets, SectorEntityToken anchor) {
		super(sector, location, daysInterval, maxFleets, anchor);
	}

	@Override
	protected CampaignFleetAPI spawnFleet() {
		
		String type = null;
		float r = (float) Math.random();
		if (r > 0.9f) {
			type = "DG";
		} else if (r > 0.75f) {
			type = "LTF";
		} else if (r > 0.6f) {
			type = "STF"; 
		} else {
			type = "SU";
		} 
		
		
		CampaignFleetAPI fleet = getSector().createFleet("Trade", type);
		getLocation().spawnFleet(getAnchor(), 0, 0, fleet);
		
		
		if (type.equals("STF") || type.equals("SU") || type.equals("LTF"))  {
			      StarSystemAPI system = getSector().getStarSystem("Corvus");
                  SectorEntityToken hgstation = system.getEntityByName("Orbital Station");
                  SectorEntityToken ttstation = system.getEntityByName("Corporate HQ");
			fleet.addAssignment(FleetAssignment.RAID_SYSTEM, null, 10);
			fleet.addAssignment(FleetAssignment.GO_TO_LOCATION_AND_DESPAWN, getAnchor(), 1000);
		} else {
			if ((float) Math.random() > 0.5f) {
				fleet.addAssignment(FleetAssignment.RAID_SYSTEM, null, 30);
				fleet.addAssignment(FleetAssignment.GO_TO_LOCATION_AND_DESPAWN, getAnchor(), 1000);
			} else {
				fleet.addAssignment(FleetAssignment.DEFEND_LOCATION, getAnchor(), 20);
				fleet.addAssignment(FleetAssignment.GO_TO_LOCATION_AND_DESPAWN, getAnchor(), 1000);
			}
		}
		
		return fleet;
	}

}
