示例#1
0
        /// <summary>
        /// Attack a character
        /// </summary>
        /// <param name="attackingCharacter">The attacking character</param>
        /// <param name="targetItem">The target string</param>
        public static void Attack(SMCharacter attackingCharacter, SMCharacter targetCharacter)
        {
            // Check that the target has hitpoints
            if (targetCharacter.Attributes.HitPoints > 0)
            {
                // Work out if this is an NPC or not
                SMRoom room = attackingCharacter.GetRoom();

                SMNPC targetNPC = room.GetNPCs().FirstOrDefault(checkChar => checkChar.GetFullName() == targetCharacter.GetFullName());

                if (targetNPC != null)
                {
                    room.ProcessNPCReactions("PlayerCharacter.AttacksThem", attackingCharacter);
                }

                List <SMNPC> NPCsInRoom = targetCharacter.GetRoom().GetNPCs().FindAll(npc => npc.GetFullName() != attackingCharacter.GetFullName());

                if (NPCsInRoom.Count > 0)
                {
                    room.ProcessNPCReactions("PlayerCharacter.Attack", attackingCharacter);
                }

                // Use the skill
                attackingCharacter.UseSkill(GetSkillToUse(attackingCharacter), targetCharacter.GetFullName(), true);
            }
            else             // Report that the target is already dead...
            {
                attackingCharacter.sendMessageToPlayer(targetCharacter.GetFullName() + " is already dead!");
            }
        }
示例#2
0
        /// <summary>
        /// Character "Shout" method
        /// </summary>
        /// <param name="speech">What the character is "Shouting"</param>
        /// <param name="charSpeaking">The character who is speaking</param>
        public void ChatShout(string speech, SMCharacter charSpeaking)
        {
            // variable for the message sending used later.
            string message;

            // Send the message to all people connected to the room
            foreach (SMCharacter smc in this.GetPeople())
            {
                // construct the local message to be sent.
                message = this.Formatter.Bold(charSpeaking.GetFullName() + " shouts:", 0) + " \"" + speech + "\"";
                this.ChatSendMessage(smc, message);
            }

            // Send a message to people connected to rooms around this room
            foreach (SMExit sme in this.RoomExits)
            {
                // Get the room details from the exit id
                SMRoom otherRooms = new SMRoom();

                otherRooms = new SlackMud().GetRoom(sme.RoomID);

                // Get the "from" location
                SMExit smre = otherRooms.RoomExits.FirstOrDefault(smef => smef.RoomID == this.RoomID);

                // Construct the message
                message = this.Formatter.Italic("Someone shouts from " + smre.Description + " (" + smre.Shortcut + "):", 0) + " \"" + speech + "\"";

                // Send the message to all people connected to the room
                foreach (SMCharacter smcInOtherRoom in otherRooms.GetPeople())
                {
                    otherRooms.ChatSendMessage(smcInOtherRoom, message);
                }
            }
        }
示例#3
0
        private string ProcessResponseString(string responseStringToProcess, SMCharacter invokingCharacter)
        {
            string responseString = responseStringToProcess;

            responseString = responseString.Replace("{playercharacter}", invokingCharacter.GetFullName());
            responseString = responseString.Replace("{response}", invokingCharacter.VariableResponse);

            return(responseString);
        }
示例#4
0
        /// <summary>
        /// Character "SAY" method
        /// </summary>
        /// <param name="speech">What the character is "Saying"</param>
        /// <param name="charSpeaking">The character who is speaking</param>
        public void ChatSay(string speech, SMCharacter charSpeaking)
        {
            // Construct the message
            string message = this.Formatter.Italic(charSpeaking.GetFullName() + " says:", 0) + " \"" + speech + "\"";

            // Send the message to all people connected to the room
            foreach (SMCharacter smc in this.GetPeople())
            {
                this.ChatSendMessage(smc, message);
            }
        }
示例#5
0
        public void LeaveParty(SMCharacter invokingCharacter, bool suppressMessages = false)
        {
            // Find the current party if they have one (and it's not just at "invited" stage).
            if ((invokingCharacter.PartyReference == null) || (invokingCharacter.PartyReference.Status != "Invited"))
            {
                // Remove them from the party reference.
                // Get the list of parties
                List <SMParty> smp = (List <SMParty>)HttpContext.Current.Application["Parties"];

                // Find the relevant party
                SMParty sp = smp.FirstOrDefault(p => p.PartyID == invokingCharacter.PartyReference.PartyID);

                if (!suppressMessages)
                {
                    sp.SendMessageToAllPartyMembers(sp, "[i]" + invokingCharacter.GetFullName() + " left the party[/i]");
                }

                // Remove the party from the global list element.
                smp.Remove(sp);

                // Find the relevant member
                SMPartyMember pm = sp.PartyMembers.FirstOrDefault(p => p.CharacterName == invokingCharacter.GetFullName());
                sp.PartyMembers.Remove(pm);

                // Check there are still people in the party
                if (sp.PartyMembers.Count > 0)
                {
                    // Add the member back to the list
                    smp.Add(sp);
                }

                // Save it out to the global list again
                HttpContext.Current.Application["Parties"] = smp;

                // Remove the party reference from the character file
                invokingCharacter.PartyReference = null;

                // Save the player information to the application.
                invokingCharacter.SaveToApplication();
            }
            else
            {
                if (!suppressMessages)
                {
                    invokingCharacter.sendMessageToPlayer("[i]You are not in a party so can't leave one[/i]");
                }
            }
        }
