001package com.fs.starfarer.api.impl.campaign.intel.bar.events;
002
003import java.util.List;
004import java.util.Map;
005import java.util.Set;
006
007import java.awt.Color;
008
009import com.fs.starfarer.api.Global;
010import com.fs.starfarer.api.campaign.CampaignFleetAPI;
011import com.fs.starfarer.api.campaign.CargoAPI;
012import com.fs.starfarer.api.campaign.FactionAPI;
013import com.fs.starfarer.api.campaign.InteractionDialogAPI;
014import com.fs.starfarer.api.campaign.PlanetAPI;
015import com.fs.starfarer.api.campaign.SectorEntityToken;
016import com.fs.starfarer.api.campaign.econ.MarketAPI;
017import com.fs.starfarer.api.campaign.rules.MemoryAPI;
018import com.fs.starfarer.api.characters.PersonAPI;
019import com.fs.starfarer.api.impl.campaign.ids.Tags;
020import com.fs.starfarer.api.impl.campaign.intel.BaseIntelPlugin;
021import com.fs.starfarer.api.impl.campaign.rulecmd.AddRemoveCommodity;
022import com.fs.starfarer.api.ui.SectorMapAPI;
023import com.fs.starfarer.api.ui.TooltipMakerAPI;
024import com.fs.starfarer.api.util.Misc;
025import com.fs.starfarer.api.util.Misc.Token;
026
027public class PlanetaryShieldIntel extends BaseIntelPlugin {
028
029        public static enum PSIStage {
030                TALK_TO_PILOT,
031                GO_TO_PLANET,
032                DONE,
033                ;
034        }
035        
036        public static int FINISHED_XP = 20000;
037        public static int PAY_PILOT_XP = 5000;
038        
039        protected PlanetAPI planet;
040        protected PlanetaryShieldBarEvent event;
041        
042        protected PSIStage stage;
043        protected int pilotCredits;
044        
045        public PlanetaryShieldIntel(PlanetAPI planet, PlanetaryShieldBarEvent event) {
046                this.planet = planet;
047                this.event = event;
048                
049                PersonAPI pilot = event.getPilot();
050                Misc.makeImportant(pilot, "psi");
051                MarketAPI market = event.getPilotMarket();
052                market.addPerson(pilot);
053                market.getCommDirectory().addPerson(pilot);
054                
055                pilotCredits = 10000 + 1000 * Misc.random.nextInt(10);
056                
057                pilot.getMemoryWithoutUpdate().set("$psi_isPilot", true);
058                pilot.getMemoryWithoutUpdate().set("$psi_eventRef", this);
059                pilot.getMemoryWithoutUpdate().set("$psi_credits", Misc.getDGSCredits(pilotCredits));
060                
061                //Misc.makeImportant(planet, "saci");
062                //cache.getMemoryWithoutUpdate().set("$saic_eventRef", this);
063                //Global.getSector().addScript(this);
064                
065                stage = PSIStage.TALK_TO_PILOT;
066        }
067        
068        @Override
069        protected void notifyEnded() {
070                super.notifyEnded();
071                Global.getSector().removeScript(this);
072                
073                PersonAPI pilot = event.getPilot();
074                MarketAPI market = event.getPilotMarket();
075                market.removePerson(pilot);
076                market.getCommDirectory().removePerson(pilot);
077                Misc.makeUnimportant(planet, "psi");
078        }
079
080
081
082        @Override
083        public boolean callEvent(String ruleId, InteractionDialogAPI dialog,
084                                                         List<Token> params, Map<String, MemoryAPI> memoryMap) {
085                String action = params.get(0).getString(memoryMap);
086                
087                CampaignFleetAPI playerFleet = Global.getSector().getPlayerFleet();
088                CargoAPI cargo = playerFleet.getCargo();
089                //MemoryAPI memory = planet.getMemoryWithoutUpdate();
090                
091                PersonAPI pilot = event.getPilot();
092                MarketAPI market = event.getPilotMarket();
093                
094                if (action.equals("prepare")) {
095                        pilot.getMemoryWithoutUpdate().set("$psi_credits", Misc.getDGSCredits(pilotCredits), 0);
096                        pilot.getMemoryWithoutUpdate().set("$psi_playerCredits", Misc.getDGSCredits(cargo.getCredits().get()), 0);
097                } else if (action.equals("canPay")) {
098                        return cargo.getCredits().get() >= pilotCredits;
099                } else if (action.equals("payPilot")) {
100                        market.removePerson(pilot);
101                        market.getCommDirectory().removePerson(pilot);
102                        
103                        cargo.getCredits().subtract(pilotCredits);
104                        AddRemoveCommodity.addCreditsLossText(pilotCredits, dialog.getTextPanel());
105                        Global.getSector().getPlayerPerson().getStats().addXP(PAY_PILOT_XP, dialog.getTextPanel());
106
107                        Misc.makeImportant(planet, "psi");
108                        stage = PSIStage.GO_TO_PLANET;
109                        sendUpdate(PSIStage.GO_TO_PLANET, dialog.getTextPanel());
110                }
111                
112                return true;
113        }
114        
115        @Override
116        public void endAfterDelay() {
117                stage = PSIStage.DONE;
118                Misc.makeUnimportant(planet, "psi");
119                super.endAfterDelay();
120        }
121
122        @Override
123        protected void notifyEnding() {
124                super.notifyEnding();
125        }
126
127
128        protected void addBulletPoints(TooltipMakerAPI info, ListInfoMode mode) {
129                
130                Color h = Misc.getHighlightColor();
131                Color g = Misc.getGrayColor();
132                float pad = 3f;
133                float opad = 10f;
134                
135                float initPad = pad;
136                if (mode == ListInfoMode.IN_DESC) initPad = opad;
137                
138                Color tc = getBulletColorForMode(mode);
139                
140                bullet(info);
141                boolean isUpdate = getListInfoParam() != null;
142                
143                MarketAPI market = event.getPilotMarket();
144                
145                if (stage == PSIStage.TALK_TO_PILOT) {
146                        info.addPara("Talk to the pilot at %s", initPad, tc, market.getFaction().getBaseUIColor(), market.getName());
147                } else if (stage == PSIStage.GO_TO_PLANET) {
148                        info.addPara("Explore the planet", tc, initPad);
149                }
150                
151                initPad = 0f;
152                
153                unindent(info);
154        }
155        
156        
157        @Override
158        public void createIntelInfo(TooltipMakerAPI info, ListInfoMode mode) {
159                Color c = getTitleColor(mode);
160                info.setParaSmallInsignia();
161                info.addPara(getName(), c, 0f);
162                info.setParaFontDefault();
163                addBulletPoints(info, mode);
164                
165        }
166        
167        @Override
168        public void createSmallDescription(TooltipMakerAPI info, float width, float height) {
169                Color h = Misc.getHighlightColor();
170                Color g = Misc.getGrayColor();
171                Color tc = Misc.getTextColor();
172                float pad = 3f;
173                float opad = 10f;
174
175                if (stage == PSIStage.TALK_TO_PILOT) {
176                        info.addPara("An old spacer told you a tale about a mysterious red planet. " +
177                                                 "The pilot - the only other survivor of the salvage expedition - may know the planet's location.", opad);
178                } else if (stage == PSIStage.GO_TO_PLANET) {
179                        info.addPara("You've talked to the old spacer's pilot comrade and convinced " +
180                                                 "them to divulge the location of the planet.", opad);
181                } else {
182                        info.addPara("You've found the planet and uncovered its secret.", opad);
183                }
184
185                addBulletPoints(info, ListInfoMode.IN_DESC);
186                
187        }
188        
189        @Override
190        public String getIcon() {
191                return Global.getSettings().getSpriteName("intel", "red_planet");
192        }
193        
194        @Override
195        public Set<String> getIntelTags(SectorMapAPI map) {
196                Set<String> tags = super.getIntelTags(map);
197                tags.add(Tags.INTEL_STORY);
198                tags.add(Tags.INTEL_EXPLORATION);
199                tags.add(Tags.INTEL_ACCEPTED);
200                tags.add(Tags.INTEL_MISSIONS);
201                return tags;
202        }
203        
204        @Override
205        public IntelSortTier getSortTier() {
206                return IntelSortTier.TIER_2;
207        }
208
209        public String getSortString() {
210                return "Red Planet";
211        }
212        
213        public String getName() {
214                if (isEnded() || isEnding()) {
215                        return "Red Planet - Completed";
216                }
217                return "Red Planet";
218        }
219        
220        @Override
221        public FactionAPI getFactionForUIColors() {
222                return super.getFactionForUIColors();
223        }
224
225        public String getSmallDescriptionTitle() {
226                return getName();
227        }
228
229        @Override
230        public SectorEntityToken getMapLocation(SectorMapAPI map) {
231                if (stage == PSIStage.TALK_TO_PILOT) {
232                        return event.getPilotMarket().getPrimaryEntity();
233                }
234                return planet;
235        }
236        
237        @Override
238        public boolean shouldRemoveIntel() {
239                return super.shouldRemoveIntel();
240        }
241
242        @Override
243        public String getCommMessageSound() {
244                return getSoundMajorPosting();
245        }
246                
247}
248
249
250
251
252
253
254