Fractal Softworks Forum

Please login or register.

Login with username, password and session length
Pages: 1 [2]

Author Topic: Example Code Request: spawnEmpArc()  (Read 11801 times)

Nekora

  • Ensign
  • *
  • Posts: 28
    • View Profile
Re: Example Code Request: spawnEmpArc()
« Reply #15 on: January 18, 2013, 12:00:47 PM »

this will work for that. With a few tweaks, let me look at it for ya...

and done, well that was easy enough, just modified the awesome code from LazyWizard... Also changed the anchor point as it looked silly ancoring to the target... well i thought it did. Anyway:
Code
package data.scripts.weapons;

import com.fs.starfarer.api.combat.BeamAPI;
import com.fs.starfarer.api.combat.BeamEffectPlugin;
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.ShipAPI;
import com.fs.starfarer.api.util.IntervalUtil;
import java.awt.Color;
import java.util.*;
import org.lwjgl.util.vector.Vector2f;

public class LightningStrikeEffect implements BeamEffectPlugin
{
    private static final float TIME_BETWEEN_BURSTS = .1f;    // How long between each discharge
    private static final Color CORE_COLOR = new Color(255, 255, 255, 255);// What color is the core of the arc?
    private static final Color FRINGE_COLOR = new Color(85, 25, 215, 255);// What color is the fringe of the arc?
    private IntervalUtil fireInterval = new IntervalUtil(TIME_BETWEEN_BURSTS, TIME_BETWEEN_BURSTS);

    @Override //i have no idea what this does
    public void advance(float amount, CombatEngineAPI engine, BeamAPI beam)
    {
        CombatEntityAPI target = beam.getDamageTarget();
        // Check that we hit something, modified to arc to shields
        if (target != null && target instanceof ShipAPI)
        {
//Only activate if beam is at full power (beam charge up time)
            if (beam.getBrightness() >= 1f)
            {
                fireInterval.advance(amount);
                if (fireInterval.intervalElapsed())
                {
                    // Source of the current lightning chain
                    Vector2f source = beam.getFrom();
                    // Victim of the current lightning chain
                    CombatEntityAPI currentVictim = target;
                    // Ensure we keep the same DPS as listed in the weapon's stats tooltip
                    float damage = beam.getWeapon().getDerivedStats().getDps()
                            * beam.getSource().getMutableStats().getBeamWeaponDamageMult().getModifiedValue()
                            * TIME_BETWEEN_BURSTS;
                    float emp = beam.getWeapon().getDerivedStats().getEmpPerSecond()
                            * TIME_BETWEEN_BURSTS;

// Spawn lightning strike
                    engine.spawnEmpArc(beam.getSource(), source,
                                beam.getSource(), currentVictim,
                                DamageType.ENERGY, damage, emp, 100000f,
                                "tachyon_lance_emp_impact", 15f,
                                FRINGE_COLOR, CORE_COLOR);
                }
            }
        }
    }
}

BTW anyone know what does the "@overide" Does?
« Last Edit: January 18, 2013, 12:29:01 PM by Nekora »
Logged

Nekora

  • Ensign
  • *
  • Posts: 28
    • View Profile
Re: Example Code Request: spawnEmpArc()
« Reply #16 on: January 18, 2013, 12:44:17 PM »

Hmm, quick tweak to LazyWizards code, Ancoring the arc to the emmiter looks much better so add the following lines to do so...
After the line of code "CombatEntityAPI currentVictim = target;" add this:
Code
CombatEntityAPI currentEmmiter = beam.getSource();	// Emmitter of the Next lightning chain is the target of this one

and change the "engine.spawnEmpArc" to:
Code
// Spawn this chain's lightning arc
engine.spawnEmpArc(beam.getSource(), source,
          currentEmmiter, currentVictim,
          DamageType.ENERGY, damage, emp, 100000f,
          "tachyon_lance_emp_impact", 15f,
          FRINGE_COLOR, CORE_COLOR);

currentEmmiter = currentVictim; // Emmitter of the Next lightning chain is the target of this one

Just makes it look a bit nicer thats all.

Should look like this:
Spoiler
Code
package data.scripts.weapons;

