Exemple #1
0
 /// <summary>
 /// Removes all the progress of a given achievement.
 /// </summary>
 /// <param name="achievementEntry"></param>
 public void RemoveAchievementProgress(AchievementEntry achievementEntry)
 {
     foreach (var achievementCriteriaEntry in achievementEntry.Criteria)
     {
         RemoveProgress(achievementCriteriaEntry.AchievementCriteriaId);
     }
 }
Exemple #2
0
 /// <summary>Removes all the progress of a given achievement.</summary>
 /// <param name="achievementEntry"></param>
 public void RemoveAchievementProgress(AchievementEntry achievementEntry)
 {
     foreach (AchievementCriteriaEntry criterion in achievementEntry.Criteria)
     {
         this.RemoveProgress(criterion.AchievementCriteriaId);
     }
 }
Exemple #3
0
 public override void OnUpdate(AchievementCollection achievements, uint value1, uint value2, ObjectBase involved)
 {
     if (!AchievementEntry.IsRealmFirstType() || AchievementCollection.ClassSpecificAchievementId[(int)achievements.Owner.Class] == AchievementEntryId ||
         AchievementCollection.RaceSpecificAchievementId[(int)achievements.Owner.Race] == AchievementEntryId)
     {
         achievements.SetCriteriaProgress(this, value1);
     }
 }
Exemple #4
0
        /// <summary>
        /// Adds a new achievement to the list, when achievement is earned.
        /// </summary>
        /// <param name="achievementEntry"></param>
        public void EarnAchievement(uint achievementEntryId)
        {
            AchievementEntry achievementEntry = AchievementMgr.GetAchievementEntry(achievementEntryId);

            if (achievementEntry == null)
            {
                return;
            }
            this.EarnAchievement(achievementEntry);
        }
Exemple #5
0
        /// <summary>
        /// Checks if the given achievement is completable.
        /// </summary>
        /// <param name="achievementEntry"></param>
        /// <returns></returns>
        public bool IsAchievementCompletable(AchievementEntry achievementEntry)
        {
            // Counter achievement were never meant to be completed.
            if (achievementEntry.Flags.HasFlag(AchievementFlags.Counter))
            {
                return(false);
            }

            // The method will return false only if the achievement has RealmFirst flags
            // and already achieved by someone.
            if (!AchievementMgr.IsRealmFirst(achievementEntry.ID))
            {
                return(false);
            }

            uint achievementForTestId = (achievementEntry.RefAchievement != 0)
                                                                                                                ? achievementEntry.RefAchievement
                                                                                                                : achievementEntry.ID;

            uint achievementForTestCount = achievementEntry.Count;


            List <AchievementCriteriaEntry> achievementCriteriaIds = achievementEntry.Criteria;

            if (achievementCriteriaIds.Count == 0)
            {
                return(false);
            }

            uint count = 0;

            // Default case
            bool completedAll = true;

            foreach (var achievementCriteriaEntry in achievementCriteriaIds)
            {
                if (IsCriteriaCompletable(achievementCriteriaEntry))
                {
                    ++count;
                }
                else
                {
                    completedAll = false;
                }

                if (achievementForTestCount > 0 && achievementForTestCount <= count)
                {
                    return(true);                               // TODO: Why return true here?
                }
            }
            // all criterias completed requirement
            return(completedAll && achievementForTestCount == 0);
        }
Exemple #6
0
        public void FinalizeDataHolder()
        {
            AchievementEntry achievementEntry = AchievementMgr.AchievementEntries[this.AchievementEntryId];

            if (achievementEntry == null)
            {
                ContentMgr.OnInvalidDBData("{0} had an invalid AchievementEntryId.", (object)this);
            }
            else
            {
                achievementEntry.Rewards.Add(this);
            }
        }
Exemple #7
0
        /// <summary>Checks if the given achievement is completable.</summary>
        /// <param name="achievementEntry"></param>
        /// <returns></returns>
        public bool IsAchievementCompletable(AchievementEntry achievementEntry)
        {
            if (achievementEntry.Flags.HasFlag((Enum)AchievementFlags.Counter) ||
                !AchievementMgr.IsRealmFirst(achievementEntry.ID))
            {
                return(false);
            }
            if (achievementEntry.RefAchievement == 0U)
            {
                int id = (int)achievementEntry.ID;
            }
            else
            {
                int refAchievement = (int)achievementEntry.RefAchievement;
            }

            uint count = achievementEntry.Count;
            List <AchievementCriteriaEntry> criteria = achievementEntry.Criteria;

            if (criteria.Count == 0)
            {
                return(false);
            }
            uint num  = 0;
            bool flag = true;

            foreach (AchievementCriteriaEntry achievementCriteriaEntry in criteria)
            {
                if (this.IsCriteriaCompletable(achievementCriteriaEntry))
                {
                    ++num;
                }
                else
                {
                    flag = false;
                }
                if (count > 0U && count <= num)
                {
                    return(true);
                }
            }

            if (flag)
            {
                return(count == 0U);
            }
            return(false);
        }
