Beispiel #1
0
 public static bool ReLoad()
 {
     try
     {
         Dictionary <int, TreasureAwardInfo> treasureAward = new Dictionary <int, TreasureAwardInfo>();
         if (TreasureAwardMgr.Load(treasureAward))
         {
             TreasureAwardMgr.m_lock.AcquireWriterLock(15000);
             try
             {
                 TreasureAwardMgr._treasureAward = treasureAward;
                 return(true);
             }
             catch
             {
             }
             finally
             {
                 TreasureAwardMgr.m_lock.ReleaseWriterLock();
             }
         }
     }
     catch (Exception ex)
     {
         if (TreasureAwardMgr.log.IsErrorEnabled)
         {
             TreasureAwardMgr.log.Error((object)"TreasureAwardMgr", ex);
         }
     }
     return(false);
 }
Beispiel #2
0
        public static List <TreasureDataInfo> GetTreasureData()
        {
            List <TreasureDataInfo>  list1         = new List <TreasureDataInfo>();
            List <TreasureAwardInfo> list2         = new List <TreasureAwardInfo>();
            List <TreasureAwardInfo> treasureInfos = TreasureAwardMgr.GetTreasureInfos();
            int num1     = 1;
            int maxRound = ThreadSafeRandom.NextStatic(Enumerable.Max(Enumerable.Select <TreasureAwardInfo, int>((IEnumerable <TreasureAwardInfo>)treasureInfos, (Func <TreasureAwardInfo, int>)(s => s.Random))));
            List <TreasureAwardInfo> list3 = Enumerable.ToList <TreasureAwardInfo>(Enumerable.Where <TreasureAwardInfo>((IEnumerable <TreasureAwardInfo>)treasureInfos, (Func <TreasureAwardInfo, bool>)(s => s.Random >= maxRound)));
            int num2 = Enumerable.Count <TreasureAwardInfo>((IEnumerable <TreasureAwardInfo>)list3);

            if (num2 > 0)
            {
                int count = num1 > num2 ? num2 : num1;
                foreach (int index in TreasureAwardMgr.GetRandomUnrepeatArray(0, num2 - 1, count))
                {
                    TreasureAwardInfo treasureAwardInfo = list3[index];
                    list2.Add(treasureAwardInfo);
                }
            }
            foreach (TreasureAwardInfo treasureAwardInfo in list2)
            {
                list1.Add(new TreasureDataInfo()
                {
                    ID         = 0,
                    UserID     = 0,
                    TemplateID = treasureAwardInfo.TemplateID,
                    Count      = treasureAwardInfo.Count,
                    ValidDate  = treasureAwardInfo.Validate,
                    pos        = -1,
                    BeginDate  = DateTime.Now,
                    IsExit     = true
                });
            }
            return(list1);
        }
Beispiel #3
0
        public static List <TreasureAwardInfo> GetTreasureInfos()
        {
            if (TreasureAwardMgr._treasureAward == null)
            {
                TreasureAwardMgr.Init();
            }
            List <TreasureAwardInfo> list = new List <TreasureAwardInfo>();

            for (int index = 1; index <= TreasureAwardMgr._treasureAward.Count; ++index)
            {
                list.Add(TreasureAwardMgr._treasureAward[index]);
            }
            return(list);
        }
Beispiel #4
0
        public static bool Init()
        {
            bool flag;

            try
            {
                TreasureAwardMgr.m_lock         = new ReaderWriterLock();
                TreasureAwardMgr._treasureAward = new Dictionary <int, TreasureAwardInfo>();
                TreasureAwardMgr.rand           = new ThreadSafeRandom();
                flag = TreasureAwardMgr.Load(TreasureAwardMgr._treasureAward);
            }
            catch (Exception ex)
            {
                if (TreasureAwardMgr.log.IsErrorEnabled)
                {
                    TreasureAwardMgr.log.Error((object)"TreasureAwardMgr", ex);
                }
                flag = false;
            }
            return(flag);
        }
Beispiel #5
0
        public static List <TreasureDataInfo> CreateTreasureData(int UserID)
        {
            List <TreasureDataInfo>            list       = new List <TreasureDataInfo>();
            Dictionary <int, TreasureDataInfo> dictionary = new Dictionary <int, TreasureDataInfo>();
            int num = 0;

            while (list.Count < 16)
            {
                List <TreasureDataInfo> treasureData = TreasureAwardMgr.GetTreasureData();
                int index = TreasureAwardMgr.rand.Next(treasureData.Count);
                TreasureDataInfo treasureDataInfo = treasureData[index];
                treasureDataInfo.UserID = UserID;
                if (!Enumerable.Contains <int>((IEnumerable <int>)dictionary.Keys, treasureDataInfo.TemplateID))
                {
                    dictionary.Add(treasureDataInfo.TemplateID, treasureDataInfo);
                    list.Add(treasureDataInfo);
                }
                ++num;
            }
            return(list);
        }