Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adding shunt and modulation config settings #4

Open
wants to merge 6 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions Data/Scripts/DefenseShields/API/TapiBackend.cs
Original file line number Diff line number Diff line change
Expand Up @@ -376,8 +376,8 @@ private static MyTuple<bool, int, int, float, float, float> TAPI_GetFaceInfoAndP

var hitShuntedSide = shuntedFaceHit != -1;
var shuntedFaces = Math.Abs(logic.ShieldRedirectState.X) + Math.Abs(logic.ShieldRedirectState.Y) + Math.Abs(logic.ShieldRedirectState.Z);
var shuntMod = !hitShuntedSide ? 1 - (shuntedFaces * Session.ShieldShuntBonus) : logic.DsSet.Settings.AutoManage ? 1 - Session.ShieldShuntBonus : 1f;
var preventBypassMod = MathHelper.Clamp(shuntedFaces * Session.ShieldBypassBonus, 0f, 1f);
var shuntMod = !hitShuntedSide ? 1 - (shuntedFaces * Session.Enforced.ShuntBonusResistance) : logic.DsSet.Settings.AutoManage ? 1 - Session.Enforced.ShuntBonusResistance : 1f;
var preventBypassMod = MathHelper.Clamp(shuntedFaces * Session.Enforced.ShuntPenResistance, 0f, 1f);

var reinforcedPercent = hitShuntedSide ? logic.DsState.State.ShieldPercent + (shuntedFaces * 8) : logic.DsState.State.ShieldPercent;
var heatedEnforcedPercent = reinforcedPercent / (1 + (logic.DsState.State.Heat * 0.005));
Expand Down Expand Up @@ -408,7 +408,7 @@ private static MyTuple<bool, int, int, float, float, float> TAPI_GetFaceInfoAndP
penChance = (float)((a * Math.Pow(x, 2)) + (b * x) + c);
}

return new MyTuple<bool, int, int, float, float, float>(false, 0, 0, logic.DsSet.Settings.AutoManage ? 1 - Session.ShieldShuntBonus : 1f, 0, penChance);
return new MyTuple<bool, int, int, float, float, float>(false, 0, 0, logic.DsSet.Settings.AutoManage ? 1 - Session.Enforced.ShuntBonusResistance : 1f, 0, penChance);
}

private static float? TAPI_PointAttackShieldCon(IMyTerminalBlock block, Vector3D pos, long attackerId, float damage, float secondaryDamage, bool energy, bool drawParticle, bool posMustBeInside = false) //inlined for performance
Expand Down
3 changes: 3 additions & 0 deletions Data/Scripts/DefenseShields/Config/SerializedValues.cs
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,9 @@ public class DefenseShieldsEnforcement
[ProtoMember(23), DefaultValue(-1)] public float MinHP = -1f;
[ProtoMember(24), DefaultValue(-1)] public float MaxRecharge = -1f;
[ProtoMember(25), DefaultValue(-1)] public float MinRecharge = -1f;
[ProtoMember(26), DefaultValue(-1)] public float ShuntBonusResistance = -1f;
[ProtoMember(27), DefaultValue(-1)] public float ShuntPenResistance = -1f;
[ProtoMember(28), DefaultValue(-1)] public float MaxModulation = -1f;
}

[ProtoContract]
Expand Down
2 changes: 1 addition & 1 deletion Data/Scripts/DefenseShields/Control/ModUi.cs
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ internal static float GetDamage(IMyTerminalBlock block)
internal static void SetDamage(IMyTerminalBlock block, float newValue)
{
var comp = block?.GameLogic?.GetAs<Modulators>();
if (comp == null || newValue > 200 || newValue < -200) return;
if (comp == null || newValue > Session.Enforced.MaxModulation || newValue < -Session.Enforced.MaxModulation) return;

if (Session.Instance.IsServer)
ComputeDamage(comp, newValue);
Expand Down
20 changes: 18 additions & 2 deletions Data/Scripts/DefenseShields/SupportClasses/StaticUtils.cs
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ public static void PrepConfigFile()
const int DisableEntityBarrier = 0;
const int Debug = 1;
const int SuperWeapons = 1;
const int Version = 92;
const int Version = 93;
const float BlockScaler = 1f;
const float PowerScaler = 1f;
const float SizeScaler = 7.5f;
Expand All @@ -46,6 +46,9 @@ public static void PrepConfigFile()
const float MinHP = 0f;
const float MaxRecharge = float.MaxValue;
const float MinRecharge = 0f;
const float ShuntBonusResistance = 0.16f;
const float ShuntPenResistance = 0.2f;
const float MaxModulation = 200f;

var dsCfgExists = MyAPIGateway.Utilities.FileExistsInGlobalStorage("DefenseShields.cfg");
if (dsCfgExists)
Expand Down Expand Up @@ -92,6 +95,16 @@ public static void PrepConfigFile()
Session.Enforced.MinHP = !unPackedData.MinHP.Equals(-1) ? unPackedData.MinHP : MinHP;
Session.Enforced.MaxRecharge = !unPackedData.MaxRecharge.Equals(-1) ? unPackedData.MaxRecharge : MaxRecharge;
Session.Enforced.MinRecharge = !unPackedData.MinRecharge.Equals(-1) ? unPackedData.MinRecharge : MinRecharge;
Session.Enforced.ShuntBonusResistance = !unPackedData.ShuntBonusResistance.Equals(-1f) ? unPackedData.ShuntBonusResistance : ShuntBonusResistance;
Session.Enforced.ShuntPenResistance = !unPackedData.ShuntPenResistance.Equals(-1f) ? unPackedData.ShuntPenResistance : ShuntPenResistance;
Session.Enforced.MaxModulation = !unPackedData.MaxModulation.Equals(-1f) ? unPackedData.MaxModulation : MaxModulation;

if (unPackedData.Version < 93)
{
Session.Enforced.ShuntBonusResistance = ShuntBonusResistance;
Session.Enforced.ShuntPenResistance = ShuntPenResistance;
Session.Enforced.MaxModulation = MaxModulation;
}

if (unPackedData.Version < 92)
{
Expand Down Expand Up @@ -154,7 +167,10 @@ public static void PrepConfigFile()
Session.Enforced.MinHP = MinHP;
Session.Enforced.MaxRecharge = MaxRecharge;
Session.Enforced.MinRecharge = MinRecharge;

Session.Enforced.ShuntBonusResistance = ShuntBonusResistance;
Session.Enforced.ShuntPenResistance = ShuntPenResistance;
Session.Enforced.MaxModulation = MaxModulation;

WriteNewConfigFile();

Log.Line($"wrote new config file - file exists: {MyAPIGateway.Utilities.FileExistsInGlobalStorage("DefenseShields.cfg")}");
Expand Down