Пример #1
0
        public ServerMessage Handle(ValueHolder valueHolder = null)
        {
            Achievement      achievement  = valueHolder.GetValue <Achievement>("Achievement");
            AchievementLevel nextLevel    = valueHolder.GetValue <AchievementLevel>("NextLevel");
            AchievementLevel currentLevel = valueHolder.GetValue <AchievementLevel>("CurrentLevel");

            ServerMessage message = BasicUtilies.GetRevisionServerMessage(Revision.PRODUCTION_201601012205_226667486);

            message.Init(r63cOutgoing.AchievementUnlocked);
            message.AppendInt32(achievement.ID);
            message.AppendInt32(nextLevel.Level);
            message.AppendInt32(1337); //idk
            message.AppendString(nextLevel.LevelBadge);
            message.AppendInt32(nextLevel.Score);
            message.AppendInt32(nextLevel.ActivityPoints);
            message.AppendInt32(nextLevel.ActivityPointsType);
            message.AppendInt32(0); //fb(?)
            message.AppendInt32(0); //fb(?)
            if (currentLevel != null)
            {
                message.AppendString(currentLevel.LevelBadge);
            }
            else
            {
                message.AppendString("");
            }
            message.AppendString(achievement.Category);
            message.AppendBoolean(true);
            return(message);
        }
Пример #2
0
        public static ServerMessage Compose(Session Session, ReadOnlyCollection <Achievement> Achievements)
        {
            ServerMessage Message = new ServerMessage(OpcodesOut.ACHIEVEMENTS_LIST);

            Message.AppendInt32(Achievements.Count);

            foreach (Achievement Achievement in Achievements)
            {
                UserAchievement UserData    = Session.AchievementCache.GetAchievementData(Achievement.GroupName);
                int             TargetLevel = (UserData != null ? UserData.Level + 1 : 1);
                int             TotalLevels = Achievement.Levels.Count;

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

                AchievementLevel TargetLevelData = Achievement.Levels[TargetLevel];

                Message.AppendUInt32(Achievement.Id);                                               // Unknown (ID?)
                Message.AppendInt32(TargetLevel);                                                   // Target level
                Message.AppendStringWithBreak(Achievement.GroupName + TargetLevel);                 // Target name/desc/badge
                Message.AppendInt32(TargetLevelData.Requirement);                                   // Progress req/target
                Message.AppendInt32(TargetLevelData.PixelReward);                                   // Pixel reward
                Message.AppendInt32(TargetLevelData.PointsReward);                                  // Unknown(??)
                Message.AppendInt32(UserData != null ? UserData.Progress : 0);                      // Current progress
                Message.AppendBoolean(UserData != null ? (UserData.Level >= TotalLevels) : false);  // Set 100% completed(??)
                Message.AppendStringWithBreak(Achievement.Category);                                // Category
                Message.AppendInt32(TotalLevels);                                                   // Total amount of levels
            }

            return(Message);
        }
        public ServerMessage Handle(T handler)
        {
            ServerMessage message = BasicUtilies.GetRevisionServerMessage(Revision.PRODUCTION_201601012205_226667486, r63cOutgoing.AchievementList);

            message.AppendInt32(Skylight.GetGame().GetAchievementManager().GetAchievements().Count);
            foreach (Achievement achievement in Skylight.GetGame().GetAchievementManager().GetAchievements())
            {
                AchievementLevel level    = handler.UserAchievements.GetAchievementLevel(achievement.GroupName) == achievement.LevelsCount ? achievement.GetLevel(handler.UserAchievements.GetAchievementLevel(achievement.GroupName)) : achievement.GetLevel(handler.UserAchievements.GetAchievementLevel(achievement.GroupName) + 1);
                AchievementLevel oldlevel = achievement.GetLevel(handler.UserAchievements.GetAchievementLevel(achievement.GroupName) - 1);

                message.AppendInt32(achievement.ID);
                message.AppendInt32(level.Level);
                message.AppendString(level.LevelBadge);
                message.AppendInt32(oldlevel?.ProgressNeeded ?? 0);
                message.AppendInt32(level.ProgressNeeded);
                message.AppendInt32(level.ActivityPoints);
                message.AppendInt32(level.ActivityPointsType);
                message.AppendInt32(handler.UserAchievements.GetAchievementProgress(achievement.GroupName));
                message.AppendBoolean(handler.UserAchievements.GetAchievementLevel(achievement.GroupName) == achievement.LevelsCount);
                message.AppendString(achievement.Category);
                message.AppendString("");
                message.AppendInt32(achievement.LevelsCount);
                message.AppendInt32(0);
            }
            message.AppendString(""); //open category
            return(message);
        }
Пример #4
0
        public AchievementsComposer(GameClient Session, List <Achievement> Achievements)
            : base(ServerPacketHeader.AchievementsMessageComposer)
        {
            WriteInteger(Achievements.Count);
            foreach (Achievement Achievement in Achievements)
            {
                UserAchievement UserData    = Session.Habbo.GetAchievementData(Achievement.GroupName);
                int             TargetLevel = (UserData != null ? UserData.Level + 1 : 1);
                int             TotalLevels = Achievement.Levels.Count;

                TargetLevel = (TargetLevel > TotalLevels ? TotalLevels : TargetLevel);

                AchievementLevel TargetLevelData = Achievement.Levels[TargetLevel];
                WriteInteger(Achievement.Id);                     // Unknown (ID?)
                WriteInteger(TargetLevel);                        // Target level
                WriteString(Achievement.GroupName + TargetLevel); // Target name/desc/badge

                WriteInteger(1);
                WriteInteger(TargetLevelData.Requirement); // Progress req/target
                WriteInteger(TargetLevelData.RewardPixels);

                WriteInteger(0);                                                          // Type of reward
                WriteInteger(UserData != null ? UserData.Progress : 0);                   // Current progress

                WriteBoolean(UserData != null ? (UserData.Level >= TotalLevels) : false); // Set 100% completed(??)
                WriteString(Achievement.Category);                                        // Category
                WriteString(string.Empty);
                WriteInteger(TotalLevels);                                                // Total amount of levels
                WriteInteger(0);
            }
            WriteString("");
        }
