Starsector API
Loading...
Searching...
No Matches
EnergyWeaponMastery.java
Go to the documentation of this file.
1package com.fs.starfarer.api.impl.campaign.skills;
2
3import org.lwjgl.util.vector.Vector2f;
4
5import com.fs.starfarer.api.GameState;
6import com.fs.starfarer.api.Global;
7import com.fs.starfarer.api.characters.AfterShipCreationSkillEffect;
8import com.fs.starfarer.api.characters.MutableCharacterStatsAPI;
9import com.fs.starfarer.api.characters.ShipSkillEffect;
10import com.fs.starfarer.api.characters.SkillSpecAPI;
11import com.fs.starfarer.api.combat.BeamAPI;
12import com.fs.starfarer.api.combat.CombatEntityAPI;
13import com.fs.starfarer.api.combat.DamageAPI;
14import com.fs.starfarer.api.combat.DamagingProjectileAPI;
15import com.fs.starfarer.api.combat.MutableShipStatsAPI;
16import com.fs.starfarer.api.combat.ShipAPI;
17import com.fs.starfarer.api.combat.ShipAPI.HullSize;
18import com.fs.starfarer.api.combat.WeaponAPI;
19import com.fs.starfarer.api.combat.WeaponAPI.WeaponType;
20import com.fs.starfarer.api.combat.listeners.AdvanceableListener;
21import com.fs.starfarer.api.combat.listeners.DamageDealtModifier;
22import com.fs.starfarer.api.ui.TooltipMakerAPI;
23import com.fs.starfarer.api.util.Misc;
24
25public class EnergyWeaponMastery {
26
27 public static float FLUX_COST_MULT = .9f;
28
29 public static float MIN_RANGE = 600;
30 public static float MAX_RANGE = 1000;
31
32 public static float ENERGY_DAMAGE_PERCENT = 30;
33 //public static float ENERGY_DAMAGE_MIN_FLUX_LEVEL = 0.25f;
34 public static float ENERGY_DAMAGE_MIN_FLUX_LEVEL = 0f;
35
36
37
38 public static class Level1 extends BaseSkillEffectDescription implements AfterShipCreationSkillEffect {
39 public void applyEffectsAfterShipCreation(ShipAPI ship, String id) {
40 ship.addListener(new EWMDamageDealtMod(ship));
41 }
42
43 public void unapplyEffectsAfterShipCreation(ShipAPI ship, String id) {
44 ship.removeListenerOfClass(EWMDamageDealtMod.class);
45 }
46
47 public void apply(MutableShipStatsAPI stats, HullSize hullSize, String id, float level) {
48 stats.getEnergyWeaponFluxBasedBonusDamageMagnitude().modifyFlat(id, ENERGY_DAMAGE_PERCENT * .01f);
49 stats.getEnergyWeaponFluxBasedBonusDamageMinLevel().modifyFlat(id, ENERGY_DAMAGE_MIN_FLUX_LEVEL);
50 }
51 public void unapply(MutableShipStatsAPI stats, HullSize hullSize, String id) {
52 stats.getEnergyWeaponFluxBasedBonusDamageMagnitude().unmodifyFlat(id);
53 stats.getEnergyWeaponFluxBasedBonusDamageMinLevel().unmodifyFlat(id);
54 }
55
56 public String getEffectDescription(float level) {
57 return null;
58 }
59
60 public void createCustomDescription(MutableCharacterStatsAPI stats, SkillSpecAPI skill,
61 TooltipMakerAPI info, float width) {
62 init(stats, skill);
63
65 info.addPara("Energy weapons deal up to %s damage at close range as the firing ship's flux level increases above %s",
66 0f, hc, hc,
67 "+" + (int) ENERGY_DAMAGE_PERCENT + "%",
68 (int) Math.round(ENERGY_DAMAGE_MIN_FLUX_LEVEL * 100f) + "%"
69 );
70 } else {
71 info.addPara("Energy weapons deal up to %s damage at close range, based on the firing ship's flux level",
72 0f, hc, hc,
73 "+" + (int) ENERGY_DAMAGE_PERCENT + "%"
74 );
75 }
76 info.addPara(indent + "Full bonus damage at %s range and below, " +
77 "no bonus damage at %s range and above",
78 0f, tc, hc,
79 "" + (int) MIN_RANGE,
80 "" + (int) MAX_RANGE
81 );
82 }
83
84 public ScopeDescription getScopeDescription() {
85 return ScopeDescription.PILOTED_SHIP;
86 }
87 }
88
89 public static class Level2 implements ShipSkillEffect {
90 public void apply(MutableShipStatsAPI stats, HullSize hullSize, String id, float level) {
91 stats.getEnergyWeaponFluxCostMod().modifyMult(id, FLUX_COST_MULT);
92 }
93
94 public void unapply(MutableShipStatsAPI stats, HullSize hullSize, String id) {
95 stats.getEnergyWeaponFluxCostMod().unmodify(id);
96 }
97
98 public String getEffectDescription(float level) {
99 return "-" + (int)Math.round((1f - FLUX_COST_MULT) * 100f) + "% flux generated by energy weapons";
100 }
101
102 public String getEffectPerLevelDescription() {
103 return null;
104 }
105
106 public ScopeDescription getScopeDescription() {
107 return ScopeDescription.PILOTED_SHIP;
108 }
109
110 }
111
112 public static Object DAM_BONUS_STATUS_KEY = new Object();
113
114 public static class EWMDamageDealtMod implements DamageDealtModifier, AdvanceableListener {
115 protected ShipAPI ship;
116 public EWMDamageDealtMod(ShipAPI ship) {
117 this.ship = ship;
118 }
119
120 public void advance(float amount) {
122 Global.getCombatEngine() != null && Global.getCombatEngine().getPlayerShip() == ship) {
123
124 int damageBonus = (int) Math.round((ship.getFluxBasedEnergyWeaponDamageMultiplier() * 100f - 100f));
125 if (damageBonus > 0) {
126 Global.getCombatEngine().maintainStatusForPlayerShip(DAM_BONUS_STATUS_KEY,
127 Global.getSettings().getSpriteName("ui", "icon_energy"),
128 "Energy weapon mastery",
129 "+" + damageBonus + "% energy weapon damage", false);
130 }
131
132 }
133 }
134
135 public String modifyDamageDealt(Object param,
136 CombatEntityAPI target, DamageAPI damage,
137 Vector2f point, boolean shieldHit) {
138
139 //if (param instanceof MissileAPI) return null;
140
141 Vector2f from = null;
142 WeaponAPI weapon = null;
143 if (param instanceof DamagingProjectileAPI) {
144 from = ((DamagingProjectileAPI)param).getSpawnLocation();
145 weapon = ((DamagingProjectileAPI)param).getWeapon();
146 } else if (param instanceof BeamAPI) {
147 from = ((BeamAPI)param).getFrom();
148 weapon = ((BeamAPI)param).getWeapon();
149 } else {
150 return null;
151 }
152
153 if (weapon == null || ship == null) return null;
154 if (weapon.getSpec().getType() != WeaponType.ENERGY) return null;
155
156 float mag = ship.getFluxBasedEnergyWeaponDamageMultiplier() - 1f;
157 if (mag <= 0) return null;
158
159 float dist = Misc.getDistance(from, point);
160 float f = 1f;
161 if (dist > MAX_RANGE) {
162 f = 0f;
163 } else if (dist > MIN_RANGE) {
164 f = 1f - (dist - MIN_RANGE) / (MAX_RANGE - MIN_RANGE);
165 }
166 if (f < 0) f = 0;
167 if (f > 1) f = 1;
168
169// Vector2f vel = new Vector2f();
170// if (target instanceof ShipAPI) {
171// vel.set(target.getVelocity());
172// }
173
174 String id = "ewm_dam_mod";
175 damage.getModifier().modifyPercent(id, (mag * f) * 100f);
176 return id;
177 }
178 }
179
180}
181
182
183
184
185
186
187
188
189
190
191
static SettingsAPI getSettings()
Definition Global.java:51
static CombatEngineAPI getCombatEngine()
Definition Global.java:63
static GameState getCurrentState()
Definition Global.java:21
void init(MutableCharacterStatsAPI stats, SkillSpecAPI skill)
String getSpriteName(String category, String id)