Starsector API
Loading...
Searching...
No Matches
DistressResponse.java
Go to the documentation of this file.
1package com.fs.starfarer.api.impl.campaign.rulecmd.salvage;
2
3import java.util.List;
4import java.util.Map;
5
6import org.lwjgl.util.vector.Vector2f;
7
8import com.fs.starfarer.api.Global;
9import com.fs.starfarer.api.campaign.CampaignFleetAPI;
10import com.fs.starfarer.api.campaign.CargoAPI;
11import com.fs.starfarer.api.campaign.FactionAPI;
12import com.fs.starfarer.api.campaign.InteractionDialogAPI;
13import com.fs.starfarer.api.campaign.OptionPanelAPI;
14import com.fs.starfarer.api.campaign.RepLevel;
15import com.fs.starfarer.api.campaign.SectorEntityToken;
16import com.fs.starfarer.api.campaign.SectorEntityToken.VisibilityLevel;
17import com.fs.starfarer.api.campaign.TextPanelAPI;
18import com.fs.starfarer.api.campaign.econ.CommoditySpecAPI;
19import com.fs.starfarer.api.campaign.rules.MemoryAPI;
20import com.fs.starfarer.api.characters.AbilityPlugin;
21import com.fs.starfarer.api.characters.PersonAPI;
22import com.fs.starfarer.api.fleet.FleetMemberAPI;
23import com.fs.starfarer.api.impl.campaign.abilities.DistressCallAbility;
24import com.fs.starfarer.api.impl.campaign.ids.Abilities;
25import com.fs.starfarer.api.impl.campaign.ids.Commodities;
26import com.fs.starfarer.api.impl.campaign.ids.Entities;
27import com.fs.starfarer.api.impl.campaign.ids.Strings;
28import com.fs.starfarer.api.impl.campaign.rulecmd.AddRemoveCommodity;
29import com.fs.starfarer.api.impl.campaign.rulecmd.BaseCommandPlugin;
30import com.fs.starfarer.api.util.Misc;
31import com.fs.starfarer.api.util.Misc.Token;
32
37public class DistressResponse extends BaseCommandPlugin {
38
39 //public static float REP_NORMAL = -0.05f;
40 public static float REP_PER_USE = -0.02f;
41 public static float REP_SCAM = -0.15f;
42
48 protected TextPanelAPI text;
51 protected MemoryAPI memory;
53 protected Map<String, MemoryAPI> memoryMap;
54 protected PersonAPI person;
56
57 public boolean execute(String ruleId, InteractionDialogAPI dialog, List<Token> params, Map<String, MemoryAPI> memoryMap) {
58
59 this.dialog = dialog;
60 this.memoryMap = memoryMap;
61
62 String command = params.get(0).getString(memoryMap);
63 if (command == null) return false;
64
66
70
73
76
79
81
82 if (command.equals("playerNeedsHelp")) {
83 return playerNeedsHelp();
84 } else if (command.equals("didNotNeedHelp")) {
86 }
87 else if (command.equals("acceptHelp")) {
88 acceptAid();
89 }
90 else if (command.equals("neverMind")) {
91 neverMind();
92 }
93 else if (command.equals("isCargoPodsScam")) {
94 return isCargoPodsScam();
95 }
96 else if (command.equals("cargoPodsScam")) {
98 }
99 else if (command.equals("unrespond")) {
100 unrespond();
101 }
102 else if (command.equals("init")) {
103 init();
104 }
105 else if (command.equals("pay")) {
106 pay();
107 }
108 else if (command.equals("thank")) {
109 thank();
110 }
111
112 return true;
113 }
114
115 protected void init() {
116 person.getMemoryWithoutUpdate().set("$distressUsesLastCycle", getNumUses(), 0);
117
118 int fuel = getNeededFuel();
119 int supplies = getNeededSupplies();
120 int maxFuel = getMaxFuel();
121 int maxSupplies = getMaxSupplies();
122
123 boolean adequate = fuel <= maxFuel * 1.5f && supplies <= maxSupplies * 1.5f;
124 person.getMemoryWithoutUpdate().set("$distressHelpAdequate", adequate, 0);
125
126
127 int distressPayment = getPayment();
128 person.getMemoryWithoutUpdate().set("$distressPayment", Misc.getWithDGS(distressPayment), 0);
129 person.getMemoryWithoutUpdate().set("$distressPaymentC", Misc.getWithDGS(distressPayment) + Strings.C, 0);
130 person.getMemoryWithoutUpdate().set("$distressCanAfford", distressPayment <= playerCargo.getCredits().get(), 0);
131 }
132
133 protected int getPayment() {
134 int fuel = getNeededFuel();
135 int supplies = getNeededSupplies();
136 int maxFuel = getMaxFuel();
137 int maxSupplies = getMaxSupplies();
138 if (fuel > maxFuel) fuel = maxFuel;
139 if (supplies > maxSupplies) supplies = maxSupplies;
140
143
144 float distressPayment = fuel * fuelComm.getBasePrice() + supplies * suppliesComm.getBasePrice();
145 distressPayment = (float) Math.ceil(distressPayment / 10000f) * 10000f;
146 distressPayment *= 2f;
147
148 return (int) distressPayment;
149 }
150
151 protected int getNumUses() {
153 if (plugin != null) {
154 int uses = ((DistressCallAbility) plugin).getNumUsesInLastPeriod();
155 return uses;
156 }
157 return 0;
158 }
159
160 protected boolean playerNeedsHelp() {
161 return getNeededFuel() > 0 || getNeededSupplies() > 0;
162 }
163
170
171
172 protected boolean isCargoPodsScam () {
175 VisibilityLevel level = entity.getVisibilityLevelTo(fleet);
176 if (level == VisibilityLevel.COMPOSITION_DETAILS ||
177 level == VisibilityLevel.COMPOSITION_AND_FACTION_DETAILS) {
178 if (entity.getCargo().getFuel() >= 10 || entity.getCargo().getSupplies() >= 10) {
179 return true;
180 }
181 }
182 }
183 }
184 return false;
185 }
186
187 protected int getNeededFuel() {
189 }
190
192 float returnDistLY = Misc.getDistanceLY(new Vector2f(), playerFleet.getLocationInHyperspace());
193 int fuel = (int) (returnDistLY * Math.max(1, playerFleet.getLogistics().getFuelCostPerLightYear()));
194 fuel *= 0.75f;
195 if (fuel < 10) fuel = 10;
196 fuel -= playerFleet.getCargo().getFuel();
197 if (fuel < 0) fuel = 0;
198
199 return fuel;
200 }
201
202 protected int getNeededSupplies() {
203 //int supplies = (int) (playerCargo.getMaxCapacity() * 0.25f);
204 float supplies = 0f;
206 supplies += member.getStats().getSuppliesPerMonth().getModifiedValue();
207 }
208 //supplies *= 2;
209
210 if (supplies < 5) supplies = 5;
211 supplies -= playerCargo.getSupplies();
212 if (supplies < 0) supplies = 0;
213
214 return (int) supplies;
215 }
216
217 protected float getRepPenalty() {
218 float uses = getNumUses();
219 return REP_PER_USE * (uses + 1);
220 }
221
222 protected void didNotNeedHelp() {
223 float penalty = getRepPenalty();
225 penalty * 2f, RepLevel.INHOSPITABLE, person, text);
226
227 unrespond();
228 }
229
230 protected void neverMind() {
231 float penalty = getRepPenalty();
233 penalty, RepLevel.INHOSPITABLE, person, text);
234 }
235
236 protected int getMaxFuel() {
237 return (int) Math.max(10, (fleet.getCargo().getMaxFuel() * 0.25f));
238 }
239 protected int getMaxSupplies() {
240 return (int) Math.max(10, (fleet.getCargo().getMaxCapacity() * 0.1f));
241 }
242
243 protected void pay() {
244 //int credits = getPayment();
245 int credits = (int) person.getMemoryWithoutUpdate().getFloat("$distressPayment");
248
249 float uses = getNumUses();
250 if (uses <= 4) {
252 0.02f, RepLevel.WELCOMING, person, text);
253 }
254 }
255
256 protected void thank() {
257 float penalty = getRepPenalty();
259 penalty * 2f, RepLevel.INHOSPITABLE, person, text);
260 }
261
262 protected void acceptAid() {
263 int fuel = getNeededFuel();
264 int supplies = getNeededSupplies();
265
266 int maxFuel = getMaxFuel();
267 int maxSupplies = getMaxSupplies();
268
269 if (fuel > maxFuel) fuel = maxFuel;
270 if (supplies > maxSupplies) supplies = maxSupplies;
271
272// float penalty = getRepPenalty();
273// Misc.adjustRep(penalty, RepLevel.INHOSPITABLE, fleet.getFaction().getId(),
274// penalty * 2f, RepLevel.INHOSPITABLE, person, text);
275
276 if (fuel > 0) {
277 playerCargo.addFuel(fuel);
279 }
280 if (supplies > 0) {
281 playerCargo.addSupplies(supplies);
283 }
284
285 unrespond();
286 }
287
288 protected void unrespond() {
289 Misc.clearTarget(fleet, true);
290 Misc.makeUnimportant(fleet, "distressResponse");
291 fleet.getMemoryWithoutUpdate().unset("$distressResponse");
293 }
294
295
296
297}
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
static SettingsAPI getSettings()
Definition Global.java:57
static SectorAPI getSector()
Definition Global.java:65
static void addCommodityGainText(String commodityId, int quantity, TextPanelAPI text)
static void addCreditsLossText(int credits, TextPanelAPI text)
static MemoryAPI getEntityMemory(Map< String, MemoryAPI > memoryMap)
boolean execute(String ruleId, InteractionDialogAPI dialog, List< Token > params, Map< String, MemoryAPI > memoryMap)
static String getWithDGS(float num)
Definition Misc.java:1381
static float getDistanceLY(SectorEntityToken from, SectorEntityToken to)
Definition Misc.java:602
static void giveStandardReturnToSourceAssignments(CampaignFleetAPI fleet)
Definition Misc.java:3836
static void adjustRep(float repChangeFaction, RepLevel limit, String factionId, float repChangePerson, RepLevel personLimit, PersonAPI person, TextPanelAPI text)
Definition Misc.java:3884
static void makeUnimportant(SectorEntityToken entity, String reason)
Definition Misc.java:4077
static void clearTarget(CampaignFleetAPI fleet, boolean forgetTransponder)
Definition Misc.java:3824
CommoditySpecAPI getCommoditySpec(String commodityId)
List< FleetMemberAPI > getMembersListCopy()
List< SectorEntityToken > getAllEntities()
VisibilityLevel getVisibilityLevelTo(SectorEntityToken other)
void set(String key, Object value)