Exemplo n.º 1
0
        public void LevelUp(IUnitOfWork unitOfWork, IStatApplier statApplier, Player player, AssignmentType completedAssignment)
        {
            var currentLevel = player.Level;
            var nextLevel = unitOfWork.LevelRepository.Get((level => level.LevelNumber == currentLevel + 1), null, "").FirstOrDefault();
            // TODO: Make several games on one API ? Check if right game fds
            if (nextLevel == null) return; // Max level reached

            // Check if experience reached
            if (player.Experience < nextLevel.ExperienceReq) return; // Not enough experience

            // Check general stats
            foreach (var generalStatAmountReq in nextLevel.GeneralStatsReq)
            {
                var playerGeneralStatAmount =
                    player.GeneralStats.FirstOrDefault(
                        u =>
                            u.StatEffect.AffectedStatBonus ==
                            generalStatAmountReq.StatEffect.AffectedStatBonus);
                if (playerGeneralStatAmount == null) throw new Exception("Database error, player has no such general stat entry");

                var res = generalStatAmountReq.CompareTo(playerGeneralStatAmount);
                if (res == 1)
                    return; // No level up
            }

            // Level up reached! DING DING DING
            player.Level += 1;
            player.JobPoints += nextLevel.JobPointReward;
            statApplier.ApplyGeneralStats(player, nextLevel.GeneralStatRewards);
        }
Exemplo n.º 2
0
        public List<Achievement> CheckAchievements(IStatApplier statApplier, IUnitOfWork unitOfWork, Player player)
        {
            // Retrieve all achievements, which the player did not already achieve
            var unachievedAchievements = unitOfWork.AchievementRepository.Get(ach => player.Achievements.TrueForAll(playerAch => playerAch.Id != ach.Id), null, "");

            var resList = new List<Achievement>();
            // Check for achieved achievements
            foreach (var unachievedAchievement in unachievedAchievements)
            {
                // Check for assignments completed of certain types
                if (!PassedAssignmentTypes(player, unachievedAchievement)) break; // Break if achievement failed here
                // Check for general stat requirements
                if (!PassedGeneralStats(player, unachievedAchievement)) break; // Break if achievement failed here
                // Check for Job Point purchase requirements
                if (!PassedJobPointPurchases(player, unachievedAchievement)) break; // Break if achievement failed here

                // Achievement gotten!
                player.Achievements.Add(unachievedAchievement);
                statApplier.ApplyJobPoints(player, unachievedAchievement.JobPointReward);
                statApplier.ApplyGeneralStats(player, unachievedAchievement.GeneralStatRewards);
                resList.Add(unachievedAchievement);
            }

            return resList; // Return all newly achieved achievements
        }