Exemplo n.º 1
0
        internal static void GetAchievementLevels(out Dictionary <string, Achievement> achievements, IQueryAdapter dbClient)
        {
            achievements = new Dictionary <string, Achievement>();

            dbClient.setQuery("SELECT * FROM achievements");
            DataTable dTable = dbClient.getTable();

            uint   id;
            string category;
            string groupName;
            int    level;
            int    rewardPixels;
            int    rewardPoints;
            int    progressNeeded;

            foreach (DataRow dRow in dTable.Rows)
            {
                id             = Convert.ToUInt32(dRow["id"]);
                category       = (string)dRow["category"];
                groupName      = (string)dRow["group_name"];
                level          = (int)dRow["level"];
                rewardPixels   = (int)dRow["reward_pixels"];
                rewardPoints   = (int)dRow["reward_points"];
                progressNeeded = (int)dRow["progress_needed"];

                AchievementLevel achievementLevel = new AchievementLevel(level, rewardPixels, rewardPoints, progressNeeded);

                if (!achievements.ContainsKey(groupName))
                {
                    Achievement achievement = new Achievement(id, groupName, category);
                    achievement.AddLevel(achievementLevel);

                    achievements.Add(groupName, achievement);
                }
                else
                {
                    achievements[groupName].AddLevel(achievementLevel);
                }
            }
        }
Exemplo n.º 2
0
        internal static void GetAchievementLevels(out Dictionary<string, Achievement> achievements, IQueryAdapter dbClient)
        {
            achievements = new Dictionary<string, Achievement>();

            dbClient.setQuery("SELECT * FROM achievements");
            DataTable dTable = dbClient.getTable();

            uint id;
            string category;
            string groupName;
            int level;
            int rewardPixels;
            int rewardPoints;
            int progressNeeded;
            foreach (DataRow dRow in dTable.Rows)
            {
                id = Convert.ToUInt32(dRow["id"]);
                category = (string)dRow["category"];
                groupName = (string)dRow["group_name"];
                level = (int)dRow["level"];
                rewardPixels = (int)dRow["reward_pixels"];
                rewardPoints = (int)dRow["reward_points"];
                progressNeeded = (int)dRow["progress_needed"];

                AchievementLevel achievementLevel = new AchievementLevel(level, rewardPixels, rewardPoints, progressNeeded);

                if (!achievements.ContainsKey(groupName))
                {
                    Achievement achievement = new Achievement(id, groupName, category);
                    achievement.AddLevel(achievementLevel);

                    achievements.Add(groupName, achievement);
                }
                else
                {
                    achievements[groupName].AddLevel(achievementLevel);
                }
            }
        }
Exemplo n.º 3
0
        internal bool ProgressUserAchievement(GameClient Session, string AchievementGroup, int ProgressAmount)
        {
            if (!Achievements.ContainsKey(AchievementGroup))
            {
                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.Add(AchievementGroup, UserData);
            }

            int TotalLevels = AchievementData.Levels.Count;

            if (UserData != null && UserData.Level == TotalLevels)
            {
                return(false); // done, no more.
            }

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

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

            AchievementLevel TargetLevelData = AchievementData.Levels[TargetLevel];

            int 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;

                Session.GetHabbo().GetBadgeComponent().GiveBadge(AchievementGroup + TargetLevel, true);

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

                Session.GetHabbo().ActivityPoints += TargetLevelData.RewardPixels;
                Session.GetHabbo().UpdateActivityPointsBalance(false);

                Session.SendMessage(AchievementUnlockedComposer.Compose(AchievementData, TargetLevel, TargetLevelData.RewardPoints,
                                                                        TargetLevelData.RewardPixels));

                using (IQueryAdapter dbClient = PiciEnvironment.GetDatabaseManager().getQueryreactor())
                {
                    if (dbClient.dbType == Pici.Storage.Database.DatabaseType.MySQL)
                    {
                        dbClient.setQuery("REPLACE INTO user_achievement VALUES (" + Session.GetHabbo().Id + ", @group, " + NewLevel + ", " + NewProgress + ")");
                    }
                    else
                    {
                        dbClient.setQuery("IF EXISTS (SELECT userid FROM user_achievement WHERE userid = " + Session.GetHabbo().Id + " AND group = @group) " +
                                          "	UPDATE user_achievement SET level = " + NewLevel + ", progress = " + NewProgress + " WHERE userid = " + Session.GetHabbo().Id + " AND group = @group " +
                                          "ELSE" +
                                          "	INSERT INTO user_achievement VALUES (" + Session.GetHabbo().Id + ",@group," + NewLevel + "," + NewProgress + ")");
                    }
                    dbClient.addParameter("group", AchievementGroup);
                    dbClient.runQuery();
                }


                UserData.Level    = NewLevel;
                UserData.Progress = NewProgress;

                Session.GetHabbo().AchievementPoints += TargetLevelData.RewardPoints;
                Session.GetHabbo().ActivityPoints    += TargetLevelData.RewardPixels;
                Session.GetHabbo().UpdateActivityPointsBalance(false);
                Session.SendMessage(AchievementScoreUpdateComposer.Compose(Session.GetHabbo().AchievementPoints));


                AchievementLevel NewLevelData = AchievementData.Levels[NewTarget];
                Session.SendMessage(AchievementProgressComposer.Compose(AchievementData, NewTarget, NewLevelData,
                                                                        TotalLevels, Session.GetHabbo().GetAchievementData(AchievementGroup)));

                return(true);
            }
            else
            {
                UserData.Level    = NewLevel;
                UserData.Progress = NewProgress;
                using (IQueryAdapter dbClient = PiciEnvironment.GetDatabaseManager().getQueryreactor())
                {
                    if (dbClient.dbType == Pici.Storage.Database.DatabaseType.MySQL)
                    {
                        dbClient.setQuery("REPLACE INTO user_achievement VALUES (" + Session.GetHabbo().Id + ", @group, " + NewLevel + ", " + NewProgress + ")");
                    }
                    else
                    {
                        dbClient.setQuery("IF EXISTS (SELECT userid FROM user_achievement WHERE userid = " + Session.GetHabbo().Id + " AND group = @group) " +
                                          "	UPDATE user_achievement SET level = " + NewLevel + ", progress = " + NewProgress + " WHERE userid = " + Session.GetHabbo().Id + " AND group = @group " +
                                          "ELSE" +
                                          "	INSERT INTO user_achievement VALUES (" + Session.GetHabbo().Id + ",@group," + NewLevel + "," + NewProgress + ")");
                    }
                    dbClient.addParameter("group", AchievementGroup);
                    dbClient.runQuery();
                }

                Session.SendMessage(AchievementProgressComposer.Compose(AchievementData, TargetLevel, TargetLevelData,
                                                                        TotalLevels, Session.GetHabbo().GetAchievementData(AchievementGroup)));
            }

            return(false);
        }
Exemplo n.º 4
0
 public void AddLevel(AchievementLevel Level)
 {
     Levels.Add(Level.Level, Level);
 }
Exemplo n.º 5
0
 public void AddLevel(AchievementLevel Level)
 {
     Levels.Add(Level.Level, Level);
 }