Пример #1
0
        public static bool Prefix(ItemDrop.ItemData item, Inventory ___m_inventory)
        {
            if (!EquipmentAndQuickSlots.EquipmentSlotsEnabled.Value)
            {
                return(true);
            }

            if (_dropping)
            {
                return(false);
            }

            _shouldDrop = false;
            if (item != null && EquipmentAndQuickSlots.IsSlotEquippable(item) && EquipmentAndQuickSlots.IsEquipmentSlot(item.m_gridPos))
            {
                if (___m_inventory.HaveEmptySlot())
                {
                    var correctInventorySlot = ___m_inventory.FindEmptySlot(false);
                    EquipUtil.MoveItemToSlot(___m_inventory, item, correctInventorySlot);
                }
                else
                {
                    _shouldDrop = true;
                }
            }

            return(true);
        }
Пример #2
0
        public static void Swap(Inventory inventoryA, ItemDrop.ItemData item, Inventory inventoryB, Vector2i slotB)
        {
            var slotA = item.m_gridPos;

            if (inventoryA == inventoryB && item.m_gridPos == slotB)
            {
                EquipmentAndQuickSlots.Log("Item already in correct slot");
                return;
            }

            var otherItemInSlot = inventoryB.GetItemAt(slotB.x, slotB.y);

            if (otherItemInSlot != null)
            {
                EquipmentAndQuickSlots.Log($"Item exists in other slot ({otherItemInSlot.m_shared.m_name})");
                inventoryB.m_inventory.Remove(otherItemInSlot);
            }

            inventoryA.m_inventory.Remove(item);
            inventoryB.m_inventory.Add(item);
            item.m_gridPos = slotB;

            if (otherItemInSlot != null)
            {
                otherItemInSlot.m_gridPos = slotA;
                inventoryA.m_inventory.Add(otherItemInSlot);
            }

            inventoryA.Changed();
            inventoryB.Changed();
        }
Пример #3
0
        public static void Prefix(Inventory __instance, int x, int y)
        {
            Container container = Container_Load_Patch.tombstoneContainer;

            if (container == null)
            {
                return;
            }

            if (x >= __instance.m_width)
            {
                int newWidth = x + 1;
                EquipmentAndQuickSlots.Log($"Changing tombstone container width ({container.m_width} -> {newWidth}) to fit item at pos {x},{y}");
                container.m_width  = newWidth;
                __instance.m_width = newWidth;
            }

            if (y >= __instance.m_height)
            {
                int newHeight = y + 1;
                EquipmentAndQuickSlots.Log($"Changing tombstone container height ({container.m_height} -> {newHeight}) to fit item at pos {x},{y}");
                container.m_height  = newHeight;
                __instance.m_height = newHeight;
            }
        }
Пример #4
0
        public void Load(Player fromPlayer)
        {
            if (fromPlayer == null)
            {
                EquipmentAndQuickSlots.LogError("Tried to load an ExtendedPlayerData with a null player!");
                return;
            }

            _player = fromPlayer;
            LoadValue(fromPlayer, "ExtendedPlayerData", out var init);
            EquipmentAndQuickSlots.LogWarning("Loaded ExtendedPlayerData");

            if (LoadValue(fromPlayer, nameof(QuickSlotInventory), out var quickSlotData))
            {
                var pkg = new ZPackage(quickSlotData);
                _isLoading = true;
                QuickSlotInventory.Load(pkg);
                _isLoading = false;
            }

            if (LoadValue(fromPlayer, nameof(EquipmentSlotInventory), out var equipSlotData))
            {
                var pkg = new ZPackage(equipSlotData);
                _isLoading = true;
                EquipmentSlotInventory.Load(pkg);
                _isLoading = false;
            }
        }
Пример #5
0
        public static bool Prefix(Humanoid __instance, ItemDrop.ItemData item)
        {
            if (!EquipmentAndQuickSlots.EquipmentSlotsEnabled.Value)
            {
                return(true);
            }

            if (_dropping)
            {
                return(false);
            }

            if (!__instance.IsPlayer())
            {
                return(true);
            }

            _shouldDrop = false;
            if (item != null && EquipmentAndQuickSlots.IsSlotEquippable(item))
            {
                if (__instance.m_inventory.HaveEmptySlot())
                {
                    var correctInventorySlot = __instance.m_inventory.FindEmptySlot(false);
                    //__instance.m_inventory.MoveItemToThis((__instance as Player).GetEquipmentSlotInventory(), item, item.m_stack, correctInventorySlot.x, correctInventorySlot.y);
                }
                else
                {
                    _shouldDrop = true;
                }
            }

            return(true);
        }
Пример #6
0
        public static bool Prefix(Inventory __instance, ref bool __result)
        {
            if (__instance.GetName() != "Inventory")
            {
                return(true);
            }

            var inventorySize         = ((__instance.m_width * __instance.m_height) - EquipmentAndQuickSlots.EquipSlotCount);
            var currentInventoryCount = __instance.m_inventory.Count;

            // Don't count armor that is in armor slots
            for (int index = 0; index < EquipmentAndQuickSlots.EquipSlotCount; index++)
            {
                var slot = EquipmentAndQuickSlots.GetEquipmentSlotForType(EquipmentAndQuickSlots.EquipSlotTypes[index]);
                var item = __instance.GetItemAt(slot.x, slot.y);
                currentInventoryCount -= (item != null) ? 1 : 0;
            }

            if (!EquipmentAndQuickSlots.QuickSlotsEnabled.Value)
            {
                inventorySize -= EquipmentAndQuickSlots.QuickUseSlotCount;
            }

            __result = currentInventoryCount < inventorySize;
            return(false);
        }
