public int AddItemManyToSlot(Item item, int quantity, int slotNum) { if (slotNum >= slots.Length || slotNum < 0) { return(-1); } ItemInventorySlot s = slots [slotNum]; if (s.isEmpty()) { return(setSlot(item, quantity, slotNum)); } else { if (s.isAddableItem(item)) { return(s.addItemMany(item, quantity)); } else { return(-1); } } }
public Sprite getIcon() { if (slot == null) { return(transparent); } else if (slot.isEmpty()) { return(transparent); } else { return(slot.getIcon()); } }
void handleSlotSelect(ItemInventorySlotUI slotUI, string menuIdentifier, string slotIdentifier, int quantity) { InventoryOperationRequest.InventoryType menuType = InventoryOperationRequest.InventoryType.Ground; InventoryOperationRequest req = null; if (menuIdentifier.Equals("BeltSlot")) { menuType = InventoryOperationRequest.InventoryType.Belt; } else if (menuIdentifier.Equals("BackpackSlot")) { menuType = InventoryOperationRequest.InventoryType.Backpack; } else if (menuIdentifier.Equals("EquipSlot")) { menuType = InventoryOperationRequest.InventoryType.Equip; } if (slotUI == null) //THREW IT ON THE GROUND { req = new InventoryOperationRequest(InventoryOperationRequest.Operation.FromCursor, InventoryOperationRequest.InventoryType.Ground, System.Int32.Parse(slotIdentifier), quantity); } else if (cursorSlot.getSlotBackingInfo().isEmpty()) { req = new InventoryOperationRequest(InventoryOperationRequest.Operation.ToCursor, menuType, System.Int32.Parse(slotIdentifier), quantity); } else { req = new InventoryOperationRequest(InventoryOperationRequest.Operation.FromCursor, menuType, System.Int32.Parse(slotIdentifier), quantity); } //perform local changes before sending info to server. Annoying to wait on server for ui change. If sync error, server should let us know eventually and fix if (InventoryOperationRequest.validateRequest(req, localPlayer.info)) //perform check server will do to verify before performing locally { ItemInventorySlot dropped = InventoryOperationRequest.performInventoryRequest(req, localPlayer); if (!localPlayer.isServer) { sendInventoryUpdateToServer(req); } else { //host drops items if (!dropped.isEmpty()) { SpawnManager spawnManager = GameObject.FindGameObjectWithTag("SpawnManager").GetComponent <SpawnManager>(); spawnManager.SpawnPlayerDroppedItem(dropped.getItem(), dropped.getQuantity(), localPlayer.controller); } } cursorSlot.updateUI(); switch (menuType) { case InventoryOperationRequest.InventoryType.Belt: beltUI.updateUI(); break; case InventoryOperationRequest.InventoryType.Backpack: backpackUI.updateUI(); break; case InventoryOperationRequest.InventoryType.Equip: if (slotIdentifier.Equals("6")) { if (localPlayer.info.backpack == null) { backpackUI.loadInventory(null); } else { backpackUI.loadInventory(localPlayer.info.backpack.inventory); } } equipUI.updateUI(localPlayer.info); break; } } }