public void ProcessQuestStep(IMessage message, IActor npc) { AI.MessageParser parser = null; int currentStep = 0; if (CurrentPlayerStep.ContainsKey(ObjectId.Parse(message.InstigatorID))) { currentStep = CurrentPlayerStep[ObjectId.Parse(message.InstigatorID)]; if (currentStep >= QuestSteps.Count) { currentStep = QuestSteps.Count - 1; CurrentPlayerStep[ObjectId.Parse(message.InstigatorID)] = currentStep; } } //find the step that contains the trigger IQuestStep step = QuestSteps[currentStep]; if (message.InstigatorType == ObjectType.Player || (step.AppliesToNPC && message.InstigatorType == ObjectType.Npc)) { //only do it for players or if we specifically say it can trigger for NPC's parser = new AI.MessageParser(message, npc, new List<ITrigger> { step.Trigger }); parser.FindTrigger(); foreach (ITrigger trigger in parser.TriggersToExecute) { if (trigger.AutoProcess && currentStep == step.Step) { AutoProcessPlayer.Enqueue(ObjectId.Parse(message.InstigatorID)); ((NPC)npc).Fsm.ChangeState(AI.Questing.GetState(), npc as NPC); currentStep = AddPlayerToQuest(ObjectId.Parse(message.InstigatorID), currentStep); break; } if (!AllowOutOfOrder && currentStep != CurrentPlayerStep[ObjectId.Parse(message.InstigatorID)] || currentStep > step.Step) { //we will not execute the trigger since they need to start this quest from the beginning break; } if (step.IfPreviousCompleted && CurrentStep < (step.Step - 1)) { //this step won't process if the previous step was not completed break; } currentStep = AddPlayerToQuest(ObjectId.Parse(message.InstigatorID), currentStep); TriggerEventArgs e = new TriggerEventArgs(npc.Id, TriggerEventArgs.IDType.Npc, ObjectId.Parse(message.InstigatorID), (TriggerEventArgs.IDType)Enum.Parse(typeof(TriggerEventArgs.IDType), message.InstigatorType.ToString()), message.Room); trigger.HandleEvent(null, e); } } }
public void AutoProcessQuestStep(IActor npc) { var id = AutoProcessPlayer.Dequeue(); IUser player = Sockets.Server.GetAUser(id); if (player == null) { player = Character.NPCUtils.GetUserAsNPCFromList(new List<ObjectId> { id }); } int stepToProcess = CurrentPlayerStep[player.UserID]; TriggerEventArgs e = new TriggerEventArgs(npc.Id, TriggerEventArgs.IDType.Npc, player.UserID, player.Player.IsNPC ? TriggerEventArgs.IDType.Npc : TriggerEventArgs.IDType.Player); QuestSteps[stepToProcess - 1].ProcessStep(null, e); }