Пример #7
0
        public static void Prefix(Player __instance)
        {
            if (__instance.m_inventory.NrOfItems() == 0)
            {
                return;
            }

            EquipmentSlotHelper.AllowMove = false;
            __instance.UnequipAllItems();
            var allInventories = __instance.GetAllInventories();

            var gameObject = Object.Instantiate(__instance.m_tombstone, __instance.GetCenterPoint(), __instance.transform.rotation);
            var container  = gameObject.GetComponent <Container>();

            // Modify tombstone prefab
            var totalPossibleSlots = allInventories.Sum(x => x.m_width * x.m_height);
            var width  = __instance.m_inventory.m_width;
            var height = (totalPossibleSlots / width) + 1;

            container.m_width              = width;
            container.m_height             = height;
            container.m_inventory.m_width  = width;
            container.m_inventory.m_height = height;

            var containerInventory = container.GetInventory();

            foreach (var inventory in allInventories)
            {
                foreach (var item in inventory.m_inventory)
                {
                    if (!item.m_shared.m_questItem && !item.m_equiped)
                    {
                        if (containerInventory.GetItemAt(item.m_gridPos.x, item.m_gridPos.y) != null)
                        {
                            containerInventory.AddItem(item);
                        }
                        else
                        {
                            containerInventory.m_inventory.Add(item);
                        }
                    }
                }

                inventory.m_inventory.RemoveAll(item => !item.m_shared.m_questItem && !item.m_equiped);
                inventory.Changed();
            }
            containerInventory.Changed();

            var tombStone     = gameObject.GetComponent <TombStone>();
            var playerProfile = Game.instance.GetPlayerProfile();
            var name          = playerProfile.GetName();
            var playerId      = playerProfile.GetPlayerID();

            tombStone.Setup(name, playerId);

            EquipmentAndQuickSlots.LogWarning($"Creating tombstone for ({name}) with w:{width} h:{height} (total:{totalPossibleSlots})");

            EquipmentSlotHelper.AllowMove = true;
        }
Пример #8
0
 private static Action <InventoryGrid, ItemDrop.ItemData, Vector2i, InventoryGrid.Modifier> OnSelected(InventoryGui inventoryGui)
 {
     return((InventoryGrid inventoryGrid, ItemDrop.ItemData item, Vector2i pos, InventoryGrid.Modifier mod) =>
     {
         EquipmentAndQuickSlots.Log($"OnSelected: inventoryGrid={inventoryGrid}, item={item?.m_shared.m_name}, pos={pos}, mod={mod}");
         inventoryGui.OnSelectedItem(inventoryGrid, item, pos, mod);
     });
 }
Пример #9
0
 private static Action <InventoryGrid, ItemDrop.ItemData, Vector2i> OnRightClicked(InventoryGui inventoryGui)
 {
     return((InventoryGrid inventoryGrid, ItemDrop.ItemData item, Vector2i pos) =>
     {
         EquipmentAndQuickSlots.Log($"OnRightClicked: inventoryGrid={inventoryGrid}, item={item?.m_shared.m_name}, pos={pos}");
         if (item == null || Player.m_localPlayer == null)
         {
             return;
         }
         Player.m_localPlayer.UseItem(Player.m_localPlayer.m_inventory.Extended(), item, true);
     });
 }
Пример #10
0
        public static bool Prefix(ItemDrop.ItemData item, Inventory ___m_inventory)
        {
            if (EquipmentAndQuickSlots.EquipmentSlotsEnabled.Value && item != null && EquipmentAndQuickSlots.IsSlotEquippable(item))
            {
                var currentInventorySlot = item.m_gridPos;
                var correctInventorySlot = EquipmentAndQuickSlots.GetEquipmentSlotForType(item.m_shared.m_itemType);
                if (currentInventorySlot != correctInventorySlot)
                {
                    EquipUtil.MoveItemToSlot(___m_inventory, item, correctInventorySlot);
                }
            }

            return(true);
        }
Пример #11
0
        public static void Postfix()
        {
            var player = Player.m_localPlayer;

            if (player == null)
            {
                return;
            }

            EquipmentAndQuickSlots.LogWarning("Recovered Tombstone Items, verifying inventory...");
            var droppedItems = new List <ItemDrop.ItemData>();

            foreach (var inventory in player.GetAllInventories())
            {
                foreach (var itemData in inventory.m_inventory)
                {
                    var isOutsideInventoryGrid = itemData.m_gridPos.x < 0 ||
                                                 itemData.m_gridPos.x >= inventory.m_width ||
                                                 itemData.m_gridPos.y < 0 ||
                                                 itemData.m_gridPos.y >= inventory.m_height;
                    if (isOutsideInventoryGrid)
                    {
                        var itemText = Localization.instance.Localize(itemData.m_shared.m_name) + (itemData.m_stack > 1 ? $" x{itemData.m_stack}" : "");
                        EquipmentAndQuickSlots.LogWarning($"> Item Outside Inventory Grid! ({itemText}, <{itemData.m_gridPos.x},{itemData.m_gridPos.y}>)");
                        inventory.RemoveItem(itemData);
                        var addSuccess = inventory.AddItem(itemData);
                        if (!addSuccess)
                        {
                            EquipmentAndQuickSlots.LogError($"> Could not add item to inventory, item dropped! ({itemText})");
                            droppedItems.Add(itemData);
                            ItemDrop.DropItem(itemData, itemData.m_stack, player.transform.position + player.transform.forward * 2 + Vector3.up, Quaternion.identity);
                        }
                    }
                }
            }

            if (droppedItems.Count > 0)
            {
                var droppedItemTexts    = droppedItems.Select(x => Localization.instance.Localize(x.m_shared.m_name) + (x.m_stack > 1 ? $" x{x.m_stack}" : ""));
                var droppedItemsMessage = ">>>> ERROR IN TOMBSTONE RECOVERY - ITEMS DROPPED: " + string.Join(", ", droppedItemTexts);
                player.Message(MessageHud.MessageType.Center, droppedItemsMessage);
                Debug.LogError(droppedItemsMessage);
                EquipmentAndQuickSlots.LogError(droppedItemsMessage);
            }
            else
            {
                EquipmentAndQuickSlots.LogWarning("> No issues!");
            }
        }
