Exemplo n.º 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);
            }
        }
        internal static void RemoveItemStat(this SimGameState sim, string id, Type type, bool damaged)
        {
            if (mechComponentRef != null && !EnginePersistence.RemoveItemStat(sim, mechComponentRef, id, type, damaged))
            {
                return;
            }

            sim.RemoveItemStat(id, type, damaged);
        }
 internal static void OnAddItemStat(SimGameState sim, MechComponentRef componentRef)
 {
     EnginePersistence.OnAddItemStat(sim, componentRef);
 }
Exemplo n.º 4
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 existingEngine = localInventory
                                 .Where(x => x != null)
                                 .Select(x => x.ComponentRef)
                                 .FirstOrDefault(x => x != null && x.Def != null && x.Def.IsMainEngine());

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

            var engineRef = existingEngine.GetEngineRef();

            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(null);
                    //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.engineDef, 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);

            return(new MechLabLocationWidgetOnMechLabDropPatch.RemoveItemResult());
        }