Advertisement
Guest User

Untitled

a guest
Sep 28th, 2016
55
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.25 KB | None | 0 0
  1. public static void DropItem(Room room, Player player, string userInput, string commandKey)
  2. {
  3. var currentRoom = room;
  4. var currentPlayer = player;
  5. string[] all = userInput.Split();
  6.  
  7. KeyValuePair<Item, Item> returnedItem = (KeyValuePair<Item, Item>)FindObject(room, player, commandKey, userInput, "inventory");
  8.  
  9. var container = returnedItem.Key;
  10. var item = returnedItem.Value;
  11.  
  12. if (all[0].Equals("all", StringComparison.InvariantCultureIgnoreCase))
  13. {
  14. var playerInv = player.Inventory;
  15. var playerInvCount = player.Inventory.Count;
  16.  
  17. for (int i = playerInvCount - 1; i >= 0; i--)
  18. {
  19. playerInv[i].location = Item.ItemLocation.Room;
  20. if (container == null)
  21. {
  22. room.items.Add(playerInv[i]);
  23. HubContext.getHubContext.Clients.Client(player.HubGuid).addNewMessageToPage("You drop a " + playerInv[i].name);
  24. HubContext.getHubContext.Clients.AllExcept(player.HubGuid).addNewMessageToPage(player.Name + " drops a " + playerInv[i].name);
  25. }
  26. else
  27. {
  28. container.containerItems.Add(playerInv[i]);
  29. HubContext.getHubContext.Clients.Client(player.HubGuid).addNewMessageToPage("You drop a " + playerInv[i].name + " into a " + container.name);
  30. HubContext.getHubContext.Clients.AllExcept(player.HubGuid).addNewMessageToPage(player.Name + " drops a " + playerInv[i].name + " into a " + container.name);
  31. }
  32. player.Inventory.Remove(playerInv[i]);
  33. }
  34. }
  35. else
  36. {
  37. if (item == null)
  38. {
  39. return;
  40. }
  41. player.Inventory.Remove(item);
  42. item.location = Item.ItemLocation.Room;
  43. if (container == null)
  44. {
  45. room.items.Add(item);
  46.  
  47. HubContext.getHubContext.Clients.Client(player.HubGuid).addNewMessageToPage("You drop a " + item.name);
  48. HubContext.getHubContext.Clients.AllExcept(player.HubGuid).addNewMessageToPage(player.Name + " drops a " + item.name);
  49. }
  50. else
  51. {
  52. container.containerItems.Add(item);
  53.  
  54. HubContext.getHubContext.Clients.Client(player.HubGuid).addNewMessageToPage("You put a " + item.name + " inside the " + container.name);
  55. HubContext.getHubContext.Clients.AllExcept(player.HubGuid).addNewMessageToPage(player.Name + " puts a " + item.name + " inside the " + container.name);
  56. }
  57. }
  58. //save to cache
  59. Cache.updateRoom(room, currentRoom);
  60. Cache.updatePlayer(player, currentPlayer);
  61. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement