001package com.fs.starfarer.api.impl.campaign.rulecmd.salvage; 002 003import java.util.List; 004import java.util.Map; 005import java.util.Random; 006 007import com.fs.starfarer.api.Global; 008import com.fs.starfarer.api.campaign.CampaignFleetAPI; 009import com.fs.starfarer.api.campaign.CargoAPI; 010import com.fs.starfarer.api.campaign.CoreInteractionListener; 011import com.fs.starfarer.api.campaign.FactionAPI; 012import com.fs.starfarer.api.campaign.InteractionDialogAPI; 013import com.fs.starfarer.api.campaign.OptionPanelAPI; 014import com.fs.starfarer.api.campaign.PlanetAPI; 015import com.fs.starfarer.api.campaign.SectorEntityToken; 016import com.fs.starfarer.api.campaign.SpecialItemData; 017import com.fs.starfarer.api.campaign.TextPanelAPI; 018import com.fs.starfarer.api.campaign.econ.MarketAPI; 019import com.fs.starfarer.api.campaign.listeners.ListenerUtil; 020import com.fs.starfarer.api.campaign.rules.MemoryAPI; 021import com.fs.starfarer.api.impl.campaign.econ.impl.PlanetaryShield; 022import com.fs.starfarer.api.impl.campaign.ids.MemFlags; 023import com.fs.starfarer.api.impl.campaign.intel.bar.events.PlanetaryShieldIntel; 024import com.fs.starfarer.api.impl.campaign.intel.bar.events.PlanetaryShieldIntel.PSIStage; 025import com.fs.starfarer.api.impl.campaign.procgen.SalvageEntityGenDataSpec.DropData; 026import com.fs.starfarer.api.impl.campaign.procgen.themes.MiscellaneousThemeGenerator; 027import com.fs.starfarer.api.impl.campaign.rulecmd.BaseCommandPlugin; 028import com.fs.starfarer.api.impl.campaign.rulecmd.salvage.special.BaseSalvageSpecial; 029import com.fs.starfarer.api.util.Misc; 030import com.fs.starfarer.api.util.Misc.Token; 031 032/** 033 * 034 */ 035public class RedPlanet extends BaseCommandPlugin { 036 037 protected CampaignFleetAPI playerFleet; 038 protected SectorEntityToken entity; 039 protected PlanetAPI planet; 040 protected FactionAPI playerFaction; 041 protected FactionAPI entityFaction; 042 protected TextPanelAPI text; 043 protected OptionPanelAPI options; 044 protected CargoAPI playerCargo; 045 protected MemoryAPI memory; 046 protected MarketAPI market; 047 protected InteractionDialogAPI dialog; 048 protected Map<String, MemoryAPI> memoryMap; 049 protected FactionAPI faction; 050 051 052 public RedPlanet() { 053 } 054 055 public RedPlanet(SectorEntityToken entity) { 056 init(entity); 057 } 058 059 protected void init(SectorEntityToken entity) { 060 memory = entity.getMemoryWithoutUpdate(); 061 this.entity = entity; 062 planet = (PlanetAPI) entity; 063 playerFleet = Global.getSector().getPlayerFleet(); 064 playerCargo = playerFleet.getCargo(); 065 066 playerFaction = Global.getSector().getPlayerFaction(); 067 entityFaction = entity.getFaction(); 068 069 faction = entity.getFaction(); 070 071 market = entity.getMarket(); 072 073 074 } 075 076 public boolean execute(String ruleId, InteractionDialogAPI dialog, List<Token> params, Map<String, MemoryAPI> memoryMap) { 077 this.dialog = dialog; 078 this.memoryMap = memoryMap; 079 080 String command = params.get(0).getString(memoryMap); 081 if (command == null) return false; 082 083 entity = dialog.getInteractionTarget(); 084 init(entity); 085 086 memory = getEntityMemory(memoryMap); 087 088 text = dialog.getTextPanel(); 089 options = dialog.getOptionPanel(); 090 091 if (command.equals("genLoot")) { 092 genLoot(); 093 } 094 095 return true; 096 } 097 098 protected void genLoot() { 099 100 OptionPanelAPI options = dialog.getOptionPanel(); 101 TextPanelAPI text = dialog.getTextPanel(); 102 103 MemoryAPI memory = planet.getMemoryWithoutUpdate(); 104 long seed = memory.getLong(MemFlags.SALVAGE_SEED); 105 Random random = Misc.getRandom(seed, 100); 106 107 DropData d = new DropData(); 108 d.chances = 5; 109 d.group = "blueprints"; 110 planet.addDropRandom(d); 111 112 d = new DropData(); 113 d.chances = 1; 114 d.group = "rare_tech"; 115 planet.addDropRandom(d); 116 117 CargoAPI salvage = SalvageEntity.generateSalvage(random, 1f, 1f, 1f, 1f, planet.getDropValue(), planet.getDropRandom()); 118 CargoAPI extra = BaseSalvageSpecial.getCombinedExtraSalvage(memoryMap); 119 salvage.addAll(extra); 120 BaseSalvageSpecial.clearExtraSalvage(memoryMap); 121 if (!extra.isEmpty()) { 122 ListenerUtil.reportExtraSalvageShown(planet); 123 } 124 salvage.addSpecial(new SpecialItemData("industry_bp", "planetaryshield"), 1); 125 salvage.sort(); 126 127 dialog.getVisualPanel().showLoot("Salvaged", salvage, false, true, true, new CoreInteractionListener() { 128 public void coreUIDismissed() { 129 dialog.dismiss(); 130 dialog.hideTextPanel(); 131 dialog.hideVisualPanel(); 132 133 PlanetaryShieldIntel intel = (PlanetaryShieldIntel) Global.getSector().getIntelManager().getFirstIntel(PlanetaryShieldIntel.class); 134 if (intel != null) { 135 Global.getSector().addScript(intel); 136 intel.endAfterDelay(); 137 //intel.sendUpdate(PSIStage.DONE, textPanel); 138 intel.sendUpdateIfPlayerHasIntel(PSIStage.DONE, false); 139 } 140 long xp = PlanetaryShieldIntel.FINISHED_XP; 141 Global.getSector().getPlayerPerson().getStats().addXP(xp); 142 } 143 }); 144 options.clearOptions(); 145 dialog.setPromptText(""); 146 147 148 planet.getMemoryWithoutUpdate().unset(MiscellaneousThemeGenerator.PLANETARY_SHIELD_PLANET); 149 Global.getSector().getMemoryWithoutUpdate().unset(MiscellaneousThemeGenerator.PLANETARY_SHIELD_PLANET_KEY); 150 PlanetaryShield.unapplyVisuals(planet); 151 152// if (keptPromise) { 153// if (random.nextFloat() > 0.5f) { 154// SectorEntityToken loc = planet.getContainingLocation().createToken(planet.getLocation()); 155// spawnPiratesToInvestigate(loc, 50f + random.nextFloat() * 50f); 156// if (random.nextFloat() > 0.5f) { 157// spawnPiratesToInvestigate(loc, 50f + random.nextFloat() * 50f); 158// } 159// } 160// } 161 } 162 163} 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183