コード例 #1
0
ファイル: FestivalHelper.cs プロジェクト: jinfei426/Scut
        /// <summary>
        /// 累计消费活动
        /// </summary>
        public static void TriggerFestivalConsume(string userID, int consumeNum, FestivalType festivalType)
        {
            FestivalInfo fest = GetInfo(festivalType);
            if (fest == null)
            {
                return;
            }
            var cacheSet = new GameDataCacheSet<UserConsume>();
            UserConsume userConsume = cacheSet.FindKey(userID);
            if (userConsume == null)
            {
                userConsume = new UserConsume();
                userConsume.UserID = userID;
                userConsume.GameCoin = 0;
                userConsume.GoldNum = 0;
                userConsume.EnergyNum = 0;
                cacheSet.Add(userConsume);
                cacheSet.Update();
                userConsume = new GameDataCacheSet<UserConsume>().FindKey(userID);
            }
            //晶石
            if (festivalType == FestivalType.SparConsumption)
            {
                if (userConsume.GoldDate < fest.StartDate)
                {
                    userConsume.GoldDate = fest.StartDate;
                    userConsume.GoldNum = consumeNum;
                }
                else
                {
                    userConsume.GoldNum = MathUtils.Addition(userConsume.GoldNum, consumeNum);
                }
            }

            //金币
            if (festivalType == FestivalType.GameCoin)
            {
                if (userConsume.CoinDate < fest.StartDate)
                {
                    userConsume.CoinDate = fest.StartDate;
                    userConsume.GameCoin = consumeNum;
                }
                else
                {
                    userConsume.GameCoin = MathUtils.Addition(userConsume.GameCoin, consumeNum);
                }
            }

            //精力
            if (festivalType == FestivalType.Energy)
            {
                if (userConsume.EnergyDate < fest.StartDate)
                {
                    userConsume.EnergyDate = fest.StartDate;
                    userConsume.EnergyNum = consumeNum;
                }
                else
                {
                    userConsume.EnergyNum = MathUtils.Addition(userConsume.EnergyNum, consumeNum);
                }
            }
            FestivalInfo[] festivalInfosArray =
              new ShareCacheStruct<FestivalInfo>().FindAll(m => m.FestivalType == festivalType).ToArray();
            foreach (FestivalInfo festivalInfo in festivalInfosArray)
            {
                FestivalConsumeCount(festivalInfo, userID);
            }
        }
コード例 #2
0
ファイル: FestivalHelper.cs プロジェクト: jinfei426/Scut
 /// <summary>
 /// 累计消费送礼
 /// </summary>
 public static void PayAccumulation(string userID, int consumeNum)
 {
     FestivalInfo fest = GetInfo(FestivalType.PayAccumulation);
     if (fest == null)
     {
         return;
     }
     var cacheSet = new GameDataCacheSet<UserConsume>();
     UserConsume userConsume = cacheSet.FindKey(userID);
     if (userConsume == null)
     {
         userConsume = new UserConsume();
         userConsume.UserID = userID;
         userConsume.GameCoin = 0;
         userConsume.GoldNum = 0;
         userConsume.EnergyNum = 0;
         cacheSet.Add(userConsume);
         cacheSet.Update();
         userConsume = new GameDataCacheSet<UserConsume>().FindKey(userID);
     }
     if (userConsume.GoldDate < fest.StartDate)
     {
         userConsume.GoldDate = fest.StartDate;
         userConsume.GoldNum = consumeNum;
     }
     else
     {
         userConsume.GoldNum = MathUtils.Addition(userConsume.GoldNum, consumeNum);
     }
     var cacheSetRestrain = new GameDataCacheSet<FestivalRestrain>();
     var festivalList = new ShareCacheStruct<FestivalInfo>().FindAll(s => s.FestivalType == FestivalType.PayAccumulation);
     foreach (var info in festivalList)
     {
         if (!info.IsStop)
             continue;
         if (info.StartDate > DateTime.Now)
             continue;
         if (info.EndDate < DateTime.Now)
             continue;
         if (info.FestivalType == FestivalType.PayAccumulation)
         {
             FestivalRestrain fRest = cacheSetRestrain.FindKey(userID, info.FestivalID);
             if (fRest != null && userConsume.GoldNum >= info.RestrainNum)
             {
                 AppendFestivalRestrain(userID, fest.FestivalID, fest.RestrainNum);
             }
         }
     }
 }