Пример #1
0
        public static void Prefix(MechLabInventoryWidget __instance, DataManager ___dataManager, IMechLabDraggableItem item)
        {
            try
            {
                var panel = __instance.ParentDropTarget as MechLabPanel;
                if (panel == null)
                {
                    return;
                }

                if (panel.baseWorkOrder == null)
                {
                    return;
                }

                if (!panel.IsSimGame)
                {
                    return;
                }

                if (item == null)
                {
                    return;
                }

                EnginePersistence.InventoryWidgetOnAddItem(__instance, panel, item);
            }
            catch (Exception e)
            {
                Control.mod.Logger.LogError(e);
            }
        }
Пример #2
0
 internal static void Postfix(MechLabPanel __instance, MechComponentRef componentRef, MechLabItemSlotElement __result)
 {
     try
     {
         RefreshSlotElementHandler.Shared.RefreshSlotElement(__result, __instance);
         EnginePersistence.FixSimGameUID(__instance.sim, componentRef);
     }
     catch (Exception e)
     {
         Control.mod.Logger.LogError(e);
     }
 }
Пример #3
0
 internal static void Postfix(this MechLabPanel __instance, MechComponentRef componentRef, MechLabItemSlotElement __result)
 {
     try
     {
         EngineCoreRefHandler.Shared.ModifySlotElement(__result, __instance);
         WeightSavingsHandler.Shared.ModifySlotElement(__result, __instance);
         EnginePersistence.FixSimGameUID(__instance.sim, componentRef);
     }
     catch (Exception e)
     {
         Control.mod.Logger.LogError(e);
     }
 }
        public static void Prefix(MechLabPanel __instance, MechComponentRef componentRef)
        {
            try
            {
                if (!__instance.IsSimGame)
                {
                    return;
                }

                EnginePersistence.FixSimGameUID(__instance.sim, componentRef);
            }
            catch (Exception e)
            {
                Control.mod.Logger.LogError(e);
            }
        }
 internal static void RemoveItemStat(this SimGameState sim, string id, Type type, bool damaged)
 {
     try
     {
         if (mechComponentRef != null)
         {
             EnginePersistence.RemoveInternalItemsStat(sim, mechComponentRef, id, type, damaged);
         }
         mechComponentRef = null;
     }
     catch (Exception e)
     {
         Control.mod.Logger.LogError(e);
     }
     sim.RemoveItemStat(id, type, damaged);
 }
Пример #6
0
        public static void Prefix(MechBayPanel __instance, MechDef selectedMech)
        {
            try
            {
                if (!__instance.IsSimGame)
                {
                    return;
                }

                EnginePersistence.FixSimGameUID(__instance.Sim, selectedMech);
            }
            catch (Exception e)
            {
                Control.mod.Logger.LogError(e);
            }
        }
        public static void Prefix(MechBayPanel __instance, MechBayMechUnitElement mechElement)
        {
            try
            {
                if (!__instance.IsSimGame)
                {
                    return;
                }

                if (mechElement == null || mechElement.MechDef == null)
                {
                    return;
                }

                EnginePersistence.FixSimGameUID(__instance.Sim, mechElement.MechDef);
            }
            catch (Exception e)
            {
                Control.mod.Logger.LogError(e);
            }
        }
Пример #8
0
        // only allow one engine part per specific location
        internal static MechLabLocationWidgetOnMechLabDropPatch.Result DropCheck(
            MechLabLocationWidget widget,
            MechLabPanel mechLab,
            MechLabItemSlotElement dragItem,
            List <MechLabItemSlotElement> localInventory)
        {
            if (widget.loadout.Location != ChassisLocations.CenterTorso)
            {
                return(null);
            }

            var newComponentRef = dragItem.ComponentRef;
            var newComponentDef = newComponentRef.Def;
            var headSinkDef     = newComponentDef as HeatSinkDef;

            if (headSinkDef == null)
            {
                return(null);
            }

            // check if we can work with it
            if (!headSinkDef.IsDHSKit() && !headSinkDef.IsSingle() && !headSinkDef.IsDouble())
            {
                return(null);
            }

            var engineSlotElement = localInventory
                                    .FirstOrDefault(x => x != null && x.ComponentRef != null && x.ComponentRef.Def != null && x.ComponentRef.Def.IsEngineCore());

            if (engineSlotElement == null)
            {
                if (headSinkDef.IsDHSKit())
                {
                    return(new MechLabLocationWidgetOnMechLabDropPatch.ErrorResult(
                               string.Format("Cannot add {0}: No Engine found", newComponentDef.Description.Name)
                               ));
                }
                else
                {
                    return(null);
                }
            }

            var engineRef = localInventory.Where(c => c != null).Select(c => c.ComponentRef).GetEngineCoreRef();

            if (mechLab.IsSimGame)
            {
                if (dragItem.OriginalDropParentType != MechLabDropTargetType.InventoryList)
                {
                    return(new MechLabLocationWidgetOnMechLabDropPatch.ErrorResult(
                               string.Format("Cannot add {0}: Item has to be from inventory", newComponentDef.Description.Name)
                               ));
                }

                if (mechLab.originalMechDef.Inventory.Any(c => c.SimGameUID == engineRef.ComponentRef.SimGameUID))
                {
                    return(new MechLabLocationWidgetOnMechLabDropPatch.ErrorResult(
                               string.Format("Cannot add {0}: Engine cannot be modified once installed, remove engine first", newComponentDef.Description.Name)
                               ));
                }
            }

            if (headSinkDef.IsDHSKit())
            {
                if (engineRef.IsDHS)
                {
                    return(new MechLabLocationWidgetOnMechLabDropPatch.ErrorResult(
                               string.Format("Cannot add {0}: Already a DHS engine", newComponentDef.Description.Name)
                               ));
                }

                if (!Control.settings.AllowMixingDoubleAndSingleHeatSinks && engineRef.AdditionalSHSCount > 0)
                {
                    return(new MechLabLocationWidgetOnMechLabDropPatch.ErrorResult(
                               string.Format("Cannot add {0}: Reinstall engine to remove additional heat sinks before converting", newComponentDef.Description.Name)
                               ));
                }

                engineRef.IsDHS = true;
            }
            else
            {
                int minHeatSinks, maxHeatSinks;
                Control.calc.CalcHeatSinks(engineRef.CoreDef, out minHeatSinks, out maxHeatSinks);

                if (engineRef.AdditionalHeatSinkCount >= maxHeatSinks - minHeatSinks)
                {
                    return(null);
                    //return new MechLabLocationWidgetOnMechLabDropPatch.ErrorResult(
                    //    string.Format("Cannot add {0}: Maximum additional heat sinks reached for engine", newComponentDef.Description.Name)
                    //);
                }

                if (!Control.settings.AllowMixingDoubleAndSingleHeatSinks)
                {
                    if (engineRef.IsDHS && headSinkDef.IsSingle() || engineRef.IsSHS && headSinkDef.IsDouble())
                    {
                        return(new MechLabLocationWidgetOnMechLabDropPatch.ErrorResult(
                                   string.Format("Cannot add {0}: Mixing DHS and SHS is not allowed", newComponentDef.Description.Name)
                                   ));
                    }
                }

                if (headSinkDef.IsDouble())
                {
                    engineRef.AdditionalDHSCount++;
                }
                else if (headSinkDef.IsSingle())
                {
                    engineRef.AdditionalSHSCount++;
                }
            }

            EnginePersistence.SaveEngineState(engineRef, mechLab);
            mechLab.ValidateLoadout(false);

            Traverse.Create(engineSlotElement).Method("RefreshInfo").GetValue();

            return(new MechLabLocationWidgetOnMechLabDropPatch.RemoveItemResult());
        }