Пример #12
0
        public static bool Prefix(InventoryGui __instance, InventoryGrid grid, ItemDrop.ItemData item, Vector2i pos, InventoryGrid.Modifier mod, GameObject ___m_dragGo, ItemDrop.ItemData ___m_dragItem)
        {
            if (grid.m_inventory.m_name.Equals("Inventory") && EquipmentAndQuickSlots.EquipmentSlotsEnabled.Value && EquipmentAndQuickSlots.IsEquipmentSlot(pos))
            {
                if (___m_dragItem != null && EquipmentAndQuickSlots.IsSlotEquippable(___m_dragItem) && EquipmentAndQuickSlots.GetEquipmentTypeForSlot(pos) == ___m_dragItem.m_shared.m_itemType)
                {
                    var player = Player.m_localPlayer;
                    player.UseItem(player.GetInventory(), ___m_dragItem, true);
                    __instance.SetupDragItem(null, null, 1);
                }
                return(false);
            }

            return(true);
        }
Пример #13
0
        public static void Postfix(List <ItemDrop.ItemData> bound, List <ItemDrop.ItemData> ___m_inventory)
        {
            if (!EquipmentAndQuickSlots.QuickSlotsEnabled.Value)
            {
                return;
            }

            foreach (ItemDrop.ItemData itemData in ___m_inventory)
            {
                if (EquipmentAndQuickSlots.IsQuickSlot(itemData.m_gridPos))
                {
                    bound.Add(itemData);
                }
            }
        }
Пример #14
0
        public void Load(Player fromPlayer)
        {
            if (fromPlayer == null)
            {
                EquipmentAndQuickSlots.LogError("Tried to load an ExtendedPlayerData with a null player!");
                return;
            }

            _player = fromPlayer;
            LoadValue(fromPlayer, "ExtendedPlayerData", out var init);
            EquipmentAndQuickSlots.LogWarning("Loaded ExtendedPlayerData");

            if (LoadValue(fromPlayer, nameof(QuickSlotInventory), out var quickSlotData))
            {
                var pkg = new ZPackage(quickSlotData);
                _isLoading = true;
                QuickSlotInventory.Load(pkg);

                if (!EquipmentAndQuickSlots.QuickSlotsEnabled.Value)
                {
                    _player.m_inventory.MoveAll(QuickSlotInventory);

                    pkg = new ZPackage(quickSlotData);
                    QuickSlotInventory.Save(pkg);
                    SaveValue(_player, nameof(QuickSlotInventory), pkg.GetBase64());
                }

                _isLoading = false;
            }

            if (LoadValue(fromPlayer, nameof(EquipmentSlotInventory), out var equipSlotData))
            {
                var pkg = new ZPackage(equipSlotData);
                _isLoading = true;
                EquipmentSlotInventory.Load(pkg);

                if (!EquipmentAndQuickSlots.EquipmentSlotsEnabled.Value)
                {
                    _player.m_inventory.MoveAll(EquipmentSlotInventory);

                    pkg = new ZPackage(quickSlotData);
                    EquipmentSlotInventory.Save(pkg);
                    SaveValue(_player, nameof(EquipmentSlotInventory), pkg.GetBase64());
                }

                _isLoading = false;
            }
        }
Пример #15
0
        private static bool Prefix(InventoryGrid __instance, ref InventoryGrid.Element __result, int x, int y, int width)
        {
            var index = y * width + x;

            if (index < 0 || index >= __instance.m_elements.Count)
            {
                EquipmentAndQuickSlots.LogError($"Tried to get element for item ({x}, {y}) in inventory ({__instance.m_inventory.m_name}) but that element is outside the bounds!");
                __result = null;
            }
            else
            {
                __result = __instance.m_elements[index];
            }

            return(false);
        }
Пример #16
0
 private static Action <InventoryGrid, ItemDrop.ItemData, Vector2i> OnEquipmentRightClicked(InventoryGui inventoryGui)
 {
     return((InventoryGrid inventoryGrid, ItemDrop.ItemData item, Vector2i pos) =>
     {
         var player = Player.m_localPlayer;
         EquipmentAndQuickSlots.Log($"OnEquipmentRightClicked: inventoryGrid={inventoryGrid}, item={item?.m_shared.m_name}, pos={pos}");
         if (item != null &&
             player != null &&
             item.m_equiped &&
             player.IsItemEquiped(item) &&
             inventoryGui.m_dragItem == null)
         {
             Player.m_localPlayer.QueueUnequipItem(item);
         }
     });
 }
