Starsector API
Loading...
Searching...
No Matches
StoragePlugin.java
Go to the documentation of this file.
1package com.fs.starfarer.api.impl.campaign.submarkets;
2
3import java.awt.Color;
4
5import com.fs.starfarer.api.Global;
6import com.fs.starfarer.api.Script;
7import com.fs.starfarer.api.campaign.CampaignFleetAPI;
8import com.fs.starfarer.api.campaign.CargoStackAPI;
9import com.fs.starfarer.api.campaign.CoreUIAPI;
10import com.fs.starfarer.api.campaign.econ.SubmarketAPI;
11import com.fs.starfarer.api.fleet.FleetMemberAPI;
12import com.fs.starfarer.api.impl.campaign.ids.Strings;
13import com.fs.starfarer.api.ui.TooltipMakerAPI;
14import com.fs.starfarer.api.util.Highlights;
15import com.fs.starfarer.api.util.Misc;
16
17public class StoragePlugin extends BaseSubmarketPlugin {
18
19 private boolean playerPaidToUnlock = false;
20
22 super.init(submarket);
23 }
24
26
27 }
28
29 @Override
30 public boolean isIllegalOnSubmarket(CargoStackAPI stack, TransferAction action) {
31 if (market.isPlayerOwned()) return false;
32 return super.isIllegalOnSubmarket(stack, action);
33 }
34
35 @Override
36 public boolean isIllegalOnSubmarket(String commodityId, TransferAction action) {
37 if (market.isPlayerOwned()) return false;
38 return super.isIllegalOnSubmarket(commodityId, action);
39 }
40
41 @Override
42 public boolean isIllegalOnSubmarket(FleetMemberAPI member, TransferAction action) {
43 if (market.isPlayerOwned() ||
44 (market.getFaction() != null && market.getFaction().isNeutralFaction())) return false;
45 return super.isIllegalOnSubmarket(member, action);
46 }
47
48 public boolean isParticipatesInEconomy() {
49 return false;
50 }
51
52 public float getTariff() {
53 return 0f;
54 }
55
56 @Override
57 public boolean isFreeTransfer() {
58 return true;
59 }
60
61 @Override
62 public String getBuyVerb() {
63 return "Take";
64 }
65
66 @Override
67 public String getSellVerb() {
68 return "Leave";
69 }
70
71 public String getIllegalTransferText(CargoStackAPI stack, TransferAction action) {
72 return "Illegal to put into storage here";
73 }
74
75// @Override
76// public void reportPlayerMarketTransaction(PlayerMarketTransaction transaction) {
77// // do nothing; don't want to adjust market stockpiles since player storage
78// // doesn't affect those
79// // don't need to do this since isParticipatesInEconomy() returns false
80// }
81
82
83
84 public boolean isEnabled(CoreUIAPI ui) {
85 //if (mode == CoreUITradeMode.SNEAK) return false;
86 //return playerPaidToUnlock;
87 return true;
88 }
89
90 public void setPlayerPaidToUnlock(boolean playerPaidToUnlock) {
91 this.playerPaidToUnlock = playerPaidToUnlock;
92 }
93
94 public OnClickAction getOnClickAction(CoreUIAPI ui) {
95 if (playerPaidToUnlock) return OnClickAction.OPEN_SUBMARKET;
96 return OnClickAction.SHOW_TEXT_DIALOG;
97 }
98
99 private int getUnlockCost() {
100 return 5000;
101 }
102
103 private boolean canPlayerAffordUnlock() {
105 int credits = (int) playerFleet.getCargo().getCredits().get();
106 return credits >= getUnlockCost();
107 }
108
109 public String getDialogText(CoreUIAPI ui) {
110 if (canPlayerAffordUnlock()) {
111 return "Gaining access to storage at this colony requires a one-time fee of " + getUnlockCost() + " credits.";
112 } else {
113 return "Gaining access to storage at this colony requires a one-time fee of " + getUnlockCost() + " credits, which you can't afford.";
114 }
115 }
117 Highlights h = new Highlights();
118 h.setText("" + getUnlockCost());
119 if (canPlayerAffordUnlock()) {
121 } else {
123 }
124 return h;
125 }
126 public DialogOption [] getDialogOptions(CoreUIAPI ui) {
127 if (canPlayerAffordUnlock()) {
128 return new DialogOption [] {
129 new DialogOption("Pay", new Script() {
130 public void run() {
132 playerFleet.getCargo().getCredits().subtract(getUnlockCost());
133 playerPaidToUnlock = true;
134 }
135 }),
136 new DialogOption("Never mind", null)
137 };
138 } else {
139 return new DialogOption [] {
140 new DialogOption("Never mind", null)
141 };
142 }
143 }
144 public String getTooltipAppendix(CoreUIAPI ui) {
145// if (!playerPaidToUnlock) {
146// return "Requires a one-time access fee of " + getUnlockCost() + " credits.";
147// }
148 return null;
149 }
151// String appendix = getTooltipAppendix(ui);
152// if (appendix == null) return null;
153//
154// Highlights h = new Highlights();
155// h.setText("" + getUnlockCost());
156// if (canPlayerAffordUnlock()) {
157// h.setColors(Misc.getHighlightColor());
158// } else {
159// h.setColors(Misc.getNegativeHighlightColor());
160// }
161// return h;
162 return null;
163 }
164
165 @Override
166 protected void createTooltipAfterDescription(TooltipMakerAPI tooltip, boolean expanded) {
167
168 if (!market.isInEconomy()) return;
169
170 float opad = 10f;
171 float pad = 3f;
172 if (market.isPlayerOwned()) {
173 tooltip.addPara(Misc.getTokenReplaced("$marketName is under your control, and there " +
174 "are no storage fees or expenses.", market.getPrimaryEntity()), opad);
175 return;
176 }
177
178 float f = Misc.getStorageFeeFraction();
179 int percent = (int) (f * 100f);
180
181 Color h = Misc.getHighlightColor();
182
183 if (!playerPaidToUnlock) {
184 tooltip.addPara("Requires a one-time access fee of %s, and a monthly fee equal to %s of the " +
185 "base value of the items in storage.", opad, h,
186 "" + getUnlockCost() + Strings.C, "" + percent + "%");
187 return;
188 }
189
190 int cargoCost = (int) (Misc.getStorageCargoValue(market) * f);
191 int shipCost = (int) (Misc.getStorageShipValue(market) * f);
192
193 if (cargoCost + shipCost > 0) {
194 //tooltip.beginGrid(150, 1);
195 tooltip.addPara("Monthly fees and expenses (%s of base value of stored items):", opad, h, "" + percent + "%");
196 tooltip.beginGridFlipped(300, 1, 80, 10);
197 int j = 0;
198 tooltip.addToGrid(0, j++, "Ships in storage", Misc.getDGSCredits(shipCost));
199 tooltip.addToGrid(0, j++, "Cargo in storage", Misc.getDGSCredits(cargoCost));
200 tooltip.addGrid(pad);
201 } else {
202 tooltip.addPara("Monthly fees and expenses are equal to %s of base value of the stored items.", opad, h, "" + percent + "%");
203 }
204 }
205
206
207}
208
209
210
211
212
static SectorAPI getSector()
Definition Global.java:65
void createTooltipAfterDescription(TooltipMakerAPI tooltip, boolean expanded)
boolean isIllegalOnSubmarket(FleetMemberAPI member, TransferAction action)
boolean isIllegalOnSubmarket(CargoStackAPI stack, TransferAction action)
String getIllegalTransferText(CargoStackAPI stack, TransferAction action)
boolean isIllegalOnSubmarket(String commodityId, TransferAction action)
void setColors(Color ... colors)
static String getDGSCredits(float num)
Definition Misc.java:1390
static float getStorageShipValue(MarketAPI market)
Definition Misc.java:4333
static float getStorageFeeFraction()
Definition Misc.java:4286
static Color getNegativeHighlightColor()
Definition Misc.java:802
static float getStorageCargoValue(MarketAPI market)
Definition Misc.java:4323
static String getTokenReplaced(String in, SectorEntityToken entity)
Definition Misc.java:4399
static Color getHighlightColor()
Definition Misc.java:792
Object addToGrid(int x, int y, String label, String value)
LabelAPI addPara(String format, float pad, Color hl, String... highlights)
void beginGridFlipped(float itemWidth, int cols, float valueWidth, float valuePad)