예제 #1
0
        /// <summary>
        /// Randomly select a single character from within a scope
        /// </summary>
        /// <param name="scope">PlayerCharacters, NPCs or AllPeople</param>
        /// <returns></returns>
        public SMCharacter GetRandomCharacter(SMCharacter ignoreChar, string scope = null)
        {
            switch (scope)
            {
            case "PlayerCharacters":
                List <SMCharacter> pc = this.GetPeople();
                pc.Remove(ignoreChar);
                pc.Shuffle();
                return(pc.FirstOrDefault());

            case "NPCs":
                List <SMCharacter> npcs = new List <SMCharacter>();
                List <SMNPC>       npcl = this.GetNPCs();
                if (npcl != null)
                {
                    foreach (SMNPC npc in npcl)
                    {
                        npcs.Add(npc);
                    }
                }
                npcs.Remove(ignoreChar);
                npcs.Shuffle();
                return(npcs.FirstOrDefault());

            default:
                List <SMCharacter> ap = GetAllPeople();
                ap.Remove(ignoreChar);
                ap.Shuffle();
                return(ap.FirstOrDefault());
            }
        }
예제 #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
        /// <summary>
        /// Gets a list of all the people in the room.
        /// </summary>
        public string GetPeopleDetails(SMCharacter smc = null)
        {
            string returnString = this.Formatter.Bold("People:");

            // Get the people within the location
            List <SMCharacter> smcs = this.GetPeople();

            // Check if the character already exists or not.
            if (smcs != null)
            {
                string[] people = new string[smcs.Count];

                for (int i = 0; i < smcs.Count; i++)
                {
                    if (smcs[i].UserID == smc.UserID)
                    {
                        people[i] = "You";
                    }
                    else
                    {
                        people[i] = smcs[i].GetFullName();
                    }
                }

                returnString += this.Formatter.ListItem(String.Join(", ", people));
            }
            else
            {
                returnString += this.Formatter.ListItem("There's nobody here.");
            }

            return(returnString);
        }
예제 #4
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(ResponseFormatterFactory.Get().General($"{targetCharacter.GetFullName()} is already dead!"));
            }
        }
예제 #5
0
        public void FindAllPartyMembers(SMCharacter invokingCharacter)
        {
            if (invokingCharacter.PartyReference != null)
            {
                SMParty sp = SMPartyHelper.GetParty(invokingCharacter.PartyReference.PartyID);

                string stringToSend = "[b]Party Members:[/b] ";
                bool   first        = true;

                foreach (SMPartyMember pm in sp.PartyMembers)
                {
                    if (first)
                    {
                        first = false;
                    }
                    else
                    {
                        stringToSend += ", ";
                    }
                    stringToSend += pm.CharacterName;
                }

                invokingCharacter.sendMessageToPlayer(stringToSend);
            }
            else // They're not in a party
            {
                invokingCharacter.sendMessageToPlayer("[i]You're not in a party.[/i]");
            }
        }
예제 #6
0
        /// <summary>
        /// Decrease the faction level for a character
        /// </summary>
        /// <param name="smc">The Character</param>
        /// <param name="factionName">The Faction Name</param>
        /// <param name="amount">The amount to decrease</param>
        /// <returns></returns>
        public static void DecreaseFactionLevel(SMCharacter smc, string factionName, int amount)
        {
            // Find the faction information from the player
            SMFaction smf = GetFactionFromPlayerList(smc, factionName);

            // Check if it's null..
            if (smf != null)
            {
                smc.Factions.Remove(smf);
                smf.Level -= amount;
            }
            else
            {
                smf = new SMFaction(factionName, (0 - amount));
                if (smc.Factions == null)
                {
                    smc.Factions = new List <SMFaction>();
                }
            }

            smc.Factions.Add(smf);

            smc.sendMessageToPlayer("[i]" + smf.FactionName + " standing decreased by " + amount + " to " + smf.Level + "[/i]");

            smc.SaveToApplication();
            smc.SaveToFile();
        }
예제 #7
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;
                    }
                }
            }
        }
예제 #8
0
        /// <summary>
        /// SMHelp class constructor, populate commandsList
        /// </summary>
        public SMHelp(string UserId)
        {
            this.commandList = this.GetCommandsList();

            this.character = new SlackMud().GetCharacter(UserId);

            this.outputFormatter = OutputFormatterFactory.Get();
        }
