Ejemplo n.º 1
0
        public void SetMatrial(Rag2Item list)
        {
            int offset = 1769 + (this.data[18] * 66);

            Rag2Item.Serialize(list, this.data, offset);
            this.data[18]++;
        }
Ejemplo n.º 2
0
        public void AddItem(Rag2Item item, byte Active, int ItemIndex)
        {
            int index = ItemIndex * 68;

            Rag2Item.Serialize(item, this.data, index);
            this.data[index + 67] = item.active;
        }
Ejemplo n.º 3
0
        /// <summary>
        /// Search for owner market items
        /// </summary>
        /// <returns></returns>
        public IEnumerable <MarketItemArgument> SearchMarketForOwner(Character target)
        {
            MySqlConnection connection = ConnectionPool.Request();
            MySqlCommand    command    = new MySqlCommand(_query_09, connection);

            command.Parameters.AddWithValue("?CharId", target.ModelId);
            MySqlDataReader reader = null;

            try
            {
                reader = command.ExecuteReader();
                while (reader.Read())
                {
                    byte[]             buffer = new byte[67];
                    MarketItemArgument item   = new MarketItemArgument();
                    item.id      = reader.GetUInt32(0);
                    item.sender  = reader.GetString(4);
                    item.price   = reader.GetUInt32(7);
                    item.expires = reader.GetMySqlDateTime(9).GetDateTime();
                    reader.GetBytes(8, 0, buffer, 0, 67);
                    Rag2Item.Deserialize(out item.item, buffer, 0);
                    yield return(item);
                }
            }
            finally
            {
                if (reader != null)
                {
                    reader.Close();
                }
                ConnectionPool.Release(connection);
            }
        }
Ejemplo n.º 4
0
        public bool CheckAgainstDroprate(Rag2Item item, uint droprate, double reducement)
        {
            int b = 9999 - (int)((double)random.Next(600, 1000) * (double)(reducement + Singleton.experience.Modifier_Drate));
            int c = b > 2000 ? b : 2000;

            int i = random.Next(0, c);
            int a = i;

            if (i < droprate)
            {
                int increment = 4000;
                while (item.count < item.info.max_stack)
                {
                    a += increment;
                    c += increment;

                    int d = random.Next(a, c);
                    if (d < droprate)
                    {
                        item.count++;
                    }
                    else
                    {
                        break;
                    }
                }
                return(true);
            }
            else
            {
                return(false);
            }
        }
Ejemplo n.º 5
0
        /// <Sql>
        /// INSERT INTO
        ///     list_maildata
        /// (
        ///     Sender,
        ///     Receiptent,
        ///     Date,
        ///     Topic,
        ///     Message,
        ///     Attachment,
        ///     Zeny
        /// ) VALUES (
        ///     @Sender,
        ///     @Receiptent,
        ///     @Date,
        ///     @Topic,
        ///     @Attachment,
        ///     @Zeny
        ///  )
        /// </Sql>
        public bool InsertNewMailItem(Character target, MailItem item)
        {
            byte[] buffer = null;
            if (item.item != null)
            {
                buffer = new byte[67];
                Rag2Item.Serialize(item.item, buffer, 0);
            }

            MySqlConnection connection = ConnectionPool.Request();
            MySqlCommand    command    = new MySqlCommand(_query_45, connection);

            command.Parameters.AddWithValue("Sender", (target != null) ? target.Name : string.Empty);
            command.Parameters.AddWithValue("Receiptent", item.Recieptent);
            command.Parameters.AddWithValue("Date", item.Timestamp);
            command.Parameters.AddWithValue("Topic", item.Topic);
            command.Parameters.AddWithValue("Message", item.Content);
            command.Parameters.AddWithValue("Zeny", item.Zeny);
            command.Parameters.AddWithValue("Attachment", buffer);

            try
            {
                return(command.ExecuteNonQuery() > 0);
            }
            catch (Exception e)
            {
                __dbtracelog.WriteError("Database", e.Message);
                return(false);
            }
            finally
            {
                ConnectionPool.Release(connection);
            }
        }