import com.fs.starfarer.api.combat.BeamAPI;
import com.fs.starfarer.api.combat.BeamEffectPlugin;
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.ShipAPI;
import com.fs.starfarer.api.util.IntervalUtil;
import java.awt.Color;
import java.util.*;
import org.lwjgl.util.vector.Vector2f;

public class ChainLightningEffect implements BeamEffectPlugin
{
    // If true, don't hit the same ship twice in the same burst
    private static final boolean IGNORE_SAME_SHIP_IN_BURST = true;
    // If true, pick a random enemy in range to be the next link in the chain
    private static final boolean PICK_RANDOM_ENEMY_IN_RANGE = false;
    // How long must the beam be fired for before it will start a second chain?
    private static final float TIME_BETWEEN_BURSTS = .2f;
    // How far can the initial chain travel to hit an enemy?
    private static final float INITIAL_CHAIN_RANGE = 1000f;
    // How much of its previous max length will each chain retain?
    private static final float RANGE_RETENTION_PER_CHAIN = .90f;
    // How much damage will each chain do, compared to the previous?
    private static final float DAMAGE_RETENTION_PER_CHAIN = .85f;
    // How many chains should we limit the weapon to generating?
    private static final int MAXIMUM_CHAINS_PER_BURST = 5;
    // What color is the core of the arc?
    private static final Color CORE_COLOR = new Color(255, 255, 255, 255);
    // What color is the fringe of the arc?
    private static final Color FRINGE_COLOR = new Color(85, 25, 215, 255);
    private IntervalUtil fireInterval = new IntervalUtil(TIME_BETWEEN_BURSTS, TIME_BETWEEN_BURSTS);

    private static float getDistance(Vector2f point1, Vector2f point2)
    {
        return (float) Math.hypot(point1.x - point2.x, point1.y - point2.y);
    }

    private static List getEnemiesInRange(CombatEntityAPI ship, float range,
            int side, CombatEngineAPI engine)
    {
        List enemies = new ArrayList(), allShips = engine.getShips();
        ShipAPI tmp;

        // Iterate through all ships on the battlefield
        for (int x = 0; x < allShips.size(); x++)
        {
            tmp = (ShipAPI) allShips.get(x);

            // Filter through and find active enemies that are within range
            if (!tmp.isHulk() && !tmp.isShuttlePod() && ship.getOwner() != side
                    && getDistance(ship.getLocation(), tmp.getLocation()) <= range)
            {
                enemies.add(tmp);
            }
        }

        return enemies;
    }