Пример #17
0
        private void Awake()
        {
            _instance = this;

            _loggingEnabled       = Config.Bind("Logging", "Logging Enabled", false, "Enable logging");
            KeyCodes[0]           = Config.Bind("Hotkeys", "Quick slot hotkey 1", "z", "Hotkey for Quick Slot 1.");
            KeyCodes[1]           = Config.Bind("Hotkeys", "Quick slot hotkey 2", "v", "Hotkey for Quick Slot 2.");
            KeyCodes[2]           = Config.Bind("Hotkeys", "Quick slot hotkey 3", "b", "Hotkey for Quick Slot 3.");
            HotkeyLabels[0]       = Config.Bind("Hotkeys", "Quick slot hotkey label 1", "", "Hotkey Label for Quick Slot 1. Leave blank to use the hotkey itself.");
            HotkeyLabels[1]       = Config.Bind("Hotkeys", "Quick slot hotkey label 2", "", "Hotkey Label for Quick Slot 2. Leave blank to use the hotkey itself.");
            HotkeyLabels[2]       = Config.Bind("Hotkeys", "Quick slot hotkey label 3", "", "Hotkey Label for Quick Slot 3. Leave blank to use the hotkey itself.");
            EquipmentSlotsEnabled = Config.Bind("Toggles", "Enable Equipment Slots", true, "Enable the equipment slots. !!! WARNING !!! If you disable this while wearing equipment, you will LOSE IT!");
            QuickSlotsEnabled     = Config.Bind("Toggles", "Enable Quick Slots", true, "Enable the quick slots. !!! WARNING !!! If you disable this while items are in the quickslots, you will LOSE THEM!");

            _harmony = Harmony.CreateAndPatchAll(Assembly.GetExecutingAssembly(), PluginId);
        }
Пример #18
0
            private static Action <InventoryGrid, ItemDrop.ItemData, Vector2i, InventoryGrid.Modifier> OnEquipmentSelected(InventoryGui inventoryGui)
            {
                return((InventoryGrid inventoryGrid, ItemDrop.ItemData item, Vector2i pos, InventoryGrid.Modifier mod) =>
                {
                    var player = Player.m_localPlayer;
                    EquipmentAndQuickSlots.Log($"OnEquipmentSelected: inventoryGrid={inventoryGrid}, item={item?.m_shared.m_name}, pos={pos}, mod={mod}");

                    if (player != null &&
                        inventoryGui.m_dragItem != null &&
                        EquipmentAndQuickSlots.IsSlotEquippable(inventoryGui.m_dragItem) &&
                        pos == EquipmentAndQuickSlots.GetEquipmentSlotForType(inventoryGui.m_dragItem.m_shared.m_itemType))
                    {
                        player.QueueEquipItem(inventoryGui.m_dragItem);
                        inventoryGui.SetupDragItem(null, null, 0);
                    }
                });
            }
        private void Awake()
        {
            _instance = this;

            _loggingEnabled       = Config.Bind("Logging", "Logging Enabled", false, "Enable logging");
            KeyCodes[0]           = Config.Bind("Hotkeys", "Quick slot hotkey 1", "z", "Hotkey for Quick Slot 1.");
            KeyCodes[1]           = Config.Bind("Hotkeys", "Quick slot hotkey 2", "v", "Hotkey for Quick Slot 2.");
            KeyCodes[2]           = Config.Bind("Hotkeys", "Quick slot hotkey 3", "b", "Hotkey for Quick Slot 3.");
            HotkeyLabels[0]       = Config.Bind("Hotkeys", "Quick slot hotkey label 1", "", "Hotkey Label for Quick Slot 1. Leave blank to use the hotkey itself.");
            HotkeyLabels[1]       = Config.Bind("Hotkeys", "Quick slot hotkey label 2", "", "Hotkey Label for Quick Slot 2. Leave blank to use the hotkey itself.");
            HotkeyLabels[2]       = Config.Bind("Hotkeys", "Quick slot hotkey label 3", "", "Hotkey Label for Quick Slot 3. Leave blank to use the hotkey itself.");
            EquipmentSlotsEnabled = Config.Bind("Toggles", "Enable Equipment Slots", true, "Enable the equipment slots. Disabling this while items are equipped with attempt to move them to your inventory.");
            QuickSlotsEnabled     = Config.Bind("Toggles", "Enable Quick Slots", true, "Enable the quick slots. Disabling this while items are in the slots with attempt to move them to your inventory.");
            ViewDebugSaveData     = Config.Bind("Toggles", "View Debug Save Data", false, "Enable to view the raw save data in the compendium.");

            _harmony = Harmony.CreateAndPatchAll(Assembly.GetExecutingAssembly(), PluginId);
        }