Ejemplo n.º 6
0
        public void SetProducts(Rag2Item list)
        {
            int offset = 119 + (this.data[17] * 66);

            Rag2Item.Serialize(list, this.data, offset);
            this.data[17]++;
        }
Ejemplo n.º 7
0
        /// <summary>
        /// Adds a item to the list
        /// </summary>
        /// <param name="item">Item to add</param>
        /// <returns>Index of the item</returns>
        public int Add(Rag2Item item)
        {
            int i = FindFirstFreeIndex();

            this.dictonairy.Add((byte)i, item);
            return(i);
        }
Ejemplo n.º 8
0
        public void AddItem(Rag2Item product, Rag2Item supply, Rag2Item supply2)
        {
            int count    = this.data[4];
            int newcount = count + 1;

            if (newcount > 25)
            {
                return;
            }

            if (product != null)
            {
                Rag2Item.Serialize(product, this.data, 0x6F + count * 66);
                Array.Copy(BitConverter.GetBytes(count), 0, this.data, 11 + count * 4, 4);
                this.data[4]++;
            }
            if (supply != null)
            {
                Rag2Item.Serialize(supply, this.data, 0x6E1 + count * 66);
                this.data[5]++;
            }
            if (supply2 != null)
            {
                Rag2Item.Serialize(supply2, this.data, 0xD53 + count * 66);
                this.data[6]++;
            }
        }
Ejemplo n.º 9
0
        public static IEnumerable <KeyValuePair <uint, Rag2Item> > GetLootList(uint npc)
        {
            //HELPER VARABLES
            string file            = String.Format("../Data/npc-loots/{0}.xml", npc);
            string WarperChildNode = "item";
            string RateNode        = "rate";

            //GO READ THE CONTENTS OF THE FILE
            if (File.Exists(file))
            {
                using (FileStream fs = new FileStream(file, FileMode.Open, FileAccess.Read))
                    using (XmlTextReader reader = new XmlTextReader(fs))
                    {
                        reader.ReadStartElement();
                        while (reader.ReadToFollowing(WarperChildNode))
                        {
                            Rag2Item item = null;
                            uint     rate;
                            uint     itemid;

                            uint.TryParse(reader[RateNode], out rate);
                            if (uint.TryParse(reader.ReadElementString(), out itemid) &&
                                Singleton.Item.TryGetItem(itemid, out item))
                            {
                                KeyValuePair <uint, Rag2Item> pair = new KeyValuePair <uint, Rag2Item>(rate, item);
                                yield return(pair);
                            }
                        }
                    }
            }
        }
Ejemplo n.º 10
0
        /// <summary>
        /// Registers a new market item
        /// </summary>
        /// <param name="arg"></param>
        /// <returns></returns>
        public uint RegisterNewMarketItem(Character target, MarketItemArgument arg)
        {
            MySqlConnection connection = ConnectionPool.Request();
            uint            result     = 0;

            try
            {
                byte[] buffer = new byte[67];
                Rag2Item.Serialize(arg.item, buffer, 0);

                MySqlCommand command = new MySqlCommand(_query_10, connection);
                command.Parameters.AddWithValue("Categorie", arg.item.info.categorie);
                command.Parameters.AddWithValue("Grade", 0);
                command.Parameters.AddWithValue("CharId", target.ModelId);
                command.Parameters.AddWithValue("CharName", arg.sender);
                command.Parameters.AddWithValue("ItemName", arg.item.info.name);
                command.Parameters.AddWithValue("ReqClvl", arg.item.clvl);
                command.Parameters.AddWithValue("Price", arg.price);
                command.Parameters.AddWithValue("ItemContent", buffer);
                command.Parameters.AddWithValue("Expires", arg.expires);

                command.ExecuteNonQuery();
                result = Convert.ToUInt32(command.LastInsertedId);
            }
            catch (Exception e)
            {
                __dbtracelog.WriteError("Database", e.Message);
            }
            finally
            {
                ConnectionPool.Release(connection);
            }

            return(result);
        }
Ejemplo n.º 11
0
        public void AddItem(Rag2Item item)
        {
            int offset = 2 + (this.index * 67);

            Rag2Item.Serialize(item, this.data, offset);
            this.data[offset + 66] = (byte)this.index;
            this.index++;
        }
