Aura.Channel.Scripting.Scripts.QuestScript.CheckCurrentObjective C# (CSharp) Метод

CheckCurrentObjective() публичный Метод

Checks and updates current obective's count.
public CheckCurrentObjective ( Creature creature ) : void
creature Aura.Channel.World.Entities.Creature
Результат void
		public void CheckCurrentObjective(Creature creature)
		{
			if (creature == null || !creature.IsPlayer)
				return;

			var quests = creature.Quests.GetAllIncomplete(this.Id);
			foreach (var quest in quests)
			{
				if (!this.CanMakeProgress(creature, quest))
					continue;

				var progress = quest.CurrentObjectiveOrLast;
				if (progress == null) return;

				var objective = this.Objectives[progress.Ident];
				if (objective == null) return;

				var prevCount = progress.Count;
				switch (objective.Type)
				{
					case ObjectiveType.ReachRank:
						var reachRankObjective = (objective as QuestObjectiveReachRank);
						var skillId = reachRankObjective.Id;
						var rank = reachRankObjective.Rank;
						var skill = creature.Skills.Get(skillId);

						if (skill != null && skill.Info.Rank >= rank)
							quest.SetDone(progress.Ident);
						else
							quest.SetUndone(progress.Ident);

						break;

					case ObjectiveType.ReachLevel:
						var reachLevelObjective = (objective as QuestObjectiveReachLevel);

						if (creature.Level >= reachLevelObjective.Amount)
							quest.SetDone(progress.Ident);

						break;

					case ObjectiveType.Collect:
						var itemId = (objective as QuestObjectiveCollect).ItemId;

						// Do not count incomplete items (e.g. tailoring, blacksmithing).
						var count = creature.Inventory.Count((Item item) => (item.Info.Id == itemId || item.Data.StackItemId == itemId) && !item.IsIncomplete);

						if (!progress.Done && count >= objective.Amount)
							quest.SetDone(progress.Ident);
						else if (progress.Done && count < objective.Amount)
							quest.SetUndone(progress.Ident);

						// Set(Un)Done modifies the count, has to be set afterwards
						progress.Count = count;
						break;

					case ObjectiveType.GetKeyword:
						var getKeywordObjective = (objective as QuestObjectiveGetKeyword);

						if (creature.Keywords.Has((ushort)getKeywordObjective.KeywordId))
							quest.SetDone(progress.Ident);

						break;

					default:
						// Objective that can't be checked here.
						break;
				}

				if (progress.Count != prevCount)
					UpdateQuest(creature, quest);
			}
		}