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.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.EveryFrameCombatPlugin;
- import com.fs.starfarer.api.combat.ShieldAPI;
- import com.fs.starfarer.api.combat.ShipAPI;
- import com.fs.starfarer.api.combat.ShipSystemAPI;
- import com.fs.starfarer.api.input.InputEventAPI;
- import java.awt.Color;
- import java.util.ArrayList;
- import java.util.HashMap;
- import java.util.List;
- import java.util.Map;
- import org.lwjgl.util.vector.Vector2f;
- import org.lazywizard.lazylib.CollisionUtils;
- import org.lazywizard.lazylib.MathUtils;
- import org.lazywizard.lazylib.combat.CombatUtils;
- public class exigency_ShieldBypass implements EveryFrameCombatPlugin {
- // Projectile ID (String), bypass effect data (ProjData)
- private static final Map<String, ProjData> PROJ_DATA = new HashMap<>();
- private static CombatEngineAPI activeEngine;
- 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
- Color.WHITE, // Shield pierce particle color
- "hit_heavy", // Hit sound
- 1f, // Hit sound pitch
- 0f, // Hit force
- 150f, // Explosion size
- 1.5f, // Explosion duration
- new Color(255, 165, 130, 200), // Explosion color
- 5.0f, // Shield pierce particle size
- 0.5f, // Shield pierce particle opacity
- 0.5f)); // Shield pierce particle duration
- PROJ_DATA.put("exigency_super_cigen_shot",
- new ProjData("exigency_shieldpierce", // Shield pierce sound
- 1.5f, // Shield pierce sound pitch
- new Color(255, 225, 200), // Shield pierce particle color
- "hit_heavy", // Hit sound
- 1f, // Hit sound pitch
- 350f, // Hit force
- 250f, // Explosion size
- 1.5f, // Explosion duration
- new Color(255, 185, 150, 255), // Explosion color
- 7.0f, // Shield pierce particle size
- 0.6f, // Shield pierce particle opacity
- 0.6f)); // Shield pierce particle duration
- PROJ_DATA.put("exigency_cigenrepeater_shot",
- new ProjData("exigency_shieldpierce_small", // Shield pierce sound
- 3f, // Shield pierce sound pitch
- Color.WHITE, // Shield pierce particle color
- "hit_light", // Hit sound
- 1f, // Hit sound pitch
- 0f, // Hit force
- 0.1f, // Explosion size
- 0.1f, // Explosion duration
- new Color(255, 165, 130, 10), // Explosion color
- 2.5f, // Shield pierce particle size
- 0.5f, // Shield pierce particle opacity
- 0.5f)); // Shield pierce particle duration
- }
- @Override
- public void advance(float amount, List<InputEventAPI> events) {
- if (activeEngine.isPaused()) {
- return;
- }
- String spec;
- ProjData data;
- // Scan all shots on the map for shield piercing projectiles
- for (DamagingProjectileAPI proj : activeEngine.getProjectiles()) {
- 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<>();
- 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());
- for (CombatEntityAPI entity : toCheck) {
- // Check for an active phase cloak/shield
- if (entity instanceof ShipAPI) {
- ShipAPI ship = (ShipAPI) entity;
- // Pass right through a cloaked ship
- ShipSystemAPI cloak = ship.getPhaseCloak();
- if (cloak != null && cloak.isActive()) {
- 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());
- activeEngine.addSmokeParticle(proj.getLocation(), Vector2f.add(ship.getVelocity(), MathUtils.getRandomPointInCircle(null, data.explosionSize / 4f), null), data.pierceSize, data.pierceOpacity, data.pierceDuration, data.shieldPierceColor);
- }
- }
- if (CollisionUtils.isPointWithinBounds(proj.getLocation(), entity)) {
- // Apply damage and destroy the projectile
- CombatUtils.applyForce(entity, proj.getVelocity(), data.hitForce);
- activeEngine.applyDamage(entity, proj.getLocation(), proj.getDamageAmount(), proj.getDamageType(), proj.getEmpAmount(), true, true, proj.getSource());
- activeEngine.spawnExplosion(proj.getLocation(), entity.getVelocity(), data.explosionColor, data.explosionSize, data.explosionDuration);
- activeEngine.spawnExplosion(MathUtils.getRandomPointOnCircumference(proj.getLocation(), data.explosionSize / 4f), entity.getVelocity(), data.explosionColor, data.explosionSize / 3f, data.explosionDuration / 2f);
- Global.getSoundPlayer().playSound(data.hitSound, data.hitSoundPitch, 1f, proj.getLocation(), entity.getVelocity());
- activeEngine.removeEntity(proj);
- }
- }
- }
- }
- @Override
- public void init(CombatEngineAPI engine) {
- activeEngine = engine;
- }
- private static final class ProjData {
- private final String hitSound, shieldPierceSound;
- private final float hitSoundPitch, shieldPierceSoundPitch, explosionSize, explosionDuration, pierceSize, pierceDuration, pierceOpacity, hitForce;
- private final Color shieldPierceColor, explosionColor;
- private ProjData(String shieldPierceSound, float shieldPierceSoundPitch, Color shieldPierceColor, String hitSound, float hitSoundPitch, float hitForce, float explosionSize, float explosionDuration, Color explosionColor, float pierceSize, float pierceOpacity, float pierceDuration) {
- this.shieldPierceSound = shieldPierceSound;
- this.shieldPierceSoundPitch = shieldPierceSoundPitch;
- this.shieldPierceColor = shieldPierceColor;
- this.pierceSize = pierceSize;
- this.pierceDuration = pierceDuration;
- this.pierceOpacity = pierceOpacity;
- this.hitSound = hitSound;
- this.hitSoundPitch = hitSoundPitch;
- this.hitForce = hitForce;
- this.explosionSize = explosionSize;
- this.explosionDuration = explosionDuration;
- this.explosionColor = explosionColor;
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement