package data.scripts.world;
import java.util.List;
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.CargoAPI;
import com.fs.starfarer.api.campaign.FactionAPI;
import com.fs.starfarer.api.campaign.StarSystemAPI;
import com.fs.starfarer.api.Global;
@SuppressWarnings("unchecked")
public class GRDefenseSpawnPoint extends BaseSpawnPoint {
public GRDefenseSpawnPoint(SectorAPI sector, LocationAPI location,
float daysInterval, int maxFleets, SectorEntityToken anchor) {
super(sector, location, daysInterval, maxFleets, anchor);
}
private CargoAPI playercargo;
@Override
public CampaignFleetAPI spawnFleet() {
// Faction pardon check
StarSystemAPI system = getSector().getStarSystem("Corvus");
List allFleets = system.getFleets();
for (int i = 0; i < allFleets.size(); i++) {
if (((CampaignFleetAPI) allFleets.get(i)).isPlayerFleet()) {
playercargo = ((CampaignFleetAPI) allFleets.get(i)).getCargo();
break;
}
}
//SectorEntityToken playerfleet = system.getEntityByName("Fleet");
SectorEntityToken station = system.getEntityByName("Orbital Depot");
CargoAPI cargo = station.getCargo();
//CargoAPI playercargo = playerfleet.getCargo();
FactionAPI player = getSector().getFaction("player");
float pvh = player.getRelationship("hegemony");
float pvi = player.getRelationship("independent");
float pvt = player.getRelationship("tritachyon");
float pvg = player.getRelationship("gunrunners");
float pvp = player.getRelationship("pirates");
if (pvh < 0) {
boolean haspardon = playercargo.removeItems(CargoAPI.CargoItemType.RESOURCES, "hpardon", 1);
if (haspardon) {
player.setRelationship("hegemony", 0);
Global.getSectorAPI().addMessage("The Gun Runners have worked their magic. The Hegemony has granted you a full pardon.");
cargo.addItems(CargoAPI.CargoItemType.RESOURCES, "hpardon", 1);
}}
if (pvi < 0) {
boolean haspardon = playercargo.removeItems(CargoAPI.CargoItemType.RESOURCES, "ipardon", 1);
if (haspardon) {
player.setRelationship("independent", 0);
Global.getSectorAPI().addMessage("The Gun Runners have worked their magic. The independents will see you as neutral now.");
cargo.addItems(CargoAPI.CargoItemType.RESOURCES, "ipardon", 1);
}}
if (pvt < 0) {
boolean haspardon = playercargo.removeItems(CargoAPI.CargoItemType.RESOURCES, "tpardon", 1);
if (haspardon) {
player.setRelationship("tritachyon", 0);
Global.getSectorAPI().addMessage("The Gun Runners have worked their magic. You've been erased from the Tri-Tachyon kill list.");
cargo.addItems(CargoAPI.CargoItemType.RESOURCES, "tpardon", 1);
}}
if (pvg < 0) {
boolean haspardon = playercargo.removeItems(CargoAPI.CargoItemType.RESOURCES, "gpardon", 1);
if (haspardon) {
player.setRelationship("gunrunners", 0);
Global.getSectorAPI().addMessage("The Gun Runners have officially forgiven your past transgressions.");
cargo.addItems(CargoAPI.CargoItemType.RESOURCES, "gpardon", 1);
}}
if (pvp < 0) {
boolean haspardon = playercargo.removeItems(CargoAPI.CargoItemType.RESOURCES, "ppardon", 1);
if (haspardon) {
player.setRelationship("pirates", 0);
Global.getSectorAPI().addMessage("The Gun Runners have worked their magic. Pirates across the sector will no longer hunt you.");
cargo.addItems(CargoAPI.CargoItemType.RESOURCES, "ppardon", 1);
}}
// Faction pardon check
CampaignFleetAPI fleet = getSector().createFleet("gunrunners", "defenseForce");
getLocation().spawnFleet(getAnchor(), 0, 0, fleet);
fleet.addAssignment(FleetAssignment.DEFEND_LOCATION, getAnchor(), 6);
fleet.addAssignment(FleetAssignment.GO_TO_LOCATION_AND_DESPAWN, getAnchor(), 1000);
return fleet;
}
}