Advertisement
Guest User

Untitled

a guest
Jul 24th, 2016
61
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 19.74 KB | None | 0 0
  1. package data.scripts.plugins;
  2.  
  3. import com.fs.starfarer.api.Global;
  4. import com.fs.starfarer.api.combat.BaseEveryFrameCombatPlugin;
  5. import com.fs.starfarer.api.combat.CollisionClass;
  6. import com.fs.starfarer.api.combat.CombatEngineAPI;
  7. import com.fs.starfarer.api.combat.CombatEntityAPI;
  8. import com.fs.starfarer.api.combat.DamagingProjectileAPI;
  9. import com.fs.starfarer.api.combat.ShieldAPI;
  10. import com.fs.starfarer.api.combat.ShipAPI;
  11. import com.fs.starfarer.api.combat.ViewportAPI;
  12. import com.fs.starfarer.api.graphics.SpriteAPI;
  13. import com.fs.starfarer.api.input.InputEventAPI;
  14. import data.scripts.utils.exigency_Twig;
  15. import java.awt.Color;
  16. import java.util.ArrayList;
  17. import java.util.HashMap;
  18. import java.util.List;
  19. import java.util.Map;
  20. import org.lazywizard.lazylib.CollisionUtils;
  21. import org.lazywizard.lazylib.MathUtils;
  22. import org.lazywizard.lazylib.combat.CombatUtils;
  23. import org.lwjgl.util.vector.Vector2f;
  24.  
  25. public class exigency_ShieldBypass extends BaseEveryFrameCombatPlugin {
  26.  
  27. // Projectile ID (String), bypass effect data (ProjData)
  28. private static final Map<String, ProjData> PROJ_DATA = new HashMap<>(5);
  29.  
  30. static {
  31. // Add all projectiles that should pierce shields here
  32. PROJ_DATA.put("exigency_rr_shot",
  33. new ProjData("exigency_shieldpierce", // Shield pierce sound
  34. 2f, // Shield pierce sound pitch
  35. new Color(50, 150, 255), // Shield pierce particle color
  36. "exigency_rr_hit", // Hit sound
  37. 0.9f, // Hit sound pitch
  38. 175f, // Hit force
  39. 100f, // Explosion size
  40. 1.5f, // Explosion duration
  41. new Color(255, 165, 130, 150), // Explosion color
  42. 200f, // Hit particle size,
  43. ParticleType.HIT, // Hit particle type (HIT, SMOKE, SMOOTH)
  44. 1f, // Hit particle duration
  45. 1f, // Hit particle alpha mod
  46. new Color(250, 150, 200, 140), // Hit particle color
  47. 30.0f, // Shield pierce particle size
  48. 0.5f, // Shield pierce particle opacity
  49. 5f, // Shield pierce particle jitter
  50. Global.getSettings().getSprite("graphics/fx/projbody.png"))); // Shield pierce sprite
  51.  
  52. PROJ_DATA.put("exigency_super_cigen_shot",
  53. new ProjData("exigency_shieldpierce", // Shield pierce sound
  54. 1.5f, // Shield pierce sound pitch
  55. new Color(100, 125, 255), // Shield pierce particle color
  56. "exigency_super_cigen_hit", // Hit sound
  57. 0.85f, // Hit sound pitch
  58. 350f, // Hit force
  59. 150f, // Explosion size
  60. 1.5f, // Explosion duration
  61. new Color(255, 185, 150, 150), // Explosion color
  62. 250f, // Hit particle size,
  63. ParticleType.HIT, // Hit particle type (HIT, SMOKE, SMOOTH)
  64. 1f, // Hit particle duration
  65. 1f, // Hit particle alpha mod
  66. new Color(250, 200, 150, 140), // Hit particle color
  67. 35.0f, // Shield pierce particle size
  68. 0.6f, // Shield pierce particle opacity
  69. 8f, // Shield pierce particle jitter
  70. Global.getSettings().getSprite("graphics/fx/projbody.png"))); // Shield pierce sprite
  71.  
  72. PROJ_DATA.put("exigency_cigenrepeater_shot",
  73. new ProjData("exigency_shieldpierce_small", // Shield pierce sound
  74. 3f, // Shield pierce sound pitch
  75. new Color(50, 150, 255), // Shield pierce particle color
  76. "exigency_cigenrepeaterhit", // Hit sound
  77. 0.9f, // Hit sound pitch
  78. 0f, // Hit force
  79. 0.1f, // Explosion size
  80. 0.2f, // Explosion duration
  81. new Color(255, 165, 130, 10), // Explosion color
  82. 70f, // Hit particle size,
  83. ParticleType.HIT, // Hit particle type (HIT, SMOKE, SMOOTH)
  84. 0.1f, // Hit particle duration
  85. 1f, // Hit particle alpha mod
  86. new Color(250, 150, 200, 30), // Hit particle color
  87. 10f, // Shield pierce particle size
  88. 0.5f, // Shield pierce particle opacity
  89. 1f, // Shield pierce particle jitter
  90. Global.getSettings().getSprite("graphics/fx/projbody.png"))); // Shield pierce sprite
  91.  
  92. PROJ_DATA.put("exigency_cigenautocannon_shot",
  93. new ProjData("exigency_shieldpierce_medium", // Shield pierce sound
  94. 2.5f, // Shield pierce sound pitch
  95. new Color(50, 150, 255), // Shield pierce particle color
  96. "exigency_cigenautocannonhit", // Hit sound
  97. 0.9f, // Hit sound pitch
  98. 0f, // Hit force
  99. 0.3f, // Explosion size
  100. 0.35f, // Explosion duration
  101. new Color(255, 165, 130, 15), // Explosion color
  102. 75f, // Hit particle size,
  103. ParticleType.HIT, // Hit particle type (HIT, SMOKE, SMOOTH)
  104. 0.15f, // Hit particle duration
  105. 1f, // Hit particle alpha mod
  106. new Color(250, 150, 200, 50), // Hit particle color
  107. 12f, // Shield pierce particle size
  108. 0.5f, // Shield pierce particle opacity
  109. 2f, // Shield pierce particle jitter
  110. Global.getSettings().getSprite("graphics/fx/projbody.png"))); // Shield pierce sprite
  111.  
  112. PROJ_DATA.put("exigency_cigen_sabot_shot",
  113. new ProjData("exigency_shieldpierce_medium", // Shield pierce sound
  114. 2.5f, // Shield pierce sound pitch
  115. new Color(50, 150, 255), // Shield pierce particle color
  116. "exigency_cigenMirvhit", // Hit sound
  117. 0.8f, // Hit sound pitch
  118. 20f, // Hit force
  119. 25f, // Explosion size
  120. 0.7f, // Explosion duration
  121. new Color(255, 165, 130, 15), // Explosion color
  122. 100f, // Hit particle size,
  123. ParticleType.HIT, // Hit particle type (HIT, SMOKE, SMOOTH)
  124. 0.5f, // Hit particle duration
  125. 1f, // Hit particle alpha mod
  126. new Color(250, 150, 200, 55), // Hit particle color
  127. 20f, // Shield pierce particle size
  128. 0.5f, // Shield pierce particle opacity
  129. 2f, // Shield pierce particle jitter
  130. Global.getSettings().getSprite("graphics/fx/projbody.png"))); // Shield pierce sprite
  131. }
  132. private CombatEngineAPI engine;
  133.  
  134. @Override
  135. public void advance(float amount, List<InputEventAPI> events) {
  136. if (engine == null) {
  137. return;
  138. }
  139.  
  140. if (engine.isPaused()) {
  141. return;
  142. }
  143.  
  144. String spec;
  145. ProjData data;
  146.  
  147. // Scan all shots on the map for shield piercing projectiles
  148. List<DamagingProjectileAPI> projectiles = engine.getProjectiles();
  149. int size = projectiles.size();
  150. for (int i = 0; i < size; i++) {
  151. DamagingProjectileAPI proj = projectiles.get(i);
  152. spec = proj.getProjectileSpecId();
  153.  
  154. // Is this projectile shield piercing?
  155. if (!PROJ_DATA.containsKey(spec)) {
  156. continue;
  157. }
  158.  
  159. data = PROJ_DATA.get(spec);
  160.  
  161. // We'll do collision checks manually
  162. proj.setCollisionClass(CollisionClass.NONE);
  163.  
  164. // Find nearby ships and asteroids
  165. List<CombatEntityAPI> toCheck = new ArrayList<>(100);
  166. toCheck.addAll(CombatUtils.getShipsWithinRange(proj.getLocation(), proj.getCollisionRadius() + 5f));
  167. toCheck.addAll(CombatUtils.getAsteroidsWithinRange(proj.getLocation(), proj.getCollisionRadius() + 5f));
  168. // Don't include the ship that fired this projectile!
  169. toCheck.remove(proj.getSource());
  170. int checkSize = toCheck.size();
  171. for (int j = 0; j < checkSize; j++) {
  172. CombatEntityAPI entity = toCheck.get(j);
  173. // Check for an active phase cloak/shield
  174. if (entity instanceof ShipAPI) {
  175. ShipAPI ship = (ShipAPI) entity;
  176.  
  177. // Pass right through a cloaked ship
  178. if (ship.getCollisionClass() == CollisionClass.NONE) {
  179. continue;
  180. }
  181.  
  182. // Ignore friendly fighters
  183. if (ship.getCollisionClass() == CollisionClass.FIGHTER && ship.getOwner() == proj.getOwner()) {
  184. continue;
  185. }
  186.  
  187. // Play sound / show effects when passing through a shield
  188. ShieldAPI shield = ship.getShield();
  189. if (shield != null && shield.isOn() && shield.isWithinArc(proj.getLocation()) &&
  190. MathUtils.isWithinRange(proj.getLocation(), shield.getLocation(), shield.getRadius())) {
  191. Global.getSoundPlayer().playLoop(data.shieldPierceSound, proj, data.shieldPierceSoundPitch, 1f,
  192. proj.getLocation(), proj.getVelocity());
  193. }
  194. }
  195.  
  196. Vector2f prevLoc = new Vector2f(proj.getVelocity());
  197. prevLoc.scale(-amount);
  198. Vector2f.add(prevLoc, proj.getLocation(), prevLoc);
  199. Vector2f collisionPoint;
  200. if (entity.getExactBounds() == null) {
  201. collisionPoint = proj.getLocation();
  202. } else {
  203. collisionPoint = CollisionUtils.getCollisionPoint(prevLoc, proj.getLocation(), entity);
  204. }
  205. if (collisionPoint == null) {
  206. if (CollisionUtils.isPointWithinBounds(proj.getLocation(), entity)) {
  207. collisionPoint = proj.getLocation();
  208. }
  209. }
  210.  
  211. if (collisionPoint != null) {
  212. // Apply damage and destroy the projectile
  213. if (entity instanceof ShipAPI) {
  214. CombatUtils.applyForce(exigency_Twig.getRoot((ShipAPI) entity), proj.getVelocity(),
  215. data.hitForce);
  216. } else {
  217. CombatUtils.applyForce(entity, proj.getVelocity(), data.hitForce);
  218. }
  219. engine.applyDamage(entity, collisionPoint, proj.getDamageAmount(), proj.getDamageType(),
  220. proj.getEmpAmount(), true, true, proj.getSource());
  221. engine.spawnExplosion(collisionPoint, entity.getVelocity(), data.explosionColor, data.explosionSize,
  222. data.explosionDuration);
  223. engine.spawnExplosion(MathUtils.getRandomPointOnCircumference(collisionPoint,
  224. data.explosionSize / 4f),
  225. entity.getVelocity(), data.explosionColor, data.explosionSize / 3f,
  226. data.explosionDuration / 2f);
  227. switch (data.particleType) {
  228. case HIT:
  229. engine.addHitParticle(collisionPoint, entity.getVelocity(), data.particleSize,
  230. data.particleAlpha, data.particleDuration, data.particleColor);
  231. break;
  232. case SMOOTH:
  233. engine.addSmoothParticle(collisionPoint, entity.getVelocity(), data.particleSize,
  234. data.particleAlpha, data.particleDuration, data.particleColor);
  235. break;
  236. default:
  237. engine.addSmokeParticle(collisionPoint, entity.getVelocity(), data.particleSize,
  238. data.particleAlpha, data.particleDuration, data.particleColor);
  239. }
  240. Global.getSoundPlayer().playSound(data.hitSound, data.hitSoundPitch, 1f, collisionPoint,
  241. entity.getVelocity());
  242. engine.removeEntity(proj);
  243. }
  244. }
  245. }
  246. }
  247.  
  248. @Override
  249. public void init(CombatEngineAPI engine) {
  250. this.engine = engine;
  251. }
  252.  
  253. @Override
  254. public void renderInWorldCoords(ViewportAPI viewport) {
  255. if (engine == null) {
  256. return;
  257. }
  258.  
  259. String spec;
  260. ProjData data;
  261.  
  262. // Scan all shots on the map for shield piercing projectiles
  263. List<DamagingProjectileAPI> projectiles = engine.getProjectiles();
  264. int size = projectiles.size();
  265. for (int i = 0; i < size; i++) {
  266. DamagingProjectileAPI proj = projectiles.get(i);
  267. spec = proj.getProjectileSpecId();
  268.  
  269. // Is this projectile shield piercing?
  270. if (!PROJ_DATA.containsKey(spec)) {
  271. continue;
  272. }
  273.  
  274. data = PROJ_DATA.get(spec);
  275.  
  276. // We'll do collision checks manually
  277. proj.setCollisionClass(CollisionClass.NONE);
  278.  
  279. // Find nearby ships and asteroids
  280. List<CombatEntityAPI> toCheck = new ArrayList<>(100);
  281. toCheck.addAll(CombatUtils.getShipsWithinRange(proj.getLocation(), proj.getCollisionRadius() + 5f));
  282. toCheck.addAll(CombatUtils.getAsteroidsWithinRange(proj.getLocation(), proj.getCollisionRadius() + 5f));
  283. // Don't include the ship that fired this projectile!
  284. toCheck.remove(proj.getSource());
  285. int checkSize = toCheck.size();
  286. for (int j = 0; j < checkSize; j++) {
  287. CombatEntityAPI entity = toCheck.get(j);
  288. // Check for an active phase cloak/shield
  289. if (entity instanceof ShipAPI) {
  290. ShipAPI ship = (ShipAPI) entity;
  291.  
  292. // Pass right through a cloaked ship
  293. if (ship.getCollisionClass() == CollisionClass.NONE) {
  294. continue;
  295. }
  296.  
  297. // Ignore friendly fighters
  298. if (ship.getCollisionClass() == CollisionClass.FIGHTER && ship.getOwner() == proj.getOwner()) {
  299. continue;
  300. }
  301.  
  302. // Play sound / show effects when passing through a shield
  303. ShieldAPI shield = ship.getShield();
  304. if (shield != null && shield.isOn() && shield.isWithinArc(proj.getLocation()) &&
  305. MathUtils.isWithinRange(proj.getLocation(), shield.getLocation(), shield.getRadius())) {
  306. data.pierceSprite.setAlphaMult(data.pierceOpacity);
  307. data.pierceSprite.setAdditiveBlend();
  308. data.pierceSprite.setAngle(proj.getFacing());
  309. data.pierceSprite.setColor(data.shieldPierceColor);
  310. float pierceSize = data.pierceSize + MathUtils.getRandomNumberInRange(-1f, 1f) *
  311. data.pierceJitter;
  312. data.pierceSprite.setSize(pierceSize *
  313. (data.pierceSprite.getWidth() / data.pierceSprite.getHeight()), pierceSize);
  314. float pierceX = proj.getLocation().x + MathUtils.getRandomNumberInRange(-1f, 1f) *
  315. data.pierceJitter;
  316. float pierceY = proj.getLocation().y + MathUtils.getRandomNumberInRange(-1f, 1f) *
  317. data.pierceJitter;
  318. data.pierceSprite.renderAtCenter(pierceX, pierceY);
  319. }
  320. }
  321. }
  322. }
  323. }
  324.  
  325. private static enum ParticleType {
  326.  
  327. HIT,
  328. SMOOTH,
  329. SMOKE
  330. }
  331.  
  332. private static final class ProjData {
  333.  
  334. final Color explosionColor;
  335. final float explosionDuration;
  336. final float explosionSize;
  337. final float hitForce;
  338. final String hitSound;
  339. final float hitSoundPitch;
  340. final float particleAlpha;
  341. final Color particleColor;
  342. final float particleDuration;
  343. final float particleSize;
  344. final ParticleType particleType;
  345. final float pierceJitter;
  346. final float pierceOpacity;
  347. final float pierceSize;
  348. final SpriteAPI pierceSprite;
  349. final Color shieldPierceColor;
  350. final String shieldPierceSound;
  351. final float shieldPierceSoundPitch;
  352.  
  353. private ProjData(String shieldPierceSound, float shieldPierceSoundPitch, Color shieldPierceColor,
  354. String hitSound, float hitSoundPitch, float hitForce, float explosionSize,
  355. float explosionDuration, Color explosionColor, float particleSize, ParticleType particleType,
  356. float particleDuration, float particleAlpha, Color particleColor, float pierceSize,
  357. float pierceOpacity, float pierceJitter, SpriteAPI pierceSprite) {
  358. this.shieldPierceSound = shieldPierceSound;
  359. this.shieldPierceSoundPitch = shieldPierceSoundPitch;
  360. this.shieldPierceColor = shieldPierceColor;
  361. this.pierceSize = pierceSize;
  362. this.pierceJitter = pierceJitter;
  363. this.pierceOpacity = pierceOpacity;
  364. this.hitSound = hitSound;
  365. this.hitSoundPitch = hitSoundPitch;
  366. this.hitForce = hitForce;
  367. this.particleSize = particleSize;
  368. this.particleType = particleType;
  369. this.particleDuration = particleDuration;
  370. this.particleAlpha = particleAlpha;
  371. this.particleColor = particleColor;
  372. this.explosionSize = explosionSize;
  373. this.explosionDuration = explosionDuration;
  374. this.explosionColor = explosionColor;
  375. this.pierceSprite = pierceSprite;
  376. }
  377. }
  378. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement