Beispiel #1
0
 public static void UpdateCachedListForSaleGoodsData(SaleGoodsData saleGoodsData, int[] typeAndID, bool add)
 {
     lock (SaleManager.Mutex_SaleGoodsDict)
     {
         if (SaleManager._OrderdSaleGoodsListDict.Count != 0)
         {
             if (null != typeAndID)
             {
                 List <SearchArgs> list = new List <SearchArgs>();
                 int color     = Global.GetEquipColor(saleGoodsData.SalingGoodsData);
                 int moneyType = SaleManager.GetSaleMoneyType(saleGoodsData.SalingGoodsData);
                 List <SearchArgs> argsList = SaleManager._OrderdSaleGoodsListDict.Keys.ToList <SearchArgs>();
                 foreach (SearchArgs key in argsList)
                 {
                     if ((key.ID == 0 && key.Type == typeAndID[0]) || key.ID == typeAndID[1] || key.Type == 1)
                     {
                         if ((1 << color - 1 & key.ColorFlags) != 0)
                         {
                             if ((key.MoneyFlags & moneyType) != 0)
                             {
                                 SaleManager.UpdateOrderdList(SaleManager._OrderdSaleGoodsListDict[key], saleGoodsData, key.OrderBy == 0, add, (SearchOrderTypes)key.OrderTypeFlags);
                             }
                         }
                     }
                 }
             }
         }
     }
 }
Beispiel #2
0
        /// <summary>
        /// 按排序类型等条件从列表中添加或删除元素
        /// </summary>
        /// <param name="list"></param>
        /// <param name="saleGoodsData"></param>
        /// <param name="desc"></param>
        /// <param name="add"></param>
        private static void UpdateOrderdList(List <SaleGoodsData> list, SaleGoodsData saleGoodsData, bool desc, bool add, SearchOrderTypes searchOrderType)
        {
            if (add)
            {
                if (desc)
                {
                    list.BinaryInsertDesc(saleGoodsData, GetComparerFor(desc, add, searchOrderType));
                }
                else
                {
                    list.BinaryInsertAsc(saleGoodsData, GetComparerFor(desc, add, searchOrderType));
                }
            }
            else
            {
#if false
                list.Remove(saleGoodsData);
#else
                int index = list.BinarySearch(saleGoodsData, GetComparerFor(desc, add, searchOrderType));
                if (index < 0)
                {
                    //二分查找失败,可能是物品属性变化或不可比较,只能遍历了
                    for (int i = 0; i < list.Count; i++)
                    {
                        if (list[i].GoodsDbID == saleGoodsData.GoodsDbID)
                        {
                            list.RemoveAt(i);
                            return;
                        }
                    }
                }
                else
                {
                    for (int i = index; i >= 0; i--)
                    {
                        if (list[i].GoodsDbID == saleGoodsData.GoodsDbID)
                        {
                            list.RemoveAt(i);
                            return;
                        }
                    }
                    for (int i = index + 1; i < list.Count; i++)
                    {
                        if (list[i].GoodsDbID == saleGoodsData.GoodsDbID)
                        {
                            list.RemoveAt(i);
                            return;
                        }
                    }
                }
#endif
            }
        }
Beispiel #3
0
        public static void AddLiXianSaleGoodsItem(LiXianSaleGoodsItem liXianSaleGoodsItem)
        {
            SaleGoodsData saleGoodsData = new SaleGoodsData
            {
                GoodsDbID       = liXianSaleGoodsItem.GoodsDbID,
                SalingGoodsData = liXianSaleGoodsItem.SalingGoodsData,
                RoleID          = liXianSaleGoodsItem.RoleID,
                RoleName        = liXianSaleGoodsItem.RoleName,
                RoleLevel       = liXianSaleGoodsItem.RoleLevel
            };

            SaleManager.AddSaleGoodsData(saleGoodsData);
        }
Beispiel #4
0
        public static void AddSaleGoodsItem(SaleGoodsItem saleGoodsItem)
        {
            SaleGoodsData saleGoodsData = new SaleGoodsData
            {
                GoodsDbID       = saleGoodsItem.GoodsDbID,
                SalingGoodsData = saleGoodsItem.SalingGoodsData,
                RoleID          = saleGoodsItem.Client.ClientData.RoleID,
                RoleName        = Global.FormatRoleName(saleGoodsItem.Client, saleGoodsItem.Client.ClientData.RoleName),
                RoleLevel       = saleGoodsItem.Client.ClientData.Level
            };

            SaleManager.AddSaleGoodsData(saleGoodsData);
        }
