protected virtual void ProcessTakeAction(TakeAction action, List <StackResponseContainerInfo> stackResponses)
        {
            byte count = action.Count;
            Item sourceItem;
            Item destItem;
            StackRequestSlotInfo source      = action.Source;
            StackRequestSlotInfo destination = action.Destination;

            sourceItem = GetContainerItem(source.ContainerId, source.Slot);
            Log.Debug($"Take {sourceItem}");

            if (sourceItem.Count == count || sourceItem.Count - count <= 0)
            {
                destItem            = sourceItem;
                sourceItem          = new ItemAir();
                sourceItem.UniqueId = 0;
                SetContainerItem(source.ContainerId, source.Slot, sourceItem);
            }
            else
            {
                destItem          = (Item)sourceItem.Clone();
                sourceItem.Count -= count;
                destItem.Count    = count;
                destItem.UniqueId = Environment.TickCount & Int32.MaxValue;
            }

            SetContainerItem(destination.ContainerId, destination.Slot, destItem);

            if (source.ContainerId == 21 || source.ContainerId == 22)
            {
                if (!(GetContainerItem(21, 14) is ItemAir) && !(GetContainerItem(22, 15) is ItemAir))
                {
                    Enchantment.SendEnchantments(_player, GetContainerItem(21, 14));
                }
                else
                {
                    Enchantment.SendEmptyEnchantments(_player);
                }
            }

            stackResponses.Add(new StackResponseContainerInfo
            {
                ContainerId = source.ContainerId,
                Slots       = new List <StackResponseSlotInfo>
                {
                    new StackResponseSlotInfo()
                    {
                        Count          = sourceItem.Count,
                        Slot           = source.Slot,
                        HotbarSlot     = source.Slot,
                        StackNetworkId = sourceItem.UniqueId
                    }
                }
            });
            stackResponses.Add(new StackResponseContainerInfo
            {
                ContainerId = destination.ContainerId,
                Slots       = new List <StackResponseSlotInfo>
                {
                    new StackResponseSlotInfo()
                    {
                        Count          = destItem.Count,
                        Slot           = destination.Slot,
                        HotbarSlot     = destination.Slot,
                        StackNetworkId = destItem.UniqueId
                    }
                }
            });
        }
예제 #2
0
        protected virtual void ProcessPlaceAction(PlaceAction action, List <StackResponseContainerInfo> stackResponses)
        {
            byte count = action.Count;
            Item sourceItem;
            Item destItem;
            StackRequestSlotInfo source      = action.Source;
            StackRequestSlotInfo destination = action.Destination;

            sourceItem = GetContainerItem(source.ContainerId, source.Slot);

            if (sourceItem.Count == count || sourceItem.Count - count <= 0)
            {
                destItem            = sourceItem;
                sourceItem          = new ItemAir();
                sourceItem.UniqueId = 0;
                SetContainerItem(source.ContainerId, source.Slot, sourceItem);
            }
            else
            {
                destItem          = (Item)sourceItem.Clone();
                sourceItem.Count -= count;
                destItem.Count    = count;
                destItem.UniqueId = Environment.TickCount;
            }

            Item existingItem = GetContainerItem(destination.ContainerId, destination.Slot);

            if (existingItem.UniqueId > 0)             // is empty/air is what this means
            {
                existingItem.Count += count;
                destItem            = existingItem;
            }
            else
            {
                SetContainerItem(destination.ContainerId, destination.Slot, destItem);
            }

            if (destination.ContainerId == 21 || destination.ContainerId == 22)
            {
                if (!(GetContainerItem(21, 14) is ItemAir) && !(GetContainerItem(22, 15) is ItemAir))
                {
                    Enchantment.SendEnchantments(_player, GetContainerItem(21, 14));
                }
                else
                {
                    Enchantment.SendEmptyEnchantments(_player);
                }
            }

            stackResponses.Add(new StackResponseContainerInfo
            {
                ContainerId = source.ContainerId,
                Slots       = new List <StackResponseSlotInfo>
                {
                    new StackResponseSlotInfo()
                    {
                        Count          = sourceItem.Count,
                        Slot           = source.Slot,
                        HotbarSlot     = source.Slot,
                        StackNetworkId = sourceItem.UniqueId
                    }
                }
            });
            stackResponses.Add(new StackResponseContainerInfo
            {
                ContainerId = destination.ContainerId,
                Slots       = new List <StackResponseSlotInfo>
                {
                    new StackResponseSlotInfo()
                    {
                        Count          = destItem.Count,
                        Slot           = destination.Slot,
                        HotbarSlot     = destination.Slot,
                        StackNetworkId = destItem.UniqueId
                    }
                }
            });
        }