Esempio n. 1
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);
                }
            }
        }
Esempio n. 2
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!"));
            }
        }
Esempio n. 3
0
        /// <summary>
        /// Saves the room to application memory.
        /// </summary>
        public void SaveToApplication()
        {
            List <SMRoom> smrs = (List <SMRoom>)HttpContext.Current.Application["SMRooms"];

            SMRoom roomInMem = smrs.FirstOrDefault(smr => smr.RoomID == this.RoomID);

            if (roomInMem != null)
            {
                smrs.Remove(roomInMem);
            }

            smrs.Add(this);
            HttpContext.Current.Application["SMRooms"] = smrs;
        }
Esempio n. 4
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...");
                }
            }
        }
Esempio n. 5
0
        /// <summary>
        /// Gets a room and also loads the room to memory if it isn't already there.
        /// </summary>
        /// <param name="roomID">The id of the location you want to load</param>
        /// <returns>A room</returns>
        public SMRoom GetRoom(string roomID)
        {
            // Get the room file if it exists
            List <SMRoom> smrs      = (List <SMRoom>)HttpContext.Current.Application["SMRooms"];
            SMRoom        roomInMem = smrs.FirstOrDefault(smr => smr.RoomID == roomID);

            // If the room is not already in memory load the room
            if (roomInMem == null)
            {
                // Get the right path, and work out if the file exists.
                string path = FilePathSystem.GetFilePath("Locations", "Loc" + roomID);

                // Check if the character exists..
                if (File.Exists(path))
                {
                    // 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 the information from the the room information.
                        roomInMem = JsonConvert.DeserializeObject <SMRoom>(json);

                        // Check whether the room is instanced or not
                        if (roomInMem.Instanced)
                        {
                            // First change the name of the room.
                            roomInMem.RoomID = roomInMem.RoomID + "||" + Guid.NewGuid();
                        }

                        // Add the room to the application memory
                        smrs.Add(roomInMem);
                        HttpContext.Current.Application["SMRooms"] = smrs;

                        // Try to spawn some creatures into the room on first load
                        roomInMem.Spawn();
                    }
                }
            }

            return(roomInMem);
        }
Esempio n. 6
0
        public string GetLocationDetails(string roomID, SMCharacter smc)
        {
            // Variable for the return string
            string returnString = "";

            // Get the room from memory
            SMRoom smr = GetRoom(roomID);

            // Check if the character exists..
            if (smr == null)
            {
                // If they don't exist inform the person as to how to create a new user
                returnString = ResponseFormatterFactory.Get().Italic("Location does not exist?  Please report this as an error to [email protected]");
            }
            else
            {
                // Return the room description, exits, people and objects
                returnString = smr.GetLocationInformation(smc);
            }

            // Return the text output
            return(returnString);
        }
Esempio n. 7
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("");
                }
            }
        }
Esempio n. 8
0
        public void ItemSpawn()
        {
            if (this.ItemSpawns != null)
            {
                List <SMNPC> smnpcl = new List <SMNPC>();

                // loop around the spawns
                foreach (SMItemSpawn smis in this.ItemSpawns)
                {
                    // random number between 1 and 100
                    int randomChance = (new Random().Next(1, 100));

                    // Check if we should try spawning
                    if (randomChance < smis.SpawnFrequency)
                    {
                        // Check how many there are of this type in the room already
                        int numberOfItemsOfType = this.RoomItems.Count(item => item.ItemName == smis.ItemName);

                        // If there are less NPCs than the max number of the type...
                        if (numberOfItemsOfType < smis.MaxNumber)
                        {
                            // .. add one / some
                            int numberToSpawn = smis.MaxSpawnAtOnce;
                            if (numberOfItemsOfType + numberToSpawn > smis.MaxNumber)
                            {
                                numberToSpawn = smis.MaxNumber - numberOfItemsOfType;
                            }

                            // Split the file name
                            string[] typeOfItem         = smis.TypeOfItem.Split('.');
                            int      totalNumberSpawned = numberToSpawn;

                            // Create the items
                            while (numberToSpawn > 0)
                            {
                                numberToSpawn--;
                                SMItem newItem = SMItemFactory.Get(typeOfItem[0], typeOfItem[1]);
                                this.RoomItems.Add(newItem);
                            }

                            // Double check enough were spawned.
                            if (totalNumberSpawned > 0)
                            {
                                // Remove the room from memory then add it again
                                List <SMRoom> allRooms = (List <SMRoom>)HttpContext.Current.Application["SMRooms"];
                                SMRoom        findRoom = allRooms.FirstOrDefault(r => r.RoomID == this.RoomID);
                                allRooms.Remove(findRoom);
                                if (findRoom != null)
                                {
                                    findRoom.RoomItems = this.RoomItems;
                                }
                                allRooms.Add(findRoom);
                                HttpContext.Current.Application["SMRoom"] = allRooms;

                                // Announce the arrival of the items.
                                this.Announce(this.Formatter.Italic(smis.SpawnMessage, 0));
                            }
                        }
                    }
                }
            }
        }