Ejemplo n.º 12
0
        public void AddItem(Rag2Item item, int ItemIndex)
        {
            int offset = this.data.Length;

            Array.Resize <byte>(ref this.data, offset + 67);
            Rag2Item.Serialize(item, this.data, offset);
            this.data[offset + 66] = (byte)ItemIndex;
            this.data[1]++;
        }
Ejemplo n.º 13
0
        /// <Sql>
        /// SELECT
        ///     *
        /// FROM
        ///     list_maildata
        /// WHERE
        ///     Sender=?Sender
        /// AND
        ///     IsOutbox=1;
        /// </Sql>
        public IEnumerable <Mail> GetOutboxMail(Character target)
        {
            MySqlConnection connection = ConnectionPool.Request();
            MySqlCommand    command    = new MySqlCommand(_query_37, connection);

            command.Parameters.AddWithValue("Sender", target.Name);
            MySqlDataReader reader = null;

            try
            {
                reader = command.ExecuteReader();
                while (reader.Read())
                {
                    // 0 - MailId
                    // 1 - Sender
                    // 2 - Receiptent
                    // 3 - Date
                    // 4 - IsRead
                    // 5 - IsChecked
                    // 6 - Topic
                    // 7 - Message
                    // 8 - Attachment
                    // 9 - Zeny


                    Mail mailsubject = new Mail();
                    mailsubject.MailId  = reader.GetUInt32(0);
                    mailsubject.Sender  = reader.GetString(1);
                    mailsubject.Time    = reader.GetDateTime(3);
                    mailsubject.IsRead  = reader.GetByte(4);
                    mailsubject.Topic   = reader.GetString(6);
                    mailsubject.Message = reader.GetString(7);
                    mailsubject.Zeny    = (int)reader.GetUInt32(9);


                    if (reader.IsDBNull(8) == false)
                    {
                        byte[] buffer = new byte[67];
                        reader.GetBytes(8, 0, buffer, 0, 67);
                        Rag2Item.Deserialize(out mailsubject.Attachment, buffer, 0);
                    }
                    if (mailsubject.IsRead == 0)
                    {
                        mailsubject.Valid = (byte)(30 - Math.Min(30, (int)((DateTime.Now - mailsubject.Time).TotalDays)));
                    }
                    yield return(mailsubject);
                }
            }
            finally
            {
                if (reader != null)
                {
                    reader.Close();
                }
                ConnectionPool.Release(connection);
            }
        }
Ejemplo n.º 14
0
        public void AddItem(Rag2Item item, bool nostock)
        {
            int offset = 11 + (this.index * 68);

            Rag2Item.Serialize(item, this.data, offset);
            this.data[offset + 66] = (byte)this.index;
            this.data[offset + 67] = (byte)(nostock == true ? 1 : 0);
            this.index++;
        }
Ejemplo n.º 15
0
        public void Add(MarketItemArgument c)
        {
            int index = this.data.Length - 112;

            Rag2Item.Serialize(c.item, this.data, index);
            Array.Copy(BitConverter.GetBytes(c.id), 0, this.data, index + 66, 4);
            UnicodeEncoding.Unicode.GetBytes(c.sender, 0, c.sender.Length, this.data, index + 70);
            Array.Copy(BitConverter.GetBytes(c.price), 0, this.data, index + 104, 4); //Price
            Array.Copy(BitConverter.GetBytes(c.id), 0, this.data, index + 108, 4);
        }
Ejemplo n.º 16
0
        public void AddItem(Rag2Item item, bool nostock, int index)
        {
            int offset = this.data.Length;

            Array.Resize <byte>(ref this.data, offset + 68);
            Rag2Item.Serialize(item, this.data, offset);
            this.data[0]++;
            this.data[offset + 66] = (byte)index;
            this.data[offset + 67] = (byte)(nostock == true ? 1 : 0);
        }
