Example #1
0
        private void RewardAndPunishmentUser_After(IUser sender, RewardAndPunishmentUserEventArgs eventArgs)
        {
            PointSettings pointSettings = pointSettingsManger.Get();
            int           totalPoints   = pointSettings.CalculateIntegratedPoint(sender.ExperiencePoints, sender.ReputationPoints);

            //更新用户等级
            //if (eventArgs.ExperiencePoints <= 0 && eventArgs.ReputationPoints <= 0)
            //    return;
            IUserService               userService     = DIContainer.Resolve <IUserService>();
            UserRankService            userRankService = new UserRankService();
            SortedList <int, UserRank> userRanks       = userRankService.GetAll();
            UserRank maxUserRank = null;

            if (userRanks != null && userRanks.Count > 0)
            {
                maxUserRank = userRanks.First().Value;
            }
            foreach (KeyValuePair <int, UserRank> userRank in userRanks)
            {
                if (totalPoints > userRank.Value.PointLower && userRank.Value.PointLower > maxUserRank.PointLower)
                {
                    maxUserRank = userRank.Value;
                }
            }
            userService.UpdateRank(sender.UserId, maxUserRank.Rank);

            //自动解除管制
            var user = userService.GetFullUser(sender.UserId);

            if (user.IsModerated && !user.IsForceModerated)
            {
                UserSettings userSettings = userSettingsManager.Get();
                if (totalPoints > userSettings.NoModeratedUserPoint)
                {
                    userService.NoModeratedUser(user.UserId);
                }
            }

            //发送通知
            if (sender == null)
            {
                return;
            }
            Notice notice = Notice.New();

            notice.UserId        = sender.UserId;
            notice.ApplicationId = 0;
            notice.TypeId        = NoticeTypeIds.Instance().Hint();
            if (eventArgs.ExperiencePoints < 0 || eventArgs.ReputationPoints < 0 || eventArgs.TradePoints < 0)
            {
                notice.Body = "您被系统扣除经验:" + -eventArgs.ExperiencePoints + "、威望:" + -eventArgs.ReputationPoints + "、金币:" + -eventArgs.TradePoints;
            }
            else
            {
                notice.Body = "您收到系统奖励经验:" + eventArgs.ExperiencePoints + "、威望:" + eventArgs.ReputationPoints + "、金币:" + eventArgs.TradePoints;
            }
            notice.LeadingActorUrl = SiteUrls.FullUrl(SiteUrls.Instance().ListNotices(sender.UserName, null, null));
            noticeService.Create(notice);
        }
Example #2
0
        public ActionResult ManageRanks()
        {
            pageResourceManager.InsertTitlePart("等级管理");



            SortedList <int, UserRank> userRanks = userRankService.GetAll();


            return(View(userRanks));
        }
Example #3
0
        /// <summary>
        /// 更改用户积分
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="eventArgs"></param>
        void ChangePointsEventModule_After(IUser sender, ChangePointsEventArgs eventArgs)
        {
            if (eventArgs.ExperiencePoints <= 0 && eventArgs.ReputationPoints <= 0)
            {
                return;
            }

            IUserService userService = DIContainer.Resolve <IUserService>();

            //自动升级
            UserRankService            userRankService = new UserRankService();
            SortedList <int, UserRank> userRanks       = userRankService.GetAll();
            UserRank maxUserRank = null;

            if (userRanks != null && userRanks.Count > 0)
            {
                maxUserRank = userRanks.ElementAt(0).Value;
            }
            IPointSettingsManager pointSettingsManger = DIContainer.Resolve <IPointSettingsManager>();
            PointSettings         pointSettings       = pointSettingsManger.Get();
            int totalPoints = pointSettings.CalculateIntegratedPoint(sender.ExperiencePoints, sender.ReputationPoints);

            foreach (KeyValuePair <int, UserRank> userRank in userRanks)
            {
                if (totalPoints > userRank.Value.PointLower && userRank.Value.PointLower > maxUserRank.PointLower)
                {
                    maxUserRank = userRank.Value;
                }
            }
            if (maxUserRank.Rank > sender.Rank)
            {
                userService.UpdateRank(sender.UserId, maxUserRank.Rank);
            }

            //自动解除管制
            var user = userService.GetFullUser(sender.UserId);

            if (user.IsModerated && !user.IsForceModerated)
            {
                UserSettings userSettings = DIContainer.Resolve <IUserSettingsManager>().Get();
                if (totalPoints > userSettings.NoModeratedUserPoint)
                {
                    userService.NoModeratedUser(user.UserId);
                }
            }
        }
Example #4
0
        public ActionResult MyRank(string spaceKey)
        {
            IUser         user          = userService.GetUser(spaceKey);
            PointSettings pointSettings = pointSettingsManger.Get();

            pageResourceManager.InsertTitlePart("我的等级");

            int totalPoints = pointSettings.CalculateIntegratedPoint(user.ExperiencePoints, user.ReputationPoints);

            SortedList <int, UserRank> userRanks = userRankService.GetAll();
            UserRank userRank = userRankService.Get(user.Rank);

            if (userRank != null)
            {
                ViewData["userRankName"] = userRank.RankName;
            }


            ViewData["userRanks"]   = userRanks;
            ViewData["totalPoints"] = totalPoints;
            if (user.Rank + 1 <= userRankService.GetAll().Count())
            {
                ViewData["nextRankName"] = userRankService.Get(user.Rank + 1).RankName;
                ViewData["leftUpgradeExperiencePoints"] = userRankService.Get(user.Rank + 1).PointLower - totalPoints;
            }
            else
            {
                ViewData["leftUpgradeExperiencePoints"] = 0;
            }

            #region 计算进度条百分比

            List <UserRank> ranks      = userRanks.Values.ToList();
            int             a          = (userRanks.Count() - 2) / 3;
            int             rank       = user.Rank;
            double          leftPoints = 0;

            if (rank >= 1 && rank < ranks.ElementAt(a).Rank)
            {
                leftPoints = totalPoints / (double)ranks.ElementAt(a).PointLower / 5;
            }
            else if (rank >= ranks.ElementAt(a).Rank&& rank < ranks.ElementAt(2 * a).Rank)
            {
                leftPoints = (totalPoints - ranks.ElementAt(a).PointLower) / (double)(ranks.ElementAt(2 * a).PointLower - ranks.ElementAt(a).PointLower) / 5 + 0.2;
            }

            else if (rank >= ranks.ElementAt(2 * a).Rank&& rank < ranks.ElementAt(3 * a).Rank)
            {
                leftPoints = (totalPoints - ranks.ElementAt(2 * a).PointLower) / (double)(ranks.ElementAt(3 * a).PointLower - ranks.ElementAt(2 * a).PointLower) / 5 + 0.4;
            }

            else if (rank >= ranks.ElementAt(3 * a).Rank&& rank < userRanks.ToArray()[userRanks.Count() - 1].Value.Rank)
            {
                leftPoints = (totalPoints - ranks.ElementAt(3 * a).PointLower) / (double)(userRanks.ToArray()[userRanks.Count() - 1].Value.PointLower - ranks.ElementAt(3 * a).PointLower) / 5 + 0.6;
            }
            else
            {
                leftPoints = totalPoints / double.MaxValue + 0.8;
            }
            ViewData["leftPoints"] = leftPoints;
            #endregion


            return(View(user));
        }