protected override void Apply(AttributeLoader loader, object wrapperObj)
        {
            if (!(wrapperObj is PowerShuntAttributesWrapper wrapper))
            {
                throw new System.InvalidCastException();
            }

            loader.ApplyPPatch(PowerLevelChargeTimeSeconds, () => wrapper.PowerLevelChargeTimeSeconds, Fixed64.UnsafeFromDouble);
            loader.ApplyPMultPatch(PowerLevelChargeTimeSecondsMult, () => wrapper.PowerLevelChargeTimeSeconds);

            loader.ApplyPPatch(PowerLevelDrainTimeSeconds, () => wrapper.PowerLevelDrainTimeSeconds, Fixed64.UnsafeFromDouble);
            loader.ApplyPMultPatch(PowerLevelDrainTimeSecondsMult, () => wrapper.PowerLevelDrainTimeSeconds);

            loader.ApplyPPatch(HeatThreshold, () => wrapper.HeatThreshold);
            loader.ApplyPMultPatch(HeatThresholdMult, () => wrapper.HeatThreshold);

            loader.ApplyPPatch(CooldownRate, () => wrapper.CooldownRate);
            loader.ApplyPMultPatch(CooldownRateMult, () => wrapper.CooldownRate);

            loader.ApplyPPatch(OverheatDamage, () => wrapper.OverheatDamage);
            loader.ApplyPMultPatch(OverheatDamageMult, () => wrapper.OverheatDamage);

            loader.ApplyPPatch(NearOverheatWarningMargin, () => wrapper.NearOverheatWarningMargin);
            loader.ApplyPMultPatch(NearOverheatWarningMarginMult, () => wrapper.NearOverheatWarningMargin);

            loader.ApplyPPatch(OverheatReminderPeriod, () => wrapper.OverheatReminderPeriod);
            loader.ApplyPMultPatch(OverheatReminderPeriodMult, () => wrapper.OverheatReminderPeriod);

            {
                var l = wrapper.PowerSystems?.Select(x => new PowerSystemAttributesWrapper(x)).ToList() ?? new List <PowerSystemAttributesWrapper>();
                loader.ApplyLPatch(PowerSystems, l, () => new PowerSystemAttributesWrapper(), "PowerSystems");
                wrapper.PowerSystems = l.ToArray();
            }

            if (ReservePowerPool != null)
            {
                InventoryAttributesWrapper inventoryAttributesWrapper = new InventoryAttributesWrapper(wrapper.ReservePowerPool);
                ReservePowerPool.Apply(loader, inventoryAttributesWrapper, null);
                wrapper.ReservePowerPool = inventoryAttributesWrapper;
            }
            if (OverheatingPool != null)
            {
                InventoryAttributesWrapper inventoryAttributesWrapper = new InventoryAttributesWrapper(wrapper.OverheatingPool);
                OverheatingPool.Apply(loader, inventoryAttributesWrapper, null);
                wrapper.OverheatingPool = inventoryAttributesWrapper;
            }
            if (HeatSystem != null)
            {
                InventoryAttributesWrapper inventoryAttributesWrapper = new InventoryAttributesWrapper(wrapper.HeatSystem);
                HeatSystem.Apply(loader, inventoryAttributesWrapper, null);
                wrapper.HeatSystem = inventoryAttributesWrapper;
            }
            if (View != null)
            {
                PowerShuntViewAttributesWrapper powerShuntViewAttributesWrapper = new PowerShuntViewAttributesWrapper(wrapper.View);
                View.Apply(loader, powerShuntViewAttributesWrapper, null);
                wrapper.View = powerShuntViewAttributesWrapper;
            }
        }
