public static void GetAchievementLevels(out Dictionary <string, Achievement> Achievements)
        {
            Achievements = new Dictionary <string, Achievement>();

            using (IQueryAdapter DbClient = ProjectHub.GetDatabaseManager().GetQueryReactor())
            {
                DbClient.SetQuery("SELECT `id`,`category`,`group_name`,`level`,`reward_pixels`,`reward_points`,`progress_needed`,`game_id` FROM `" + ProjectHub.DbPrefix + "achievements`");
                DataTable DataTable = DbClient.getTable();

                if (DataTable != null)
                {
                    foreach (DataRow DataRow in DataTable.Rows)
                    {
                        int              Id               = Convert.ToInt32(DataRow["id"]);
                        string           Category         = Convert.ToString(DataRow["category"]);
                        string           GroupName        = Convert.ToString(DataRow["group_name"]);
                        int              Level            = Convert.ToInt32(DataRow["level"]);
                        int              RewardPixels     = Convert.ToInt32(DataRow["reward_pixels"]);
                        int              RewardPoints     = Convert.ToInt32(DataRow["reward_points"]);
                        int              ProgressNeeded   = Convert.ToInt32(DataRow["progress_needed"]);
                        AchievementLevel AchievementLevel = new AchievementLevel(Level, RewardPixels, RewardPoints, ProgressNeeded);

                        if (!Achievements.ContainsKey(GroupName))
                        {
                            Achievement Achievement = new Achievement(Id, GroupName, Category, Convert.ToInt32(DataRow["game_id"]));
                            Achievement.AddLevel(AchievementLevel);
                            Achievements.Add(GroupName, Achievement);
                        }
                        else
                        {
                            Achievements[GroupName].AddLevel(AchievementLevel);
                        }
                    }
                }
            }
        }
Esempio n. 2
0
        public bool ProgressAchievement(GameClient Session, string AchievementGroup, int ProgressAmount, bool FromZero = false)
        {
            if (!Achievements.ContainsKey(AchievementGroup) || Session == null)
            {
                return(false);
            }

            Achievement AchievementData = null;

            AchievementData = Achievements[AchievementGroup];
            UserAchievement UserData = Session.GetHabbo().GetAchievementData(AchievementGroup);

            if (UserData == null)
            {
                UserData = new UserAchievement(AchievementGroup, 0, 0);
                Session.GetHabbo().Achievements.TryAdd(AchievementGroup, UserData);
            }

            int TotalLevels = AchievementData.Levels.Count;

            if (UserData != null && UserData.Level == TotalLevels)
            {
                return(false);
            }

            int TargetLevel = (UserData != null ? UserData.Level + 1 : 1);

            if (TargetLevel > TotalLevels)
            {
                TargetLevel = TotalLevels;
            }

            AchievementLevel TargetLevelData = AchievementData.Levels[TargetLevel];
            int NewProgress = 0;

            if (FromZero)
            {
                NewProgress = ProgressAmount;
            }
            else
            {
                NewProgress = (UserData != null ? UserData.Progress + ProgressAmount : ProgressAmount);
            }

            int NewLevel  = (UserData != null ? UserData.Level : 0);
            int NewTarget = NewLevel + 1;

            if (NewTarget > TotalLevels)
            {
                NewTarget = TotalLevels;
            }

            if (NewProgress >= TargetLevelData.Requirement)
            {
                NewLevel++;
                NewTarget++;
                int ProgressRemainder = NewProgress - TargetLevelData.Requirement;
                NewProgress = 0;

                if (TargetLevel == 1)
                {
                    Session.GetHabbo().GetBadgeComponent().GiveBadge(AchievementGroup + TargetLevel, true, Session);
                }
                else
                {
                    Session.GetHabbo().GetBadgeComponent().RemoveBadge(Convert.ToString(AchievementGroup + (TargetLevel - 1)));
                    Session.GetHabbo().GetBadgeComponent().GiveBadge(AchievementGroup + TargetLevel, true, Session);
                }

                if (NewTarget > TotalLevels)
                {
                    NewTarget = TotalLevels;
                }

                Session.SendMessage(new AchievementUnlockedComposer(AchievementData, TargetLevel, TargetLevelData.RewardPoints, TargetLevelData.RewardPixels));
                Session.GetHabbo().GetMessenger().BroadcastAchievement(Session.GetHabbo().Id, Users.Messenger.MessengerEventTypes.ACHIEVEMENT_UNLOCKED, AchievementGroup + TargetLevel);

                using (IQueryAdapter DbClient = ProjectHub.GetDatabaseManager().GetQueryReactor())
                {
                    DbClient.SetQuery("REPLACE INTO `" + ProjectHub.DbPrefix + "user_achievements` VALUES ('" + Session.GetHabbo().Id + "', @group, '" + NewLevel + "', '" + NewProgress + "')");
                    DbClient.AddParameter("group", AchievementGroup);
                    DbClient.RunQuery();
                }

                UserData.Level    = NewLevel;
                UserData.Progress = NewProgress;
                Session.GetHabbo().Duckets += TargetLevelData.RewardPixels;
                Session.GetHabbo().GetStats().AchievementPoints += TargetLevelData.RewardPoints;
                Session.SendMessage(new HabboActivityPointNotificationComposer(Session.GetHabbo().Duckets, TargetLevelData.RewardPixels));
                Session.SendMessage(new AchievementScoreComposer(Session.GetHabbo().GetStats().AchievementPoints));
                AchievementLevel NewLevelData = AchievementData.Levels[NewTarget];
                Session.SendMessage(new AchievementProgressedComposer(AchievementData, NewTarget, NewLevelData, TotalLevels, Session.GetHabbo().GetAchievementData(AchievementGroup)));

                return(true);
            }
            else
            {
                UserData.Level    = NewLevel;
                UserData.Progress = NewProgress;

                using (IQueryAdapter DbClient = ProjectHub.GetDatabaseManager().GetQueryReactor())
                {
                    DbClient.SetQuery("REPLACE INTO `" + ProjectHub.DbPrefix + "user_achievements` VALUES ('" + Session.GetHabbo().Id + "', @group, '" + NewLevel + "', '" + NewProgress + "')");
                    DbClient.AddParameter("group", AchievementGroup);
                    DbClient.RunQuery();
                }

                Session.SendMessage(new AchievementProgressedComposer(AchievementData, TargetLevel, TargetLevelData, TotalLevels, Session.GetHabbo().GetAchievementData(AchievementGroup)));
            }

            return(false);
        }
Esempio n. 3
0
 public void AddLevel(AchievementLevel Level)
 {
     Levels.Add(Level.Level, Level);
 }