Ejemplo n.º 1
0
		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);
				}
			}
		}
Ejemplo n.º 2
0
		public void ParseMessage(IMessage message) {
			//send the message to the AI logic 
			if (!ObjectId.Parse(message.InstigatorID).Equals(this.Id)) {
				//does the AI need to do something based on this
				Fsm.InterpretMessage(message, this);

				//let's see if we have a general trigger hit
				List<ITrigger> triggers = new List<ITrigger>();
				Triggers.ForEach((t) => triggers.Add(t)); //converting the to ITrigger here until I can figure out how to get it to come back as ITrigger form the DB

				var parser = new AI.MessageParser(message, this, triggers);
				parser.FindTrigger();

				if (parser.TriggersToExecute.Count > 0) {
					foreach (ITrigger trigger in parser.TriggersToExecute) {
						trigger.HandleEvent(null, new TriggerEventArgs(this.Id, TriggerEventArgs.IDType.Npc, ObjectId.Parse(message.InstigatorID), (TriggerEventArgs.IDType)Enum.Parse(typeof(TriggerEventArgs.IDType), message.InstigatorType.ToString())));
					}
				}

				//now let's see if there's a quest that will trigger
				foreach (IQuest quest in Quests) {
					quest.ProcessQuestStep(message, this);
				}
				Save();
			}
		}