Exemple #1
0
 public void SetSlot(int slotNumber,SLOT slot)
 {
     if (slotNumber >= slots.Length)
     {
         throw new IndexOutOfRangeException("Slot index is larger than the number of slots in container!");
     }
     if (slotNumber < 0)
     {
         throw new IndexOutOfRangeException("Slot index is < 0!!");
     }
     slots[slotNumber] = slot;
 }
Exemple #2
0
        public void SetItem(short slot,SLOT data)
        {
            container.SetSlot(slot,data);

            foreach (Player p in players.ToArray())
            {
                if (!p.client.loggedin || p.client.isDisconnected || p.WindowManager.CurrentWindow != this)                 //Player cannot possibly have this window open
                {
                    players.Remove(p);
                }                                              //Remove this player from the player list

                //This player has this window open, so we get to update the slot we have updated!
                //p.client.SetSlot
            }
        }
Exemple #3
0
        internal bool AddItemToInventory(SLOT data)
        {
            int slotNumber = 27;    //Start at the first slot for the hotbar

            while (true)            //we should likely check for inf. loops....
            {
                SLOT currentSlot = inventory.MainInventory.GetSlot(slotNumber);

                if (currentSlot.material.ID == -1)                 //Check if slot is empty
                {
                    inventory.SetSlot(slotNumber,data);
                    return(true);
                }
                int MaxStack = currentSlot.material.DirectAccess.MaximumStack;
                if (currentSlot.Count < MaxStack && currentSlot.material.ID == data.material.ID && currentSlot.Meta == data.Meta)
                {
                    Console.WriteLine("All data matches, adding to stack");
                    int countCanAdd = MaxStack - currentSlot.Count; //The number of items we can add to this stack

                    if (countCanAdd >= data.Count)                  //We can add our entire stack
                    {
                        data.Count += currentSlot.Count;            //Modify the count of the slot
                        inventory.SetSlot(slotNumber,data);         //Set the slot in inventory
                        return(true);                               //Return pickup is accepted
                    }
                    else
                    {
                        //TODO split into two parts and only pick up what we can, we may have to return a slot for this, or spit out the items we cannot pick up...
                    }
                }

                //Incrementation area
                if (slotNumber == 26)
                {
                    return(false);            //Only return false AFTER checking slot 26
                }
                slotNumber++;                 //Increment at the end so we can check the first slot of the hotbar and last slot of inventory (its an odd setup, just go with it)
                if (slotNumber == 36)
                {
                    slotNumber = 0;                                  //Return to zero after checking the hotbar (36 is oob)
                }
            }
            return(false);
        }
Exemple #4
0
        internal SLOT ReadSlot()
        {
            short id = ReadShort();

            if (id == -1)
            {
                return(new SLOT()); //No item here!
            }
            else                    //We have an item / block
            {
                SLOT slot = new SLOT();
                slot.material = MaterialManager.Materials[id];
                slot.Count    = ReadByte();
                slot.Meta     = ReadShort();

                short NBTLength = ReadShort();
                if (NBTLength > 0)
                {
                    slot.ZippedNBT = ReadByteArray(NBTLength);
                }
                return(slot);
            }
        }
Exemple #5
0
 /// <summary>
 /// This method is called when a player clicks on the window
 /// </summary>
 /// <param name="SlotNumber">The index of the slot that was clicked by the player</param>
 /// <param name="bytton">The button parameter that the player clicked with</param>
 /// <param name="mode">The mode this players click is in</param>
 /// <param name="CI">The CurrentItem that the player has clicked (what is currently in that slot in the players window, if it does not match what SHOULD be in it, we should have already returned false</param>
 /// <param name="w">The WINDOW class that this click is referring to, you can get most of the information you need about the window here, any changes here will be pushed to all players that have this same window open, assuming its a crossplayer window</param>
 /// <param name="PWM">The PlayerWindowManager class that this click was called from, in this class you can get the information for the SLOT attached to the cursor and information on the player</param>
 /// <returns>This should return a bool as to whether or not this transaction has completed succesfully, return false to reject this transaction (in which case no changes should be made to the inventory.</returns>
 public abstract bool Click(short SlotNumber,byte button,byte mode,SLOT CI,Window w,PlayerWindowManager PWM);
Exemple #6
0
        internal BlockLocation BL;                   //This is only set if we have a BLOCK that has a window

        internal bool Click(short SN,byte button,byte Mode,SLOT CI,PlayerWindowManager PWM)
        {
            return(WindowType.Click(SN,button,Mode,CI,this,PWM));
        }
Exemple #7
0
        internal void ClickWindow(byte ID,short SlotNumber,byte button,short ActionNumber,byte Mode,SLOT ClickedItem)
        {
            bool completed = Windows[ID].Click(SlotNumber,button,Mode,ClickedItem,this);

            //if completed = false then we need to reject this action!
            //if completed = true then this action is good!
        }
Exemple #8
0
 public void SetSlot(int slotNumber,SLOT slot)
 {
     Console.WriteLine("Setting Slot!");
     MainInventory.SetSlot(slotNumber,slot);
     Owner.client.SendSetSlot(0,(short)(slotNumber + 9),slot);
 }