internal override void OnClicked(WindowClickPacket packet) { if (IsSharedSlot(packet.Slot)) { if (!SharedSlotClicked(packet)) return; base.OnClicked(packet); Container.ChangeSlot(packet.WindowId, packet.Slot, Slots[packet.Slot]); } else base.OnClicked(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; }
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); }
public InterfaceClickedEventArgs(Interface iface, WindowClickPacket packet) { this.Interface = iface; this.Slot = packet.Slot; this.RightClick = packet.RightClick; 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); } }
private void OnWindowClick(WindowClickPacket p) { if (WindowClick != null) WindowClick.Invoke(this, new PacketEventArgs<WindowClickPacket>(p)); }
public static void HandlePacketWindowClick(Client client, WindowClickPacket packet) { Interface iface = client.Owner.CurrentInterface ?? client.Owner.Inventory; iface.OnClicked(packet); }
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; } } } }
public static void ReadWindowClick(Client client, PacketReader reader) { WindowClickPacket wc = new WindowClickPacket(); wc.Read(reader); if (!reader.Failed) Client.HandlePacketWindowClick(client, wc); }
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 (ItemStack.IsVoid(Cursor)) { // Empty click in void: ignore e.Cancel(); } else if (e.RightClick) { // Right-click in void: drop item Client.Server.DropItem(Client, new ItemStack(Cursor.Type, 1, Cursor.Durability)); Cursor.Count--; } else { // Left-click in void: drop stack Client.Server.DropItem(Client, Cursor); Cursor = ItemStack.Void; } return; case ClickLocation.Interface: target = e.Interface; break; case ClickLocation.Inventory: target = Client.Inventory; break; } // Ensure a true void stack for our calculations if (ItemStack.IsVoid(Cursor)) Cursor = ItemStack.Void; if (ItemStack.IsVoid(target.Slots[e.Slot])) target[e.Slot] = ItemStack.Void; // The fun begins. if (target.Slots[e.Slot].StacksWith(Cursor)) { if (ItemStack.IsVoid(Cursor)) { // Useless click e.Cancel(); } else if (e.RightClick) { // Right-click on same item if (target.Slots[e.Slot].Count >= 64) { // Stack is already full: ignore e.Cancel(); } else { // Increment stack target.Slots[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.Slots[e.Slot].Count = unchecked((sbyte)total); Cursor.Count = 0; } else { // Make stack 64, and put remainder in cursor target.Slots[e.Slot].Count = 64; Cursor.Count = unchecked((sbyte)(total - 64)); } } } else if (!ItemStack.IsVoid(Cursor) && e.RightClick && ItemStack.IsVoid(target.Slots[e.Slot])) { // Right-click on empty slot with items in cursor: drop one item from Cursor into slot target.Slots[e.Slot].Type = Cursor.Type; target.Slots[e.Slot].Durability = Cursor.Durability; target.Slots[e.Slot].Count = 1; Cursor.Count--; if (Cursor.Count == 0) Cursor = ItemStack.Void; } else if (e.RightClick && ItemStack.IsVoid(Cursor)) { // Right-click with empty cursor: split stack in half int count = target.Slots[e.Slot].Count; target.Slots[e.Slot].Count /= 2; count -= target.Slots[e.Slot].Count; Cursor = new ItemStack(target.Slots[e.Slot].Type, (sbyte)count, target.Slots[e.Slot].Durability); } else if (e.RightClick) { // Right-click on different type: ignored click e.Cancel(); } else { // Left-click on different type: swap stacks ItemStack swap = target[e.Slot]; target[e.Slot] = Cursor; Cursor = swap; } } catch (Exception ex) { e.Cancel(); Client.SendMessage("§cInventory Error: " + ex.Message); Client.Logger.Log(ex); } finally { PacketHandler.SendPacket(new TransactionPacket { Accepted = !e.Cancelled, Transaction = e.Transaction, WindowId = e.Interface.Handle }); EndTransaction(); } }
internal override void OnClicked(WindowClickPacket packet) { ItemStack newItem = ItemStack.Void; if (packet.Slot == (short)FurnaceSlots.Output) { lock (_furnaceInstance) { if (!ItemStack.IsVoid(Cursor)) { Owner.Client.SendPacket(new TransactionPacket { Accepted = false, Transaction = packet.Transaction, WindowId = packet.WindowId }); return; //if (!Cursor.StacksWith(this[OUTPUT_SLOT]) || Cursor.Count + this[OUTPUT_SLOT].Count > 64) //{} } else { Cursor = ItemStack.Void; Cursor.Slot = -1; Cursor.Type = this[(short)FurnaceSlots.Output].Type; Cursor.Durability = this[(short)FurnaceSlots.Output].Durability; // Add the output item to the Cursor Cursor.Count += this[(short)FurnaceSlots.Output].Count; this[(short)FurnaceSlots.Output] = ItemStack.Void; _furnaceInstance.ChangeOutput(ItemStack.Void); } return; } } base.OnClicked(packet); if (packet.Slot == (short)FurnaceSlots.Input) { lock (_furnaceInstance) { if (!ItemStack.IsVoid(this[(short)FurnaceSlots.Input])) { newItem.Type = this[(short)FurnaceSlots.Input].Type; newItem.Count = this[(short)FurnaceSlots.Input].Count; newItem.Durability = this[(short)FurnaceSlots.Input].Durability; } _furnaceInstance.ChangeInput(newItem); } } else if (packet.Slot == (short)FurnaceSlots.Fuel) { lock (_furnaceInstance) { if (!ItemStack.IsVoid(this[(short)FurnaceSlots.Fuel])) { newItem.Type = this[(short)FurnaceSlots.Fuel].Type; newItem.Count = this[(short)FurnaceSlots.Fuel].Count; newItem.Durability = this[(short)FurnaceSlots.Fuel].Durability; } _furnaceInstance.ChangeFuel(newItem); } } }
internal override void OnClicked(WindowClickPacket packet) { if (packet.Slot >= 1 && packet.Slot <= 4) { Recipe recipe = GetRecipe(); if (recipe == null) { this[0].Type = 0; this[0].Durability = 0; } else { this[0] = recipe.Result; } } if (packet.Slot == 0) { if (!ItemStack.IsVoid(Cursor)) { if (Cursor.Type != this[0].Type || Cursor.Durability != this[0].Durability || Cursor.Count + this[0].Count > 64) { PacketHandler.SendPacket(new TransactionPacket { Accepted = false, Transaction = packet.Transaction, WindowId = packet.WindowId }); return; } 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; } this.Cursor.Count += this[0].Count; this[0] = ItemStack.Void; List<ItemStack> ingredients = new List<ItemStack>(); for (short i = 1; i <= 9; i++) ingredients.Add(ItemStack.IsVoid(Slots[i]) ? ItemStack.Void : this[i]); Recipe recipe = GetRecipe(); for (int i = 0; i < ingredients.Count; i++) { if (ItemStack.IsVoid(ingredients[i])) continue; for (int i2 = 0; i2 < recipe.Ingredients2.Length; i2++) { if (ingredients[i].Type == recipe.Ingredients2[i2].Type) { ingredients[i].Count -= recipe.Ingredients2[i2].Count; break; } } } } else { base.OnClicked(packet); } }
internal override void OnClicked(WindowClickPacket packet) { if (packet.Slot == 0) { if (!ItemStack.IsVoid(Cursor)) { if (Cursor.Type != this[0].Type || Cursor.Durability != this[0].Durability || Cursor.Count + this[0].Count > 64) { PacketHandler.SendPacket(new TransactionPacket { Accepted = false, Transaction = packet.Transaction, WindowId = packet.WindowId }); return; } 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; } this.Cursor.Count += this[0].Count; } else { base.OnClicked(packet); } }