Пример #20
0
        private static void Postfix(InventoryGrid __instance, Player player, ItemDrop.ItemData dragItem)
        {
            if (__instance.name == "QuickSlotGrid")
            {
                for (int i = 0; i < EquipmentAndQuickSlots.QuickSlotCount; ++i)
                {
                    var element     = __instance.m_elements[i];
                    var bindingText = element.m_go.transform.Find("binding").GetComponent <Text>();
                    bindingText.enabled            = true;
                    bindingText.horizontalOverflow = HorizontalWrapMode.Overflow;
                    bindingText.text = EquipmentAndQuickSlots.GetBindingLabel(i);
                }
            }
            else if (__instance.name == "EquipmentSlotGrid")
            {
                float     horizontalSpacing = __instance.m_elementSpace + 10;
                float     verticalSpacing   = __instance.m_elementSpace + 10;
                string[]  equipNames        = { "Head", "Chest", "Legs", "Shoulders", "Utility 1", "Utility 2" };
                Vector2[] equipPositions    =
                {
                    new Vector2(),                                        // Head
                    new Vector2(0, -verticalSpacing),                     // Chest
                    new Vector2(0, -2 * verticalSpacing),                 // Legs
                    new Vector2(horizontalSpacing, 0),                    // Shoulders
                    new Vector2(horizontalSpacing, -1 * verticalSpacing), // Utility 1
                    new Vector2(horizontalSpacing, -2 * verticalSpacing), // Utility 2
                };

                for (int i = 0; i < EquipmentAndQuickSlots.EquipSlotCount; ++i)
                {
                    var element     = __instance.m_elements[i];
                    var bindingText = element.m_go.transform.Find("binding").GetComponent <Text>();
                    bindingText.enabled            = true;
                    bindingText.horizontalOverflow = HorizontalWrapMode.Overflow;
                    bindingText.text = equipNames[i];
                    bindingText.rectTransform.anchoredPosition = new Vector2(32, 5);

                    Vector2 offset = new Vector2();// Vector2(692, -20);
                    (element.m_go.transform as RectTransform).anchoredPosition = offset + equipPositions[i];
                }
            }
        }
Пример #21
0
        private static void Postfix(InventoryGrid __instance)
        {
            if (__instance.name == "QuickSlotGrid")
            {
                for (var i = 0; i < EquipmentAndQuickSlots.QuickSlotCount; ++i)
                {
                    var element     = __instance.m_elements[i];
                    var bindingText = element.m_go.transform.Find("binding").GetComponent <Text>();
                    bindingText.enabled            = true;
                    bindingText.horizontalOverflow = HorizontalWrapMode.Overflow;
                    bindingText.text = EquipmentAndQuickSlots.GetBindingLabel(i);
                }
            }
            else if (__instance.name == "EquipmentSlotGrid")
            {
                var       horizontalSpacing = __instance.m_elementSpace + 10;
                var       verticalSpacing   = __instance.m_elementSpace + 10;
                string[]  equipNames        = { "Head", "Chest", "Legs", "Shoulders", "Utility" };
                Vector2[] equipPositions    =
                {
                    new Vector2(),                                           // Head
                    new Vector2(0, -verticalSpacing),                        // Chest
                    new Vector2(0, -2 * verticalSpacing),                    // Legs
                    new Vector2(horizontalSpacing, -0.5f * verticalSpacing), // Shoulders
                    new Vector2(horizontalSpacing, -1.5f * verticalSpacing), // Utility 1
                    //new Vector2(horizontalSpacing, -2 * verticalSpacing), // Utility 2
                };

                for (var i = 0; i < EquipmentAndQuickSlots.EquipSlotCount; ++i)
                {
                    var element     = __instance.m_elements[i];
                    var bindingText = element.m_go.transform.Find("binding").GetComponent <Text>();
                    bindingText.enabled            = true;
                    bindingText.horizontalOverflow = HorizontalWrapMode.Overflow;
                    bindingText.text = equipNames[i];
                    bindingText.rectTransform.anchoredPosition = new Vector2(32, 5);

                    var offset = new Vector2(-20, 79);
                    element.m_go.RectTransform().anchoredPosition = offset + equipPositions[i];
                }
            }
        }
Пример #22
0
        public void Save()
        {
            if (_player == null)
            {
                EquipmentAndQuickSlots.LogError("Tried to save an ExtendedPlayerData without a player!");
                return;
            }

            EquipmentAndQuickSlots.LogWarning("Saving ExtendedPlayerData");
            SaveValue(_player, "ExtendedPlayerData", "This player is using ExtendedPlayerData!");

            var pkg = new ZPackage();

            QuickSlotInventory.Save(pkg);
            SaveValue(_player, nameof(QuickSlotInventory), pkg.GetBase64());

            pkg = new ZPackage();
            EquipmentSlotInventory.Save(pkg);
            SaveValue(_player, nameof(EquipmentSlotInventory), pkg.GetBase64());
        }
Пример #23
0
        public static void Postfix(Humanoid __instance, ItemDrop.ItemData item, bool __result)
        {
            if (!__result || __instance == null || item == null || !__instance.IsPlayer())
            {
                return;
            }

            Debug.Log($"Equipped item {item.m_shared.m_setName} at slot <{item.m_gridPos}>");
            var player = __instance as Player;

            if (EquipmentAndQuickSlots.EquipmentSlotsEnabled.Value && EquipmentAndQuickSlots.IsSlotEquippable(item) && player.GetEquipmentSlotInventory() != null)
            {
                var currentInventorySlot = item.m_gridPos;
                var correctInventorySlot = EquipmentAndQuickSlots.GetEquipmentSlotForType(item.m_shared.m_itemType);
                if (currentInventorySlot.x != correctInventorySlot)
                {
                    //player.GetEquipmentSlotInventory().MoveItemToThis(__instance.m_inventory, item, item.m_stack, correctInventorySlot, 0);
                }
            }

            return;
        }
Пример #24
0
        public bool OverrideAddItem(ItemDrop.ItemData item)
        {
            CallBase = true;
            var result = false;

            foreach (var inventory in _inventories)
            {
                if (!inventory.CountAsEmptySlots(_player))
                {
                    continue;
                }

                if (inventory.AddItem(item))
                {
                    EquipmentAndQuickSlots.LogWarning($"Added item ({item.m_shared.m_name}) to ({inventory.m_name}) at ({item.m_gridPos})");
                    result = true;
                    break;
                }
            }

            CallBase = false;
            return(result);
        }
