001package com.fs.starfarer.api.impl.campaign.missions;
002
003import java.util.List;
004import java.util.Map;
005
006import java.awt.Color;
007
008import com.fs.starfarer.api.campaign.InteractionDialogAPI;
009import com.fs.starfarer.api.campaign.PlanetAPI;
010import com.fs.starfarer.api.campaign.econ.CommodityOnMarketAPI;
011import com.fs.starfarer.api.campaign.econ.MarketAPI;
012import com.fs.starfarer.api.campaign.rules.MemoryAPI;
013import com.fs.starfarer.api.characters.PersonAPI;
014import com.fs.starfarer.api.impl.campaign.ids.Conditions;
015import com.fs.starfarer.api.impl.campaign.ids.Tags;
016import com.fs.starfarer.api.impl.campaign.missions.hub.HubMissionWithBarEvent;
017import com.fs.starfarer.api.impl.campaign.missions.hub.ReqMode;
018import com.fs.starfarer.api.ui.TooltipMakerAPI;
019import com.fs.starfarer.api.util.Misc;
020import com.fs.starfarer.api.util.Misc.Token;
021
022public class RaidSecretOutpostMission extends HubMissionWithBarEvent {
023
024        //public static float PIRATE_PROB = 0.5f;
025        public static float MISSION_DAYS = 120f;
026        public static int RAID_DIFFICULTY = 48;
027        public static int MARINES_REQUIRED = RAID_DIFFICULTY / 2;
028        public static float MIN_VALUE = 80000f;
029        public static float MAX_VALUE = 140000f;
030        
031        public static enum Stage {
032                GO_TO_OUTPOST,
033                COMPLETED,
034                FAILED,
035        }
036        
037        public static enum Variation {
038                BASIC,
039                DECIV,
040        }
041        
042        protected MarketAPI market;
043        protected PersonAPI person;
044        protected PlanetAPI planet;
045        protected int goodsAmount;
046        protected CommodityOnMarketAPI com;
047        protected int quantity;
048        //protected Variation variation;
049
050        
051        @Override
052        protected boolean create(MarketAPI createdAt, boolean barEvent) {
053                // if this mission type was already accepted by the player, abort
054                if (!setGlobalReference("$rsom_ref")) {
055                        return false;
056                }
057                
058                resetSearch();
059                requireSystemTags(ReqMode.ANY, Tags.THEME_REMNANT_SUPPRESSED, Tags.THEME_DERELICT, Tags.THEME_MISC, Tags.THEME_RUINS);
060                requireSystemTags(ReqMode.NOT_ANY, Tags.THEME_SPECIAL);
061                requireSystemInInnerSector();
062                //requireSystemHasPulsar();
063                //requireSystemIsDense();
064                //requirePlanetIsGasGiant();
065                requirePlanetNotStar();
066                requirePlanetNotGasGiant(); // for the writing.
067                requirePlanetConditions(ReqMode.NOT_ANY, Conditions.DECIVILIZED);
068                requirePlanetUnpopulated();
069                preferPlanetNotFullySurveyed();
070                preferPlanetUnexploredRuins();
071                preferPlanetInDirectionOfOtherMissions();
072                planet = pickPlanet();
073                
074//              spawnEntity(Entities.INACTIVE_GATE, "$gaData_test", EntityLocationType.ORBITING_PARAM, 
075//                                      planet, planet.getStarSystem(), false);
076//              spawnMissionNode("$gaData_test", EntityLocationType.ORBITING_PARAM, planet, planet.getStarSystem());
077                
078                if (planet == null) return false;
079
080                person = getPerson();
081                if (person == null) return false;
082                
083                market = person.getMarket();
084                if (market == null) return false;
085                
086                setStartingStage(Stage.GO_TO_OUTPOST);
087                addSuccessStages(Stage.COMPLETED);
088                addFailureStages(Stage.FAILED);
089                
090                makeImportant(planet, "$rsom_targetPlanet", Stage.GO_TO_OUTPOST);
091                //makeImportant(person, "$rsom_contact", Stage.RETURN);
092                
093                connectWithGlobalFlag(Stage.GO_TO_OUTPOST, Stage.COMPLETED, "$rsom_raidedOutpost");
094                //connectWithGlobalFlag(Stage.RETURN, Stage.COMPLETED, "$rsom_returnedData");
095                
096                setNoAbandon();
097                setTimeLimit(Stage.FAILED, MISSION_DAYS, null);
098                
099                requireCommodityIllegal();
100                requireCommodityDemandAtLeast(1);
101                
102                //market = com.getMarket();
103                //if (market == null) return false;
104                
105                com = pickCommodity();
106                if (com == null) return false;
107                
108                float value = MIN_VALUE + getQuality() * (MAX_VALUE - MIN_VALUE);
109                value *= 0.9f + genRandom.nextFloat() * 0.2f;
110                
111                quantity = getRoundNumber(value / com.getCommodity().getBasePrice());
112                if (quantity < 10) quantity = 10;
113                
114                
115                //setCreditReward(CreditReward.AVERAGE);
116
117//              spawnEntity(Entities.FUSION_LAMP, "$gaData_test", EntityLocationType.ORBITING_PARAM,
118//                                              planet, planet.getStarSystem(), false);
119                
120//              beginStageTrigger(Stage.GET_IN_COMMS_RANGE);
121//              triggerSpawnEntity(Entities.INACTIVE_GATE, "$gaData_test", EntityLocationType.ORBITING_PARAM,
122//                                                 planet, planet.getStarSystem(), false);
123//              triggerEntityMakeImportant();
124//              endTrigger();
125                
126                //StarSystemAPI system = planet.getStarSystem();
127                
128                setRepFactionChangesNone(); // intra-underworld meddling pans out to no change, let's say.
129
130                return true;
131        }
132        
133        protected void updateInteractionDataImpl() {
134                set("$rsom_contactName", person.getNameString());
135                set("$rsom_market", market.getName());
136                set("$rsom_planetId", planet.getId());
137                set("$rsom_planetName", planet.getName());
138                set("$rsom_systemName", planet.getStarSystem().getNameWithLowercaseType());
139                set("$rsom_dist", getDistanceLY(planet));
140                set("$rsom_product", com.getCommodity().getLowerCaseName());
141                set("$rsom_productID", com.getCommodity().getId());
142                set("$rsom_quantity", quantity);
143                set("$rsom_marinesReq", MARINES_REQUIRED);
144                set("$rsom_raidDifficulty", RAID_DIFFICULTY);
145                
146        }
147        
148        @Override
149        protected boolean callAction(String action, String ruleId, final InteractionDialogAPI dialog,
150                                                                 List<Token> params, final Map<String, MemoryAPI> memoryMap) {
151                if ("giveOutpostPlunder".equals(action)) {
152
153                        return true;
154                }
155                
156                return super.callAction(action, ruleId, dialog, params, memoryMap);
157        }
158        
159        @Override
160        public void addDescriptionForNonEndStage(TooltipMakerAPI info, float width, float height) {
161                float opad = 10f;
162                Color h = Misc.getHighlightColor();
163                if (currentStage == Stage.GO_TO_OUTPOST) {
164
165                        info.addPara(getGoToPlanetTextPre(planet) +
166                                                ", use the codes to bypass defenses to raid and plunder the " + com.getCommodity().getLowerCaseName() + " in the hidden outpost there. "
167                                                + "Bring at least %s marines to ensure success.", opad, h, Misc.getWithDGS(MARINES_REQUIRED));
168                        
169                //} else if (currentStage == Stage.RETURN) {
170                //      info.addPara(getReturnText(market), opad);
171                }
172//              else {
173//                      super.addDescriptionForCurrentStage(info, width, height); // shows the completed/failed/abandoned text, if needed
174//              }
175        }
176
177        @Override
178        public boolean addNextStepText(TooltipMakerAPI info, Color tc, float pad) {
179                Color h = Misc.getHighlightColor();
180                if (currentStage == Stage.GO_TO_OUTPOST) {
181                        //info.addPara("Go to " + planet.getName() + " in the " + planet.getStarSystem().getNameWithLowercaseTypeShort(), tc, pad);
182                        info.addPara(getGoToPlanetTextShort(planet), tc, pad);
183                        return true;
184                //} else if (currentStage == Stage.RETURN) {
185                //      info.addPara(getReturnTextShort(market), tc, pad);
186                //      return true;
187                }
188                return false;
189        }
190
191        @Override
192        public String getBaseName() {
193                return "Raid Secret Outpost";
194        }
195        
196        @Override
197        public String getBlurbText() {
198                return null; // rules.csv
199        }
200
201}
202
203