Exemple #1
0
        protected override bool SharedSlotClicked(WindowClickPacket packet)
        {
            if (packet.Slot == (short)FurnaceSlots.Output)
            {
                if (ItemHelper.IsVoid(Container[packet.Slot]))
                {
                    Owner.Client.SendPacket(new TransactionPacket
                    {
                        Accepted    = false,
                        Transaction = packet.Transaction,
                        WindowId    = packet.WindowId
                    });
                    return(false);
                }
                var output = Container[packet.Slot];
                if (!ItemHelper.IsVoid(Cursor))
                {
                    if (!Cursor.StacksWith(output) || (Cursor.StacksWith(output) && Cursor.Count >= 64))
                    {
                        Owner.Client.SendPacket(new TransactionPacket
                        {
                            Accepted    = false,
                            Transaction = packet.Transaction,
                            WindowId    = packet.WindowId
                        });
                        return(false);
                    }
                }
                var newOutput = ItemHelper.Void;
                if (ItemHelper.IsVoid(Cursor))
                {
                    Cursor            = ItemHelper.GetInstance(output.Type);
                    Cursor.Count      = output.Count;
                    Cursor.Durability = output.Durability;
                    Cursor.Damage     = output.Damage;
                }
                else
                {
                    int freeSpaceInCursor = 64 - Cursor.Count;
                    int takeFromOutput    = (output.Count > freeSpaceInCursor ? freeSpaceInCursor : output.Count);
                    Cursor.Count += (sbyte)takeFromOutput;
                    if (takeFromOutput < output.Count)
                    {
                        newOutput            = ItemHelper.GetInstance(output.Type);
                        newOutput.Count      = (sbyte)(output.Count - takeFromOutput);
                        newOutput.Durability = output.Durability;
                        newOutput.Damage     = output.Damage;
                    }
                }
                Container.ChangeSlot(Handle, packet.Slot, newOutput);
                this[(short)FurnaceSlots.Output] = newOutput;
                return(false);
            }

            return(base.SharedSlotClicked(packet));
        }
Exemple #2
0
        public static void ReadWindowClick(Client client, PacketReader reader)
        {
            WindowClickPacket wc = new WindowClickPacket();

            wc.Read(reader);

            if (!reader.Failed)
            {
                Client.HandlePacketWindowClick(client, wc);
            }
        }
Exemple #3
0
        protected override bool SharedSlotClicked(WindowClickPacket packet)
        {
            if (packet.Slot == (short)FurnaceSlots.Output)
            {
                if (Container[packet.Slot].IsVoid())
                {
                    Owner.Client.SendPacket(new TransactionPacket
                    {
                        Accepted    = false,
                        Transaction = packet.Transaction,
                        WindowId    = packet.WindowId
                    });
                    return(false);
                }
                ItemStack output = Container[packet.Slot];
                if (!Cursor.IsVoid())
                {
                    if (!Cursor.StacksWith(output) || (Cursor.StacksWith(output) && Cursor.Count >= 64))
                    {
                        Owner.Client.SendPacket(new TransactionPacket
                        {
                            Accepted    = false,
                            Transaction = packet.Transaction,
                            WindowId    = packet.WindowId
                        });
                        return(false);
                    }
                }
                ItemStack newOutput = ItemStack.Void;
                if (Cursor.IsVoid())
                {
                    Cursor      = new ItemStack(output.Type, output.Count, output.Durability);
                    Cursor.Slot = -1;
                }
                else
                {
                    int freeSpaceInCursor = 64 - Cursor.Count;
                    int takeFromOutput    = (output.Count > freeSpaceInCursor ? freeSpaceInCursor : output.Count);
                    Cursor.Count += (sbyte)takeFromOutput;
                    if (takeFromOutput < output.Count)
                    {
                        newOutput = new ItemStack(output.Type, (sbyte)(output.Count - takeFromOutput), output.Durability);
                    }
                }
                Container.ChangeSlot(Handle, packet.Slot, newOutput);
                this[(short)FurnaceSlots.Output] = newOutput;
                return(false);
            }

            return(base.SharedSlotClicked(packet));
        }
        protected virtual bool SharedSlotClicked(WindowClickPacket packet)
        {
            if (Container.SlotCanBeChanged(packet))
            {
                return(true);
            }

            Owner.Client.SendPacket(new TransactionPacket
            {
                Accepted    = false,
                Transaction = packet.Transaction,
                WindowId    = packet.WindowId
            });
            return(false);
        }
 internal override void OnClicked(WindowClickPacket packet)
 {
     if (IsSharedSlot(packet.Slot))
     {
         if (!SharedSlotClicked(packet))
         {
             return;
         }
         base.OnClicked(packet);
         Container.ChangeSlot(packet.WindowId, packet.Slot, this[packet.Slot]);
     }
     else
     {
         base.OnClicked(packet);
     }
 }
