Advertisement
Guest User

Untitled

a guest
Jul 30th, 2015
253
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 10.48 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.DamageType;
  9. import com.fs.starfarer.api.combat.DamagingProjectileAPI;
  10. import com.fs.starfarer.api.combat.ShipAPI;
  11. import com.fs.starfarer.api.input.InputEventAPI;
  12. import data.scripts.util.tiandong_Twig;
  13. import java.awt.Color;
  14. import java.util.Iterator;
  15. import java.util.LinkedList;
  16. import java.util.List;
  17. import org.dark.shaders.light.LightShader;
  18. import org.dark.shaders.light.StandardLight;
  19. import org.lazywizard.lazylib.CollisionUtils;
  20. import org.lazywizard.lazylib.MathUtils;
  21. import org.lazywizard.lazylib.VectorUtils;
  22. import org.lazywizard.lazylib.combat.CombatUtils;
  23. import org.lwjgl.util.vector.Vector2f;
  24.  
  25. public class tiandong_WeaponPlugin extends BaseEveryFrameCombatPlugin {
  26.  
  27. private static final float BURST_FLAK_AREA_DAMAGE = 80f;
  28. private static final float BURST_FLAK_AREA_EFFECT = 150f;
  29. private static final float BURST_FLAK_AREA_EFFECT_INNER = 50f;
  30. private static final float BURST_FLAK_AREA_FORCE = 30f;
  31. private static final Color BURST_FLAK_COLOR_CORE = new Color(255, 155, 155, 255);
  32. private static final Color BURST_FLAK_COLOR_PARTICLE = new Color(255, 155, 155, 255);
  33. private static final float BURST_FLAK_FUSE_RANGE = 50f;
  34. private static final String BURST_FLAK_PROJECTILE_ID = "tiandong_burstflak_shot";
  35. private static final String FLARE_PROJECTILE_ID = "SOME_SHIT";
  36. private static final String BURST_FLAK_SOUND_ID = "tiandong_burstflakcannon_explosion";
  37. private static final Vector2f ZERO = new Vector2f();
  38.  
  39. public static void burstFlakExplode(DamagingProjectileAPI projectile, Vector2f point, CombatEngineAPI engine) {
  40. if (point == null) {
  41. return;
  42. }
  43.  
  44. tiandong_EffectsHook.createFlakShockwave(point);
  45.  
  46. Global.getCombatEngine().addHitParticle(projectile.getLocation(), ZERO, BURST_FLAK_AREA_EFFECT, 0.4f, 0.6f, BURST_FLAK_COLOR_CORE);
  47. Vector2f vel = new Vector2f();
  48. for (int i = 0; i < 30; i++) {
  49. vel.set(((float) Math.random() * 1.25f + 0.25f) * BURST_FLAK_AREA_EFFECT, 0f);
  50. VectorUtils.rotate(vel, (float) Math.random() * 360f, vel);
  51. Global.getCombatEngine().addSmoothParticle(projectile.getLocation(), vel, (float) Math.random() * 2.5f + 2.5f, 1f,
  52. (float) Math.random() * 0.3f + 0.6f, BURST_FLAK_COLOR_PARTICLE);
  53. }
  54.  
  55. StandardLight light = new StandardLight(projectile.getLocation(), ZERO, ZERO, null);
  56. light.setColor(BURST_FLAK_COLOR_CORE);
  57. light.setSize(BURST_FLAK_AREA_EFFECT * 1.1f);
  58. light.setIntensity(0.15f);
  59. light.fadeOut(0.2f);
  60. LightShader.addLight(light);
  61.  
  62. Global.getSoundPlayer().playSound(BURST_FLAK_SOUND_ID, 1f, 1f, point, projectile.getVelocity());
  63.  
  64. List<ShipAPI> ships = CombatUtils.getShipsWithinRange(point, BURST_FLAK_AREA_EFFECT);
  65. List<CombatEntityAPI> targets = CombatUtils.getAsteroidsWithinRange(point, BURST_FLAK_AREA_EFFECT);
  66. targets.addAll(CombatUtils.getMissilesWithinRange(point, BURST_FLAK_AREA_EFFECT));
  67.  
  68. Iterator<ShipAPI> iter = ships.iterator();
  69. while (iter.hasNext()) {
  70. ShipAPI ship = iter.next();
  71. if (ship.getCollisionClass() == CollisionClass.NONE) {
  72. iter.remove();
  73. continue;
  74. }
  75.  
  76. if (!ship.isFighter() && !ship.isDrone()) {
  77. continue;
  78. }
  79.  
  80. boolean remove = false;
  81. for (ShipAPI shp : ships) {
  82. if (shp.getShield() != null && shp != ship) {
  83. if (shp.getShield().isWithinArc(ship.getLocation()) && shp.getShield().isOn() &&
  84. MathUtils.getDistance(ship.getLocation(), shp.getShield().getLocation()) <= shp.getShield().getRadius()) {
  85. remove = true;
  86. }
  87. }
  88. }
  89.  
  90. if (remove) {
  91. iter.remove();
  92. }
  93. }
  94.  
  95. ships = tiandong_Twig.getSortedAreaList(point, ships);
  96. targets.addAll(ships);
  97.  
  98. for (CombatEntityAPI tgt : targets) {
  99. /* No friendly fire for flak */
  100. if (tgt.getOwner() == projectile.getOwner()) {
  101. continue;
  102. }
  103.  
  104. float distance = tiandong_Twig.getActualDistance(point, tgt, true);
  105. float reduction = 1f;
  106. if (distance > BURST_FLAK_AREA_EFFECT_INNER) {
  107. reduction = (BURST_FLAK_AREA_EFFECT - distance) / (BURST_FLAK_AREA_EFFECT - BURST_FLAK_AREA_EFFECT_INNER);
  108. }
  109.  
  110. if (reduction <= 0f) {
  111. continue;
  112. }
  113.  
  114. boolean shieldHit = false;
  115. if (tgt instanceof ShipAPI) {
  116. ShipAPI ship = (ShipAPI) tgt;
  117. if (ship.getShield() != null && ship.getShield().isWithinArc(point)) {
  118. shieldHit = true;
  119. }
  120. }
  121.  
  122. Vector2f damagePoint;
  123. if (shieldHit) {
  124. ShipAPI ship = (ShipAPI) tgt;
  125. damagePoint = MathUtils.getPointOnCircumference(null, ship.getShield().getRadius(), VectorUtils.getAngle(ship.getShield().getLocation(), point));
  126. Vector2f.add(damagePoint, tgt.getLocation(), damagePoint);
  127. } else {
  128. Vector2f projection = VectorUtils.getDirectionalVector(point, tgt.getLocation());
  129. projection.scale(tgt.getCollisionRadius());
  130. Vector2f.add(projection, tgt.getLocation(), projection);
  131. damagePoint = CollisionUtils.getCollisionPoint(point, projection, tgt);
  132. }
  133. if (damagePoint == null) {
  134. damagePoint = point;
  135. }
  136. engine.applyDamage(tgt, damagePoint, BURST_FLAK_AREA_DAMAGE * reduction, DamageType.FRAGMENTATION, 0f, false, false, projectile.getSource());
  137.  
  138. /* Force on projectiles is a little OP for a PD weapon */
  139. if (!(tgt instanceof DamagingProjectileAPI)) {
  140. CombatUtils.applyForce(tgt, VectorUtils.getAngle(point, tgt.getLocation()), BURST_FLAK_AREA_FORCE * reduction);
  141. }
  142. }
  143.  
  144. /* Don't want it exploding multiple times, do we? Also cleans up the look of it */
  145. engine.removeEntity(projectile);
  146. }
  147. private CombatEngineAPI engine;
  148.  
  149. @Override
  150. public void advance(float amount, List<InputEventAPI> events) {
  151. if (engine == null) {
  152. return;
  153. }
  154. if (engine.isPaused()) {
  155. return;
  156. }
  157.  
  158. List<DamagingProjectileAPI> projectiles = engine.getProjectiles();
  159. int size = projectiles.size();
  160. for (int i = 0; i < size; i++) {
  161. DamagingProjectileAPI proj = projectiles.get(i);
  162. String spec = proj.getProjectileSpecId();
  163. Vector2f loc = proj.getLocation();
  164. if (spec == null) {
  165. continue;
  166. }
  167.  
  168. switch (spec) {
  169. case BURST_FLAK_PROJECTILE_ID: {
  170. /* Detonate at the end-of-life, like real flak */
  171. if (proj.isFading() && (Math.random() < 0.5)) {
  172. tiandong_WeaponPlugin.burstFlakExplode(proj, loc, engine);
  173. break;
  174. }
  175.  
  176. List<CombatEntityAPI> targets = new LinkedList<>();
  177. targets.addAll(CombatUtils.getMissilesWithinRange(loc, BURST_FLAK_FUSE_RANGE));
  178. targets.addAll(CombatUtils.getShipsWithinRange(loc, BURST_FLAK_FUSE_RANGE));
  179.  
  180. for (CombatEntityAPI target : targets) {
  181. /* Don't explode on neutrals or allies -- unless the projectile is neutral, in which case everything is fair game */
  182. if ((proj.getOwner() == 0) && (target.getOwner() != 1)) {
  183. continue;
  184. }
  185. if ((proj.getOwner() == 1) && (target.getOwner() != 0)) {
  186. continue;
  187. }
  188. if (target.getCollisionClass() == CollisionClass.NONE) {
  189. continue;
  190. }
  191.  
  192. float distance = tiandong_Twig.getActualDistance(loc, target, true);
  193. if ((distance <= BURST_FLAK_FUSE_RANGE) && (Math.random() < 0.7)) {
  194. tiandong_WeaponPlugin.burstFlakExplode(proj, loc, engine);
  195. break;
  196. }
  197. }
  198. break;
  199. }
  200. case FLARE_PROJECTILE_ID: {
  201. if (proj.isFading()) {
  202. break;
  203. }
  204.  
  205. List<CombatEntityAPI> targets = new LinkedList<>();
  206. targets.addAll(CombatUtils.getMissilesWithinRange(loc, BURST_FLAK_FUSE_RANGE));
  207. targets.addAll(CombatUtils.getShipsWithinRange(loc, BURST_FLAK_FUSE_RANGE));
  208.  
  209. for (CombatEntityAPI target : targets) {
  210. /* Don't explode on neutrals or allies -- unless the projectile is neutral, in which case everything is fair game */
  211. if ((proj.getOwner() == 0) && (target.getOwner() != 1)) {
  212. continue;
  213. }
  214. if ((proj.getOwner() == 1) && (target.getOwner() != 0)) {
  215. continue;
  216. }
  217. if (target.getCollisionClass() == CollisionClass.NONE) {
  218. continue;
  219. }
  220.  
  221. float distance = tiandong_Twig.getActualDistance(loc, target, true);
  222. if ((distance <= BURST_FLAK_FUSE_RANGE) && (Math.random() < 0.7)) {
  223. tiandong_WeaponPlugin.burstFlakExplode(proj, loc, engine);
  224. break;
  225. }
  226. }
  227. break;
  228. }
  229. default:
  230. }
  231. }
  232. }
  233.  
  234. @Override
  235. public void init(CombatEngineAPI engine) {
  236. this.engine = engine;
  237. }
  238. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement