1package com.fs.starfarer.api.impl.campaign.rulecmd;
6import com.fs.starfarer.api.GameState;
7import com.fs.starfarer.api.Global;
8import com.fs.starfarer.api.campaign.CampaignFleetAPI;
9import com.fs.starfarer.api.campaign.CargoAPI;
10import com.fs.starfarer.api.campaign.CargoStackAPI;
11import com.fs.starfarer.api.campaign.InteractionDialogAPI;
12import com.fs.starfarer.api.campaign.SpecialItemData;
13import com.fs.starfarer.api.campaign.TextPanelAPI;
14import com.fs.starfarer.api.campaign.econ.CommoditySpecAPI;
15import com.fs.starfarer.api.campaign.rules.MemoryAPI;
16import com.fs.starfarer.api.characters.PersonAPI;
17import com.fs.starfarer.api.combat.ShipVariantAPI;
18import com.fs.starfarer.api.fleet.FleetMemberAPI;
19import com.fs.starfarer.api.impl.campaign.ids.Strings;
20import com.fs.starfarer.api.loading.AbilitySpecAPI;
21import com.fs.starfarer.api.loading.FighterWingSpecAPI;
22import com.fs.starfarer.api.loading.WeaponSpecAPI;
23import com.fs.starfarer.api.ui.LabelAPI;
24import com.fs.starfarer.api.util.Misc;
25import com.fs.starfarer.api.util.Misc.Token;
26import com.fs.starfarer.api.util.MutableValue;
33 public boolean execute(String ruleId, InteractionDialogAPI dialog, List<Token> params, Map<String, MemoryAPI> memoryMap) {
34 if (dialog ==
null)
return false;
36 String commodityId = params.get(0).getString(memoryMap);
39 if (params.get(1).isOperator()) {
40 quantity = -1 * params.get(2).getFloat(memoryMap);
43 quantity = params.get(1).getFloat(memoryMap);
45 boolean withText = Math.abs(quantity) >= 1;
46 if (dialog !=
null && params.size() >= next + 1) {
47 withText = params.get(next).getBoolean(memoryMap) && withText;
50 if (commodityId.equals(
"credits")) {
51 MutableValue credits =
Global.
getSector().getPlayerFleet().getCargo().getCredits();
53 credits.add(quantity);
58 credits.subtract(Math.abs(quantity));
59 if (credits.get() < 0) credits.set(0);
66 Global.
getSector().getPlayerFleet().getCargo().addCommodity(commodityId, quantity);
71 Global.
getSector().getPlayerFleet().getCargo().removeCommodity(commodityId, Math.abs(quantity));
79 if (!
"credits".equals(commodityId)) {
88 if (
"credits".equals(commodityId)) {
90 MemoryAPI memory =
Global.
getSector().getCharacterData().getMemoryWithoutUpdate();
91 memory.set(
"$credits", (
int)fleet.getCargo().getCredits().get(), 0);
92 memory.set(
"$creditsStr", Misc.getWithDGS((
int)fleet.getCargo().getCredits().get()), 0);
93 memory.set(
"$creditsStrC", Misc.getWithDGS((
int)fleet.getCargo().getCredits().get()) + Strings.C, 0);
97 MemoryAPI memory =
Global.
getSector().getCharacterData().getMemoryWithoutUpdate();
98 String key =
"$" + commodityId;
99 if (memory.contains(key)) {
100 if (memory.get(key) instanceof Integer || memory.get(key) instanceof Float) {
101 memory.set(key, (
int)
Global.
getSector().getPlayerFleet().getCargo().getCommodityQuantity(commodityId), 0);
110 public static void addStackGainText(CargoStackAPI stack, TextPanelAPI text,
boolean lowerCase) {
111 if (stack.getSize() < 1)
return;
112 text.setFontSmallInsignia();
113 String name = stack.getDisplayName();
115 name = name.toLowerCase();
117 int quantity = (int) stack.getSize();
118 text.addParagraph(
"Gained " + Misc.getWithDGS(quantity) + Strings.X +
" " + name +
"", Misc.getPositiveHighlightColor());
119 text.highlightInLastPara(Misc.getHighlightColor(), Misc.getWithDGS(quantity) + Strings.X);
120 text.setFontInsignia();
126 if (spec ==
null)
return;
128 text.setFontSmallInsignia();
129 String name = spec.getWingName();
130 text.addParagraph(
"Gained " + Misc.getWithDGS(quantity) + Strings.X +
" " + name +
"", Misc.getPositiveHighlightColor());
131 text.highlightInLastPara(Misc.getHighlightColor(), Misc.getWithDGS(quantity) + Strings.X);
132 text.setFontInsignia();
136 if (spec ==
null)
return;
138 text.setFontSmallInsignia();
139 String name = spec.getWingName();
140 text.addParagraph(
"Lost " + Misc.getWithDGS(quantity) + Strings.X +
" " + name +
"", Misc.getNegativeHighlightColor());
141 text.highlightInLastPara(Misc.getHighlightColor(), Misc.getWithDGS(quantity) + Strings.X);
142 text.setFontInsignia();
147 if (spec ==
null)
return;
149 text.setFontSmallInsignia();
150 String name = spec.getWeaponName();
151 text.addParagraph(
"Gained " + Misc.getWithDGS(quantity) + Strings.X +
" " + name +
"", Misc.getPositiveHighlightColor());
152 text.highlightInLastPara(Misc.getHighlightColor(), Misc.getWithDGS(quantity) + Strings.X);
153 text.setFontInsignia();
157 if (spec ==
null)
return;
159 text.setFontSmallInsignia();
160 String name = spec.getWeaponName();
161 text.addParagraph(
"Lost " + Misc.getWithDGS(quantity) + Strings.X +
" " + name +
"", Misc.getNegativeHighlightColor());
162 text.highlightInLastPara(Misc.getHighlightColor(), Misc.getWithDGS(quantity) + Strings.X);
163 text.setFontInsignia();
166 public static void addItemGainText(SpecialItemData data,
int quantity, TextPanelAPI text) {
168 cargo.addSpecial(data, 1);
169 CargoStackAPI stack = cargo.getStacksCopy().get(0);
171 text.setFontSmallInsignia();
172 String name = stack.getDisplayName();
174 text.addParagraph(
"Gained " + name +
"", Misc.getPositiveHighlightColor());
175 text.highlightInLastPara(Misc.getHighlightColor(), name);
177 text.addParagraph(
"Gained " + Misc.getWithDGS(quantity) + Strings.X +
" " + name +
"", Misc.getPositiveHighlightColor());
178 text.highlightInLastPara(Misc.getHighlightColor(), Misc.getWithDGS(quantity) + Strings.X);
180 text.setFontInsignia();
182 public static void addItemLossText(SpecialItemData data,
int quantity, TextPanelAPI text) {
184 cargo.addSpecial(data, 1);
185 CargoStackAPI stack = cargo.getStacksCopy().get(0);
187 text.setFontSmallInsignia();
188 String name = stack.getDisplayName();
190 text.addParagraph(
"Lost " + name +
"", Misc.getNegativeHighlightColor());
191 text.highlightInLastPara(Misc.getHighlightColor(), name);
193 text.addParagraph(
"Lost " + Misc.getWithDGS(quantity) + Strings.X +
" " + name +
"", Misc.getNegativeHighlightColor());
194 text.highlightInLastPara(Misc.getHighlightColor(), Misc.getWithDGS(quantity) + Strings.X);
196 text.setFontInsignia();
201 text.setFontSmallInsignia();
204 String name = spec.getLowerCaseName();
207 text.addParagraph(
"Gained " + Misc.getWithDGS(quantity) + Strings.X +
" " + name +
"", Misc.getPositiveHighlightColor());
208 text.highlightInLastPara(Misc.getHighlightColor(), Misc.getWithDGS(quantity) + Strings.X);
209 text.setFontInsignia();
214 text.setFontSmallInsignia();
217 String name = spec.getLowerCaseName();
220 text.addParagraph(
"Lost " + Misc.getWithDGS(quantity) + Strings.X +
" " + name +
"", Misc.getNegativeHighlightColor());
221 text.highlightInLastPara(Misc.getHighlightColor(), Misc.getWithDGS(quantity) + Strings.X);
222 text.setFontInsignia();
226 text.setFontSmallInsignia();
227 String str = Misc.getWithDGS(credits) + Strings.C;
228 text.addParagraph(
"Gained " + str +
"", Misc.getPositiveHighlightColor());
229 text.highlightInLastPara(Misc.getHighlightColor(), str);
230 text.setFontInsignia();
234 MemoryAPI memory =
Global.
getSector().getCharacterData().getMemoryWithoutUpdate();
235 memory.set(
"$credits", (
int)fleet.getCargo().getCredits().get(), 0);
236 memory.set(
"$creditsStr", Misc.getWithDGS((
int)fleet.getCargo().getCredits().get()), 0);
237 memory.set(
"$creditsStrC", Misc.getWithDGS((
int)fleet.getCargo().getCredits().get()) + Strings.C, 0);
242 text.setFontSmallInsignia();
243 String str = Misc.getWithDGS(credits) + Strings.C;
244 text.addParagraph(
"Lost " + str +
"", Misc.getNegativeHighlightColor());
245 text.highlightInLastPara(Misc.getHighlightColor(), str);
246 text.setFontInsignia();
250 MemoryAPI memory =
Global.
getSector().getCharacterData().getMemoryWithoutUpdate();
251 memory.set(
"$credits", (
int)fleet.getCargo().getCredits().get(), 0);
252 memory.set(
"$creditsStr", Misc.getWithDGS((
int)fleet.getCargo().getCredits().get()), 0);
253 memory.set(
"$creditsStrC", Misc.getWithDGS((
int)fleet.getCargo().getCredits().get()) + Strings.C, 0);
260 text.setFontSmallInsignia();
261 String str =
"\"" + ability.getName() +
"\"";
262 text.addParagraph(
"Gained ability: " + str +
"", Misc.getPositiveHighlightColor());
263 text.highlightInLastPara(Misc.getHighlightColor(), str);
264 text.setFontInsignia();
269 text.setFontSmallInsignia();
270 String rank = officer.getRank();
272 rank = Misc.ucFirst(rank);
274 String str = officer.getName().getFullName();
275 if (rank !=
null) str = rank +
" " + str;
276 LabelAPI label = text.addParagraph(str +
" (level " + officer.getStats().getLevel() +
") has joined your fleet", Misc.getPositiveHighlightColor());
277 label.setHighlightColors(Misc.getHighlightColor(), Misc.getHighlightColor());
278 label.setHighlight(str,
"(level " + officer.getStats().getLevel() +
")");
280 text.setFontInsignia();
284 text.setFontSmallInsignia();
285 String rank = officer.getRank();
287 rank = Misc.ucFirst(rank);
289 String str = officer.getName().getFullName();
290 if (rank !=
null) str = rank +
" " + str;
291 text.addParagraph(str +
" has left your fleet", Misc.getNegativeHighlightColor());
292 text.highlightInLastPara(Misc.getHighlightColor(), str);
293 text.setFontInsignia();
297 text.setFontSmallInsignia();
302 String rank =
"Administrator";
303 String str = admin.getName().getFullName();
304 if (rank !=
null) str = rank +
" " + str;
305 text.addParagraph(str +
" has entered your service", Misc.getPositiveHighlightColor());
306 text.highlightInLastPara(Misc.getHighlightColor(), str);
307 text.setFontInsignia();
312 text.setFontSmallInsignia();
313 String str = member.getShipName() +
", " + member.getVariant().getHullSpec().getHullNameWithDashClass() +
" " + member.getVariant().getHullSpec().getDesignation();
314 text.addParagraph(
"Acquired " + str +
"", Misc.getPositiveHighlightColor());
315 text.highlightInLastPara(Misc.getHighlightColor(), str);
316 text.setFontInsignia();
320 text.setFontSmallInsignia();
321 String str = member.getShipName() +
", " + member.getVariant().getHullSpec().getHullNameWithDashClass() +
" " + member.getVariant().getHullSpec().getDesignation();
322 text.addParagraph(
"Lost " + str +
"", Misc.getNegativeHighlightColor());
323 text.highlightInLastPara(Misc.getHighlightColor(), str);
324 text.setFontInsignia();
328 text.setFontSmallInsignia();
329 String str = variant.getHullSpec().getHullNameWithDashClass() +
" " + variant.getHullSpec().getDesignation();
330 text.addParagraph(
"Acquired " + str +
"", Misc.getPositiveHighlightColor());
331 text.highlightInLastPara(Misc.getHighlightColor(), str);
332 text.setFontInsignia();
335 public static void addCRLossText(FleetMemberAPI member, TextPanelAPI text,
float crLoss) {
336 text.setFontSmallInsignia();
337 String str = member.getShipName() +
", " + member.getVariant().getHullSpec().getHullNameWithDashClass() +
" " + member.getVariant().getHullSpec().getDesignation();
338 String cr = Math.round(crLoss * 100f) +
"%";
339 text.addPara(
"%s has lost %s combat readiness", Misc.getNegativeHighlightColor(), Misc.getHighlightColor(),
341 text.highlightInLastPara(Misc.getHighlightColor(), str);
342 text.setFontInsignia();
static SettingsAPI getSettings()
static FactoryAPI getFactory()
static GameState getCurrentState()
static SectorAPI getSector()
static void addAdminGainText(PersonAPI admin, TextPanelAPI text)
static void addWeaponLossText(String weaponId, int quantity, TextPanelAPI text)
static void addFleetMemberGainText(ShipVariantAPI variant, TextPanelAPI text)
static void addCommodityLossText(String commodityId, int quantity, TextPanelAPI text)
static void addFighterLossText(String wingId, int quantity, TextPanelAPI text)
static void addCreditsGainText(int credits, TextPanelAPI text)
static void updatePlayerMemoryQuantity(String commodityId)
static void addFleetMemberLossText(FleetMemberAPI member, TextPanelAPI text)
static void addAbilityGainText(String abilityId, TextPanelAPI text)
static void addStackGainText(CargoStackAPI stack, TextPanelAPI text, boolean lowerCase)
static void addOfficerGainText(PersonAPI officer, TextPanelAPI text)
static void addStackGainText(CargoStackAPI stack, TextPanelAPI text)
static void addItemGainText(SpecialItemData data, int quantity, TextPanelAPI text)
static void addCommodityGainText(String commodityId, int quantity, TextPanelAPI text)
static void addItemLossText(SpecialItemData data, int quantity, TextPanelAPI text)
static void addWeaponGainText(String weaponId, int quantity, TextPanelAPI text)
static void addOfficerLossText(PersonAPI officer, TextPanelAPI text)
static void addCreditsLossText(int credits, TextPanelAPI text)
boolean execute(String ruleId, InteractionDialogAPI dialog, List< Token > params, Map< String, MemoryAPI > memoryMap)
static void addFleetMemberGainText(FleetMemberAPI member, TextPanelAPI text)
static void addCRLossText(FleetMemberAPI member, TextPanelAPI text, float crLoss)
static void addFighterGainText(String wingId, int quantity, TextPanelAPI text)
CargoAPI createCargo(boolean unlimitedStacks)
AbilitySpecAPI getAbilitySpec(String abilityId)
CommoditySpecAPI getCommoditySpec(String commodityId)
FighterWingSpecAPI getFighterWingSpec(String wingId)
WeaponSpecAPI getWeaponSpec(String weaponId)