Exemple #8
0
        public override void Convert(byte[] rawData)
        {
            AchievementEntry achievementEntry = new AchievementEntry();

            achievementEntry.ID          = DBCRecordConverter.GetUInt32(rawData, 0);
            achievementEntry.FactionFlag = DBCRecordConverter.GetInt32(rawData, 1);
            achievementEntry.MapID       = (MapId)DBCRecordConverter.GetUInt32(rawData, 2);
            achievementEntry.Names       = this.GetStrings(rawData, 4);
            AchievementCategoryEntryId uint32 = (AchievementCategoryEntryId)DBCRecordConverter.GetUInt32(rawData, 38);

            achievementEntry.Category       = AchievementMgr.GetCategoryEntry(uint32);
            achievementEntry.Points         = DBCRecordConverter.GetUInt32(rawData, 39);
            achievementEntry.Flags          = (AchievementFlags)DBCRecordConverter.GetUInt32(rawData, 41);
            achievementEntry.Count          = DBCRecordConverter.GetUInt32(rawData, 60);
            achievementEntry.RefAchievement = DBCRecordConverter.GetUInt32(rawData, 61);
            AchievementMgr.AchievementEntries[achievementEntry.ID] = achievementEntry;
        }
Exemple #9
0
		public override void Convert(byte[] rawData)
		{
			var achievementEntry = new AchievementEntry();
			achievementEntry.ID = GetUInt32(rawData, 0);
			achievementEntry.FactionFlag = GetInt32(rawData, 1);
			achievementEntry.MapID = (MapId)GetUInt32(rawData, 2);
			achievementEntry.Names = GetStrings(rawData, 4);
			
			var category = (AchievementCategoryEntryId)GetUInt32(rawData, 38);		// set category
			achievementEntry.Category = AchievementMgr.GetCategoryEntry(category);

			achievementEntry.Points = GetUInt32(rawData, 39);
			achievementEntry.Flags = (AchievementFlags)GetUInt32(rawData, 41);
			achievementEntry.Count = GetUInt32(rawData, 60);
			achievementEntry.RefAchievement = (uint)GetUInt32(rawData, 61);

			AchievementMgr.AchievementEntries[achievementEntry.ID] = achievementEntry;
		}
Exemple #10
0
        public override void Convert(byte[] rawData)
        {
            var achievementEntry = new AchievementEntry();

            achievementEntry.ID          = GetUInt32(rawData, 0);
            achievementEntry.FactionFlag = GetInt32(rawData, 1);
            achievementEntry.MapID       = (MapId)GetUInt32(rawData, 2);
            achievementEntry.Names       = GetStrings(rawData, 4);

            var category = (AchievementCategoryEntryId)GetUInt32(rawData, 38);                          // set category

            achievementEntry.Category = AchievementMgr.GetCategoryEntry(category);

            achievementEntry.Points         = GetUInt32(rawData, 39);
            achievementEntry.Flags          = (AchievementFlags)GetUInt32(rawData, 41);
            achievementEntry.Count          = GetUInt32(rawData, 60);
            achievementEntry.RefAchievement = (uint)GetUInt32(rawData, 61);

            AchievementMgr.AchievementEntries[achievementEntry.ID] = achievementEntry;
        }
Exemple #11
0
 /// <summary>
 /// Adds a new achievement to the list, when achievement is earned.
 /// </summary>
 /// <param name="achievementEntry"></param>
 public void EarnAchievement(AchievementEntry achievement)
 {
     this.AddAchievement(AchievementRecord.CreateNewAchievementRecord(this.m_owner, achievement.ID));
     this.CheckPossibleAchievementUpdates(AchievementCriteriaType.CompleteAchievement, achievement.ID, 1U,
                                          (Unit)null);
     this.RemoveAchievementProgress(achievement);
     foreach (AchievementReward reward in achievement.Rewards)
     {
         reward.GiveReward(this.Owner);
     }
     if (this.m_owner.IsInGuild)
     {
         this.m_owner.Guild.Broadcast(
             AchievementHandler.CreateAchievementEarnedToGuild(achievement.ID, this.m_owner));
     }
     if (achievement.IsRealmFirstType())
     {
         AchievementHandler.SendServerFirstAchievement(achievement.ID, this.m_owner);
     }
     AchievementHandler.SendAchievementEarned(achievement.ID, this.m_owner);
 }
