Пример #1
0
        /// <summary>
        /// 读邮件
        /// </summary>
        public void HandleReadMail(long mail_idx)
        {
            Player player = UnitManager.Instance.GetUnitByIdx(m_char_idx) as Player;

            if (player == null)
            {
                return;
            }
            MailInfo mail_info;

            if (m_all_mails.TryGetValue(mail_idx, out mail_info))
            {
                if (m_del_mails.Contains(mail_idx))
                {
                    return;
                }

                //是否全服邮件
                if (mail_info.receiver_idx == 0)
                {
                    if (!m_had_recv_mails.Contains(mail_idx))
                    {//同步到db,已经领取过全局邮件
                        m_had_recv_mails.Add(mail_idx);
                        SQLMailHandle.UpdateCharRecvs(m_char_idx, m_had_recv_mails, player.db_id);
                    }
                }
                else if (!Utils.HasFlag(mail_info.flags, (uint)eMailFlags.READED))
                {//修改标记
                    mail_info.flags = Utils.InsertFlag(mail_info.flags, (uint)eMailFlags.READED);
                    m_save_mails.Add(mail_idx);
                    m_is_dirty = true;
                }

                //通知客户端
                ss2c.MailRead msg_client = PacketPools.Get(ss2c.msg.MAIL_READ) as ss2c.MailRead;
                msg_client.mail_info.Copy(mail_info);
                ServerNetManager.Instance.SendProxy(player.client_uid, msg_client);
            }
        }
Пример #2
0
        /// <summary>
        /// 邮件操作:优先级依次是 读->领取附件->删除
        /// </summary>
        public void HandleCommandMail(long mail_idx, eMailCommandType type)
        {
            PlayerCache player = PlayerCacheManager.Instance.GetMember(m_char_idx);

            if (player == null)
            {
                return;
            }

            switch (type)
            {
            case eMailCommandType.READ_MAIL:
            {
                MailInfo mail_info;
                if (m_all_mails.TryGetValue(mail_idx, out mail_info))
                {
                    if (m_del_mails.Contains(mail_idx))
                    {
                        break;
                    }
                    if (m_save_mails.Contains(mail_idx))
                    {
                        break;
                    }
                    if (mail_info.receiver_idx == 0)
                    {
                        if (!m_had_recv_mails.Contains(mail_idx))
                        {        //同步到db,已经领取过全局邮件
                            m_had_recv_mails.Add(mail_idx);
                            SQLMailHandle.UpdateCharRecvs(m_char_idx, m_had_recv_mails);
                        }
                        break;
                    }

                    //判断是否已经读取
                    if (!Utils.HasFlag(mail_info.flags, (uint)eMailFlags.READED))
                    {
                        m_save_mails.Add(mail_idx);
                        mail_info.flags = Utils.InsertFlag(mail_info.flags, (uint)eMailFlags.READED);
                        m_is_dirty      = true;
                    }
                }
            }
            break;

            case eMailCommandType.DELETE_MAIL:
            {
                MailInfo mail_info;
                if (m_all_mails.TryGetValue(mail_idx, out mail_info))
                {
                    if (m_del_mails.Contains(mail_idx))
                    {
                        break;
                    }
                    if (mail_info.receiver_idx == 0)
                    {
                        break;
                    }

                    m_del_mails.Add(mail_idx);
                    m_save_mails.Remove(mail_idx);
                    m_all_mails.Remove(mail_idx);
                    CommonObjectPools.Despawn(mail_info);
                    m_is_dirty = true;
                }
            }
            break;

            case eMailCommandType.TAKE_MAIL:
            case eMailCommandType.TAKE_MAIL_BUT_RETAIN:
            {
                MailInfo mail_info;
                if (m_all_mails.TryGetValue(mail_idx, out mail_info))
                {
                    if (m_del_mails.Contains(mail_idx))
                    {
                        break;
                    }
                    if (mail_info.receiver_idx == 0)
                    {
                        break;
                    }

                    //修改状态,前提是带附件
                    if (Utils.HasFlag(mail_info.flags, (uint)eMailFlags.CARRY_ITEM))
                    {
                        m_save_mails.Remove(mail_idx);
                        mail_info.flags = Utils.InsertFlag(mail_info.flags, (uint)eMailFlags.READED);
                        mail_info.flags = Utils.RemoveFlag(mail_info.flags, (uint)eMailFlags.CARRY_ITEM);
                        m_is_dirty      = true;
                    }
                }
            }
            break;
            }
        }