public override MoveItemsResult ClientTryTakeAllItems( ICharacter character, IItemsContainer fromContainer, bool showNotificationIfInventoryFull = true) { if (fromContainer.OccupiedSlotsCount == 0) { // no items to move return(new MoveItemsResult() { AreAllItemMoved = true }); } var privateState = GetPrivateState(character); var containerHotbar = privateState.ContainerHotbar; var containerInventory = privateState.ContainerInventory; // define a function for spawning item at specified container var clientItemsService = Client.Items; var result = new MoveItemsResult(); bool TryMoveItemsTo(IItemsContainer toContainer, bool onlyToExistingStacks) { var movedItemResult = clientItemsService.TryMoveAllItems( fromContainer, toContainer, onlyToExistingStacks); if (movedItemResult.MovedItems.Count == 0) { // cannot move any item return(false); } // something moved (perhaps all) result.MergeWith(movedItemResult, areAllItemsMoved: movedItemResult.AreAllItemMoved); return(movedItemResult.AreAllItemMoved); } // 1. Try to add to existing stacks in hotbar. // 3. Try to add to existing stacks or move to in inventory. // 3. Try to move to in hotbar. if (TryMoveItemsTo(containerHotbar, onlyToExistingStacks: true) || TryMoveItemsTo(containerInventory, onlyToExistingStacks: false) || TryMoveItemsTo(containerHotbar, onlyToExistingStacks: false)) { // all items are moved! } if (result.MovedItems.Count > 0) { ItemsSoundPresets.ItemGeneric.PlaySound(ItemSound.Pick); } if (!result.AreAllItemMoved && showNotificationIfInventoryFull) { NotificationSystem.ClientShowNotificationNoSpaceInInventory(); } return(result); }
private void ExecuteCommandMatch(bool isUp) { var playerPrivateState = PlayerCharacter.GetPrivateState(Character); var playerInventory = playerPrivateState.ContainerInventory; var playerHotbar = playerPrivateState.ContainerHotbar; var receivingContainers = new List <IItemsContainer>(); IEnumerable <IItem> sourceItems; if (isUp) { // move items "up" - from player inventory to this crate container sourceItems = playerInventory.Items; receivingContainers.AddRange(inputContainers); foreach (var receivingContainer in receivingContainers) { ClientContainerSortHelper.ConsolidateItemStacks((IClientItemsContainer)receivingContainer); } } else { // move items "down" - from this crate container to player containers sourceItems = outputContainers.SelectMany(i => i.Items); receivingContainers.Add(playerInventory); receivingContainers.Add(playerHotbar); } var isAtLeastOneItemMoved = false; if (isUp && isInsertingWithoutMatch) { foreach (var itemToMove in sourceItems.OrderBy(i => i.ProtoItem.Id)) { if (receivingContainers .Any(it => ItemsService.MoveOrSwapItem(itemToMove, it, allowSwapping: false, isLogErrors: false))) { isAtLeastOneItemMoved = true; } } if (isAtLeastOneItemMoved) { ItemsSoundPresets.ItemGeneric.PlaySound(ItemSound.Drop); } return; } var itemTypesToMove = new HashSet <IProtoItem>(receivingContainers.SelectMany(i => i.Items).Select(i => i.ProtoItem)); var itemsToMove = sourceItems .Where(item => itemTypesToMove.Contains(item.ProtoItem)) .OrderBy(i => i.ProtoItem.Id) .ToList(); foreach (var itemToMove in itemsToMove) { if (receivingContainers .Any(it => ItemsService.MoveOrSwapItem(itemToMove, it, allowSwapping: false, isLogErrors: false))) { isAtLeastOneItemMoved = true; } } if (isAtLeastOneItemMoved) { ItemsSoundPresets.ItemGeneric.PlaySound(ItemSound.Drop); } if (!isUp && itemsToMove.Any(i => outputContainers.Contains(i.Container))) { // at least one item stuck in the container when matching down // it means there are not enough space NotificationSystem.ClientShowNotificationNoSpaceInInventory(); } }