Exemple #12
0
        public void Load()
        {
            foreach (AchievementRecord achievementRecord in AchievementRecord.Load((int)this.Owner.EntityId.Low))
            {
                AchievementEntry achievementEntry =
                    AchievementMgr.GetAchievementEntry(achievementRecord.AchievementEntryId);
                if (achievementEntry != null)
                {
                    if (this.m_completedAchievements.ContainsKey(achievementEntry.ID))
                    {
                        AchievementCollection.log.Warn("Character {0} had Achievement {1} more than once.",
                                                       (object)this.m_owner, (object)achievementEntry.ID);
                    }
                    else
                    {
                        this.AddAchievement(achievementRecord);
                    }
                }
                else
                {
                    AchievementCollection.log.Warn("Character {0} has invalid Achievement: {1}", (object)this.m_owner,
                                                   (object)achievementRecord.AchievementEntryId);
                }
            }

            foreach (AchievementProgressRecord achievementProgressRecord in AchievementProgressRecord.Load(
                         (int)this.Owner.EntityId.Low))
            {
                if (this.m_progressRecords.ContainsKey(achievementProgressRecord.AchievementCriteriaId))
                {
                    AchievementCollection.log.Warn(
                        "Character {0} had progress for Achievement Criteria {1} more than once.",
                        (object)this.m_owner, (object)achievementProgressRecord.AchievementCriteriaId);
                }
                else
                {
                    this.AddProgressRecord(achievementProgressRecord);
                }
            }
        }
Exemple #13
0
        /// <summary>
        /// Checks if the given criteria is completable
        /// </summary>
        /// <param name="achievementCriteriaEntry"></param>
        /// <returns></returns>
        public bool IsCriteriaCompletable(AchievementCriteriaEntry achievementCriteriaEntry)
        {
            AchievementEntry achievementEntry = achievementCriteriaEntry.AchievementEntry;

            // Counter achievement were never meant to be completed.
            if (achievementEntry.Flags.HasFlag(AchievementFlags.Counter))
            {
                return(false);
            }

            //TODO: Add support for realm first.

            // We never completed the criteria befoer.
            AchievementProgressRecord achievementProgressRecord =
                m_owner.Achievements.GetAchievementCriteriaProgress(achievementCriteriaEntry.AchievementCriteriaId);

            if (achievementProgressRecord == null)
            {
                return(false);
            }
            return(achievementCriteriaEntry.IsAchieved(achievementProgressRecord));
        }
Exemple #14
0
        /// <summary>
        /// Adds a new achievement to the list, when achievement is earned.
        /// </summary>
        /// <param name="achievementEntry"></param>
        public void EarnAchievement(AchievementEntry achievement)
        {
            AddAchievement(AchievementRecord.CreateNewAchievementRecord(m_owner, achievement.ID));
            CheckPossibleAchievementUpdates(AchievementCriteriaType.CompleteAchievement, (uint)achievement.ID, 1);
            RemoveAchievementProgress(achievement);

            foreach (var achievementReward in achievement.Rewards)
            {
                achievementReward.GiveReward(Owner);
            }

            if (m_owner.IsInGuild)
            {
                m_owner.Guild.Broadcast(AchievementHandler.CreateAchievementEarnedToGuild(achievement.ID, m_owner));
            }

            if (achievement.IsRealmFirstType())
            {
                AchievementHandler.SendServerFirstAchievement(achievement.ID, m_owner);
            }

            AchievementHandler.SendAchievementEarned(achievement.ID, m_owner);
        }
