Starsector API
Loading...
Searching...
No Matches
CommerceBountyManager.java
Go to the documentation of this file.
1package com.fs.starfarer.api.impl.campaign.intel.events;
2
3import com.fs.starfarer.api.EveryFrameScript;
4import com.fs.starfarer.api.Global;
5import com.fs.starfarer.api.campaign.StarSystemAPI;
6import com.fs.starfarer.api.campaign.comm.IntelInfoPlugin;
7import com.fs.starfarer.api.campaign.econ.MarketAPI;
8import com.fs.starfarer.api.impl.campaign.ids.Factions;
9import com.fs.starfarer.api.impl.campaign.ids.Industries;
10import com.fs.starfarer.api.impl.campaign.intel.SystemBountyIntel;
11import com.fs.starfarer.api.util.IntervalUtil;
12import com.fs.starfarer.api.util.Misc;
13
14public class CommerceBountyManager implements EveryFrameScript {
15
16 protected IntervalUtil tracker = new IntervalUtil(0.5f, 1.5f);
17
18 public boolean isDone() {
19 return false;
20 }
21
22 public boolean runWhilePaused() {
23 return false;
24 }
25
26 public void advance(float amount) {
27 float days = Global.getSector().getClock().convertToDays(amount);
28 tracker.advance(days);
29 if (tracker.intervalElapsed()) {
30// HostileActivityEventIntel ha = HostileActivityEventIntel.get();
31// if (ha == null) return;
32
33 //boolean haLevelSufficient = ha.isStageActive(Stage.HA_1);
34 boolean haLevelSufficient = true;
35
36 for (StarSystemAPI system : Misc.getPlayerSystems(false)) {
37 SystemBountyIntel bounty = getCommerceBounty(system);
38 if (bounty != null && bounty.isEnding()) continue;
39
40 boolean hasFunctionalCommerce = doesStarSystemHavePlayerCommerceIndustry(system, true);
41 boolean hasCommerce = doesStarSystemHavePlayerCommerceIndustry(system, false);
42
43 if (bounty != null && (!hasCommerce || !haLevelSufficient)) {
44 bounty.endAfterDelay();
45 continue;
46 }
47
48 MarketAPI market = getPlayerCommerceMarket(system);
49 if (market == null) continue;
50
51 if (bounty == null && hasFunctionalCommerce && haLevelSufficient) {
52 float reward = Global.getSettings().getFloat("baseCommerceSystemBounty");
53 new SystemBountyIntel(market, (int) reward, true);
54 }
55 }
56 }
57 }
58
59 public static SystemBountyIntel getCommerceBounty(StarSystemAPI system) {
60 for (IntelInfoPlugin curr : Global.getSector().getIntelManager().getIntel(SystemBountyIntel.class)) {
62 if (intel.getLocation() == system && intel.isCommerceMode()) return intel;
63 }
64 return null;
65 }
66 public static boolean doesStarSystemHavePlayerCommerceIndustry(StarSystemAPI system, boolean requireFunctional) {
67 for (MarketAPI market : Misc.getMarketsInLocation(system, Factions.PLAYER)) {
68 if (requireFunctional && market.hasFunctionalIndustry(Industries.COMMERCE)) {
69 return true;
70 }
71 if (!requireFunctional && market.hasIndustry(Industries.COMMERCE)) {
72 return true;
73 }
74 }
75 return false;
76 }
77 public static MarketAPI getPlayerCommerceMarket(StarSystemAPI system) {
78 MarketAPI best = null;
79 for (MarketAPI market : Misc.getMarketsInLocation(system, Factions.PLAYER)) {
80 if (market.hasIndustry(Industries.COMMERCE)) {
81 if (best == null || best.getSize() < market.getSize()) {
82 best = market;
83 }
84 }
85 }
86 return best;
87 }
88
89}
90
91
92
93
static SettingsAPI getSettings()
Definition Global.java:51
static SectorAPI getSector()
Definition Global.java:59
static boolean doesStarSystemHavePlayerCommerceIndustry(StarSystemAPI system, boolean requireFunctional)