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); }
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); }
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); } }); }
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; }
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(); }