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

            using (IQueryAdapter dbClient = PlusEnvironment.GetDatabaseManager().GetQueryReactor())
            {
                dbClient.SetQuery("SELECT `id`,`category`,`group_name`,`level`,`reward_pixels`,`reward_points`,`progress_needed`,`game_id` FROM `achievements`");
                DataTable dTable = dbClient.getTable();

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

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

                        if (!Achievements.ContainsKey(groupName))
                        {
                            Achievement Achievement = new Achievement(id, groupName, category, Convert.ToInt32(dRow["game_id"]));
                            Achievement.AddLevel(AchievementLevel);
                            Achievements.Add(groupName, Achievement);
                        }
                        else
                            Achievements[groupName].AddLevel(AchievementLevel);
                    }
                }
            }
        }
 public AchievementUnlockedComposer(Achievement Achievement, int Level, int PointReward, int PixelReward)
     : base(ServerPacketHeader.AchievementUnlockedMessageComposer)
 {
     base.WriteInteger(Achievement.Id); // Achievement ID
     base.WriteInteger(Level); // Achieved level
     base.WriteInteger(144); // Unknown. Random useless number.
    base.WriteString(Achievement.GroupName + Level); // Achieved name
     base.WriteInteger(PointReward); // Point reward
     base.WriteInteger(PixelReward); // Pixel reward
     base.WriteInteger(0); // Unknown.
     base.WriteInteger(10); // Unknown.
     base.WriteInteger(21); // Unknown. (Extra reward?)
    base.WriteString(Level > 1 ? Achievement.GroupName + (Level - 1) : string.Empty);
    base.WriteString(Achievement.Category);
     base.WriteBoolean(true);
 }
 public AchievementProgressedComposer(Achievement Achievement, int TargetLevel, AchievementLevel TargetLevelData,int TotalLevels, UserAchievement UserData)
     : base(ServerPacketHeader.AchievementProgressedMessageComposer)
 {
     base.WriteInteger(Achievement.Id); // Unknown (ID?)
     base.WriteInteger(TargetLevel); // Target level
    base.WriteString(Achievement.GroupName + TargetLevel); // Target name/desc/badge
     base.WriteInteger(1); // Progress req/target 
     base.WriteInteger(TargetLevelData.Requirement); // Reward in Pixels
     base.WriteInteger(TargetLevelData.RewardPixels); // Reward Ach Score
     base.WriteInteger(0); // ?
     base.WriteInteger(UserData != null ? UserData.Progress : 0); // Current progress
     base.WriteBoolean(UserData != null ? (UserData.Level >= TotalLevels) : false); // Set 100% completed(??)
    base.WriteString(Achievement.Category); // Category
    base.WriteString(string.Empty);
     base.WriteInteger(TotalLevels); // Total amount of levels 
     base.WriteInteger(0);
 }
Beispiel #4
0
        public bool ProgressAchievement(GameClient session, string group, int progress, bool fromBeginning = false)
        {
            if (!_achievements.ContainsKey(group) || session == null)
            {
                return(false);
            }

            Achievement data = null;

            data = _achievements[group];

            UserAchievement userData = session.GetHabbo().GetAchievementData(group);

            if (userData == null)
            {
                userData = new UserAchievement(group, 0, 0);
                session.GetHabbo().Achievements.TryAdd(group, userData);
            }

            int TotalLevels = data.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 = data.Levels[TargetLevel];
            int NewProgress = 0;

            if (fromBeginning)
            {
                NewProgress = progress;
            }
            else
            {
                NewProgress = (userData != null ? userData.Progress + progress : progress);
            }

            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(group + TargetLevel, true, session);
                }
                else
                {
                    session.GetHabbo().GetBadgeComponent().RemoveBadge(Convert.ToString(group + (TargetLevel - 1)));
                    session.GetHabbo().GetBadgeComponent().GiveBadge(group + TargetLevel, true, session);
                }

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


                session.SendPacket(new AchievementUnlockedComposer(data, TargetLevel, TargetLevelData.RewardPoints, TargetLevelData.RewardPixels));
                session.GetHabbo().GetMessenger().BroadcastAchievement(session.GetHabbo().Id, Users.Messenger.MessengerEventTypes.AchievementUnlocked, group + TargetLevel);

                using (IQueryAdapter dbClient = PlusEnvironment.GetDatabaseManager().GetQueryReactor())
                {
                    dbClient.SetQuery("REPLACE INTO `user_achievements` VALUES ('" + session.GetHabbo().Id + "', @group, '" + NewLevel + "', '" + NewProgress + "')");
                    dbClient.AddParameter("group", group);
                    dbClient.RunQuery();
                }

                userData.Level    = NewLevel;
                userData.Progress = NewProgress;

                session.GetHabbo().Duckets += TargetLevelData.RewardPixels;
                session.GetHabbo().GetStats().AchievementPoints += TargetLevelData.RewardPoints;
                session.SendPacket(new HabboActivityPointNotificationComposer(session.GetHabbo().Duckets, TargetLevelData.RewardPixels));
                session.SendPacket(new AchievementScoreComposer(session.GetHabbo().GetStats().AchievementPoints));

                AchievementLevel NewLevelData = data.Levels[NewTarget];
                session.SendPacket(new AchievementProgressedComposer(data, NewTarget, NewLevelData, TotalLevels, session.GetHabbo().GetAchievementData(group)));

                return(true);
            }
            else
            {
                userData.Level    = NewLevel;
                userData.Progress = NewProgress;
                using (IQueryAdapter dbClient = PlusEnvironment.GetDatabaseManager().GetQueryReactor())
                {
                    dbClient.SetQuery("REPLACE INTO `user_achievements` VALUES ('" + session.GetHabbo().Id + "', @group, '" + NewLevel + "', '" + NewProgress + "')");
                    dbClient.AddParameter("group", group);
                    dbClient.RunQuery();
                }

                session.SendPacket(new AchievementProgressedComposer(data, TargetLevel, TargetLevelData, TotalLevels, session.GetHabbo().GetAchievementData(group)));
            }
            return(false);
        }