private static void SetMotto(Session Session, ClientMessage Message) { string NewMotto = UserInputFilter.FilterString(Message.PopString().Trim()); if (NewMotto.Length > 38) { NewMotto = NewMotto.Substring(0, 38); } if (NewMotto == Session.CharacterInfo.Motto) { return; } using (SqlDatabaseClient MySqlClient = SqlDatabaseManager.GetClient()) { Session.CharacterInfo.UpdateMotto(MySqlClient, NewMotto); AchievementManager.ProgressUserAchievement(MySqlClient, Session, "ACH_Motto", 1); } QuestManager.ProgressUserQuest(Session, QuestType.PROFILE_CHANGE_MOTTO); Session.SendInfoUpdate(); }
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 = RightsManager.GetBadgeByCode(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; }
private static void SetFigure(Session Session, ClientMessage Message) { // todo: verify data(!!!!) string NewGender = Message.PopString().ToLower(); string NewFigure = UserInputFilter.FilterString(Message.PopString()); if (NewGender != "m" && NewGender != "f") { NewGender = "m"; } if (NewFigure.Length == 0 || (NewFigure == Session.CharacterInfo.Figure)) { return; } using (SqlDatabaseClient MySqlClient = SqlDatabaseManager.GetClient()) { Session.CharacterInfo.UpdateFigure(MySqlClient, NewGender, NewFigure); AchievementManager.ProgressUserAchievement(MySqlClient, Session, "ACH_AvatarLooks", 1); } QuestManager.ProgressUserQuest(Session, QuestType.PROFILE_CHANGE_LOOK); Session.SendInfoUpdate(); }