Exemple #1
0
        public void SendMailTo(SQLTransaction trans, MailReceiver receiver, MailSender sender, MailCheckMask checkMask = MailCheckMask.None, uint deliver_delay = 0)
        {
            Player pReceiver = receiver.GetPlayer();               // can be NULL
            Player pSender   = sender.GetMailMessageType() == MailMessageType.Normal ? Global.ObjAccessor.FindPlayer(ObjectGuid.Create(HighGuid.Player, sender.GetSenderId())) : null;

            if (pReceiver != null)
            {
                PrepareItems(pReceiver, trans);                            // generate mail template items
            }
            uint mailId = Global.ObjectMgr.GenerateMailID();

            long deliver_time = GameTime.GetGameTime() + deliver_delay;

            //expire time if COD 3 days, if no COD 30 days, if auction sale pending 1 hour
            uint expire_delay;

            // auction mail without any items and money
            if (sender.GetMailMessageType() == MailMessageType.Auction && m_items.Empty() && m_money == 0)
            {
                expire_delay = WorldConfig.GetUIntValue(WorldCfg.MailDeliveryDelay);
            }
            // default case: expire time if COD 3 days, if no COD 30 days (or 90 days if sender is a game master)
            else
            if (m_COD != 0)
            {
                expire_delay = 3 * Time.Day;
            }
            else
            {
                expire_delay = (uint)(pSender != null && pSender.IsGameMaster() ? 90 * Time.Day : 30 * Time.Day);
            }

            long expire_time = deliver_time + expire_delay;

            // Add to DB
            byte index             = 0;
            PreparedStatement stmt = DB.Characters.GetPreparedStatement(CharStatements.INS_MAIL);

            stmt.AddValue(index, mailId);
            stmt.AddValue(++index, (byte)sender.GetMailMessageType());
            stmt.AddValue(++index, (sbyte)sender.GetStationery());
            stmt.AddValue(++index, GetMailTemplateId());
            stmt.AddValue(++index, sender.GetSenderId());
            stmt.AddValue(++index, receiver.GetPlayerGUIDLow());
            stmt.AddValue(++index, GetSubject());
            stmt.AddValue(++index, GetBody());
            stmt.AddValue(++index, !m_items.Empty());
            stmt.AddValue(++index, expire_time);
            stmt.AddValue(++index, deliver_time);
            stmt.AddValue(++index, m_money);
            stmt.AddValue(++index, m_COD);
            stmt.AddValue(++index, (byte)checkMask);
            trans.Append(stmt);

            foreach (var item in m_items.Values)
            {
                stmt = DB.Characters.GetPreparedStatement(CharStatements.INS_MAIL_ITEM);
                stmt.AddValue(0, mailId);
                stmt.AddValue(1, item.GetGUID().GetCounter());
                stmt.AddValue(2, receiver.GetPlayerGUIDLow());
                trans.Append(stmt);
            }

            // For online receiver update in game mail status and data
            if (pReceiver != null)
            {
                pReceiver.AddNewMailDeliverTime(deliver_time);

                if (pReceiver.IsMailsLoaded())
                {
                    Mail m = new();
                    m.messageID      = mailId;
                    m.mailTemplateId = GetMailTemplateId();
                    m.subject        = GetSubject();
                    m.body           = GetBody();
                    m.money          = GetMoney();
                    m.COD            = GetCOD();

                    foreach (var item in m_items.Values)
                    {
                        m.AddItem(item.GetGUID().GetCounter(), item.GetEntry());
                    }

                    m.messageType  = sender.GetMailMessageType();
                    m.stationery   = sender.GetStationery();
                    m.sender       = sender.GetSenderId();
                    m.receiver     = receiver.GetPlayerGUIDLow();
                    m.expire_time  = expire_time;
                    m.deliver_time = deliver_time;
                    m.checkMask    = checkMask;
                    m.state        = MailState.Unchanged;

                    pReceiver.AddMail(m);                           // to insert new mail to beginning of maillist

                    if (!m_items.Empty())
                    {
                        foreach (var item in m_items.Values)
                        {
                            pReceiver.AddMItem(item);
                        }
                    }
                }
                else if (!m_items.Empty())
                {
                    DeleteIncludedItems(null);
                }
            }
            else if (!m_items.Empty())
            {
                DeleteIncludedItems(null);
            }
        }
Exemple #2
0
 public void SendMailTo(SQLTransaction trans, Player receiver, MailSender sender, MailCheckMask checkMask = MailCheckMask.None, uint deliver_delay = 0)
 {
     SendMailTo(trans, new MailReceiver(receiver), sender, checkMask, deliver_delay);
 }