Exemplo n.º 1
0
        public void AddResponse(NPCConversations npcc, NPCConversationStep npccs, SMCharacter invokingCharacter, List <ShortcutToken> stl, string responseOptions)
        {
            // Set up a list to hold them in the character (if there isn't one already)
            if (this.AwaitingCharacterResponses == null)
            {
                this.AwaitingCharacterResponses = new List <SMNPCAwaitingCharacterResponse>();
            }

            // Create the awaiting response token.
            SMNPCAwaitingCharacterResponse acr = new SMNPCAwaitingCharacterResponse();

            acr.ConversationID      = npcc.ConversationID;
            acr.ConversationStep    = npccs.StepID;
            acr.WaitingForCharacter = invokingCharacter;
            acr.RoomID = this.RoomID;

            // Work out the timeout conversation if there is one.
            string nextStepAfterTimeout = null;
            int    timeout = 10000;

            if (npccs.NextStep != null)
            {
                string[] getNextStep = npccs.NextStep.Split('.');
                nextStepAfterTimeout = getNextStep[0];
                timeout = int.Parse(getNextStep[1]);
            }

            // Set the conversation timeout
            acr.ConversationStepAfterTimeout = nextStepAfterTimeout;
            acr.UnixTimeStampTimeout         = Utility.Utils.GetUnixTimeOffset(timeout);

            // Add the item to the character, and send a message to the player regarding the available responses.
            this.AwaitingCharacterResponses.Add(acr);
            invokingCharacter.SetAwaitingResponse(this.UserID, stl, timeout, this.RoomID);

            if ((responseOptions != null) && (!responseOptions.Contains("{variable}")))
            {
                invokingCharacter.sendMessageToPlayer(responseOptions);
            }
        }
Exemplo n.º 2
0
        public void ProcessCharacterResponse(string responseShortCut, SMCharacter invokingCharacter)
        {
            // Get the current unix time
            int currentUnixTime = Utility.Utils.GetUnixTime();

            // Double check we're not going to get a null exception
            if (this.AwaitingCharacterResponses != null)
            {
                // Delete all responses over that time
                // this.AwaitingCharacterResponses.RemoveAll(awaitingitems => awaitingitems.UnixTimeStampTimeout < currentUnixTime);

                if (this.AwaitingCharacterResponses.Count > 0)
                {
                    // Get the Character Response.
                    SMNPCAwaitingCharacterResponse acr = this.AwaitingCharacterResponses.FirstOrDefault(rw => rw.WaitingForCharacter.UserID == invokingCharacter.UserID);

                    // Make sure we've returned something
                    if (acr != null)
                    {
                        // Load the conversation
                        NPCConversations npcc = this.NPCConversationStructures.FirstOrDefault(nc => nc.ConversationID == acr.ConversationID);
                        if (npcc != null)
                        {
                            // Get the relevant part of the conversation to go to
                            NPCConversationStep currentStep = npcc.ConversationSteps.FirstOrDefault(step => step.StepID == acr.ConversationStep);

                            if ((currentStep != null) && (currentStep.ResponseOptions != null))
                            {
                                NPCConversationStepResponseOptions nextstep = currentStep.ResponseOptions.FirstOrDefault(ro => ro.ResponseOptionShortcut.ToLower() == responseShortCut.ToLower());

                                // TODO - Update this location with the character variable info.

                                if (nextstep == null)
                                {
                                    nextstep = currentStep.ResponseOptions.FirstOrDefault(ro => ro.ResponseOptionShortcut.ToLower() == "{variable}");
                                    invokingCharacter.VariableResponse = responseShortCut;
                                }

                                if (nextstep != null)
                                {
                                    NPCResponseOptionAction nroa = nextstep.ResponseOptionActionSteps.FirstOrDefault();

                                    if (nroa != null)
                                    {
                                        // Get the conversation / step to go to.
                                        string[] convostep = nroa.AdditionalData.Split('.');

                                        // check whether the conversation is the same as the original if not get the new one
                                        if (convostep[0] != npcc.ConversationID)
                                        {
                                            npcc = this.NPCConversationStructures.FirstOrDefault(nc => nc.ConversationID == convostep[0]);
                                        }

                                        // Remove the item from the awaiting items.
                                        AwaitingCharacterResponses.Remove(acr);

                                        // Remove it from the character too, it's processed now so we don't need it any more!
                                        invokingCharacter.NPCsWaitingForResponses.RemoveAll(ar => ar.NPCID == this.UserID);
                                        invokingCharacter.SaveToApplication();
                                        invokingCharacter.SaveToFile();

                                        // process it
                                        ProcessConversationStep(npcc, convostep[1], invokingCharacter);
                                    }
                                }
                            }
                        }
                    }
                }
            }
        }