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

	public GRRaiderSpawnPoint(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 > .60f) {
			type = "raider";
		} else if (r > 0.15f) {
			type = "smuggler";
		} else {
			type = "smuggler2";
		}
		
		CampaignFleetAPI fleet = getSector().createFleet("gunrunners", type);
		getLocation().spawnFleet(getAnchor(), 0, 0, fleet);
		
		
		if (type.equals("smuggler") || type.equals("smuggler2")) {
      StarSystemAPI system = getSector().getStarSystem("Corvus");
      SectorEntityToken hgstation = system.getEntityByName("Orbital Station");
      SectorEntityToken ttstation = system.getEntityByName("Orbital Headquarters");
      if (ttstation == null) {
        ttstation = system.getEntityByName("Corvus IV");}
      if ((float) Math.random() > 0.5f) {
        fleet.addAssignment(FleetAssignment.GO_TO_LOCATION, hgstation, 20);
        fleet.addAssignment(FleetAssignment.GO_TO_LOCATION, ttstation, 20);
        fleet.addAssignment(FleetAssignment.GO_TO_LOCATION_AND_DESPAWN, getAnchor(), 1000);
			} else {
        fleet.addAssignment(FleetAssignment.GO_TO_LOCATION, ttstation, 20);
        fleet.addAssignment(FleetAssignment.GO_TO_LOCATION, hgstation, 20);
        fleet.addAssignment(FleetAssignment.GO_TO_LOCATION_AND_DESPAWN, getAnchor(), 1000);
			}
		} else {
				fleet.addAssignment(FleetAssignment.RAID_SYSTEM, null, 30);
				fleet.addAssignment(FleetAssignment.GO_TO_LOCATION_AND_DESPAWN, getAnchor(), 1000);
		}
		return fleet;
	}

}
