Fractal Softworks Forum

Please login or register.

Login with username, password and session length
Advanced search  

News:

Starsector 0.97a is out! (02/02/24); New blog post: Simulator Enhancements (03/13/24)

Author Topic: Is there any way to make beams generate hard flux?  (Read 2299 times)

celestis

  • Captain
  • ****
  • Posts: 285
    • View Profile
Is there any way to make beams generate hard flux?
« on: May 13, 2014, 02:26:53 AM »

Hello!
This is quite a duplicate of http://fractalsoftworks.com/forum/index.php?topic=3345.0, but I was warned about necro-posting, so decided to create another thread.
The question is: is it possible to make some beam weapons generate hard flux on target ship? I don't mean changing vanilla game, but just a possibility for modding.

In the referenced thread, Alex said:
Quote
I'll see about adding the ability to do hard flux damage to beam weapons via mods.
But it was in 2012 :) So I just wanted to raise the question again.
Thanks
Logged

Debido

  • Admiral
  • *****
  • Posts: 1183
    • View Profile
Re: Is there any way to make beams generate hard flux?
« Reply #1 on: May 13, 2014, 03:03:06 AM »

Yes. Check out the BeamAPI. You might want to getDamageTarget() then cast it as a ShipAPI, then get the FluxTracker for the ship's ShipAPI interface then increaseFlux(amount,true) through the FluxTracker to give give the ship hard flux.

EDIT: If you don't want enjoy the learning experience of how to do all the code monkey stuff yourself, I can post a solution fairly quick if you want the code.
« Last Edit: May 13, 2014, 03:06:55 AM by Debido »
Logged

celestis

  • Captain
  • ****
  • Posts: 285
    • View Profile
Re: Is there any way to make beams generate hard flux?
« Reply #2 on: May 13, 2014, 03:10:43 AM »

Thanks for answer, I will try! Though I don't need your code, as I find coding somewhat fun and challenging)
Logged

Xalendi

  • Commander
  • ***
  • Posts: 198
    • View Profile
Re: Is there any way to make beams generate hard flux?
« Reply #3 on: May 18, 2014, 10:14:20 AM »

I would quite like your code though please, if you're willing.
Logged

Debido

  • Admiral
  • *****
  • Posts: 1183
    • View Profile
Re: Is there any way to make beams generate hard flux?
« Reply #4 on: May 19, 2014, 01:49:10 AM »

I would quite like your code though please, if you're willing.

Here you go!

Code: java

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.ShipAPI;
import com.fs.starfarer.api.util.IntervalUtil;

/**
 *
 * @author Debido
 * fragments derived from Xenoargh's MegaBeamDamageEffect plugin
 *
 * This script is intended to allow the given Beam weapon using this script to apply hard flux damage to the enemy ship if the beam hits their shield
 * This is probably OP, so be careful with game balancing!
 */

public class BeamFullFlux implements BeamEffectPlugin {

    private final IntervalUtil fireInterval = new IntervalUtil(0.1f, 0.1f); //interval between applying flux
    private final float fluxMultiplier = 10.0f; //determines how much hard flux is generated in the enemy ship. 1.0f would be 100% of weapon DPS, 0.1f would be 10%, and 10f would be 1000%

    @Override
    public void advance(float amount, CombatEngineAPI engine, BeamAPI beam) {

        if (engine.isPaused()) {
            return;
        }

        fireInterval.advance(amount);

        CombatEntityAPI target = beam.getDamageTarget();
        //If we have a target, target is a Ship, and shields are being hit.
        if (target != null && target instanceof ShipAPI && target.getShield() != null && target.getShield().isWithinArc(beam.getTo())) {
            if (fireInterval.intervalElapsed()) {
                if (beam.getBrightness() >= 1f) {
                    ShipAPI ship = (ShipAPI) target; //cast as ship
                    ship.getFluxTracker().increaseFlux(fluxMultiplier * beam.getWeapon().getDerivedStats().getDps() / 10f, true); //apply flux
                }

            }

        }
    }
}

« Last Edit: May 19, 2014, 01:58:30 AM by Debido »
Logged

Xalendi

  • Commander
  • ***
  • Posts: 198
    • View Profile
Re: Is there any way to make beams generate hard flux?
« Reply #5 on: May 19, 2014, 03:30:46 PM »

Brilliant, thank you.
Logged