Beispiel #1
0
		public override void Convert(byte[] rawData)
		{
			var achievementEntry = new AchievementEntry();
			achievementEntry.ID = (AchievementEntryId)GetUInt32(rawData, 0);
			achievementEntry.FactionFlag = GetInt32(rawData, 1);
			achievementEntry.MapID = (MapId)GetUInt32(rawData, 2);
			achievementEntry.Name = new string[16];
			for (int i = 0; i < 16; i++)
				achievementEntry.Name[i] = GetString(rawData, i + 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 = (AchievementEntryId)GetUInt32(rawData, 61);

			AchievementMgr.AchievementEntries[achievementEntry.ID] = achievementEntry;
		}
Beispiel #2
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;

			AchievementEntryId 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);
		}
Beispiel #3
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);
			}
		}
Beispiel #4
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);
		}