Exemple #6
0
        public InterfaceClickedEventArgs(Interface iface, WindowClickPacket packet)
        {
            this.Interface   = iface;
            this.Slot        = packet.Slot;
            this.MouseButton = packet.MouseButton;
            this.Transaction = packet.Transaction;

            if (Slot < 0)
            {
                Slot     = 0;
                Location = ClickLocation.Void;
            }
            else if (Slot < Interface.SlotCount)
            {
                Location = ClickLocation.Interface;
            }
            else
            {
                Location = ClickLocation.Inventory;
                Slot     = (short)(Slot - Interface.SlotCount + 9);
            }
        }
Exemple #7
0
        internal virtual void OnClicked(WindowClickPacket packet)
        {
            InterfaceClickedEventArgs e = new InterfaceClickedEventArgs(this, packet);

            if (Clicked != null)
            {
                Clicked.Invoke(this, e);
            }

            StartTransaction(); // Don't send update packets while we process this transaction, as that would be redundant.
            try
            {
                Interface target = null;
                switch (e.Location)
                {
                case ClickLocation.Void:
                    if (ItemHelper.IsVoid(Cursor))
                    {           // Empty click in void: ignore
                        e.Cancel();
                    }
                    switch (e.MouseButton)
                    {
                    case WindowClickPacket.MouseButtonClicked.Right:
                        // Right-click in void: drop item
                        var item = ItemHelper.GetInstance(Cursor.Type);
                        item.Durability = Cursor.Durability;
                        item.Damage     = Cursor.Damage;
                        item.Count      = 1;
                        Owner.Server.DropItem(Owner, item);
                        Cursor.Count--;
                        break;

                    case WindowClickPacket.MouseButtonClicked.Left:
                        // Left-click in void: drop stack
                        Owner.Server.DropItem(Owner, Cursor);
                        Cursor = ItemHelper.Void;
                        break;
                    }

                    return;

                case ClickLocation.Interface:
                    target = e.Interface;
                    break;

                case ClickLocation.Inventory:
                    target = Owner.Inventory;
                    break;
                }

                // Ensure a true void stack for our calculations
                if (ItemHelper.IsVoid(Cursor))
                {
                    Cursor = ItemHelper.Void;
                }
                if (ItemHelper.IsVoid(target._slots[e.Slot]))
                {
                    target[e.Slot] = ItemHelper.Void;
                }

                // The fun begins.
                if (target._slots[e.Slot].StacksWith(Cursor))
                {
                    if (ItemHelper.IsVoid(Cursor))
                    {   // Useless click
                        e.Cancel();
                    }
                    else if (e.MouseButton == WindowClickPacket.MouseButtonClicked.Right)
                    {     // Right-click on same item
                        if (target._slots[e.Slot].Count >= 64)
                        { // Stack is already full: ignore
                            e.Cancel();
                        }
                        else
                        {       // Increment stack
                            target[e.Slot].Count++;
                            Cursor.Count--;
                        }
                    }
                    else
                    {
                        // Left-click on same item
                        int total = target._slots[e.Slot].Count + Cursor.Count;
                        if (total <= 64)
                        {       // Move all items to stack
                            target[e.Slot].Count = unchecked ((sbyte)total);
                            Cursor.Count         = 0;
                        }
                        else
                        {       // Make stack 64, and put remainder in cursor
                            target[e.Slot].Count = 64;
                            Cursor.Count         = unchecked ((sbyte)(total - 64));
                        }
                    }
                }
                else if (!ItemHelper.IsVoid(Cursor) && (e.MouseButton == WindowClickPacket.MouseButtonClicked.Right) && ItemHelper.IsVoid(target._slots[e.Slot]))
                {
                    // Right-click on empty slot with items in cursor: drop one item from Cursor into slot

                    target[e.Slot]       = Cursor.Clone();
                    target[e.Slot].Count = 1;
                    Cursor.Count--;
                    if (Cursor.Count == 0)
                    {
                        Cursor = ItemHelper.Void;
                    }
                }
                else if (e.MouseButton == WindowClickPacket.MouseButtonClicked.Right && ItemHelper.IsVoid(Cursor))
                {       // Right-click with empty cursor: split stack in half
                    sbyte count = target._slots[e.Slot].Count;
                    target[e.Slot].Count /= 2;
                    count       -= target._slots[e.Slot].Count;
                    Cursor       = target._slots[e.Slot].Clone();
                    Cursor.Count = count;
                    //Cursor = new ItemStack(target.Slots[e.Slot].Type, (sbyte)count, target.Slots[e.Slot].Durability);
                }
                else if (e.MouseButton == WindowClickPacket.MouseButtonClicked.Right)
                {       // Right-click on different type: ignored click
                    e.Cancel();
                }
                else
                {       // Left-click on different type: swap stacks
                    var swap = target[e.Slot].Clone();
                    target[e.Slot] = Cursor;
                    Cursor         = swap;
                }
            }
            catch (Exception ex)
            {
                e.Cancel();
                Owner.Client.SendMessage("§cInventory Error: " + ex.Message);
                Owner.Client.Logger.Log(ex);
            }
            finally
            {
                Owner.Client.SendPacket(new TransactionPacket
                {
                    Accepted    = !e.Cancelled,
                    Transaction = e.Transaction,
                    WindowId    = e.Interface.Handle
                });
                EndTransaction();
            }
        }