Ejemplo n.º 17
0
        public void Add(MarketItemArgument item)
        {
            int index = this.data.Length;

            Array.Resize <byte>(ref this.data, 2 + (++this.data[1] * 75));
            Rag2Item.Serialize(item.item, this.data, index + 0);
            Array.Copy(BitConverter.GetBytes(item.price), 0, this.data, index + 66, 4);
            this.data[index + 70] = (byte)Math.Max(0, (item.expires - DateTime.Now).TotalHours);
            Array.Copy(BitConverter.GetBytes(item.id), 0, this.data, index + 71, 4);
        }
Ejemplo n.º 18
0
        /// <summary>
        /// Removes a item
        /// </summary>
        /// <param name="item">Item to remove</param>
        /// <returns>True if the item was removed</returns>
        public bool Remove(Rag2Item item)
        {
            foreach (KeyValuePair <byte, Rag2Item> pair in this.dictonairy)
            {
                if (pair.Value == item)
                {
                    this.dictonairy.Remove(pair.Key);
                    return(true);
                }
            }

            return(false);
        }
Ejemplo n.º 19
0
        /// <summary>
        /// Occurs when retrieving item attachement from the id.
        /// </summary>
        /// <param name="cpkt"></param>
        private void CM_RETRIEVEITEMATTACHMENT(CMSG_GETITEMATTACHMENT cpkt)
        {
            byte result = 0;

            try
            {
                Rag2Item item = Singleton.Database.GetItemAttachment(cpkt.MailId);

                //No attachment
                if (item == null)
                {
                    result = 1;
                }
                //Not the same item type
                else if (item.info.item != cpkt.ItemId)
                {
                    result = 1;
                }
                //Not enough space
                else if (this.character.container.Count == this.character.container.Capacity)
                {
                    result = 1;
                }
                //Update the database
                else if (Singleton.Database.UpdateItemAttachment(cpkt.MailId, null) == false)
                {
                    result = 1;
                }
                //Everything is okay
                else
                {
                    int          index = this.character.container.Add(item);
                    SMSG_ADDITEM spkt  = new SMSG_ADDITEM();
                    spkt.Container    = 2;
                    spkt.UpdateReason = (byte)ItemUpdateReason.AttachmentSent;
                    spkt.SessionId    = this.character.id;
                    spkt.SetItem(item, index);
                    this.Send((byte[])spkt);
                }
            }
            finally
            {
                SMSG_MAILITEMAWNSER spkt = new SMSG_MAILITEMAWNSER();
                spkt.SessionId = cpkt.SessionId;
                spkt.Result    = result;
                this.Send((byte[])spkt);
            }
        }
Ejemplo n.º 20
0
        public bool TryGetItem(uint id, out Rag2Item item)
        {
            Rag2Item temp   = new Rag2Item();
            bool     result = item_drops.TryGetValue(id, out temp.info);

            if (result == true)
            {
                item            = temp;
                item.clvl       = (byte)item.info.req_clvl;
                item.durabillty = (int)item.info.max_durability;
            }
            else
            {
                item = null;
            }
            return(result);
        }
Ejemplo n.º 21
0
        public static ItemSkillUsageEventArgs Create(Rag2Item item, MapObject sender, MapObject target)
        {
            ItemSkillUsageEventArgs skillusage = new ItemSkillUsageEventArgs(sender, target);

            skillusage.iteminfo = item.info;

            if (item == null)
            {
                return(null);
            }
            else if (!Singleton.SpellManager.TryGetSpell(item.info.skill, out skillusage.info))
            {
                return(null);
            }
            else
            {
                return(skillusage);
            }
        }
