Exemplo n.º 1
0
        private static bool GetDropItems(eDropType type, int dropId, ref List <ItemInfo> itemInfos)
        {
            bool result;

            if (dropId == 0)
            {
                result = false;
            }
            else
            {
                try
                {
                    int             dropItemCount = 1;
                    List <DropItem> unFiltItems   = DropMgr.FindDropItem(dropId);
                    int             maxRound      = DropInventory.random.Next((
                                                                                  from s in unFiltItems
                                                                                  select s.Random).Max());
                    List <DropItem> filtItems = (
                        from s in unFiltItems
                        where s.Random >= maxRound
                        select s).ToList <DropItem>();
                    int maxItems = filtItems.Count <DropItem>();
                    if (maxItems == 0)
                    {
                        result = false;
                        return(result);
                    }
                    dropItemCount = ((dropItemCount > maxItems) ? maxItems : dropItemCount);
                    int[] randomArray = DropInventory.GetRandomUnrepeatArray(0, maxItems - 1, dropItemCount);
                    int[] array       = randomArray;
                    for (int j = 0; j < array.Length; j++)
                    {
                        int i                 = array[j];
                        int itemCount         = DropInventory.random.Next(filtItems[i].BeginData, filtItems[i].EndData);
                        ItemTemplateInfo temp = ItemMgr.FindItemTemplate(filtItems[i].ItemId);
                        ItemInfo         item = ItemInfo.CreateFromTemplate(temp, itemCount, 101);
                        if (item != null)
                        {
                            item.IsBinds   = filtItems[i].IsBind;
                            item.ValidDate = filtItems[i].ValueDate;
                            item.IsTips    = filtItems[i].IsTips;
                            item.IsLogs    = filtItems[i].IsLogs;
                            if (itemInfos == null)
                            {
                                itemInfos = new List <ItemInfo>();
                            }
                            switch (type)
                            {
                            case eDropType.Cards:
                            case eDropType.Box:
                            case eDropType.NPC:
                            case eDropType.Boss:
                            case eDropType.Special:
                                if (DropInfoMgr.CanDrop(temp.TemplateID))
                                {
                                    itemInfos.Add(item);
                                }
                                break;

                            default:
                                itemInfos.Add(item);
                                break;
                            }
                        }
                    }
                    if (itemInfos != null && itemInfos.Count > 0)
                    {
                        result = true;
                        return(result);
                    }
                }
                catch (Exception ex)
                {
                    //if (DropInventory.log.IsErrorEnabled)
                    {
                        DropInventory.log.Error(string.Concat(new object[]
                        {
                            "Drop Error:",
                            type,
                            " @ ",
                            ex
                        }));
                    }
                }
                result = false;
            }
            return(result);
        }
Exemplo n.º 2
0
 private static bool GetDropItems(eDropType type, int dropId, ref List <ItemInfo> itemInfos)
 {
     if (dropId == 0)
     {
         return(false);
     }
     try
     {
         int             num      = 1;
         List <DropItem> source   = DropMgr.FindDropItem(dropId);
         int             maxRound = ThreadSafeRandom.NextStatic((
                                                                    from s in source
                                                                    select s.Random).Max());
         List <DropItem> list = (
             from s in source
             where s.Random >= maxRound
             select s).ToList <DropItem>();
         int  num2 = list.Count <DropItem>();
         bool result;
         if (num2 == 0)
         {
             result = false;
             return(result);
         }
         num = ((num > num2) ? num2 : num);
         int[] randomUnrepeatArray = DropInventory.GetRandomUnrepeatArray(0, num2 - 1, num);
         int[] array = randomUnrepeatArray;
         for (int i = 0; i < array.Length; i++)
         {
             int index = array[i];
             int count = ThreadSafeRandom.NextStatic(list[index].BeginData, list[index].EndData);
             ItemTemplateInfo itemTemplateInfo = ItemMgr.FindItemTemplate(list[index].ItemId);
             ItemInfo         itemInfo         = ItemInfo.CreateFromTemplate(itemTemplateInfo, count, 101);
             if (itemInfo != null)
             {
                 itemInfo.IsBinds   = list[index].IsBind;
                 itemInfo.ValidDate = list[index].ValueDate;
                 if (itemInfos == null)
                 {
                     itemInfos = new List <ItemInfo>();
                 }
                 if (DropInfoMgr.CanDrop(itemTemplateInfo.TemplateID))
                 {
                     itemInfos.Add(itemInfo);
                 }
             }
         }
         result = true;
         return(result);
     }
     catch (Exception ex)
     {
         if (DropInventory.log.IsErrorEnabled)
         {
             DropInventory.log.Error(string.Concat(new object[]
             {
                 "Drop Error:",
                 type,
                 " @ ",
                 ex
             }));
         }
     }
     return(false);
 }
Exemplo n.º 3
0
        /// <summary>
        /// 获取掉落多个物品
        /// </summary>
        /// <param name="e"></param>
        /// <returns></returns>
        private static bool GetDropItems(eDropType type, int dropId, ref List <ItemInfo> itemInfos)
        {
            #region 定义变量
            if (dropId == 0)
            {
                return(false);
            }
            #endregion

            try
            {
                #region 生成随机物品
                int             dropItemCount = 1;
                List <DropItem> unFiltItems   = Bussiness.Managers.DropMgr.FindDropItem(dropId);
                int             maxRound      = Bussiness.ThreadSafeRandom.NextStatic(unFiltItems.Select(s => s.Random).Max());
                List <DropItem> filtItems     = unFiltItems.Where(s => s.Random >= maxRound).ToList();
                int             maxItems      = filtItems.Count();
                if (maxItems == 0)
                {
                    return(false);
                }
                else
                {
                    dropItemCount = dropItemCount > maxItems ? maxItems : dropItemCount;
                }
                int[] randomArray = GetRandomUnrepeatArray(0, maxItems - 1, dropItemCount);
                #endregion

                #region 设置随机物品属性
                foreach (int i in randomArray)
                {
                    int itemCount         = Bussiness.ThreadSafeRandom.NextStatic(filtItems[i].BeginData, filtItems[i].EndData);
                    ItemTemplateInfo temp = Bussiness.Managers.ItemMgr.FindItemTemplate(filtItems[i].ItemId);
                    ItemInfo         item = ItemInfo.CreateFromTemplate(temp, itemCount, 101);
                    if (item == null)
                    {
                        continue;
                    }
                    item.IsBinds   = filtItems[i].IsBind;
                    item.ValidDate = filtItems[i].ValueDate;
                    if (itemInfos == null)
                    {
                        itemInfos = new List <ItemInfo>();
                    }
                    if (DropInfoMgr.CanDrop(temp.TemplateID))//宏观掉落
                    {
                        itemInfos.Add(item);
                    }
                }
                return(true);

                #endregion
            }
            catch (Exception ex)
            {
                if (log.IsErrorEnabled)
                {
                    log.Error("Drop Error:" + type + " @ " + ex);
                }
            }
            return(false);
        }