示例#6
0
        /// <summary>
        /// Character "Whisper" method
        /// </summary>
        /// <param name="speech">What the character is "Whispering"</param>
        /// <param name="charSpeaking">The character who is speaking</param>
        /// /// <param name="whisperToName">The character who is being whispered to</param>
        public void ChatWhisper(string speech, SMCharacter charSpeaking, string whisperToName)
        {
            // Construct the message
            string message = this.Formatter.Italic(charSpeaking.GetFullName() + " whispers:", 0) + " \"" + speech + "\"";

            // See if the person being whispered to is in the room
            SMCharacter smc = this.GetPeople().FirstOrDefault(charWhisperedto => charWhisperedto.GetFullName() == whisperToName);

            if (smc != null)
            {
                this.ChatSendMessage(smc, message);
            }
            else
            {
                message = "That person doesn't appear to be here?";
                // TODO Send message to player to say they can't whisper to that person.
            }
        }
示例#7
0
        /// <summary>
        /// Character "EMOTE" method
        /// </summary>
        /// <param name="emoting">What the character is "Emoting"</param>
        /// <param name="charSpeaking">The character who is emoting</param>
        public void ChatEmote(string speech, SMCharacter charSpeaking, SMNPC charNPCSpeak = null)
        {
            // Construct the message
            // Precursor items for generic NPCs
            string precursor = "";

            if ((charNPCSpeak != null) && (charNPCSpeak.IsGeneric))
            {
                precursor = charNPCSpeak.PronounSingular.ToUpper() + " ";
            }

            // Output the message
            string message = this.Formatter.Italic(precursor + charSpeaking.GetFullName() + " " + speech, 0);

            // Send the message to all people connected to the room
            foreach (SMCharacter smc in this.GetPeople())
            {
                this.ChatSendMessage(smc, message);
            }
        }
示例#8
0
        /// <summary>
        /// A new party creation
        /// </summary>
        /// <param name="invokingCharacter">The character creating the party.</param>
        public void CreateParty(SMCharacter invokingCharacter, bool suppressMessage = false)
        {
            if ((invokingCharacter.PartyReference == null) || (invokingCharacter.PartyReference.Status == "Invited"))
            {
                // Create a new id
                PartyID = Guid.NewGuid().ToString();

                // Add the invoking character to the party
                SMPartyMember smpm = new SMPartyMember();
                smpm.CharacterName = invokingCharacter.GetFullName();
                smpm.UserID        = invokingCharacter.UserID;
                PartyMembers       = new List <SMPartyMember>();
                PartyMembers.Add(smpm);

                // Add the party to the global memory
                List <SMParty> smp = (List <SMParty>)HttpContext.Current.Application["Parties"];
                smp.Add(this);

                // Save the party to the memory.
                HttpContext.Current.Application["Parties"] = smp;

                // Reference the new party against the character
                invokingCharacter.PartyReference = new SMPartyReference(this.PartyID, "Leader");

                if (!suppressMessage)
                {
                    invokingCharacter.sendMessageToPlayer("[i]Party created.[/i]");
                }

                // Save the player information to the application.
                invokingCharacter.SaveToApplication();
            }
            else // They are already in a party
            {
                if (!suppressMessage)
                {
                    invokingCharacter.sendMessageToPlayer("[i]Can not create a party as you're already in one.[/i]");
                }
            }
        }
