예제 #1
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();
        }
예제 #2
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."));
            }
        }
예제 #3
0
        public void ProcessCharacterResponse(string responseShortCut, SMCharacter invokingCharacter)
        {
            // Get the current unix time
            int currentUnixTime = Utility.Utils.GetUnixTime();

            // Double check we're not going to get a null exception
            if (this.AwaitingCharacterResponses != null)
            {
                // Delete all responses over that time
                // this.AwaitingCharacterResponses.RemoveAll(awaitingitems => awaitingitems.UnixTimeStampTimeout < currentUnixTime);

                if (this.AwaitingCharacterResponses.Count > 0)
                {
                    // Get the Character Response.
                    SMNPCAwaitingCharacterResponse acr = this.AwaitingCharacterResponses.FirstOrDefault(rw => rw.WaitingForCharacter.UserID == invokingCharacter.UserID);

                    // Make sure we've returned something
                    if (acr != null)
                    {
                        // Load the conversation
                        NPCConversations npcc = this.NPCConversationStructures.FirstOrDefault(nc => nc.ConversationID == acr.ConversationID);
                        if (npcc != null)
                        {
                            // Get the relevant part of the conversation to go to
                            NPCConversationStep currentStep = npcc.ConversationSteps.FirstOrDefault(step => step.StepID == acr.ConversationStep);

                            if ((currentStep != null) && (currentStep.ResponseOptions != null))
                            {
                                NPCConversationStepResponseOptions nextstep = currentStep.ResponseOptions.FirstOrDefault(ro => ro.ResponseOptionShortcut.ToLower() == responseShortCut.ToLower());

                                // TODO - Update this location with the character variable info.

                                if (nextstep == null)
                                {
                                    nextstep = currentStep.ResponseOptions.FirstOrDefault(ro => ro.ResponseOptionShortcut.ToLower() == "{variable}");
                                    invokingCharacter.VariableResponse = responseShortCut;
                                }

                                if (nextstep != null)
                                {
                                    NPCResponseOptionAction nroa = nextstep.ResponseOptionActionSteps.FirstOrDefault();

                                    if (nroa != null)
                                    {
                                        // Get the conversation / step to go to.
                                        string[] convostep = nroa.AdditionalData.Split('.');

                                        // check whether the conversation is the same as the original if not get the new one
                                        if (convostep[0] != npcc.ConversationID)
                                        {
                                            npcc = this.NPCConversationStructures.FirstOrDefault(nc => nc.ConversationID == convostep[0]);
                                        }

                                        // Remove the item from the awaiting items.
                                        AwaitingCharacterResponses.Remove(acr);

                                        // Remove it from the character too, it's processed now so we don't need it any more!
                                        invokingCharacter.NPCsWaitingForResponses.RemoveAll(ar => ar.NPCID == this.UserID);
                                        invokingCharacter.SaveToApplication();
                                        invokingCharacter.SaveToFile();

                                        // process it
                                        ProcessConversationStep(npcc, convostep[1], invokingCharacter);
                                    }
                                }
                            }
                        }
                    }
                }
            }
        }
예제 #4
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);
                    }
                }
            }
        }