public void ValidateMech(MechDef mechDef, Errors errors)
        {
            var slots   = new MechDefSlots(mechDef);
            var missing = slots.Missing;

            if (missing > 0)
            {
                errors.Add(MechValidationType.InvalidInventorySlots, $"RESERVED SLOTS: Mech requires {missing} additional free slots");
            }
        }
Beispiel #2
0
        public void ValidateMech_old(MechDef mechDef, Dictionary <MechValidationType, List <string> > errorMessages)
        {
            var slots   = new MechDefSlots(mechDef);
            var missing = slots.Missing;

            if (missing > 0)
            {
                errorMessages[MechValidationType.InvalidInventorySlots]
                .Add($"RESERVED SLOTS: Mech requires {missing} additional free slots");
            }
        }
Beispiel #3
0
        public string PostValidateDrop(MechLabItemSlotElement drop_item, MechDef mech, List <InvItem> new_inventory,
                                       List <IChange> changes)
        {
            var slots   = new MechDefSlots(mech.Chassis, new_inventory.Select(x => x.item).ToList());
            var missing = slots.Missing;

            if (missing > 0)
            {
                return
                    ($"Cannot add {drop_item.ComponentRef.Def.Description.Name}: Mech requires {missing} additional free slots");
            }

            return(string.Empty);
        }
        internal MechDefBuilder(ChassisDef chassisDef, List <MechComponentRef> inventory)
        {
            Slots = new MechDefSlots(chassisDef, inventory);

            Inventory = inventory;

            //Control.mod.Logger.LogDebug("");
            //Control.mod.Logger.LogDebug($"chassisDef={chassisDef.Description.Id}");

            foreach (var group in inventory.GroupBy(r => r.MountedLocation))
            {
                var location = group.Key;
                var sum      = group.Sum(r => r.Def.InventorySize);
                LocationUsage[location] = sum;
                //Control.mod.Logger.LogDebug($"location={location} sum={sum}");
            }
        }
Beispiel #5
0
        private static readonly ChassisLocations[] Locations = MechDefSlots.Locations;       // order of locations to fill up first
        #endregion

        internal void RefreshData(MechLabPanel mechLab)
        {
            var fillerImageCache = MechLabLocationWidgetSetDataPatch.FillerImageCache;

            if (fillerImageCache.Count < Locations.Length)
            {
                return;
            }

            var slots = new MechDefSlots(mechLab.activeMechDef);

            using (var reservedSlots = slots.GetReservedSlots().GetEnumerator())
            {
                foreach (var location in Locations)
                {
                    var fillerImages = fillerImageCache[location];
                    var widget       = mechLab.GetLocationWidget((ArmorLocation)location); // by chance armorlocation = chassislocation for main locations
                    var adapter      = new MechLabLocationWidgetAdapter(widget);
                    var used         = adapter.usedSlots;
                    for (var i = 0; i < adapter.maxSlots; i++)
                    {
                        var fillerImage = fillerImages[i];
                        if (i >= used && reservedSlots.MoveNext())
                        {
                            var reservedSlot = reservedSlots.Current;
                            if (reservedSlot == null)
                            {
                                throw new NullReferenceException();
                            }
                            fillerImage.gameObject.SetActive(true);
                            var uicolor = reservedSlot.ReservedSlotColor;
                            var color   = LazySingletonBehavior <UIManager> .Instance.UIColorRefs.GetUIColor(uicolor);

                            fillerImage.color = slots.IsOverloaded ? DynamicSlotsSpaceMissingColor : color;
                        }
                        else
                        {
                            fillerImage.gameObject.SetActive(false);
                        }
                    }
                }
            }
        }
        private static readonly ChassisLocations[] Locations = MechDefSlots.Locations;       // order of locations to fill up first
        #endregion

        internal void RefreshData(MechLabPanel mechLab)
        {
            if (MechLabLocationWidget_SetData_Patch.Fillers.Count < Locations.Length)
            {
                return;
            }

            var slots = new MechDefSlots(mechLab.activeMechDef);

            using (var reservedSlots = slots.GetReservedSlots().GetEnumerator())
            {
                foreach (var location in Locations)
                {
                    var fillers = MechLabLocationWidget_SetData_Patch.Fillers[location];
                    var widget  = mechLab.GetLocationWidget((ArmorLocation)location); // by chance armorlocation = chassislocation for main locations
                    var adapter = new MechLabLocationWidgetAdapter(widget);
                    var used    = adapter.usedSlots;
                    for (var i = 0; i < adapter.maxSlots; i++)
                    {
                        var filler = fillers[i];
                        if (i >= used && reservedSlots.MoveNext())
                        {
                            var reservedSlot = reservedSlots.Current;
                            if (reservedSlot == null)
                            {
                                throw new NullReferenceException();
                            }
                            filler.Show(reservedSlot);
                        }
                        else
                        {
                            filler.Hide();
                        }
                    }
                }
            }
        }
Beispiel #7
0
        public bool ValidateMechCanBeFielded(MechDef mechDef)
        {
            var slots = new MechDefSlots(mechDef);

            return(slots.Missing <= 0);
        }