Starsector API
Loading...
Searching...
No Matches
RangedSpecialization.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.characters.AfterShipCreationSkillEffect;
6import com.fs.starfarer.api.characters.MutableCharacterStatsAPI;
7import com.fs.starfarer.api.characters.ShipSkillEffect;
8import com.fs.starfarer.api.characters.SkillSpecAPI;
9import com.fs.starfarer.api.combat.BeamAPI;
10import com.fs.starfarer.api.combat.CombatEntityAPI;
11import com.fs.starfarer.api.combat.DamageAPI;
12import com.fs.starfarer.api.combat.DamagingProjectileAPI;
13import com.fs.starfarer.api.combat.MissileAPI;
14import com.fs.starfarer.api.combat.MutableShipStatsAPI;
15import com.fs.starfarer.api.combat.ShipAPI;
16import com.fs.starfarer.api.combat.ShipAPI.HullSize;
17import com.fs.starfarer.api.combat.listeners.DamageDealtModifier;
18import com.fs.starfarer.api.ui.TooltipMakerAPI;
19import com.fs.starfarer.api.util.Misc;
20
22
23 public static boolean CRITS = false;
24
25 public static float PROJ_SPEED_BONUS = 30;
26
27 public static float MIN_RANGE = 800;
28 public static float MAX_RANGE = 1600;
29 public static float MAX_CHANCE_PERCENT = 30; // used as damage percent mod when CRITS == false
30 public static float CRIT_DAMAGE_BONUS_PERCENT = 100;
31
32
33
34 public static class Level1 extends BaseSkillEffectDescription implements AfterShipCreationSkillEffect {
35 public void applyEffectsAfterShipCreation(ShipAPI ship, String id) {
36 ship.addListener(new RangedSpecDamageDealtMod());
37 }
38
39 public void unapplyEffectsAfterShipCreation(ShipAPI ship, String id) {
40 ship.removeListenerOfClass(RangedSpecDamageDealtMod.class);
41 }
42
43 public void apply(MutableShipStatsAPI stats, HullSize hullSize, String id, float level) {}
44 public void unapply(MutableShipStatsAPI stats, HullSize hullSize, String id) {}
45
46 public String getEffectDescription(float level) {
47 return null;
48 }
49
50 public void createCustomDescription(MutableCharacterStatsAPI stats, SkillSpecAPI skill,
51 TooltipMakerAPI info, float width) {
52 init(stats, skill);
53
54 if (CRITS) {
55 info.addPara("Ballistic and energy weapons have a chance to deal %s damage at long range",
56 0f, hc, hc, "+" + (int) CRIT_DAMAGE_BONUS_PERCENT + "%");
57 info.addPara(indent + "%s chance at %s range and below, " +
58 "%s chance at %s range and above",
59 0f, tc, hc,
60 "0%",
61 "" + (int) MIN_RANGE,
62 "" + (int) MAX_CHANCE_PERCENT + "%",
63 "" + (int) MAX_RANGE
64 );
65 } else {
66 info.addPara("Ballistic and energy weapons deal up to %s damage at long range",
67 0f, hc, hc, "+" + (int) MAX_CHANCE_PERCENT + "%");
68 info.addPara(indent + "%s at %s range and below, " +
69 "%s at %s range and above",
70 0f, tc, hc,
71 "0%",
72 "" + (int) MIN_RANGE,
73 "" + (int) MAX_CHANCE_PERCENT + "%",
74 "" + (int) MAX_RANGE
75 );
76 }
77 //info.addPara(indent + "Beam weapons have their damage increased by the chance percentage instead", tc, 0f);
78 }
79
80 public ScopeDescription getScopeDescription() {
81 return ScopeDescription.PILOTED_SHIP;
82 }
83 }
84
85 public static class Level2 implements ShipSkillEffect {
86 public void apply(MutableShipStatsAPI stats, HullSize hullSize, String id, float level) {
87 stats.getProjectileSpeedMult().modifyPercent(id, PROJ_SPEED_BONUS);
88 }
89
90 public void unapply(MutableShipStatsAPI stats, HullSize hullSize, String id) {
91 stats.getProjectileSpeedMult().unmodify(id);
92 }
93
94 public String getEffectDescription(float level) {
95 return "+" + (int)(PROJ_SPEED_BONUS) + "% ballistic and energy projectile speed";
96 }
97
98 public String getEffectPerLevelDescription() {
99 return null;
100 }
101
102 public ScopeDescription getScopeDescription() {
103 return ScopeDescription.PILOTED_SHIP;
104 }
105
106 }
107
108 public static class RangedSpecDamageDealtMod implements DamageDealtModifier {
109 public String modifyDamageDealt(Object param,
110 CombatEntityAPI target, DamageAPI damage,
111 Vector2f point, boolean shieldHit) {
112 if (param instanceof MissileAPI) return null;
113
114 Vector2f from = null;
115 if (param instanceof DamagingProjectileAPI) {
116 from = ((DamagingProjectileAPI)param).getSpawnLocation();
117 } else if (param instanceof BeamAPI) {
118 from = ((BeamAPI)param).getFrom();
119 } else {
120 return null;
121 }
122
123 float chancePercent = 0f;
124 float dist = Misc.getDistance(from, point);
125 float f = (dist - MIN_RANGE) / (MAX_RANGE - MIN_RANGE);
126 if (f < 0) f = 0;
127 if (f > 1) f = 1;
128
129 //f = 0.5f;
130 //f = 1f;
131 //System.out.println("RangedSpec mult: " + f);
132
133 String id = null;
134
135 chancePercent = (int) Math.round(MAX_CHANCE_PERCENT * f);
136 if (chancePercent <= 0) return null;
137
138 //System.out.println("Chance: " + chancePercent);
139
140 Vector2f vel = new Vector2f();
141 if (target instanceof ShipAPI) {
142 vel.set(target.getVelocity());
143 }
144
145 if (param instanceof DamagingProjectileAPI) {
146 if (CRITS) {
147 if ((float) Math.random() < chancePercent * 0.01f) {
148 id = "ranged_spec_dam_mod";
149 damage.getModifier().modifyPercent(id, CRIT_DAMAGE_BONUS_PERCENT);
150 //Misc.spawnExtraHitGlow(param, point, vel, f);
151 }
152 } else {
153 id = "ranged_spec_dam_mod";
154 damage.getModifier().modifyPercent(id, chancePercent);
155 //Misc.spawnExtraHitGlow(param, point, vel, f);
156 }
157 } else if (param instanceof BeamAPI) {
158 if (CRITS) {
159 if ((float) Math.random() < chancePercent * 0.01f) {
160 id = "ranged_spec_dam_mod";
161 damage.getModifier().modifyPercent(id, CRIT_DAMAGE_BONUS_PERCENT);
162 //Misc.spawnExtraHitGlow(param, point, vel, f);
163 }
164 } else {
165 id = "ranged_spec_dam_mod";
166 damage.getModifier().modifyPercent(id, chancePercent);
167 //Misc.spawnExtraHitGlow(param, point, vel, f);
168 }
169 }
170
171 return id;
172 }
173 }
174
175
176
177// public static class TestDamageModifier implements DamageDealtModifier {
178// public String modifyDamageDealt(Object param,
179// CombatEntityAPI target, DamageAPI damage,
180// Vector2f point, boolean shieldHit) {
181// //if (true) return null;
182// String id = "dam_mod1" + (float) Math.random();
183// damage.getModifier().modifyMult(id, 0.1f);
184// return id;
185// }
186// }
187//
188// public static class TestDamageModifierTaken implements DamageTakenModifier {
189// public String modifyDamageTaken(Object param,
190// CombatEntityAPI target, DamageAPI damage,
191// Vector2f point, boolean shieldHit) {
192// //if (true) return null;
193// String id = "dam_mod2" + (float) Math.random();
194// damage.getModifier().modifyMult(id, 10f);
195// return id;
196// }
197// }
198
199}
200
201
202
203
204
205
206
207
208
209
210
void init(MutableCharacterStatsAPI stats, SkillSpecAPI skill)