Exemple #8
0
        internal override void OnClicked(WindowClickPacket packet)
        {
            if (packet.Slot == 0 && !this[0].IsVoid())
            {
                if (!Cursor.IsVoid())
                {
                    if (Cursor.Type != this[0].Type || Cursor.Durability != this[0].Durability || Cursor.Count + this[0].Count > 64)
                    {
                        Owner.Client.SendPacket(new TransactionPacket
                        {
                            Accepted    = false,
                            Transaction = packet.Transaction,
                            WindowId    = packet.WindowId
                        });
                        return;
                    }
                    // TODO: Why was this here? We can't modify the this[0] item as this will change the result of the recipe (it is currently a reference to recipe.Result)
                    //this[0].Count += Cursor.Count;
                    //Cursor = ItemStack.Void;
                }
                else
                {
                    this.Cursor            = ItemStack.Void;
                    this.Cursor.Slot       = -1;
                    this.Cursor.Type       = this[0].Type;
                    this.Cursor.Durability = this[0].Durability;
                }

                // Add the newly crafted item to the Cursor
                this.Cursor.Count += this[0].Count;

                // Cook Ingredients, and update recipe output slot in case ingredients are now insufficient for another
                if (!this[0].IsVoid())
                {
                    Recipe recipe = GetRecipe();
                    if (recipe != null)
                    {
                        List <ItemStack> ingredients = new List <ItemStack>();
                        for (short i = 1; i <= this.CraftingSlotCount; i++)
                        {
                            ingredients.Add(Slots[i].IsVoid() ? ItemStack.Void : this[i]);
                        }

                        // Use the ingredients
                        recipe.UseIngredients(ingredients.ToArray());

                        // Check if any now have a count of 0 then set the slot to void
                        foreach (var item in ingredients)
                        {
                            if (!item.IsVoid() && item.Count <= 0) // should never be less than 0, just some defensive coding
                            {
                                this[item.Slot] = ItemStack.Void;
                            }
                        }

                        // We have to try and get the recipe again to make sure there is enough ingredients left to do one more
                        recipe = GetRecipe();
                        if (recipe == null)
                        {
                            // Not enough ingredients, set recipe output slot to void item
                            this[0] = ItemStack.Void;
                        }
                    }
                }
            }
            else
            {
                base.OnClicked(packet);

                // If one of the ingredient slots have just been updated, update the contents of the recipe output slot
                if (packet.Slot >= 1 && packet.Slot <= this.CraftingSlotCount)
                {
                    Recipe recipe = GetRecipe();
                    if (recipe == null)
                    {
                        this[0] = ItemStack.Void;
                    }
                    else
                    {
                        this[0] = recipe.Result;
                    }
                }
            }
        }
Exemple #9
0
        public static void HandlePacketWindowClick(Client client, WindowClickPacket packet)
        {
            Interface iface = client.Owner.CurrentInterface ?? client.Owner.Inventory;

            iface.OnClicked(packet);
        }