protected virtual void ProcessDestroyAction(DestroyAction action, List <StackResponseContainerInfo> stackResponses)
        {
            byte count = action.Count;
            StackRequestSlotInfo source = action.Source;

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

            sourceItem.Count -= count;
            if (sourceItem.Count <= 0)
            {
                sourceItem = new ItemAir();
                SetContainerItem(source.ContainerId, source.Slot, sourceItem);
            }

            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
                    }
                }
            });
        }
        protected virtual void ProcessSwapAction(SwapAction action, List <StackResponseContainerInfo> stackResponses)
        {
            StackRequestSlotInfo source      = action.Source;
            StackRequestSlotInfo destination = action.Destination;

            Item sourceItem = GetContainerItem(source.ContainerId, source.Slot);
            Item destItem   = GetContainerItem(destination.ContainerId, destination.Slot);

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

            if (source.ContainerId == 21 || source.ContainerId == 22 || 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          = destItem.Count,
                        Slot           = source.Slot,
                        HotbarSlot     = source.Slot,
                        StackNetworkId = destItem.UniqueId
                    }
                }
            });
            stackResponses.Add(new StackResponseContainerInfo
            {
                ContainerId = destination.ContainerId,
                Slots       = new List <StackResponseSlotInfo>
                {
                    new StackResponseSlotInfo()
                    {
                        Count          = sourceItem.Count,
                        Slot           = destination.Slot,
                        HotbarSlot     = destination.Slot,
                        StackNetworkId = sourceItem.UniqueId
                    }
                }
            });
        }
        protected virtual void ProcessDropAction(DropAction action, List <StackResponseContainerInfo> stackResponses)
        {
            byte count = action.Count;
            Item dropItem;
            StackRequestSlotInfo source = action.Source;

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

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

            _player.DropItem(dropItem);

            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
                    }
                }
            });
        }
        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
                    }
                }
            });
        }
Пример #5
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
                    }
                }
            });
        }