Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package data.scripts.plugins;
- import com.fs.starfarer.api.Global;
- import com.fs.starfarer.api.combat.BaseEveryFrameCombatPlugin;
- import com.fs.starfarer.api.combat.CollisionClass;
- import com.fs.starfarer.api.combat.CombatEngineAPI;
- import com.fs.starfarer.api.combat.CombatEntityAPI;
- import com.fs.starfarer.api.combat.DamagingProjectileAPI;
- import com.fs.starfarer.api.combat.ShieldAPI;
- import com.fs.starfarer.api.combat.ShipAPI;
- import com.fs.starfarer.api.combat.ViewportAPI;
- import com.fs.starfarer.api.graphics.SpriteAPI;
- import com.fs.starfarer.api.input.InputEventAPI;
- import data.scripts.utils.exigency_Twig;
- import java.awt.Color;
- import java.util.ArrayList;
- import java.util.HashMap;
- import java.util.List;
- import java.util.Map;
- import org.lazywizard.lazylib.CollisionUtils;
- import org.lazywizard.lazylib.MathUtils;
- import org.lazywizard.lazylib.combat.CombatUtils;
- import org.lwjgl.util.vector.Vector2f;
- public class exigency_ShieldBypass extends BaseEveryFrameCombatPlugin {
- // Projectile ID (String), bypass effect data (ProjData)
- private static final Map<String, ProjData> PROJ_DATA = new HashMap<>(5);
- static {
- // Add all projectiles that should pierce shields here
- PROJ_DATA.put("exigency_rr_shot",
- new ProjData("exigency_shieldpierce", // Shield pierce sound
- 2f, // Shield pierce sound pitch
- new Color(50, 150, 255), // Shield pierce particle color
- "exigency_rr_hit", // Hit sound
- 0.9f, // Hit sound pitch
- 175f, // Hit force
- 100f, // Explosion size
- 1.5f, // Explosion duration
- new Color(255, 165, 130, 150), // Explosion color
- 200f, // Hit particle size,
- ParticleType.HIT, // Hit particle type (HIT, SMOKE, SMOOTH)
- 1f, // Hit particle duration
- 1f, // Hit particle alpha mod
- new Color(250, 150, 200, 140), // Hit particle color
- 30.0f, // Shield pierce particle size
- 0.5f, // Shield pierce particle opacity
- 5f, // Shield pierce particle jitter
- Global.getSettings().getSprite("graphics/fx/projbody.png"))); // Shield pierce sprite
- PROJ_DATA.put("exigency_super_cigen_shot",
- new ProjData("exigency_shieldpierce", // Shield pierce sound
- 1.5f, // Shield pierce sound pitch
- new Color(100, 125, 255), // Shield pierce particle color
- "exigency_super_cigen_hit", // Hit sound
- 0.85f, // Hit sound pitch
- 350f, // Hit force
- 150f, // Explosion size
- 1.5f, // Explosion duration
- new Color(255, 185, 150, 150), // Explosion color
- 250f, // Hit particle size,
- ParticleType.HIT, // Hit particle type (HIT, SMOKE, SMOOTH)
- 1f, // Hit particle duration
- 1f, // Hit particle alpha mod
- new Color(250, 200, 150, 140), // Hit particle color
- 35.0f, // Shield pierce particle size
- 0.6f, // Shield pierce particle opacity
- 8f, // Shield pierce particle jitter
- Global.getSettings().getSprite("graphics/fx/projbody.png"))); // Shield pierce sprite
- PROJ_DATA.put("exigency_cigenrepeater_shot",
- new ProjData("exigency_shieldpierce_small", // Shield pierce sound
- 3f, // Shield pierce sound pitch
- new Color(50, 150, 255), // Shield pierce particle color
- "exigency_cigenrepeaterhit", // Hit sound
- 0.9f, // Hit sound pitch
- 0f, // Hit force
- 0.1f, // Explosion size
- 0.2f, // Explosion duration
- new Color(255, 165, 130, 10), // Explosion color
- 70f, // Hit particle size,
- ParticleType.HIT, // Hit particle type (HIT, SMOKE, SMOOTH)
- 0.1f, // Hit particle duration
- 1f, // Hit particle alpha mod
- new Color(250, 150, 200, 30), // Hit particle color
- 10f, // Shield pierce particle size
- 0.5f, // Shield pierce particle opacity
- 1f, // Shield pierce particle jitter
- Global.getSettings().getSprite("graphics/fx/projbody.png"))); // Shield pierce sprite
- PROJ_DATA.put("exigency_cigenautocannon_shot",
- new ProjData("exigency_shieldpierce_medium", // Shield pierce sound
- 2.5f, // Shield pierce sound pitch
- new Color(50, 150, 255), // Shield pierce particle color
- "exigency_cigenautocannonhit", // Hit sound
- 0.9f, // Hit sound pitch
- 0f, // Hit force
- 0.3f, // Explosion size
- 0.35f, // Explosion duration
- new Color(255, 165, 130, 15), // Explosion color
- 75f, // Hit particle size,
- ParticleType.HIT, // Hit particle type (HIT, SMOKE, SMOOTH)
- 0.15f, // Hit particle duration
- 1f, // Hit particle alpha mod
- new Color(250, 150, 200, 50), // Hit particle color
- 12f, // Shield pierce particle size
- 0.5f, // Shield pierce particle opacity
- 2f, // Shield pierce particle jitter
- Global.getSettings().getSprite("graphics/fx/projbody.png"))); // Shield pierce sprite
- PROJ_DATA.put("exigency_cigen_sabot_shot",
- new ProjData("exigency_shieldpierce_medium", // Shield pierce sound
- 2.5f, // Shield pierce sound pitch
- new Color(50, 150, 255), // Shield pierce particle color
- "exigency_cigenMirvhit", // Hit sound
- 0.8f, // Hit sound pitch
- 20f, // Hit force
- 25f, // Explosion size
- 0.7f, // Explosion duration
- new Color(255, 165, 130, 15), // Explosion color
- 100f, // Hit particle size,
- ParticleType.HIT, // Hit particle type (HIT, SMOKE, SMOOTH)
- 0.5f, // Hit particle duration
- 1f, // Hit particle alpha mod
- new Color(250, 150, 200, 55), // Hit particle color
- 20f, // Shield pierce particle size
- 0.5f, // Shield pierce particle opacity
- 2f, // Shield pierce particle jitter
- Global.getSettings().getSprite("graphics/fx/projbody.png"))); // Shield pierce sprite
- }
- private CombatEngineAPI engine;
- @Override
- public void advance(float amount, List<InputEventAPI> events) {
- if (engine == null) {
- return;
- }
- if (engine.isPaused()) {
- return;
- }
- String spec;
- ProjData data;
- // Scan all shots on the map for shield piercing projectiles
- List<DamagingProjectileAPI> projectiles = engine.getProjectiles();
- int size = projectiles.size();
- for (int i = 0; i < size; i++) {
- DamagingProjectileAPI proj = projectiles.get(i);
- spec = proj.getProjectileSpecId();
- // Is this projectile shield piercing?
- if (!PROJ_DATA.containsKey(spec)) {
- continue;
- }
- data = PROJ_DATA.get(spec);
- // We'll do collision checks manually
- proj.setCollisionClass(CollisionClass.NONE);
- // Find nearby ships and asteroids
- List<CombatEntityAPI> toCheck = new ArrayList<>(100);
- toCheck.addAll(CombatUtils.getShipsWithinRange(proj.getLocation(), proj.getCollisionRadius() + 5f));
- toCheck.addAll(CombatUtils.getAsteroidsWithinRange(proj.getLocation(), proj.getCollisionRadius() + 5f));
- // Don't include the ship that fired this projectile!
- toCheck.remove(proj.getSource());
- int checkSize = toCheck.size();
- for (int j = 0; j < checkSize; j++) {
- CombatEntityAPI entity = toCheck.get(j);
- // Check for an active phase cloak/shield
- if (entity instanceof ShipAPI) {
- ShipAPI ship = (ShipAPI) entity;
- // Pass right through a cloaked ship
- if (ship.getCollisionClass() == CollisionClass.NONE) {
- continue;
- }
- // Ignore friendly fighters
- if (ship.getCollisionClass() == CollisionClass.FIGHTER && ship.getOwner() == proj.getOwner()) {
- continue;
- }
- // Play sound / show effects when passing through a shield
- ShieldAPI shield = ship.getShield();
- if (shield != null && shield.isOn() && shield.isWithinArc(proj.getLocation()) &&
- MathUtils.isWithinRange(proj.getLocation(), shield.getLocation(), shield.getRadius())) {
- Global.getSoundPlayer().playLoop(data.shieldPierceSound, proj, data.shieldPierceSoundPitch, 1f,
- proj.getLocation(), proj.getVelocity());
- }
- }
- Vector2f prevLoc = new Vector2f(proj.getVelocity());
- prevLoc.scale(-amount);
- Vector2f.add(prevLoc, proj.getLocation(), prevLoc);
- Vector2f collisionPoint;
- if (entity.getExactBounds() == null) {
- collisionPoint = proj.getLocation();
- } else {
- collisionPoint = CollisionUtils.getCollisionPoint(prevLoc, proj.getLocation(), entity);
- }
- if (collisionPoint == null) {
- if (CollisionUtils.isPointWithinBounds(proj.getLocation(), entity)) {
- collisionPoint = proj.getLocation();
- }
- }
- if (collisionPoint != null) {
- // Apply damage and destroy the projectile
- if (entity instanceof ShipAPI) {
- CombatUtils.applyForce(exigency_Twig.getRoot((ShipAPI) entity), proj.getVelocity(),
- data.hitForce);
- } else {
- CombatUtils.applyForce(entity, proj.getVelocity(), data.hitForce);
- }
- engine.applyDamage(entity, collisionPoint, proj.getDamageAmount(), proj.getDamageType(),
- proj.getEmpAmount(), true, true, proj.getSource());
- engine.spawnExplosion(collisionPoint, entity.getVelocity(), data.explosionColor, data.explosionSize,
- data.explosionDuration);
- engine.spawnExplosion(MathUtils.getRandomPointOnCircumference(collisionPoint,
- data.explosionSize / 4f),
- entity.getVelocity(), data.explosionColor, data.explosionSize / 3f,
- data.explosionDuration / 2f);
- switch (data.particleType) {
- case HIT:
- engine.addHitParticle(collisionPoint, entity.getVelocity(), data.particleSize,
- data.particleAlpha, data.particleDuration, data.particleColor);
- break;
- case SMOOTH:
- engine.addSmoothParticle(collisionPoint, entity.getVelocity(), data.particleSize,
- data.particleAlpha, data.particleDuration, data.particleColor);
- break;
- default:
- engine.addSmokeParticle(collisionPoint, entity.getVelocity(), data.particleSize,
- data.particleAlpha, data.particleDuration, data.particleColor);
- }
- Global.getSoundPlayer().playSound(data.hitSound, data.hitSoundPitch, 1f, collisionPoint,
- entity.getVelocity());
- engine.removeEntity(proj);
- }
- }
- }
- }
- @Override
- public void init(CombatEngineAPI engine) {
- this.engine = engine;
- }
- @Override
- public void renderInWorldCoords(ViewportAPI viewport) {
- if (engine == null) {
- return;
- }
- String spec;
- ProjData data;
- // Scan all shots on the map for shield piercing projectiles
- List<DamagingProjectileAPI> projectiles = engine.getProjectiles();
- int size = projectiles.size();
- for (int i = 0; i < size; i++) {
- DamagingProjectileAPI proj = projectiles.get(i);
- spec = proj.getProjectileSpecId();
- // Is this projectile shield piercing?
- if (!PROJ_DATA.containsKey(spec)) {
- continue;
- }
- data = PROJ_DATA.get(spec);
- // We'll do collision checks manually
- proj.setCollisionClass(CollisionClass.NONE);
- // Find nearby ships and asteroids
- List<CombatEntityAPI> toCheck = new ArrayList<>(100);
- toCheck.addAll(CombatUtils.getShipsWithinRange(proj.getLocation(), proj.getCollisionRadius() + 5f));
- toCheck.addAll(CombatUtils.getAsteroidsWithinRange(proj.getLocation(), proj.getCollisionRadius() + 5f));
- // Don't include the ship that fired this projectile!
- toCheck.remove(proj.getSource());
- int checkSize = toCheck.size();
- for (int j = 0; j < checkSize; j++) {
- CombatEntityAPI entity = toCheck.get(j);
- // Check for an active phase cloak/shield
- if (entity instanceof ShipAPI) {
- ShipAPI ship = (ShipAPI) entity;
- // Pass right through a cloaked ship
- if (ship.getCollisionClass() == CollisionClass.NONE) {
- continue;
- }
- // Ignore friendly fighters
- if (ship.getCollisionClass() == CollisionClass.FIGHTER && ship.getOwner() == proj.getOwner()) {
- continue;
- }
- // Play sound / show effects when passing through a shield
- ShieldAPI shield = ship.getShield();
- if (shield != null && shield.isOn() && shield.isWithinArc(proj.getLocation()) &&
- MathUtils.isWithinRange(proj.getLocation(), shield.getLocation(), shield.getRadius())) {
- data.pierceSprite.setAlphaMult(data.pierceOpacity);
- data.pierceSprite.setAdditiveBlend();
- data.pierceSprite.setAngle(proj.getFacing());
- data.pierceSprite.setColor(data.shieldPierceColor);
- float pierceSize = data.pierceSize + MathUtils.getRandomNumberInRange(-1f, 1f) *
- data.pierceJitter;
- data.pierceSprite.setSize(pierceSize *
- (data.pierceSprite.getWidth() / data.pierceSprite.getHeight()), pierceSize);
- float pierceX = proj.getLocation().x + MathUtils.getRandomNumberInRange(-1f, 1f) *
- data.pierceJitter;
- float pierceY = proj.getLocation().y + MathUtils.getRandomNumberInRange(-1f, 1f) *
- data.pierceJitter;
- data.pierceSprite.renderAtCenter(pierceX, pierceY);
- }
- }
- }
- }
- }
- private static enum ParticleType {
- HIT,
- SMOOTH,
- SMOKE
- }
- private static final class ProjData {
- final Color explosionColor;
- final float explosionDuration;
- final float explosionSize;
- final float hitForce;
- final String hitSound;
- final float hitSoundPitch;
- final float particleAlpha;
- final Color particleColor;
- final float particleDuration;
- final float particleSize;
- final ParticleType particleType;
- final float pierceJitter;
- final float pierceOpacity;
- final float pierceSize;
- final SpriteAPI pierceSprite;
- final Color shieldPierceColor;
- final String shieldPierceSound;
- final float shieldPierceSoundPitch;
- private ProjData(String shieldPierceSound, float shieldPierceSoundPitch, Color shieldPierceColor,
- String hitSound, float hitSoundPitch, float hitForce, float explosionSize,
- float explosionDuration, Color explosionColor, float particleSize, ParticleType particleType,
- float particleDuration, float particleAlpha, Color particleColor, float pierceSize,
- float pierceOpacity, float pierceJitter, SpriteAPI pierceSprite) {
- this.shieldPierceSound = shieldPierceSound;
- this.shieldPierceSoundPitch = shieldPierceSoundPitch;
- this.shieldPierceColor = shieldPierceColor;
- this.pierceSize = pierceSize;
- this.pierceJitter = pierceJitter;
- this.pierceOpacity = pierceOpacity;
- this.hitSound = hitSound;
- this.hitSoundPitch = hitSoundPitch;
- this.hitForce = hitForce;
- this.particleSize = particleSize;
- this.particleType = particleType;
- this.particleDuration = particleDuration;
- this.particleAlpha = particleAlpha;
- this.particleColor = particleColor;
- this.explosionSize = explosionSize;
- this.explosionDuration = explosionDuration;
- this.explosionColor = explosionColor;
- this.pierceSprite = pierceSprite;
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement