Ejemplo n.º 1
0
        /// <summary>
        /// Checks if the player can ever complete the given achievement.
        /// </summary>
        /// <param name="achievementCriteriaEntry"></param>
        /// <returns></returns>
        private bool IsAchieveable(AchievementCriteriaEntry achievementCriteriaEntry)
        {
            if (DisableStaffAchievements)
            {
                if (Owner.Role.IsStaff)
                {
                    return(false);
                }
            }
            // Skip achievements we have completed
            if (HasCompleted(achievementCriteriaEntry.AchievementEntryId))
            {
                return(false);
            }

            // Skip achievements that have different faction requirement then the player faction.
            if (achievementCriteriaEntry.AchievementEntry.FactionFlag == (int)AchievementFactionGroup.Alliance && Owner.FactionGroup != FactionGroup.Alliance)
            {
                return(false);
            }
            if (achievementCriteriaEntry.AchievementEntry.FactionFlag == (int)AchievementFactionGroup.Horde && Owner.FactionGroup != FactionGroup.Horde)
            {
                return(false);
            }

            // Skip achievements that require to be groupfree and
            if (achievementCriteriaEntry.GroupFlag.HasFlag(AchievementCriteriaGroupFlags.AchievementCriteriaGroupNotInGroup) && Owner.IsInGroup)
            {
                return(false);
            }

            return(true);
        }
Ejemplo n.º 2
0
 /// <summary>
 /// Checks if the player can ever complete the given achievement.
 /// </summary>
 /// <param name="achievementCriteriaEntry"></param>
 /// <returns></returns>
 private bool IsAchieveable(AchievementCriteriaEntry achievementCriteriaEntry)
 {
     return((!AchievementCollection.DisableStaffAchievements || !this.Owner.Role.IsStaff) &&
            !this.HasCompleted(achievementCriteriaEntry.AchievementEntryId) &&
            ((achievementCriteriaEntry.AchievementEntry.FactionFlag != 1 ||
              this.Owner.FactionGroup == FactionGroup.Alliance) &&
             (achievementCriteriaEntry.AchievementEntry.FactionFlag != 0 ||
              this.Owner.FactionGroup == FactionGroup.Horde)) &&
            (!achievementCriteriaEntry.GroupFlag.HasFlag((Enum)AchievementCriteriaGroupFlags
                                                         .AchievementCriteriaGroupNotInGroup) || !this.Owner.IsInGroup));
 }
Ejemplo n.º 3
0
        /// <summary>
        /// Sets the progress with a given Criteria entry.
        /// </summary>
        /// <param name="entry"></param>
        /// <param name="newValue"></param>
        /// <param name="progressType"></param>
        internal void SetCriteriaProgress(AchievementCriteriaEntry entry, uint newValue, ProgressType progressType = ProgressType.ProgressSet)
        {
            // not create record for 0 counter
            if (newValue == 0)
            {
                return;
            }

            var  achievementProgressRecord = GetOrCreateProgressRecord(entry.AchievementCriteriaId);
            uint updateValue;

            switch (progressType)
            {
            case ProgressType.ProgressAccumulate:
                updateValue = newValue + achievementProgressRecord.Counter;
                break;

            case ProgressType.ProgressHighest:
                updateValue = achievementProgressRecord.Counter < newValue ? newValue : achievementProgressRecord.Counter;
                break;

            default:
                updateValue = newValue;
                break;
            }

            if (updateValue == achievementProgressRecord.Counter)
            {
                return;
            }

            achievementProgressRecord.Counter = updateValue;


            if (entry.TimeLimit > 0)
            {
                DateTime now = DateTime.Now;
                if (achievementProgressRecord.StartOrUpdateTime.AddSeconds(entry.TimeLimit) < now)
                {
                    achievementProgressRecord.Counter = 1;
                }
                achievementProgressRecord.StartOrUpdateTime = now;
            }

            AchievementHandler.SendAchievmentStatus(achievementProgressRecord, Owner);



            if (IsAchievementCompletable(entry.AchievementEntry))
            {
                EarnAchievement(entry.AchievementEntry);
            }
        }
        public void FinalizeDataHolder()
        {
            AchievementCriteriaEntry criteriaEntryById = AchievementMgr.GetCriteriaEntryById(this.CriteriaId);

            if (criteriaEntryById == null)
            {
                ContentMgr.OnInvalidDBData("{0} had an invalid criteria id.", (object)this);
            }
            else
            {
                criteriaEntryById.RequirementSet.Add(this);
            }
        }
Ejemplo n.º 5
0
        /// <summary>Checks if the given criteria is completable</summary>
        /// <param name="achievementCriteriaEntry"></param>
        /// <returns></returns>
        public bool IsCriteriaCompletable(AchievementCriteriaEntry achievementCriteriaEntry)
        {
            if (achievementCriteriaEntry.AchievementEntry.Flags.HasFlag((Enum)AchievementFlags.Counter))
            {
                return(false);
            }
            AchievementProgressRecord criteriaProgress =
                this.m_owner.Achievements.GetAchievementCriteriaProgress(achievementCriteriaEntry
                                                                         .AchievementCriteriaId);

            if (criteriaProgress == null)
            {
                return(false);
            }
            return(achievementCriteriaEntry.IsAchieved(criteriaProgress));
        }
Ejemplo n.º 6
0
        /// <summary>Sets the progress with a given Criteria entry.</summary>
        /// <param name="entry"></param>
        /// <param name="newValue"></param>
        /// <param name="progressType"></param>
        internal void SetCriteriaProgress(AchievementCriteriaEntry entry, uint newValue,
                                          ProgressType progressType = ProgressType.ProgressSet)
        {
            if (newValue == 0U)
            {
                return;
            }
            AchievementProgressRecord progressRecord = this.GetOrCreateProgressRecord(entry.AchievementCriteriaId);
            uint num;

            switch (progressType)
            {
            case ProgressType.ProgressAccumulate:
                num = newValue + progressRecord.Counter;
                break;

            case ProgressType.ProgressHighest:
                num = progressRecord.Counter < newValue ? newValue : progressRecord.Counter;
                break;

            default:
                num = newValue;
                break;
            }

            if ((int)num == (int)progressRecord.Counter)
            {
                return;
            }
            progressRecord.Counter = num;
            if (entry.TimeLimit > 0U)
            {
                DateTime now = DateTime.Now;
                if (progressRecord.StartOrUpdateTime.AddSeconds((double)entry.TimeLimit) < now)
                {
                    progressRecord.Counter = 1U;
                }
                progressRecord.StartOrUpdateTime = now;
            }

            AchievementHandler.SendAchievmentStatus(progressRecord, this.Owner);
            if (!this.IsAchievementCompletable(entry.AchievementEntry))
            {
                return;
            }
            this.EarnAchievement(entry.AchievementEntry);
        }
Ejemplo n.º 7
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));
        }
Ejemplo n.º 8
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;
        }
Ejemplo n.º 9
0
        /// <summary>
        /// Sets the progress with a given Criteria entry.
        /// </summary>
        /// <param name="entry"></param>
        /// <param name="newValue"></param>
        /// <param name="progressType"></param>
        internal void SetCriteriaProgress(AchievementCriteriaEntry entry, uint newValue, ProgressType progressType = ProgressType.ProgressSet)
        {
            // not create record for 0 counter
            if (newValue == 0)
                return;

            var achievementProgressRecord = GetOrCreateProgressRecord(entry.AchievementCriteriaId);
            uint updateValue;

            switch (progressType)
            {
                case ProgressType.ProgressAccumulate:
                    updateValue = newValue + achievementProgressRecord.Counter;
                    break;
                case ProgressType.ProgressHighest:
                    updateValue = achievementProgressRecord.Counter < newValue ? newValue : achievementProgressRecord.Counter;
                    break;
                default:
                    updateValue = newValue;
                    break;
            }

            if (updateValue == achievementProgressRecord.Counter)
                return;

            achievementProgressRecord.Counter = updateValue;

            if (entry.TimeLimit > 0)
            {
                DateTime now = DateTime.Now;
                if (achievementProgressRecord.StartOrUpdateTime.AddSeconds(entry.TimeLimit) < now)
                {
                    achievementProgressRecord.Counter = 1;
                }
                achievementProgressRecord.StartOrUpdateTime = now;
            }

            AchievementHandler.SendAchievmentStatus(achievementProgressRecord, Owner);

            if (IsAchievementCompletable(entry.AchievementEntry))
            {
                EarnAchievement(entry.AchievementEntry);
            }
        }
Ejemplo n.º 10
0
        /// <summary>
        /// Checks if the player can ever complete the given achievement.
        /// </summary>
        /// <param name="achievementCriteriaEntry"></param>
        /// <returns></returns>
        private bool IsAchieveable(AchievementCriteriaEntry achievementCriteriaEntry)
        {
            if (DisableStaffAchievements)
            {
                if (Owner.Role.IsStaff)
                    return false;
            }
            // Skip achievements we have completed
            if (HasCompleted(achievementCriteriaEntry.AchievementEntryId))
                return false;

            // Skip achievements that have different faction requirement then the player faction.
            if (achievementCriteriaEntry.AchievementEntry.FactionFlag == (int)AchievementFactionGroup.Alliance && Owner.FactionGroup != FactionGroup.Alliance)
                return false;
            if (achievementCriteriaEntry.AchievementEntry.FactionFlag == (int)AchievementFactionGroup.Horde && Owner.FactionGroup != FactionGroup.Horde)
                return false;

            // Skip achievements that require to be groupfree and
            if (achievementCriteriaEntry.GroupFlag.HasFlag(AchievementCriteriaGroupFlags.AchievementCriteriaGroupNotInGroup) && Owner.IsInGroup)
                return false;

            return true;
        }
Ejemplo n.º 11
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);
        }