public OperationResultVo FillProfileGamificationDetails(Guid currentUserId, ref ProfileViewModel vm)
        {
            try
            {
                Gamification gamification = gamificationDomainService.GetByUserId(vm.UserId);

                GamificationLevel currentLevel = gamificationDomainService.GetLevel(gamification.CurrentLevelNumber);

                if (currentLevel == null)
                {
                    currentLevel = new GamificationLevel
                    {
                        Name = "No Levels On The Database"
                    };
                }

                vm.IndieXp.LevelName          = currentLevel.Name;
                vm.IndieXp.CurrentLevelNumber = gamification.CurrentLevelNumber;
                vm.IndieXp.XpCurrentLevel     = gamification.XpCurrentLevel;
                vm.IndieXp.XpCurrentLevelMax  = gamification.XpToNextLevel + gamification.XpCurrentLevel;

                return(new OperationResultVo(true));
            }
            catch (Exception ex)
            {
                return(new OperationResultVo(ex.Message));
            }
        }
Beispiel #2
0
        public int ProcessAction(Guid userId, PlatformAction action)
        {
            int scoreValue = 5;

            GamificationAction actionToProcess = Task.Run(async() => await gamificationActionRepository.GetByAction(action)).Result;

            if (actionToProcess != null)
            {
                scoreValue = actionToProcess.ScoreValue;
            }

            Task <IEnumerable <Gamification> > userGamificationTask = gamificationRepository.GetByUserId(userId);

            userGamificationTask.Wait();

            Gamification userGamification = userGamificationTask.Result.FirstOrDefault();

            if (userGamification == null)
            {
                GamificationLevel newLevel = Task.Run(async() => await gamificationLevelRepository.GetByNumber(1)).Result;

                userGamification = GenerateNewGamification(userId);

                userGamification.XpCurrentLevel += scoreValue;
                userGamification.XpTotal        += scoreValue;
                userGamification.XpToNextLevel   = (newLevel.XpToAchieve - scoreValue);

                gamificationRepository.Add(userGamification);
            }
            else
            {
                userGamification.XpCurrentLevel += scoreValue;
                userGamification.XpTotal        += scoreValue;
                userGamification.XpToNextLevel  -= scoreValue;

                if (userGamification.XpToNextLevel <= 0)
                {
                    GamificationLevel currentLevel = Task.Run(async() => await gamificationLevelRepository.GetByNumber(userGamification.CurrentLevelNumber)).Result;
                    GamificationLevel newLevel     = Task.Run(async() => await gamificationLevelRepository.GetByNumber(userGamification.CurrentLevelNumber + 1)).Result;

                    if (newLevel != null)
                    {
                        userGamification.CurrentLevelNumber = newLevel.Number;
                        userGamification.XpCurrentLevel     = (userGamification.XpCurrentLevel - currentLevel.XpToAchieve);
                        userGamification.XpToNextLevel      = (newLevel.XpToAchieve - userGamification.XpCurrentLevel);
                    }
                }

                gamificationRepository.Update(userGamification);
            }

            return(scoreValue);
        }
Beispiel #3
0
        private Gamification GenerateNewGamification(Guid userId)
        {
            Gamification userGamification;

            GamificationLevel firstLevel = Task.Run(async() => await gamificationLevelRepository.GetByNumber(1)).Result;

            userGamification = new Gamification
            {
                CurrentLevelNumber = firstLevel.Number,
                UserId             = userId,
                XpCurrentLevel     = 0,
                XpToNextLevel      = firstLevel.XpToAchieve,
                XpTotal            = 0
            };

            return(userGamification);
        }