From bedda42ebb3a4eb7172900e9c9e5e14540f559ce Mon Sep 17 00:00:00 2001 From: agm-114 Date: Sun, 1 Dec 2024 10:56:59 +0530 Subject: [PATCH] More ammo changes. --- AGMLIB/Dynamic Systems/DynamicReduction.cs | 46 ++++++++++++---------- 1 file changed, 26 insertions(+), 20 deletions(-) diff --git a/AGMLIB/Dynamic Systems/DynamicReduction.cs b/AGMLIB/Dynamic Systems/DynamicReduction.cs index d75fb20..46002e0 100644 --- a/AGMLIB/Dynamic Systems/DynamicReduction.cs +++ b/AGMLIB/Dynamic Systems/DynamicReduction.cs @@ -1,4 +1,5 @@  +using System.Linq; using UnityEngine.UI.Extensions; public class DynamicReduction : ActiveSettings { @@ -7,7 +8,7 @@ public class DynamicReduction : ActiveSettings private ResourceType Res => ResourceDefinitions.Instance.GetResource(ResourceName); private ResourceValue[] _requiredResources; - public SimpleFilter Filter; + public ISimpleFilter Filter; protected override void FixedUpdate() { @@ -22,25 +23,7 @@ public bool TargetedComponent(HullComponent hullComponent) { if (!Module.isActiveAndEnabled) return false; - - if (Filter == null) - return true; - - if (hullComponent is not WeaponComponent weaponComponent) - return Filter.DefaultFilterMode; - - MunitionTags[] _compatibleAmmoTags = Common.GetVal(weaponComponent, "_compatibleAmmoTags"); - IEnumerable taglist = _compatibleAmmoTags.ToList().ConvertAll(tag => tag.Subclass); - if(Filter.Blacklist.Intersect(taglist).Any()) - return false; - if(Filter.Whitelist.Intersect(taglist).Any() ) - return true; - taglist = _compatibleAmmoTags.ToList().ConvertAll(tag => tag.Class); - if (Filter.Blacklist.Intersect(taglist).Any()) - return false; - if (Filter.Whitelist.Intersect(taglist).Any()) - return true; - return Filter.DefaultFilterMode; + return Filter?.CheckComponent(hullComponent) ?? true; } public static ResourceValue Reduce(ResourceValue basevalue, HullComponent hullComponent) @@ -112,12 +95,35 @@ public void Reset() } } +public class PastConsumption : MonoBehaviour +{ + public Dictionary AmountExtra = new(); +} + + +[HarmonyPatch(typeof(Ship), nameof(Ship.RunResourceTick))] +class ShipRunResourceTick +{ + + public static void Prefix(Ship __instance) + { + // + PastConsumption pastConsumption = __instance.GetComponent() ?? __instance.gameObject.AddComponent(); + pastConsumption.AmountExtra = Common.GetVal>(__instance, "_resources").Values.ToDictionary(pool => pool, pool => pool.AmountRemaining); + + + } + +} + + [HarmonyPatch(typeof(HullComponent), nameof(HullComponent.ConsumeResources))] class HullComponentConsumeResources { public static void Prefix(HullComponent __instance, ResourcePool pool) { + //Debug.LogError("ticking consumer"); DynamicReduction.UpdateResources(__instance); }