示例#9
0
        /// <summary>
        /// Logs someone in with the Slack UserID
        /// </summary>
        /// <param name="userID">Slack UserID</param>
        /// <returns>A string response</returns>
        public string Login(string userID, bool newCharacter = false, string responseURL = null, string connectionService = "slack", string password = null)
        {
            // Variables for the return string
            string returnString = "";

            // Get all current characters
            List <SMCharacter> smcs      = (List <SMCharacter>)HttpContext.Current.Application["SMCharacters"];
            SMCharacter        character = smcs.FirstOrDefault(smc => smc.UserID == userID);

            // Get the right path, and work out if the file exists.
            string path = FilePathSystem.GetFilePath("Characters", "Char" + userID);

            // Check if the character exists..
            if (!File.Exists(path))
            {
                // If they don't exist inform the person as to how to create a new user
                returnString  = ResponseFormatterFactory.Get().General("You must create a character, to do so, use the command /sm CreateCharacter FIRSTNAME,LASTNAME,SEX,AGE");
                returnString += ResponseFormatterFactory.Get().General("i.e. /sm CreateCharacter Paul,Hutson,m,34");

                // return information [need to return this without a player!]
                return(returnString);
            }
            else
            {
                if ((character != null) && (!newCharacter))
                {
                    returnString = ResponseFormatterFactory.Get().General("You're already logged in!");
                    return(returnString);
                }
                else
                {
                    // Get the character
                    character = GetCharacter(userID, password);

                    // Reset the character activity, just in case!
                    character.CurrentActivity = null;

                    // Set the response URL of the character
                    if (responseURL != null)
                    {
                        character.ResponseURL = responseURL;
                    }

                    // Set the connection service
                    character.ConnectionService = connectionService;

                    // Set the last login datetime
                    character.LastLogindate = DateTime.Now;

                    // Check that the currency is OK.
                    if (character.Currency == null)
                    {
                        character.Currency = new SMCurrency();
                        character.Currency.AmountOfCurrency = 50;
                    }

                    if (!newCharacter)
                    {
                        returnString = ResponseFormatterFactory.Get().Bold("Welcome back " + character.FirstName + " " + character.LastName + " (you are level " + character.CalculateLevel() + ")", 1);
                    }
                    else
                    {
                        returnString  = ResponseFormatterFactory.Get().Bold("Welcome to SlackMud!");
                        returnString += ResponseFormatterFactory.Get().General("We've created your character in the magical world of Arrelvia!");                         // TODO, use a welcome script!
                    }

                    // Check if the player was last in an instanced location.
                    if (character.RoomID.Contains("||"))
                    {
                        // Find the details of the original room type
                        SMRoom originalRoom = GetRoom(character.RoomID.Substring(0, character.RoomID.IndexOf("||")));
                        character.RoomID = originalRoom.InstanceReloadLocation;
                    }

                    // Clear out any old party references
                    character.PartyReference = null;

                    // Get the location details
                    returnString += GetLocationDetails(character.RoomID, character);

                    // Clear old responses an quests from the character
                    character.ClearQuests();
                    if (character.NPCsWaitingForResponses != null)
                    {
                        character.NPCsWaitingForResponses.RemoveAll(a => a.NPCID != "");
                    }

                    // Return the text output
                    character.sendMessageToPlayer(returnString);

                    // Walk the character in
                    SMRoom room = character.GetRoom();
                    if (room != null)
                    {
                        // Announce someone has walked into the room.
                        room.Announce(ResponseFormatterFactory.Get().Italic(character.GetFullName() + " walks in."));
                        room.ProcessNPCReactions("PlayerCharacter.Enter", character);
                    }

                    return("");
                }
            }
        }
示例#10
0
        /// <summary>
        /// Create new character method
        /// </summary>
        /// <param name="userID">UserID - from the Slack UserID</param>
        /// <param name="firstName">The first name of the character</param>
        /// <param name="lastName">The last name of the character</param>
        /// <param name="age">The age of the character</param>
        /// <param name="sexIn">M or F for the male / Female character</param>
        /// <param name="characterType">M or F for the male / Female character</param>
        /// <returns>A string with the character information</returns>
        public string CreateCharacter(string userID, string firstName, string lastName, string sexIn, string age, string characterType = "BaseCharacter", string responseURL = null, string userName = null, string password = null, bool autoLogin = true)
        {
            // Get the path for the character
            string path = FilePathSystem.GetFilePath("Characters", "Char" + userID);

            // If the file doesn't exist i.e. the character doesn't exist
            if (!File.Exists(path))
            {
                // Create the character options
                SMCharacter SMChar = new SMCharacter();
                SMChar.UserID              = userID;
                SMChar.FirstName           = firstName;
                SMChar.LastName            = lastName;
                SMChar.LastLogindate       = DateTime.Now;
                SMChar.LastInteractionDate = DateTime.Now;
                SMChar.PKFlag              = false;
                SMChar.Sex = char.Parse(sexIn);
                SMChar.Age = int.Parse(age);
                if (userName != null)
                {
                    SMChar.Username = userName;
                }
                if (password != null)
                {
                    SMChar.Password = Utility.Crypto.EncryptStringAES(password);
                }

                // Add default attributes to the character
                SMChar.Attributes = CreateBaseAttributesFromJson("Attribute." + characterType);

                // Set default character slots before adding items to them
                SMChar.Slots = CreateSlotsFromJSON("Slots." + characterType);

                // Add default items to the character
                SMSlot back = SMChar.GetSlotByName("Back");
                back.EquippedItem = SMItemFactory.Get("Container", "SmallBackpack");

                // Add default body parts to the new character
                SMChar.BodyParts = CreateBodyPartsFromJSON("BodyParts." + characterType);

                // Add the base currency
                SMChar.Currency = CreateCurrencyFromJSON("Currency.BaseCharacter");

                // Set the start location
                SMChar.RoomID = "1";
                string defaultRoomPath = FilePathSystem.GetFilePath("Scripts", "EnterWorldProcess-FirstLocation");
                if (File.Exists(defaultRoomPath))
                {
                    // Use a stream reader to read the file in (based on the path)
                    using (StreamReader r = new StreamReader(defaultRoomPath))
                    {
                        // Create a new JSON string to be used...
                        string json = r.ReadToEnd();

                        // ... get the information from the the start location token..
                        SMStartLocation sl = JsonConvert.DeserializeObject <SMStartLocation>(json);

                        // Set the start location.
                        SMChar.RoomID = sl.StartLocation;

                        // TODO Add room to memory if not already there.
                    }
                }

                // Write the character to the stream
                SMChar.SaveToFile();

                // Write an account reference to the CharNamesList
                new SMAccountHelper().AddNameToList(SMChar.GetFullName(), SMChar.UserID, SMChar);

                // Check if there is a response URL
                if ((responseURL != null) && (autoLogin))
                {
                    // Log the newly created character into the game if in something like Slack
                    Login(userID, true, responseURL);
                    return("");
                }
                else
                {
                    // Return the userid ready for logging in
                    return(userID);
                }
            }
            else
            {
                // If they already have a character tell them they do and that they need to login.
                // log the newly created character into the game
                // Login(userID, true, responseURL);

                // Get all current characters
                List <SMCharacter> smcs      = (List <SMCharacter>)HttpContext.Current.Application["SMCharacters"];
                SMCharacter        character = smcs.FirstOrDefault(smc => smc.UserID == userID);

                return(ResponseFormatterFactory.Get().General("You already have a character, you cannot create another."));
            }
        }