    @Override
    public void advance(float amount, CombatEngineAPI engine, BeamAPI beam)
    {
        CombatEntityAPI target = beam.getDamageTarget();

        // Check that we hit something and that it wasn't a shield hit
        //if (target != null && target instanceof ShipAPI
        //        && (target.getShield() == null || !target.getShield().isWithinArc(beam.getTo())))
//fudge that, Arc off shields
if (target != null && target instanceof ShipAPI)
        {
            if (beam.getBrightness() >= 1f)
            {
                fireInterval.advance(amount);
                if (fireInterval.intervalElapsed())
                {
                    // Count how many links are in the chain so far
                    int numStrikes = 0;

                    // Source of the current lightning chain
                    Vector2f source = beam.getFrom();
                    // Victim of the current lightning chain
                    CombatEntityAPI currentVictim = target;
                    // Emmitter of the current lightning chain
                    CombatEntityAPI currentEmmiter = beam.getSource();


                    float range = INITIAL_CHAIN_RANGE;
                    // Ensure we keep the same DPS as listed in the weapon's stats tooltip
                    float damage = beam.getWeapon().getDerivedStats().getDps()
                            * beam.getSource().getMutableStats().getBeamWeaponDamageMult().getModifiedValue()
                            * TIME_BETWEEN_BURSTS;
                    float emp = beam.getWeapon().getDerivedStats().getEmpPerSecond()
                            * TIME_BETWEEN_BURSTS;

                    // This is used to prevent hitting the same target twice
                    // if IGNORE_SAME_SHIP_IN_BURST is set to true
                    Set struck = new HashSet();

                    do
                    {
                        // Spawn this chain's lightning arc
                        engine.spawnEmpArc(beam.getSource(), source,
                                currentEmmiter, currentVictim,
                                DamageType.ENERGY, damage, emp, 100000f,
                                "tachyon_lance_emp_impact", 15f,
                                FRINGE_COLOR, CORE_COLOR);

// Emmitter of the Next lightning chain is the target of this one
                        currentEmmiter = currentVictim;

                        // Check that we haven't hit our chain limit
                        if (++numStrikes >= MAXIMUM_CHAINS_PER_BURST)
                        {
                            return;
                        }

                        // Reduce the stats of the next chain
                        range *= RANGE_RETENTION_PER_CHAIN;
                        damage *= DAMAGE_RETENTION_PER_CHAIN;
                        emp *= DAMAGE_RETENTION_PER_CHAIN;

                        // Find our next victim
                        source = currentVictim.getLocation();
                        List enemies = getEnemiesInRange(currentVictim, range,
                                beam.getSource().getOwner(), engine);
                        enemies.remove(currentVictim);

                        // Remove enemies that have already been struck once
                        // (only if IGNORE_SAME_SHIP_IN_BURST is true)
                        if (IGNORE_SAME_SHIP_IN_BURST)
                        {
                            struck.add(currentVictim);
                            enemies.removeAll(struck);
                        }

                        // Remove enemies who would block or avoid a strike
                        ShipAPI tmp;
                        //for (Iterator iter = enemies.iterator(); iter.hasNext();)
                        //{
                        //    tmp = (ShipAPI) iter.next();
                        //    if ((tmp.getShield() != null && tmp.getShield().isOn()
                        //            && tmp.getShield().isWithinArc(source))
                        //            || (tmp.getPhaseCloak() != null
                        //            && tmp.getPhaseCloak().isActive()))
                        //    {
                        //        iter.remove();
                        //    }
                        //}
//Again... lets hit shields but not phazed
for (Iterator iter = enemies.iterator(); iter.hasNext();)
                        {
                            tmp = (ShipAPI) iter.next();
                            if (tmp.getPhaseCloak() != null
                                    && tmp.getPhaseCloak().isActive())
                            {
                                iter.remove();
                            }
                        }


                        // Pick a random valid enemy in range
                        if (!enemies.isEmpty())
                        {
                            if (PICK_RANDOM_ENEMY_IN_RANGE)
                            {
                                currentVictim = (ShipAPI) enemies.get((int) (Math.random() * enemies.size()));
                            }
                            else
                            {
                                ShipAPI closest = null;
                                float distance, closestDistance = Float.MAX_VALUE;

                                // Find the closest enemy in range
                                for (int x = 0; x < enemies.size(); x++)
                                {
                                    tmp = (ShipAPI) enemies.get(x);

                                    distance = getDistance(tmp.getLocation(),
                                            currentVictim.getLocation());

                                    // This ship is closer than the previous best
                                    if (distance < closestDistance)
                                    {
                                        closest = tmp;
                                        closestDistance = distance;
                                    }
                                }

                                currentVictim = closest;
                            }
                            // No enemies in range, end the chain
                        }
                        else
                        {
                            currentVictim = null;
                        }
                    }
                    while (currentVictim != null);
                }
            }
        }
    }
}
[close]
« Last Edit: January 18, 2013, 05:37:57 PM by Nekora »
Logged

LazyWizard

  • Global Moderator
  • Admiral
  • *****
  • Posts: 1365
    • View Profile
    • GitHub Profile
Re: Example Code Request: spawnEmpArc()
« Reply #17 on: January 18, 2013, 05:34:01 PM »

BTW anyone know what does the "@overide" Does?

It's a Java annotation. In this case, it's just saying that this method is either overriding a method of the superclass or implementing one from an interface.

Starfarer strips these out when it compiles the code since Janino can't handle them, but I still put them in the source to note that this is an inherited method (plus there are a few benefits to adding this annotation if you use an IDE). :)
Logged

Nekora

  • Ensign
  • *
  • Posts: 28
    • View Profile
Re: Example Code Request: spawnEmpArc()
« Reply #18 on: January 19, 2013, 02:28:16 PM »

