001package com.fs.starfarer.api.impl.campaign.econ;
002
003import java.awt.Color;
004
005import com.fs.starfarer.api.impl.campaign.intel.events.PiracyRespiteScript;
006import com.fs.starfarer.api.impl.campaign.rulecmd.KantaCMD;
007import com.fs.starfarer.api.ui.TooltipMakerAPI;
008import com.fs.starfarer.api.util.Misc;
009
010public class PiracyRespite extends BaseMarketConditionPlugin {
011
012        public static boolean NEW_MODE = true;
013        //public static float ACCESSIBILITY_BONUS = 0.3f;
014        public static float ACCESSIBILITY_BONUS = 0.1f;
015        public static float ACCESSIBILITY_BONUS_KANTA = 0.1f;
016        
017        public PiracyRespite() {
018        }
019
020        
021        public static float getBonus() {
022                float bonus = ACCESSIBILITY_BONUS;
023                if (KantaCMD.playerHasProtection()) {
024                        bonus += ACCESSIBILITY_BONUS_KANTA;
025                }
026                return bonus;
027        }
028
029        public void apply(String id) {
030                if (NEW_MODE) return;
031                String text = Misc.ucFirst(getName().toLowerCase());
032                if (KantaCMD.playerHasProtection()) {
033                        text += " (with Kanta's Protection)";
034                }
035                market.getAccessibilityMod().modifyFlat(id, getBonus(), text);
036        }
037
038        public void unapply(String id) {
039                if (NEW_MODE) return;
040                market.getAccessibilityMod().unmodifyFlat(id);
041        }
042        
043        @Override
044        public void createTooltipAfterDescription(TooltipMakerAPI tooltip, boolean expanded) {
045                PiracyRespiteScript script = PiracyRespiteScript.get();
046                if (script == null) return;
047                
048                Color h = Misc.getHighlightColor();
049                
050                float opad = 10f;
051                
052                if (NEW_MODE) {
053                        if (KantaCMD.playerHasProtection()) {
054                                tooltip.addPara("Your colonies have %s, and pirates are wary of "
055                                                + "attacking trade fleets serving them lest they attract her wrath. "
056                                                + "Shipping disruptions from piracy are virtually eliminated.", opad, Misc.getPositiveHighlightColor(),
057                                                "Kanta's Protection");
058                        } else {
059                                tooltip.addPara("You've defeated a large armada sent against your colonies, and pirates are wary of "
060                                                + "attacking trade fleets serving them, "
061                                                + "resulting in a greatly reduced number of shipping disruptions.", opad);
062                        }
063                } else {
064                        int rem = Math.round(script.getDaysRemaining());
065                        String days = rem == 1 ? "day" : "days";
066        
067                        if (KantaCMD.playerHasProtection()) {
068                                tooltip.addPara("Your colonies have %s, resulting in an "
069                                                + "increased accessibility bonus.", opad, Misc.getPositiveHighlightColor(),
070                                                "Kanta's Protection");
071                        }
072                        
073                        if (rem >= 0) {
074                                tooltip.addPara("%s accessibility (%s " + days + " remaining).", 
075                                                opad, h,
076                                                "+" + (int)Math.round(getBonus() * 100f) + "%", "" + rem);
077                        } else {
078                                tooltip.addPara("%s accessibility.", 
079                                                opad, h,
080                                                "+" + (int)Math.round(getBonus() * 100f) + "%");
081                        }
082                }
083        }
084
085        @Override
086        public boolean hasCustomTooltip() {
087                return true;
088        }
089
090}
091
092
093
094
095