internal void AdjustComponentDef(MechComponentDef def)
    {
        if (change == null)
        {
            return;
        }

        if (!identifier.IsCustomType(def))
        {
            return;
        }

        var newTonnage = change.Change(def.Tonnage);

        if (!newTonnage.HasValue)
        {
            return;
        }

        var value     = newTonnage.Value;
        var propInfo  = typeof(UpgradeDef).GetProperty("Tonnage");
        var propValue = Convert.ChangeType(value, propInfo.PropertyType);

        propInfo.SetValue(def, propValue, null);
    }
示例#2
0
    private static void ModifyInventorySlots(ref LocationDef locationDef, ChassisLocations location, ValueChange <int> change)
    {
        if (locationDef.Location != location)
        {
            return;
        }

        var newValue = change.Change(locationDef.InventorySlots);

        if (!newValue.HasValue)
        {
            return;
        }

        if (location == ChassisLocations.CenterTorso)
        {
            newValue += MechLabSlotsFeature.settings.TopLeftWidget.Slots +
                        MechLabSlotsFeature.settings.TopRightWidget.Slots;
        }

        var info  = typeof(LocationDef).GetField("InventorySlots");
        var value = Convert.ChangeType(newValue, info.FieldType);
        var box   = (object)locationDef;

        info.SetValue(box, value);
        locationDef = (LocationDef)box;

        Control.Logger.Debug?.Log($"set InventorySlots={locationDef.InventorySlots} on location={location}");
    }