Beispiel #5
0
 private static void UpdateOrderdList(List <SaleGoodsData> list, SaleGoodsData saleGoodsData, bool desc, bool add, SearchOrderTypes searchOrderType)
 {
     if (add)
     {
         if (desc)
         {
             list.BinaryInsertDesc(saleGoodsData, SaleManager.GetComparerFor(desc, add, searchOrderType));
         }
         else
         {
             list.BinaryInsertAsc(saleGoodsData, SaleManager.GetComparerFor(desc, add, searchOrderType));
         }
     }
     else
     {
         int index = list.BinarySearch(saleGoodsData, SaleManager.GetComparerFor(desc, add, searchOrderType));
         if (index < 0)
         {
             for (int i = 0; i < list.Count; i++)
             {
                 if (list[i].GoodsDbID == saleGoodsData.GoodsDbID)
                 {
                     list.RemoveAt(i);
                     break;
                 }
             }
         }
         else
         {
             for (int i = index; i >= 0; i--)
             {
                 if (list[i].GoodsDbID == saleGoodsData.GoodsDbID)
                 {
                     list.RemoveAt(i);
                     return;
                 }
             }
             for (int i = index + 1; i < list.Count; i++)
             {
                 if (list[i].GoodsDbID == saleGoodsData.GoodsDbID)
                 {
                     list.RemoveAt(i);
                     break;
                 }
             }
         }
     }
 }
Beispiel #6
0
        public static void AddSaleGoodsData(SaleGoodsData saleGoodsData)
        {
            int goodsID = saleGoodsData.SalingGoodsData.GoodsID;

            int[] typeAndID = SaleManager.GetTypeAndID(goodsID);
            if (null != typeAndID)
            {
                lock (SaleManager.Mutex_SaleGoodsDict)
                {
                    List <SaleGoodsData> list = SaleManager._SaleGoodsDict2[typeAndID[0]][typeAndID[1]];
                    SaleManager.UpdateOrderdList(list, saleGoodsData, true, true, SearchOrderTypes.OrderByMoney);
                    SaleManager._SaleGoodsDict[saleGoodsData.GoodsDbID] = saleGoodsData;
                    SaleManager.UpdateCachedListForSaleGoodsData(saleGoodsData, typeAndID, true);
                }
            }
        }
Beispiel #7
0
        /// <summary>
        /// 更新缓存的列表
        /// </summary>
        /// <param name="saleGoodsData"></param>
        /// <param name="typeAndID"></param>
        /// <param name="add"></param>
        public static void UpdateCachedListForSaleGoodsData(SaleGoodsData saleGoodsData, int[] typeAndID, bool add)
        {
            lock (Mutex_SaleGoodsDict)
            {
                if (_OrderdSaleGoodsListDict.Count == 0)
                {
                    return;
                }
                if (null != typeAndID)
                {
                    List <SearchArgs> list = new List <SearchArgs>();
                    int color     = Global.GetEquipColor(saleGoodsData.SalingGoodsData);
                    int moneyType = saleGoodsData.SalingGoodsData.SaleMoney1 > 0 ? 1 : 2;
                    List <SearchArgs> argsList = _OrderdSaleGoodsListDict.Keys.ToList();
                    foreach (var key in argsList)
                    {
                        if ((key.ID == 0 && key.Type == typeAndID[0]) || key.ID == typeAndID[1] || key.Type == 1)
                        {
                            if ((1 << (color - 1) & key.ColorFlags) == 0)
                            {
                                continue;
                            }
                            if ((key.MoneyFlags & moneyType) == 0)
                            {
                                continue;
                            }
#if false
                            _OrderdSaleGoodsListDict.Remove(key);
#else
                            //新增了几种排序类型,还要要写好几种排序比较器,先用上面的方法,直接清除掉吧
                            UpdateOrderdList(_OrderdSaleGoodsListDict[key], saleGoodsData, key.OrderBy == 0, add, (SearchOrderTypes)key.OrderTypeFlags);
#endif
                        }
                    }
                }
            }
        }