示例#11
0
        /// <summary>
        /// Gets a character and also loads the character to memory if it isn't already there.
        /// </summary>
        /// <param name="userID">The id of the character you want to load</param>
        /// <returns>A character</returns>
        public SMCharacter GetCharacter(string userID, string userName = null, string password = null)
        {
            // Get the character file if it exists
            List <SMCharacter> smcs      = (List <SMCharacter>)HttpContext.Current.Application["SMCharacters"];
            SMCharacter        charInMem = smcs.FirstOrDefault(smc => smc.UserID == userID);

            if (charInMem == null)
            {
                // Get the right path, and work out if the file exists.
                string path = FilePathSystem.GetFilePath("Characters", "Char" + userID);

                // Check if the character exists..
                if (File.Exists(path))
                {
                    using (StreamReader r = new StreamReader(path))
                    {
                        // Get the character from the json string
                        string json = r.ReadToEnd();
                        charInMem = JsonConvert.DeserializeObject <SMCharacter>(json);

                        bool canLogin = true;
                        if (password != null)
                        {
                            canLogin = (Crypto.DecryptStringAES(charInMem.Password) == password);
                        }
                        if ((canLogin) && (password != null))
                        {
                            canLogin = (Crypto.DecryptStringAES(charInMem.Password) == password);
                        }

                        if (canLogin)
                        {
                            // Add the character to the application memory
                            smcs.Add(charInMem);
                            HttpContext.Current.Application["SMCharacters"] = smcs;

                            // Send a message so everyone knows someone has logged in.
                            SendGlobalMessage(charInMem, "[i][b]Global Message:[/b] " + charInMem.GetFullName() + " has logged into the game[/i]");
                        }
                    }
                }
            }
            return(charInMem);
        }
示例#12
0
        public void JoinParty(SMCharacter invokingCharacter, bool suppressMessages = false)
        {
            // Check the character has an open invite
            if ((invokingCharacter.PartyReference != null) && (invokingCharacter.PartyReference.Status == "Invited"))
            {
                // Find the party in the list of parties
                List <SMParty> smp = (List <SMParty>)HttpContext.Current.Application["Parties"];

                // Find the relevant party
                SMParty sp = smp.FirstOrDefault(p => p.PartyID == invokingCharacter.PartyReference.PartyID);

                // If it exists...
                if (sp != null)
                {
                    // Remove the party from the global list for a mo..
                    smp.Remove(sp);

                    // ... add the character to the party.
                    SMPartyMember smpm = new SMPartyMember();
                    smpm.CharacterName = invokingCharacter.GetFullName();
                    smpm.UserID        = invokingCharacter.UserID;
                    sp.PartyMembers.Add(smpm);

                    // Add the party to the list again..
                    smp.Add(sp);

                    // .. and save the list out
                    HttpContext.Current.Application["Parties"] = smp;

                    // ... send a message to all the people in the party.
                    if (!suppressMessages)
                    {
                        sp.SendMessageToAllPartyMembers(sp, "[i]" + smpm.CharacterName + " joined the party[/i]");
                    }

                    // ... change the status of the party element on the character to "joined"
                    invokingCharacter.PartyReference.Status = "Joined";

                    // Save the player information to the application.
                    invokingCharacter.SaveToApplication();
                }
                else // .. the party no longer exists, so can't be joined
                {
                    // Tell the player
                    if (!suppressMessages)
                    {
                        invokingCharacter.sendMessageToPlayer("[i]That party no longer exists.[/i]");
                    }

                    // Remove the reference from their party invite list.
                    invokingCharacter.PartyReference = null;

                    // Save the player information to the application.
                    invokingCharacter.SaveToApplication();
                }
            }
            else // No party
            {
                if (!suppressMessages)
                {
                    invokingCharacter.sendMessageToPlayer("[i]You have no open party invites.[/i]");
                }
            }
        }
