Ejemplo n.º 1
0
        public void SendChangeItem(int oldItem, int newItem)
        {
            CPlayerChangeItem msg = new CPlayerChangeItem();

            msg.old_id = oldItem;
            msg.new_id = newItem;
            Client.Instance.Send(msg);
        }
Ejemplo n.º 2
0
        private void OnRecvPlayerChangeItem(IChannel channel, Message message)
        {
            CPlayerChangeItem request = message as CPlayerChangeItem;

            using (var conn = GameDataBase.GetConnection())
            {
                using (var trans = conn.BeginTransaction())
                {
                    using (var cmd = conn.CreateCommand())
                    {
                        cmd.CommandText = "Update Item Set status='Storing' Where item_id=@old_id;";
                        cmd.Parameters.AddWithValue("old_id", request.old_id);
                        int res = cmd.ExecuteNonQuery();
                        if (res != 1)
                        {
                            ClientTipInfo(channel, "Oh! Change Item Error!");
                            trans.Rollback();
                            return;
                        }
                    }
                    using (var cmd = conn.CreateCommand())
                    {
                        cmd.CommandText = "Update Item Set status='Using' Where item_id=@new_id;";
                        cmd.Parameters.AddWithValue("new_id", request.new_id);
                        int res = cmd.ExecuteNonQuery();
                        if (res != 1)
                        {
                            ClientTipInfo(channel, "Oh! Change Iten Error!");
                            trans.Rollback();
                            return;
                        }
                    }
                    trans.Commit();
                }
            }
            SPlayerChangeItem response = new SPlayerChangeItem();

            response.new_id = request.new_id;
            response.old_id = request.old_id;
            channel.Send(response);
            var player = (Player)channel.GetContent();

            FrontEnd.Item.DItem ditem = null;
            foreach (var item in player.wearing)
            {
                if (item.Value.item_id == request.old_id)
                {
                    ditem = item.Value;
                }
            }
            player.wearing.Remove(ditem.item_type);
            player.inventory.Add(ditem.item_id, ditem);
            ditem = player.inventory[request.new_id];
            player.inventory.Remove(request.new_id);
            player.wearing.Add(ditem.item_type, ditem);
            player.refreshAttr();
            return;
        }