Starsector API
Loading...
Searching...
No Matches
PlayerMarketTransaction.java
Go to the documentation of this file.
1package com.fs.starfarer.api.campaign;
2
3import java.util.ArrayList;
4import java.util.List;
5
6import com.fs.starfarer.api.Global;
7import com.fs.starfarer.api.campaign.CampaignUIAPI.CoreUITradeMode;
8import com.fs.starfarer.api.campaign.CargoAPI.CargoItemType;
9import com.fs.starfarer.api.campaign.econ.MarketAPI;
10import com.fs.starfarer.api.campaign.econ.SubmarketAPI;
11import com.fs.starfarer.api.fleet.FleetMemberAPI;
12import com.fs.starfarer.api.impl.campaign.shared.PlayerTradeDataForSubmarket;
13
15
16 public static class ShipSaleInfo {
17 private FleetMemberAPI member;
18 private float price;
19 public ShipSaleInfo(FleetMemberAPI member, float price) {
20 this.member = member;
21 this.price = price;
22 }
23 public FleetMemberAPI getMember() {
24 return member;
25 }
26 public void setMember(FleetMemberAPI member) {
27 this.member = member;
28 }
29 public float getPrice() {
30 return price;
31 }
32 public void setPrice(float price) {
33 this.price = price;
34 }
35 }
36
37 public static enum LineItemType {
38 BOUGHT,
39 SOLD,
40 UPDATE,
41 }
42 public static class TransactionLineItem {
43 private String id;
44 private LineItemType itemType;
45 private CargoItemType cargoType;
46 private SubmarketAPI submarket;
47 private float quantity;
48 private float price;
49 private float tariff;
50 private float demandPrice;
51 private float demandTariff;
52 private long timestamp;
53 public TransactionLineItem(String id, LineItemType itemType,
54 CargoItemType cargoType, SubmarketAPI submarket,
55 float quantity, float price, float tariff, long timestamp) {
56 this.id = id;
57 this.itemType = itemType;
58 this.cargoType = cargoType;
59 this.submarket = submarket;
60 this.quantity = quantity;
61 this.price = price;
62 this.tariff = tariff;
63 this.timestamp = timestamp;
64 }
69 public float getDemandPrice() {
70 return demandPrice;
71 }
72 public void setDemandPrice(float price2) {
73 this.demandPrice = price2;
74 }
75 public float getDemandTariff() {
76 return demandTariff;
77 }
78 public void setDemandTariff(float demandTariff) {
79 this.demandTariff = demandTariff;
80 }
81 public float getTariff() {
82 return tariff;
83 }
84 public void setTariff(float tariff) {
85 this.tariff = tariff;
86 }
87 public SubmarketAPI getSubmarket() {
88 return submarket;
89 }
90 public void setSubmarket(SubmarketAPI submarket) {
91 this.submarket = submarket;
92 }
93 public String getId() {
94 return id;
95 }
96 public void setId(String id) {
97 this.id = id;
98 }
99 public LineItemType getItemType() {
100 return itemType;
101 }
102 public void setItemType(LineItemType itemType) {
103 this.itemType = itemType;
104 }
105 public CargoItemType getCargoType() {
106 return cargoType;
107 }
108 public void setCargoType(CargoItemType cargoType) {
109 this.cargoType = cargoType;
110 }
111 public float getQuantity() {
112 return quantity;
113 }
114 public void setQuantity(float quantity) {
115 this.quantity = quantity;
116 }
117 public float getPrice() {
118 return price;
119 }
120 public void setPrice(float price) {
121 this.price = price;
122 }
123 public long getTimestamp() {
124 return timestamp;
125 }
126 public void setTimestamp(long timestamp) {
127 this.timestamp = timestamp;
128 }
129 }
130
131 private float creditValue;
132 private CargoAPI bought = Global.getFactory().createCargo(true);
133 private CargoAPI sold = Global.getFactory().createCargo(true);
134
135 private List<TransactionLineItem> lineItems = new ArrayList<TransactionLineItem>();
136
137 private MarketAPI market;
138 private SubmarketAPI submarket;
139
140 private List<ShipSaleInfo> shipsBought = new ArrayList<ShipSaleInfo>();
141 private List<ShipSaleInfo> shipsSold = new ArrayList<ShipSaleInfo>();
142 private final CoreUITradeMode tradeMode;
143
144 public PlayerMarketTransaction(MarketAPI market, SubmarketAPI submarket, CoreUITradeMode tradeMode) {
145 this.market = market;
146 this.submarket = submarket;
147 this.tradeMode = tradeMode;
148 }
149
150
151 public CoreUITradeMode getTradeMode() {
152 return tradeMode;
153 }
154
159 public List<TransactionLineItem> getLineItems() {
160 return lineItems;
161 }
162
163 public float getBaseTradeValueImpact() {
164 float total = 0;
165 for (CargoStackAPI stack : bought.getStacksCopy()) {
166 float qty = stack.getSize();
167// if (qty < 1) continue;
168// float val = (float) stack.getBaseValuePerUnit() * qty * playerImpactMult;
170 stack.getType(), stack.getData(), stack.getBaseValuePerUnit(), qty);
171 total += val;
172 }
173
174 for (CargoStackAPI stack : sold.getStacksCopy()) {
175 float qty = stack.getSize();
176// if (qty < 1) continue;
177// float val = (float) stack.getBaseValuePerUnit() * qty * playerImpactMult;
178// if (!market.hasCondition(Conditions.FREE_PORT) &&
179// stack.isCommodityStack() && market.isIllegal(stack.getCommodityId())) {
180// val *= illegalImpactMult;
181// }
183 stack.getType(), stack.getData(), stack.getBaseValuePerUnit(), qty);
184 total += val;
185 }
186
187 return total;
188 }
189
190
196 public float getCreditValue() {
197 return creditValue;
198 }
199 public void setCreditValue(float creditValue) {
200 this.creditValue = creditValue;
201 }
203 return bought;
204 }
205 public void setBought(CargoAPI bought) {
206 this.bought = bought;
207 }
208 public CargoAPI getSold() {
209 return sold;
210 }
211 public void setSold(CargoAPI sold) {
212 this.sold = sold;
213 }
215 return market;
216 }
218 return submarket;
219 }
220
221 public float getQuantityBought(String commodityId) {
222// float total = 0f;
223// for (CargoStackAPI stack : getBought().getStacksCopy()) {
224// String id = stack.getCommodityId();
225// if (id != null && id.equals(commodityId)) total += stack.getSize();
226// }
227// return total;
228 return getBought().getQuantity(CargoItemType.RESOURCES, commodityId);
229 }
230 public float getQuantitySold(String commodityId) {
231// float total = 0f;
232// for (CargoStackAPI stack : getSold().getStacksCopy()) {
233// String id = stack.getCommodityId();
234// if (id != null && id.equals(commodityId)) total += stack.getSize();
235// }
236 return getSold().getQuantity(CargoItemType.RESOURCES, commodityId);
237 }
238
239 public List<ShipSaleInfo> getShipsBought() {
240 return shipsBought;
241 }
242
243 public List<ShipSaleInfo> getShipsSold() {
244 return shipsSold;
245 }
246
247
248}
249
250
251
252
253
static FactoryAPI getFactory()
Definition Global.java:41
PlayerMarketTransaction(MarketAPI market, SubmarketAPI submarket, CoreUITradeMode tradeMode)
static float computeImpactOfHavingAlreadySold(MarketAPI market, CargoItemType type, Object data, float baseValue, float qty)
static float computeImpactOfHavingAlreadyBought(MarketAPI market, CargoItemType type, Object data, float baseValue, float qty)
CargoAPI createCargo(boolean unlimitedStacks)
float getQuantity(CargoAPI.CargoItemType type, Object data)
List< CargoStackAPI > getStacksCopy()