Exemple #15
0
        public override void Convert(byte[] rawData)
        {
            AchievementCriteriaType         uint32 = (AchievementCriteriaType)DBCRecordConverter.GetUInt32(rawData, 2);
            AchievementCriteriaEntryCreator criteriaEntryCreator = AchievementMgr.GetCriteriaEntryCreator(uint32);

            if (criteriaEntryCreator == null)
            {
                return;
            }
            AchievementCriteriaEntry achievementCriteriaEntry = criteriaEntryCreator();

            achievementCriteriaEntry.AchievementCriteriaId = DBCRecordConverter.GetUInt32(rawData, 0);
            achievementCriteriaEntry.AchievementEntryId    = DBCRecordConverter.GetUInt32(rawData, 1);
            AchievementEntry achievementEntry = achievementCriteriaEntry.AchievementEntry;

            if (achievementEntry == null)
            {
                return;
            }
            achievementEntry.Criteria.Add(achievementCriteriaEntry);
            DBCRecordConverter.CopyTo(rawData, (object)achievementCriteriaEntry, 3);
            achievementCriteriaEntry.CompletionFlag = DBCRecordConverter.GetUInt32(rawData, 26);
            achievementCriteriaEntry.GroupFlag      =
                (AchievementCriteriaGroupFlags)DBCRecordConverter.GetUInt32(rawData, 27);
            achievementCriteriaEntry.TimeLimit = DBCRecordConverter.GetUInt32(rawData, 29);
            List <AchievementCriteriaEntry> criteriaEntriesByType = AchievementMgr.GetCriteriaEntriesByType(uint32);

            if (criteriaEntriesByType != null)
            {
                criteriaEntriesByType.Add(achievementCriteriaEntry);
            }
            achievementCriteriaEntry.RequirementSet =
                new AchievementCriteriaRequirementSet(achievementCriteriaEntry.AchievementCriteriaId);
            AchievementMgr.CriteriaEntriesById[achievementCriteriaEntry.AchievementCriteriaId] =
                achievementCriteriaEntry;
        }
 /// <summary>
 /// Removes all the progress of a given achievement.
 /// </summary>
 /// <param name="achievementEntry"></param>
 public void RemoveAchievementProgress(AchievementEntry achievementEntry)
 {
     foreach (var achievementCriteriaEntry in achievementEntry.Criteria)
     {
         RemoveProgress(achievementCriteriaEntry.AchievementCriteriaId);
     }
 }
        /// <summary>
        /// Adds a new achievement to the list, when achievement is earned.
        /// </summary>
        /// <param name="achievementEntry"></param>
        public void EarnAchievement(AchievementEntry achievement)
        {
            AddAchievement(AchievementRecord.CreateNewAchievementRecord(m_owner, achievement.ID));
            CheckPossibleAchievementUpdates(AchievementCriteriaType.CompleteAchievement, (uint)achievement.ID, 1);
            RemoveAchievementProgress(achievement);

            foreach (var achievementReward in achievement.Rewards)
                achievementReward.GiveReward(Owner);

            if (m_owner.IsInGuild)
                m_owner.Guild.Broadcast(AchievementHandler.CreateAchievementEarnedToGuild(achievement.ID, m_owner));

            if (achievement.IsRealmFirstType())
                AchievementHandler.SendServerFirstAchievement(achievement.ID, m_owner);

            AchievementHandler.SendAchievementEarned(achievement.ID, m_owner);
        }
        /// <summary>
        /// Checks if the given achievement is completable.
        /// </summary>
        /// <param name="achievementEntry"></param>
        /// <returns></returns>
        public bool IsAchievementCompletable(AchievementEntry achievementEntry)
        {
            // Counter achievement were never meant to be completed.
            if (achievementEntry.Flags.HasFlag(AchievementFlags.Counter))
                return false;

            // The method will return false only if the achievement has RealmFirst flags
            // and already achieved by someone.
            if (!AchievementMgr.IsRealmFirst(achievementEntry.ID))
                return false;

            uint achievementForTestId = (achievementEntry.RefAchievement != 0)
                                                        ? achievementEntry.RefAchievement
                                                        : achievementEntry.ID;

            uint achievementForTestCount = achievementEntry.Count;

            List<AchievementCriteriaEntry> achievementCriteriaIds = achievementEntry.Criteria;

            if (achievementCriteriaIds.Count == 0)
                return false;

            uint count = 0;

            // Default case
            bool completedAll = true;

            foreach (var achievementCriteriaEntry in achievementCriteriaIds)
            {
                if (IsCriteriaCompletable(achievementCriteriaEntry))
                    ++count;
                else
                    completedAll = false;

                if (achievementForTestCount > 0 && achievementForTestCount <= count)
                    return true;		// TODO: Why return true here?
            }
            // all criterias completed requirement
            return (completedAll && achievementForTestCount == 0);
        }