Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package data.scripts.weapons;
- import com.fs.starfarer.api.Global;
- import com.fs.starfarer.api.combat.CombatEngineAPI;
- import com.fs.starfarer.api.combat.CombatEntityAPI;
- import com.fs.starfarer.api.combat.DamageType;
- import com.fs.starfarer.api.combat.DamagingProjectileAPI;
- import com.fs.starfarer.api.combat.OnHitEffectPlugin;
- import com.fs.starfarer.api.combat.ShipAPI;
- import java.awt.Color;
- import org.lazywizard.lazylib.MathUtils;
- import org.lwjgl.util.vector.Vector2f;
- public class ShardOnHitEffect implements OnHitEffectPlugin {
- // The sound the projectile makes if it deals extra damage
- private String SOUND_ID;
- // The damage types that the extra damage can deal (randomly selected)
- private static final DamageType[] TYPES = {
- DamageType.ENERGY
- };
- // How likely it is that the extra damage will be applied (1 = 100% chance)
- private float EXTRA_DAMAGE_CHANCE;
- private Color EXPLOSION_COLOR;
- private Color PARTICLE_COLOR;
- private int NUM_PARTICLES;
- private float MIN_EXTRA_DAMAGE;
- private float MAX_EXTRA_DAMAGE;
- @Override
- public void onHit(DamagingProjectileAPI projectile, CombatEntityAPI target, Vector2f point, boolean shieldHit, CombatEngineAPI engine) {
- String id = projectile.getWeapon().getId();
- switch (id) {
- case "someweapon":
- SOUND_ID = "shardsplode";
- EXTRA_DAMAGE_CHANCE = 0.18f;
- EXPLOSION_COLOR = new Color(130, 235, 217, 255);
- PARTICLE_COLOR = new Color(130, 235, 217, 255);
- NUM_PARTICLES = 14;
- MIN_EXTRA_DAMAGE = 140f;
- MAX_EXTRA_DAMAGE = 260f;
- break;
- case "someotherweapon":
- SOUND_ID = "shardsplode";
- EXTRA_DAMAGE_CHANCE = 0.18f;
- EXPLOSION_COLOR = new Color(130, 235, 217, 255);
- PARTICLE_COLOR = new Color(130, 235, 217, 255);
- NUM_PARTICLES = 14;
- MIN_EXTRA_DAMAGE = 140f;
- MAX_EXTRA_DAMAGE = 260f;
- break;
- default:
- // This shouldn't ever occur but it's here because I'm paranoid
- SOUND_ID = "shardsplode";
- EXTRA_DAMAGE_CHANCE = 0.18f;
- EXPLOSION_COLOR = new Color(130, 235, 217, 255);
- PARTICLE_COLOR = new Color(130, 235, 217, 255);
- NUM_PARTICLES = 14;
- MIN_EXTRA_DAMAGE = 140f;
- MAX_EXTRA_DAMAGE = 260f;
- break;
- }
- // Check if we hit a ship (not its shield)
- if (target instanceof ShipAPI && !shieldHit && Math.random() <= EXTRA_DAMAGE_CHANCE) {
- // Apply extra damage of a random type
- engine.applyDamage(target, point,
- MathUtils.getRandomNumberInRange(MIN_EXTRA_DAMAGE, MAX_EXTRA_DAMAGE),
- TYPES[(int) ((float) Math.random() * TYPES.length)], 0f, false,
- true, projectile.getSource());
- // Spawn visual effects
- engine.spawnExplosion(point, (Vector2f) new Vector2f(target.getVelocity()).scale(.45f), EXPLOSION_COLOR, 46f, 1.5f);
- float speed = projectile.getVelocity().length();
- float facing = projectile.getFacing();
- for (int x = 0; x < NUM_PARTICLES; x++) {
- engine.addHitParticle(point, MathUtils.getPointOnCircumference(
- null, MathUtils.getRandomNumberInRange(speed * .007f, speed * .17f),
- MathUtils.getRandomNumberInRange(facing - 180f, facing + 180f)),
- 7f, 1f, 1.6f, PARTICLE_COLOR);
- }
- // Sound follows enemy that was hit
- Global.getSoundPlayer().playSound(SOUND_ID, 1f, 0.5f, target.getLocation(), target.getVelocity());
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement