What I'm trying to get done: make a Hull Mod that won't allow other, similar Hull Mods to be stacked with it.
Basically, this code doesn't work at all:
@Override
public boolean isApplicableToShip(ShipAPI ship) {
return (
ship.getMutableStats().getBallisticWeaponRangeBonus().isUnmodified()
&& ship.getMutableStats().getEnergyWeaponRangeBonus().isUnmodified()
);
}
It always returns false, in a Mission. I've triple-checked that nothing else modifies the ShipAPI MutableStats on my end.
So, I tried this instead:
@Override
public boolean isApplicableToShip(ShipAPI ship) {
return (
ship.getMutableStats().getBallisticWeaponRangeBonus().getBonusMult() <= 1.25f
&& ship.getMutableStats().getEnergyWeaponRangeBonus().getBonusMult() <= 1.25f
);
}
This "works", in the sense that another Hull Mod with identical code returns false when this one's active, but with pretty obvious problems.
So, why is .isUnmodified() returning false all the time? That's a mystery; I don't have a way that I can dig that up.
However, the other problem with the second code sample is that, while it works, it
doesn't work if:
@Override
public void applyEffectsAfterShipCreation(ShipAPI ship, String id) {
MutableShipStatsAPI myStats = ship.getMutableStats();
myStats.getBallisticWeaponRangeBonus().modifyMult(id, 1.5f);
}
Now, this code's supposed to only apply after ship creation (says it right there on the tin). So I'm really confused about why it's happening at all; the ShipAPI should have a flag saying it's been created and then this code should run, correct? When we're applying Hull Mods in the Refit screen, when we exit that part of the UI, the ShipAPI should get destroyed and rebuilt every time a Hull Mod's been installed or removed, to avoid this logic problem, I'd think. So, yeah, confused; using applyEffectsBeforeShipCreation() doesn't work, either. I can't seem to get a practical filter working here.