Aura.Channel.Scripting.Scripts.NpcScript.CompletePtj C# (CSharp) Method

CompletePtj() public method

Completes PTJ quest, if one is active. Rewards the selected rewards.
public CompletePtj ( string rewardReply ) : void
rewardReply string Example: @reward:0
return void
		public void CompletePtj(string rewardReply)
		{
			var quest = this.Player.Quests.GetPtjQuest();
			if (quest == null)
				return;

			// Get reward group index
			var rewardGroupIdx = 0;
			if (!int.TryParse(rewardReply.Substring("@reward:".Length), out rewardGroupIdx))
			{
				Log.Warning("NpcScript.CompletePtj: Invalid reply '{0}'.", rewardReply);
				return;
			}

			// Get reward group id
			// The client displays a list of all available rewards,
			// ordered by group id, with unobtainable ones disabled.
			// What it sends is the index of the element in that list,
			// not the actual group id, because that would be too easy.
			var rewardGroup = -1;
			var group = quest.Data.RewardGroups.Values.OrderBy(a => a.Id).ElementAt(rewardGroupIdx);
			if (group == null)
				Log.Warning("NpcScript.CompletePtj: Invalid group index '{0}' for quest '{1}'.", rewardGroupIdx, quest.Id);
			else if (!group.HasRewardsFor(quest.GetResult()))
				throw new Exception("Invalid reward group, doesn't have rewards for result.");
			else
				rewardGroup = group.Id;

			// Complete
			this.Player.Quests.Complete(quest, rewardGroup, false);

			ChannelServer.Instance.Events.OnCreatureCompletedPtj(this.Player, quest.Data.PtjType);
		}