示例#13
0
        private void ProcessConversationStep(NPCConversations npcc, string stepID, SMCharacter invokingCharacter)
        {
            NPCConversationStep npccs = npcc.ConversationSteps.FirstOrDefault(cs => cs.StepID == stepID);
            bool continueToNextStep   = true;

            if (npccs != null)
            {
                switch (npccs.Scope.ToLower())
                {
                case "choice":
                    string[] choices       = npccs.AdditionalData.Split(',');
                    int      choicesNumber = choices.Count();
                    int      randomChoice  = (new Random().Next(1, choicesNumber + 1)) - 1;
                    if (randomChoice > choicesNumber)
                    {
                        randomChoice = 0;
                    }
                    ProcessConversationStep(npcc, choices[randomChoice], invokingCharacter);
                    break;

                case "say":
                    this.Say(ProcessResponseString(npccs.AdditionalData, invokingCharacter));
                    break;

                case "shout":
                    this.Shout(ProcessResponseString(npccs.AdditionalData, invokingCharacter));
                    break;

                case "whisper":
                    this.Whisper(ProcessResponseString(npccs.AdditionalData, invokingCharacter), invokingCharacter.GetFullName());
                    break;

                case "emote":
                    this.GetRoom().ChatEmote(ProcessResponseString(npccs.AdditionalData, invokingCharacter), this, this);
                    break;

                case "saytoplayer":
                    // Construct the message
                    string sayToPlayerMessage = OutputFormatterFactory.Get().Italic(this.GetFullName() + " says:", 0) + " \"" + ProcessResponseString(npccs.AdditionalData, invokingCharacter) + "\"";

                    // Send the message
                    invokingCharacter.sendMessageToPlayer(sayToPlayerMessage);
                    break;

                case "emotetoplayer":
                    // Construct the message
                    string emoteToPlayerMessage = OutputFormatterFactory.Get().Italic(this.GetFullName() + " " + ProcessResponseString(npccs.AdditionalData, invokingCharacter));

                    // Send the message
                    invokingCharacter.sendMessageToPlayer(emoteToPlayerMessage);
                    break;

                case "attack":
                    // Simply attack a target player
                    this.Attack(invokingCharacter.GetFullName());
                    break;

                case "giveitem":
                    // give an item to the player
                    string[] additionalDataSplit = npccs.AdditionalData.Split(',');
                    string[] itemParts           = additionalDataSplit[0].Split('.');

                    // Create the item..
                    if (itemParts.Count() == 2)
                    {
                        int numberToCreate = int.Parse(additionalDataSplit[1]);

                        // Create the right number of the items.
                        while (numberToCreate > 0)
                        {
                            // Get the item (with a new GUID)
                            SMItem itemBeingGiven = SMItemFactory.Get(itemParts[0], itemParts[1]);

                            // Pass it to the player
                            invokingCharacter.PickUpItem("", itemBeingGiven, true);

                            // Reduce the number to create
                            numberToCreate--;
                        }
                    }
                    break;

                case "addquest":
                    // Load the quest
                    SMQuest smq = SMQuestFactory.Get(npccs.AdditionalData);
                    if (smq != null)
                    {
                        invokingCharacter.AddQuest(smq);
                    }
                    break;

                case "updatequest":
                    // Load the quest
                    SMQuest qtu = SMQuestFactory.Get(npccs.AdditionalData);
                    if (qtu != null)
                    {
                        invokingCharacter.UpdateQuest(qtu);
                    }
                    break;

                case "checkquestinprogress":
                    // Check the quest log isn't null
                    if (invokingCharacter.QuestLog != null)
                    {
                        if (invokingCharacter.QuestLog.Count(questcheck => (questcheck.QuestName.ToLower() == npccs.AdditionalData.ToLower()) && (questcheck.Completed)) > 0)
                        {
                            continueToNextStep = false;
                        }
                    }
                    break;

                case "setplayerattribute":
                    // Add a response option
                    switch (npccs.AdditionalData.ToLower())
                    {
                    case "firstname":
                        invokingCharacter.FirstName = invokingCharacter.VariableResponse;
                        break;

                    case "lastname":
                        invokingCharacter.LastName = invokingCharacter.VariableResponse;
                        break;

                    case "sex":
                        invokingCharacter.Sex = char.Parse(invokingCharacter.VariableResponse);
                        break;
                    }
                    invokingCharacter.SaveToApplication();
                    invokingCharacter.SaveToFile();
                    break;

                case "setvariableresponse":
                    invokingCharacter.VariableResponse = npccs.AdditionalData.ToLower();
                    break;

                case "teachskill":
                    // Check if the player already has the skill
                    if (invokingCharacter.Skills == null)
                    {
                        invokingCharacter.Skills = new List <SMSkillHeld>();
                    }

                    // Get the skill and level to teach to
                    string[] skillToTeach = npccs.AdditionalData.Split('.');

                    // Check if the character already has the skill
                    if (invokingCharacter.Skills.Count(skill => skill.SkillName == skillToTeach[0]) == 0)
                    {
                        // Create a new skill help object
                        SMSkillHeld smsh = new SMSkillHeld();
                        smsh.SkillName  = skillToTeach[0];
                        smsh.SkillLevel = int.Parse(skillToTeach[1]);

                        // Finally add it to the player
                        invokingCharacter.Skills.Add(smsh);

                        // Save the player
                        invokingCharacter.SaveToApplication();
                        invokingCharacter.SaveToFile();

                        // Inform the player they have learnt a new skill
                        invokingCharacter.sendMessageToPlayer(OutputFormatterFactory.Get().Italic($"You learn a new skill: {smsh.SkillName}({smsh.SkillLevel})."));
                    }

                    break;

                case "wait":
                    System.Threading.Thread.Sleep(int.Parse(npccs.AdditionalData) * 1000);
                    break;
                }

                if (continueToNextStep)
                {
                    if (npccs.ResponseOptions != null)
                    {
                        if (npccs.ResponseOptions.Count > 0)
                        {
                            ProcessResponseOptions(npcc, npccs, invokingCharacter);
                        }
                    }

                    if (npccs.NextStep != null)
                    {
                        string[] splitNextStep = npccs.NextStep.Split('.');
                        if (splitNextStep[1] != "0")
                        {
                            System.Threading.Thread.Sleep(int.Parse(splitNextStep[1]) * 1000);
                        }
                        ProcessConversationStep(npcc, splitNextStep[0], invokingCharacter);
                    }
                }
            }
        }
