Esempio n. 1
0
        public static List<string> GetRightsForBadge(Badge Badge)
        {
            List<string> Rights = new List<string>();

            foreach (uint SetId in Badge.RightsSets)
            {
                if (SetId > 0 && mRightSets.ContainsKey(SetId))
                {
                    foreach (string Right in mRightSets[SetId])
                    {
                        if (Rights.Contains(Right))
                        {
                            continue;
                        }

                        Rights.Add(Right);
                    }
                }
            }

            return Rights;
        }
Esempio n. 2
0
        public void UpdateAchievementBadge(SqlDatabaseClient MySqlClient, string AchievementGroup, Badge NewBadge)
        {
            MySqlClient.SetParameter("userid", mUserId);
            MySqlClient.SetParameter("sourcetype", "achievement");
            MySqlClient.SetParameter("sourcedata", AchievementGroup);
            MySqlClient.SetParameter("badgeid", NewBadge.Id);

            lock (mSyncRoot)
            {
                if (mAchievementBadges.ContainsKey(AchievementGroup))
                {
                    Badge OldBadge = mAchievementBadges[AchievementGroup];

                    if (OldBadge == NewBadge)
                    {
                        MySqlClient.ClearParameters();
                        return;
                    }

                    mIndexCache.Remove(OldBadge.Code);
                    mAchievementBadges[AchievementGroup] = NewBadge;

                    MySqlClient.ExecuteNonQuery("UPDATE badges SET badge_id = @badgeid WHERE user_id = @userid AND source_type = @sourcetype AND source_data = @sourcedata LIMIT 1");

                    foreach (KeyValuePair <int, Badge> Badge in mEquippedBadges)
                    {
                        if (Badge.Value.Id == OldBadge.Id)
                        {
                            mEquippedBadges[Badge.Key] = NewBadge;
                            break;
                        }
                    }
                }
                else
                {
                    mAchievementBadges.Add(AchievementGroup, NewBadge);
                    MySqlClient.ExecuteNonQuery("INSERT INTO badges (user_id,badge_id,source_type,source_data) VALUES (@userid,@badgeid,@sourcetype,@sourcedata)");
                }

                mRightsCache = RegenerateRights();
                mIndexCache.Add(NewBadge.Code);
            }
        }
Esempio n. 3
0
        public static bool ProgressUserAchievement(SqlDatabaseClient MySqlClient, Session Session, string AchievementGroup, int ProgressAmount)
        {
            if (!mAchievements.ContainsKey(AchievementGroup))
            {
                return false;
            }

            Achievement AchievementData = null;

            lock (mSyncRoot)
            {
                AchievementData = mAchievements[AchievementGroup];
            }

            UserAchievement UserData = Session.AchievementCache.GetAchievementData(AchievementGroup);

            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;

                Badge BadgeData = new Badge(AchievementGroup + TargetLevel);

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

                Session.BadgeCache.UpdateAchievementBadge(MySqlClient, AchievementGroup, BadgeData);
                Session.NewItemsCache.MarkNewItem(MySqlClient, 4, BadgeData.Id);
                Session.SendData(InventoryNewItemsComposer.Compose(4, BadgeData.Id));

                Session.CharacterInfo.UpdateActivityPointsBalance(MySqlClient, TargetLevelData.PixelReward);
                Session.SendData(ActivityPointsBalanceComposer.Compose(Session.CharacterInfo.ActivityPointsBalance,
                    TargetLevelData.PixelReward));

                Session.SendData(AchievementUnlockedComposer.Compose(AchievementData, TargetLevel, TargetLevelData.PointsReward,
                    TargetLevelData.PixelReward));

                Session.AchievementCache.AddOrUpdateData(MySqlClient, AchievementGroup, NewLevel, NewProgress);

                Session.CharacterInfo.UpdateScore(MySqlClient, TargetLevelData.PointsReward);
                Session.SendData(AchievementScoreUpdateComposer.Compose(Session.CharacterInfo.Score));

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

                Session.SendInfoUpdate();

                Session.MessengerFriendCache.BroadcastToFriends(MessengerFriendEventComposer.Compose(Session.CharacterId,
                    MessengerFriendEventType.AchievementUnlocked, BadgeData.Code));

                RoomInstance Instance = RoomManager.GetInstanceByRoomId(Session.CurrentRoomId);

                if (Instance != null)
                {
                    Instance.BroadcastMessage(RoomUserBadgesComposer.Compose(Session.CharacterId,
                        Session.BadgeCache.EquippedBadges));
                }

                if (ProgressRemainder > 0)
                {
                    ProgressUserAchievement(MySqlClient, Session, AchievementGroup, ProgressRemainder);
                }

                return true;
            }

            Session.AchievementCache.AddOrUpdateData(MySqlClient, AchievementGroup, NewLevel, NewProgress);
            Session.SendData(AchievementProgressComposer.Compose(AchievementData, TargetLevel, TargetLevelData,
            TotalLevels, Session.AchievementCache.GetAchievementData(AchievementGroup)));
            return false;
        }
