GainElements() public static method

public static GainElements ( byte slot, int itemid, short amount ) : byte[]
slot byte
itemid int
amount short
return byte[]
Example #1
0
        /////////////////////////////////////////////////////////////////////////////////
        // Item destruction with alchemy
        /////////////////////////////////////////////////////////////////////////////////
        public void BreakItem()
        {
            try
            {
                //Checks before we continue
                if (Character.Stall.Stallactive || Character.Action.nAttack || Character.Action.sAttack || Character.Alchemy.working)
                {
                    return;
                }
                //Set bool
                Character.Alchemy.working = true;
                //TODO: Timer for alchemy start / end
                PacketReader reader        = new PacketReader(PacketInformation.buffer);
                byte         rondorequired = reader.Byte();
                byte         slot          = reader.Byte();
                reader.Close();


                //Get our item information (item)
                Global.slotItem item = GetItem((uint)Character.Information.CharacterID, slot, 0);

                //Get our degree information
                byte itemdegree = Data.ItemBase[item.ID].Degree;

                //First we get our elements (Same degree as weapon)
                //This should return 4 items
                //Add check rondo count if high enough.
                Character.Alchemy.Elementlist = GetDegreeElements(item.ID, Character);
                //Check if the item has any blues on it.
                if (Data.ItemBlue[item.dbID].totalblue != 0)
                {
                    Character.Alchemy.StonesList = GetStonesDegree(item.ID, Character);
                }

                //Check current free slots of the player
                byte slotcheck = GetFreeSlot();
                //If slot amount is lower then 4 return
                //Slots free must be 6 i believe because of stones (TODO: Check info official).
                if (slotcheck < 4)
                {
                    //Send error message inventory full ...
                    return;
                }
                //Player has enough slots so we continue adding the new items
                else
                {
                    //Update rondo quantity
                    Character.Information.InventorylistSlot = GetPlayerItems(Character);
                    foreach (byte e in Character.Information.InventorylistSlot)
                    {
                        //Set slotitem
                        Global.slotItem itemrondoinfo = GetItem((uint)Character.Information.CharacterID, e, 0);
                        if (itemrondoinfo.ID != 0)
                        {
                            if (Data.ItemBase[itemrondoinfo.ID].Etctype == Global.item_database.EtcType.DESTROYER_RONDO)
                            {
                                //Update amount
                                itemrondoinfo.Amount -= rondorequired;
                                ItemUpdateAmount(itemrondoinfo, Character.Information.CharacterID);
                            }
                        }
                    }
                    //Clean our list
                    Character.Information.InventorylistSlot.Clear();
                    //Remove the item used in dissembling (Query).
                    MsSQL.DeleteData("DELETE FROM char_items WHERE id='" + item.dbID + "' AND owner='" + Character.Information.CharacterID + "'");
                    //Remove the item used in dissembling (Visual).
                    ItemUpdateAmount(item, Character.Information.CharacterID);
                    //Send packet #2
                    client.Send(Packet.DestroyItem());
                    //Repeat for each element in our list.
                    foreach (int e in Character.Alchemy.Elementlist)
                    {
                        if (e != 0)
                        {
                            //TODO: Make detailed randoms
                            //Make random add count for the elements
                            //NOTE: Check what item has what element on destruction. if pk2 contains or not.
                            int elementamount = 0;

                            #region Amounts
                            if (Data.ItemBase[item.ID].Degree == 1)
                            {
                                elementamount = rnd.Next(1, 60);
                            }
                            else if (Data.ItemBase[item.ID].Degree == 2)
                            {
                                elementamount = rnd.Next(1, 90);
                            }
                            else if (Data.ItemBase[item.ID].Degree == 3)
                            {
                                elementamount = rnd.Next(1, 120);
                            }
                            else if (Data.ItemBase[item.ID].Degree == 4)
                            {
                                elementamount = rnd.Next(1, 150);
                            }
                            else if (Data.ItemBase[item.ID].Degree == 5)
                            {
                                elementamount = rnd.Next(1, 200);
                            }
                            else if (Data.ItemBase[item.ID].Degree == 6)
                            {
                                elementamount = rnd.Next(1, 250);
                            }
                            else if (Data.ItemBase[item.ID].Degree == 7)
                            {
                                elementamount = rnd.Next(1, 300);
                            }
                            else if (Data.ItemBase[item.ID].Degree == 8)
                            {
                                elementamount = rnd.Next(1, 375);
                            }
                            else if (Data.ItemBase[item.ID].Degree == 9)
                            {
                                elementamount = rnd.Next(1, 450);
                            }
                            else if (Data.ItemBase[item.ID].Degree == 10)
                            {
                                elementamount = rnd.Next(1, 600);
                            }
                            else if (Data.ItemBase[item.ID].Degree == 11)
                            {
                                elementamount = rnd.Next(1, 800);
                            }
                            #endregion

                            int stoneamount = 0;

                            #region Stones
                            if (Data.ItemBlue[item.dbID].totalblue != 0)
                            {
                                if (Data.ItemBlue[item.dbID].totalblue == 1)
                                {
                                    stoneamount = rnd.Next(0, 1);
                                }
                                else if (Data.ItemBlue[item.dbID].totalblue == 2)
                                {
                                    stoneamount = rnd.Next(0, 2);
                                }
                            }
                            #endregion

                            slotcheck = GetFreeSlot();
                            //Stack items todo
                            AddItem(Data.ItemBase[e].ID, 10, slotcheck, Character.Information.CharacterID, 0);
                            client.Send(Packet.GainElements(slotcheck, Data.ItemBase[e].ID, (short)elementamount));
                        }
                    }
                    //Clear created list content.
                    Character.Alchemy.Elementlist.Clear();
                }
                //Reset bool
                Character.Alchemy.working = false;
            }
            catch (Exception ex)
            {
                Console.WriteLine("Alchemy error destroyer {0}", ex);
            }
        }
