Example #1
0
 private string GetPredefinedPrefabName(BaseComponentRef componentRef)
 {
     if (componentRef.Def.PrefabIdentifier.StartsWith("chrPrfWeap", true, CultureInfo.InvariantCulture) ||
         componentRef.Def.PrefabIdentifier.StartsWith("chrPrfComp", true, CultureInfo.InvariantCulture))
     {
         return(componentRef.Def.PrefabIdentifier);
     }
     return(null);
 }
 private static void RefreshDef(BaseComponentRef target)
 {
     if (target.Def == null)
     {
         if (target.DataManager == null)
         {
             target.DataManager = UnityGameInstance.BattleTechGame.DataManager;
         }
         target.RefreshComponentDef();
     }
 }
 public static void Postfix(BaseComponentRef componentRef, ref string __result)
 {
     try
     {
         Control.Logger.Trace?.Log($"GetComponentPrefabName prefabName={__result} ComponentDefID={componentRef.ComponentDefID} PrefabIdentifier={componentRef.Def.PrefabIdentifier}");
     }
     catch (Exception e)
     {
         Control.Logger.Error.Log(e);
     }
 }
Example #4
0
 public static void SetFixed(BaseComponentRef __instance)
 {
     if (__instance.Def == null)
     {
         return;
     }
     if (__instance.Def.IsDefault())
     {
         var trav = Traverse.Create(__instance).Property <bool>("IsFixed");
         trav.Value = true;
     }
 }
Example #5
0
 public static void Postfix(BaseComponentRef componentRef, ref string __result)
 {
     try
     {
         if (HardpointFixFeature.Shared.Settings.TraceLogDebugMappings || (componentRef.ComponentDefType == ComponentType.Weapon && string.IsNullOrEmpty(__result)))
         {
             Control.mod.Logger.LogDebug($"GetComponentPrefabName prefabName={__result} ComponentDefID={componentRef.ComponentDefID} PrefabIdentifier={componentRef.Def.PrefabIdentifier}");
         }
     }
     catch (Exception e)
     {
         Control.mod.Logger.LogError(e);
     }
 }
        public static bool IsDefault(this BaseComponentRef item)
        {
            if (item?.Def == null)
            {
                return(false);
            }
            var f = item.Flags <CCFlags>();

            if (f == null)
            {
                return(false);
            }
            return(f.Default);
        }
 public static bool Prefix(BaseComponentRef componentRef, ref string?__result)
 {
     try
     {
         if (CalculatorSetup.SharedCalculator != null)
         {
             __result = CalculatorSetup.SharedCalculator.GetPrefabName(componentRef);
             return(false);
         }
     }
     catch (Exception e)
     {
         Control.Logger.Error.Log(e);
     }
     return(true);
 }
Example #8
0
 public static bool Prefix(BaseComponentRef componentRef, ref string __result)
 {
     try
     {
         if (calculator != null)
         {
             __result = calculator.GetPrefabName(componentRef);
             return(false);
         }
     }
     catch (Exception e)
     {
         Control.mod.Logger.LogError(e);
     }
     return(true);
 }
Example #9
0
 public static bool Prefix(HardpointDataDef hardpointDataDef, BaseComponentRef componentRef, ref List <string> usedPrefabNames, ref string __result)
 {
     try
     {
         if (calculator != null && componentRef is MechComponentRef mechComponentRef && mechComponentRef.ComponentDefType == ComponentType.Weapon)
         {
             __result = calculator.GetPrefabName(mechComponentRef) ?? hardpointDataDef.HardpointData[0].weapons[0][0];
             usedPrefabNames.Add(__result);
             return(false);
         }
     }
     catch (Exception e)
     {
         Control.mod.Logger.LogError(e);
     }
     return(true);
 }
        // ReSharper disable once RedundantAssignment
        public static bool Prefix(HardpointDataDef hardpointDataDef, BaseComponentRef componentRef, string prefabBase, string location, ref List <string> usedPrefabNames, ref string __result)
        {
            try
            {
                if (componentRef is MechComponentRef mechComponentRef && mechComponentRef.ComponentDefType == ComponentType.Weapon)
                {
                    __result = calculator?.GetPrefabName(mechComponentRef);
                }

                return(__result == null);
            }
            catch (Exception e)
            {
                Control.mod.Logger.LogError(e);
                return(true);
            }
        }
 public static void SetFixed(BaseComponentRef __instance)
 {
     try
     {
         if (__instance.Def == null)
         {
             return;
         }
         if (__instance.Def.Flags <CCFlags>().NoRemove)
         {
             var trav = Traverse.Create(__instance).Property <bool>("IsFixed");
             trav.Value = true;
         }
     }
     catch (Exception e)
     {
         Control.LogError($"Error in {__instance?.ComponentDefID} refreshing, check item", e);
     }
 }
Example #12
0
        internal string GetPrefabName(BaseComponentRef componentRef)
        {
            var pre = GetPredefinedPrefabName(componentRef);

            if (pre != null)
            {
                return(pre);
            }
            if (componentRef is MechComponentRef mechComponentRef)
            {
                if (weaponMappings.TryGetValue(mechComponentRef, out var prefabName))
                {
                    return(prefabName);
                }
                if (HardpointFixFeature.Shared.Settings.FallbackPrefabsForComponentDefIds.Contains(componentRef.ComponentDefID))
                {
                    return(GetFallbackPrefabIdentifier(mechComponentRef));
                }
            }
            return(null);
        }
 public static T Flags <T>(this BaseComponentRef item)
     where T : class, new()
 {
     return(FlagsController <T> .Shared[item?.Def]);
 }
Example #14
0
 public static bool IsCategory(this BaseComponentRef cref, string category)
 {
     return(cref.GetComponents <Category>().Any(c => c.CategoryID == category));
 }
Example #15
0
 public static bool IsCategory(this BaseComponentRef cref, string categoryid, out Category category)
 {
     category = cref.GetComponents <Category>().FirstOrDefault(c => c.CategoryID == categoryid);
     return(category != null);
 }
 public static bool Is <T>(this BaseComponentRef target)
 {
     RefreshDef(target);
     return(target.Def.Is <T>());
 }
 public static IEnumerable <T> GetComponents <T>(this BaseComponentRef target)
 {
     RefreshDef(target);
     return(target.Def.GetComponents <T>());
 }
 public static T GetComponent <T>(this BaseComponentRef target)
 {
     RefreshDef(target);
     return(target.Def.GetComponent <T>());
 }
 internal static MechComponentDef Def(this BaseComponentRef @this)
 {
     mechComponentRef = @this as MechComponentRef;
     return(@this.Def);
 }
 internal static string ComponentDefID(this BaseComponentRef @this)
 {
     mechComponentRef = @this as MechComponentRef;
     return(@this.ComponentDefID);
 }
Example #21
0
 public static bool IsDefault(this BaseComponentRef cref)
 {
     return(cref.Is <Flags>(out var f) && f.Default);
 }
Example #22
0
 internal static ComponentType GetComponentDefType(BaseComponentRef @this)
 {
     return(@this.ComponentDefType == ComponentType.Weapon ? ComponentType.NotSet : @this.ComponentDefType);
 }
Example #23
0
 public static Category GetCategory(this BaseComponentRef item, string categoryid)
 {
     return(item.GetComponents <Category>()?.FirstOrDefault(i => i.CategoryID == categoryid));
 }