62 public boolean execute(String ruleId, InteractionDialogAPI dialog, List<Token> params, Map<String, MemoryAPI> memoryMap) {
63 if (dialog ==
null)
return false;
64 if (!(dialog.getInteractionTarget() instanceof CampaignFleetAPI))
return false;
67 CampaignFleetAPI other = (CampaignFleetAPI) dialog.getInteractionTarget();
69 FactionAPI faction = other.getFaction();
71 CargoInspectionResult result =
new CargoInspectionResult();
73 float totalIllegal = 0;
74 float totalIllegalFound = 0;
79 for (CargoStackAPI stack : playerFleet.getCargo().getStacksCopy()) {
80 boolean legal = !faction.isIllegal(stack);
82 totalLegal += stack.getSize();
84 totalIllegal += stack.getSize();
86 all.addFromStack(stack);
88 float guiltMult = InvestigationEvent.getPlayerRepGuiltMult(faction);
90 float capacity = playerFleet.getCargo().getMaxCapacity();
92 float shieldedFraction = Misc.getShieldedCargoFraction(playerFleet);
93 float unshieldedFraction = 1f - shieldedFraction;
95 float shieldedMult = (0.5f + 0.5f * unshieldedFraction);
97 if (totalLegal + totalIllegal > 0) {
98 List<CargoStackAPI> stacks = all.getStacksCopy();
99 Collections.shuffle(stacks);
100 float illegalSoFar = 0;
101 for (CargoStackAPI stack : stacks) {
102 if (stack.getSize() <= 0)
continue;
103 boolean legal = !faction.isIllegal(stack);
104 illegalSoFar += stack.getSize();
105 float chanceToFind = illegalSoFar / (totalLegal + totalIllegal);
106 chanceToFind *= guiltMult;
107 chanceToFind *= shieldedMult;
109 legalFound.addFromStack(stack);
110 }
else if ((
float) Math.random() < chanceToFind) {
111 float qty = stack.getSize();
112 qty = qty * (0.33f + (float) Math.random() * 0.67f);
114 qty = Math.round(qty);
115 if (qty < 1) qty = 1;
116 illegalFound.addItems(stack.getType(), stack.getData(), qty);
121 result.setLegalFound(legalFound);
122 result.setIllegalFound(illegalFound);
123 if (illegalFound.isEmpty()) {
124 result.setType(CargoInspectionResultType.TOLL);
126 result.setType(CargoInspectionResultType.TOLL_AND_FINE);
130 float shipTollAmount = 0f;
131 for (FleetMemberAPI member : playerFleet.getFleetData().getMembersListCopy()) {
132 shipTollAmount += member.getBaseSellValue() * 0.125f * faction.getTollFraction();
134 shipTollAmount = (int)shipTollAmount;
136 float tollFraction = faction.getTollFraction();
137 float fineFraction = faction.getFineFraction();
141 for (CargoStackAPI stack : legalFound.getStacksCopy()) {
142 toll += stack.getSize() * stack.getBaseValuePerUnit() * tollFraction * shieldedMult;
144 for (CargoStackAPI stack : illegalFound.getStacksCopy()) {
145 fine += stack.getSize() * stack.getBaseValuePerUnit() * fineFraction;
146 totalIllegalFound += stack.getSize();
149 float totalTollAndFine = shipTollAmount + toll + fine;
156 result.setTollAmount(totalTollAndFine);
158 MemoryAPI memory = memoryMap.get(MemKeys.LOCAL);
159 memory.set(
"$tollAmount",
"" + (
int)result.getTollAmount(), 0);
160 memory.set(
"$inspectionResultType", result.getType().name(), 0);
161 memory.set(
"$playerCanAffordPayment", playerFleet.getCargo().getCredits().get() >= result.getTollAmount(), 0);
162 memory.set(
"$cargoInspectionResult", result, 0);
165 TextPanelAPI text = dialog.getTextPanel();
167 text.setFontVictor();
168 text.setFontSmallInsignia();
170 Color hl = Misc.getHighlightColor();
171 Color red = Misc.getNegativeHighlightColor();
172 text.addParagraph(
"-----------------------------------------------------------------------------");
174 text.addParagraph(
"Fleet size toll: " + (
int) shipTollAmount);
175 text.highlightInLastPara(hl,
"" + (
int) shipTollAmount);
176 text.addParagraph(
"Cargo toll: " + (
int) toll);
177 text.highlightInLastPara(hl,
"" + (
int) toll);
179 if (!illegalFound.isEmpty()) {
180 text.addParagraph(
"Contraband found!", red);
182 List<String> highlights =
new ArrayList<String>();
183 for (CargoStackAPI stack : illegalFound.getStacksCopy()) {
184 para += stack.getDisplayName() +
" x " + (int)stack.getSize() +
"\n";
185 highlights.add(
"" + (
int)stack.getSize());
187 para = para.substring(0, para.length() - 1);
188 text.addParagraph(para);
189 text.highlightInLastPara(hl, highlights.toArray(
new String [0]));
191 text.addParagraph(
"Fine: " + (
int) fine);
192 text.highlightInLastPara(hl,
"" + (
int) fine);
195 text.addParagraph(
"Total: " + (
int) totalTollAndFine +
" credits");
196 text.highlightInLastPara(hl,
"" + (
int) totalTollAndFine);
198 text.addParagraph(
"-----------------------------------------------------------------------------");
200 text.setFontInsignia();