Ejemplo n.º 1
0
        //分发邮件
        private Mail PushMail(MailManager _this,
                              string name,
                              string text,
                              List <KeyValuePair <int, int> > reward,
                              string sender             = "",
                              List <ItemBaseData> datas = null, int type = 0)
        {
            if (_this.Mails.Count >= StaticParam.MaxMailCount)
            {
                var minMail = GetTimeMin(_this);
                if (minMail == null)
                {
                    return(null);
                }
                minMail.Name      = name;
                minMail.Text      = text;
                minMail.Send      = sender;
                minMail.StartTime = DateTime.Now.ToBinary();
                minMail.OverTime  = DateTime.Now.AddDays(15).ToBinary();
                minMail.State     = 0;
                minMail.Type      = type;
                if (reward == null)
                {
                    minMail.Reward.Clear();
                }
                else
                {
                    minMail.Reward.Clear();
                    foreach (var i in reward)
                    {
                        var itemDb = new ItemBaseData();
                        ShareItemFactory.Create(i.Key, itemDb);
                        itemDb.Count = i.Value;
                        minMail.Reward.Add(itemDb);
                        if (datas != null)
                        {
                            datas.Add(itemDb);
                        }
                    }
                    //foreach (KeyValuePair<int, int> i in reward)
                    //{
                    //    ItemBaseData itemDb = new ItemBaseData();
                    //    ItemFactory.Create(i.Key, itemDb);
                    //    itemDb.Count = i.Value;
                    //    minMail.Reward.Clear();
                    //    minMail.Reward.Add(itemDb);
                    //}
                }
                minMail.MarkDirty();
                return(minMail);
            }
            var nextId   = _this.GetNextId();
            var tempmail = new Mail(_this.mCharacter, nextId);

            tempmail.Name = name;
            tempmail.Send = sender;
            tempmail.Text = text;
            tempmail.Type = type;
            if (reward != null)
            {
                foreach (var i in reward)
                {
                    var itemDb = new ItemBaseData();
                    ShareItemFactory.Create(i.Key, itemDb);
                    itemDb.Count = i.Value;
                    tempmail.Reward.Add(itemDb);
                    if (datas != null)
                    {
                        datas.Add(itemDb);
                    }
                }
                //foreach (KeyValuePair<int, int> i in reward)
                //{
                //    ItemBaseData itemDb = new ItemBaseData();
                //    ItemFactory.Create(i.Key, itemDb);
                //    itemDb.Count = i.Value;
                //    tempmail.Reward.Add(itemDb);
                //    if (datas != null)
                //    {
                //        datas.Add(itemDb);
                //    }
                //}
            }
            tempmail.OverTime = DateTime.Now.AddDays(15).ToBinary();
            //tempmail.OverTime = DateTime.Now.AddHours(15).ToBinary();
            _this.Mails.Add(tempmail.Guid, tempmail);
            _this.AddChild(tempmail);
            _this.mDbData.mData.Add(tempmail.mDbData);
            tempmail.MarkDirty();
            return(tempmail);
        }
Ejemplo n.º 2
0
        //接收邮件
        public Mail PushMail(MailManager _this,
                             string name,
                             string text,
                             Dictionary <int, int> reward,
                             string sender             = "",
                             List <ItemBaseData> datas = null, int type = 0)
        {
            // pushMailCount 记录邮件的发送次数
            var  pushMailCount = 0;
            Mail mail          = null;
            var  items         = new List <KeyValuePair <int, int> >();
            var  index         = 1;

            // 拆分邮件中的附件
            foreach (var i in reward)
            {
                var tbItem = Table.GetItemBase(i.Key);
                if (tbItem == null)
                {
                    Logger.Error("Get a error item ID=" + i.Key.ToString());
                    continue;
                }

                var count = i.Value;
                if (count < 1)
                {
                    continue;
                }
                if (tbItem.MaxCount == -1 || tbItem.MaxCount >= count)
                {
                    if (items.Count >= 5)
                    {
                        mail = PushMail(_this, string.Format("{0}{1}", name, string.Format("({0})", index)), text, items,
                                        sender, datas, type);
                        index++;
                        items = new List <KeyValuePair <int, int> >();
                        pushMailCount++;
                    }
                    items.Add(new KeyValuePair <int, int>(i.Key, count));
                    continue;
                }
                do
                {
                    if (items.Count >= 5)
                    {
                        mail = PushMail(_this, string.Format("{0}{1}", name, string.Format("({0})", index)), text, items,
                                        sender, datas, type);
                        index++;
                        items = new List <KeyValuePair <int, int> >();
                        pushMailCount++;
                    }
                    if (tbItem.MaxCount < count)
                    {
                        items.Add(new KeyValuePair <int, int>(i.Key, tbItem.MaxCount));
                        count -= tbItem.MaxCount;
                    }
                    else
                    {
                        items.Add(new KeyValuePair <int, int>(i.Key, count));
                        count = 0;
                    }
                } while (count > 0);
            }

            // 如果邮件的发送次数为0,应该发一封
            if (items.Count > 0 || pushMailCount == 0)
            {
                mail = PushMail(_this, string.Format("{0}{1}", name, index == 1 ? "" : string.Format("({0})", index)),
                                text, items, sender, datas, type);
            }
            return(mail);
            //if (Mails.Count >= StaticParam.MaxMailCount)
            //{
            //    Mail minMail = GetTimeMin();
            //    if (minMail == null) return null;
            //    minMail.Name = name;
            //    minMail.Text = text;
            //    minMail.StartTime = DateTime.Now.ToBinary();
            //    minMail.OverTime = DateTime.Now.AddDays(15).ToBinary();
            //    minMail.State = 0;
            //    if (reward == null)
            //    {
            //        minMail.Reward.Clear();
            //    }
            //    else
            //    {
            //        foreach (KeyValuePair<int, int> i in reward)
            //        {
            //            ItemBaseData itemDb = new ItemBaseData();
            //            ItemFactory.Create(i.Key, itemDb);
            //            itemDb.Count = i.Value;
            //            minMail.Reward.Clear();
            //            minMail.Reward.Add(itemDb);
            //        }
            //        //minMail.Reward = reward;
            //    }
            //    minMail.MarkDirty();
            //    return minMail;
            //}
            //ulong nextId = GetNextId();
            //Mail tempmail = new Mail(mCharacter, nextId);
            //tempmail.Name = name;
            //tempmail.Send = sender;
            //tempmail.Text = text;
            //if (reward != null)
            //{
            //    //tempmail.Reward = reward;
            //    foreach (KeyValuePair<int, int> i in reward)
            //    {
            //        ItemBaseData itemDb = new ItemBaseData();
            //        ItemFactory.Create(i.Key, itemDb);
            //        itemDb.Count = i.Value;
            //        tempmail.Reward.Add(itemDb);
            //        if (datas != null)
            //        {
            //            datas.Add(itemDb);
            //        }
            //    }
            //}
            //tempmail.OverTime = DateTime.Now.AddDays(15).ToBinary();
            ////tempmail.OverTime = DateTime.Now.AddHours(15).ToBinary();
            //Mails.Add(tempmail.Guid, tempmail);
            //AddChild(tempmail);
            //mDbData.mData.Add(tempmail.mDbData);
            //tempmail.MarkDirty();
            //return tempmail;
        }