Ejemplo n.º 22
0
        /// <Sql>
        /// SELECT
        ///     *
        /// FROM
        ///     list_maildata
        /// WHERE
        ///     InboxId=?Id
        /// LIMIT 1;
        /// </Sql>
        public MailItem GetMailItemById(MySqlConnection connection, uint id)
        {
            MySqlCommand command = new MySqlCommand(_query_47, connection);

            command.Parameters.AddWithValue("Id", id);
            MySqlDataReader reader = null;

            try
            {
                reader = command.ExecuteReader(); // argument CommandBehavior.SingleRow removed (Darkin)
                while (reader.Read())
                {
                    MailItem item = new MailItem();
                    item.Recieptent = reader.GetString(2);
                    item.Topic      = reader.GetString(6);
                    item.Content    = reader.GetString(7);
                    item.Timestamp  = reader.GetDateTime(3);
                    item.Zeny       = reader.GetUInt32(9);
                    if (reader.IsDBNull(8) == false)
                    {
                        byte[] buffer = new byte[67];
                        reader.GetBytes(8, 0, buffer, 0, 67);
                        Rag2Item.Deserialize(out item.item, buffer, 0);
                    }

                    //Singleton.Item.TryGetItemWithCount(27, 1, out item.item);
                    return(item);
                }
                return(null);
            }
            catch (Exception e)
            {
                __dbtracelog.WriteError("Database", e.Message);
                return(null);
            }
            finally
            {
                if (reader != null)
                {
                    reader.Close();
                }
            }
        }
Ejemplo n.º 23
0
        public bool GetItemByAuctionId(MySqlConnection connection, uint id, out AuctionArgument item)
        {
            MySqlCommand command = new MySqlCommand();

            command.CommandText = _query_08;
            command.Connection  = connection;
            command.Parameters.AddWithValue("AuctionId", id);
            MySqlDataReader reader = null;

            item = null;

            try
            {
                reader = command.ExecuteReader(CommandBehavior.SingleResult);
                while (reader.Read())
                {
                    item      = new AuctionArgument();
                    item.name = reader.GetString(4);
                    item.zeny = reader.GetUInt32(7);

                    byte[] buffer = new byte[67];
                    reader.GetBytes(8, 0, buffer, 0, 67);
                    Rag2Item.Deserialize(out item.item, buffer, 0);
                    return(true);
                }
            }
            catch (MySqlException e)
            {
                __dbtracelog.WriteError("Database", e.Message);
                return(false);
            }
            finally
            {
                if (reader != null)
                {
                    reader.Close();
                }
            }

            return(false);
        }
Ejemplo n.º 24
0
        /// <Sql>
        /// SELECT
        ///     *
        /// FROM
        ///     list_maildata
        /// WHERE
        ///     list_maildata.MailId=1;
        /// </Sql>
        public Rag2Item GetItemAttachment(uint MailId)
        {
            MySqlConnection connection = ConnectionPool.Request();
            MySqlCommand    command    = new MySqlCommand(_query_43, connection);

            command.Parameters.AddWithValue("Id", MailId);
            MySqlDataReader reader = null;

            try
            {
                byte[] buffer = (byte[])command.ExecuteScalar();
                if (buffer != null)
                {
                    Rag2Item item;
                    if (Rag2Item.Deserialize(out item, buffer, 0))
                    {
                        return(item);
                    }
                    return(null);
                }
                else
                {
                    return(null);
                }
            }
            catch (Exception e)
            {
                __dbtracelog.WriteError("Database", e.Message);
                return(null);
            }
            finally
            {
                if (reader != null)
                {
                    reader.Close();
                }
                ConnectionPool.Release(connection);
            }
        }
Ejemplo n.º 25
0
        /// <Sql>
        /// UPDATE
        ///     list_maildata
        /// SET
        ///     Attachment=?Attachment
        /// WHERE
        ///     MailId=?Id
        /// </Sql>
        public bool UpdateItemAttachment(uint MailId, Rag2Item Attachment)
        {
            MySqlConnection connection = ConnectionPool.Request();
            MySqlCommand    command    = new MySqlCommand(_query_44, connection);

            command.Parameters.AddWithValue("Id", MailId);
            command.Parameters.AddWithValue("Attachment", Attachment);

            try
            {
                return(command.ExecuteNonQuery() > 0);
            }
            catch (Exception e)
            {
                __dbtracelog.WriteError("Database", e.Message);
                return(false);
            }
            finally
            {
                ConnectionPool.Release(connection);
            }
        }
