Example #1
0
        /// <summary>
        /// Saves the character to application memory.
        /// </summary>
        public override SMItem ProduceCorpse()
        {
            // Create the corpse
            SMItem corpse = SMItemFactory.Get("Misc", "Corpse");

            corpse.ItemName = this.GetFullName() + " Corpse";

            // If it's an animal or some such, create the destroyed output elements.
            if (this.DestroyedOutput != null)
            {
                corpse.DestroyedOutput = this.DestroyedOutput;
            }

            // Previous item family type
            corpse.PreviousItemFamily = this.FamilyType;

            // Create the "held items" list ready for transferring items to the corpse.
            corpse.HeldItems = new List <SMItem>();

            if (this.Slots != null)
            {
                foreach (SMSlot sms in this.Slots)
                {
                    if (!sms.isEmpty())
                    {
                        corpse.HeldItems.Add(sms.EquippedItem);
                    }
                }
            }

            // TODO Add clothing / armour items to the held items list ready for looting.

            return(corpse);
        }
Example #2
0
        /// <summary>
        /// Gets a new instance of the items DestroyedOutput.
        /// </summary>
        /// <returns>New items list or null.</returns>
        public List <SMItem> GetDestroyedItems()
        {
            // Create the return list.
            List <SMItem> smil = new List <SMItem>();

            if (this.DestroyedOutput != null)
            {
                string[] splitDestroyedObjects = this.DestroyedOutput.Split('|');

                foreach (string destroyedObject in splitDestroyedObjects)
                {
                    // get "xxx.yyy.zzz" from "xxx.yyy.zzz,n"
                    string item = destroyedObject.Split(',')[0];

                    // get list of parts x, y, z from x.y.z
                    List <string> parts = item.Split('.').ToList();

                    // get and remove x from the list
                    string category = parts[0];
                    parts.RemoveAt(0);

                    // get y.z by joining the remaining elements
                    string name = string.Join(".", parts);

                    smil.Add(SMItemFactory.Get(category, name));
                }
            }

            return(smil);
        }
Example #3
0
        /// <summary>
        /// Gets a new instance of the items DestroyedOutput.
        /// </summary>
        /// <returns>New item or null.</returns>
        public SMItem GetDestroyedItem()
        {
            if (this.DestroyedOutput != null)
            {
                // get "xxx.yyy.zzz" from "xxx.yyy.zzz,n"
                string item = this.DestroyedOutput.Split(',')[0];

                // get list of parts x, y, z from x.y.z
                List <string> parts = item.Split('.').ToList();

                // get and remove x from the list
                string category = parts[0];
                parts.RemoveAt(0);

                // get y.z by joining the remaining elements
                string name = string.Join(".", parts);

                // Return a newly factoried item
                return(SMItemFactory.Get(category, name));
            }

            return(null);
        }
Example #4
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."));
            }
        }
Example #5
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);
                    }
                }
            }
        }
Example #6
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));
                            }
                        }
                    }
                }
            }
        }