Ejemplo n.º 1
0
        private void ProcessResponse(NPCResponses npr, SMCharacter invokingCharacter, SMItem itemIn)
        {
            // Process each of the response steps
            foreach (NPCResponseStep NPCRS in npr.ResponseSteps)
            {
                // Get the invoking character
                invokingCharacter = new SlackMud().GetCharacter(invokingCharacter.UserID);

                // Check the character is still in the same room
                if (invokingCharacter.RoomID == this.RoomID)
                {
                    switch (NPCRS.ResponseStepType)
                    {
                    case "Conversation":
                        ProcessConversation(NPCRS, invokingCharacter);
                        break;

                    case "Attack":
                        this.Attack(invokingCharacter.GetFullName());
                        break;

                    case "UseSkill":
                        string[] dataSplit = null;
                        if (NPCRS.ResponseStepData.Contains('.'))
                        {
                            dataSplit = NPCRS.ResponseStepData.Split('.');
                        }
                        else
                        {
                            dataSplit[0] = NPCRS.ResponseStepData;
                            dataSplit[1] = null;
                        }

                        this.UseSkill(dataSplit[0], dataSplit[1]);
                        break;

                    case "ItemCheck":
                        // Get the additional data
                        string[] itemType = npr.AdditionalData.Split('.');

                        if (itemType[0] == "Family")
                        {
                            if (itemIn.ItemFamily != itemType[1])
                            {
                                // Drop the item
                                this.GetRoom().AddItem(itemIn);
                                this.GetRoom().Announce(OutputFormatterFactory.Get().Italic($"\"{this.GetFullName()}\" dropped {itemIn.SingularPronoun} {itemIn.ItemName}."));
                            }
                            else
                            {
                                ProcessConversation(NPCRS, invokingCharacter);
                            }
                        }

                        break;
                    }
                }
            }
        }
Ejemplo n.º 2
0
        public void RespondToAction(string actionType, SMCharacter invokingCharacter, SMItem itemIn = null)
        {
            // Get a list of characters that respond to this action type in the room
            List <NPCResponses> listToChooseFrom = NPCResponses.FindAll(npcr => npcr.ResponseType == actionType);

            // If there are some responses for this character for the actionType
            if (listToChooseFrom != null)
            {
                // If there is more than one of the item randomise the list
                if (listToChooseFrom.Count > 1)
                {
                    listToChooseFrom = listToChooseFrom.OrderBy(item => new Random().Next()).ToList();
                }

                // Loop around until a response is selected
                bool responseSelected = false;
                foreach (NPCResponses npr in listToChooseFrom)
                {
                    // If we're still looking for a response try the next one (if there is one)
                    if (!responseSelected)
                    {
                        // randomly select whether this happens or not
                        int rndChance = new Random().Next(1, 100);
                        if (rndChance <= npr.Frequency)
                        {
                            // If the invoking character is null
                            if ((invokingCharacter == null) && (this.RoomID != "IsSpawned"))
                            {
                                // Get a random player (in line with the scope of the additional data)
                                invokingCharacter = this.GetRoom().GetRandomCharacter(this, npr.AdditionalData);
                            }

                            // If the invoking character is not null
                            if (invokingCharacter != null)
                            {
                                // Process the response
                                ProcessResponse(npr, invokingCharacter, itemIn);
                            }

                            // Set that a response has been selected so we can drop out of the loop
                            responseSelected = true;
                        }
                    }
                }
            }
        }