Example #2
0
        /////////////////////////////////////////////////////////////////////////////////
        // Create stones
        /////////////////////////////////////////////////////////////////////////////////
        public void AlchemyCreateStone()
        {
            try
            {
                //Open packet reader
                PacketReader reader       = new PacketReader(PacketInformation.buffer);
                byte         type         = reader.Byte();
                byte         type1        = reader.Byte();
                byte         type2        = reader.Byte();
                byte         tabletslot   = reader.Byte();
                byte         elementslot1 = reader.Byte();
                byte         elementslot2 = reader.Byte();
                byte         elementslot3 = reader.Byte();
                byte         elementslot4 = reader.Byte();
                reader.Close();

                //Tablet information
                Global.slotItem tabletslotitem = GetItem((uint)Character.Information.CharacterID, tabletslot, 0);

                //Get stone information equaly to the tablet
                int stone = GetStoneFromTablet(tabletslotitem.ID);

                //Earth element information
                Global.slotItem element1slotitem = GetItem((uint)Character.Information.CharacterID, elementslot1, 0);
                //Water element information
                Global.slotItem element2slotitem = GetItem((uint)Character.Information.CharacterID, elementslot2, 0);
                //Fire element information
                Global.slotItem element3slotitem = GetItem((uint)Character.Information.CharacterID, elementslot3, 0);
                //Wind element information
                Global.slotItem element4slotitem = GetItem((uint)Character.Information.CharacterID, elementslot4, 0);

                //Check if the requirements are ok (Extra check amount).
                if (element1slotitem.Amount < Data.ItemBase[tabletslotitem.ID].EARTH_ELEMENTS_AMOUNT_REQ)
                {
                    return;
                }
                if (element2slotitem.Amount < Data.ItemBase[tabletslotitem.ID].WATER_ELEMENTS_AMOUNT_REQ)
                {
                    return;
                }
                if (element3slotitem.Amount < Data.ItemBase[tabletslotitem.ID].FIRE_ELEMENTS_AMOUNT_REQ)
                {
                    return;
                }
                if (element2slotitem.Amount < Data.ItemBase[tabletslotitem.ID].WIND_ELEMENTS_AMOUNT_REQ)
                {
                    return;
                }

                //Check if the requirements are ok (Extra check element name).
                if (Data.ItemBase[element1slotitem.ID].Name != Data.ItemBase[tabletslotitem.ID].EARTH_ELEMENTS_NAME)
                {
                    return;
                }
                if (Data.ItemBase[element2slotitem.ID].Name != Data.ItemBase[tabletslotitem.ID].WATER_ELEMENTS_NAME)
                {
                    return;
                }
                if (Data.ItemBase[element3slotitem.ID].Name != Data.ItemBase[tabletslotitem.ID].FIRE_ELEMENTS_NAME)
                {
                    return;
                }
                if (Data.ItemBase[element4slotitem.ID].Name != Data.ItemBase[tabletslotitem.ID].WIND_ELEMENTS_NAME)
                {
                    return;
                }

                //Update amount of elements
                element1slotitem.Amount -= (short)Data.ItemBase[tabletslotitem.ID].EARTH_ELEMENTS_AMOUNT_REQ;
                element2slotitem.Amount -= (short)Data.ItemBase[tabletslotitem.ID].WATER_ELEMENTS_AMOUNT_REQ;
                element3slotitem.Amount -= (short)Data.ItemBase[tabletslotitem.ID].FIRE_ELEMENTS_AMOUNT_REQ;
                element4slotitem.Amount -= (short)Data.ItemBase[tabletslotitem.ID].WIND_ELEMENTS_AMOUNT_REQ;

                ItemUpdateAmount(element1slotitem, Character.Information.CharacterID);
                ItemUpdateAmount(element2slotitem, Character.Information.CharacterID);
                ItemUpdateAmount(element3slotitem, Character.Information.CharacterID);
                ItemUpdateAmount(element4slotitem, Character.Information.CharacterID);

                //Update amount of tablet
                tabletslotitem.Amount -= 1;
                ItemUpdateAmount(tabletslotitem, Character.Information.CharacterID);

                //Send alchemy packet
                client.Send(Packet.StoneCreation(tabletslot));

                //Check for new free slots in inventory
                byte freeslot = GetFreeSlot();
                //Update database and insert new item
                AddItem(stone, 1, freeslot, Character.Information.CharacterID, 0);
                //Send visual packet add stone (creation works, just need to check why it sends 2x same packet).
                client.Send(Packet.GainElements(freeslot, stone, 1));
            }
            catch (Exception ex)
            {
                Console.WriteLine("Stone creation error {0}", ex);
                Systems.Debugger.Write(ex);
            }
        }