ugh, just spent a few hours trying to get a ball lighting aoe weapon to work, turns out "spawnType":"PLASMA" does not alow onhiteffects... damnit...

well incase you are intrested in what i came up with:
Code
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.DamageType;
import com.fs.starfarer.api.combat.DamagingProjectileAPI;
import com.fs.starfarer.api.combat.OnHitEffectPlugin;
import com.fs.starfarer.api.combat.ShipAPI;


import com.fs.starfarer.api.util.IntervalUtil;
import java.util.*;

public class LightningAOEHitEffect implements OnHitEffectPlugin {

//Based on LazyWizard's chain lightning code.


    private static final boolean IGNORE_SAME_SHIP_IN_BURST = true; // If true, don't hit the same ship twice in the same burst
    private static final boolean PICK_RANDOM_ENEMY_IN_RANGE = true; // If true, pick a random enemy in range to be the next hit in the burst
    private static final float RANGE_MOD = 1.5f; // Range of aoe * damage
    private static final int MAXIMUM_CHAINS_PER_BURST = 5; // How many chains should we limit the weapon to generating?
    private static final Color CORE_COLOR = new Color(255, 255, 255, 255); // What color is the core of the arc?
    private static final Color FRINGE_COLOR = new Color(85, 25, 215, 255); // What color is the fringe of the arc?

private static float getDistance(Vector2f point1, Vector2f point2)
    {
        return (float) Math.hypot(point1.x - point2.x, point1.y - point2.y);
    }

private static List getEnemiesInRange(CombatEntityAPI ship, float range, int side, CombatEngineAPI engine)
    {
        List enemies = new ArrayList(), allShips = engine.getShips();
        ShipAPI tmp;
        // Iterate through all ships on the battlefield
        for (int x = 0; x < allShips.size(); x++)
        {
            tmp = (ShipAPI) allShips.get(x);

            // Filter through and find active enemies that are within range
            if (!tmp.isHulk() && !tmp.isShuttlePod() && ship.getOwner() != side
                    && getDistance(ship.getLocation(), tmp.getLocation()) <= range)
            {
                enemies.add(tmp);
            }
        }

        return enemies;
    }



public void onHit(DamagingProjectileAPI projectile, CombatEntityAPI target, Vector2f point, boolean shieldHit, CombatEngineAPI engine)
{
//did we hit a ship?
if (target instanceof ShipAPI)
{

//damage is 1/4 of original hit
float emp = projectile.getEmpAmount() * .25f;
float damage = projectile.getDamageAmount() * .25f;
float range = projectile.getDamageAmount() * RANGE_MOD;
//float range = 1000f;

// Count how many links are in the chain so far
            int numStrikes = 0;

            // Victim of the current lightning chain
            CombatEntityAPI currentVictim = target;
               
            // This is used to prevent hitting the same target twice
            // if IGNORE_SAME_SHIP_IN_BURST is set to true
            Set struck = new HashSet();

do
            {
// Spawn this chain's lightning arc
                engine.spawnEmpArc(projectile.getSource(), point, projectile, currentVictim,
                                DamageType.ENERGY, damage, emp, 100000f,
                                "tachyon_lance_emp_impact", 15f,
                                FRINGE_COLOR, CORE_COLOR);

// Check that we haven't hit our chain limit
                if (++numStrikes >= MAXIMUM_CHAINS_PER_BURST)
                   {
                        return;
                   }

                // Find our next victim
                List enemies = getEnemiesInRange(currentVictim, range, projectile.getSource().getOwner(), engine);
                enemies.remove(currentVictim);

                // Remove enemies that have already been struck once
                // (only if IGNORE_SAME_SHIP_IN_BURST is true)
                if (IGNORE_SAME_SHIP_IN_BURST)
                {
struck.add(currentVictim);
                    enemies.removeAll(struck);
                }

                // Remove enemies who would block or avoid a strike
                ShipAPI tmp;
                for (Iterator iter = enemies.iterator(); iter.hasNext();)
                {
tmp = (ShipAPI) iter.next();
                    if (tmp.getPhaseCloak() != null && tmp.getPhaseCloak().isActive())
                    {
iter.remove();
                    }
                }

                // Pick a random valid enemy in range
                if (!enemies.isEmpty())
                {
if (PICK_RANDOM_ENEMY_IN_RANGE)
                    {
currentVictim = (ShipAPI) enemies.get((int) (Math.random() * enemies.size()));
                    }
                    else
                    {
ShipAPI closest = null;
                        float distance, closestDistance = Float.MAX_VALUE;

// Find the closest enemy in range
for (int x = 0; x < enemies.size(); x++)
{
tmp = (ShipAPI) enemies.get(x);

distance = getDistance(tmp.getLocation(), currentVictim.getLocation());

// This ship is closer than the previous best
if (distance < closestDistance)
{
closest = tmp;
closestDistance = distance;
}
}
                    currentVictim = closest;
                    }
                    // No enemies in range, end the chain
                }
                else
                {
                    currentVictim = null;
                }
            }
            while (currentVictim != null);
}
}
}
Logged

