Aura.Channel.Scripting.Scripts.NpcScript.RandomPtj C# (CSharp) Метод

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

Returns a random quest id from the given ones, based on the current Erinn day and the player's success rate for this PTJ type.
public RandomPtj ( PtjType type ) : int
type PtjType
Результат int
		public int RandomPtj(PtjType type, params int[] questIds)
		{
			var level = this.GetPtjQuestLevel(type);

			// Check ids
			if (questIds.Length == 0)
				throw new ArgumentException("NpcScript.RandomPtj: questIds may not be empty.");

			// Check quest scripts and get a list of available ones
			var questScripts = questIds.Select(id => ChannelServer.Instance.ScriptManager.QuestScripts.Get(id)).Where(a => a != null);
			var questScriptsCount = questScripts.Count();
			if (questScriptsCount == 0)
				throw new Exception("NpcScript.RandomPtj: Unable to find any of the given quests.");
			if (questScriptsCount != questIds.Length)
			{
				var missing = questIds.Where(a => !questScripts.Any(b => b.Id == a));
				Log.Warning("NpcScript.RandomPtj: Some of the given quest ids are unknown (" + string.Join(", ", missing) + ").");
			}

			// Check same level quests
			var sameLevelQuests = questScripts.Where(a => a.Level == level);
			var sameLevelQuestsCount = sameLevelQuests.Count();

			if (sameLevelQuestsCount == 0)
			{
				// Try to fall back to Basic
				sameLevelQuests = questScripts.Where(a => a.Level == QuestLevel.Basic);
				sameLevelQuestsCount = sameLevelQuests.Count();

				if (sameLevelQuestsCount == 0)
					throw new Exception("NpcScript.RandomPtj: Missing quest for level '" + level + "'.");

				Log.Warning("NpcScript.RandomPtj: Missing quest for level '" + level + "', using 'Basic' as fallback.");
			}

			// Return random quest's id
			// Random is seeded with the current Erinn day so we always get
			// the same result for one in-game day.
			var rnd = new Random(ErinnTime.Now.DateTimeStamp);
			var randomQuest = sameLevelQuests.ElementAt(rnd.Next(sameLevelQuestsCount));

			return randomQuest.Id;
		}