Example #1
0
            public static bool Prefix(WeaponLoadout __instance)
            {
                var item = __instance.Item;

                if (IsManaBow(item))
                {
                    // custom mana cost
                    float manaCost = item.OwnerCharacter.Stats.GetFinalManaConsumption(null, ManaBowCost);
                    item.OwnerCharacter.Stats.UseMana(null, manaCost);

                    // (vanilla) update weapon loadout remaining shots
                    int remaining = (int)At.GetField(__instance, "m_remainingShots");
                    remaining--;
                    At.SetField(__instance, "m_remainingShots", remaining);

                    if (remaining < 0)
                    {
                        remaining = 0;
                    }

                    if (remaining == 0)
                    {
                        __instance.Unload();
                    }

                    // unequip the arrow
                    var ammo = __instance.Item.OwnerCharacter.Inventory.Equipment.GetEquippedItem(EquipmentSlot.EquipmentSlotIDs.Quiver) as Ammunition;
                    __instance.Item.OwnerCharacter.Inventory.Equipment.UnequipItem(ammo, false, null);
                    ammo.transform.SetParent(null);
                    ammo.transform.ResetLocal();

                    // vanilla method
                    At.Invoke(__instance, "SetHasChanged");

                    return(false);
                }

                return(true);
            }
Example #2
0
            public static bool Prefix(WeaponLoadout __instance, bool _destroyOnEmpty)
            {
                var item = __instance.Item;

                if (IsManaBow(item))
                {
                    // custom mana cost
                    float manaCost = item.OwnerCharacter.Stats.GetFinalManaConsumption(null, ManaBowCost);
                    item.OwnerCharacter.Stats.UseMana(null, manaCost);

                    // (vanilla) update weapon loadout remaining shots
                    __instance.m_remainingShots--;

                    if (__instance.m_remainingShots < 0)
                    {
                        __instance.m_remainingShots = 0;
                    }

                    if (__instance.m_remainingShots == 0)
                    {
                        __instance.Unload();
                    }

                    // unequip the arrow
                    var ammo = __instance.Item.OwnerCharacter.Inventory.Equipment.GetEquippedItem(EquipmentSlot.EquipmentSlotIDs.Quiver) as Ammunition;
                    __instance.Item.OwnerCharacter.Inventory.Equipment.UnequipItem(ammo, false, null);
                    ammo.transform.SetParent(null);
                    ammo.transform.ResetLocal();

                    // vanilla method
                    __instance.SetHasChanged();

                    return(false);
                }
                // Copied from Raid Mode for compatibility
                else if (__instance is WeaponLoadoutItem loadoutItem)
                {
                    if (!loadoutItem.ReduceAmmunitionOnLoad)
                    {
                        if (loadoutItem.m_loadedAmmunition != null && __instance.Item.OwnerCharacter.IsLocalPlayer)
                        {
                            Global.RPCManager.SendSkillUseItem(loadoutItem.m_loadedAmmunition.UID, 1);
                            if (PhotonNetwork.isNonMasterClientInRoom && loadoutItem.m_loadedAmmunition.RemainingAmount < 1)
                            {
                                loadoutItem.m_loadedAmmunition.RemainingAmount--;
                            }
                        }

                        if (_destroyOnEmpty)
                        {
                            loadoutItem.m_loadedAmmunition = null;
                        }

                        else if (loadoutItem.m_loadedAmmunition == null || loadoutItem.m_loadedAmmunition.RemainingAmount == 0)
                        {
                            if (loadoutItem.m_loadedAmmunition)
                            {
                                loadoutItem.m_loadedAmmunition.SaveType = Item.SaveTypes.NonSavable;
                            }

                            if (loadoutItem.m_lastLoadedItems.Count > 0)
                            {
                                loadoutItem.m_lastLoadedItems.RemoveAt(0);
                            }

                            if (loadoutItem.m_lastLoadedItems.Count > 0)
                            {
                                loadoutItem.m_loadedAmmunition = (loadoutItem.m_lastLoadedItems[0] as Ammunition);
                            }
                        }
                    }

                    WeaponLoadout_ReduceShotAmount.ReversePatch(__instance, _destroyOnEmpty);

                    if (loadoutItem.ReduceAmmunitionOnLoad)
                    {
                        __instance.DataSynced();
                    }
                }

                return(true);
            }