Fractal Softworks Forum

Please login or register.

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

Author Topic: Can't Check MutableStat Properly in BaseHullMod.isApplicableToShip()  (Read 4053 times)

xenoargh

  • Admiral
  • *****
  • Posts: 5078
  • naively breaking things!
    • View Profile
Re: Can't Check MutableStat Properly in BaseHullMod.isApplicableToShip()
« Reply #15 on: February 11, 2019, 05:04:49 PM »

...with Gunnery Implants workaround:

Code
package data.hullmods;

import com.fs.starfarer.api.combat.BaseHullMod;
import com.fs.starfarer.api.combat.MutableShipStatsAPI;
import com.fs.starfarer.api.combat.MutableStat;
import com.fs.starfarer.api.combat.ShipAPI;
import com.fs.starfarer.api.combat.ShipAPI.HullSize;
import com.fs.starfarer.api.loading.HullModSpecAPI;
import java.util.HashMap;
import java.util.Map;

public class AdvancedTargetingCore extends BaseHullMod {

private static final Map<HullSize,Float> MAG = new HashMap();

private String myID = ":";

static {
MAG.put(HullSize.FIGHTER, -20f);
MAG.put(HullSize.FRIGATE, -20f);
MAG.put(HullSize.DESTROYER, -15f);
MAG.put(HullSize.CRUISER, -10f);
MAG.put(HullSize.CAPITAL_SHIP, -5f);
}

@Override
public void init(HullModSpecAPI spec) {
myID = spec.getId();
}

@Override
public boolean isApplicableToShip(ShipAPI ship) {
//MULT BONUSES
HashMap<String, MutableStat.StatMod> multMods = ship.getMutableStats().getBallisticWeaponRangeBonus().getMultBonuses();
for(MutableStat.StatMod modifier : multMods.values()){
String modName = modifier.getSource();
float modValue = modifier.getValue();
if(!modName.equalsIgnoreCase("gunnery_implants") && !modName.equalsIgnoreCase(myID) && modValue > 1.0f){
return false;
}
}
multMods = ship.getMutableStats().getEnergyWeaponRangeBonus().getMultBonuses();
for(MutableStat.StatMod modifier : multMods.values()){
String modName = modifier.getSource();
float modValue = modifier.getValue();
if(!modName.equalsIgnoreCase("gunnery_implants") && !modName.equalsIgnoreCase(myID) && modValue > 1.0f){
return false;
}
}
//FLAT BONUSES
multMods = ship.getMutableStats().getBallisticWeaponRangeBonus().getFlatBonuses();
for(MutableStat.StatMod modifier : multMods.values()){
String modName = modifier.getSource();
float modValue = modifier.getValue();
if(!modName.equalsIgnoreCase("gunnery_implants") && !modName.equalsIgnoreCase(myID) && modValue > 0f){
return false;
}
}
multMods = ship.getMutableStats().getEnergyWeaponRangeBonus().getFlatBonuses();
for(MutableStat.StatMod modifier : multMods.values()){
String modName = modifier.getSource();
float modValue = modifier.getValue();
if(!modName.equalsIgnoreCase("gunnery_implants") && !modName.equalsIgnoreCase(myID) && modValue > 0f){
return false;
}
}
//PERCENT BONUSES
multMods = ship.getMutableStats().getBallisticWeaponRangeBonus().getPercentBonuses();
for(MutableStat.StatMod modifier : multMods.values()){
String modName = modifier.getSource();
float modValue = modifier.getValue();
if(!modName.equalsIgnoreCase("gunnery_implants") && !modName.equalsIgnoreCase(myID) && modValue > 0f){
return false;
}
}
multMods = ship.getMutableStats().getEnergyWeaponRangeBonus().getPercentBonuses();
for(MutableStat.StatMod modifier : multMods.values()){
String modName = modifier.getSource();
float modValue = modifier.getValue();
if(!modName.equalsIgnoreCase("gunnery_implants") && !modName.equalsIgnoreCase(myID) && modValue > 0f){
return false;
}
}

//WeaponRangeMultPastThreshold checks
multMods = ship.getMutableStats().getWeaponRangeMultPastThreshold().getMultMods();
for(MutableStat.StatMod modifier : multMods.values()){
String modName = modifier.getSource();
float modValue = modifier.getValue();
if(!modName.equalsIgnoreCase("gunnery_implants") && !modName.equalsIgnoreCase(myID) && modValue > 1.0f){
return false;
}
}
multMods = ship.getMutableStats().getWeaponRangeMultPastThreshold().getFlatMods();
for(MutableStat.StatMod modifier : multMods.values()){
String modName = modifier.getSource();
float modValue = modifier.getValue();
if(!modName.equalsIgnoreCase("gunnery_implants") && !modName.equalsIgnoreCase(myID) && modValue > 0f){
return false;
}
}
multMods = ship.getMutableStats().getWeaponRangeMultPastThreshold().getPercentMods();
for(MutableStat.StatMod modifier : multMods.values()){
String modName = modifier.getSource();
float modValue = modifier.getValue();
if(!modName.equalsIgnoreCase("gunnery_implants") && !modName.equalsIgnoreCase(myID) && modValue > 0f){
return false;
}
}
return true;
}

@Override
public String getUnapplicableReason(ShipAPI ship) {
return "Incompatible with other Hull Mods that increase ranges.";
}

public static float RANGE_BONUS = 115f;
public static float PD_MINUS = 20f;

@Override
public String getDescriptionParam(int index, HullSize hullSize) {
if (index == 0) return "" + (int)Math.round(RANGE_BONUS) + "%";
if (index == 1) return "" + (100 - (int)Math.round(PD_MINUS)) + "%";
if (index == 2) return "" + Math.round(MAG.get(hullSize)) + " su/sec.";
return null;
}


