Example #1
0
        internal static void SetupCalculator(ChassisDef chassisDef, List <MechComponentRef> componentRefs)
        {
            if (chassisDef?.HardpointDataDef?.HardpointData == null)
            {
                return;
            }

            if (componentRefs == null || componentRefs.Count == 0)
            {
                return;
            }

            componentRefs = componentRefs
                            .Where(c => c != null)
                            .Where(c => c.ComponentDefType == ComponentType.Weapon)
                            .Where(c => c.Def is WeaponDef)
                            .ToList();

            if (componentRefs.Count == 0)
            {
                return;
            }

            try
            {
                calculator = new WeaponComponentPrefabCalculator(chassisDef, componentRefs);
            }
            catch (Exception e)
            {
                Control.mod.Logger.LogError(e);
            }
        }
        private int GetNotMappedPrefabNameCount(MechComponentRef newComponentRef)
        {
            var chassis  = _adapter.MechLab.activeMechDef.Chassis;
            var location = _adapter.Loadout.Location;

            var componentRefs = _adapter.LocalInventory
                                .Select(item => item.ComponentRef)
                                .Where(c => c.Def.ComponentType == ComponentType.Weapon)
                                .ToList();

            componentRefs.Add(newComponentRef);

            var calculator = new WeaponComponentPrefabCalculator(chassis, componentRefs, location);

            return(calculator.NotMappedPrefabNameCount);
        }
Example #3
0
        public static void Setup(ChassisDef chassisDef, List <MechComponentRef> componentRefs)
        {
            if (chassisDef?.HardpointDataDef?.HardpointData == null)
            {
                return;
            }

            if (componentRefs == null || componentRefs.Count == 0)
            {
                return;
            }

            componentRefs = componentRefs
                            .Where(c => c != null)
                            .Where(c => c.ComponentDefType == ComponentType.Weapon)
                            .Select(c =>
            {
                if (c.DataManager == null)
                {
                    c.DataManager = UnityGameInstance.BattleTechGame.DataManager;
                    c.RefreshComponentDef();
                }
                return(c);
            })
                            .Where(c => c.Def is WeaponDef)
                            .ToList();

            if (componentRefs.Count == 0)
            {
                return;
            }

            try
            {
                SharedCalculator = new WeaponComponentPrefabCalculator(chassisDef, componentRefs);
            }
            catch (Exception e)
            {
                Control.Logger.Error.Log(e);
            }
        }
Example #4
0
        internal static void HardpointDataDef_FromJSON(HardpointDataDef def)
        {
            if (!HardpointFixFeature.Shared.Settings.AutoFixHardpointDataDefs)
            {
                return;
            }

            // chrPrfWeap_battlemaster_leftarm_ac20_bh1 -> chrPrfWeap_battlemaster_leftarm_ac20_1
            string Unique(string prefab)
            {
                return(prefab.Substring(0, prefab.Length - 3) + WeaponComponentPrefabCalculator.GroupNumber(prefab));
            }

            string SelectSingle(IEnumerable <string> enumerable)
            {
                var list   = enumerable.ToList();
                var chosen = list[0];

                if (list.Count > 1)
                {
                    var duplicates = string.Join(",", list.OrderBy(x => x).Distinct());
                    Control.mod.Logger.LogWarning($"Removing duplicate hardpoint entries [{duplicates}], kept a single {chosen}");
                }
                return(chosen);
            }

            // normalize data, remove all duplicates in each location
            for (var i = 0; i < def.HardpointData.Length; i++)
            {
                def.HardpointData[i].weapons = def.HardpointData[i].weapons
                                               .SelectMany(x => x)
                                               .OrderBy(x => x)
                                               .GroupBy(x => Unique(x))
                                               .Select(x => SelectSingle(x))
                                               .GroupBy(x => WeaponComponentPrefabCalculator.GroupNumber(x))
                                               .OrderBy(x => x.Key)
                                               .Select(x => x.ToArray())
                                               .ToArray();
            }
        }
Example #5
0
 internal static void ResetCalculator()
 {
     calculator = null;
 }
Example #6
0
 public static void Reset()
 {
     SharedCalculator = null;
 }