예제 #9
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);
        }
예제 #10
0
        public void RebuildCharacterJSONFile()
        {
            string        commandsFolderPath = FilePathSystem.GetFilePathFromFolder("Characters");
            DirectoryInfo dirInfo            = new DirectoryInfo(commandsFolderPath);

            FileInfo[] CommandFiles = dirInfo.GetFiles("*.json");

            List <SMCharacter> smcl = new List <SMCharacter>();

            foreach (FileInfo file in CommandFiles)
            {
                if (file.Name != "CharNamesList.json")
                {
                    string path = FilePathSystem.GetFilePath("Characters", file.Name, "");
                    // Use a stream reader to read the file in (based on the path)
                    using (StreamReader r = new StreamReader(path))
                    {
                        // Create a new JSON string to be used...
                        string json = r.ReadToEnd();

                        // Get all the commands from the commands file
                        try
                        {
                            SMCharacter nsmc = JsonConvert.DeserializeObject <SMCharacter>(json);
                            smcl.Add(nsmc);
                        }
                        catch
                        {
                            Utils.LogError("Failed to write char record in CharNamesList.json - record: " + file.Name);
                        }
                    }
                }
            }

            List <SMAccount> smal = new List <SMAccount>();

            foreach (SMCharacter smc in smcl)
            {
                SMAccount sma = new SMAccount();
                sma.AccountReference = smc.UserID;
                sma.CharacterName    = smc.GetFullName();
                sma.UserName         = smc.Username;
                sma.HashedPassword   = smc.Password;

                smal.Add(sma);
            }

            string listJSON = JsonConvert.SerializeObject(smal, Formatting.Indented);
            string path2    = FilePathSystem.GetFilePath("Characters", "CharNamesList");

            using (StreamWriter w = new StreamWriter(path2))
            {
                w.WriteLine(listJSON);
            }
        }
예제 #11
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);
            }
        }
예제 #12
0
        /// <summary>
        /// Adds the name to the CharNamesList
        /// </summary>
        /// <param name="fullCharName">The full name of the character being added</param>
        /// <returns></returns>
        public void AddNameToList(string fullCharName, string accountReference, SMCharacter smc = null)
        {
            // Load the char names list into memory
            string           path          = FilePathSystem.GetFilePath("Characters", "CharNamesList");
            List <SMAccount> allCharacters = new List <SMAccount>();

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

            // Create a new character reference
            SMAccount smcn = new SMAccount();

            smcn.CharacterName    = fullCharName;
            smcn.AccountReference = accountReference;
            // If the character is passed in...
            if (smc != null)
            {
                // ... check if there is a username and password associated
                if ((smc.Username != null) && (smc.Password != null))
                {
                    // Assigned the username to the email address
                    smcn.UserName       = smc.Username;
                    smcn.HashedPassword = smc.Password;
                }
            }

            // Check if the account reference is already in the list
            SMAccount sma = allCharacters.FirstOrDefault(c => c.AccountReference == accountReference);

            // If it does exist...
            if (sma != null)
            {
                // ... remove the old version
                allCharacters.Remove(sma);
            }

            // Add the character to the list
            allCharacters.Add(smcn);

            // Save the list to disk.
            string listJSON = JsonConvert.SerializeObject(allCharacters, Formatting.Indented);

            using (StreamWriter w = new StreamWriter(path))
            {
                w.WriteLine(listJSON);
            }
        }
예제 #13
0
        public static void StartAnNPCReactionCheck(SMNPC npc, string actionType, SMCharacter invokingCharacter, SMItem itemIn = null)
        {
            HttpContext ctx = HttpContext.Current;

            Thread npcReactionThread = new Thread(new ThreadStart(() =>
            {
                HttpContext.Current = ctx;
                npc.RespondToAction("PlayerCharacter.GivesItemToThem", invokingCharacter, itemIn);
            }));

            npcReactionThread.Start();
        }
예제 #14
0
        /// <summary>
        /// Checks if a user is logged in by getting their character from memory by UserID.
        /// </summary>
        /// <param name="UserID"></param>
        /// <returns>True if the user is logged in, otherwise false.</returns>
        private bool IsLoggedIn(string UserID)
        {
            List <SMCharacter> smcs      = (List <SMCharacter>)HttpContext.Current.Application["SMCharacters"];
            SMCharacter        charInMem = smcs.FirstOrDefault(smc => smc.UserID == UserID);

            if (charInMem != null)
            {
                return(true);
            }

            return(false);
        }