Nekora

  • Ensign
  • *
  • Posts: 28
    • View Profile
Re: Example Code Request: spawnEmpArc()
« Reply #19 on: January 21, 2013, 03:15:07 PM »

Oh, another question. Is there a way to count how long a beam has been held onto a target? I want to make the chain lightning arc more times the longer a beam is held on a single target.

Guess i would need a way of makeing a global tag to check if the target is the same as the last and then if it is incrament the counter, if not reset it... no idea how to do that though? can we attatch infromation to the beam emmiter entity?
Logged

silentstormpt

  • Admiral
  • *****
  • Posts: 1060
    • View Profile
Re: Example Code Request: spawnEmpArc()
« Reply #20 on: January 21, 2013, 06:13:16 PM »

IntervalUtil float amount, check for it when the emp is spawned/being spawned,
Logged

LazyWizard

  • Global Moderator
  • Admiral
  • *****
  • Posts: 1365
    • View Profile
    • GitHub Profile
Re: Example Code Request: spawnEmpArc()
« Reply #21 on: January 21, 2013, 06:17:35 PM »

Oh, another question. Is there a way to count how long a beam has been held onto a target? I want to make the chain lightning arc more times the longer a beam is held on a single target.

Guess i would need a way of makeing a global tag to check if the target is the same as the last and then if it is incrament the counter, if not reset it... no idea how to do that though? can we attatch infromation to the beam emmiter entity?

Yes, that should be simple. Either have an IntervalUtil and count how many times it has elapsed on the current target (see the tachyon lance or chain lightning code for an IntervalUtil example), or just have a float heldTime and CombatEntityAPI lastHit and have something similar to the following in your beam's advance():

Code
if (<check if target hit is valid>)
{
   if (target == lastHit)
   {
      heldTime += amount;
   }
   else
   {
      lastHit = target;
      heldTime = amount;
   }
   // Normal hit code
}
else
{
   heldTime = 0f;
   lastHit = null;
}
Logged

Nekora

  • Ensign
  • *
  • Posts: 28
    • View Profile
Re: Example Code Request: spawnEmpArc()
« Reply #22 on: January 22, 2013, 07:51:23 AM »

Thanks again wizard, that worked perfectly.

heres my proof of concept code:
Code
package data.scripts.weapons;

import com.fs.starfarer.api.combat.BeamAPI;
import com.fs.starfarer.api.combat.BeamEffectPlugin;
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.ShipAPI;
import com.fs.starfarer.api.util.IntervalUtil;
import java.awt.Color;
import java.util.*;
import org.lwjgl.util.vector.Vector2f;