예제 #2
0
        public void ApplyStorageAttributesPatch(StorageAttributesPatch storageAttributesPatch, StorageAttributesWrapper storageAttributesWrapper)
        {
            applyPropertyPatch(storageAttributesPatch.LinkToPlayerBank, () => storageAttributesWrapper.LinkToPlayerBank);
            applyPropertyPatch(storageAttributesPatch.IsResourceController, () => storageAttributesWrapper.IsResourceController);

            var loadout = storageAttributesWrapper.InventoryLoadout.ToList();

            foreach (var kvp in storageAttributesPatch.InventoryLoadout)
            {
                var inventoryId    = kvp.Key;
                var inventoryPatch = kvp.Value;

                using (logger.BeginScope($"InventoryBinding: {inventoryId}"))
                {
                    var index = loadout.FindIndex(b => b.InventoryID == inventoryId);

                    InventoryAttributesWrapper inventoryAttributesWrapper;

                    if (index < 0)
                    {
                        index = loadout.Count;

                        var name = $"SUBSYSTEM-{storageAttributesWrapper.Name}-{inventoryId}";
                        logger.Log($"(created InventoryAttributes: {name})");

                        inventoryAttributesWrapper = new InventoryAttributesWrapper(
                            name: name,
                            inventoryId: inventoryId
                            );
                    }
                    else
                    {
                        var inventoryBinding = loadout[index];
                        inventoryAttributesWrapper = new InventoryAttributesWrapper(inventoryBinding.InventoryAttributes);
                    }

                    ApplyInventoryAttributesPatch(inventoryPatch, inventoryAttributesWrapper);

                    var newBinding = new InventoryBinding(
                        inventoryID: inventoryId,
                        inventoryBindingIndex: index,
                        inventoryAttributes: inventoryAttributesWrapper
                        );

                    if (index == loadout.Count)
                    {
                        loadout.Add(newBinding);
                    }
                    else
                    {
                        loadout[index] = newBinding;
                    }
                }
            }

            storageAttributesWrapper.InventoryLoadout = loadout.ToArray();
        }
예제 #3
0
 private void ApplyInventoryAttributesPatch(InventoryAttributesPatch inventoryPatch, InventoryAttributesWrapper inventoryAttributesWrapper)
 {
     applyPropertyPatch(inventoryPatch.Capacity, () => inventoryAttributesWrapper.Capacity);
     applyPropertyPatch(inventoryPatch.HasUnlimitedCapacity, () => inventoryAttributesWrapper.HasUnlimitedCapacity);
     applyPropertyPatch(inventoryPatch.StartingAmount, () => inventoryAttributesWrapper.StartingAmount);
 }
예제 #4
0
        protected override void Apply(AttributeLoader loader, object wrapperObj)
        {
            if (!(wrapperObj is StorageAttributesWrapper wrapper))
            {
                throw new System.InvalidCastException();
            }

            loader.ApplyPPatch(LinkToPlayerBank, () => wrapper.LinkToPlayerBank);
            loader.ApplyPPatch(IsResourceController, () => wrapper.IsResourceController);

            var loadout = wrapper.InventoryLoadout.ToList();

            loader.logger.BeginScope($"Available inventory IDs: {String.Join(", ", loadout.Select(x => x.InventoryID).ToArray())}").Dispose();

            foreach (var kvp in InventoryLoadout)
            {
                var inventoryId    = kvp.Key;
                var inventoryPatch = kvp.Value;

                using (loader.logger.BeginScope($"InventoryBinding: {inventoryId}"))
                {
                    var index = loadout.FindIndex(b => b.InventoryID == inventoryId);

                    InventoryAttributesWrapper inventoryAttributesWrapper;

                    if (index < 0)
                    {
                        index = loadout.Count;

                        var name = $"SUBSYSTEM-{wrapper.Name}-{inventoryId}";
                        loader.logger.Log($"(created InventoryAttributes: {name})");

                        inventoryAttributesWrapper = new InventoryAttributesWrapper(
                            name: name,
                            inventoryId: inventoryId
                            );
                    }
                    else
                    {
                        var inventoryBinding = loadout[index];
                        inventoryAttributesWrapper = new InventoryAttributesWrapper(inventoryBinding.InventoryAttributes);
                    }

                    inventoryPatch.Apply(loader, inventoryAttributesWrapper, null);

                    var newBinding = new InventoryBinding(
                        inventoryID: inventoryId,
                        inventoryBindingIndex: index,
                        inventoryAttributes: inventoryAttributesWrapper
                        );

                    if (index == loadout.Count)
                    {
                        loadout.Add(newBinding);
                    }
                    else
                    {
                        loadout[index] = newBinding;
                    }
                }
            }

            wrapper.InventoryLoadout = loadout.ToArray();
        }