001package com.fs.starfarer.api.impl.campaign.missions.academy;
002
003import java.util.List;
004import java.util.Map;
005
006import java.awt.Color;
007
008import com.fs.starfarer.api.Global;
009import com.fs.starfarer.api.campaign.CampaignFleetAPI;
010import com.fs.starfarer.api.campaign.InteractionDialogAPI;
011import com.fs.starfarer.api.campaign.PlanetAPI;
012import com.fs.starfarer.api.campaign.SectorEntityToken;
013import com.fs.starfarer.api.campaign.StarSystemAPI;
014import com.fs.starfarer.api.campaign.econ.MarketAPI;
015import com.fs.starfarer.api.campaign.rules.MemoryAPI;
016import com.fs.starfarer.api.characters.PersonAPI;
017import com.fs.starfarer.api.impl.campaign.ids.Factions;
018import com.fs.starfarer.api.impl.campaign.ids.FleetTypes;
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.missions.hub.ReqMode;
022import com.fs.starfarer.api.impl.campaign.rulecmd.salvage.special.TransmitterTrapSpecial;
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 GATransverseJump extends GABaseMission {
028
029        public static enum Stage {
030                GO_TO_OUTPOST,
031                RETURN_TO_ACADEMY,
032                COMPLETED,
033                FAILED,
034        }
035        
036        //public static List<SectorEntityToken> system_jumppoints; 
037        
038        protected StarSystemAPI system;
039        protected PlanetAPI planet;
040        protected PersonAPI researcher;
041        
042        @Override
043        protected boolean create(MarketAPI createdAt, boolean barEvent) {
044                // replaced this with "non_repeatable" tag in person_missions.csv
045                // if this mission was EVER completed by the player, abort!
046                //if (getCreator().getNumCompleted() > 0) return false;
047                
048                // if this mission type was already accepted by the player, abort
049                if (!setGlobalReference("$gaTJ_ref")) {
050                        return false;
051                }
052                
053                //genRandom = Misc.random; // for testing purposes to roll new search results each time
054
055                resetSearch();
056                // expanded from just THEME_MISC
057                // since the various jump point-related requirements narrows down the valid options
058                requireSystemTags(ReqMode.ANY, Tags.THEME_MISC, Tags.THEME_MISC_SKIP, Tags.THEME_RUINS);
059                requireSystemTags(ReqMode.NOT_ANY, Tags.THEME_UNSAFE, Tags.THEME_CORE);
060                requireSystemNotAlreadyUsedForStory();
061                requireSystemNotHasPulsar();
062                requireSystemHasAtLeastNumJumpPoints(2);
063                preferSystemHasAtLeastNumJumpPoints(3);
064                preferSystemOnFringeOfSector();
065                preferSystemUnexplored();
066                //preferSystemInDirectionOfOtherMissions();
067                requirePlanetNotStar();
068                requirePlanetUnpopulated();
069                requirePlanetNotGasGiant();
070                preferPlanetNotNearJumpPoint(5000f);
071                preferPlanetNotNearJumpPoint(2000f);
072                preferPlanetNotFullySurveyed();
073
074                planet = pickPlanet();
075                
076                if (planet == null) {
077                        return false;
078                }
079                
080                system = planet.getStarSystem();
081                
082                setStartingStage(Stage.GO_TO_OUTPOST);
083                addSuccessStages(Stage.COMPLETED);
084                addFailureStages(Stage.FAILED);
085                
086                setStoryMission();
087                
088                //setMusic(planet, MusicPlayerPluginImpl.MUSIC_ENCOUNTER_MYSTERIOUS_AGGRO, Stage.GO_TO_OUTPOST);
089                
090                makeImportant(planet, "$gaTJ_targetPlanet", Stage.GO_TO_OUTPOST);
091                makeImportant(getPerson(), "$gaTJ_needToReturn", Stage.RETURN_TO_ACADEMY);
092                
093                connectWithGlobalFlag(Stage.GO_TO_OUTPOST, Stage.RETURN_TO_ACADEMY, "$gaTJ_needToReturn");
094                setStageOnGlobalFlag(Stage.COMPLETED, "$gaTJ_completed");
095                
096                
097                setCreditReward(CreditReward.HIGH);
098
099                researcher = Global.getSector().getFaction(Factions.INDEPENDENT).createRandomPerson(genRandom);
100                researcher.setRankId(Ranks.CITIZEN);
101                researcher.setPostId(Ranks.POST_ACADEMICIAN);
102                
103                // Tri-Tach black ops merc patrol(s) spawn
104                // ideally spawned to guard all possible system jump-points
105                // then, once player grabs Baird's spy, they all move to planet and start search pattern
106                
107                List<SectorEntityToken> jumpPoints = system.getJumpPoints();
108                for (SectorEntityToken point : jumpPoints) {
109                        addMercFleet(point);
110                }
111                
112                beginStageTrigger(Stage.COMPLETED);
113                triggerSetGlobalMemoryValuePermanent("$asebSayBairdWantsToTalk", true);
114                endTrigger();
115                
116                setSystemWasUsedForStory(Stage.GO_TO_OUTPOST, system);
117
118                return true;
119        }
120        
121        @Override
122        protected boolean callAction(String action, String ruleId, InteractionDialogAPI dialog, List<Token> params,
123                                                                Map<String, MemoryAPI> memoryMap) {
124                if (dialog != null && action.equals("showResearcher")) {
125                        showPersonInfo(researcher, dialog, false, false);
126                        return true;
127                }
128                if ("triggerMercFleets".equals(action)) {
129                        for (CampaignFleetAPI fleet : system.getFleets()) {
130                                if (fleet.getMemoryWithoutUpdate().contains("$gaTJ_merc")) {
131                                        TransmitterTrapSpecial.makeFleetInterceptPlayer(fleet, true, false, true, 1000f);
132                                }
133                        }
134                        
135                        return true;
136                }
137                return false;
138        }
139        
140        protected void updateInteractionDataImpl() {
141                set("$gaTJ_planetId", planet.getId());
142                set("$gaTJ_planetName", planet.getName());
143                set("$gaTJ_systemName", planet.getStarSystem().getNameWithNoType());
144                set("$gaTJ_dist", getDistanceLY(planet));
145                set("$gaTJ_reward", Misc.getWithDGS(getCreditsReward()));
146                set("$gaTJ_researcherName", researcher.getNameString());
147                set("$gaTJ_heOrShe", researcher.getHeOrShe());
148                set("$gaTJ_HeOrShe", researcher.getHeOrShe().substring(0, 1).toUpperCase() + researcher.getHeOrShe().substring(1));
149                set("$gaTJ_hisOrHer", researcher.getHisOrHer());
150                set("$gaTJ_HisOrHet", researcher.getHisOrHer().substring(0, 1).toUpperCase() + researcher.getHisOrHer().substring(1));
151                set("$gaTJ_himOrHer", researcher.getHimOrHer());
152                set("$gaTJ_HimOrHet", researcher.getHimOrHer().substring(0, 1).toUpperCase() + researcher.getHimOrHer().substring(1));
153
154        }
155        
156        @Override
157        public void addDescriptionForNonEndStage(TooltipMakerAPI info, float width, float height) {
158                float opad = 10f;
159                Color h = Misc.getHighlightColor();
160                if (currentStage == Stage.GO_TO_OUTPOST) {
161                        info.addPara(getGoToPlanetTextPre(planet) +
162                                        ", and contact the 'researcher' at the Tri-Tachyon black research site located there.", opad);
163                } else if (currentStage == Stage.RETURN_TO_ACADEMY) {
164                        // shared way to get the same text to ensure consistency across different missions
165                        info.addPara(getReturnText("the Galatia Academy") + ".", opad);
166                }
167        }
168
169        @Override
170        public boolean addNextStepText(TooltipMakerAPI info, Color tc, float pad) {
171                Color h = Misc.getHighlightColor();
172                if (currentStage == Stage.GO_TO_OUTPOST) {
173                        info.addPara(getGoToPlanetTextShort(planet), tc, pad);
174                        return true;
175                } else if (currentStage == Stage.RETURN_TO_ACADEMY) {
176                        // shared way to get the same text to ensure consistency across different missions
177                        info.addPara(getReturnTextShort("the Galatia Academy"), tc, pad);
178                        return true;
179                }
180                return false;
181        }
182
183        @Override
184        public String getBaseName() {
185                return "Extract 'Researcher'";
186        }
187        
188        protected void addMercFleet(SectorEntityToken patrolPoint) {
189                // changed requirePlayerInHyperspace to false so that if ctrl-clicking into the system, the mercs
190                // still spawn. Generally only want to requirePlayerInHyperspace for an encounter intended to be in
191                // hyperspace, and even then that's situational
192                beginWithinHyperspaceRangeTrigger(planet, 3f, false, Stage.GO_TO_OUTPOST);
193                triggerCreateFleet(FleetSize.LARGE, FleetQuality.VERY_HIGH, Factions.MERCENARY, FleetTypes.PATROL_LARGE, system);
194                triggerSetFleetFaction(Factions.INDEPENDENT);
195                triggerSetFleetOfficers(OfficerNum.MORE, OfficerQuality.HIGHER);
196                
197                // do we want this here? Probably not, this is a one-off mission and so the strength shouldn't scale
198                //triggerAutoAdjustFleetStrengthMajor();
199                
200                triggerMakeHostileAndAggressive();
201                triggerMakeNoRepImpact();
202                triggerFleetAllowLongPursuit();
203                triggerSetFleetAlwaysPursue();
204                
205                triggerPickLocationAroundEntity(patrolPoint, 1000f);
206                triggerSpawnFleetAtPickedLocation("$gaTJ_merc", null);
207                triggerOrderFleetPatrol(true, patrolPoint);
208                
209                //triggerFleetMakeImportant(null, Stage.RETURN_TO_ACADEMY);
210                endTrigger();
211        }
212}
213
214
215
216
217