I use five multiframe decoration weapons to make it, tophead, frontleft, frontright, backleft, backright.
Why I chose multiframe not particle, because of particle is a rare resource, too many particle is not good.
Here is the core part of my code, have fun
:
package data.scripts.effect.additive;
import java.util.List;
import java.util.ArrayList;
import java.awt.Color;
import org.lwjgl.util.vector.Vector2f;
import com.fs.starfarer.api.combat.CombatEngineAPI;
import com.fs.starfarer.api.combat.EveryFrameWeaponEffectPlugin;
import com.fs.starfarer.api.combat.WeaponAPI;
import com.fs.starfarer.api.combat.WeaponAPI.WeaponSize;
import com.fs.starfarer.api.combat.ShipAPI;
import com.fs.starfarer.api.AnimationAPI;
import com.fs.starfarer.api.Global;
public class AttitudeControl_Effect {
private static float amountSpeed = 20f;
private static int growAmount = 7;
private static List WeaponList = new ArrayList();
static{
WeaponList.add("AttitudeControl_HT");
WeaponList.add(0);
WeaponList.add("AttitudeControl_TL");
WeaponList.add(1);
WeaponList.add("AttitudeControl_TR");
WeaponList.add(2);
WeaponList.add("AttitudeControl_BL");
WeaponList.add(3);
WeaponList.add("AttitudeControl_BR");
WeaponList.add(4);
}
private int recordAmount = 0;
private int growUpAmount = 0;
private float currentAmount = 0f;
private float currentAngularVelocity = 0f;
private Vector2f currentVelocity = new Vector2f(0f, 0f);
private boolean checkRun = false;
private int frame = 0;
public AttitudeControl_Effect(float amount, CombatEngineAPI engine, WeaponAPI weapon){
for(int i = 0;i < WeaponList.size() && !this.checkRun;i+=2){
String weaponGet = (String)WeaponList.get(i);
if(weaponGet.equals(weapon.getId())){
this.checkRun = true;
}
}
}
public void advance(float amount, CombatEngineAPI engine, WeaponAPI weapon) {
if (engine.isPaused()) return;
if(weapon.getShip().isHulk()) return;
if(!this.checkRun) return;
this.currentAmount = this.currentAmount + amount * this.amountSpeed;
if((int)this.currentAmount > this.recordAmount){
this.recordAmount = (int)this.currentAmount;
if(this.currentAmount > 100){
this.currentAmount = 0f;
this.recordAmount = 0;
}
}else{
return;
}
ShipAPI ship = weapon.getShip();
AnimationAPI animation = weapon.getAnimation();
int value[] = new int[5];
value[0] = 0;
value[1] = 0;
value[2] = 0;
value[3] = 0;
value[4] = 0;
float angularVelocityChange = ship.getAngularVelocity() - this.currentAngularVelocity;
this.currentAngularVelocity = ship.getAngularVelocity();
if(angularVelocityChange == 0f && ship.getAngularVelocity() != 0f){
angularVelocityChange = ship.getAngularVelocity();
}
float velocityX = ship.getVelocity().getX() - this.currentVelocity.getX();
float velocityY = ship.getVelocity().getY() - this.currentVelocity.getY();
this.currentVelocity.setX(ship.getVelocity().getX());
this.currentVelocity.setY(ship.getVelocity().getY());
float wholeSize = (float)Math.sqrt(ship.getVelocity().getX() * ship.getVelocity().getX() + ship.getVelocity().getY() * ship.getVelocity().getY());
wholeSize = (wholeSize > 50f)?50f:wholeSize;
if(velocityX < wholeSize * 0.001f && velocityX > wholeSize * -0.001f){
velocityX = 0f;
}
if(velocityY < wholeSize * 0.001f && velocityY > wholeSize * -0.001f){
velocityY = 0f;
}
float velocityAngle = -1f;
if(velocityX != 0f || velocityY != 0f){
if(velocityX != 0f){
velocityAngle = (float)Math.atan((double)(velocityY / velocityX)) * (float)(180f / Math.PI);
if(velocityX < 0f){
velocityAngle = velocityAngle + 180f;
}
}else{
if(velocityY > 0f){
velocityAngle = 90f;
}else{
velocityAngle = 270f;
}
}
velocityAngle = velocityAngle - ship.getFacing();
if(velocityAngle < 0f){
velocityAngle += 360f;
}
velocityX = (float)Math.sin(velocityAngle / (180f / Math.PI));
velocityY = (float)Math.cos(velocityAngle / (180f / Math.PI));
if(velocityX < 0.01f && velocityX > -0.01f){
velocityX = 0f;
}
if(velocityY <= 0.1f && velocityY >= -0.1f){
velocityY = 0f;
}
if(velocityX > 0f){
value[2]++;
value[4]++;
}else if(velocityX < 0f){
value[1]++;
value[3]++;
}
if(velocityY < 0f){
value[0]++;
}
}
if(ship.getAngularVelocity() != this.currentAngularVelocity || ship.getAngularVelocity() != 0f){
if(angularVelocityChange > 0){
value[2]++;
value[3]++;
}else{
value[1]++;
value[4]++;
}
}
if(value[1] > 0 && value[2] > 0){
value[1] = 0;
value[2] = 0;
}
if(value[3] > 0 && value[4] > 0){
value[3] = 0;
value[4] = 0;
}
if(value[0] > 0 || value[1] > 0 || value[2] > 0 || value[3] > 0 || value[4] > 0){
for(int i = 0;i < WeaponList.size();i+=2){
String weaponGet = (String)WeaponList.get(i);
if(weaponGet.equals(weapon.getId())){
int group = (Integer)WeaponList.get(i+1);
for(;group >= 5;group-=5){}
if(value[group] > 0){
if(this.growUpAmount <= this.growAmount){
this.growUpAmount++;
this.frame = this.growUpAmount;
}else{
//this.frame++;
this.frame = this.growAmount + (int)((float)Math.random() * (float)(animation.getNumFrames() - this.growAmount - 1)) + 1;
if(this.frame >= animation.getNumFrames()){
this.frame = this.growUpAmount + 1;
}
}
animation.setFrame(this.frame);
}else{
if(this.growUpAmount > 0){
this.growUpAmount--;
this.frame = this.growUpAmount;
}else{
this.growUpAmount = 0;
this.frame = this.growUpAmount;
}
animation.setFrame(this.frame);
}
}
}
}else{
if(this.growUpAmount > 0){
this.growUpAmount--;
this.frame = this.growUpAmount;
}else{
this.growUpAmount = 0;
this.frame = this.growUpAmount;
}
animation.setFrame(this.frame);
}
}
}