Ejemplo n.º 26
0
        /// <summary>
        /// Looses durabillity loss on defensive equipment
        /// </summary>
        /// <remarks>
        /// Durabillity loss on kro2 is calculated with a ratio of 50 : 1.
        /// Shield, Shirt, Pants, Shoes each durabillity loss it will rotate
        /// over the next equipment set.
        /// </remarks>
        public static void DoEquipment(Character target, uint damage)
        {
            if (target == null)
            {
                return;
            }
            bool canupdate      = false;
            int  NewDurabillity = 0;
            byte Slot           = 0;

            target.TakenDamage += damage;
            while (target.TakenDamage > 50)
            {
                target.TakenDamage -= 50;

                switch (target.LastEquipmentDuraLoss)
                {
                case 0:        //Shield
                    Rag2Item equip = target.Equipment[15];
                    if (equip == null || equip.active == 1 || equip.durabillty == 0)
                    {
                        goto case 1;
                    }
                    Slot                         = 15;
                    equip.durabillty            -= 1;
                    NewDurabillity               = equip.durabillty;
                    target.LastEquipmentDuraLoss = 1;
                    canupdate                    = true;
                    break;

                case 1:         //Shirt
                    Rag2Item shirt = target.Equipment[3];
                    if (shirt == null || shirt.active == 1 || shirt.durabillty == 0)
                    {
                        goto case 2;
                    }
                    Slot                         = 3;
                    shirt.durabillty            -= 1;
                    NewDurabillity               = shirt.durabillty;
                    target.LastEquipmentDuraLoss = 2;
                    canupdate                    = true;
                    break;

                case 2:         //Pants
                    Rag2Item pants = target.Equipment[4];
                    if (pants == null || pants.active == 1 || pants.durabillty == 0)
                    {
                        goto case 3;
                    }
                    Slot                         = 4;
                    pants.durabillty            -= 1;
                    NewDurabillity               = pants.durabillty;
                    target.LastEquipmentDuraLoss = 3;
                    canupdate                    = true;
                    break;

                case 3:         //Shoes
                    Rag2Item shoes = target.Equipment[5];
                    if (shoes == null || shoes.active == 1 || shoes.durabillty == 0)
                    {
                        return;
                    }
                    Slot                         = 5;
                    shoes.durabillty            -= 1;
                    NewDurabillity               = shoes.durabillty;
                    target.LastEquipmentDuraLoss = 0;
                    canupdate                    = true;
                    break;
                }

                if (canupdate == true)
                {
                    SMSG_ITEMADJUST spkt = new SMSG_ITEMADJUST();
                    spkt.Container = 1;
                    spkt.Function  = 3;
                    spkt.Slot      = Slot;
                    spkt.SessionId = target.id;
                    spkt.Value     = (uint)NewDurabillity;
                    target.client.Send((byte[])spkt);
                }
            }
        }
Ejemplo n.º 27
0
 /// <summary>
 /// Creates a new shoppair
 /// </summary>
 /// <param name="item">item to stock</param>
 /// <param name="NoStock">True if the item has infinite stock</param>
 public ShopPair(Rag2Item item, bool NoStock)
 {
     this.item    = item;
     this.NoStock = NoStock;
 }
Ejemplo n.º 28
0
        private void CM_QUESTITEMSTART(CMSG_QUESTITEMSTART cpkt)
        {
            Rag2Item item = this.character.container[cpkt.Index];

            if (item == null)
            {
                return;
            }
            if (item.info.quest == 0)
            {
                return;
            }

            byte result = 1;

            if (Singleton.Database.IsQuestComplete(this.character, item.info.quest))
            {
                result = 1;
            }
            else if (this.character.QuestObjectives[item.info.quest] != null)
            {
                result = 2;
            }
            else
            {
                try
                {
                    QuestBase Quest;
                    if (Singleton.Quests.TryFindQuests(item.info.quest, out Quest) == false || Quest.OnStart(this.character.id) < 0)
                    {
                        result = 1;
                        QuestBase.InvalidateQuest(Quest, this.character);
                    }
                    else
                    {
                        result = 0;
                        int newLength = this.character.container[cpkt.Index].count - 1;
                        if (newLength > 0)
                        {
                            this.character.container[cpkt.Index].count = newLength;
                            SMSG_UPDATEITEM spkt2 = new SMSG_UPDATEITEM();
                            spkt2.Amount       = (byte)newLength;
                            spkt2.UpdateReason = 8;
                            spkt2.UpdateType   = 4;
                            spkt2.Container    = 2;
                            spkt2.SessionId    = this.character.id;
                            spkt2.Index        = cpkt.Index;
                            this.Send((byte[])spkt2);
                        }
                        else
                        {
                            this.character.container.RemoveAt(cpkt.Index);
                            SMSG_DELETEITEM spkt3 = new SMSG_DELETEITEM();
                            spkt3.UpdateReason = 8;
                            spkt3.Container    = 2;
                            spkt3.Index        = cpkt.Index;
                            spkt3.SessionId    = this.character.id;
                            this.Send((byte[])spkt3);
                        }

                        Quest.CheckQuest(this.character);
                    }
                }
                catch (Exception)
                {
                    Trace.TraceError("Error starting quest: {0}", item.info.quest);
                }
            }


            SMSG_USEQUESTITEM spkt = new SMSG_USEQUESTITEM();

            spkt.Index     = cpkt.Index;
            spkt.Result    = result;
            spkt.SessionId = this.character.id;
            this.Send((byte[])spkt);
        }