Пример #25
0
        private void Awake()
        {
            _instance = this;

            _loggingEnabled       = Config.Bind("Logging", "Logging Enabled", false, "Enable logging");
            KeyCodes[0]           = Config.Bind("Hotkeys", "Quick slot hotkey 1", "z", "Hotkey for Quick Slot 1.");
            KeyCodes[1]           = Config.Bind("Hotkeys", "Quick slot hotkey 2", "v", "Hotkey for Quick Slot 2.");
            KeyCodes[2]           = Config.Bind("Hotkeys", "Quick slot hotkey 3", "b", "Hotkey for Quick Slot 3.");
            HotkeyLabels[0]       = Config.Bind("Hotkeys", "Quick slot hotkey label 1", "", "Hotkey Label for Quick Slot 1. Leave blank to use the hotkey itself.");
            HotkeyLabels[1]       = Config.Bind("Hotkeys", "Quick slot hotkey label 2", "", "Hotkey Label for Quick Slot 2. Leave blank to use the hotkey itself.");
            HotkeyLabels[2]       = Config.Bind("Hotkeys", "Quick slot hotkey label 3", "", "Hotkey Label for Quick Slot 3. Leave blank to use the hotkey itself.");
            EquipmentSlotsEnabled = Config.Bind("Toggles", "Enable Equipment Slots", true, "Enable the equipment slots. Disabling this while items are equipped with attempt to move them to your inventory.");
            QuickSlotsEnabled     = Config.Bind("Toggles", "Enable Quick Slots", true, "Enable the quick slots. Disabling this while items are in the slots with attempt to move them to your inventory.");
            ViewDebugSaveData     = Config.Bind("Toggles", "View Debug Save Data", false, "Enable to view the raw save data in the compendium.");
            QuickSlotsAnchor      = Config.Bind("Quick Slots", "Quick Slots Anchor", TextAnchor.LowerLeft, "The point on the HUD to anchor the Quick Slots bar. Changing this also changes the pivot of the Quick Slots to that corner.");
            QuickSlotsPosition    = Config.Bind("Quick Slots", "Quick Slots Position", new Vector2(216, 150), "The position offset from the Quick Slots Anchor at which to place the Quick Slots.");

            LoadAssets();

            _harmony = Harmony.CreateAndPatchAll(Assembly.GetExecutingAssembly(), PluginId);

            HasAuga = Auga.API.IsLoaded();
        }
Пример #26
0
 public ExtendedInventory(Player player, string name, Sprite bkg, int w, int h) : base(name, bkg, w, h)
 {
     EquipmentAndQuickSlots.LogWarning("New Extended Inventory for Player");
     _player = player;
 }
Пример #27
0
        private static void Postfix(InventoryGrid __instance, Player player, ItemDrop.ItemData dragItem, List <InventoryGrid.Element> ___m_elements)
        {
            if (__instance.name != "PlayerGrid")
            {
                return;
            }

            if (EquipmentAndQuickSlots.QuickSlotsEnabled.Value)
            {
                var quickSlotBkg = GetOrCreateBackground(__instance, "QuickSlotBkg");
                quickSlotBkg.anchoredPosition = new Vector2(480, -173);
                quickSlotBkg.SetSizeWithCurrentAnchors(RectTransform.Axis.Horizontal, 240);
                quickSlotBkg.SetSizeWithCurrentAnchors(RectTransform.Axis.Vertical, 90);
            }
            else
            {
                var existingBkg = __instance.transform.parent.Find("QuickSlotBkg");
                if (existingBkg != null)
                {
                    GameObject.Destroy(existingBkg.gameObject);
                }
            }

            if (EquipmentAndQuickSlots.EquipmentSlotsEnabled.Value)
            {
                var equipmentBkg = GetOrCreateBackground(__instance, "EquipmentBkg");
                equipmentBkg.anchoredPosition = new Vector2(485, 10);
                equipmentBkg.SetSizeWithCurrentAnchors(RectTransform.Axis.Horizontal, 210);
                equipmentBkg.SetSizeWithCurrentAnchors(RectTransform.Axis.Vertical, 260);
            }
            else
            {
                var existingBkg = __instance.transform.parent.Find("EquipmentBkg");
                if (existingBkg != null)
                {
                    GameObject.Destroy(existingBkg.gameObject);
                }
            }

            float horizontalSpacing = __instance.m_elementSpace + 10;
            float verticalSpacing   = __instance.m_elementSpace + 10;

            string[]  equipNames     = { "Head", "Chest", "Legs", "Shoulders", "Utility" };
            Vector2[] equipPositions =
            {
                new Vector2(),                                           // Head
                new Vector2(0, -verticalSpacing),                        // Chest
                new Vector2(0, -2 * verticalSpacing),                    // Legs
                new Vector2(horizontalSpacing, -0.5f * verticalSpacing), // Shoulders
                new Vector2(horizontalSpacing, -1.5f * verticalSpacing), // Utility
            };

            var y = EquipmentAndQuickSlots.GetBonusInventoryRowIndex();

            for (int i = 0; i < EquipmentAndQuickSlots.EquipSlotCount; ++i)
            {
                var x       = i;
                var element = GetElement(___m_elements, x, y);

                if (!EquipmentAndQuickSlots.EquipmentSlotsEnabled.Value)
                {
                    element.m_go.SetActive(false);
                    continue;
                }
                else
                {
                    element.m_go.SetActive(true);
                }

                var bindingText = element.m_go.transform.Find("binding").GetComponent <Text>();
                bindingText.enabled            = true;
                bindingText.horizontalOverflow = HorizontalWrapMode.Overflow;
                bindingText.text = equipNames[i];
                bindingText.rectTransform.anchoredPosition = new Vector2(32, 5);

                Vector2 offset = new Vector2(692, -20);
                (element.m_go.transform as RectTransform).anchoredPosition = offset + equipPositions[i];
            }

            for (int i = 0; i < EquipmentAndQuickSlots.QuickUseSlotCount; ++i)
            {
                var x       = EquipmentAndQuickSlots.QuickUseSlotIndexStart + i;
                var element = GetElement(___m_elements, x, y);
                if (EquipmentAndQuickSlots.QuickSlotsEnabled.Value)
                {
                    element.m_go.SetActive(true);
                    var bindingText = element.m_go.transform.Find("binding").GetComponent <Text>();
                    bindingText.enabled            = true;
                    bindingText.horizontalOverflow = HorizontalWrapMode.Overflow;
                    bindingText.text = EquipmentAndQuickSlots.GetBindingLabel(i);

                    Vector2 offset   = new Vector2(310, 0);
                    Vector2 position = (Vector2) new Vector3((float)x * __instance.m_elementSpace, (float)y * -__instance.m_elementSpace);
                    (element.m_go.transform as RectTransform).anchoredPosition = offset + position;
                }
                else
                {
                    element.m_go.SetActive(false);
                }
            }
        }
