001package com.fs.starfarer.api.impl.campaign.intel.bar.events;
002
003import java.awt.Color;
004
005import com.fs.starfarer.api.Global;
006import com.fs.starfarer.api.campaign.CargoAPI;
007import com.fs.starfarer.api.campaign.OptionPanelAPI;
008import com.fs.starfarer.api.campaign.PersonImportance;
009import com.fs.starfarer.api.campaign.RepLevel;
010import com.fs.starfarer.api.campaign.TextPanelAPI;
011import com.fs.starfarer.api.campaign.econ.MarketAPI;
012import com.fs.starfarer.api.characters.PersonAPI;
013import com.fs.starfarer.api.impl.campaign.ids.Factions;
014import com.fs.starfarer.api.impl.campaign.ids.Ranks;
015import com.fs.starfarer.api.impl.campaign.ids.Sounds;
016import com.fs.starfarer.api.impl.campaign.ids.Tags;
017import com.fs.starfarer.api.impl.campaign.rulecmd.AddRemoveCommodity;
018import com.fs.starfarer.api.impl.campaign.rulecmd.SetStoryOption;
019import com.fs.starfarer.api.impl.campaign.rulecmd.SetStoryOption.BaseOptionStoryPointActionDelegate;
020import com.fs.starfarer.api.impl.campaign.rulecmd.SetStoryOption.StoryOptionParams;
021import com.fs.starfarer.api.ui.TooltipMakerAPI;
022import com.fs.starfarer.api.util.Misc;
023
024public class TriTachLoanBarEvent extends BaseGetCommodityBarEvent {
025        
026        public static int REPAYMENT_DAYS = 400;
027        
028        public TriTachLoanBarEvent() {
029                super();
030        }
031        
032        public boolean shouldShowAtMarket(MarketAPI market) {
033                if (!super.shouldShowAtMarket(market)) return false;
034                
035                if (!market.getFactionId().equals(Factions.TRITACHYON)) {
036                        return false;
037                }
038                
039                if (market.getStabilityValue() < 4) return false;
040                
041                if (Global.getSector().getFaction(Factions.TRITACHYON).getRelToPlayer().isAtBest(RepLevel.HOSTILE)) {
042                        return false;
043                }
044                
045                return true;
046        }
047        
048        protected int loanAmount;
049        protected int repaymentAmount;
050        protected int repaymentDays;
051        //protected boolean negotiated = false;
052        
053        @Override
054        protected void regen(MarketAPI market) {
055                if (this.market == market) return;
056                
057                super.regen(market);
058                
059                loanAmount = 200000 + random.nextInt(6) * 10000;
060                repaymentAmount = (int) (loanAmount * 1.5f);
061                //repaymentDays = 365;
062                repaymentDays = REPAYMENT_DAYS;
063        }
064
065        @Override
066        protected void doStandardConfirmActions() {
067                CargoAPI cargo = Global.getSector().getPlayerFleet().getCargo();
068                cargo.getCredits().add(loanAmount);
069                
070                TextPanelAPI text = dialog.getTextPanel();
071                AddRemoveCommodity.addCreditsGainText(loanAmount, text);
072                
073                createIntel();
074        }
075        
076        protected int getNegotiatedAmount() {
077                return repaymentAmount - (int) ((repaymentAmount - loanAmount) * 0.5f);
078        }
079        
080        protected void addStoryOption() {
081                String id = "negotiate_id";
082                options.addOption("Negotiate a lower rate on the loan", id);
083                
084                StoryOptionParams params = new StoryOptionParams(id, 1, "negotiateLoanRate", Sounds.STORY_POINT_SPEND_TECHNOLOGY,
085                                "Negotiated lower rate on " + Misc.getDGSCredits(loanAmount) + " loan from Tri-Tachyon investor");
086                
087                SetStoryOption.set(dialog, params, 
088                        new BaseOptionStoryPointActionDelegate(dialog, params) {
089
090                                @Override
091                                public void confirm() {
092                                        super.confirm();
093                                        repaymentAmount = getNegotiatedAmount();
094                                        //negotiated = true;
095                                        dialog.getTextPanel().addPara(getNegotiatedText());
096                                        OptionPanelAPI options = dialog.getOptionPanel();
097                                        options.clearOptions();
098                                        options.addOption("Continue", OPTION_CONFIRM);
099                                        //optionSelected(null, OPTION_CONFIRM);
100                                }
101                                
102                                @Override
103                                public String getTitle() {
104                                        //return "Negotiating loan repayment";
105                                        return null;
106                                }
107
108                                @Override
109                                public void createDescription(TooltipMakerAPI info) {
110                                        float opad = 10f;
111                                        info.setParaInsigniaLarge();
112                                        
113                                        info.addSpacer(-opad * 1f);
114                                        
115                                        info.addPara("The loan amount is %s.",
116                                                        0f, Misc.getHighlightColor(),
117                                                        Misc.getDGSCredits(loanAmount));
118                                        
119                                        info.addPara("You're able to negotiate the repayment amount from %s down to " +
120                                                        "%s.", opad, Misc.getHighlightColor(),
121                                                        Misc.getDGSCredits(repaymentAmount),
122                                                        Misc.getDGSCredits(getNegotiatedAmount()));
123                                        
124                                        info.addSpacer(opad * 2f);
125                                        addActionCostSection(info);
126                                }
127                        
128                });
129        }
130        
131        @Override
132        public void optionSelected(String optionText, Object optionData) {
133                super.optionSelected(optionText, optionData);
134        }
135
136        protected void createIntel() {
137                TriTachLoanIntel intel = new TriTachLoanIntel(this, market);
138                Global.getSector().getIntelManager().addIntel(intel, false, dialog.getTextPanel());
139        }
140
141        @Override
142        protected String getPersonFaction() {
143                return Factions.TRITACHYON;
144        }
145        
146        @Override
147        protected String getPersonRank() {
148                return Ranks.CITIZEN;
149        }
150
151// do this after load is repaid
152//      @Override
153//      protected void doExtraConfirmActions() {
154//              ContactIntel.addPotentialContact(person, market, text);
155//      }
156
157        @Override
158        protected void adjustPerson(PersonAPI person) {
159                super.adjustPerson(person);
160                person.setImportanceAndVoice(PersonImportance.MEDIUM, random);
161                person.addTag(Tags.CONTACT_TRADE);
162        }
163        
164        @Override
165        protected String getPersonPost() {
166                return Ranks.POST_EXECUTIVE;
167        }
168        
169        @Override
170        protected float getPriceMult() {
171                return 0;
172        }
173        
174        @Override
175        protected String getPrompt() {
176                return "A Tri-Tachyon careerist sits at a spotless table, sipping something expensive-looking.";
177        }
178        
179        @Override
180        protected String getOptionText() {
181                return "Introduce yourself to the Tri-Tachyon " + getManOrWoman() + " and try to land some investment credits";
182        }
183        
184        @Override
185        protected String getMainText() {
186                return "A young Tri-Tachyon factioneer in a perfect suit sips from some insubstantial drink " +
187                                "as sophisticated as it is expensive. After introductions " + getHeOrShe() + 
188                                " quickly cuts to the point, and says \"I'm simply in the business of statistics, and " +
189                                "I like your growth potential. I think that you can take my %s now and pay " +
190                                "%s back to me in, oh, %s days. If not, \"" + getHeOrShe() + 
191                                " mimics a stricken look, \"I'll ruin your reputation across Tri-Tachyon space. What do you say?\"";
192        }
193        
194        @Override
195        protected String [] getMainTextTokens() {
196                return new String [] { Misc.getDGSCredits(loanAmount), Misc.getDGSCredits(repaymentAmount), 
197                                                           "" + (int)repaymentDays };
198        }
199        @Override
200        protected Color [] getMainTextColors() {
201                return new Color [] { Misc.getHighlightColor(), Misc.getHighlightColor(), Misc.getHighlightColor() };
202        }
203        
204        @Override
205        protected String getConfirmText() {
206                return "Accept the deal and order another round to celebrate";
207        }
208        
209        @Override
210        protected String getCancelText() {
211                return "Decline the deal, explaining that you're \"just here to network\"";
212        }
213
214        protected String getNegotiatedText() {
215                return "The Tri-Tachyon " + getManOrWoman() + "'s smile freezes in place as you launch into a sophisticated " + 
216                " pitch to modify the proposed terms. You notice " + getHisOrHer() + 
217                " eyes tracking rapidly, navigating some ocular data interface as you speak; " + getHeOrShe() + 
218                " seems thrown off-balance by your savvy, and never quite recovers that signature megacorp implacability." +
219                " By the time it is agreed that a substantially lower repayment figure will benefit all parties, the dazed " + 
220                "investor finds " + getHisOrHer() + " drink has gone flat. " + getHeOrShe() + " brusquely orders a replacement.";
221        }
222        
223        @Override
224        protected String getAcceptText() {
225                return "You leave the lounge rich in credits, having exchanged secure comm keys with the " +
226                                "Tri-Tachyon shark and receiving the transfer immediately. Your head spins with plans " +
227                                "for how to leverage your new assets - and a bit from the drink, you admit to yourself.";
228        }
229
230        
231        
232        public int getLoanAmount() {
233                return loanAmount;
234        }
235
236        public void setLoanAmount(int loanAmount) {
237                this.loanAmount = loanAmount;
238        }
239
240        public int getRepaymentAmount() {
241                return repaymentAmount;
242        }
243
244        public void setRepaymentAmount(int repaymentAmount) {
245                this.repaymentAmount = repaymentAmount;
246        }
247
248        public int getRepaymentDays() {
249                return repaymentDays;
250        }
251
252        public void setRepaymentDays(int repaymentDays) {
253                this.repaymentDays = repaymentDays;
254        }
255        
256        protected boolean showCargoCap() {
257                return false;
258        }
259        
260}
261
262
263