Starsector API
Loading...
Searching...
No Matches
DemandCargo.java
Go to the documentation of this file.
1package com.fs.starfarer.api.impl.campaign.rulecmd.salvage;
2
3import java.util.ArrayList;
4import java.util.List;
5import java.util.Map;
6import java.util.Random;
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.CargoStackAPI;
12import com.fs.starfarer.api.campaign.FactionAPI;
13import com.fs.starfarer.api.campaign.InteractionDialogAPI;
14import com.fs.starfarer.api.campaign.OptionPanelAPI;
15import com.fs.starfarer.api.campaign.SectorEntityToken;
16import com.fs.starfarer.api.campaign.TextPanelAPI;
17import com.fs.starfarer.api.campaign.econ.CommoditySpecAPI;
18import com.fs.starfarer.api.campaign.rules.MemoryAPI;
19import com.fs.starfarer.api.characters.PersonAPI;
20import com.fs.starfarer.api.fleet.FleetMemberAPI;
21import com.fs.starfarer.api.impl.campaign.ids.Commodities;
22import com.fs.starfarer.api.impl.campaign.rulecmd.BaseCommandPlugin;
23import com.fs.starfarer.api.util.Misc;
24import com.fs.starfarer.api.util.Misc.Token;
25
28public class DemandCargo extends BaseCommandPlugin {
29
30 public static class DemandData {
31 public CargoAPI cargo;//Global.getFactory().createCargo(true);
32 public List<FleetMemberAPI> ships = new ArrayList<FleetMemberAPI>();
33 public int credits = 0;
34 public boolean hasAnythingWorthwhile = true;
35 }
36
37
38
39 protected CampaignFleetAPI playerFleet;
40 protected CampaignFleetAPI otherFleet;
41 protected SectorEntityToken entity;
42 protected FactionAPI playerFaction;
43 protected FactionAPI entityFaction;
44 protected TextPanelAPI text;
45 protected OptionPanelAPI options;
46 protected CargoAPI playerCargo;
47 protected MemoryAPI memory;
48 protected InteractionDialogAPI dialog;
49 protected Map<String, MemoryAPI> memoryMap;
50 protected PersonAPI person;
51 protected FactionAPI faction;
52
53 protected boolean buysAICores;
54 protected float valueMult;
55 protected float repMult;
56
57 protected DemandData data = new DemandData();
58
59 public DemandCargo() {
60 super();
61 }
62
63 public boolean execute(String ruleId, InteractionDialogAPI dialog, List<Token> params, Map<String, MemoryAPI> memoryMap) {
64
65// Pirate interaction flow:
66// They hail you OR you open the comm link and "perhaps we can avoid fighting"
67// <some greeting/setup text>
68// -> Continue
69// <negotiating text, list of stuff>
70// -> Cut the comm link, OR
71// -> Order the transfer
72// <lost X> text
73// -> Continue?
74// <ending text, allow you to disengage>
75// -> Cut the comm link
76
77 this.dialog = dialog;
78 this.memoryMap = memoryMap;
79
80 String command = params.get(0).getString(memoryMap);
81 if (command == null) return false;
82
84
85 entity = dialog.getInteractionTarget();
86 text = dialog.getTextPanel();
87 options = dialog.getOptionPanel();
88
89 otherFleet = (CampaignFleetAPI) entity;
90
91 playerFleet = Global.getSector().getPlayerFleet();
92 playerCargo = playerFleet.getCargo();
93
94 playerFaction = Global.getSector().getPlayerFaction();
95 entityFaction = entity.getFaction();
96
97 person = dialog.getInteractionTarget().getActivePerson();
98 if (person != null) {
99 faction = person.getFaction();
100 } else {
102 }
103
104 String key = "$DemandCargo_temp";
105 MemoryAPI mem = otherFleet.getMemoryWithoutUpdate();
106 if (mem.contains(key)) {
107 data = (DemandData) mem.get(key);
108 } else {
109 data = new DemandData();
110 data.cargo = Global.getFactory().createCargo(true);;
111 mem.set(key, data, 0f);
112 }
113
114 if (command.equals("selectCargo")) {
115 selectCores();
116 } else if (command.equals("playerHasValuableCargo")) {
117 //return playerHasCores();
118 }
119
120 return true;
121 }
122
123 protected Random getRandom() {
124 String key = "$DemandCargo_random";
125 MemoryAPI mem = otherFleet.getMemoryWithoutUpdate();
126 Random random = null;
127 if (mem.contains(key)) {
128 random = (Random) mem.get(key);
129 } else {
130 //random = new Random(Misc.getSalvageSeed(otherFleet));
131 long seed = Misc.getSalvageSeed(otherFleet);
132 seed /= 321L;
133 seed *= (Global.getSector().getClock().getMonth() + 10);
134 random = new Random(seed);
135 }
136 mem.set(key, random, 30f);
137
138 return random;
139 }
140
141 protected void computeAndPrintDemands() {
142 int fleetValue = 0;
143
144 for (FleetMemberAPI member : playerFleet.getFleetData().getMembersListCopy()) {
145 fleetValue += member.getHullSpec().getBaseValue();
146 }
147
148 for (CargoStackAPI stack : playerCargo.getStacksCopy()) {
149 fleetValue += stack.getBaseValuePerUnit() * stack.getSize();
150 }
151
152 float demandFraction = 0.2f;
153
154 float rel = otherFleet.getFaction().getRelToPlayer().getRel();
155
156 if (rel > 0) {
157 demandFraction *= (0.2f + 0.8f * rel);
158 }
159
160 int demandValue = (int) (fleetValue * demandFraction);
161
162 Random random = getRandom();
163
164
165
166 }
167
168
169
170 protected void selectCores() {
171 CargoAPI copy = Global.getFactory().createCargo(false);
172 //copy.addAll(cargo);
173 for (CargoStackAPI stack : playerCargo.getStacksCopy()) {
174 CommoditySpecAPI spec = stack.getResourceIfResource();
175 if (spec != null && spec.getDemandClass().equals(Commodities.AI_CORES)) {
176 copy.addFromStack(stack);
177 }
178 }
179 copy.sort();
180
181// final float width = 310f;
182// dialog.showCargoPickerDialog("Select AI cores to turn in", "Confirm", "Cancel", true, width, copy, new CargoPickerListener() {
183// public void pickedCargo(CargoAPI cargo) {
184// cargo.sort();
185// for (CargoStackAPI stack : cargo.getStacksCopy()) {
186// playerCargo.removeItems(stack.getType(), stack.getData(), stack.getSize());
187// if (stack.isCommodityStack()) { // should be always, but just in case
188// AddRemoveCommodity.addCommodityLossText(stack.getCommodityId(), (int) stack.getSize(), text);
189// }
190// }
191//
192// float bounty = computeCoreCreditValue(cargo);
193// float repChange = computeCoreReputationValue(cargo);
194//
195// if (bounty > 0) {
196// playerCargo.getCredits().add(bounty);
197// AddRemoveCommodity.addCreditsGainText((int)bounty, text);
198// }
199//
200// if (repChange >= 1f) {
201// CustomRepImpact impact = new CustomRepImpact();
202// impact.delta = repChange * 0.01f;
203// Global.getSector().adjustPlayerReputation(
204// new RepActionEnvelope(RepActions.CUSTOM, impact,
205// null, text, true),
206// faction.getId());
207//
208// impact.delta *= 0.25f;
209// if (impact.delta >= 0.01f) {
210// Global.getSector().adjustPlayerReputation(
211// new RepActionEnvelope(RepActions.CUSTOM, impact,
212// null, text, true),
213// person);
214// }
215// }
216//
217// FireBest.fire(null, dialog, memoryMap, "AICoresTurnedIn");
218// }
219// public void cancelledCargoSelection() {
220// }
221// public void recreateTextPanel(TooltipMakerAPI panel, CargoAPI cargo, CargoStackAPI pickedUp, boolean pickedUpFromSource, CargoAPI combined) {
222//
223// float bounty = computeCoreCreditValue(combined);
224// float repChange = computeCoreReputationValue(combined);
225//
226// float pad = 3f;
227// float small = 5f;
228// float opad = 10f;
229//
230// panel.setParaFontOrbitron();
231// panel.addPara(Misc.ucFirst(faction.getDisplayName()), faction.getBaseUIColor(), 1f);
232// //panel.addPara(faction.getDisplayNameLong(), faction.getBaseUIColor(), opad);
233// //panel.addPara(faction.getDisplayName() + " (" + entity.getMarket().getName() + ")", faction.getBaseUIColor(), opad);
234// panel.setParaFontDefault();
235//
236// panel.addImage(faction.getLogo(), width * 1f, pad);
237//
238//
239// //panel.setParaFontColor(Misc.getGrayColor());
240// //panel.setParaSmallInsignia();
241// //panel.setParaInsigniaLarge();
242// panel.addPara("Compared to dealing with other factions, turning AI cores in to " +
243// faction.getDisplayNameLongWithArticle() + " " +
244// "will result in:", opad);
245// panel.beginGridFlipped(width, 1, 40f, 10f);
246// //panel.beginGrid(150f, 1);
247// panel.addToGrid(0, 0, "Bounty value", "" + (int)(valueMult * 100f) + "%");
248// panel.addToGrid(0, 1, "Reputation gain", "" + (int)(repMult * 100f) + "%");
249// panel.addGrid(pad);
250//
251// panel.addPara("If you turn in the selected AI cores, you will receive a %s bounty " +
252// "and your standing with " + faction.getDisplayNameWithArticle() + " will improve by %s points.",
253// opad * 1f, Misc.getHighlightColor(),
254// Misc.getWithDGS(bounty) + Strings.C,
255// "" + (int) repChange);
256//
257//
258// //panel.addPara("Bounty: %s", opad, Misc.getHighlightColor(), Misc.getWithDGS(bounty) + Strings.C);
259// //panel.addPara("Reputation: %s", pad, Misc.getHighlightColor(), "+12");
260// }
261// });
262 }
263
264
265
266
267
268}
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
static FactoryAPI getFactory()
Definition Global.java:35
static SectorAPI getSector()
Definition Global.java:59
static MemoryAPI getEntityMemory(Map< String, MemoryAPI > memoryMap)
boolean execute(String ruleId, InteractionDialogAPI dialog, List< Token > params, Map< String, MemoryAPI > memoryMap)
CargoAPI createCargo(boolean unlimitedStacks)