Ejemplo n.º 29
0
 bool IDatabase.UpdateItemAttachment(uint MailId, Rag2Item Attachment)
 {
     return(UpdateItemAttachment(MailId, Attachment));
 }
Ejemplo n.º 30
0
        /// <summary>
        /// Occurs when your aggreeing with the trade.
        /// After the trade content has been agreed.
        /// </summary>
        private void CM_TRADECONFIRM(CMSG_TRADECONFIRM cpkt)
        {
            TradeSession session = this.character.TradeSession;

            if (session != null)
            {
                //OBTAIN THE ORGIN TARGET
                Character target;
                TradeSession.TradeItem[] Items;
                if (this.character.TradeSession.Source == this.character)
                {
                    target = session.Target;
                    Items  = session.TargetItem;
                }
                else
                {
                    target = session.Source;
                    Items  = session.SourceItem;
                }

                //Calculate required slots
                int slots = 0;
                for (int i = 0; i < 16; i++)
                {
                    if (Items[i] == null)
                    {
                        continue;
                    }
                    slots++;
                }

                if (slots > this.character.container.Capacity - this.character.container.Count)
                {
                    //Not enough space oponent
                    SMSG_TRADERESULT2 spkt = new SMSG_TRADERESULT2();
                    spkt.Reason    = (byte)TradeResult.TargetNotEnoughInventorySpace;
                    spkt.SessionId = target.id;
                    target.client.Send((byte[])spkt);

                    //Not enough space myself
                    SMSG_TRADERESULT2 spkt2 = new SMSG_TRADERESULT2();
                    spkt2.Reason    = (byte)TradeResult.NotEnoughIventorySpace;
                    spkt2.SessionId = this.character.id;
                    this.Send((byte[])spkt2);

                    //Set tradesession to null;
                    this.character.TradeSession = null;
                    target.TradeSession         = null;
                    return;
                }
                else
                {
                    if (session.Source == this.character)
                    {
                        session.SourceHasAgreed = true;
                    }
                    else
                    {
                        session.TargetHasAgreed = true;
                    }
                }

                if (session.TargetHasAgreed && session.SourceHasAgreed)
                {
                    target.ZENY         += session.ZenySource;
                    this.character.ZENY -= session.ZenySource;

                    target.ZENY         -= session.ZenyTarget;
                    this.character.ZENY += session.ZenyTarget;

                    List <Rag2Item> SourceList = new List <Rag2Item>();
                    List <Rag2Item> TargetList = new List <Rag2Item>();
                    for (int i = 0; i < 16; i++)
                    {
                        TradeSession.TradeItem item = session.SourceItem[i];
                        if (item == null)
                        {
                            continue;
                        }

                        Rag2Item ragitem = this.character.container[item.Slot];
                        if (ragitem.count - item.Count == 0)
                        {
                            SourceList.Add(ragitem);
                            this.character.container.RemoveAt(item.Slot);
                            SMSG_DELETEITEM spkt = new SMSG_DELETEITEM();
                            spkt.Container    = 2;
                            spkt.Index        = item.Slot;
                            spkt.SessionId    = this.character.id;
                            spkt.UpdateReason = (byte)ItemUpdateReason.SendToTrader;
                            this.Send((byte[])spkt);
                        }
                        else
                        {
                            SourceList.Add(ragitem.Clone(item.Count));
                            ragitem.count -= item.Count;
                            SMSG_UPDATEITEM spkt = new SMSG_UPDATEITEM();
                            spkt.Container    = 2;
                            spkt.Index        = item.Slot;
                            spkt.SessionId    = this.character.id;
                            spkt.UpdateReason = (byte)ItemUpdateReason.SendToTrader;
                            spkt.UpdateType   = 4;
                            this.Send((byte[])spkt);
                        }
                    }

                    for (int i = 0; i < 16; i++)
                    {
                        TradeSession.TradeItem item = session.TargetItem[i];
                        if (item == null)
                        {
                            continue;
                        }

                        Rag2Item ragitem = target.container[item.Slot];
                        if (ragitem.count - item.Count == 0)
                        {
                            TargetList.Add(ragitem);
                            this.character.container.RemoveAt(item.Slot);
                            SMSG_DELETEITEM spkt = new SMSG_DELETEITEM();
                            spkt.Container    = 2;
                            spkt.Index        = item.Slot;
                            spkt.SessionId    = target.id;
                            spkt.UpdateReason = (byte)ItemUpdateReason.SendToTrader;
                            target.client.Send((byte[])spkt);
                        }
                        else
                        {
                            TargetList.Add(ragitem.Clone(item.Count));
                            ragitem.count -= item.Count;
                            SMSG_UPDATEITEM spkt = new SMSG_UPDATEITEM();
                            spkt.Container    = 2;
                            spkt.Index        = item.Slot;
                            spkt.SessionId    = target.id;
                            spkt.UpdateReason = (byte)ItemUpdateReason.SendToTrader;
                            spkt.UpdateType   = 4;
                            target.client.Send((byte[])spkt);
                        }
                    }

                    for (int i = 0; i < SourceList.Count; i++)
                    {
                        Rag2Item     ragitem = SourceList[i];
                        int          index   = target.container.Add(ragitem);
                        SMSG_ADDITEM spkt    = new SMSG_ADDITEM();
                        spkt.Container    = 2;
                        spkt.UpdateReason = (byte)ItemUpdateReason.ReceiveFromTrade;
                        spkt.SessionId    = target.id;
                        spkt.SetItem(ragitem, index);
                        target.client.Send((byte[])spkt);
                    }

                    for (int i = 0; i < TargetList.Count; i++)
                    {
                        Rag2Item     ragitem = TargetList[i];
                        int          index   = this.character.container.Add(ragitem);
                        SMSG_ADDITEM spkt    = new SMSG_ADDITEM();
                        spkt.Container    = 2;
                        spkt.UpdateReason = (byte)ItemUpdateReason.ReceiveFromTrade;
                        spkt.SessionId    = this.character.id;
                        spkt.SetItem(ragitem, index);
                        this.Send((byte[])spkt);
                    }

                    //Update zeny yourself
                    SMSG_SENDZENY spkt4 = new SMSG_SENDZENY();
                    spkt4.SessionId = this.character.id;
                    spkt4.Zeny      = this.character.ZENY;
                    this.Send((byte[])spkt4);

                    //Update zeny opponent
                    SMSG_SENDZENY spkt5 = new SMSG_SENDZENY();
                    spkt5.SessionId = target.id;
                    spkt5.Zeny      = target.ZENY;
                    target.client.Send((byte[])spkt5);

                    //Set traderesult to succesfull
                    SMSG_TRADERESULT2 spkt3 = new SMSG_TRADERESULT2();
                    spkt3.SessionId = this.character.id;
                    this.Send((byte[])spkt3);

                    //Set traderesult successfull oponent
                    SMSG_TRADERESULT2 spkt2 = new SMSG_TRADERESULT2();
                    spkt2.SessionId = target.id;
                    target.client.Send((byte[])spkt2);

                    //Set the tradesession to null
                    this.character.TradeSession = null;
                    target.TradeSession         = null;
                }
            }
        }