示例#14
0
        public void ProcessNPCReactions(string actionType, SMCharacter invokingCharacter, string extraData = null)
        {
            List <SMNPC> lNPCs = new List <SMNPC>();

            lNPCs = ((List <SMNPC>)HttpContext.Current.Application["SMNPCs"]).FindAll(npc => ((npc.RoomID == invokingCharacter.RoomID) && (npc.GetFullName() != invokingCharacter.GetFullName())));

            // Check if the character already exists or not.
            if (lNPCs != null)
            {
                // Get the NPCs who have a response of the right type
                if (extraData != null)
                {
                    switch (actionType)
                    {
                    case "PlayerCharacter.ExaminesThem":
                        lNPCs = lNPCs.FindAll(npc => ((npc.NPCResponses.Count(npcr => npcr.ResponseType.ToLower() == actionType.ToLower()) > 0) && (npc.UserID == extraData)));
                        break;

                    default:
                        lNPCs = lNPCs.FindAll(npc => npc.NPCResponses.Count(npcr => npcr.ResponseType.ToLower() == actionType.ToLower()) > 0);
                        break;
                    }
                }
                else
                {
                    lNPCs = lNPCs.FindAll(npc => npc.NPCResponses.Count(npcr => npcr.ResponseType.ToLower() == actionType.ToLower()) > 0);
                }

                if (lNPCs != null)
                {
                    foreach (SMNPC reactingNPC in lNPCs)
                    {
                        HttpContext ctx = HttpContext.Current;

                        Thread npcReactionThread = new Thread(new ThreadStart(() =>
                        {
                            HttpContext.Current = ctx;
                            reactingNPC.RespondToAction(actionType, invokingCharacter);
                        }));

                        npcReactionThread.Start();
                    }
                }
            }
        }
