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