package data.scripts.EveryFrameCombatPlugin;
import com.fs.starfarer.api.combat.CombatEngineAPI;
import com.fs.starfarer.api.combat.CombatEntityAPI;
import com.fs.starfarer.api.combat.EveryFrameCombatPlugin;
import com.fs.starfarer.api.combat.MissileAPI;
import com.fs.starfarer.api.input.InputEventAPI;
import com.fs.starfarer.api.util.IntervalUtil;
import org.lwjgl.util.vector.Vector2f;
import java.util.List;
import static org.lazywizard.lazylib.combat.CombatUtils.getShipsWithinRange;
public class Scatterb implements EveryFrameCombatPlugin {
private IntervalUtil tracker = new IntervalUtil(0.35f, 0.4f);
private static CombatEngineAPI activeEngine;
public void advance(float amount, MissileAPI missile, CombatEntityAPI target, CombatEngineAPI engine, java.lang.String SBKR1, List events) {
if (getShipsWithinRange(missile.getLocation(), 400f, true).get(0).isAlive())
{
target = getShipsWithinRange(missile.getLocation(), 400f, true).get(0);
{
//create variables
//capitalized can be changed
//insert targeter code here (anything goes, you may need to change it so T gives tx/ty a float value
//see at bottom for possible code
CombatEntityAPI T = target;//end point of " " (enemy api/point in space/ect) for targeter
MissileAPI P = missile; //start point of " " for weapon
float px = P.getLocation().getX(); //get location og p (for center of dakakakaka)
float py = P.getLocation().getY();
//float mvx = missile.getVelocity().getX();
//float mvy = missile.getVelocity().getY();
float tx = T.getLocation().getX(); //get location of t (for center of pew pew)
float ty = T.getLocation().getY();
double rxd = .5 - Math.random(); //generate a random double with -vs component, range -.5 to +.5
float rx = (float)rxd*2; // convert to float
double ryd = .5 - Math.random();
float ry = (float)ryd*2;
double rpd = Math.random(); //+ve random
float rp = (float)rpd;
float Tvar = 50f; //radius of t (sets mirv spread (angular))
float Pvar = 1f; //variable for vectors can use random float
double prany = py/Math.abs(py)*Pvar;
double pranx = px/Math.abs(px)*Pvar;
float prx = (float)pranx;
float pry = (float)prany;
float Rvar = 5f; //how much the velocities of projectiles can vary
double rvd = .5 - Math.random(); //generate random velocity multiplier for smooth function (to arr roughness back in
float rv = (float)rvd*Rvar;
//math
float Fx = (tx * rx * Tvar); //create randomized point field to shoot at
float Fy = (ty * ry * Tvar);
float Vx = (Fx * px * prx); //create vectors for pewpews to follow
float Vy = (Fy * py * pry);
double Smoothv = (Math.sqrt(((tx-px)*(tx-px))+((ty-py)*(ty-py)))/Math.sqrt((Vx*Vx)+(Vy*Vy)))*rv; //smoothes out ragged shot
float Sv = (float) Smoothv;
Vector2f Pjv = new Vector2f(Vx*Sv, Vy*Sv); //make the actual vector
engine.spawnProjectile(null, null,
SBKR1,
missile.getLocation(), 0,Pjv);
engine.removeEntity(missile); //make missile go poof
}
}
}
@Override
public void advance(float amount, List events) {
}
@Override
public void init(CombatEngineAPI engine) {
//To change body of implemented methods use File | Settings | File Templates.
}
}