001package com.fs.starfarer.api.impl.campaign.intel.bar.events; 002 003import java.util.LinkedHashSet; 004import java.util.Map; 005import java.util.Set; 006 007import com.fs.starfarer.api.Global; 008import com.fs.starfarer.api.campaign.CargoAPI; 009import com.fs.starfarer.api.campaign.InteractionDialogAPI; 010import com.fs.starfarer.api.campaign.OptionPanelAPI; 011import com.fs.starfarer.api.campaign.PlanetAPI; 012import com.fs.starfarer.api.campaign.TextPanelAPI; 013import com.fs.starfarer.api.campaign.econ.MarketAPI; 014import com.fs.starfarer.api.campaign.rules.MemoryAPI; 015import com.fs.starfarer.api.characters.FullName.Gender; 016import com.fs.starfarer.api.characters.PersonAPI; 017import com.fs.starfarer.api.impl.campaign.DebugFlags; 018import com.fs.starfarer.api.impl.campaign.ids.Factions; 019import com.fs.starfarer.api.impl.campaign.ids.Ranks; 020import com.fs.starfarer.api.impl.campaign.ids.Tags; 021import com.fs.starfarer.api.impl.campaign.procgen.themes.MiscellaneousThemeGenerator; 022import com.fs.starfarer.api.util.Misc; 023import com.fs.starfarer.api.util.WeightedRandomPicker; 024 025public class PlanetaryShieldBarEvent extends BaseBarEventWithPerson { 026 027 public static enum OptionId { 028 INIT, 029 APOLOGIZE, 030 CONTINUE_1, 031 CONTINUE_2, 032 WHERE_WAS_SYSTEM, 033 CONTINUE_3, 034 LEAVE, 035 036 } 037 038 public static PlanetAPI getTargetPlanet() { 039 return (PlanetAPI) Global.getSector().getMemoryWithoutUpdate().get(MiscellaneousThemeGenerator.PLANETARY_SHIELD_PLANET_KEY); 040 } 041 042 043 public PlanetaryShieldBarEvent() { 044 super(); 045 } 046 047 public boolean shouldShowAtMarket(MarketAPI market) { 048 if (!super.shouldShowAtMarket(market)) return false; 049 050 051 if (market.getFactionId().equals(Factions.LUDDIC_CHURCH) || 052 market.getFactionId().equals(Factions.LUDDIC_PATH)) { 053 return false; 054 } 055 056 if (getTargetPlanet() == null) return false; 057 058 if (Global.getSector().getIntelManager().hasIntelOfClass(PlanetaryShieldIntel.class)) { 059 return false; 060 } 061 062 if (Global.getSector().getPlayerStats().getLevel() < 10 && !DebugFlags.BAR_DEBUG) return false; 063 064 return true; 065 } 066 067 protected PersonAPI pilot; 068 protected MarketAPI pilotMarket = null; 069 @Override 070 protected void regen(MarketAPI market) { 071 if (this.market == market) return; 072 super.regen(market); 073 074 if (person.getGender() == Gender.MALE) { 075 person.setPortraitSprite(Global.getSettings().getSpriteName("intel", "old_spacer_male")); 076 } else { 077 person.setPortraitSprite(Global.getSettings().getSpriteName("intel", "old_spacer_female")); 078 } 079 080 pilot = Global.getSector().getFaction(Factions.INDEPENDENT).createRandomPerson(random); 081 pilot.setRankId(Ranks.PILOT); 082 pilot.setPostId(Ranks.POST_CITIZEN); 083 084 WeightedRandomPicker<MarketAPI> picker = new WeightedRandomPicker<MarketAPI>(random); 085 for (MarketAPI curr : Global.getSector().getEconomy().getMarketsInGroup(null)) { 086 if (curr == market) continue; 087 if (curr.isPlayerOwned()) continue; 088 if (curr.isHidden()) continue; 089 if (curr.isInvalidMissionTarget()) continue; 090 if (curr.getStabilityValue() <= 0) continue; 091 092 float w = curr.getSize(); 093 if (curr.isFreePort()) w += 10f; 094 picker.add(curr, w); 095 } 096 097 if (picker.isEmpty()) picker.add(market, 1f); 098 099 pilotMarket = picker.pick(); 100 } 101 102 @Override 103 public void addPromptAndOption(InteractionDialogAPI dialog, Map<String, MemoryAPI> memoryMap) { 104 super.addPromptAndOption(dialog, memoryMap); 105 106 regen(dialog.getInteractionTarget().getMarket()); 107 108 TextPanelAPI text = dialog.getTextPanel(); 109 text.addPara("A rough-looking veteran spacer with cybernetic eyes seems to be staring intently at you; " + 110 "it's a little unnerving."); 111 112// Color c = Misc.getHighlightColor(); 113// c = Misc.getHighlightedOptionColor(); 114 115 dialog.getOptionPanel().addOption("Ask the veteran spacer what " + getHeOrShe() + "'s looking at", this, 116 null); 117 } 118 119 120 @Override 121 public void init(InteractionDialogAPI dialog, Map<String, MemoryAPI> memoryMap) { 122 super.init(dialog, memoryMap); 123 124 done = false; 125 126 dialog.getVisualPanel().showPersonInfo(person, true); 127 128 optionSelected(null, OptionId.INIT); 129 } 130 131 @Override 132 public void optionSelected(String optionText, Object optionData) { 133 if (!(optionData instanceof OptionId)) { 134 return; 135 } 136 OptionId option = (OptionId) optionData; 137 138 OptionPanelAPI options = dialog.getOptionPanel(); 139 TextPanelAPI text = dialog.getTextPanel(); 140 options.clearOptions(); 141 142// continue 143// > Offer to apologize for the misunderstanding by buying $himOrHer a drink. 144// 145// exit 146// > Suggest that they read the manual then leave. 147 148 switch (option) { 149 case INIT: 150 text.addPara("\"Ain't nothing, I'm just reading my mail,\" " + getHeOrShe() + 151 " growls back. Then laughs, and taps " + getHisOrHer() + " temple. " + 152 "\"Swear I'll never get proper used to these things.\""); 153 options.addOption("Offer to apologize for the misunderstanding by buying " + getHimOrHer() + " a drink", OptionId.APOLOGIZE); 154 options.addOption("Suggest that " + getHeOrShe() + " read the manual then leave", OptionId.LEAVE); 155 break; 156 case APOLOGIZE: 157 text.addPara("The old space-hand opens up as one drink turns to two or three. " + 158 Misc.ucFirst(getHeOrShe()) + " tells stories of old injuries earned, including that of " + 159 getHisOrHer() + " lost eyes.\n\n\"Was just two survivors from that mission, me and the pilot. " + 160 "Lucky bastards, we two.\" It all began when " + getHeOrShe() + " was hired on to " + 161 "a salvage fleet trawling decivilized systems outside the Core Worlds. " + 162 "The loot was good, and any brigand they couldn't fight, they could flee." + 163 "\n\nThen the officers found something new in a data-cache. " + 164 "Rumours flew among the crew, who were told nothing, as the fleet suddenly left a rich " + 165 "asteroid belt to make for the outer system jump-point. " + 166 "They fared two hyperspace storms before arriving at a distant star system."); 167 168 options.addOption("Continue", OptionId.CONTINUE_1); 169 break; 170 case CONTINUE_1: 171 text.addPara("There they found a planet all shining and red. \"It weren't anything natural. " + 172 "It was all... shapes, angles, glowing like plasma. That's truth,\" " + getHeOrShe() + 173 " says quietly, \"I've seen Gates, sure, and orbital works big as you like. Ain't " + 174 "never seen anything Domain-made glow like that across a whole planet's face. " + 175 "Not anything that weren't a weapon, I mean.\""); 176 177 options.addOption("Continue", OptionId.CONTINUE_2); 178 break; 179 case CONTINUE_2: 180 text.addPara("\"While we were gawkin', the prox alarm goes and it's battle stations\", " + getHeOrShe() + 181 " continues. Hostile ships came fast upon the salvage fleet, flitting with agility " + 182 "belying advanced tech. They had equally advanced weapons, too, and with those they " + 183 "attacked with no mercy. \"It weren't pirates, nor military,\" here the spacer loses " + 184 getHisOrHer() + " cheer at a good story. \"Ludd's hells, I swear to you it weren't anything human.\""); 185 186 text.addPara("The spacer explains that just " + getHeOrShe() + " and the pilot got away in an " + 187 "escape pod which was only \"mostly\" malfunctioning. \"The miracle wasn't that I " + 188 "fixed it, it's that they could thaw enough of me out at the end of it for me to keep " + 189 "livin', if you call this livin'.\""); 190 191 options.addOption("\"Where was this system with the red planet?\"", OptionId.WHERE_WAS_SYSTEM); 192 break; 193 case WHERE_WAS_SYSTEM: 194 text.addPara("You emphasize your interest in the subject by having the spacer's drink refreshed. " + 195 Misc.ucFirst(getHeOrShe()) + " shakes " + getHisOrHer() + " head, \"Captain, " + 196 "I wouldn't wish my fate on you or anyone. Besides, I have no idea.\" A pause, then, " + 197 "\"" + pilot.getNameString() + " would - that's the pilot,\" " + getHeOrShe() + " finally admits."); 198 199 text.addPara("The old spacer tells you that " + pilot.getName().getFirst() + " did not live the experience in such " + 200 "stride as " + getHimOrHerself() + ", and has taken to drinking themselves senseless " + 201 "in semi-retirement " + pilotMarket.getOnOrAt() + " " + pilotMarket.getName() + ". " + 202 "\"Some folks, I don't think they react well " + 203 "to the emergency cryo-pods. Like a bit o' their brain is still froze up and not coming back.\""); 204 205 String icon = Global.getSettings().getSpriteName("intel", "red_planet"); 206 Set<String> tags = new LinkedHashSet<String>(); 207 tags.add(Tags.INTEL_MISSIONS); 208 209 dialog.getVisualPanel().showMapMarker(pilotMarket.getPrimaryEntity(), 210 "Destination: " + pilotMarket.getName(), pilotMarket.getFaction().getBaseUIColor(), 211 true, icon, null, tags); 212 213 options.addOption("Continue", OptionId.CONTINUE_3); 214 break; 215 case CONTINUE_3: 216 text.addPara("You consider a trip to " + pilotMarket.getName() + " to see if you can get the exact location of " + 217 "this mysterious planet with its unknown technology. You also realize that the old spacer " + 218 "has fallen asleep in " + getHisOrHer() + " seat, cybernetic eyes blanked out in standby mode."); 219 220 BarEventManager.getInstance().notifyWasInteractedWith(this); 221 addIntel(); 222 223 options.addOption("Leave the old spacer to " + getHisOrHer() + " rest", OptionId.LEAVE); 224 break; 225 case LEAVE: 226 noContinue = true; 227 done = true; 228 break; 229 } 230 } 231 232 233 protected void addIntel() { 234 CargoAPI cargo = Global.getSector().getPlayerFleet().getCargo(); 235 TextPanelAPI text = dialog.getTextPanel(); 236 237 PlanetAPI planet = getTargetPlanet(); 238 boolean success = false; 239 if (planet != null) { 240 PlanetaryShieldIntel intel = new PlanetaryShieldIntel(planet, this); 241 if (!intel.isDone()) { 242 Global.getSector().getIntelManager().addIntel(intel, false, text); 243 success = true; 244 } 245 } 246 247 if (!success) { 248 text.addPara("For a minute there, you were caught by the story, but you now see that following up " + 249 "on it would be a fool's errand."); 250 } 251 } 252 253 @Override 254 protected String getPersonFaction() { 255 return Factions.INDEPENDENT; 256 } 257 258 @Override 259 protected String getPersonRank() { 260 return Ranks.SPACE_SAILOR; 261 } 262 263 @Override 264 protected String getPersonPost() { 265 return Ranks.CITIZEN; 266 } 267 268 @Override 269 protected String getPersonPortrait() { 270 return null; 271 } 272 273 @Override 274 protected Gender getPersonGender() { 275 return Gender.ANY; 276 } 277 278 public PersonAPI getPilot() { 279 return pilot; 280 } 281 282 public MarketAPI getPilotMarket() { 283 return pilotMarket; 284 } 285 286} 287 288