public class CascadeChainLightningEffect implements BeamEffectPlugin
{
    private static final boolean IGNORE_SAME_SHIP_IN_BURST = true; // If true, don't hit the same ship twice in the same burst
    private static final boolean PICK_RANDOM_ENEMY_IN_RANGE = false; // If true, pick a random enemy in range to be the next link in the chain
    private static final float TIME_BETWEEN_BURSTS = .3f; // How long must the beam be fired for before it will start a second chain?
    private static final float INITIAL_CHAIN_RANGE = 200f; // How far can the initial chain travel to hit an enemy?
    private static final float RANGE_RETENTION_PER_CHAIN = .90f; // How much of its previous max length will each chain retain?
    private static final float DAMAGE_RETENTION_PER_CHAIN = .85f; // How much damage will each chain do, compared to the previous?
    private static final int MAXIMUM_CHAINS_PER_BURST = 10; // How many chains should we limit the weapon to generating?
    private static final Color CORE_COLOR = new Color(255, 255, 255, 255); // What color is the core of the arc?
    private static final Color FRINGE_COLOR = new Color(215, 25, 25, 255); // What color is the fringe of the arc?
    private IntervalUtil fireInterval = new IntervalUtil(TIME_BETWEEN_BURSTS, TIME_BETWEEN_BURSTS);

private static final float baseglow = 10f; //base arc glow
private float heldTime = 0f; //How long have we been fireing the beam.
private CombatEntityAPI lastHit = null; //The last target we hit.

    private static float getDistance(Vector2f point1, Vector2f point2)
    {
        return (float) Math.hypot(point1.x - point2.x, point1.y - point2.y);
    }

    private static List getEnemiesInRange(CombatEntityAPI ship, float range,
            int side, CombatEngineAPI engine)
    {
        List enemies = new ArrayList(), allShips = engine.getShips();
        ShipAPI tmp;

        // Iterate through all ships on the battlefield
        for (int x = 0; x < allShips.size(); x++)
        {
            tmp = (ShipAPI) allShips.get(x);

            // Filter through and find active enemies that are within range
            if (!tmp.isHulk() && !tmp.isShuttlePod() && ship.getOwner() != side
                    && getDistance(ship.getLocation(), tmp.getLocation()) <= range)
            {
                enemies.add(tmp);
            }
        }

        return enemies;
    }

    @Override
    public void advance(float amount, CombatEngineAPI engine, BeamAPI beam)
    {
        CombatEntityAPI target = beam.getDamageTarget();

        // Check that we hit something and that it wasn't a shield hit
        //if (target != null && target instanceof ShipAPI
        //        && (target.getShield() == null || !target.getShield().isWithinArc(beam.getTo())))
//fudge that, Arc off shields
if (target != null && target instanceof ShipAPI)
        {
            fireInterval.advance(amount);
            if (fireInterval.intervalElapsed())
            {
//check if target hit is the same target
if (target == lastHit)
{
heldTime += amount;
}
else
{
lastHit = target;
heldTime = amount;
}

                // Count how many links are in the chain so far
                int numStrikes = 0;
                // Source of the current lightning chain
                Vector2f source = beam.getFrom();
                // Victim of the current lightning chain
                CombatEntityAPI currentVictim = target;
                // Emmitter of the current lightning chain
                CombatEntityAPI currentEmmiter = beam.getSource();


                float range = INITIAL_CHAIN_RANGE * heldTime;
                // Ensure we keep the same DPS as listed in the weapon's stats tooltip
                float damage = (beam.getWeapon().getDerivedStats().getDps()
                        * beam.getSource().getMutableStats().getBeamWeaponDamageMult().getModifiedValue()
                        * TIME_BETWEEN_BURSTS) * heldTime;
                float emp = (beam.getWeapon().getDerivedStats().getEmpPerSecond()
                        * TIME_BETWEEN_BURSTS) * heldTime;

float glow = baseglow * heldTime;

                // This is used to prevent hitting the same target twice
                // if IGNORE_SAME_SHIP_IN_BURST is set to true
                Set struck = new HashSet();

                do
                {
                    // Spawn this chain's lightning arc
                    engine.spawnEmpArc(beam.getSource(), source,
                                currentEmmiter, currentVictim,
                                DamageType.ENERGY, damage, emp, 100000f,
                                "tachyon_lance_emp_impact", glow,
                                FRINGE_COLOR, CORE_COLOR);

// Emmitter of the Next lightning chain is the target of this one
                    currentEmmiter = currentVictim;

                    // Check that we haven't hit our chain limit
                    if (++numStrikes >= MAXIMUM_CHAINS_PER_BURST)
                    {
                        return;
                    }

                    // Reduce the stats of the next chain
                    range *= RANGE_RETENTION_PER_CHAIN;
                    damage *= DAMAGE_RETENTION_PER_CHAIN;
                    emp *= DAMAGE_RETENTION_PER_CHAIN;

                    // Find our next victim
                    source = currentVictim.getLocation();
                    List enemies = getEnemiesInRange(currentVictim, range,
                            beam.getSource().getOwner(), engine);
                    enemies.remove(currentVictim);

                    // Remove enemies that have already been struck once
                    // (only if IGNORE_SAME_SHIP_IN_BURST is true)
                    if (IGNORE_SAME_SHIP_IN_BURST)
                    {
                        struck.add(currentVictim);
                        enemies.removeAll(struck);
                    }

                    // Remove enemies who would block or avoid a strike
                    ShipAPI tmp;
//Again... lets hit shields but not phazed
    for (Iterator iter = enemies.iterator(); iter.hasNext();)
                    {
                        tmp = (ShipAPI) iter.next();
                        if (tmp.getPhaseCloak() != null
                                && tmp.getPhaseCloak().isActive())
                        {
                            iter.remove();
                        }
                    }


                    // Pick a random valid enemy in range
                    if (!enemies.isEmpty())
                    {
                        if (PICK_RANDOM_ENEMY_IN_RANGE)
                        {
                            currentVictim = (ShipAPI) enemies.get((int) (Math.random() * enemies.size()));
                        }
                        else
                        {
                            ShipAPI closest = null;
                            float distance, closestDistance = Float.MAX_VALUE;

                            // Find the closest enemy in range
                            for (int x = 0; x < enemies.size(); x++)
                            {
                                tmp = (ShipAPI) enemies.get(x);

                                distance = getDistance(tmp.getLocation(),
                                        currentVictim.getLocation());
                                // This ship is closer than the previous best
                                if (distance < closestDistance)
                                {
                                    closest = tmp;
                                    closestDistance = distance;
                                }
                            }

                            currentVictim = closest;
                        }
                        // No enemies in range, end the chain
                    }
                    else
                    {
                        currentVictim = null;
                    }
                }
                while (currentVictim != null);
            }
        }
    }
}