Пример #5
0
        public override void Compose(ServerPacket packet)
        {
            packet.WriteInteger(GameId);
            packet.WriteInteger(Achievements.Count);
            foreach (Achievement Ach in Achievements.ToList())
            {
                UserAchievement UserData    = Habbo.GetAchievementData(Ach.GroupName);
                int             TargetLevel = (UserData != null ? UserData.Level + 1 : 1);

                AchievementLevel TargetLevelData = Ach.Levels[TargetLevel];

                packet.WriteInteger(Ach.Id);                                                          // ach id
                packet.WriteInteger(TargetLevel);                                                     // target level
                packet.WriteString(Ach.GroupName + TargetLevel);                                      // badge
                packet.WriteInteger(TargetLevelData.Requirement);                                     // requirement
                packet.WriteInteger(TargetLevelData.Requirement);                                     // requirement
                packet.WriteInteger(TargetLevelData.RewardPixels);                                    // pixels
                packet.WriteInteger(0);                                                               // ach score
                packet.WriteInteger(UserData != null ? UserData.Progress : 0);                        // Current progress
                packet.WriteBoolean(UserData != null ? (UserData.Level >= Ach.Levels.Count) : false); // Set 100% completed(??)
                packet.WriteString(Ach.Category);
                packet.WriteString("basejump");
                packet.WriteInteger(0); // total levels
                packet.WriteInteger(0);
            }
            packet.WriteString("");
        }
        public GameAchievementListComposer(GameClient Session, ICollection <Achievement> Achievements, int GameId)
            : base(ServerPacketHeader.GameAchievementListMessageComposer)
        {
            base.WriteInteger(GameId);
            base.WriteInteger(Achievements.Count);
            foreach (Achievement Ach in Achievements.ToList())
            {
                UserAchievement UserData    = Session.GetHabbo().GetAchievementData(Ach.GroupName);
                int             TargetLevel = (UserData != null ? UserData.Level + 1 : 1);

                AchievementLevel TargetLevelData = Ach.Levels[TargetLevel];

                base.WriteInteger(Ach.Id);                                                          // ach id
                base.WriteInteger(TargetLevel);                                                     // target level
                base.WriteString(Ach.GroupName + TargetLevel);                                      // badge
                base.WriteInteger(TargetLevelData.Requirement);                                     // requirement
                base.WriteInteger(TargetLevelData.Requirement);                                     // requirement
                base.WriteInteger(TargetLevelData.RewardPixels);                                    // pixels
                base.WriteInteger(0);                                                               // ach score
                base.WriteInteger(UserData != null ? UserData.Progress : 0);                        // Current progress
                base.WriteBoolean(UserData != null ? (UserData.Level >= Ach.Levels.Count) : false); // Set 100% completed(??)
                base.WriteString(Ach.Category);
                base.WriteString("basejump");
                base.WriteInteger(0); // total levels
                base.WriteInteger(0);
            }
            base.WriteString("");
        }
        public ServerMessage Handle(ValueHolder valueHolder = null)
        {
            GameClient       session     = valueHolder.GetValue <GameClient>("Session");
            Achievement      achievement = valueHolder.GetValue <Achievement>("Achievement");
            AchievementLevel level       = valueHolder.GetValue <AchievementLevel>("Level");
            AchievementLevel lastLevel   = valueHolder.GetValue <AchievementLevel>("LastLevel");

            ServerMessage message = BasicUtilies.GetRevisionServerMessage(Revision.RELEASE63_201211141113_913728051);

            message.Init(r63bOutgoing.AchievementUpdate);
            message.AppendInt32(achievement.ID);                                                                                                   //id
            message.AppendInt32(level.Level);                                                                                                      //current level
            message.AppendString(level.LevelBadge);                                                                                                //badge code
            message.AppendInt32(lastLevel != null ? lastLevel.ProgressNeeded : 0);                                                                 //require
            message.AppendInt32(level.ProgressNeeded);                                                                                             //progress needed
            message.AppendInt32(level.ActivityPoints);                                                                                             //pixes
            message.AppendInt32(level.ActivityPointsType);                                                                                         //currency type
            message.AppendInt32(session.GetHabbo().GetUserAchievements().GetAchievementProgress(achievement.GroupName));                           //current progress
            message.AppendBoolean(session.GetHabbo().GetUserAchievements().GetAchievementLevel(achievement.GroupName) == achievement.LevelsCount); //completed or not
            message.AppendString(achievement.Category);                                                                                            //category
            message.AppendString("");                                                                                                              //unused
            message.AppendInt32(achievement.LevelsCount);                                                                                          //how many levels
            message.AppendInt32(0);                                                                                                                //dont show progress bar
            return(message);
        }
Пример #8
0
        public override void Compose(ServerPacket packet)
        {
            packet.WriteInteger(Achievements.Count);
            foreach (Achievement Achievement in Achievements)
            {
                UserAchievement UserData    = Habbo.GetAchievementData(Achievement.GroupName);
                int             TargetLevel = (UserData != null ? UserData.Level + 1 : 1);
                int             TotalLevels = Achievement.Levels.Count;

                TargetLevel = (TargetLevel > TotalLevels ? TotalLevels : TargetLevel);

                AchievementLevel TargetLevelData = Achievement.Levels[TargetLevel];
                packet.WriteInteger(Achievement.Id);                     // Unknown (ID?)
                packet.WriteInteger(TargetLevel);                        // Target level
                packet.WriteString(Achievement.GroupName + TargetLevel); // Target name/desc/badge

                packet.WriteInteger(1);
                packet.WriteInteger(TargetLevelData.Requirement); // Progress req/target
                packet.WriteInteger(TargetLevelData.RewardPixels);

                packet.WriteInteger(0);                                                          // Type of reward
                packet.WriteInteger(UserData != null ? UserData.Progress : 0);                   // Current progress

                packet.WriteBoolean(UserData != null ? (UserData.Level >= TotalLevels) : false); // Set 100% completed(??)
                packet.WriteString(Achievement.Category);                                        // Category
                packet.WriteString(string.Empty);
                packet.WriteInteger(TotalLevels);                                                // Total amount of levels
                packet.WriteInteger(0);
            }
            packet.WriteString("");
        }
Пример #9
0
 public AchievementsMessageComposer(GameClient Session, List <Achievement> Achievements)
     : base(ServerPacketHeader.AchievementsMessageComposer)
 {
     WriteInteger(Achievements.Count);
     foreach (Achievement achievement in Achievements)
     {
         UserAchievement achievementData = Session.GetHabbo().GetAchievementData(achievement.GroupName);
         int             TargetLevel     = achievementData != null ? achievementData.Level + 1 : 1;
         int             count           = achievement.Levels.Count;
         if (TargetLevel > count)
         {
             TargetLevel = count;
         }
         AchievementLevel achievementLevel = achievement.Levels[TargetLevel];
         WriteInteger(achievement.Id);
         WriteInteger(TargetLevel);
         WriteString(achievement.GroupName + TargetLevel);
         WriteInteger(0);
         WriteInteger(achievementLevel.Requirement); //?
         WriteInteger(achievementLevel.RewardPixels);
         WriteInteger(0);                            //-1 = rien, 5 = PointWinwin?
         WriteInteger(achievementData != null ? achievementData.Progress : 0);
         WriteBoolean(achievementData != null && achievementData.Level >= count);
         WriteString(achievement.Category);
         WriteString(string.Empty);
         WriteInteger(count);
         WriteInteger(0);
     }
     WriteString(string.Empty);
 }
        public ServerMessage Handle(ValueHolder valueHolder = null)
        {
            Achievement      achievement  = valueHolder.GetValue <Achievement>("Achievement");
            AchievementLevel nextLevel    = valueHolder.GetValue <AchievementLevel>("NextLevel");
            AchievementLevel currentLevel = valueHolder.GetValue <AchievementLevel>("CurrentLevel");

            ServerMessage message = BasicUtilies.GetRevisionServerMessage(Revision.RELEASE63_35255_34886_201108111108);

            message.Init(r63aOutgoing.AchievementUnlocked);
            message.AppendInt32(achievement.ID);
            message.AppendInt32(nextLevel.Level);
            message.AppendInt32(1337); //idk
            message.AppendString(nextLevel.LevelBadge);
            message.AppendInt32(nextLevel.Score);
            message.AppendInt32(nextLevel.ActivityPoints);
            message.AppendInt32(nextLevel.ActivityPointsType);
            message.AppendInt32(0); //fb(?)
            message.AppendInt32(0); //fb(?)
            if (currentLevel != null)
            {
                message.AppendString(currentLevel.LevelBadge);
            }
            else
            {
                message.AppendString("");
            }
            message.AppendString(achievement.Category);
            return(message);
        }
