Exemplo n.º 1
0
 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();
     }
 }
Exemplo n.º 2
0
 private void HandleWindowChange(object sender, WindowChangeEventArgs e)
 {
     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;
 }
Exemplo n.º 3
0
        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))
            {
                // Set up the initial state
                TryInitializeFurnace(state, window.EventScheduler, world, window.Coordinates, window.ItemRepository);
            }

            Handling = false;
        }
Exemplo n.º 4
0
        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));
            }
        }
Exemplo n.º 5
0
 protected internal virtual void OnWindowChange(WindowChangeEventArgs e)
 {
     if (WindowChange != null)
         WindowChange(this, e);
 }