Although i have knoticed the chain will arc to the fireing ship for some reason... odd
Logged

Pelly

  • Admiral
  • *****
  • Posts: 757
    • View Profile
Re: Example Code Request: spawnEmpArc()
« Reply #23 on: June 07, 2013, 06:25:33 AM »

Really, Really sorry for the necro.

Lazy/Nekora did you ever solve the reason why the arcs returned back to your own ship and took out your own engines? As I have implemented this code into a weapon and it is very annoying to see that happen to your own ship.

Again I apologise for the Necro.
Logged

LazyWizard

  • Global Moderator
  • Admiral
  • *****
  • Posts: 1365
    • View Profile
    • GitHub Profile
Re: Example Code Request: spawnEmpArc()
« Reply #24 on: June 07, 2013, 11:02:46 AM »

There's a more up-to-date version of the chain lightning code here. The only bug I know of in this version is that occasionally there's a graphics glitch where there's a random 'glow' with no arc attached.

Edit: you'll want to change FakeEntity to SimpleEntity and import org.lazywizard.lazylib.combat.entities.SimpleEntity.
« Last Edit: June 07, 2013, 11:06:27 AM by LazyWizard »
Logged

Pelly

  • Admiral
  • *****
  • Posts: 757
    • View Profile
Re: Example Code Request: spawnEmpArc()
« Reply #25 on: June 07, 2013, 12:10:54 PM »

Thank you Lazy boyo, though now i know your plan to make every mod require your mod and then charge us many of our souls to use it :P
Logged

silentstormpt

  • Admiral
  • *****
  • Posts: 1060
    • View Profile
Re: Example Code Request: spawnEmpArc()
« Reply #26 on: June 07, 2013, 07:05:36 PM »

There's a more up-to-date version of the chain lightning code here. The only bug I know of in this version is that occasionally there's a graphics glitch where there's a random 'glow' with no arc attached.

Edit: you'll want to change FakeEntity to SimpleEntity and import org.lazywizard.lazylib.combat.entities.SimpleEntity.

Those happen more often when multiple (in a very fast rate) arcs are hitting the same place
Logged
Pages: 1 [2]