001package com.fs.starfarer.api.impl.campaign.econ;
002
003import java.util.Arrays;
004import java.util.HashMap;
005import java.util.LinkedHashMap;
006import java.util.List;
007import java.util.Map;
008
009import java.awt.Color;
010
011import com.fs.starfarer.api.Global;
012import com.fs.starfarer.api.campaign.CampaignFleetAPI;
013import com.fs.starfarer.api.campaign.StarSystemAPI;
014import com.fs.starfarer.api.campaign.econ.MarketAPI;
015import com.fs.starfarer.api.campaign.econ.MarketConditionAPI;
016import com.fs.starfarer.api.campaign.econ.MarketConditionPlugin;
017import com.fs.starfarer.api.ui.LabelAPI;
018import com.fs.starfarer.api.ui.TooltipMakerAPI;
019import com.fs.starfarer.api.util.Misc;
020
021public class BaseMarketConditionPlugin implements MarketConditionPlugin {
022
023        protected MarketAPI market;
024        protected MarketConditionAPI condition;
025        
026        public void init(MarketAPI market, MarketConditionAPI condition) {
027                this.market = market;
028                this.condition = condition;
029        }
030        
031        public void apply(String id) {
032        }
033
034        public void unapply(String id) {
035        }
036        
037        
038        public void advance(float amount) {
039                
040        }
041        
042        public String getModId() {
043                return condition.getIdForPluginModifications();
044        }
045        
046        
047        public static float getLowStabilityBonusMult(MarketAPI market) {
048                float s = market.getStabilityValue();
049                //if (true) return 1f + (10f - s) * 0.2f;
050                if (true) return 1f + (10f - s) * 0.1f;
051                
052                switch ((int)market.getStabilityValue()) {
053                case 0:
054                        return 3f;
055                case 1:
056                        return 2.5f;
057                case 2:
058                        return 2f;
059                case 3:
060                        return 1.5f;
061                case 4:
062                case 5:
063                case 6:
064                case 7:
065                case 8:
066                case 9:
067                case 10:
068                        return 1f;
069                default:
070                        return 1f;
071                }
072        }
073        
074        public static float getLowStabilityPenaltyMult(MarketAPI market) {
075                float s = market.getStabilityValue();
076                //if (true) return 0.1f + s * 0.09f;
077                if (true) return 0.5f + s * 0.05f;
078                
079                switch ((int)market.getStabilityValue()) {
080                case 0:
081                        return 0.1f;
082                case 1:
083                        return 0.25f;
084                case 2:
085                        return 0.5f;
086                case 3:
087                        return .75f;
088                case 4:
089                case 5:
090                case 6:
091                case 7:
092                case 8:
093                case 9:
094                case 10:
095                        return 1f;
096                default:
097                        return 1f;
098                }
099        }
100        
101        public static float getHighStabilityBonusMult(MarketAPI market) {
102                float s = market.getStabilityValue();
103                //if (true) return 1f + s * 0.2f;
104                if (true) return 1f + s * 0.1f;
105                
106                switch ((int)market.getStabilityValue()) {
107                case 0:
108                case 1:
109                case 2:
110                case 3:
111                case 4:
112                case 5:
113                case 6:
114                        return 1f;
115                case 7:
116                        return 1.5f;
117                case 8:
118                        return 2f;
119                case 9:
120                        return 2.5f;
121                case 10:
122                        return 3f;
123                default:
124                        return 1f;
125                }
126        }
127        
128        public static float getHighStabilityPenaltyMult(MarketAPI market) {
129                float s = market.getStabilityValue();
130                //if (true) return 0.1f + (10f - s) * 0.09f;
131                if (true) return 0.5f + (10f - s) * 0.05f;
132                
133                switch ((int)market.getStabilityValue()) {
134                case 0:
135                case 1:
136                case 2:
137                case 3:
138                case 4:
139                case 5:
140                case 6:
141                        return 1f;
142                case 7:
143                        return .75f;
144                case 8:
145                        return 0.5f;
146                case 9:
147                        return 0.25f;
148                case 10:
149                        return 0.1f;
150                default:
151                        return 1f;
152                }               
153        }
154        
155        public static void main(String[] args) {
156        }
157
158
159        public List<String> getRelatedCommodities() {
160                return null;
161        }
162
163        public void setParam(Object param) {
164                
165        }
166
167        public Map<String, String> getTokenReplacements() {
168                HashMap<String, String> tokens = new LinkedHashMap<String, String>();
169                
170                tokens.put("$playerName", Global.getSector().getCharacterData().getName());
171                if (market != null) {
172                        tokens.put("$marketFaction", market.getFaction().getDisplayName());
173                        tokens.put("$TheMarketFaction", Misc.ucFirst(market.getFaction().getDisplayNameWithArticle()));
174                        tokens.put("$theMarketFaction", market.getFaction().getDisplayNameWithArticle());
175                        
176                        if (market.getPrimaryEntity().getLocation() instanceof StarSystemAPI) {
177                                //tokens.put("$marketSystem", ((StarSystemAPI)eventTarget.getLocation()).getBaseName() + " star system");
178                                tokens.put("$marketSystem", ((StarSystemAPI)market.getPrimaryEntity().getLocation()).getBaseName());
179                        } else {
180                                tokens.put("$marketSystem", "hyperspace");
181                        }
182                        tokens.put("$marketName", market.getName());
183                        tokens.put("$MarketName", Misc.ucFirst(market.getName()));
184                        tokens.put("$market", market.getName());
185                        tokens.put("$Market", Misc.ucFirst(market.getName()));
186                }
187                
188                CampaignFleetAPI playerFleet = Global.getSector().getPlayerFleet();
189                if (playerFleet != null) {
190                        String fleetOrShip = "fleet";
191                        if (playerFleet.getFleetData().getMembersListCopy().size() == 1) {
192                                fleetOrShip = "ship";
193                                if (playerFleet.getFleetData().getMembersListCopy().get(0).isFighterWing()) {
194                                        fleetOrShip = "fighter wing";
195                                }
196                        }
197                        tokens.put("$playerShipOrFleet", fleetOrShip);
198                }
199                
200                return tokens;
201        }
202
203        public String[] getHighlights() {
204                return null;
205        }
206        
207        public Color[] getHighlightColors() {
208                String [] highlights = getHighlights();
209                if (highlights != null) {
210                        Color c = Global.getSettings().getColor("buttonShortcut");
211                        Color [] colors = new Color[highlights.length];
212                        Arrays.fill(colors, c);
213                        return colors;
214                }
215                return null;
216        }
217        
218        
219        public void addTokensToList(List<String> list, String ... keys) {
220                Map<String, String> tokens = getTokenReplacements();
221                for (String key : keys) {
222                        if (tokens.containsKey(key)) {
223                                list.add(tokens.get(key));
224                        }
225                }
226        }
227
228        public boolean isTransient() {
229                return true;
230        }
231
232        public boolean showIcon() {
233                return true;
234        }
235        
236        
237        public boolean hasCustomTooltip() {
238                return true;
239        }
240        
241        public void createTooltip(TooltipMakerAPI tooltip, boolean expanded) {
242                float opad = 10f;
243                
244                if (!Global.CODEX_TOOLTIP_MODE) {
245                        Color color = market.getTextColorForFactionOrPlanet();
246                        tooltip.addTitle(condition.getName(), color);
247                }
248                
249                String text = condition.getSpec().getDesc();
250                Map<String, String> tokens = getTokenReplacements();
251                if (tokens != null) {
252                        for (String token : tokens.keySet()) {
253                                String value = tokens.get(token);
254                                text = text.replaceAll("(?s)\\" + token, value);
255                        }
256                }
257                
258                if (!text.isEmpty()) {
259                        LabelAPI body = tooltip.addPara(text, opad);
260                        if (getHighlights() != null) {
261                                if (getHighlightColors() != null) {
262                                        body.setHighlightColors(getHighlightColors());
263                                } else {
264                                        body.setHighlightColor(Misc.getHighlightColor());
265                                }
266                                body.setHighlight(getHighlights());
267                        }
268                }
269                
270                createTooltipAfterDescription(tooltip, expanded);
271        }
272        
273        
274        protected void createTooltipAfterDescription(TooltipMakerAPI tooltip, boolean expanded) {
275                
276        }
277        
278        public boolean isTooltipExpandable() {
279                return false;
280        }
281        
282        public float getTooltipWidth() {
283                return 500f;
284        }
285
286        public boolean isPlanetary() {
287                if (condition == null) return true;
288                
289                return condition.getSpec().isPlanetary();
290        }
291
292        public boolean runWhilePaused() {
293                return false;
294        }
295
296        public String getIconName() {
297                return condition.getSpec().getIcon();
298        }
299
300        public String getName() {
301                return condition.getSpec().getName();
302        }
303        
304        
305
306}
307
308
309
310