private void Inventory_WindowChange(object sender, WindowChangeEventArgs e) { if (SendInventoryUpdates) { Client.SendPacket(new SetSlotPacket(0, (short)e.SlotIndex, e.Value)); } }
void HandleWindowChange(object sender, WindowChangeEventArgs e) { if (!(sender is InventoryWindow)) { QueuePacket(new SetSlotPacket((sender as IWindow).ID, (short)e.SlotIndex, e.Value.ID, e.Value.Count, e.Value.Metadata)); return; } QueuePacket(new SetSlotPacket(0, (short)e.SlotIndex, e.Value.ID, e.Value.Count, e.Value.Metadata)); if (e.SlotIndex == SelectedSlot) { var notified = Server.GetEntityManagerForWorld(World).ClientsForEntity(Entity); foreach (var c in notified) { c.QueuePacket(new EntityEquipmentPacket(Entity.EntityID, 0, SelectedItem.ID, SelectedItem.Metadata)); } } if (e.SlotIndex >= InventoryWindow.ArmorIndex && e.SlotIndex < InventoryWindow.ArmorIndex + InventoryWindow.Armor.Length) { short slot = (short)(4 - (e.SlotIndex - InventoryWindow.ArmorIndex)); var notified = Server.GetEntityManagerForWorld(World).ClientsForEntity(Entity); foreach (var c in notified) { c.QueuePacket(new EntityEquipmentPacket(Entity.EntityID, slot, e.Value.ID, e.Value.Metadata)); } } }
private void PlayerInventoryChange(object sender, WindowChangeEventArgs windowChangeEventArgs) { var window = (Window)sender; var source = server.Clients.FirstOrDefault(c => c.Entity.Inventory == window); if (source == null) { return; // This should never happen, but somehow does. } var clients = GetKnownClients(source.Entity); if (windowChangeEventArgs.SlotIndex >= InventoryWindow.ArmorIndex && windowChangeEventArgs.SlotIndex < InventoryWindow.ArmorIndex + 4) { // TODO: Prevent non-armor items from being used here foreach (var client in clients) { int index = windowChangeEventArgs.SlotIndex - InventoryWindow.ArmorIndex; client.SendPacket(new EntityEquipmentPacket(source.Entity.Id, (EntityEquipmentPacket.EntityEquipmentSlot)(4 - index), windowChangeEventArgs.Value)); } } source.SendPacket(new SetSlotPacket(0, (short)windowChangeEventArgs.SlotIndex, windowChangeEventArgs.Value)); if (source.Entity.SelectedSlot == windowChangeEventArgs.SlotIndex) { foreach (var client in clients) { client.SendPacket(new EntityEquipmentPacket(source.Entity.Id, EntityEquipmentPacket.EntityEquipmentSlot.HeldItem, client.Entity.SelectedItem)); } } }
protected void FurnaceWindowChanged(object sender, WindowChangeEventArgs e, IWorld world) { if (Handling) { return; } var window = sender as FurnaceWindow; var index = e.SlotIndex; if (index >= FurnaceWindow.MainIndex) { return; } Handling = true; e.Handled = true; window[index] = e.Value; var state = GetState(world, window.Coordinates); state.Items[0] = window[0]; state.Items[1] = window[1]; state.Items[2] = window[2]; SetState(world, window.Coordinates, state); Handling = true; if (!TrackedFurnaces.ContainsKey(window.Coordinates)) { TryInitializeFurnace(state, window.EventScheduler, world, window.Coordinates, window.ItemRepository); } Handling = false; }
protected internal virtual void OnWindowChange(WindowChangeEventArgs e) { if (WindowChange != null) { WindowChange(this, e); } }
public virtual ItemStack this[int index] { get { foreach (var area in WindowAreas) { if (index >= area.StartIndex && index < area.StartIndex + area.Length) { return(area[index - area.StartIndex]); } } throw new IndexOutOfRangeException(); } set { foreach (var area in WindowAreas) { if (index >= area.StartIndex && index < area.StartIndex + area.Length) { var eventArgs = new WindowChangeEventArgs(index, value); OnWindowChange(eventArgs); if (!eventArgs.Handled) { area[index - area.StartIndex] = value; } return; } } throw new IndexOutOfRangeException(); } }
private void HandleWindowChange(object sender, WindowChangeEventArgs e) { if (Repository == null) { return; } var current = Repository.GetRecipe(Bench); if (e.SlotIndex == CraftingOutput) { if (e.Value.Empty && current != null) // Item picked up { RemoveItemFromOutput(current); current = Repository.GetRecipe(Bench); } } if (current == null) { Items[CraftingOutput] = ItemStack.EmptyStack; } else { Items[CraftingOutput] = current.Output; } }