public static void Postfix(MechDef mechDef, ref Dictionary <MechValidationType, List <Text> > errorMessages)
 {
     try
     {
         ArmorStructureRatioFeature.ValidateMechArmorStructureRatio(mechDef, errorMessages);
     }
     catch (Exception e)
     {
         Control.Logger.Error.Log(e);
     }
 }
Exemplo n.º 2
0
 public static void Postfix(MechDef mechDef)
 {
     try
     {
         ArmorStructureRatioFeature.ValidateMechArmorStructureRatio(mechDef);
     }
     catch (Exception e)
     {
         Control.Logger.Error.Log(e);
     }
 }
Exemplo n.º 3
0
    internal static void OnArmorAddOrSubtract(MechLabLocationWidget widget, bool isRearArmor, float direction)
    {
        var stepPrecision = ArmorMaximizerFeature.Shared.Settings.StepPrecision.Get() ?? ArmorStructureRatioFeature.ArmorPerStep;
        var stepSize      = ArmorMaximizerFeature.Shared.Settings.StepSize.Get() ?? ArmorStructureRatioFeature.ArmorPerStep;

        var stepDirection = direction < 0 ? -1 : 1;
        var current       = isRearArmor ? widget.currentRearArmor : widget.currentArmor;

        var updated = stepDirection > 0
            ? PrecisionUtils.RoundUp(current + stepSize, stepPrecision)
            : PrecisionUtils.RoundDown(current - stepSize, stepPrecision);

        Control.Logger.Trace?.Log($"HandleArmorUpdate stepDirection={stepDirection} current={current} precision={stepPrecision} isRearArmor={isRearArmor}");
        if (stepDirection > 0)
        {
            var max = isRearArmor ? widget.maxRearArmor : widget.maxArmor;
            updated = Mathf.Min(updated, max);

            var maxTotal     = ArmorStructureRatioFeature.GetMaximumArmorPoints(widget.chassisLocationDef);
            var maxOther     = maxTotal - updated;
            var currentOther = isRearArmor ? widget.currentArmor : widget.currentRearArmor;
            var updatedOther = Mathf.Min(currentOther, maxOther);

            var otherNotChanged = PrecisionUtils.Equals(currentOther, updatedOther);
            if (otherNotChanged || !ArmorLocationLocker.IsLocked(widget.loadout.Location, !isRearArmor))
            {
                widget.SetArmor(isRearArmor, updated);
                widget.SetArmor(!isRearArmor, updatedOther);
            }

            Control.Logger.Trace?.Log($"HandleArmorUpdate updated={updated} maxTotal={maxTotal} maxOther={maxOther} currentOther={currentOther} updatedOther={updatedOther} isRearArmor={updatedOther}");
        }
        else
        {
            updated = Mathf.Max(updated, 0);
            widget.SetArmor(isRearArmor, updated);
            Control.Logger.Trace?.Log($"HandleArmorUpdate updated={updated}");
        }
    }