예제 #15
0
        /// <summary>
        /// Gets any type of character and also loads the character to memory if it isn't already there.
        /// Note: This returns NPCs as well as Player Characters
        /// </summary>
        /// <param name="userID">The id of the character you want to load</param>
        /// <returns>A character</returns>
        public SMCharacter GetAllCharacters(string userID)
        {
            // Get the room file if it exists
            SMCharacter returnCharacter = ((List <SMNPC>)HttpContext.Current.Application["SMNPCs"]).FirstOrDefault(smc => smc.UserID == userID);

            if (returnCharacter == null)
            {
                returnCharacter = GetCharacter(userID);
            }

            return(returnCharacter);
        }
예제 #16
0
 /// <summary>
 /// Attack a Creature
 /// </summary>
 /// <param name="attackingCharacter">The attacking character</param>
 /// <param name="targetCharacter">The target character</param>
 public static void Attack(SMCharacter attackingCharacter, SMCreature targetCreature)
 {
     // Check that the target has hitpoints
     if (targetCreature.Attributes.HitPoints > 0)
     {
         // Use the skill
         attackingCharacter.UseSkill(GetSkillToUse(attackingCharacter), targetCreature.CreatureName, true);
     }
     else // Report that the target can not be found
     {
         attackingCharacter.sendMessageToPlayer(ResponseFormatterFactory.Get().General($"{targetCreature.CreatureName} can not be found"));
     }
 }
예제 #17
0
 /// <summary>
 /// Attack an item
 /// </summary>
 /// <param name="attackingCharacter">The attacking character</param>
 /// <param name="targetItem">The target item</param>
 public static void Attack(SMCharacter attackingCharacter, SMItem targetItem)
 {
     // Check that the target has hitpoints
     if (targetItem.HitPoints > 0)
     {
         // Use the skill
         attackingCharacter.UseSkill(GetSkillToUse(attackingCharacter), targetItem.ItemName, true);
     }
     else             // Report that the target can not be found
     {
         attackingCharacter.sendMessageToPlayer(targetItem.ItemName + " can not be found");
     }
 }
예제 #18
0
        /// <summary>
        /// Gets a character object, and loads it into memory.
        /// </summary>
        /// <param name="userID">userID is based on the id from the slack channel</param>
        /// <param name="newCharacter">newCharacter to change the output of the text based on whether the character is new or not</param>
        /// <returns>String message for usage</returns>
        public string GetCharacterOLD(string userID, bool newCharacter = false)
        {
            List <SMCharacter> smcs      = (List <SMCharacter>)HttpContext.Current.Application["SMCharacters"];
            SMCharacter        character = smcs.FirstOrDefault(smc => smc.UserID == userID);

            if ((character != null) && (!newCharacter))
            {
                return("You're already logged in!");
            }
            else
            {
                string path = FilePathSystem.GetFilePath("Characters", "Char" + userID);

                if (File.Exists(path))
                {
                    SMCharacter smc = new SMCharacter();

                    using (StreamReader r = new StreamReader(path))
                    {
                        string json = r.ReadToEnd();
                        smc = JsonConvert.DeserializeObject <SMCharacter>(json);
                    }

                    SMRoom room = smc.GetRoom();
                    if (room != null)
                    {
                        //TODO room.Announce() someone has entered the room or new player ect...
                    }

                    smcs.Add(smc);
                    HttpContext.Current.Application["SMCharacters"] = smcs;

                    if (!newCharacter)
                    {
                        return("Welcome back " + smc.FirstName);
                    }

                    string returnString = "Welcome to SlackMud!\n";
                    returnString += "We've created your character in the magical world of Arrelvia!";                     // TODO, use a welcome script!
                    // TODO, get room details

                    return(returnString);
                }
                else
                {
                    // If the UserID doesn't have a character already, inform them that they need to create one.
                    return("You do not have a character yet, you need to create one...");
                }
            }
        }
예제 #19
0
        private void ProcessConversation(NPCResponseStep NPCRS, SMCharacter invokingCharacter)
        {
            // First get the conversation
            string[] rsd = NPCRS.ResponseStepData.Split('.');

            // Get the conversation
            NPCConversations npcc = this.NPCConversationStructures.FirstOrDefault(constructure => constructure.ConversationID == rsd[0]);

            // Check we definitely found a structure to use
            if (npcc != null)
            {
                ProcessConversationStep(npcc, rsd[1], invokingCharacter);
            }
        }
