public static void Prefix(MechLabPanel __instance)
    {
        try
        {
            var mechDef = __instance.CreateMechDef();

            var id   = $"{mechDef.Description.Name}_{mechDef.Description.Id}";
            var path = Path.Combine(Path.Combine(Control.Mod.Directory, "Saves"), $"{id}.json");
            Directory.CreateDirectory(Directory.GetParent(path).FullName);

            using (var writer = new StreamWriter(path))
            {
                var p = new JSONParameters
                {
                    EnableAnonymousTypes      = true,
                    SerializeToLowerCaseNames = false,
                    UseFastGuid             = false,
                    KVStyleStringDictionary = false,
                    SerializeNullValues     = false
                };

                var json = JSON.ToNiceJSON(mechDef, p);
                writer.Write(json);
            }
        }
        catch (Exception e)
        {
            Control.Logger.Error.Log(e);
        }
    }
            public static bool Prefix(MechLabMechInfoWidget __instance, MechLabPanel ___mechLab)
            {
                return(_harmonyManager.PrefixLogExceptions(() =>
                {
                    if (!_inCalculateTonnage)
                    {
                        try
                        {
                            _inCalculateTonnage = true;
                            _unusedHardpointMass = GetEmptyHardpointMass(___mechLab.CreateMechDef());
                            __instance.CalculateTonnage();
                        }
                        finally
                        {
                            _inCalculateTonnage = false;
                        }

                        return false;
                    }
                    else
                    {
                        return true;
                    }
                }));
            }
        internal static void Postfix(
            MechLabMechInfoWidget __instance,
            ref MechLabPanel ___mechLab,
            ref MechLabHardpointElement[] ___hardpoints)
        {
            try
            {
                var mechDef = ___mechLab.CreateMechDef();
                if (mechDef == null)
                {
                    return;
                }

                var inventory  = mechDef.Inventory.Select(x => x.Def);
                var hardpoints = MechDefBuilder.Locations.SelectMany(x => mechDef.Chassis.GetLocationDef(x).Hardpoints).ToArray();

                var calc = new HardpointOmniUsageCalculator(inventory, hardpoints);

                Control.Logger.Debug?.Log(calc);

                __instance.totalBallisticHardpoints = calc.Ballistic.TheoreticalMax;
                __instance.totalEnergyHardpoints    = calc.Energy.TheoreticalMax;
                __instance.totalMissileHardpoints   = calc.Missile.TheoreticalMax;
                __instance.totalSmallHardpoints     = calc.Small.TheoreticalMax;

                ___hardpoints[0].SetData(WeaponCategoryEnumeration.GetBallistic(), calc.Ballistic.HardpointTotalString);
                ___hardpoints[1].SetData(WeaponCategoryEnumeration.GetEnergy(), calc.Energy.HardpointTotalString);
                ___hardpoints[2].SetData(WeaponCategoryEnumeration.GetMissile(), calc.Missile.HardpointTotalString);
                ___hardpoints[3].SetData(WeaponCategoryEnumeration.GetSupport(), calc.Small.HardpointTotalString);
            }
            catch (Exception e)
            {
                Control.Logger.Error.Log(e);
            }
        }
    public static bool Prefix(
        MechLabPanel ___mechLab,
        ref float ___currentTonnage,
        TextMeshProUGUI ___totalTonnage,
        UIColorRefTracker ___totalTonnageColor,
        TextMeshProUGUI ___remainingTonnage,
        UIColorRefTracker ___remainingTonnageColor)
    {
        try
        {
            var mechDef = ___mechLab.CreateMechDef();
            if (mechDef == null)
            {
                return(false);
            }

            WeightsHandler.AdjustInfoWidget(
                mechDef,
                ___remainingTonnageColor,
                ___totalTonnageColor,
                ___totalTonnage,
                ___remainingTonnage,
                out ___currentTonnage
                );
            return(false);
        }
        catch (Exception e)
        {
            Control.Logger.Error.Log(e);
        }
        return(true);
    }
Пример #5
0
        public void AdjustSlotElement(MechLabItemSlotElement instance, MechLabPanel panel)
        {
            var def = instance.ComponentRef.GetComponent <CoolingDef>();

            if (def == null)
            {
                return;
            }

            var engine = panel.CreateMechDef()?.GetEngine();

            if (engine == null)
            {
                return;
            }

            instance.bonusTextB.text = BonusValueEngineHeatSinkCounts(engine);
        }
    public static void Postfix(
        MechLabPanel ___mechLab,
        LocalizableText ___remainingTonnage)
    {
        try
        {
            var mechDef = ___mechLab.CreateMechDef();
            if (mechDef == null)
            {
                return;
            }

            SetupCapacitiesLayout(mechDef, ___remainingTonnage);
        }
        catch (Exception e)
        {
            Control.Logger.Error.Log(e);
        }
    }
Пример #7
0
        internal static void SetJumpJetHardpointCount(MechLabMechInfoWidget widget, MechLabPanel mechLab, MechLabHardpointElement[] hardpoints)
        {
            if (hardpoints == null || hardpoints[4] == null)
            {
                return;
            }

            var mechDef = mechLab?.CreateMechDef();

            if (mechDef == null)
            {
                return;
            }

            var stats = new MechDefMovementStatistics(mechDef);

            widget.totalJumpjets = stats.JumpJetMaxCount;

            hardpoints[4].SetData(WeaponCategoryEnumeration.GetAMS(), $"{stats.JumpJetCount} / {stats.JumpJetMaxCount}");
        }
Пример #8
0
        public void AdjustSlotElement(MechLabItemSlotElement instance, MechLabPanel panel)
        {
            var def = instance.ComponentRef.GetComponent <EngineHeatBlockDef>();

            if (def == null)
            {
                return;
            }

            var mechDef = panel?.CreateMechDef();
            var engine  = mechDef?.GetEngine();

            if (engine == null)
            {
                return;
            }

            instance.bonusTextA.text = BonusValueEngineHeatDissipation(engine);
            instance.bonusTextB.text = BonusValueEngineHeatSinkCounts(engine);
        }