Advertisement
DarkRevenant

Untitled

Apr 28th, 2014
176
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 3.87 KB | None | 0 0
  1. package data.scripts.weapons;
  2.  
  3. import com.fs.starfarer.api.Global;
  4. import com.fs.starfarer.api.combat.CombatEngineAPI;
  5. import com.fs.starfarer.api.combat.CombatEntityAPI;
  6. import com.fs.starfarer.api.combat.DamageType;
  7. import com.fs.starfarer.api.combat.DamagingProjectileAPI;
  8. import com.fs.starfarer.api.combat.OnHitEffectPlugin;
  9. import com.fs.starfarer.api.combat.ShipAPI;
  10. import java.awt.Color;
  11. import org.lazywizard.lazylib.MathUtils;
  12. import org.lwjgl.util.vector.Vector2f;
  13.  
  14. public class ShardOnHitEffect implements OnHitEffectPlugin {
  15.  
  16.     // The sound the projectile makes if it deals extra damage
  17.     private String SOUND_ID;
  18.     // The damage types that the extra damage can deal (randomly selected)
  19.     private static final DamageType[] TYPES = {
  20.         DamageType.ENERGY
  21.     };
  22.     // How likely it is that the extra damage will be applied (1 = 100% chance)
  23.     private float EXTRA_DAMAGE_CHANCE;
  24.     private Color EXPLOSION_COLOR;
  25.     private Color PARTICLE_COLOR;
  26.     private int NUM_PARTICLES;
  27.     private float MIN_EXTRA_DAMAGE;
  28.     private float MAX_EXTRA_DAMAGE;
  29.  
  30.     @Override
  31.     public void onHit(DamagingProjectileAPI projectile, CombatEntityAPI target, Vector2f point, boolean shieldHit, CombatEngineAPI engine) {
  32.         String id = projectile.getWeapon().getId();
  33.         switch (id) {
  34.             case "someweapon":
  35.                 SOUND_ID = "shardsplode";
  36.                 EXTRA_DAMAGE_CHANCE = 0.18f;
  37.                 EXPLOSION_COLOR = new Color(130, 235, 217, 255);
  38.                 PARTICLE_COLOR = new Color(130, 235, 217, 255);
  39.                 NUM_PARTICLES = 14;
  40.                 MIN_EXTRA_DAMAGE = 140f;
  41.                 MAX_EXTRA_DAMAGE = 260f;
  42.                 break;
  43.             case "someotherweapon":
  44.                 SOUND_ID = "shardsplode";
  45.                 EXTRA_DAMAGE_CHANCE = 0.18f;
  46.                 EXPLOSION_COLOR = new Color(130, 235, 217, 255);
  47.                 PARTICLE_COLOR = new Color(130, 235, 217, 255);
  48.                 NUM_PARTICLES = 14;
  49.                 MIN_EXTRA_DAMAGE = 140f;
  50.                 MAX_EXTRA_DAMAGE = 260f;
  51.                 break;
  52.             default:
  53.                 // This shouldn't ever occur but it's here because I'm paranoid
  54.                 SOUND_ID = "shardsplode";
  55.                 EXTRA_DAMAGE_CHANCE = 0.18f;
  56.                 EXPLOSION_COLOR = new Color(130, 235, 217, 255);
  57.                 PARTICLE_COLOR = new Color(130, 235, 217, 255);
  58.                 NUM_PARTICLES = 14;
  59.                 MIN_EXTRA_DAMAGE = 140f;
  60.                 MAX_EXTRA_DAMAGE = 260f;
  61.                 break;
  62.         }
  63.        
  64.         // Check if we hit a ship (not its shield)
  65.         if (target instanceof ShipAPI && !shieldHit && Math.random() <= EXTRA_DAMAGE_CHANCE) {
  66.             // Apply extra damage of a random type
  67.             engine.applyDamage(target, point,
  68.                     MathUtils.getRandomNumberInRange(MIN_EXTRA_DAMAGE, MAX_EXTRA_DAMAGE),
  69.                     TYPES[(int) ((float) Math.random() * TYPES.length)], 0f, false,
  70.                     true, projectile.getSource());
  71.  
  72.             // Spawn visual effects
  73.             engine.spawnExplosion(point, (Vector2f) new Vector2f(target.getVelocity()).scale(.45f), EXPLOSION_COLOR, 46f, 1.5f);
  74.             float speed = projectile.getVelocity().length();
  75.             float facing = projectile.getFacing();
  76.             for (int x = 0; x < NUM_PARTICLES; x++) {
  77.                 engine.addHitParticle(point, MathUtils.getPointOnCircumference(
  78.                         null, MathUtils.getRandomNumberInRange(speed * .007f, speed * .17f),
  79.                         MathUtils.getRandomNumberInRange(facing - 180f, facing + 180f)),
  80.                         7f, 1f, 1.6f, PARTICLE_COLOR);
  81.             }
  82.  
  83.             // Sound follows enemy that was hit
  84.             Global.getSoundPlayer().playSound(SOUND_ID, 1f, 0.5f, target.getLocation(), target.getVelocity());
  85.         }
  86.     }
  87. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement