static bool Prefix(UnitAbilityResourceCollection __instance, BlueprintScriptableObject blueprint, ref int __result)
        {
            var owner = Helpers.GetField <UnitDescriptor>(__instance, "m_Owner");
            var connected_resources = owner?.Get <UnitPartConnectResource>()?.getConnectedResource(blueprint as BlueprintAbilityResource);

            if (connected_resources == null)
            {
                return(true);
            }

            int val = 0;
            UnitAbilityResource resource = Harmony12.Traverse.Create(__instance).Method("GetResource", blueprint).GetValue <UnitAbilityResource>();

            if (resource != null)
            {
                val = resource.Amount;
            }

            __result = 0;
            foreach (var cr in connected_resources)
            {
                __result += __instance.GetResourceAmount(cr);
            }

            __result = Math.Min(__result, val);
            return(false);
        }
Exemplo n.º 2
0
        static void Postfix(UnitAbilityResourceCollection __instance, BlueprintScriptableObject blueprint, int amount)
        {
            var owner = Helpers.GetField <UnitDescriptor>(__instance, "m_Owner");
            var connected_resource = owner?.Get <UnitPartConnectResource>()?.getConnectedResource(blueprint as BlueprintAbilityResource);

            if (connected_resource == null)
            {
                return;
            }

            __instance.Spend(connected_resource, amount);
        }
 static public void Postfix(UnitAbilityResourceCollection __instance, BlueprintScriptableObject blueprint, ref UnitDescriptor ___m_Owner)
 {
     if ((blueprint as BlueprintAbilityResource) == ArcaneReservoir.resource)
     {
         int arcanist_level = ___m_Owner.Progression.GetClassLevel(ArcanistClass.arcanist);
         __instance.Spend(blueprint, arcanist_level / 2 + arcanist_level % 2);
     }
     //resource used as special counters. Should not be restored after rest.
     if ((blueprint as BlueprintAbilityResource) == SpellResistanceDrain.drained_arcane_points_res)
     {
         __instance.Spend(blueprint, 5);
     }
 }
        static bool Prefix(UnitAbilityResourceCollection __instance, BlueprintScriptableObject blueprint, int amount, bool restoreFull, UnitDescriptor ___m_Owner)
        {
            UnitAbilityResource resource = Harmony12.Traverse.Create(__instance).Method("GetResource", blueprint).GetValue <UnitAbilityResource>();

            if (resource == null)
            {
                return(true);
            }

            var fake_resource = resource.Blueprint?.GetComponent <FakeResourceAmountFullRestore>()?.fake_resource;

            if (fake_resource == null || !restoreFull)
            {
                return(true);
            }
            else
            {
                int maxAmount = fake_resource.GetMaxAmount(___m_Owner);
                resource.Amount = maxAmount;
                return(false);
            }
        }
        static void Postfix(UnitAbilityResourceCollection __instance, BlueprintScriptableObject blueprint, int amount)
        {
            var owner = Helpers.GetField <UnitDescriptor>(__instance, "m_Owner");
            var connected_resources = owner?.Get <UnitPartConnectResource>()?.getConnectedResource(blueprint as BlueprintAbilityResource);

            if (connected_resources == null || connected_resources.Length == 0)
            {
                return;
            }

            connected_resources = connected_resources.OrderByDescending(c => __instance.GetResourceAmount(c)).ToArray();
            var max_resource_id = 0;

            while (amount > 0)
            {
                var next_resource_id = (max_resource_id + 1) % connected_resources.Length;
                if (__instance.GetResourceAmount(connected_resources[next_resource_id]) > __instance.GetResourceAmount(connected_resources[max_resource_id]))
                {
                    max_resource_id = next_resource_id;
                }
                __instance.Spend(connected_resources[max_resource_id], 1);
                amount--;
            }
        }
 static bool Prefix(UnitAbilityResourceCollection __instance, BlueprintScriptableObject blueprint, int amount, ref bool __result)
 {
     __result = __instance.GetResourceAmount(blueprint) >= amount;
     return(false);
 }
Exemplo n.º 7
0
 static void Postfix(UnitAbilityResourceCollection __instance, UnitDescriptor ___m_Owner, BlueprintScriptableObject blueprint)
 {
     EventBus.RaiseEvent <IResourceHandler>(h => h.HandleResourceChanged(___m_Owner, blueprint));
 }