001package com.fs.starfarer.api.impl.campaign.rulecmd;
002
003import java.awt.Color;
004import java.util.List;
005import java.util.Map;
006
007import com.fs.starfarer.api.Global;
008import com.fs.starfarer.api.campaign.CampaignFleetAPI;
009import com.fs.starfarer.api.campaign.FactionAPI;
010import com.fs.starfarer.api.campaign.InteractionDialogAPI;
011import com.fs.starfarer.api.campaign.TextPanelAPI;
012import com.fs.starfarer.api.campaign.rules.MemoryAPI;
013import com.fs.starfarer.api.characters.MutableCharacterStatsAPI.SkillLevelAPI;
014import com.fs.starfarer.api.impl.campaign.econ.ShippingDisruption;
015import com.fs.starfarer.api.impl.campaign.fleets.EconomyFleetAssignmentAI.EconomyRouteData;
016import com.fs.starfarer.api.impl.campaign.fleets.EconomyFleetRouteManager;
017import com.fs.starfarer.api.impl.campaign.fleets.RouteManager;
018import com.fs.starfarer.api.impl.campaign.fleets.RouteManager.RouteData;
019import com.fs.starfarer.api.impl.campaign.ids.MemFlags;
020import com.fs.starfarer.api.ui.LabelAPI;
021import com.fs.starfarer.api.util.Misc;
022import com.fs.starfarer.api.util.Misc.Token;
023
024public class FleetDesc extends BaseCommandPlugin {
025
026        public boolean execute(String ruleId, InteractionDialogAPI dialog, List<Token> params, Map<String, MemoryAPI> memoryMap) {
027                if (dialog == null) return false;
028                if (!(dialog.getInteractionTarget() instanceof CampaignFleetAPI)) return false;
029                
030                CampaignFleetAPI playerFleet = Global.getSector().getPlayerFleet();
031                CampaignFleetAPI fleet = (CampaignFleetAPI) dialog.getInteractionTarget();
032                
033                FactionAPI faction = fleet.getFaction();
034                TextPanelAPI text = dialog.getTextPanel();
035                
036                if (Global.getSettings().isDevMode() && !Global.getSettings().getBoolean("playtestingMode")) {
037                        text.addParagraph("Admiral skills:");
038                        for (SkillLevelAPI skill : fleet.getCommanderStats().getSkillsCopy()) {
039                                if (skill.getSkill().isAdmiralSkill()) {
040                                        text.addParagraph("    " + skill.getSkill().getId());
041                                }
042                        }
043                }
044                
045                
046                MemoryAPI mem = fleet.getMemoryWithoutUpdate();
047                if (!mem.contains("$shownFleetDescAlready")) {
048                        mem.set("$shownFleetDescAlready", true, 0);
049                }
050                
051                boolean smuggler = mem.getBoolean(MemFlags.MEMORY_KEY_SMUGGLER);
052                boolean trader = mem.getBoolean(MemFlags.MEMORY_KEY_TRADE_FLEET);
053                
054                Color hl = Misc.getHighlightColor();
055                Color red = Misc.getNegativeHighlightColor();
056                
057                RouteData route = RouteManager.getInstance().getRoute(EconomyFleetRouteManager.SOURCE_ID, fleet);
058                if ((trader || smuggler) && route != null) {
059                        EconomyRouteData data = (EconomyRouteData) route.getCustom();
060                        
061                        Integer id = route.getCurrentSegmentId();
062                        
063                        String from = data.from.getName();
064                        String to = data.to.getName();
065                        //int index = route.getCurrentIndex();
066                        if (id >= EconomyFleetRouteManager.ROUTE_DST_LOAD) {
067                                from = data.to.getName();
068                                to = data.from.getName();
069                        }
070                        String cargo = "";
071
072                        if (id <= EconomyFleetRouteManager.ROUTE_DST_UNLOAD) {
073                                cargo = EconomyRouteData.getCargoList(data.cargoDeliver);
074                                if (!cargo.isEmpty() && id == EconomyFleetRouteManager.ROUTE_SRC_LOAD) cargo += " (being loaded)";
075                        } else {
076                                cargo = EconomyRouteData.getCargoList(data.cargoReturn);
077                                if (!cargo.isEmpty() && id == EconomyFleetRouteManager.ROUTE_DST_LOAD) cargo += " (being loaded)";
078                        }
079                        
080                        if (trader || smuggler) {
081                                LabelAPI label = text.addParagraph("You encounter " + fleet.getFaction().getPersonNamePrefixAOrAn() + " " + 
082                                                fleet.getFaction().getPersonNamePrefix() + " "+ fleet.getName().toLowerCase() + ".");
083                                label.highlightFirst(fleet.getFaction().getPersonNamePrefix());
084                                label.setHighlightColor(fleet.getFaction().getBaseUIColor());
085                                
086                                text.setFontSmallInsignia();
087                                
088                                text.addParagraph("--------------------------------------------------------------------------------------------------------------");
089                                if (data.from.isHidden()) {
090                                        text.addPara("Port of origin: %s", hl, "Unknown");
091                                } else {
092                                        text.addPara("Port of origin: %s", hl, data.from.getName());
093                                }
094                                text.addPara("Current destination: %s", hl, to);
095                                if (from.equals(data.to.getName())) {
096                                        text.addPara("Returning from: %s", hl, data.to.getName());
097                                }
098                                if (cargo.isEmpty()) {
099                                        text.addPara("No cargo");
100                                } else {
101                                        text.addPara("Cargo: %s", hl, cargo);
102                                        //text.addPara(cargo);
103                                }
104                                
105                                text.addParagraph("--------------------------------------------------------------------------------------------------------------");
106                                text.setFontInsignia();
107                                
108                                int penalty = Math.round(ShippingDisruption.getPenaltyForShippingLost(data.from.getSize(), data.size) * 100f);
109                                
110
111                                if (!fleet.getFaction().isPlayerFaction()) {
112                                        if (data.from.isHidden()) {
113                                                text.addPara("If this fleet does not reach its destination safely, it will cause a shortage " +
114                                                                "of the commodities it carries. " +
115                                                                "In addition, its loss would reduce the accessibility of its port of origin by %s for up to three months.",
116                                                                Misc.getTextColor(), Misc.getHighlightColor(), "" + penalty + "%");
117                                        } else {
118                                                text.addPara("If this fleet does not reach its destination safely, it will cause a shortage " +
119                                                                "of the commodities it carries. " +
120                                                                "In addition, its loss would reduce the accessbility of " + data.from.getName() + " by %s for up to three months.",
121                                                                Misc.getTextColor(), Misc.getHighlightColor(), "" + penalty + "%");
122                                        }
123                                }
124                        }
125                }
126                
127                if (!fleet.getFaction().isPlayerFaction() && !fleet.getFaction().isNeutralFaction()) {
128                        if (fleet.getMemoryWithoutUpdate().getBoolean(MemFlags.MEMORY_KEY_NO_REP_IMPACT)) {
129                                if (Misc.isDecentralized(fleet.getFaction())) {
130//                                      text.addPara("This fleet's behavior falls outside the accepted norms of the faction it nominally belongs to. " +
131//                                                               "Engaging it in battle will not cause any changes to your reputation.",
132//                                                               Misc.getHighlightColor(), "will not cause any changes to your reputation");
133                                        text.addPara("Engaging this fleet in battle will not cause any changes to your reputation with the faction it nominally belongs to.",
134                                                        Misc.getHighlightColor(), "will not cause any changes to your reputation");
135                                } else {
136                                        text.addPara("This fleet is operating without official sanction from the faction it nominally belongs to. " +
137                                                        "Engaging it in battle will not cause any changes to your reputation.",
138                                                        Misc.getHighlightColor(), "will not cause any changes to your reputation");
139                                }
140                        } else if (fleet.getMemoryWithoutUpdate().getBoolean(MemFlags.MEMORY_KEY_LOW_REP_IMPACT) && fleet.knowsWhoPlayerIs()) {
141                                if (Misc.isDecentralized(fleet.getFaction())) {
142//                                      text.addPara("This fleet's behavior falls outside the accepted norms of the faction it nominally belongs to. " +
143//                                                      "Engaging it in battle will not cause immediate hostilities " +
144//                                                      "with the faction it belongs to, though it will slightly strain the relationship.",
145//                                                      Misc.getHighlightColor(), "will not cause immediate hostilities");
146                                        text.addPara("Engaging this fleet in battle will not cause immediate hostilities " +
147                                                        "with the faction it nominally belongs to, though it will slightly strain the relationship.",
148                                                        Misc.getHighlightColor(), "will not cause immediate hostilities");
149                                } else {
150                                        text.addPara("This fleet is either operating in a legal gray area or its behavior " +
151                                                        "falls outside accepted norms. Engaging it in battle will not cause immediate hostilities " +
152                                                        "with the faction it nominally belongs to, though it will slightly strain the relationship.",
153                                                        Misc.getHighlightColor(), "will not cause immediate hostilities");
154                                }
155                        }
156                }
157                
158                return true;
159        }
160
161}
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176