  @Override
public void applyEffectsAfterShipCreation(ShipAPI ship, String id) {
MutableShipStatsAPI myStats = ship.getMutableStats();
myStats.getBallisticWeaponRangeBonus().modifyMult(id, 1f + (RANGE_BONUS * 0.01f));
myStats.getEnergyWeaponRangeBonus().modifyMult(id, 1f + (RANGE_BONUS * 0.01f));
myStats.getNonBeamPDWeaponRangeBonus().modifyMult(id, 1f - (PD_MINUS * 0.01f));
myStats.getBeamPDWeaponRangeBonus().modifyMult(id, 1f - (PD_MINUS * 0.01f));
myStats.getMaxSpeed().modifyFlat(id, MAG.get(ship.getHullSize()));
}
}

Logged
Please check out my SS projects :)
Xeno's Mod Pack

xenoargh

  • Admiral
  • *****
  • Posts: 5078
  • naively breaking things!
    • View Profile
Re: Can't Check MutableStat Properly in BaseHullMod.isApplicableToShip()
« Reply #16 on: February 11, 2019, 05:15:39 PM »

Oops, nope.  What's the id for that?  "gunnery_implants" doesn't work, neither does "GunneryImplants$Level3".

Logged
Please check out my SS projects :)
Xeno's Mod Pack

xenoargh

  • Admiral
  • *****
  • Posts: 5078
  • naively breaking things!
    • View Profile
Re: Can't Check MutableStat Properly in BaseHullMod.isApplicableToShip()
« Reply #17 on: February 11, 2019, 05:39:05 PM »

Ah, it's "gunnery_implants_ship_2".  Whew.
Logged
Please check out my SS projects :)
Xeno's Mod Pack

xenoargh

  • Admiral
  • *****
  • Posts: 5078
  • naively breaking things!
    • View Profile
Re: Can't Check MutableStat Properly in BaseHullMod.isApplicableToShip()
« Reply #18 on: February 11, 2019, 05:44:17 PM »

Okie doke, this is compatible with Gunnery Implants (presuming, of course, that that id never, ever changes).  

It's not possible to check to see whether buffs come from Skills per se; probably there's a way to do a workaround with Officers to get those ids without knowing what they are in advance, but tbh, I think I've solved enough medium-hard problems for one day.

Code
package data.hullmods;

import com.fs.starfarer.api.combat.BaseHullMod;
import com.fs.starfarer.api.combat.MutableShipStatsAPI;
import com.fs.starfarer.api.combat.MutableStat;
import com.fs.starfarer.api.combat.ShipAPI;
import com.fs.starfarer.api.combat.ShipAPI.HullSize;
import com.fs.starfarer.api.loading.HullModSpecAPI;
import java.util.HashMap;
import java.util.Map;

