コード例 #1
0
ファイル: SlackMud.cs プロジェクト: PaulHutson/SlackMUDRPG
        public string GetFlushLocation()
        {
            string defaultRoomPath = FilePathSystem.GetFilePath("Scripts", "Flush-Location");

            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.
                    return(sl.StartLocation);
                }
            }

            return("1");
        }
コード例 #2
0
ファイル: SlackMud.cs プロジェクト: PaulHutson/SlackMUDRPG
        /// <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."));
            }
        }