Пример #28
0
        public static void RefreshEquipmentInSlots(Player player)
        {
            var inventories        = player.GetAllInventories();
            var equipSlotInventory = player.GetEquipmentSlotInventory();
            var swaps = new List <SwapData>();
            var drops = new List <SwapData>();

            // Swap in newly equipped items
            foreach (var inventory in inventories)
            {
                if (inventory != equipSlotInventory)
                {
                    foreach (var item in inventory.m_inventory)
                    {
                        if (item.m_equiped && EquipmentAndQuickSlots.IsSlotEquippable(item))
                        {
                            var equipSlot = EquipmentAndQuickSlots.GetEquipmentSlotForType(item.m_shared.m_itemType);
                            if (equipSlot.x < 0 || equipSlot.y < 0)
                            {
                                continue;
                            }
                            swaps.Add(new SwapData(inventory, item, equipSlotInventory, equipSlot));
                            EquipmentAndQuickSlots.LogWarning($"move ({item.m_shared.m_name}) to equip slot");
                        }
                    }
                }
            }

            foreach (var swap in swaps)
            {
                Swap(swap.InventoryA, swap.Item, swap.InventoryB, swap.SlotB);
            }
            swaps.Clear();

            // Swap out unequipped items and incorrectly added
            foreach (var item in equipSlotInventory.m_inventory)
            {
                if (!item.m_equiped || !EquipmentAndQuickSlots.IsSlotEquippable(item))
                {
                    var  destInventories = player.GetAllInventories();
                    bool moved           = false;
                    foreach (var destInventory in destInventories)
                    {
                        if (!destInventory.CountAsEmptySlots(player))
                        {
                            continue;
                        }

                        var emptySlot = destInventory.FindEmptySlot(false);
                        if (emptySlot.x >= 0 && emptySlot.y >= 0)
                        {
                            moved = true;
                            swaps.Add(new SwapData(equipSlotInventory, item, destInventory, emptySlot));
                            break;
                        }
                    }

                    EquipmentAndQuickSlots.LogWarning($"move ({item.m_shared.m_name}) to main inventory");
                    if (!moved)
                    {
                        if (!CanEquip(item, player))
                        {
                            player.Message(MessageHud.MessageType.Center, "Item force unequipped, inventory full, dropped item");
                            drops.Add(new SwapData(equipSlotInventory, item, null, new Vector2i()));
                        }
                        else
                        {
                            item.m_equiped = true;
                            player.Message(MessageHud.MessageType.Center, "Could not unequip, inventory full");
                        }
                    }
                }
                else
                {
                    var equipSlot = EquipmentAndQuickSlots.GetEquipmentSlotForType(item.m_shared.m_itemType);
                    if ((equipSlot.x >= 0 && equipSlot.y >= 0) && item.m_gridPos != equipSlot)
                    {
                        item.m_gridPos = equipSlot;
                        EquipmentAndQuickSlots.LogWarning($"move ({item.m_shared.m_name}) to correct slot ({equipSlot})");
                    }
                }
            }

            foreach (var drop in drops)
            {
                ItemDrop.DropItem(drop.Item, drop.Item.m_stack, player.transform.position, Quaternion.identity);
                drop.InventoryA.RemoveItem(drop.Item);
            }
            drops.Clear();

            foreach (var swap in swaps)
            {
                Swap(swap.InventoryA, swap.Item, swap.InventoryB, swap.SlotB);
            }
            swaps.Clear();
        }