예제 #20
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]");
                }
            }
        }
예제 #21
0
        /// <summary>
        /// Send a global message to all players - it is suppressed for the player sending the message.
        /// </summary>
        /// <param name="invokingCharacter">The character invoking the message</param>
        /// <param name="message">The message being sent</param>
        public void SendGlobalMessage(SMCharacter invokingCharacter, string message)
        {
            // Load the player list.
            List <SMCharacter> smcs = (List <SMCharacter>)HttpContext.Current.Application["SMCharacters"];

            // Look around the players...
            foreach (SMCharacter smc in smcs)
            {
                // ... if it isn't the character invoking the message send...
                if (smc != invokingCharacter)
                {
                    // ... send them the message.
                    smc.sendMessageToPlayer(message);
                }
            }
        }
예제 #22
0
        /// <summary>
        /// Get the faction level for character for a specific faction
        /// </summary>
        /// <param name="smc">The Character</param>
        /// <param name="factionName">The Faction Name</param>
        /// <returns></returns>
        public static int GetFactionAmount(SMCharacter smc, string factionName)
        {
            // Find the faction information from the player
            SMFaction smf = GetFactionFromPlayerList(smc, factionName);

            // Check if it's null..
            if (smf != null)
            {
                // .. if it's not return the level
                return(smf.Level);
            }
            else // there isn't a faction yet
            {
                // return 0
                return(0);
            }
        }
예제 #23
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;
                        }
                    }
                }
            }
        }
예제 #24
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();
                    }
                }
            }
        }
예제 #25
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.
            }
        }
예제 #26
0
        public void Announce(string msg, SMCharacter sender = null, bool suppressMessageToSender = false)
        {
            // Send the message to all people connected to the room
            foreach (SMCharacter smc in this.GetPeople())
            {
                bool sendMessage = true;

                if ((suppressMessageToSender) && (sender != null) && (sender.UserID == smc.UserID))
                {
                    sendMessage = false;
                }

                if (sendMessage)
                {
                    this.ChatSendMessage(smc, msg);
                }
            }
        }
예제 #27
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);
        }
예제 #28
0
        /// <summary>
        /// Internal Method to create a room decription, created as it's going to be used over and over...
        /// </summary>
        /// <param name="smr">An SMRoom</param>
        /// <returns>String including a full location string</returns>
        public string GetLocationInformation(SMCharacter smc)
        {
            // Construct the room string.
            string returnString = "";

            if (smc != null)
            {
                if ((!smc.NewbieTipsDisabled) && (this.RoomNewbieTips != null) && (this.RoomNewbieTips != ""))
                {
                    returnString += this.Formatter.GetNewLines(1);
                    returnString += this.Formatter.Bold("----- NEWBIE TIPS -----", 1);
                    returnString += this.Formatter.General(this.RoomNewbieTips, 1);
                    returnString += this.Formatter.Bold("-----     END     -----", 2);
                }
            }

            // Add the location details for the room
            string nameOfLocation = this.RoomID;

            if (nameOfLocation.Contains("||"))
            {
                nameOfLocation = nameOfLocation.Substring(0, nameOfLocation.IndexOf("||"));
            }
            returnString += this.Formatter.Bold($"Location Details - {nameOfLocation.Replace(".",", ")}:", 1);
            returnString += this.Formatter.Italic(this.RoomDescription, 2);

            // Add the people within the location
            returnString += this.GetPeopleDetails(smc);

            // Add the NPCs within the location
            returnString += this.GetNPCDetails();
            returnString += this.Formatter.GetNewLines(1);

            // Add the exits to the room so that someone can leave.
            returnString += this.GetExitDetails(smc);
            returnString += this.Formatter.GetNewLines(1);

            // Show all the items within the room that can be returned.
            returnString += this.GetItemDetails();

            // Return the string to the calling method.
            return(returnString);
        }
예제 #29
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);
            }
        }
예제 #30
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 room 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, "ProvinceMUD") == password);
                        }
                        if ((canLogin) && (password != null))
                        {
                            canLogin = (Crypto.DecryptStringAES(charInMem.Password, "ProvinceMUD") == password);
                        }

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