示例#1
0
 public void Send()
 {
     MailMgr.SendMail(this);
 }
示例#2
0
        /// <summary>
        /// Creates and sends a new Mail with the given parameters
        /// </summary>
        public MailError SendMail(CharacterRecord recipient,
                                  string subject,
                                  string body,
                                  MailStationary stationary,
                                  ICollection <Item> items,
                                  uint money,
                                  uint cod)
        {
            if (subject.Length > MailMgr.MaxMailSubjectLength ||
                body.Length > MailMgr.MaxMailBodyLength)
            {
                // Player cannot send mails this long through the mail dialog
                return(MailError.INTERNAL_ERROR);
            }

            // Can't send mail to yourself.
            if (recipient.EntityLowId == m_chr.EntityId.Low)
            {
                MailHandler.SendResult(m_chr.Client, 0, MailResult.MailSent, MailError.CANNOT_SEND_TO_SELF);
                return(MailError.CANNOT_SEND_TO_SELF);
            }

            var requiredCash = money;

            // Check that sender is good for the money.
            if (MailMgr.ChargePostage)
            {
                if (!m_chr.GodMode)
                {
                    requiredCash += MailMgr.PostagePrice;

                    var count = (items == null) ? 0u : (uint)items.Count;
                    if (count > 0)
                    {
                        requiredCash += ((count - 1) * MailMgr.PostagePrice);
                    }
                }
            }

            if (requiredCash > m_chr.Money)
            {
                MailHandler.SendResult(m_chr.Client, 0u, MailResult.MailSent, MailError.NOT_ENOUGH_MONEY);
                return(MailError.NOT_ENOUGH_MONEY);
            }

            // Charge for the letter (already checked, Character has enough)
            m_chr.Money -= requiredCash;

            // All good, send an ok message
            MailHandler.SendResult(m_chr.Client, 0u, MailResult.MailSent, MailError.OK);
            m_chr.Achievements.CheckPossibleAchievementUpdates(AchievementCriteriaType.GoldSpentForMail, requiredCash);

            var deliveryDelay = 0u;

            if (!m_chr.GodMode)
            {
                if ((money > 0 || (items != null && items.Count > 0)) && (m_chr.Account.AccountId != recipient.AccountId))
                {
                    deliveryDelay = MailMgr.MaxPacketDeliveryDelay;
                }
            }

            // Create a new letter object
            var letter = new MailMessage(subject, body)
            {
                LastModifiedOn    = null,
                SenderId          = m_chr.EntityId.Low,
                ReceiverId        = recipient.EntityLowId,
                MessageStationary = stationary,
                MessageType       = MailType.Normal,
                CashOnDelivery    = cod,
                IncludedMoney     = money,
                SendTime          = DateTime.Now,
                DeliveryTime      = DateTime.Now.AddSeconds(deliveryDelay)
            };

            // Attach items to the new letter
            if (items != null && items.Count > 0)
            {
                // remove the item from the sender's inventory and add them to the list
                letter.SetItems(items);
            }

            MailMgr.SendMail(letter);
            return(MailError.OK);
        }
示例#3
0
        /// <summary>
        /// Creates and sends a new Mail with the given parameters
        /// </summary>
        public MailError SendMail(CharacterRecord recipient, string subject, string body, MailStationary stationary,
                                  ICollection <Item> items, uint money, uint cod)
        {
            if (subject.Length > 128 || body.Length > 512)
            {
                return(MailError.INTERNAL_ERROR);
            }
            if ((int)recipient.EntityLowId == (int)m_chr.EntityId.Low)
            {
                MailHandler.SendResult(m_chr.Client, 0U, MailResult.MailSent,
                                       MailError.CANNOT_SEND_TO_SELF);
                return(MailError.CANNOT_SEND_TO_SELF);
            }

            uint amount = money;

            if (MailMgr.ChargePostage && !m_chr.GodMode)
            {
                amount += MailMgr.PostagePrice;
                uint num = items == null ? 0U : (uint)items.Count;
                if (num > 0U)
                {
                    amount += (num - 1U) * MailMgr.PostagePrice;
                }
            }

            if (amount > m_chr.Money)
            {
                MailHandler.SendResult(m_chr.Client, 0U, MailResult.MailSent,
                                       MailError.NOT_ENOUGH_MONEY);
                return(MailError.NOT_ENOUGH_MONEY);
            }

            m_chr.SubtractMoney(amount);
            MailHandler.SendResult(m_chr.Client, 0U, MailResult.MailSent, MailError.OK);
            m_chr.Achievements.CheckPossibleAchievementUpdates(AchievementCriteriaType.GoldSpentForMail, amount,
                                                               0U, null);
            uint num1 = 0;

            if (!m_chr.GodMode && (money > 0U || items != null && items.Count > 0) &&
                m_chr.Account.AccountId != recipient.AccountId)
            {
                num1 = MailMgr.MaxPacketDeliveryDelay;
            }
            MailMessage letter = new MailMessage(subject, body)
            {
                LastModifiedOn    = new DateTime?(),
                SenderId          = m_chr.EntityId.Low,
                ReceiverId        = recipient.EntityLowId,
                MessageStationary = stationary,
                MessageType       = MailType.Normal,
                CashOnDelivery    = cod,
                IncludedMoney     = money,
                SendTime          = DateTime.Now,
                DeliveryTime      = DateTime.Now.AddSeconds(num1)
            };

            if (items != null && items.Count > 0)
            {
                letter.SetItems(items);
            }
            MailMgr.SendMail(letter);
            return(MailError.OK);
        }