001package com.fs.starfarer.api.impl.campaign.missions.academy; 002 003import java.awt.Color; 004 005import com.fs.starfarer.api.campaign.SectorEntityToken; 006import com.fs.starfarer.api.campaign.StarSystemAPI; 007import com.fs.starfarer.api.campaign.econ.MarketAPI; 008import com.fs.starfarer.api.impl.campaign.ids.Entities; 009import com.fs.starfarer.api.impl.campaign.ids.Factions; 010import com.fs.starfarer.api.impl.campaign.ids.FleetTypes; 011import com.fs.starfarer.api.impl.campaign.ids.Tags; 012import com.fs.starfarer.api.impl.campaign.missions.hub.ReqMode; 013import com.fs.starfarer.api.ui.TooltipMakerAPI; 014import com.fs.starfarer.api.util.Misc; 015 016public class GADerelictArtifact extends GABaseMission { 017 018 public static float MISSION_DAYS = 120f; 019 public static float PROB_PIRATES = 0.33f; 020 public static float PROB_SCAVENGER = 0.5f; 021 022 023 public static enum Stage { 024 GO_TO_DERELCIT, 025 GET_IT_FROM_PIRATES, 026 GET_IT_FROM_SCAVENGER, 027 RETURN_TO_ACADEMY, 028 COMPLETED, 029 FAILED, 030 } 031 032 public static enum Variation { 033 BASIC, 034 REMNANTS, 035 PIRATES, 036 SCAVENGER, 037 } 038 039 protected StarSystemAPI system; 040 protected SectorEntityToken entity; 041 protected StarSystemAPI pirateSystem; 042 protected String widget; 043 protected Variation variation; 044 protected int piratePayment; 045 protected int piratePaymentLow; 046 protected int scavPayment; 047 protected int scavPaymentHigh; 048 049 @Override 050 protected boolean create(MarketAPI createdAt, boolean barEvent) { 051 // if this mission type was already accepted by the player, abort 052 if (!setGlobalReference("$gaDA_ref")) { 053 return false; 054 } 055 056 pickDepartment(GADepartments.INDUSTRIAL, GADepartments.SOCIAL, 057 GADepartments.MILITARY, GADepartments.SCIENCE, GADepartments.WEIRD); 058 widget = pickOne( "unique superconducting structural element", 059 "an advanced field conversion prototype", 060 "a transparametric integrator", 061 "an extremely rare material sample", 062 "an uncommon power system component", 063 "a Domain-era forge component", 064 "a small-scale momentum decoupling device", 065 "a fascinating low-power field projector"); 066 067 requireSystemTags(ReqMode.ANY, Tags.THEME_REMNANT_RESURGENT, Tags.THEME_REMNANT_SUPPRESSED, 068 Tags.THEME_DERELICT, Tags.THEME_MISC, Tags.THEME_RUINS); 069 //requireSystemTags(ReqMode.ANY, Tags.THEME_REMNANT_RESURGENT, Tags.THEME_REMNANT_SUPPRESSED); 070 requireSystemTags(ReqMode.NOT_ANY, Tags.THEME_REMNANT_SECONDARY); // remove not-very-dangerous remnant systems 071 preferSystemUnexplored(); 072 preferSystemInDirectionOfOtherMissions(); 073 074 system = pickSystem(); 075 if (system == null) return false; 076 077 entity = spawnDerelictOfType(null, new LocData(EntityLocationType.HIDDEN, null, system, false)); 078 if (entity == null) return false; 079 080 setStartingStage(Stage.GO_TO_DERELCIT); 081 addSuccessStages(Stage.COMPLETED); 082 addFailureStages(Stage.FAILED); 083 084 makeImportant(entity, "$gaDA_entity", Stage.GO_TO_DERELCIT); 085 makeImportant(getPerson(), "$gaDA_returnHere", Stage.RETURN_TO_ACADEMY); 086 087 connectWithGlobalFlag(Stage.GO_TO_DERELCIT, Stage.GET_IT_FROM_PIRATES, "$gaDA_piratesTookIt"); 088 connectWithGlobalFlag(Stage.GO_TO_DERELCIT, Stage.GET_IT_FROM_SCAVENGER, "$gaDA_scavengerTookIt"); 089 setStageOnGlobalFlag(Stage.RETURN_TO_ACADEMY, "$gaDA_gotWidget"); 090 connectWithGlobalFlag(Stage.RETURN_TO_ACADEMY, Stage.COMPLETED, "$gaDA_returnedWidget"); 091 092 if (WITH_TIME_LIMIT) { 093 setTimeLimit(Stage.FAILED, MISSION_DAYS, entity.getStarSystem(), Stage.RETURN_TO_ACADEMY); 094 } 095 //setCreditReward(30000, 40000); 096 setCreditReward(CreditReward.AVERAGE); 097 setDefaultGARepRewards(); 098 099 if (system.hasTag(Tags.THEME_REMNANT)) { 100 variation = Variation.REMNANTS; 101 //setCreditReward(50000, 60000); 102 setCreditReward(CreditReward.HIGH); 103 } else { 104 if (rollProbability(PROB_PIRATES)) { 105 variation = Variation.PIRATES; 106 } else if (rollProbability(PROB_SCAVENGER)) { 107 variation = Variation.SCAVENGER; 108 } else { 109 variation = Variation.BASIC; 110 } 111 } 112 113 setMapMarkerNameColorBasedOnStar(system); 114 115// variation = Variation.BASIC; 116// variation = Variation.PIRATES; 117// variation = Variation.SCAVENGER; 118 119 if (variation == Variation.PIRATES) { 120 requireSystemTags(ReqMode.ANY, Tags.THEME_MISC_SKIP, Tags.THEME_DERELICT, Tags.THEME_MISC, Tags.THEME_RUINS); 121 requireSystemTags(ReqMode.NOT_ANY, Tags.THEME_UNSAFE); 122 requireSystemNot(system); 123 requireSystemWithinRangeOf(entity.getLocationInHyperspace(), 10); 124 pirateSystem = pickSystem(); 125 if (pirateSystem == null) return false; 126 127 piratePayment = genRoundNumber(10000, 15000); 128 piratePaymentLow = genRoundNumber(2000, 5000); 129 130 beginStageTrigger(Stage.GET_IT_FROM_PIRATES); 131 triggerSpawnEntity(Entities.SUPPLY_CACHE, new LocData(EntityLocationType.HIDDEN, null, pirateSystem, false)); 132 triggerSaveGlobalEntityRef("$gaDA_cache"); 133 triggerCreateFleet(FleetSize.LARGE, FleetQuality.DEFAULT, Factions.PIRATES, FleetTypes.PATROL_MEDIUM, pirateSystem); 134 triggerAutoAdjustFleetStrengthMajor(); 135 triggerSetStandardHostilePirateFlags(); 136 triggerMakeFleetIgnoredByOtherFleets(); 137 triggerPickLocationAtInSystemJumpPoint(pirateSystem); 138 triggerSpawnFleetAtPickedLocation(); 139 triggerOrderFleetPatrolEntity(true); 140 triggerFleetMakeImportant("$gaDA_pirate", Stage.GET_IT_FROM_PIRATES); 141 triggerFleetAddDefeatTrigger("gaDAFleetWithWidgetDefeated"); 142 endTrigger(); 143 } else if (variation == Variation.SCAVENGER) { 144 scavPayment = genRoundNumber(10000, 15000); 145 scavPaymentHigh = genRoundNumber(20000, 25000); 146 147 beginStageTrigger(Stage.GET_IT_FROM_SCAVENGER); 148 triggerCreateFleet(FleetSize.MEDIUM, FleetQuality.LOWER, Factions.SCAVENGERS, FleetTypes.SCAVENGER_MEDIUM, system); 149 triggerAutoAdjustFleetStrengthModerate(); 150 triggerSetFleetFaction(Factions.INDEPENDENT); 151 152// triggerFleetSetSingleShipOnly(); 153// triggerFleetSetAllWeapons(); 154// triggerFleetSetFlagship("radiant_Standard"); 155// triggerFleetSetOfficers(OfficerNum.FC_ONLY, OfficerQuality.AI_ALPHA); 156 157 triggerMakeLowRepImpact(); 158 159 triggerPickLocationAtClosestToPlayerJumpPoint(system); 160 triggerSetEntityToPickedJumpPoint(); 161 triggerPickLocationAroundEntity(5000); 162 triggerSpawnFleetAtPickedLocation(); 163 164 triggerFleetSetTravelActionText("exploring system"); 165 triggerFleetSetPatrolActionText("preparing to leave system"); 166 triggerOrderFleetPatrolEntity(false); 167 168 triggerFleetMakeImportant("$gaDA_scavenger", Stage.GET_IT_FROM_SCAVENGER); 169 triggerFleetAddDefeatTrigger("gaDAFleetWithWidgetDefeated"); 170 endTrigger(); 171 } 172 173 return true; 174 } 175 176 protected void updateInteractionDataImpl() { 177 set("$gaDA_department", department); 178 set("$gaDA_widget", widget); 179 set("$gaDA_widgetNoArticle", getWidgetWithoutArticle()); 180 set("$gaDA_starName", entity.getStarSystem().getNameWithNoType()); 181 set("$gaDA_systemName", entity.getStarSystem().getNameWithLowercaseTypeShort()); 182 set("$gaDA_dist", getDistanceLY(entity)); 183 set("$gaDA_fuel", getFuel(entity, true)); 184 set("$gaDA_reward", Misc.getWithDGS(getCreditsReward())); 185 set("$gaDA_piratePayment", Misc.getWithDGS(piratePayment)); 186 set("$gaDA_piratePaymentLow", Misc.getWithDGS(piratePaymentLow)); 187 set("$gaDA_scavPayment", Misc.getWithDGS(scavPayment)); 188 set("$gaDA_scavPaymentHigh", Misc.getWithDGS(scavPaymentHigh)); 189 190 set("$gaDA_notRemnants", variation != Variation.REMNANTS); 191 set("$gaDA_variation", variation); 192 } 193 194 protected String getWidgetWithoutArticle() { 195 if (widget.startsWith("a ")) { 196 return widget.replaceFirst("a ", ""); 197 } 198 if (widget.startsWith("an ")) { 199 return widget.replaceFirst("an ", ""); 200 } 201 return widget; 202 } 203 204 @Override 205 public void addDescriptionForNonEndStage(TooltipMakerAPI info, float width, float height) { 206 float opad = 10f; 207 Color h = Misc.getHighlightColor(); 208 if (currentStage == Stage.GO_TO_DERELCIT) { 209 String extra = ""; 210 if (variation == Variation.REMNANTS) extra = " 'Autonomous weapon systems' may pose a danger."; 211 info.addPara("Retrieve " + widget + " from a derelict ship " + getLocated(entity) + "." + extra, opad); 212 } else if (currentStage == Stage.GET_IT_FROM_PIRATES) { 213 SectorEntityToken cache = getEntityFromGlobal("$gaDA_cache"); 214 info.addPara("Retrieve the " + getWidgetWithoutArticle() + 215 " from the pirates as they resupply from a cache " + getLocated(cache) + ".", opad); 216 } else if (currentStage == Stage.GET_IT_FROM_SCAVENGER) { 217 info.addPara("Go to the nearest jump-point and retrieve the " + getWidgetWithoutArticle() + 218 " from scavengers before they leave the system.", opad); 219 } else if (currentStage == Stage.RETURN_TO_ACADEMY) { 220 info.addPara("Return the " + getWidgetWithoutArticle() + " to the Galatia Academy and talk to " + 221 getPerson().getNameString() + " to receive your reward.", opad); 222 } 223 } 224 225 @Override 226 public boolean addNextStepText(TooltipMakerAPI info, Color tc, float pad) { 227 Color h = Misc.getHighlightColor(); 228 if (currentStage == Stage.GO_TO_DERELCIT) { 229 if (system.isCurrentLocation()) { 230 info.addPara("Retrieve the " + getWidgetWithoutArticle() + " from a derelict ship", tc, pad); 231 } else { 232 info.addPara(getGoToSystemTextShort(system), tc, pad); 233 } 234 return true; 235 } else if (currentStage == Stage.GET_IT_FROM_PIRATES) { 236 info.addPara("Retrieve the " + getWidgetWithoutArticle() + " from pirates in the " + 237 pirateSystem.getNameWithLowercaseType(), tc, pad); 238 } else if (currentStage == Stage.GET_IT_FROM_SCAVENGER) { 239 info.addPara("Retrieve the " + getWidgetWithoutArticle() + " from scavengers at the nearest jump-point", 240 tc, pad); 241 } else if (currentStage == Stage.RETURN_TO_ACADEMY) { 242 info.addPara("Return to the Galatia Academy and talk to " + getPerson().getNameString(), tc, pad); 243 return true; 244 } 245 return false; 246 } 247 248 @Override 249 public String getBaseName() { 250 return "Derelict Artifact Recovery"; 251 } 252 253} 254 255