001package com.fs.starfarer.api.impl.campaign.missions;
002
003import java.awt.Color;
004
005import com.fs.starfarer.api.campaign.PlanetAPI;
006import com.fs.starfarer.api.campaign.econ.MarketAPI;
007import com.fs.starfarer.api.characters.PersonAPI;
008import com.fs.starfarer.api.impl.campaign.ids.Conditions;
009import com.fs.starfarer.api.impl.campaign.ids.Tags;
010import com.fs.starfarer.api.impl.campaign.missions.hub.HubMissionWithBarEvent;
011import com.fs.starfarer.api.impl.campaign.missions.hub.ReqMode;
012import com.fs.starfarer.api.ui.TooltipMakerAPI;
013import com.fs.starfarer.api.util.Misc;
014
015public class RuinsDataSwapMission extends HubMissionWithBarEvent {
016
017        //public static float PIRATE_PROB = 0.5f;
018        public static float MISSION_DAYS = 120f;
019        public static int RAID_DIFFICULTY = 60;
020        public static int MARINES_REQUIRED = RAID_DIFFICULTY / 2;
021        
022        
023        public static enum Stage {
024                GO_TO_RUINS,
025                RETURN,
026                COMPLETED,
027                FAILED,
028        }
029        
030        public static enum Variation {
031                BASIC,
032                DECIV,
033        }
034        
035        protected MarketAPI market;
036        protected PersonAPI person;
037        protected PlanetAPI planet;
038        protected String targetWithArticle;
039        protected String target;
040        protected String megacorp;
041        protected Variation variation;
042        //protected int piratePayment;
043        
044        @Override
045        protected boolean create(MarketAPI createdAt, boolean barEvent) {
046                // if this mission type was already accepted by the player, abort
047                if (!setGlobalReference("$rdsm_ref")) {
048                        return false;
049                }
050                
051                targetWithArticle = pickOne("a library", "a datavault", "an archive", "a laboratory");
052                target = targetWithArticle.substring(targetWithArticle.indexOf(" ") + 1);
053                
054                megacorp = pickOne("Fabrique Orbitale", "Bhilai Exospace", "Hastaeus Industries", "Exogen Systems", "Ursa Group");
055                
056                resetSearch();
057                requireSystemTags(ReqMode.ANY, Tags.THEME_REMNANT_SUPPRESSED, Tags.THEME_DERELICT, Tags.THEME_MISC, Tags.THEME_RUINS);
058                requireSystemTags(ReqMode.NOT_ANY, Tags.THEME_SPECIAL);
059                //requireSystemInInnerSector();
060                //requireSystemHasPulsar();
061                //requireSystemIsDense();
062                //requirePlanetIsGasGiant();
063                //requirePlanetConditions(ReqMode.ALL, Conditions.DECIVILIZED);
064                requirePlanetUnpopulated();
065                requirePlanetWithRuins();
066                preferPlanetNotFullySurveyed();
067                preferPlanetUnexploredRuins();
068                preferPlanetInDirectionOfOtherMissions();
069                planet = pickPlanet();
070                
071//              spawnEntity(Entities.INACTIVE_GATE, "$gaData_test", EntityLocationType.ORBITING_PARAM, 
072//                                      planet, planet.getStarSystem(), false);
073//              spawnMissionNode("$gaData_test", EntityLocationType.ORBITING_PARAM, planet, planet.getStarSystem());
074                
075                if (planet == null) return false;
076
077                person = getPerson();
078                if (person == null) return false;
079                
080                market = person.getMarket();
081                if (market == null) return false;
082                
083                setStartingStage(Stage.GO_TO_RUINS);
084                addSuccessStages(Stage.COMPLETED);
085                addFailureStages(Stage.FAILED);
086                
087                makeImportant(planet, "$rdsm_targetPlanet", Stage.GO_TO_RUINS);
088                makeImportant(person, "$rdsm_contact", Stage.RETURN);
089                
090                connectWithGlobalFlag(Stage.GO_TO_RUINS, Stage.RETURN, "$rdsm_gotData");
091                connectWithGlobalFlag(Stage.RETURN, Stage.COMPLETED, "$rdsm_returnedData");
092                
093                //setNoAbandon();
094                setTimeLimit(Stage.FAILED, MISSION_DAYS, null, Stage.RETURN);
095                
096                setCreditReward(CreditReward.AVERAGE);
097
098//              spawnEntity(Entities.FUSION_LAMP, "$gaData_test", EntityLocationType.ORBITING_PARAM,
099//                                              planet, planet.getStarSystem(), false);
100                
101//              beginStageTrigger(Stage.GET_IN_COMMS_RANGE);
102//              triggerSpawnEntity(Entities.INACTIVE_GATE, "$gaData_test", EntityLocationType.ORBITING_PARAM,
103//                                                 planet, planet.getStarSystem(), false);
104//              triggerEntityMakeImportant();
105//              endTrigger();
106                
107                //StarSystemAPI system = planet.getStarSystem();
108                if (planet.hasCondition(Conditions.DECIVILIZED)) {
109                        variation = Variation.DECIV;
110                } else {
111                        variation = Variation.BASIC;
112                }
113                
114                return true;
115        }
116        
117        protected void updateInteractionDataImpl() {
118                set("$rdsm_contactName", person.getNameString());
119                set("$rdsm_megacorpName", megacorp);
120                set("$rdsm_market", market.getName());
121                set("$rdsm_target", target);
122                set("$rdsm_planetId", planet.getId());
123                set("$rdsm_planetName", planet.getName());
124                set("$rdsm_systemName", planet.getStarSystem().getNameWithLowercaseType());
125                set("$rdsm_dist", getDistanceLY(planet));
126                set("$rdsm_reward", Misc.getWithDGS(getCreditsReward()));
127                //set("$gaData_piratePayment", Misc.getWithDGS(piratePayment));
128                //variation = Variation.BASIC;
129                set("$rdsm_variation", variation);
130                if (variation == Variation.DECIV) {
131                        set("$rdsm_marinesReq", MARINES_REQUIRED);
132                        set("$rdsm_raidDifficulty", RAID_DIFFICULTY);
133                }
134        }
135        
136        @Override
137        public void addDescriptionForNonEndStage(TooltipMakerAPI info, float width, float height) {
138                float opad = 10f;
139                Color h = Misc.getHighlightColor();
140                if (currentStage == Stage.GO_TO_RUINS) {
141                        if (variation == Variation.DECIV) {
142                                info.addPara(getGoToPlanetTextPre(planet) +
143                                                        ", and swap the datacore from the " + megacorp + " " + target + " in the ruins there. There have "
144                                                                        + "been reports of decivs so you should bring at least %s " +
145                                                         "marines to ensure the job goes smoothly.", opad, h, Misc.getWithDGS(MARINES_REQUIRED));
146                        } else {
147                                String extra = "";
148                                info.addPara(getGoToPlanetTextPre(planet) + 
149                                                         ", and swap the datacore from the " + megacorp + " " + target + " in the ruins there with the one provided." + extra, opad);
150                        }
151                } else if (currentStage == Stage.RETURN) {
152                        info.addPara(getReturnText(market), opad);
153                }
154//              else {
155//                      super.addDescriptionForCurrentStage(info, width, height); // shows the completed/failed/abandoned text, if needed
156//              }
157        }
158
159        @Override
160        public boolean addNextStepText(TooltipMakerAPI info, Color tc, float pad) {
161                Color h = Misc.getHighlightColor();
162                if (currentStage == Stage.GO_TO_RUINS) {
163                        //info.addPara("Go to " + planet.getName() + " in the " + planet.getStarSystem().getNameWithLowercaseTypeShort(), tc, pad);
164                        info.addPara(getGoToPlanetTextShort(planet), tc, pad);
165                        return true;
166                } else if (currentStage == Stage.RETURN) {
167                        info.addPara(getReturnTextShort(market), tc, pad);
168                        return true;
169                }
170                return false;
171        }
172
173        @Override
174        public String getBaseName() {
175                return "Ruins Datacore Swap";
176        }
177        
178        @Override
179        public String getBlurbText() {
180                return null; // rules.csv
181        }
182
183}
184
185