public class AdvancedTargetingCore extends BaseHullMod {

private static final Map<HullSize,Float> MAG = new HashMap();

private String myID = ":";

static {
MAG.put(HullSize.FIGHTER, -20f);
MAG.put(HullSize.FRIGATE, -20f);
MAG.put(HullSize.DESTROYER, -15f);
MAG.put(HullSize.CRUISER, -10f);
MAG.put(HullSize.CAPITAL_SHIP, -5f);
}

@Override
public void init(HullModSpecAPI spec) {
myID = spec.getId();
}

@Override
public boolean isApplicableToShip(ShipAPI ship) {
//MULT BONUSES
HashMap<String, MutableStat.StatMod> multMods = ship.getMutableStats().getBallisticWeaponRangeBonus().getMultBonuses();
for(MutableStat.StatMod modifier : multMods.values()){
String modName = modifier.getSource();
float modValue = modifier.getValue();
if(!modName.equalsIgnoreCase("gunnery_implants_ship_2") && !modName.equalsIgnoreCase(myID) && modValue > 1.0f){
return false;
}
}
multMods = ship.getMutableStats().getEnergyWeaponRangeBonus().getMultBonuses();
for(MutableStat.StatMod modifier : multMods.values()){
String modName = modifier.getSource();
float modValue = modifier.getValue();
if(!modName.equalsIgnoreCase("gunnery_implants_ship_2") && !modName.equalsIgnoreCase(myID) && modValue > 1.0f){
return false;
}
}
//FLAT BONUSES
multMods = ship.getMutableStats().getBallisticWeaponRangeBonus().getFlatBonuses();
for(MutableStat.StatMod modifier : multMods.values()){
String modName = modifier.getSource();
float modValue = modifier.getValue();
if(!modName.equalsIgnoreCase("gunnery_implants_ship_2") && !modName.equalsIgnoreCase(myID) && modValue > 0f){
return false;
}
}
multMods = ship.getMutableStats().getEnergyWeaponRangeBonus().getFlatBonuses();
for(MutableStat.StatMod modifier : multMods.values()){
String modName = modifier.getSource();
float modValue = modifier.getValue();
if(!modName.equalsIgnoreCase("gunnery_implants_ship_2") && !modName.equalsIgnoreCase(myID) && modValue > 0f){
return false;
}
}
//PERCENT BONUSES
multMods = ship.getMutableStats().getBallisticWeaponRangeBonus().getPercentBonuses();
for(MutableStat.StatMod modifier : multMods.values()){
String modName = modifier.getSource();
float modValue = modifier.getValue();
if(!modName.equalsIgnoreCase("gunnery_implants_ship_2") && !modName.equalsIgnoreCase(myID) && modValue > 0f){
return false;
}
}
multMods = ship.getMutableStats().getEnergyWeaponRangeBonus().getPercentBonuses();
for(MutableStat.StatMod modifier : multMods.values()){
String modName = modifier.getSource();
float modValue = modifier.getValue();
if(!modName.equalsIgnoreCase("gunnery_implants_ship_2") && !modName.equalsIgnoreCase(myID) && modValue > 0f){
return false;
}
}

//WeaponRangeMultPastThreshold checks
multMods = ship.getMutableStats().getWeaponRangeMultPastThreshold().getMultMods();
for(MutableStat.StatMod modifier : multMods.values()){
String modName = modifier.getSource();
float modValue = modifier.getValue();
if(!modName.equalsIgnoreCase("gunnery_implants_ship_2") && !modName.equalsIgnoreCase(myID) && modValue > 1.0f){
return false;
}
}
multMods = ship.getMutableStats().getWeaponRangeMultPastThreshold().getFlatMods();
for(MutableStat.StatMod modifier : multMods.values()){
String modName = modifier.getSource();
float modValue = modifier.getValue();
if(!modName.equalsIgnoreCase("gunnery_implants_ship_2") && !modName.equalsIgnoreCase(myID) && modValue > 0f){
return false;
}
}
multMods = ship.getMutableStats().getWeaponRangeMultPastThreshold().getPercentMods();
for(MutableStat.StatMod modifier : multMods.values()){
String modName = modifier.getSource();
float modValue = modifier.getValue();
if(!modName.equalsIgnoreCase("gunnery_implants_ship_2") && !modName.equalsIgnoreCase(myID) && modValue > 0f){
return false;
}
}
return true;
}

@Override
public String getUnapplicableReason(ShipAPI ship) {
return "Incompatible with other Hull Mods that increase ranges.";
}

public static float RANGE_BONUS = 115f;
public static float PD_MINUS = 20f;

@Override
public String getDescriptionParam(int index, HullSize hullSize) {
if (index == 0) return "" + (int)Math.round(RANGE_BONUS) + "%";
if (index == 1) return "" + (100 - (int)Math.round(PD_MINUS)) + "%";
if (index == 2) return "" + Math.round(MAG.get(hullSize)) + " su/sec.";
return null;
}


  @Override
public void applyEffectsAfterShipCreation(ShipAPI ship, String id) {
MutableShipStatsAPI myStats = ship.getMutableStats();
myStats.getBallisticWeaponRangeBonus().modifyMult(id, 1f + (RANGE_BONUS * 0.01f));
myStats.getEnergyWeaponRangeBonus().modifyMult(id, 1f + (RANGE_BONUS * 0.01f));
myStats.getNonBeamPDWeaponRangeBonus().modifyMult(id, 1f - (PD_MINUS * 0.01f));
myStats.getBeamPDWeaponRangeBonus().modifyMult(id, 1f - (PD_MINUS * 0.01f));
myStats.getMaxSpeed().modifyFlat(id, MAG.get(ship.getHullSize()));
}
}


For everybody joining the conversation at this point, the code above is an example of a Hull Mod that scans for changes to a MutableStat (i.e., a "buff") and won't allow itself to be installed if there's already something buffing that particular stat.  

It won't remove other Hull Mods or do anything "hostile", it just won't be able to be installed, and if it's installed and something else is installed that buffs that stat, it'll automatically get removed.

Obviously, it's not possible to use this approach with everything, but this does open up all sorts of ways to make Hull Mods "aware" of each other, in terms of buff/debuffs of stats.
« Last Edit: February 11, 2019, 05:51:51 PM by xenoargh »
Logged
Please check out my SS projects :)
Xeno's Mod Pack
Pages: 1 [2]