Starsector API
Loading...
Searching...
No Matches
CommRelayScript.java
Go to the documentation of this file.
1package com.fs.starfarer.api.impl.campaign.skills;
2
3import java.util.HashSet;
4import java.util.List;
5import java.util.Set;
6
7import com.fs.starfarer.api.Global;
8import com.fs.starfarer.api.characters.PersonAPI;
9import com.fs.starfarer.api.combat.BaseEveryFrameCombatPlugin;
10import com.fs.starfarer.api.combat.BattleObjectiveAPI;
11import com.fs.starfarer.api.combat.CombatEngineAPI;
12import com.fs.starfarer.api.combat.CombatFleetManagerAPI;
13import com.fs.starfarer.api.combat.DeployedFleetMemberAPI;
14import com.fs.starfarer.api.combat.ShipAPI;
15import com.fs.starfarer.api.combat.ViewportAPI;
16import com.fs.starfarer.api.impl.campaign.ids.BattleObjectives;
17import com.fs.starfarer.api.impl.campaign.ids.Stats;
18import com.fs.starfarer.api.input.InputEventAPI;
19
20public class CommRelayScript extends BaseEveryFrameCombatPlugin {
21 public static final float RATE_BONUS_PER_COMM_RELAY = 25f;
22 public static final Object KEY_STATUS = new Object();
23 public static final String BONUS_ID = "comm_relay_script_bonus";
24
25
26 private CombatEngineAPI engine;
27 public void init(CombatEngineAPI engine) {
28 this.engine = engine;
29 }
30
31 private ShipAPI prevPlayerShip = null;
32 private int skipFrames = 0;
33 private Set<CombatFleetManagerAPI> needsCleanup = new HashSet<CombatFleetManagerAPI>();
34 public void advance(float amount, List<InputEventAPI> events) {
35 if (engine == null) return;
36 if (engine.isPaused()) return;
37
38 // if the player changed flagships:
39 // skip a few frames to make sure the status ends up on top of the status list
40 ShipAPI playerShip = engine.getPlayerShip();
41 if (playerShip != prevPlayerShip) {
42 prevPlayerShip = playerShip;
43 skipFrames = 20;
44 }
45
46 if (skipFrames > 0) {
47 skipFrames--;
48 return;
49 }
50
51 updateForSide(engine.getFleetManager(0));
52 updateForSide(engine.getFleetManager(1));
53 }
54
55
56 private void updateForSide(CombatFleetManagerAPI manager) {
57
58 PersonAPI commander = manager.getFleetCommander();
59 if (commander == null) {
60 manager.getTaskManager(false).getCPRateModifier().unmodify(BONUS_ID);
61 return;
62 }
63
64
65 float total = 0f;
66
67 float modifier = commander.getStats().getDynamic().getValue(Stats.COMMAND_POINT_RATE_COMMANDER);
68 boolean relaysOnly = modifier == 1f;
69 List<DeployedFleetMemberAPI> deployed = manager.getDeployedCopyDFM();
70 for (DeployedFleetMemberAPI member : deployed) {
71 if (member.isFighterWing()) continue;
72 float curr = member.getShip().getMutableStats().getDynamic().getValue(Stats.COMMAND_POINT_RATE_FLAT, 0f);
73 total += curr;
74 }
75
76 if (total > 0) relaysOnly = false;
77
78
79 int numRelays = 0;
80 for (BattleObjectiveAPI obj : engine.getObjectives()) {
81 if (obj.getOwner() == manager.getOwner() && BattleObjectives.COMM_RELAY.equals(obj.getType())) {
82 total += RATE_BONUS_PER_COMM_RELAY / 100f;
83 numRelays++;
84 }
85 }
86
87
88 manager.getTaskManager(false).getCPRateModifier().modifyFlat(BONUS_ID, total);
89
90
91 modifier += manager.getTaskManager(false).getCPRateModifier().getModifiedValue();
92 modifier -= 1f;
93
94 if (manager.getOwner() == 0) {
95 // use mult instead of modifier since mult includes skill bonus and modifier is only relays
96 float withMult = manager.getTaskManager(false).getCPRateMult();
97 String icon = Global.getSettings().getSpriteName("ui", "icon_tactical_coordinated_maneuvers");
98 String title = "command network";
99 //String data = "+" + (int)(modifier * 100f) + "% cp recovery rate";
100
101 String data = "+" + (int)Math.round((withMult - 1f) * 100f) + "% cp recovery rate";
102 boolean debuff = false;
103 if (withMult < 1f) {
104 data = "" + (int)Math.round((withMult - 1f) * 100f) + "% cp recovery rate";
105 debuff = true;
106 }
107
108// if (relaysOnly) {
109// title = "comm relay";
110// if (numRelays > 1) {
111// title += "s";
112// title += " (" + numRelays + ")";
113// }
114// }
115
116 if (withMult != 1) {
117 engine.maintainStatusForPlayerShip(KEY_STATUS, icon,
118 title,
119 data, debuff);
120 }
121 }
122
123 }
124
125 protected void cleanUpIfNeeded(CombatFleetManagerAPI manager) {
126 if (needsCleanup.contains(manager)) {
127 needsCleanup.remove(manager);
128 List<DeployedFleetMemberAPI> deployed = manager.getDeployedCopyDFM();
129 for (DeployedFleetMemberAPI member : deployed) {
130 if (member.isFighterWing()) continue;
131 if (member.getShip() == null) continue;
132 member.getShip().getMutableStats().getMaxSpeed().unmodify(BONUS_ID);
133 }
134 }
135 }
136
137
138
139
140 public void renderInUICoords(ViewportAPI viewport) {
141 }
142
143 public void renderInWorldCoords(ViewportAPI viewport) {
144 }
145
146
147 public boolean hasInputPriority() {
148 // TODO Auto-generated method stub
149 return false;
150 }
151
152}
void advance(float amount, List< InputEventAPI > events)