Пример #11
0
        /// <summary>
        ///     Gets the achievement levels.
        /// </summary>
        /// <param name="achievements">The achievements.</param>
        /// <param name="dbClient">The database client.</param>
        internal static void GetAchievementLevels(out Dictionary <string, Achievement> achievements, IQueryAdapter dbClient)
        {
            achievements = new Dictionary <string, Achievement>();

            dbClient.SetQuery("SELECT * FROM achievements_data");

            foreach (DataRow dataRow in dbClient.GetTable().Rows)
            {
                string achievementName = dataRow["achievement_name"].ToString();

                AchievementLevel level = new AchievementLevel((uint)dataRow["achievement_level"], (uint)dataRow["reward_pixels"], (uint)dataRow["reward_points"], (uint)dataRow["progress_needed"]);

                if (!achievements.ContainsKey(achievementName))
                {
                    achievements.Add(achievementName, new Achievement((uint)dataRow["id"], achievementName, dataRow["achievement_category"].ToString()));
                }

                if (!achievements[achievementName].CheckLevel(level))
                {
                    achievements[achievementName].AddLevel(level);
                }
                else
                {
                    Writer.WriteLine("Was Found a Duplicated Level for: " + achievementName + ", Level: " + level.Level, "Yupi.Achievements", ConsoleColor.Cyan);
                }
            }
        }
Пример #12
0
        public override void Compose(Yupi.Protocol.ISender session, IList <UserAchievement> achievements)
        {
            using (ServerMessage message = Pool.GetMessageBuffer(Id))
            {
                message.AppendInteger(achievements.Count);

                foreach (UserAchievement achievement in achievements)
                {
                    AchievementLevel nextLevel = achievement.Achievement.NextLevel(achievement.Level);

                    message.AppendInteger(achievement.Id);
                    message.AppendInteger(nextLevel.Level);
                    message.AppendString(achievement.Achievement.DisplayName + achievement.Level.Level);
                    message.AppendInteger(achievement.Level.Requirement);
                    message.AppendInteger(nextLevel.Requirement);
                    message.AppendInteger(nextLevel.RewardPoints);
                    message.AppendInteger(0);
                    message.AppendInteger(achievement.Progress);
                    message.AppendBool(achievement.Level.Level == achievement.Achievement.GetMaxLevel());
                    message.AppendString(achievement.Achievement.Category);
                    message.AppendString(string.Empty); // TODO Hardcoded
                    message.AppendInteger(achievement.Achievement.GetMaxLevel());
                    message.AppendInteger(0);
                }

                message.AppendString(string.Empty);
                session.Send(message);
            }
        }
Пример #13
0
        internal static ServerMessage Compose(GameClient Session, List <Achievement> Achievements)
        {
            ServerMessage Message = new ServerMessage(436); //436

            Message.AppendInt32(Achievements.Count);

            foreach (Achievement Achievement in Achievements)
            {
                UserAchievement UserData    = Session.GetHabbo().GetAchievementData(Achievement.GroupName);
                int             TargetLevel = (UserData != null ? UserData.Level + 1 : 1);
                int             TotalLevels = Achievement.Levels.Count;

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

                AchievementLevel TargetLevelData = Achievement.Levels[TargetLevel];

                Message.AppendUInt(Achievement.Id);                                                 // Unknown (ID?)
                Message.AppendInt32(TargetLevel);                                                   // Target level
                Message.AppendStringWithBreak(Achievement.GroupName + TargetLevel);                 // Target name/desc/badge
                Message.AppendInt32(TargetLevelData.Requirement);                                   // Progress req/target
                Message.AppendInt32(TargetLevelData.RewardPixels);                                  // Pixel reward
                Message.AppendInt32(TargetLevelData.RewardPoints);                                  // Unknown(??)
                Message.AppendInt32(UserData != null ? UserData.Progress : 0);                      // Current progress
                Message.AppendBoolean(UserData != null ? (UserData.Level >= TotalLevels) : false);  // Set 100% completed(??)
                Message.AppendStringWithBreak(Achievement.Category);                                // Category
                Message.AppendInt32(TotalLevels);                                                   // Total amount of levels
            }

            return(Message);
        }
Пример #14
0
        public ServerMessage Handle(T handler)
        {
            ServerMessage message = BasicUtilies.GetRevisionServerMessage(Revision.PRODUCTION_201601012205_226667486, r63cOutgoing.SendTalentTrack);

            message.AppendString(handler.Track.Name);

            List <string>          perks = null;
            Dictionary <uint, int> items = null;

            bool lastCompleted = true;

            message.AppendInt32(handler.Track.GetLevels().Count);
            foreach (TalentTrackLevel level in handler.Track.GetLevels())
            {
                bool completed = handler.Track.GetLevels().Count - 1 == level.Level ? false : lastCompleted && level.HasCompleted(handler.Habbo);

                message.AppendInt32(level.Level);
                message.AppendInt32(lastCompleted ? completed ? 2 : 1 : 0);
                message.AppendInt32(level.AchievementsRequired.Count);
                foreach (KeyValuePair <string, int> achievement in level.AchievementsRequired)
                {
                    AchievementLevel achievementLevel = Skylight.GetGame().GetAchievementManager().GetAchievement(achievement.Key).GetLevel(achievement.Value);

                    message.AppendInt32(achievementLevel.ID);
                    message.AppendInt32(achievementLevel.Level);
                    message.AppendString(achievementLevel.LevelBadge);
                    message.AppendInt32(lastCompleted ? completed || handler.Habbo.GetUserAchievements().GetAchievementLevel(achievement.Key) >= achievementLevel.Level ? 2 : 1 : 0); //state
                    message.AppendInt32(handler.Habbo.GetUserAchievements().GetAchievementProgress(achievement.Key));
                    message.AppendInt32(achievementLevel.ProgressNeeded);
                }

                message.AppendInt32(perks?.Count ?? 0);
                if (perks != null)
                {
                    foreach (string perk in perks)
                    {
                        message.AppendString(perk);
                    }
                }

                message.AppendInt32(items?.Count ?? 0);
                if (items != null)
                {
                    foreach (KeyValuePair <uint, int> item in items)
                    {
                        message.AppendString(item.Key.ToString());
                        message.AppendInt32(item.Value);
                    }
                }

                lastCompleted = completed;
                perks         = level.PrizePerks;
                items         = level.PrizeItems;
            }
            return(message);
        }
