package data.scripts.weapons;
import java.awt.Color;
import org.lwjgl.util.vector.Vector2f;
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.OnHitEffectPlugin;
import org.lazywizard.lazylib.MathUtils;
public class ExplosiveOnHitEffect implements OnHitEffectPlugin {
public static Vector2f randomCircularVelocity(Vector2f position,float velocity)
{
Vector2f velPos = MathUtils.getRandomPointOnCircumference(position, velocity);
Vector2f newVel = Vector2f.sub(velPos,position,null);
return newVel;
}
@Override
public void onHit(DamagingProjectileAPI projectile, CombatEntityAPI target,
Vector2f point, boolean shieldHit, CombatEngineAPI engine) {
float emp = projectile.getEmpAmount();
float dam = projectile.getDamageAmount();
int repeat = Math.max(6,(int) ((dam / 100f) + 10f));
int repeatTwo = repeat / 3;
for(int i = 0; i < repeat; i++)
{
Vector2f randPoint = MathUtils.getRandomPointInCircle(point,dam/35f);
float randSize = MathUtils.getRandomNumberInRange(dam/25f,Math.max(dam / 20f,15f));
Vector2f randVec = randomCircularVelocity(randPoint,MathUtils.getRandomNumberInRange(30f,Math.max(dam / 50f,31f)));
float randDur = 0.1f + MathUtils.getRandomNumberInRange(0.0f,0.3f);
int yelVal = (int) (Math.random() * 200f + 32f);
int randTrans = (int) MathUtils.getRandomNumberInRange(64f,128f);
engine.addSmoothParticle(randPoint, randVec, randSize, 1f, randDur, new Color(255,yelVal,0,randTrans));
}
for(int i = 0; i < repeat; i++)
{
int yelVal = (int) (Math.random() * 128f + 64f);
Vector2f randPoint = MathUtils.getRandomPointInCircle(point,dam/100f);
//Random Vectors, in order of speed; generally, we need smoke and central poof to be slower than others
Vector2f randVecFast = randomCircularVelocity(randPoint,MathUtils.getRandomNumberInRange(30f,Math.max(dam / 2f,31f)));
Vector2f randVecFastTwo = randomCircularVelocity(randPoint,MathUtils.getRandomNumberInRange(30f,Math.max(dam / 2f,31f)));
Vector2f randVec = randomCircularVelocity(randPoint,MathUtils.getRandomNumberInRange(30f,Math.max(dam / 25f,31f)));
Vector2f randVecTwo = randomCircularVelocity(randPoint,MathUtils.getRandomNumberInRange(30f,Math.max(dam / 35f,31f)));
Vector2f randVecThree = randomCircularVelocity(randPoint,MathUtils.getRandomNumberInRange(15f,Math.max(dam / 40f,16f)));
float randSize = MathUtils.getRandomNumberInRange(10f,Math.max(dam / 50f,15f));
float randSizeTwo = MathUtils.getRandomNumberInRange(5f,10f);
float randDur = 1f + MathUtils.getRandomNumberInRange(-0.5f,3f);
float randDurTwo = MathUtils.getRandomNumberInRange(0.5f,1f);
int randTrans = (int) MathUtils.getRandomNumberInRange(32f,200f);
int randGray = (int) MathUtils.getRandomNumberInRange(32f,64f);
engine.addHitParticle(point, randVecFast, randSizeTwo, 1f, randDurTwo * 0.5f, new Color(255,yelVal + 64,0,randTrans + 55));
engine.addHitParticle(point, randVecFastTwo, randSizeTwo, 1f, randDurTwo * 0.65f, new Color(255,yelVal + 64,0,randTrans + 55));
engine.addHitParticle(point, randVec, randSize, 1f, randDurTwo, new Color(255,yelVal-64,0,randTrans));
engine.addHitParticle(point, randVecTwo, randSize, 1f, randDurTwo * 0.75f, new Color(255,yelVal-32,0,randTrans));
engine.addHitParticle(point, randVecThree, randSize, 1f, randDurTwo * 0.5f, new Color(255,yelVal,0,randTrans));
engine.addSmokeParticle(point, randVecThree, MathUtils.getRandomNumberInRange(dam / 100f,dam / 50f), MathUtils.getRandomNumberInRange(0.5f,1f), randDur, new Color(randGray,randGray,randGray,randTrans));
}
}
}