Пример #9
0
        // only allow one engine part per specific location
        public MechLabDropResult ValidateDrop(MechLabItemSlotElement dragItem, MechLabLocationWidget widget)
        {
            var newComponentRef = dragItem.ComponentRef;
            var newComponentDef = newComponentRef.Def;

            var heatSinkDef    = newComponentDef.GetComponent <EngineHeatSink>();
            var heatSinkKitDef = newComponentDef.GetComponent <EngineHeatSinkKit>();

            // check if we can work with it
            if (heatSinkDef == null && heatSinkKitDef == null)
            {
                return(null);
            }

            var adapter        = new MechLabLocationWidgetAdapter(widget);
            var localInventory = adapter.localInventory;

            var engineSlotElement = localInventory.FirstOrDefault(x => x?.ComponentRef?.Def?.GetComponent <EngineCoreDef>() != null);

            if (engineSlotElement == null)
            {
                if (heatSinkKitDef != null)
                {
                    return(new MechLabDropErrorResult(
                               $"Cannot add {newComponentDef.Description.Name}: No Engine found"
                               ));
                }

                return(null);
            }

            var engineRef = engineSlotElement.ComponentRef.GetEngineCoreRef();
            var engineDef = engineRef.CoreDef;

            var mechLab = adapter.mechLab;

            if (mechLab.IsSimGame)
            {
                if (dragItem.OriginalDropParentType != MechLabDropTargetType.InventoryList)
                {
                    return(new MechLabDropErrorResult(
                               $"Cannot add {newComponentDef.Description.Name}: Item has to be from inventory"
                               ));
                }

                if (mechLab.originalMechDef.Inventory.Any(c => c.SimGameUID == engineRef.ComponentRef.SimGameUID))
                {
                    return(new MechLabDropErrorResult(
                               $"Cannot add {newComponentDef.Description.Name}: Engine cannot be modified once installed, remove engine first"
                               ));
                }
            }

            if (heatSinkKitDef != null)
            {
                if (engineRef.HeatSinkDef != newComponentDef.DataManager.GetDefaultEngineHeatSinkDef())
                {
                    return(new MechLabDropErrorResult(
                               $"Cannot add {newComponentDef.Description.Name}: Reinstall engine to remove internal heat sinks"
                               ));
                }

                if (engineRef.AdditionalHeatSinkCount > 0)
                {
                    return(new MechLabDropErrorResult(
                               $"Cannot add {newComponentDef.Description.Name}: Reinstall engine to remove additional heat sinks before converting"
                               ));
                }

                engineRef.HeatSinkDef = mechLab.dataManager.GetEngineHeatSinkDef(heatSinkKitDef.HeatSinkDefId);
            }
            else
            {
                if (engineRef.AdditionalHeatSinkCount >= engineDef.MaxAdditionalHeatSinks)
                {
                    return(null);
                }

                if (!Control.settings.AllowMixingHeatSinkTypes)
                {
                    if (engineRef.HeatSinkDef.HSCategory != heatSinkDef.HSCategory)
                    {
                        return(new MechLabDropErrorResult(
                                   $"Cannot add {newComponentDef.Description.Name}: Mixing heat sink types is not allowed"
                                   ));
                    }
                }

                engineRef.Query(heatSinkDef).AdditionalCount++;
            }

            EnginePersistence.SaveEngineState(engineRef, mechLab);
            mechLab.ValidateLoadout(false);

            EngineCoreRefHandler.Shared.ModifySlotElement(engineSlotElement);

            return(new MechLabDropRemoveDragItemResult());
        }