/// <summary> /// Is used to interact with NPCs. If there is no conversation going, it will initialize one. /// If the end of a conversation has been reached, it will end the conversation. /// </summary> /// <param name="firedEvent">The event of the fired thingy.</param> protected void interact(Event firedEvent) { string entityName = firedEvent.payload["EntityKey"]; Entity entity = firedEvent.GameReference.currentLevel.Entities[entityName]; if (this.conversations.Keys.Contains(firedEvent.payload["EntityKey"])) { if (this.currentConversation == null) { this.StartConversation(entityName, entity); } else if (((DialogueNode)this.currentConversation[this.currentConversationState]).NextState == 0) { this.EndConversation(entityName); } else { DialogueNode currentDiagNode = (DialogueNode)this.currentConversation[this.currentConversationState]; this.currentConversationBubble.isReadyForDeletion = true; this.currentConversationState = currentDiagNode.NextState; currentDiagNode = (DialogueNode)this.currentConversation[this.currentConversationState]; this.currentConversationBubble = new TextBubble(entity, currentDiagNode.Text); this.activeTextBubbles.AddLast(this.currentConversationBubble); } if (this.currentConversation != null) { Event newEvent = new Event(); newEvent.GameReference = firedEvent.GameReference; newEvent.Type = firedEvent.payload["EntityKey"] + "Speaking"; newEvent.payload.Add("State", "" + this.currentConversationState); firedEvent.GameReference.EventManager.notify(newEvent); } } else Console.WriteLine("ENTITY[" + firedEvent.payload["EntityKey"] + "] HAS NO DIALOGUE"); }
/// <summary> /// Starts a conversation with a given entity. This entity ID is used to identify which conversation to execute. /// </summary> /// <param name="entityName">The entity to begin conversing with. Used as a handle to pick the conversation "column."</param> public bool StartConversation(String entityName, Entity entity) { this.currentConversation = this.conversations[entityName]; this.currentConversationState = 0; this.currentConversationBubble = new TextBubble(entity, ((DialogueNode)this.currentConversation[this.currentConversationState]).Text); this.activeTextBubbles.AddLast(this.currentConversationBubble); if (this.currentConversation == null) return false; // Flag that we're currently talking, it's rude to interrupt. this.npcStates[entityName] = DialogueManager.STATE_TALKING; return true; }
/// <summary> /// Ends all current conversations and resets the conversation handles and anchors. /// </summary> public void EndConversation(string entityName) { this.currentConversation = null; this.currentConversationState = 0; // If there is an active text bubble, remember to kill it before nulling. if (this.currentConversationBubble != null) { this.currentConversationBubble.isReadyForDeletion = true; this.currentConversationBubble = null; } // Switch the NPC's talking state off. this.npcStates[entityName] = DialogueManager.STATE_NONE; }
/// <summary> /// Is used to interact with NPCs. If there is no conversation going, it will initialize one. /// If the end of a conversation has been reached, it will end the conversation. /// </summary> /// <param name="entityName">The entity to interact with.</param> /// <param name="entity">The entity that the dialogue is happening with.</param> public void Interact(Event firedEvent) { string entityName = firedEvent.payload["EntityKey"]; Entity entity = firedEvent.gameReference.currentLevel.Entities[entityName]; if (this.currentConversation == null) { this.StartConversation(entityName, entity); } else if (((DialogueNode)this.currentConversation[this.currentConversationState]).NextState == 0) { this.EndConversation(); } else { DialogueNode currentDiagNode = (DialogueNode)this.currentConversation[this.currentConversationState]; this.currentConversationBubble.isReadyForDeletion = true; this.currentConversationState = currentDiagNode.NextState; currentDiagNode = (DialogueNode)this.currentConversation[this.currentConversationState]; this.currentConversationBubble = new TextBubble(entity, currentDiagNode.Text); this.activeTextBubbles.AddLast(this.currentConversationBubble); } }
/// <summary> /// Ends all current conversations and resets the conversation handles and anchors. /// </summary> public void EndConversation() { this.currentConversation = null; this.currentConversationState = 0; // If there is an active text bubble, remember to kill it before nulling. if (this.currentConversationBubble != null) { this.currentConversationBubble.isReadyForDeletion = true; this.currentConversationBubble = null; } }
/// <summary> /// Starts a conversation with a given entity. This entity ID is used to identify which conversation to execute. /// </summary> /// <param name="entityName">The entity to begin conversing with. Used as a handle to pick the conversation "column."</param> public bool StartConversation(String entityName, Entity entity) { this.currentConversation = this.conversations[entityName]; this.currentConversationState = 0; this.currentConversationBubble = new TextBubble(entity, ((DialogueNode)this.currentConversation[this.currentConversationState]).Text); this.activeTextBubbles.AddLast(this.currentConversationBubble); if (this.currentConversation == null) return false; return true; }