示例#15
0
        /// <summary>
        /// Inspect a person, object, etc.
        /// </summary>
        /// <param name="smc">The character doing the inspecting</param>
        /// <param name="thingToInspect">The thing that the person wants to inspect</param>
        public void InspectThing(SMCharacter smc, string thingToInspect)
        {
            // Check if it's a character first
            SMCharacter targetCharacter = this.GetPeople().FirstOrDefault(checkChar => checkChar.GetFullName().ToLower() == thingToInspect.ToLower());

            if (targetCharacter != null)
            {
                smc.sendMessageToPlayer(OutputFormatterFactory.Get().Bold("Description of " + targetCharacter.GetFullName() + " (Level " + targetCharacter.CalculateLevel() + "):"));
                if ((targetCharacter.Description != null) || (targetCharacter.Description != ""))
                {
                    smc.sendMessageToPlayer(OutputFormatterFactory.Get().Italic(targetCharacter.Description));
                }
                else
                {
                    smc.sendMessageToPlayer(OutputFormatterFactory.Get().Italic("No description set..."));
                }
                smc.sendMessageToPlayer(OutputFormatterFactory.Get().CodeBlock(targetCharacter.GetInventoryList()));
                targetCharacter.sendMessageToPlayer(OutputFormatterFactory.Get().Italic(smc.GetFullName() + " looks at you"));
                return;
            }

            // If not a character, check if it is an NPC...
            SMNPC targetNPC = this.GetNPCs().FirstOrDefault(checkChar => checkChar.GetFullName().ToLower() == thingToInspect.ToLower());

            if (targetNPC != null)
            {
                smc.sendMessageToPlayer(OutputFormatterFactory.Get().Bold("Description of " + targetNPC.GetFullName() + " (Level " + targetNPC.CalculateLevel() + "):"));
                if ((targetNPC.Description != null) || (targetNPC.Description != ""))
                {
                    smc.sendMessageToPlayer(OutputFormatterFactory.Get().Italic(targetNPC.Description));
                }
                else
                {
                    smc.sendMessageToPlayer(OutputFormatterFactory.Get().Italic("No description set..."));
                }
                smc.sendMessageToPlayer(OutputFormatterFactory.Get().CodeBlock(targetNPC.GetInventoryList()));
                targetNPC.GetRoom().ProcessNPCReactions("PlayerCharacter.ExaminesThem", smc, targetNPC.UserID);
                targetNPC.GetRoom().ProcessNPCReactions("PlayerCharacter.Examines", smc);
                return;
            }

            // If not an NPC, check the players equipped items and the items in the room...
            SMItem smi = smc.GetEquippedItem(thingToInspect);

            if (smi == null)
            {
                smi = SMItemHelper.GetItemFromList(this.RoomItems, thingToInspect);
            }

            if (smi != null)
            {
                string itemDeatils = OutputFormatterFactory.Get().Bold("Description of \"" + smi.ItemName + "\":");
                itemDeatils += OutputFormatterFactory.Get().ListItem(smi.ItemDescription);

                if (smi.CanHoldOtherItems())
                {
                    itemDeatils += OutputFormatterFactory.Get().Italic($"This \"{smi.ItemName}\" contains the following items:");
                    itemDeatils += SMItemHelper.GetContainerContents(smi);
                }

                smc.sendMessageToPlayer(itemDeatils);
                return;
            }

            // Otherwise nothing found
            smc.sendMessageToPlayer(OutputFormatterFactory.Get().Italic("Can not inspect that item."));
        }
示例#16
0
        /// <summary>
        /// Invite someone to a party.
        /// </summary>
        /// <param name="invokingCharacter"></param>
        /// <param name="characterName"></param>
        /// <param name="suppressMessages"></param>
        public void InviteToParty(SMCharacter invokingCharacter, string characterName, bool suppressMessages = false)
        {
            // See if the person being invited exists in memory
            SMCharacter smc = ((List <SMCharacter>)HttpContext.Current.Application["SMCharacters"]).FirstOrDefault(ch => ch.GetFullName() == characterName);

            // check that the player exists...
            if (smc != null)
            {
                // Check that they're not already in a party
                if ((smc.PartyReference == null))
                {
                    // For use later
                    bool canJoinParty = true;

                    // Check the invoking player is in a party... and they're the leader
                    if (invokingCharacter.PartyReference != null)
                    {
                        if (invokingCharacter.PartyReference.Status != "Leader")
                        {
                            canJoinParty = false;
                            if (!suppressMessages)
                            {
                                invokingCharacter.sendMessageToPlayer("[i]You are not the party leader so can not invite someone[/i]");
                            }
                        }
                    }
                    else // The player inviting does't have a party yet..
                    {
                        // .. so lets create it.
                        new SMParty().CreateParty(invokingCharacter, true);
                    }

                    // If the player can join the party...
                    if (canJoinParty)
                    {
                        if (!suppressMessages)
                        {
                            // Send a message to the player being invited...
                            smc.sendMessageToPlayer("[i]You have been invited to a party by " + invokingCharacter.GetFullName() + " - to accept type \"AcceptInvite\"[/i]");
                        }

                        // Add the SMPartyReference to the character
                        smc.PartyReference = new SMPartyReference(invokingCharacter.PartyReference.PartyID, "Invited");

                        // Save the player information to the application.
                        smc.SaveToApplication();
                    }
                }
                else
                {
                    if (!suppressMessages)
                    {
                        invokingCharacter.sendMessageToPlayer("[i]Can not invite that character to a party as they are already in a party.[/i]");
                    }
                }
            }
            else
            {
                if (!suppressMessages)
                {
                    invokingCharacter.sendMessageToPlayer("[i]Can not find a character named + \"" + characterName + "\"[/i]");
                }
            }
        }
