Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*Original scripting framework by Debido
- Ship revival code originally ship boarding code by Xenoargh
- Designed for use with the BGE mod by Tecrys
- */
- package bge.data.scripts.plugins;
- import com.fs.starfarer.api.Global;
- import com.fs.starfarer.api.campaign.FleetDataAPI;
- import com.fs.starfarer.api.combat.CombatEngineAPI;
- import com.fs.starfarer.api.combat.DamageType;
- import com.fs.starfarer.api.combat.EveryFrameCombatPlugin;
- import com.fs.starfarer.api.combat.ShipAPI;
- import com.fs.starfarer.api.fleet.FleetMemberAPI;
- import com.fs.starfarer.api.fleet.FleetMemberType;
- import com.fs.starfarer.api.mission.FleetSide;
- import com.fs.starfarer.api.util.IntervalUtil;
- import java.awt.Color;
- import java.util.*;
- import org.lazywizard.lazylib.MathUtils;
- import org.lwjgl.util.vector.Vector2f;
- public class BGENecroMorphosisMonitor implements EveryFrameCombatPlugin {
- // Stores the currently monitored juiceTokens
- private final List<ShipRequestData> revivalList = new ArrayList();
- private final List<ShipAPI> deadShips = new ArrayList();
- private static final float REVIVE_CHANCE = 0.90f;
- private final Random myRandom = new Random();
- private CombatEngineAPI engine; //required
- private static final float INTERVAL_FRACTION = 5f;
- private final IntervalUtil tracker = new IntervalUtil(INTERVAL_FRACTION, INTERVAL_FRACTION);
- @Override
- public void advance(float amount, List events) {
- if (engine != Global.getCombatEngine()) {
- deadShips.clear();
- revivalList.clear();
- this.engine = Global.getCombatEngine();
- return;
- }
- if (engine.isPaused()) {
- return;
- }
- tracker.advance(amount);
- if (tracker.intervalElapsed()) {
- List<ShipAPI> ships = engine.getShips();
- // We run through all the ships and check for newly-destroyed ships, adding them to the revival list
- for (ShipAPI ship : ships) {
- if (ship == null) {
- continue;
- }
- if (ship.isHulk() == true) {
- if (deadShips.contains(ship) == false && ship.getVariant().getHullMods().contains("BGENecroMorphosis")) {
- deadShips.add(ship);
- revivalList.add(new ShipRequestData(ship));
- }
- }
- }
- for (ShipRequestData shipData : revivalList) {
- if (shipData.isRevived || shipData.chargeCounter != 0) {
- myRandom.setSeed(System.currentTimeMillis()); //generate new seed
- float chance = myRandom.nextFloat(); //get the next float chance
- if (chance <= REVIVE_CHANCE) { //if the float chance is less than our revival chance, revive them
- shipData.isRevived = true;
- ShipAPI reviveTarget = shipData.ship;
- int owner = reviveTarget.getOwner(); //debug stuff
- //int playerOwner = Global.getCombatEngine().getPlayerShip().getOwner(); //debug stuff
- ShipAPI randShip = engine.getShips().get(0);
- if (owner == 0 || owner == 100) {
- Vector2f loc = reviveTarget.getLocation();
- float facing = reviveTarget.getFacing();
- String variantID = shipData.ship.getVariant().getHullVariantId();
- //Safety code here
- //ShipHullSpecAPI shipHull = reviveTarget.getHullSpec();
- //String hullName = shipHull.getHullId();
- String shipName = reviveTarget.getVariant().getDesignation();//Get the ship name to prevent duplicates
- //shipName = shipName + ship.getVariant().getHullSpec().getHullName();
- //Give our fleet the captured ship.
- ShipAPI spawned = engine.getFleetManager(FleetSide.PLAYER).spawnShipOrWing(variantID, loc, facing);
- if (spawned == null) {
- return;
- }
- spawned.setCurrentCR(MathUtils.getRandomNumberInRange(0.25f, 0.5f));
- //This code just moves the captured enemy ship a long way off the map and blows it up.
- //We ~must~ blow it up; using remove() results in an un-winnable battle state, because it doesn't count as "dead".
- loc.x += 100000f;
- loc.y += 100000f;
- engine.spawnEmpArc(randShip, loc, reviveTarget, reviveTarget,
- DamageType.ENERGY,
- 10000000000f,
- 0f, // emp
- 10000000f, // max range
- "tachyon_lance_emp_impact",
- 30f, // thickness
- new Color(255, 100, 0, 255),
- new Color(255, 200, 0, 255)
- );
- //Here we're checking to make sure we're in a Campaign mission context; if not, halt!
- if (Global.getSector().getPlayerFleet() != null) {
- //If in campaign, we need to keep the ship we've captured after the battle, because ships spawned during the battle aren't...
- //...being carried over to the cargo at the end of the battle.
- //This also means that if the player loses the captured ship during the battle, they'll keep it anyway.
- //Fixing that would probably require some list of captured ships and a post-battle state check...
- //...or a cyclic script that would remove them if they become Hulks during the battle.
- //For now, this suffices, even if it's not totally polished.
- FleetDataAPI fleet = Global.getSector().getPlayerFleet().getFleetData();
- if (fleet != null) {
- //boolean isPlayerShip = false;
- boolean foundClone = false;
- List<FleetMemberAPI> members = fleet.getMembersListCopy();
- for (FleetMemberAPI thisMember : members) {
- String thisMemberName = thisMember.getShipName();
- if (thisMemberName == null) {
- continue;
- }
- if (shipName == null) {
- continue;
- }
- if (thisMemberName.contains(shipName)) {
- foundClone = true;
- //Sets the name back to the same name
- thisMember.setShipName(shipName);
- }
- }
- if (foundClone == false) {
- FleetMemberAPI newShip = Global.getFactory().createFleetMember(FleetMemberType.SHIP, variantID);
- fleet.addFleetMember(newShip);
- newShip.getVariant().setVariantDisplayName(shipName);
- }
- }
- }
- } else {
- Vector2f loc = reviveTarget.getLocation();
- float facing = reviveTarget.getFacing();
- String variantID; //Safety code here
- //ShipHullSpecAPI shipHull = reviveTarget.getHullSpec();
- //String hullName = shipHull.getHullId();
- variantID = shipData.ship.getVariant().getHullVariantId();
- //Give the enemy fleet the captured ship.
- engine.getFleetManager(FleetSide.ENEMY).spawnShipOrWing(variantID, loc, facing);
- //This code just moves the captured enemy ship a long way off the map and blows it up.
- //We ~must~ blow it up; using remove() results in an un-winnable battle state, because it doesn't count as "dead".
- loc.x += 100000f;
- loc.y += 100000f;
- engine.spawnEmpArc(randShip, loc, reviveTarget, reviveTarget,
- DamageType.ENERGY,
- 10000000000f,
- 0f, // emp
- 100000f, // max range
- "tachyon_lance_emp_impact",
- 30f, // thickness
- new Color(255, 100, 0, 255),
- new Color(255, 200, 0, 255)
- );
- }
- //it.remove();
- tracker.getIntervalDuration();
- } //IF REVIVAL CHANCE MORE THAN 0.9f
- else {
- shipData.chargeCounter--;
- } //ELSE
- } //IF NOT REVIVED
- }
- }
- }
- @Override
- public void init(CombatEngineAPI engine) {
- }
- private static class ShipRequestData {
- public ShipAPI ship;
- public boolean isRevived = false;
- public int chargeCounter = 4;
- private ShipRequestData(ShipAPI reviveTarget) {
- this.ship = reviveTarget;
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement