public bool Complete(Quest quest, int rewardGroup, bool owl)
{
if (!this.Has(quest))
throw new ArgumentException("Quest not found in this manager.");
var success = this.EndQuest(quest, rewardGroup, owl);
if (success)
{
quest.State = QuestState.Complete;
// Remove quest item after the state was set, so the item
// is removed, but not the quest.
_creature.Inventory.Remove(quest.QuestItem);
// Remove collected items for Collect objectives at the end
// of the objectives. This way all items that were to be
// collected are removed automatically, unless the last
// objectives are different, like Talk, in which case the
// NPC should control what happens.
// Starts at the last objective and goes back until the first
// one or a non-Collect objective is reached.
for (var i = quest.Data.Objectives.Count - 1; i >= 0; --i)
{
var progress = quest.GetProgress(i);
var objective = quest.Data.Objectives[progress.Ident];
var collectObjective = objective as QuestObjectiveCollect;
if (collectObjective == null)
break;
_creature.Inventory.Remove(collectObjective.ItemId, Math.Min(collectObjective.Amount, progress.Count));
}
ChannelServer.Instance.Events.OnPlayerCompletesQuest(_creature, quest.Id);
// Complete event
quest.Data.OnComplete(_creature);
}
return success;
}