public void ValidateAndPerformInventoryRequest(InventoryOperationRequest request, Player p) { if (InventoryOperationRequest.validateRequest(request, p.info)) { InventoryOperationRequest.performInventoryRequest(request, p); } }
public void CmdRequestInventoryActions(byte[] operationInfo) { NetworkReader reader = new NetworkReader(operationInfo); InventoryOperationRequest request = new InventoryOperationRequest(InventoryOperationRequest.Operation.FromCursor, InventoryOperationRequest.InventoryType.Ground, 0); request.Deserialize(reader); Debug.Log("recieved inventory request\nop:" + request.op + "\nquant: " + request.quantity + "\nswapinv: " + request.swapInv + "\nswapslot" + request.swapInvSlot); if (InventoryOperationRequest.validateRequest(request, info)) { ItemInventorySlot dropped = InventoryOperationRequest.performInventoryRequest(request, this); SpawnManager spawnManager = GameObject.FindGameObjectWithTag("SpawnManager").GetComponent <SpawnManager> (); Debug.Log("player dropping " + dropped.getQuantity() + " " + dropped.getItem() + " items"); spawnManager.SpawnPlayerDroppedItem(dropped.getItem(), dropped.getQuantity(), controller); } else { Debug.Log("recieved bad inventory request! client may be out of sync"); } }
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; } } }