Пример #29
0
            public static bool Prefix(HotkeyBar __instance, Player player)
            {
                if (__instance.name != "QuickSlotsHotkeyBar")
                {
                    return(true);
                }

                if (player == null || player.IsDead())
                {
                    foreach (var element in __instance.m_elements)
                    {
                        Object.Destroy(element.m_go);
                    }

                    __instance.m_elements.Clear();
                }
                else
                {
                    player.GetQuickSlotInventory().GetBoundItems(__instance.m_items);
                    __instance.m_items.Sort((x, y) => x.m_gridPos.x.CompareTo(y.m_gridPos.x));
                    const int showElementCount = EquipmentAndQuickSlots.QuickSlotCount;
                    if (__instance.m_elements.Count != showElementCount)
                    {
                        foreach (var element in __instance.m_elements)
                        {
                            Object.Destroy(element.m_go);
                        }

                        __instance.m_elements.Clear();
                        for (var index = 0; index < showElementCount; ++index)
                        {
                            var elementData = new HotkeyBar.ElementData()
                            {
                                m_go = Object.Instantiate(__instance.m_elementPrefab, __instance.transform)
                            };
                            elementData.m_go.transform.localPosition = new Vector3(index * __instance.m_elementSpace, 0.0f, 0.0f);
                            elementData.m_icon       = elementData.m_go.transform.transform.Find("icon").GetComponent <Image>();
                            elementData.m_durability = elementData.m_go.transform.Find("durability").GetComponent <GuiBar>();
                            elementData.m_amount     = elementData.m_go.transform.Find("amount").GetComponent <Text>();
                            elementData.m_equiped    = elementData.m_go.transform.Find("equiped").gameObject;
                            elementData.m_queued     = elementData.m_go.transform.Find("queued").gameObject;
                            elementData.m_selection  = elementData.m_go.transform.Find("selected").gameObject;

                            var bindingText = elementData.m_go.transform.Find("binding").GetComponent <Text>();
                            bindingText.enabled            = true;
                            bindingText.horizontalOverflow = HorizontalWrapMode.Overflow;
                            bindingText.text = EquipmentAndQuickSlots.GetBindingLabel(index);

                            __instance.m_elements.Add(elementData);
                        }
                    }

                    foreach (var element in __instance.m_elements)
                    {
                        element.m_used = false;
                    }

                    var isGamepadActive = ZInput.IsGamepadActive();
                    foreach (var itemData in __instance.m_items)
                    {
                        var element = __instance.m_elements[itemData.m_gridPos.x];
                        element.m_used = true;
                        element.m_icon.gameObject.SetActive(true);
                        element.m_icon.sprite = itemData.GetIcon();
                        element.m_durability.gameObject.SetActive(itemData.m_shared.m_useDurability);
                        if (itemData.m_shared.m_useDurability)
                        {
                            if (itemData.m_durability <= 0.0)
                            {
                                element.m_durability.SetValue(1f);
                                element.m_durability.SetColor((double)Mathf.Sin(Time.time * 10f) > 0.0 ? Color.red : new Color(0.0f, 0.0f, 0.0f, 0.0f));
                            }
                            else
                            {
                                element.m_durability.SetValue(itemData.GetDurabilityPercentage());
                                element.m_durability.ResetColor();
                            }
                        }

                        element.m_equiped.SetActive(itemData.m_equiped);
                        element.m_queued.SetActive(player.IsItemQueued(itemData));
                        if (itemData.m_shared.m_maxStackSize > 1)
                        {
                            element.m_amount.gameObject.SetActive(true);
                            element.m_amount.text = itemData.m_stack.ToString() + "/" + itemData.m_shared.m_maxStackSize.ToString();
                        }
                        else
                        {
                            element.m_amount.gameObject.SetActive(false);
                        }
                    }

                    for (var index = 0; index < __instance.m_elements.Count; ++index)
                    {
                        var element = __instance.m_elements[index];
                        element.m_selection.SetActive(isGamepadActive && index == __instance.m_selected);
                        if (!element.m_used)
                        {
                            element.m_icon.gameObject.SetActive(false);
                            element.m_durability.gameObject.SetActive(false);
                            element.m_equiped.SetActive(false);
                            element.m_queued.SetActive(false);
                            element.m_amount.gameObject.SetActive(false);
                        }
                    }
                }

                return(false);
            }
Пример #30
0
        public static bool Prefix(Inventory __instance, ref Vector2i __result, bool topFirst, int ___m_height, int ___m_width)
        {
            if (__instance.GetName() != "Inventory")
            {
                return(true);
            }

            if (topFirst)
            {
                for (int index1 = 0; index1 < ___m_height; ++index1)
                {
                    if (!EquipmentAndQuickSlots.QuickSlotsEnabled.Value && index1 == ___m_height - 1)
                    {
                        continue;
                    }

                    for (int index2 = 0; index2 < ___m_width; ++index2)
                    {
                        if (EquipmentAndQuickSlots.IsEquipmentSlot(index2, index1))
                        {
                            continue;
                        }

                        if (__instance.GetItemAt(index2, index1) == null)
                        {
                            __result = new Vector2i(index2, index1);
                            return(false);
                        }
                    }
                }
            }
            else
            {
                // Skip the last row
                for (int index1 = ___m_height - 2; index1 >= 0; --index1)
                {
                    for (int index2 = 0; index2 < ___m_width; ++index2)
                    {
                        if (__instance.GetItemAt(index2, index1) == null)
                        {
                            __result = new Vector2i(index2, index1);
                            return(false);
                        }
                    }
                }

                if (EquipmentAndQuickSlots.QuickSlotsEnabled.Value)
                {
                    // Then do the bonus quick slots last
                    for (int index = 0; index < EquipmentAndQuickSlots.QuickUseSlotCount; ++index)
                    {
                        var slotPosition = EquipmentAndQuickSlots.GetQuickSlotPosition(index);
                        if (__instance.GetItemAt(slotPosition.x, slotPosition.y) == null)
                        {
                            __result = slotPosition;
                            return(false);
                        }
                    }
                }
            }
            __result = new Vector2i(-1, -1);

            return(false);
        }