示例#17
0
        /// <summary>
        /// Inspect a person, object, etc.
        /// </summary>
        /// <param name="smc">The character doing the inspecting</param>
        /// <param name="thingToInspect">The thing that the person wants to inspect</param>
        public void InspectThing(SMCharacter smc, string thingToInspect)
        {
            // Check if it's a character first
            SMCharacter targetCharacter = this.GetPeople().FirstOrDefault(checkChar => (checkChar.GetFullName().ToLower() == thingToInspect.ToLower()) || (checkChar.FirstName.ToLower() == thingToInspect.ToLower()) || (checkChar.LastName.ToLower() == thingToInspect.ToLower()));

            if (targetCharacter != null)
            {
                string levelText = "";
                if (int.Parse(targetCharacter.CalculateLevel()) > 0)
                {
                    levelText = " (Level " + targetCharacter.CalculateLevel() + ")";
                }

                smc.sendMessageToPlayer(this.Formatter.Bold("Description of " + targetCharacter.GetFullName() + levelText + ":"));
                if ((targetCharacter.Description != null) && (targetCharacter.Description != ""))
                {
                    smc.sendMessageToPlayer(this.Formatter.Italic(targetCharacter.Description));
                }
                else
                {
                    smc.sendMessageToPlayer(this.Formatter.Italic("No description set..."));
                }

                List <string> inventory       = targetCharacter.GetInventoryList();
                string        inventoryOutput = String.Empty;

                if (inventory.Any())
                {
                    foreach (string item in inventory)
                    {
                        inventoryOutput += this.Formatter.ListItem(item);
                    }

                    inventoryOutput += this.Formatter.GetNewLines(1);
                }

                smc.sendMessageToPlayer(inventoryOutput);

                targetCharacter.sendMessageToPlayer(this.Formatter.Italic(smc.GetFullName() + " looks at you"));
                return;
            }

            // If not a character, check if it is an NPC...
            SMNPC targetNPC = this.GetNPCs().FirstOrDefault(checkChar => (checkChar.GetFullName().ToLower() == thingToInspect.ToLower()) || (checkChar.NPCType.ToLower() == thingToInspect.ToLower()));

            if (targetNPC != null)
            {
                string levelText = "";
                if (int.Parse(targetNPC.CalculateLevel()) > 0)
                {
                    levelText = " (Level " + targetNPC.CalculateLevel() + ")";
                }

                smc.sendMessageToPlayer(this.Formatter.Bold("Description of " + targetNPC.GetFullName() + levelText + ":"));
                if ((targetNPC.Description != null) && (targetNPC.Description != ""))
                {
                    smc.sendMessageToPlayer(this.Formatter.Italic(targetNPC.Description));
                }
                else
                {
                    smc.sendMessageToPlayer(this.Formatter.Italic("No description set..."));
                }

                List <string> inventory       = targetNPC.GetInventoryList();
                string        inventoryOutput = String.Empty;

                if (inventory.Any())
                {
                    foreach (string item in inventory)
                    {
                        inventoryOutput += this.Formatter.ListItem(item);
                    }

                    inventoryOutput += this.Formatter.GetNewLines(1);
                }

                smc.sendMessageToPlayer(inventoryOutput);

                targetNPC.GetRoom().ProcessNPCReactions("PlayerCharacter.ExaminesThem", smc, targetNPC.UserID);
                targetNPC.GetRoom().ProcessNPCReactions("PlayerCharacter.Examines", smc);
                return;
            }

            // If not an NPC, check the players equipped items and the items in the room...
            SMItem smi = smc.GetEquippedItem(thingToInspect);

            if (smi == null)
            {
                smi = SMItemHelper.GetItemFromList(this.RoomItems, thingToInspect);
            }

            if (smi != null)
            {
                string itemDeatils = this.Formatter.Bold("Description of \"" + smi.ItemName + "\":", 1);
                itemDeatils += this.Formatter.General(smi.ItemDescription, 1);

                if (smi.CanHoldOtherItems())
                {
                    itemDeatils += this.Formatter.Italic($"This \"{smi.ItemName}\" contains the following items:", 1);
                    itemDeatils += SMItemHelper.GetContainerContents(smi);
                }

                if (smi.Effects != null)
                {
                    smi.InitiateEffects(smc);
                }

                smc.sendMessageToPlayer(itemDeatils);
                return;
            }

            // Otherwise nothing found
            smc.sendMessageToPlayer(this.Formatter.Italic("Can not inspect that item."));
        }
示例#18
0
        /// <summary>
        /// Update the user details of the character to the character names file
        /// This provides easy reference to the username / password when logging in
        /// on other platforms.
        /// </summary>
        /// <param name="smc">The character being used</param>
        public void UpdateUserDetails(SMCharacter smc)
        {
            // Load the char names list into memory
            string           path          = FilePathSystem.GetFilePath("Characters", "CharNamesList");
            List <SMAccount> allCharacters = new List <SMAccount>();

            if (File.Exists(path))
            {
                using (StreamReader r = new StreamReader(path))
                {
                    string json = r.ReadToEnd();
                    allCharacters = JsonConvert.DeserializeObject <List <SMAccount> >(json);
                }
            }

            // Find the relevant one
            SMAccount smcn = allCharacters.FirstOrDefault(c => c.CharacterName.ToLower() == smc.GetFullName().ToLower());

            // remove the existing one from the memory
            allCharacters.Remove(smcn);

            // Check if we found something, if we didn't we might have an issue..
            if (smcn != null)
            {
                smcn.EmailAddress   = smc.Username;
                smcn.HashedPassword = smc.Password;
            }

            // Now save that back out.
            allCharacters.Add(smcn);

            string listJSON = JsonConvert.SerializeObject(allCharacters, Formatting.Indented);

            using (StreamWriter w = new StreamWriter(path))
            {
                w.WriteLine(listJSON);
            }
        }