示例#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
        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]");
                }
            }
        }
示例#3
0
        /// <summary>
        /// A new party creation
        /// </summary>
        /// <param name="invokingCharacter">The character creating the party.</param>
        public void CreateParty(SMCharacter invokingCharacter, bool suppressMessage = false)
        {
            if ((invokingCharacter.PartyReference == null) || (invokingCharacter.PartyReference.Status == "Invited"))
            {
                // Create a new id
                PartyID = Guid.NewGuid().ToString();

                // Add the invoking character to the party
                SMPartyMember smpm = new SMPartyMember();
                smpm.CharacterName = invokingCharacter.GetFullName();
                smpm.UserID        = invokingCharacter.UserID;
                PartyMembers       = new List <SMPartyMember>();
                PartyMembers.Add(smpm);

                // Add the party to the global memory
                List <SMParty> smp = (List <SMParty>)HttpContext.Current.Application["Parties"];
                smp.Add(this);

                // Save the party to the memory.
                HttpContext.Current.Application["Parties"] = smp;

                // Reference the new party against the character
                invokingCharacter.PartyReference = new SMPartyReference(this.PartyID, "Leader");

                if (!suppressMessage)
                {
                    invokingCharacter.sendMessageToPlayer("[i]Party created.[/i]");
                }

                // Save the player information to the application.
                invokingCharacter.SaveToApplication();
            }
            else // They are already in a party
            {
                if (!suppressMessage)
                {
                    invokingCharacter.sendMessageToPlayer("[i]Can not create a party as you're already in one.[/i]");
                }
            }
        }
示例#4
0
        public void MoveAllPartyMembersToLocation(string roomIDToMoveTo, string leavingMethod, string enteringMethod, bool processResponses = true)
        {
            // See if the person being invited exists in memory
            List <SMCharacter> characterList = (List <SMCharacter>)HttpContext.Current.Application["SMCharacters"];

            SMRoom smr = new SlackMud().GetRoom(roomIDToMoveTo);

            // Scroll through the party members
            foreach (SMPartyMember smpmToMove in this.PartyMembers)
            {
                // See if the person being invited exists in memory
                SMCharacter smc = characterList.FirstOrDefault(ch => ch.GetFullName() == smpmToMove.CharacterName);

                if (smc != null)
                {
                    // Move the player.
                    smc.ActualMove(smr, leavingMethod, enteringMethod, processResponses);

                    // Save the player move.
                    smc.SaveToApplication();
                }
            }
        }
示例#5
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);
                                    }
                                }
                            }
                        }
                    }
                }
            }
        }
示例#6
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);
                    }
                }
            }
        }
示例#7
0
        /// <summary>
        /// Invite someone to a party.
        /// </summary>
        /// <param name="invokingCharacter"></param>
        /// <param name="characterName"></param>
        /// <param name="suppressMessages"></param>
        public void InviteToParty(SMCharacter invokingCharacter, string characterName, bool suppressMessages = false)
        {
            // See if the person being invited exists in memory
            SMCharacter smc = ((List <SMCharacter>)HttpContext.Current.Application["SMCharacters"]).FirstOrDefault(ch => ch.GetFullName() == characterName);

            // check that the player exists...
            if (smc != null)
            {
                // Check that they're not already in a party
                if ((smc.PartyReference == null))
                {
                    // For use later
                    bool canJoinParty = true;

                    // Check the invoking player is in a party... and they're the leader
                    if (invokingCharacter.PartyReference != null)
                    {
                        if (invokingCharacter.PartyReference.Status != "Leader")
                        {
                            canJoinParty = false;
                            if (!suppressMessages)
                            {
                                invokingCharacter.sendMessageToPlayer("[i]You are not the party leader so can not invite someone[/i]");
                            }
                        }
                    }
                    else // The player inviting does't have a party yet..
                    {
                        // .. so lets create it.
                        new SMParty().CreateParty(invokingCharacter, true);
                    }

                    // If the player can join the party...
                    if (canJoinParty)
                    {
                        if (!suppressMessages)
                        {
                            // Send a message to the player being invited...
                            smc.sendMessageToPlayer("[i]You have been invited to a party by " + invokingCharacter.GetFullName() + " - to accept type \"AcceptInvite\"[/i]");
                        }

                        // Add the SMPartyReference to the character
                        smc.PartyReference = new SMPartyReference(invokingCharacter.PartyReference.PartyID, "Invited");

                        // Save the player information to the application.
                        smc.SaveToApplication();
                    }
                }
                else
                {
                    if (!suppressMessages)
                    {
                        invokingCharacter.sendMessageToPlayer("[i]Can not invite that character to a party as they are already in a party.[/i]");
                    }
                }
            }
            else
            {
                if (!suppressMessages)
                {
                    invokingCharacter.sendMessageToPlayer("[i]Can not find a character named + \"" + characterName + "\"[/i]");
                }
            }
        }
示例#8
0
        public void JoinParty(SMCharacter invokingCharacter, bool suppressMessages = false)
        {
            // Check the character has an open invite
            if ((invokingCharacter.PartyReference != null) && (invokingCharacter.PartyReference.Status == "Invited"))
            {
                // Find the party in 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 it exists...
                if (sp != null)
                {
                    // Remove the party from the global list for a mo..
                    smp.Remove(sp);

                    // ... add the character to the party.
                    SMPartyMember smpm = new SMPartyMember();
                    smpm.CharacterName = invokingCharacter.GetFullName();
                    smpm.UserID        = invokingCharacter.UserID;
                    sp.PartyMembers.Add(smpm);

                    // Add the party to the list again..
                    smp.Add(sp);

                    // .. and save the list out
                    HttpContext.Current.Application["Parties"] = smp;

                    // ... send a message to all the people in the party.
                    if (!suppressMessages)
                    {
                        sp.SendMessageToAllPartyMembers(sp, "[i]" + smpm.CharacterName + " joined the party[/i]");
                    }

                    // ... change the status of the party element on the character to "joined"
                    invokingCharacter.PartyReference.Status = "Joined";

                    // Save the player information to the application.
                    invokingCharacter.SaveToApplication();
                }
                else // .. the party no longer exists, so can't be joined
                {
                    // Tell the player
                    if (!suppressMessages)
                    {
                        invokingCharacter.sendMessageToPlayer("[i]That party no longer exists.[/i]");
                    }

                    // Remove the reference from their party invite list.
                    invokingCharacter.PartyReference = null;

                    // Save the player information to the application.
                    invokingCharacter.SaveToApplication();
                }
            }
            else // No party
            {
                if (!suppressMessages)
                {
                    invokingCharacter.sendMessageToPlayer("[i]You have no open party invites.[/i]");
                }
            }
        }