Пример #15
0
        public bool HasCompleted(Habbo habbo)
        {
            foreach (KeyValuePair <string, int> achievement in this.AchievementsRequired)
            {
                AchievementLevel achievementLevel = Skylight.GetGame().GetAchievementManager().GetAchievement(achievement.Key).GetLevel(achievement.Value);
                if (habbo.GetUserAchievements().GetAchievementLevel(achievement.Key) < achievementLevel.Level)
                {
                    return(false);
                }
            }

            return(true);
        }
        public override void DoJob()
        {
            Console.WriteLine("Starting TotalPaiedInvoiceJob...");
            RestClient    client   = RevisoRestClient.CreateClient();
            RestRequest   request  = new RestRequest("v2/invoices/paid?pageSize=10000", Method.GET);
            IRestResponse response = client.Execute(request);

            if (response.StatusCode != HttpStatusCode.OK)
            {
                string err = String.Format("{0} => {1}", response.StatusCode, response.ErrorMessage);
                throw new InvalidOperationException(err);
            }

            string json = response.Content;
            // deserializzazione e test delle proprietà principali
            JsonObject dto   = JsonConvert.DeserializeObject <JsonObject>(json);
            JArray     array = dto["collection"] as JArray;

            if (array == null)
            {
                throw new InvalidOperationException("array");
            }

            List <Invoice>   listInvoice      = JsonConvert.DeserializeObject <List <Invoice> >(array.ToString());
            AchievementLevel level            = Achievements.ElaborateTotalPaied2018Invoice(listInvoice);
            string           connectionString = "Data Source=NB-FMARCHETTI2;Initial Catalog=HACKNIGHT_TSPESARO;Persist Security Info=True;User ID=sa;Password=teamsystem";

            using (SqlConnection connection = new SqlConnection(connectionString))
            {
                using (SqlCommand command = connection.CreateCommand())
                {
                    connection.Open();
                    int    goalRuleId = 13;
                    string sqlCommand = null;
                    if (level == AchievementLevel.Zero)
                    {
                        sqlCommand = String.Format("DELETE FROM USER_ACHIEVEMENTS WHERE USR_ID = 1 AND GOAL_RULE_ID = {0}", goalRuleId);
                    }
                    else
                    {
                        sqlCommand = String.Format(@"IF NOT EXISTS (SELECT TOP 1 1 FROM USER_ACHIEVEMENTS WHERE USR_ID = 1 AND GOAL_RULE_ID = {0})
BEGIN
    INSERT INTO USER_ACHIEVEMENTS (USR_ID, GOAL_RULE_ID) VALUES (1, {0})
END;", goalRuleId);
                    }
                    command.CommandText = sqlCommand;
                    command.ExecuteNonQuery();
                    connection.Close();
                }
            }
        }
Пример #17
0
        public ServerPacket Compose()
        {
            ServerPacket message = new ServerPacket(Outgoing.AchievementListMessageComposer);

            message.WriteInteger(Alias.Server.AchievementManager.Achievements.Count);
            foreach (Achievement achievement in Alias.Server.AchievementManager.Achievements.Values)
            {
                if (!habbo.Achievements.GetAchievementProgress(achievement.Id, out int amount))
                {
                    amount = 0;
                }

                AchievementLevel currentLevel = achievement.GetLevelForProgress(amount);
                AchievementLevel nextLevel    = achievement.GetNextLevel(currentLevel != null ? currentLevel.Level : 0);

                if (currentLevel != null && currentLevel.Level == achievement.Levels.Count)
                {
                    nextLevel = null;
                }

                int targetLevel = 1;

                if (nextLevel != null)
                {
                    targetLevel = nextLevel.Level;
                }

                if (currentLevel != null && currentLevel.Level == achievement.Levels.Count)
                {
                    targetLevel = currentLevel.Level;
                }

                message.WriteInteger(achievement.Id);
                message.WriteInteger(targetLevel);
                message.WriteString("ACH_" + achievement.Name + targetLevel);
                message.WriteInteger(currentLevel != null ? currentLevel.Progress : 0);
                message.WriteInteger(nextLevel != null ? nextLevel.Progress : 0);
                message.WriteInteger(nextLevel != null ? nextLevel.RewardAmount : 0);
                message.WriteInteger(nextLevel != null ? nextLevel.RewardType : 0);
                message.WriteInteger(amount);
                message.WriteBoolean(this.habbo.Achievements.HasAchieved(achievement));
                message.WriteString(achievement.Category.ToString().ToLower());
                message.WriteString(string.Empty);
                message.WriteInteger(achievement.Levels.Count);
                message.WriteInteger(0);                 //1 = Progressbar visible if the achievement is completed
            }
            message.WriteString(string.Empty);
            return(message);
        }
Пример #18
0
        public AchievementsComposer(GameClient Session, List <Achievement> Achievements)
            : base(ServerPacketHeader.AchievementsMessageComposer)
        {
            WriteInteger(Achievements.Count);
            foreach (Achievement Achievement in Achievements)
            {
                UserAchievement UserData    = Session.GetHabbo().GetAchievementData(Achievement.GroupName);
                int             TargetLevel = (UserData != null ? UserData.Level + 1 : 1);
                int             TotalLevels = Achievement.Levels.Count;

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

                int count = Achievement.Levels.Count;
                if (i > count)
                {
                    i = count;
                }
                AchievementLevel TargetLevelData  = Achievement.Levels[TargetLevel];
                AchievementLevel achievementLevel = Achievement.Levels[i];
                AchievementLevel oldLevel         = (Achievement.Levels.ContainsKey(i - 1)) ? Achievement.Levels[i - 1] : achievementLevel;
                WriteInteger(Achievement.Id);                                   // Unknown (ID?)
                WriteInteger(i);                                                // Target level
                WriteString(string.Format("{0}{1}", Achievement.GroupName, i)); // Target name/desc/badge
                WriteInteger(oldLevel.Requirement);
                WriteInteger(TargetLevelData.Requirement);                      // Progress req/target
                WriteInteger(TargetLevelData.RewardPixels);
                WriteInteger(0);                                                // Type of reward
                WriteInteger(UserData != null ? UserData.Progress : 0);         // Current progress
                if (UserData == null)
                {
                    WriteBoolean(false);
                }
                else if (UserData.Level >= TotalLevels)
                {
                    WriteBoolean(true);
                }
                else
                {
                    WriteBoolean(false);
                }
                WriteString(Achievement.Category);   // Category
                WriteString(string.Empty);
                WriteInteger(count);                 // Total amount of levels
                WriteInteger(0);
            }
            WriteString("");
        }
Пример #19
0
 private int GetUpaiedGoalRuleByLevel(AchievementLevel level)
 {
     if (level == AchievementLevel.One)
     {
         return(10);
     }
     if (level == AchievementLevel.Two)
     {
         return(11);
     }
     if (level == AchievementLevel.Three)
     {
         return(12);
     }
     throw new InvalidOperationException("level out of range!");
 }
 private int GetCustomerGoalRuleByLevel(AchievementLevel level)
 {
     if (level == AchievementLevel.One)
     {
         return(7);
     }
     if (level == AchievementLevel.Two)
     {
         return(8);
     }
     if (level == AchievementLevel.Three)
     {
         return(9);
     }
     throw new InvalidOperationException("level out of range!");
 }
 internal static ServerMessage Compose(Achievement Achievement, int TargetLevel, AchievementLevel TargetLevelData,
     int TotalLevels, UserAchievement UserData)
 {
     ServerMessage Message = new ServerMessage(913);
     Message.AppendUInt(Achievement.Id);                                               // Unknown (ID?)
     Message.AppendInt32(TargetLevel);                                                   // Target level
     Message.AppendStringWithBreak(Achievement.GroupName + TargetLevel);                 // Target name/desc/badge
     Message.AppendInt32(TargetLevelData.Requirement);                                   // Progress req/target
     Message.AppendInt32(TargetLevelData.RewardPixels);                                   // Pixel reward
     Message.AppendInt32(TargetLevelData.RewardPoints);                                  // Unknown(??)
     Message.AppendInt32(UserData != null ? UserData.Progress : 0);                      // Current progress
     Message.AppendBoolean(UserData != null ? (UserData.Level >= TotalLevels) : false);  // Set 100% completed(??)
     Message.AppendStringWithBreak(Achievement.Category);                                // Category
     Message.AppendInt32(TotalLevels);                                                   // Total amount of levels
     return Message;
 }
Пример #22
0
        /// <summary>
        /// Composes the specified session.
        /// </summary>
        /// <param name="Session">The session.</param>
        /// <param name="Achievements">The achievements.</param>
        /// <returns>ServerMessage.</returns>
        internal static ServerMessage Compose(GameClient Session, List <Achievement> Achievements)
        {
            var serverMessage = new ServerMessage(LibraryParser.OutgoingRequest("AchievementListMessageComposer"));

            serverMessage.AppendInteger(Achievements.Count);
            foreach (Achievement achievement in Achievements)
            {
                UserAchievement achievementData = Session.GetHabbo().GetAchievementData(achievement.GroupName);
                int             i = achievementData != null ? (achievementData.Level + 1) : 1;

                int count = achievement.Levels.Count;
                if (i > count)
                {
                    i = count;
                }
                AchievementLevel achievementLevel = achievement.Levels[i];
                AchievementLevel oldLevel         = (achievement.Levels.ContainsKey(i - 1)) ? achievement.Levels[i - 1] : achievementLevel;
                serverMessage.AppendInteger(achievement.Id);
                serverMessage.AppendInteger(i);
                serverMessage.AppendString(string.Format("{0}{1}", achievement.GroupName, i));
                serverMessage.AppendInteger(oldLevel.Requirement);
                serverMessage.AppendInteger(achievementLevel.Requirement);
                serverMessage.AppendInteger(achievementLevel.RewardPoints);
                serverMessage.AppendInteger(0);
                serverMessage.AppendInteger(achievementData != null ? achievementData.Progress : 0);
                if (achievementData == null)
                {
                    serverMessage.AppendBool(false);
                }
                else if (achievementData.Level >= count)
                {
                    serverMessage.AppendBool(true);
                }
                else
                {
                    serverMessage.AppendBool(false);
                }
                serverMessage.AppendString(achievement.Category);
                serverMessage.AppendString(string.Empty);
                serverMessage.AppendInteger(count);
                serverMessage.AppendInteger(0);
            }
            serverMessage.AppendString("");
            return(serverMessage);
        }
Пример #23
0
        internal static ServerMessage Compose(GameClient Session, List <Achievement> Achievements)
        {
            ServerMessage serverMessage = new ServerMessage(Outgoing.AchievementListMessageComposer);

            serverMessage.AppendInt32(Achievements.Count);
            foreach (Achievement achievement in Achievements)
            {
                UserAchievement achievementData = Session.GetHabbo().GetAchievementData(achievement.GroupName);
                int             i     = achievementData != null ? checked (achievementData.Level + 1) : 1;
                int             count = achievement.Levels.Count;
                if (i > count)
                {
                    i = count;
                }
                AchievementLevel achievementLevel = achievement.Levels[i];
                AchievementLevel oldLevel         = (achievement.Levels.ContainsKey(i - 1)) ? achievement.Levels[i - 1] : achievementLevel;

                serverMessage.AppendUInt(achievement.Id);
                serverMessage.AppendInt32(i);
                serverMessage.AppendString(achievement.GroupName + i);
                serverMessage.AppendInt32(oldLevel.Requirement);         // Requisito Anterior
                serverMessage.AppendInt32(achievementLevel.Requirement); // Requisito Nuevo
                serverMessage.AppendInt32(achievementLevel.RewardPoints);
                serverMessage.AppendInt32(0);
                serverMessage.AppendInt32(achievementData != null ? achievementData.Progress : 0); // Progreso Total
                if (achievementData == null)
                {
                    serverMessage.AppendBoolean(false);
                }
                else if (achievementData.Level >= count)
                {
                    serverMessage.AppendBoolean(true);
                }
                else
                {
                    serverMessage.AppendBoolean(false); // Terminado
                }
                serverMessage.AppendString(achievement.Category);
                serverMessage.AppendString(string.Empty);
                serverMessage.AppendInt32(count); // Número de niveles
                serverMessage.AppendInt32(0);
            }
            serverMessage.AppendString("");
            return(serverMessage);
        }
Пример #24
0
 /// <summary>
 /// Composes the specified achievement.
 /// </summary>
 /// <param name="Achievement">The achievement.</param>
 /// <param name="TargetLevel">The target level.</param>
 /// <param name="TargetLevelData">The target level data.</param>
 /// <param name="TotalLevels">The total levels.</param>
 /// <param name="UserData">The user data.</param>
 /// <returns>ServerMessage.</returns>
 internal static ServerMessage Compose(Achievement Achievement, int TargetLevel, AchievementLevel TargetLevelData, int TotalLevels, UserAchievement UserData)
 {
     var serverMessage = new ServerMessage(LibraryParser.OutgoingRequest("AchievementProgressMessageComposer"));
     serverMessage.AppendInteger(Achievement.Id);
     serverMessage.AppendInteger(TargetLevel);
     serverMessage.AppendString(string.Format("{0}{1}", Achievement.GroupName, TargetLevel));
     serverMessage.AppendInteger(TargetLevelData.Requirement);
     serverMessage.AppendInteger(TargetLevelData.Requirement);
     serverMessage.AppendInteger(TargetLevelData.RewardPixels);
     serverMessage.AppendInteger(0);
     serverMessage.AppendInteger(UserData != null ? UserData.Progress : 0);
     serverMessage.AppendBool(UserData != null && UserData.Level >= TotalLevels);
     serverMessage.AppendString(Achievement.Category);
     serverMessage.AppendString(string.Empty);
     serverMessage.AppendInteger(TotalLevels);
     serverMessage.AppendInteger(0);
     return serverMessage;
 }
 internal static ServerMessage Compose(Achievement Achievement, int TargetLevel, AchievementLevel TargetLevelData, int TotalLevels, UserAchievement UserData)
 {
     ServerMessage serverMessage = new ServerMessage(Outgoing.AchievementProgressMessageComposer);
     serverMessage.AppendUInt(Achievement.Id);
     serverMessage.AppendInt32(TargetLevel);
     serverMessage.AppendString(Achievement.GroupName + TargetLevel);
     serverMessage.AppendInt32(TargetLevelData.Requirement);
     serverMessage.AppendInt32(TargetLevelData.Requirement);
     serverMessage.AppendInt32(TargetLevelData.RewardPixels);
     serverMessage.AppendInt32(0);
     serverMessage.AppendInt32(UserData != null ? UserData.Progress : 0);
     serverMessage.AppendBoolean(UserData != null && UserData.Level >= TotalLevels);
     serverMessage.AppendString(Achievement.Category);
     serverMessage.AppendString(string.Empty);
     serverMessage.AppendInt32(TotalLevels);
     serverMessage.AppendInt32(0);
     return serverMessage;
 }
Пример #26
0
 internal static ServerMessage Compose(Achievement Achievement, int TargetLevel, AchievementLevel TargetLevelData,
     int TotalLevels, UserAchievement UserData)
 {
     ServerMessage Message = PacketHandelingManager.GetRecycledItem(OutputCode.AchievementEvent);
     Message.AddUInt32(Achievement.Id);                                               // Unknown (ID?)
     Message.AddInt32(TargetLevel);                                                   // Target level
     Message.AddString(Achievement.GroupName + TargetLevel);                 // Target name/desc/badge
     Message.AddInt32(TargetLevelData.Requirement);                                   // Progress req/target        
     Message.AddInt32(TargetLevelData.RewardPixels);                                   // Pixel reward       
     Message.AddInt32(TargetLevelData.RewardPoints);                                  // Unknown(??)
     Message.AddInt32(0); // ?
     Message.AddInt32(UserData != null ? UserData.Progress : 0);                      // Current progress
     Message.AddBoolean(UserData != null ? (UserData.Level >= TotalLevels) : false);  // Set 100% completed(??)
     Message.AddString(Achievement.Category);                               // Category
     Message.AddString(String.Empty);
     Message.AddInt32(TotalLevels);                                                   // Total amount of levels 
     Message.AddInt32(0);                                      // Total amount of levels 
     return Message;
 }
Пример #27
0
        /// <summary>
        ///     Composes the specified session.
        /// </summary>
        /// <param name="session">The session.</param>
        /// <param name="achievements">The achievements.</param>
        /// <returns>ServerMessage.</returns>
        internal static ServerMessage Compose(GameClient session, List <Achievement> achievements)
        {
            ServerMessage serverMessage = new ServerMessage(LibraryParser.OutgoingRequest("AchievementListMessageComposer"));

            serverMessage.AppendInteger(achievements.Count);

            foreach (Achievement achievement in achievements)
            {
                UserAchievement achievementData = session.GetHabbo().GetAchievementData(achievement.GroupName);

                uint i = achievementData?.Level + 1 ?? 1;

                uint count = (uint)achievement.Levels.Count;

                if (i > count)
                {
                    i = count;
                }

                AchievementLevel achievementLevel = achievement.Levels[i];

                AchievementLevel oldLevel = achievement.Levels.ContainsKey(i - 1) ? achievement.Levels[i - 1] : achievementLevel;

                serverMessage.AppendInteger(achievement.Id);
                serverMessage.AppendInteger(i);
                serverMessage.AppendString($"{achievement.GroupName}{i}");
                serverMessage.AppendInteger(oldLevel.Requirement);
                serverMessage.AppendInteger(achievementLevel.Requirement);
                serverMessage.AppendInteger(achievementLevel.RewardPoints);
                serverMessage.AppendInteger(0);
                serverMessage.AppendInteger(achievementData?.Progress ?? 0);
                serverMessage.AppendBool(!(achievementData == null || achievementData.Level < count));
                serverMessage.AppendString(achievement.Category);
                serverMessage.AppendString(string.Empty);
                serverMessage.AppendInteger(count);
                serverMessage.AppendInteger(0);
            }

            serverMessage.AppendString(string.Empty);

            return(serverMessage);
        }
Пример #28
0
        internal static ServerMessage Compose(Achievement Achievement, int TargetLevel, AchievementLevel TargetLevelData,
            int TotalLevels, UserAchievement UserData)
        {
            //I,I,S,I,I,I,I,I,B,S,S,I,I

            ServerMessage Message = new ServerMessage(Outgoing.AchievementProgress);
            Message.AppendInt32(Achievement.Id);                                               // Unknown (ID?)
            Message.AppendInt32(TargetLevel);                                                   // Target level
            Message.AppendString(Achievement.GroupName + TargetLevel);                 // Target name/desc/badge
            Message.AppendInt32(TargetLevelData.Requirement);                                   // Progress req/target
            Message.AppendInt32(TargetLevelData.Requirement);                                   // Reward in Pixels
            Message.AppendInt32(TargetLevelData.RewardPixels);                                  // Reward Ach Score
            Message.AppendInt32(0); // ?
            Message.AppendInt32(UserData != null ? UserData.Progress : 0);                      // Current progress
            Message.AppendBoolean(UserData != null ? (UserData.Level >= TotalLevels) : false);  // Set 100% completed(??)
            Message.AppendString(Achievement.Category);                               // Category
            Message.AppendString(String.Empty);
            Message.AppendInt32(TotalLevels);                                                   // Total amount of levels
            Message.AppendInt32(0);
            return Message;
        }
Пример #29
0
        /// <summary>
        ///     Composes the specified achievement.
        /// </summary>
        /// <param name="achievement">The achievement.</param>
        /// <param name="targetLevel">The target level.</param>
        /// <param name="targetLevelData">The target level data.</param>
        /// <param name="totalLevels">The total levels.</param>
        /// <param name="userData">The user data.</param>
        /// <returns>ServerMessage.</returns>
        internal static ServerMessage Compose(Achievement achievement, uint targetLevel,
                                              AchievementLevel targetLevelData, uint totalLevels, UserAchievement userData)
        {
            ServerMessage serverMessage = new ServerMessage(LibraryParser.OutgoingRequest("AchievementProgressMessageComposer"));

            serverMessage.AppendInteger(achievement.Id);
            serverMessage.AppendInteger(targetLevel);
            serverMessage.AppendString($"{achievement.GroupName}{targetLevel}");
            serverMessage.AppendInteger(targetLevelData.Requirement);
            serverMessage.AppendInteger(targetLevelData.Requirement);
            serverMessage.AppendInteger(targetLevelData.RewardPixels);
            serverMessage.AppendInteger(0);
            serverMessage.AppendInteger(userData.Progress);
            serverMessage.AppendBool(userData.Level >= totalLevels);
            serverMessage.AppendString(achievement.Category);
            serverMessage.AppendString(string.Empty);
            serverMessage.AppendInteger(totalLevels);
            serverMessage.AppendInteger(0);

            return(serverMessage);
        }
Пример #30
0
        public bool HasAchieved(Achievement achievement)
        {
            if (!GetAchievementProgress(achievement.Id, out int progress))
            {
                return(false);
            }

            AchievementLevel level = achievement.GetLevelForProgress(progress);

            if (level == null)
            {
                return(false);
            }

            AchievementLevel nextLevel = achievement.GetNextLevel(level.Level);

            if (nextLevel == null && progress >= level.Progress)
            {
                return(true);
            }

            return(false);
        }
Пример #31
0
        public ServerPacket Compose()
        {
            ServerPacket message = new ServerPacket(Outgoing.AchievementUnlockedMessageComposer);

            if (!habbo.Achievements.GetAchievementProgress(this.achievement.Id, out int progress))
            {
                progress = 0;
            }
            AchievementLevel level = achievement.GetLevelForProgress(progress);

            message.WriteInteger(this.achievement.Id);
            message.WriteInteger(level.Level);
            message.WriteInteger(144);
            message.WriteString("ACH_" + this.achievement.Name + level.Level);
            message.WriteInteger(level.RewardAmount);
            message.WriteInteger(level.RewardType);
            message.WriteInteger(0);
            message.WriteInteger(10);
            message.WriteInteger(21);
            message.WriteString(level.Level > 1 ? "ACH_" + this.achievement.Name + (level.Level - 1) : "");
            message.WriteString(this.achievement.Category.ToString().ToLower());
            message.WriteBoolean(true);
            return(message);
        }
Пример #32
0
 public AchievementProgressedComposer(Achievement achievement, int targetLevel, AchievementLevel targetLevelData, int totalLevels, UserAchievement userData)
     : base(ServerPacketHeader.AchievementProgressedMessageComposer)
 {
     WriteInteger(achievement.Id);                                    // Unknown (ID?)
     WriteInteger(targetLevel);                                       // Target level
     WriteString(achievement.GroupName + targetLevel);                // Target name/desc/badge
     WriteInteger(1);                                                 // Progress req/target
     WriteInteger(targetLevelData.Requirement);                       // Reward in Pixels
     WriteInteger(targetLevelData.RewardPixels);                      // Reward Ach Score
     WriteInteger(0);                                                 // ?
     WriteInteger(userData?.Progress ?? 0);                           // Current progress
     WriteBoolean(userData != null && userData.Level >= totalLevels); // Set 100% completed(??)
     WriteString(achievement.Category);                               // Category
     WriteString(string.Empty);
     WriteInteger(totalLevels);                                       // Total amount of levels
     WriteInteger(0);
 }
Пример #33
0
        /// <summary>
        ///     Progresses the user achievement.
        /// </summary>
        /// <param name="session">The session.</param>
        /// <param name="achievementGroup">The achievement group.</param>
        /// <param name="progressAmount">The progress amount.</param>
        /// <param name="fromZero">if set to <c>true</c> [from zero].</param>
        /// <returns><c>true</c> if XXXX, <c>false</c> otherwise.</returns>
        internal bool ProgressUserAchievement(GameClient session, string achievementGroup, uint progressAmount,
                                              bool fromZero = false)
        {
            if (Achievements.ContainsKey(achievementGroup) && session?.GetHabbo() != null)
            {
                Achievement achievement = Achievements[achievementGroup];

                Habbo user = session.GetHabbo();

                // Get UserAchievementData, if the user doesn't has the Achievement, create a new.
                UserAchievement userAchievement = user.Achievements.ContainsKey(achievementGroup)
                    ? user.GetAchievementData(achievementGroup)
                    : new UserAchievement(achievementGroup, 0, 0);

                // If is a New Achievement is fromZero
                if (!user.Achievements.ContainsKey(achievementGroup))
                {
                    fromZero = true;
                }

                // If user hasn't the Achievement, after created the new, Must add in Collections.
                if (!user.Achievements.ContainsKey(achievementGroup))
                {
                    user.Achievements.Add(achievementGroup, userAchievement);
                }

                // Get Achievement
                userAchievement = user.Achievements[achievementGroup];

                // Total Levels from this Achievement
                uint achievementLevelsCount = (uint)achievement.Levels.Count;

                // Get User Achievement Level
                uint achievementCurrentLevel = userAchievement.Level;

                // Get User Achievement Progress
                uint achievementCurrentProgress = userAchievement.Progress;

                // If the next Level is the last level must set to Levels.Count (Ex: 38 Levels => .Count = 37 (Max Level in the Array, but .Count 37 == 38, Soo need put Level - 1)
                uint achievementNextLevel = achievementCurrentLevel + 1 > achievementLevelsCount
                    ? achievementLevelsCount
                    : achievementCurrentLevel + 1;

                // Set Achievement Progress
                uint achievementProgress = achievementCurrentProgress + progressAmount;

                // If he has already the Max, something is wrong.
                if (achievementCurrentLevel == achievementLevelsCount)
                {
                    return(false);
                }

                // Get Next Level Data
                AchievementLevel achievementNextLevelData = achievement.Levels[achievementNextLevel];

                // if progress isn't sufficient or, isn't new Achievement
                if (achievementProgress < achievementNextLevelData.Requirement || achievementCurrentLevel >= 1)
                {
                    fromZero = false;
                }

                // If progress is sufficient to next level, or is new Achievement
                if (achievementProgress >= achievementNextLevelData.Requirement || (achievementCurrentLevel < 1))
                {
                    fromZero = true;
                }

                // if is a new level (but level isn't 0)
                if (achievementProgress >= achievementNextLevelData.Requirement)
                {
                    achievementProgress = 0;
                }

                // If is new Level
                if (fromZero)
                {
                    // Set Level
                    userAchievement.SetLevel(achievementNextLevel);

                    // Set Progress
                    userAchievement.SetProgress(achievementProgress);

                    // Give Reward Points
                    user.AchievementPoints += achievementNextLevelData.RewardPoints;
                    user.NotifyNewPixels(achievementNextLevelData.RewardPixels);
                    user.Duckets += achievementNextLevelData.RewardPixels;

                    // Update Points Balance
                    user.UpdateActivityPointsBalance();

                    // Remove old Badge - (Is not problem if is First Level Badge, because if the user hasn't the badg, simply, will not remove.
                    user.GetBadgeComponent()
                    .RemoveBadge(Convert.ToString($"{achievementGroup}{achievementNextLevel - 1}"), session);

                    // Give new Badge
                    user.GetBadgeComponent().GiveBadge($"{achievementGroup}{achievementNextLevel}", true, session);

                    // Update in Database
                    using (IQueryAdapter queryReactor = Yupi.GetDatabaseManager().GetQueryReactor())
                        queryReactor.RunFastQuery(
                            $"REPLACE INTO users_achievements VALUES ('{user.Id}', '{achievementGroup}', '{achievementNextLevel}', '{achievementProgress}')");

                    // Send Unlocked Composer
                    session.SendMessage(AchievementUnlockedComposer.Compose(achievement, achievementNextLevel,
                                                                            achievementNextLevelData.RewardPoints, achievementNextLevelData.RewardPixels));

                    // Send Score Composer
                    session.SendMessage(AchievementScoreUpdateComposer.Compose(user.AchievementPoints));

                    // Send Progress Composer
                    session.SendMessage(AchievementProgressComposer.Compose(achievement, achievementNextLevel,
                                                                            achievementNextLevelData, achievementLevelsCount, userAchievement));

                    // Set Talent
                    if (
                        Yupi.GetGame()
                        .GetTalentManager()
                        .Talents.Values.Any(talent => talent.AchievementGroup == achievementGroup))
                    {
                        Yupi.GetGame()
                        .GetTalentManager()
                        .CompleteUserTalent(session,
                                            Yupi.GetGame().GetTalentManager().GetTalentData(achievementGroup));
                    }
                }
                else
                {
                    // Get Current Level Data
                    AchievementLevel achievementCurrentLevelData = achievement.Levels[achievementCurrentLevel];

                    // It's the Same Level
                    userAchievement.SetLevel(achievementCurrentLevel);

                    // But increase Progress
                    userAchievement.SetProgress(achievementProgress);

                    // Update in Database
                    using (IQueryAdapter queryReactor = Yupi.GetDatabaseManager().GetQueryReactor())
                        queryReactor.RunFastQuery(
                            $"REPLACE INTO users_achievements VALUES ('{user.Id}', '{achievementGroup}', '{achievementCurrentLevel}', '{achievementProgress}')");

                    // Compose Current Data
                    session.SendMessage(AchievementProgressComposer.Compose(achievement, achievementCurrentLevel,
                                                                            achievementCurrentLevelData, achievementLevelsCount, userAchievement));
                }

                // Send User New Data
                GameClientMessageHandler messageHandler = session.GetMessageHandler();

                messageHandler.GetResponse().Init(LibraryParser.OutgoingRequest("UpdateUserDataMessageComposer"));
                messageHandler.GetResponse().AppendInteger(-1);
                messageHandler.GetResponse().AppendString(user.Look);
                messageHandler.GetResponse().AppendString(user.Gender.ToLower());
                messageHandler.GetResponse().AppendString(user.Motto);
                messageHandler.GetResponse().AppendInteger(user.AchievementPoints);

                messageHandler.SendResponse();

                return(true);
            }

            return(false);
        }
Пример #34
0
        public static ServerMessage Compose(Achievement Achievement, int TargetLevel, AchievementLevel TargetLevelData,
                                            int TotalLevels, UserAchievement UserData)
        {
            ServerMessage Message = new ServerMessage(OpcodesOut.ACHIEVEMENTS_PROGRESS_UPDATE);

            Message.AppendUInt32(Achievement.Id);                                               // Unknown (ID?)
            Message.AppendInt32(TargetLevel);                                                   // Target level
            Message.AppendStringWithBreak(Achievement.GroupName + TargetLevel);                 // Target name/desc/badge
            Message.AppendInt32(TargetLevelData.Requirement);                                   // Progress req/target
            Message.AppendInt32(TargetLevelData.PixelReward);                                   // Pixel reward
            Message.AppendInt32(TargetLevelData.PointsReward);                                  // Unknown(??)
            Message.AppendInt32(UserData != null ? UserData.Progress : 0);                      // Current progress
            Message.AppendBoolean(UserData != null ? (UserData.Level >= TotalLevels) : false);  // Set 100% completed(??)
            Message.AppendStringWithBreak(Achievement.Category);                                // Category
            Message.AppendInt32(TotalLevels);                                                   // Total amount of levels
            return(Message);
        }
Пример #35
0
        public async void ProgressAchievement(string name, int amount = 1)
        {
            if (Alias.Server.AchievementManager.TryGetAchievement(name, out Achievement achievement))
            {
                if (!GetAchievementProgress(achievement.Id, out int progress))
                {
                    progress = 0;
                    _achievements.Add(achievement.Id, amount);
                    await _dao.AddPlayerAchievementAsync(achievement.Id, amount, _player.Id);
                }

                AchievementLevel oldLevel = achievement.GetLevelForProgress(progress);
                if (oldLevel == null)
                {
                    return;
                }

                if (oldLevel.Level == achievement.Levels.Count && amount == oldLevel.Progress)                 //Maximum achievement reached.
                {
                    return;
                }

                _achievements[achievement.Id] += amount;
                await _dao.UpdatePlayerAchievementAsync(achievement.Id, amount, _player.Id);

                _player.Session.Send(new AchievementProgressComposer(_player, achievement));

                AchievementLevel newLevel = achievement.GetLevelForProgress(progress + amount);
                if (oldLevel.Level != newLevel.Level && newLevel.Level >= achievement.Levels.Count)
                {
                    _player.Session.Send(new AchievementUnlockedComposer(_player, achievement));

                    if (!_player.Badges.TryGetBadge("ACH_" + achievement.Name + oldLevel.Level, out BadgeDefinition badge))
                    {
                        await _player.Badges.AddBadgeAsync("ACH_" + achievement.Name + newLevel.Level);
                    }
                    else
                    {
                        badge.Code = "ACH_" + achievement.Name + newLevel.Level;
                        await _player.Badges.UpdateBadgeAsync(badge, "ACH_" + achievement.Name + oldLevel.Level);
                    }

                    if (badge.Slot > 0)
                    {
                        if (_player.CurrentRoom != null)
                        {
                            _player.CurrentRoom.EntityManager.Send(new UserBadgesComposer(_player.Badges.GetWearingBadges, _player.Id));
                        }
                        else
                        {
                            _player.Session.Send(new UserBadgesComposer(_player.Badges.GetWearingBadges, _player.Id));
                        }
                    }

                    _player.AchievementScore += newLevel.RewardPoints;

                    if (_player.CurrentRoom != null)
                    {
                        _player.CurrentRoom.EntityManager.Send(new RoomUserDataComposer(_player.Entity));
                    }

                    //todo: talent track shit
                }
            }
        }