Esempio n. 4
0
        public void UpdateAchievementBadge(SqlDatabaseClient MySqlClient, string AchievementGroup, Badge NewBadge)
        {
            MySqlClient.SetParameter("userid", mUserId);
            MySqlClient.SetParameter("sourcetype", "achievement");
            MySqlClient.SetParameter("sourcedata", AchievementGroup);
            MySqlClient.SetParameter("badgecode", NewBadge.Code);

            lock (mSyncRoot)
            {
                if (mAchievementBadges.ContainsKey(AchievementGroup))
                {
                    Badge OldBadge = mAchievementBadges[AchievementGroup];

                    if (OldBadge == NewBadge)
                    {
                        MySqlClient.ClearParameters();
                        return;
                    }

                    mIndexCache.Remove(OldBadge.Code);
                    mAchievementBadges[AchievementGroup] = NewBadge;

                    MySqlClient.ExecuteNonQuery("UPDATE badges SET badge_code = @badgecode WHERE user_id = @userid AND source_type = @sourcetype AND source_data = @sourcedata LIMIT 1");

                    foreach (KeyValuePair<int, Badge> Badge in mEquippedBadges)
                    {
                        if (Badge.Value.Code == OldBadge.Code)
                        {
                            mEquippedBadges[Badge.Key] = NewBadge;
                            break;
                        }
                    }
                }
                else
                {
                    mAchievementBadges.Add(AchievementGroup, NewBadge);
                    MySqlClient.ExecuteNonQuery("INSERT INTO user_badges (user_id,badge_code,source_type,source_data) VALUES (@userid,@badgecode,@sourcetype,@sourcedata)");
                }

                mIndexCache.Add(NewBadge.Code);
            }
        }
Esempio n. 5
0
        public void ReloadCache(SqlDatabaseClient MySqlClient, AchievementCache UserAchievementCache)
        {
            Dictionary<int, Badge> EquippedBadges = new Dictionary<int, Badge>();
            List<Badge> StaticBadges = new List<Badge>();
            Dictionary<string, Badge> AchievementBadges = new Dictionary<string, Badge>();
            List<string> IndexCache = new List<string>();

            MySqlClient.SetParameter("userid", mUserId);
            DataTable Table = MySqlClient.ExecuteQueryTable("SELECT badge_code,slot_id,source_type,source_data FROM user_badges WHERE user_id = @userid");

            foreach (DataRow Row in Table.Rows)
            {
                string SourceType = Row["source_type"].ToString();
                string SourceData = Row["source_data"].ToString();

                Badge BadgeToEquip = null;

                if (SourceType == "static")
                {
                    BadgeToEquip = new Badge(Row["badge_code"].ToString());
                    StaticBadges.Add(BadgeToEquip);
                }
                else if (SourceType == "achievement")
                {
                    if (AchievementBadges.ContainsKey(SourceData))
                    {
                        continue;
                    }

                    UserAchievement UserAchievement = UserAchievementCache.GetAchievementData(SourceData);

                    if (UserAchievement == null || UserAchievement.Level < 1)
                    {
                        MySqlClient.SetParameter("userid", mUserId);
                        MySqlClient.SetParameter("badgecode", Row["badge_code"].ToString());
                        MySqlClient.ExecuteNonQuery("DELETE FROM user_badges WHERE user_id = @userid AND badge_id = @badgeid");
                        continue;
                    }

                    string Code = UserAchievement.GetBadgeCodeForLevel();

                    BadgeToEquip = new Badge(Code);
                    AchievementBadges.Add(SourceData, BadgeToEquip);
                }

                if (BadgeToEquip != null)
                {
                    int SlotId = (int)Row["slot_id"];

                    if (!EquippedBadges.ContainsKey(SlotId) && SlotId >= 1 && SlotId <= 5)
                    {
                        EquippedBadges.Add(SlotId, BadgeToEquip);
                    }

                    IndexCache.Add(BadgeToEquip.Code);
                }
            }

            lock (mSyncRoot)
            {
                mEquippedBadges = EquippedBadges;
                mStaticBadges = StaticBadges;
                mAchievementBadges = AchievementBadges;
                mIndexCache = IndexCache;
            }
        }
Esempio n. 6
0
        private static void SetBadgeOrder(Session Session, ClientMessage Message)
        {
            int i = 0;
            Dictionary<int, Badge> NewSettings = new Dictionary<int, Badge>();

            while (Message.RemainingLength > 0)
            {
                if (i > 5)
                {
                    continue;
                }

                int SlotId = Message.PopWiredInt32();
                string BadgeCode = Message.PopString();
                Badge BadgeRef = new Badge(BadgeCode);

                if (BadgeRef == null || !Session.BadgeCache.ContainsCode(BadgeCode) || SlotId >= 6 ||
                    SlotId <= 0 || NewSettings.ContainsKey(SlotId))
                {
                    continue;
                }

                NewSettings.Add(SlotId, BadgeRef);

                i++;
            }

            using (SqlDatabaseClient MySqlClient = SqlDatabaseManager.GetClient())
            {
                Session.BadgeCache.UpdateBadgeOrder(MySqlClient, NewSettings);
            }

            RoomInstance Instance = RoomManager.GetInstanceByRoomId(Session.CurrentRoomId);

            if (Instance == null)
            {
                return;
            }

            Instance.BroadcastMessage(RoomUserBadgesComposer.Compose(Session.CharacterId, Session.BadgeCache.EquippedBadges));
            QuestManager.ProgressUserQuest(Session, QuestType.PROFILE_BADGE);
        }