Beispiel #1
0
        public void FindAllPartyMembers(SMCharacter invokingCharacter)
        {
            if (invokingCharacter.PartyReference != null)
            {
                SMParty sp = SMPartyHelper.GetParty(invokingCharacter.PartyReference.PartyID);

                string stringToSend = "[b]Party Members:[/b] ";
                bool   first        = true;

                foreach (SMPartyMember pm in sp.PartyMembers)
                {
                    if (first)
                    {
                        first = false;
                    }
                    else
                    {
                        stringToSend += ", ";
                    }
                    stringToSend += pm.CharacterName;
                }

                invokingCharacter.sendMessageToPlayer(stringToSend);
            }
            else // They're not in a party
            {
                invokingCharacter.sendMessageToPlayer("[i]You're not in a party.[/i]");
            }
        }
Beispiel #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!"));
            }
        }
Beispiel #3
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();
        }
Beispiel #4
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]");
                }
            }
        }
Beispiel #5
0
 /// <summary>
 /// Attack a Creature
 /// </summary>
 /// <param name="attackingCharacter">The attacking character</param>
 /// <param name="targetCharacter">The target character</param>
 public static void Attack(SMCharacter attackingCharacter, SMCreature targetCreature)
 {
     // Check that the target has hitpoints
     if (targetCreature.Attributes.HitPoints > 0)
     {
         // Use the skill
         attackingCharacter.UseSkill(GetSkillToUse(attackingCharacter), targetCreature.CreatureName, true);
     }
     else // Report that the target can not be found
     {
         attackingCharacter.sendMessageToPlayer(ResponseFormatterFactory.Get().General($"{targetCreature.CreatureName} can not be found"));
     }
 }
Beispiel #6
0
        public bool BuyItem(string itemNumber, int numberToBuy, SMCharacter smc)
        {
            // Check that there is an item with that number
            SMShopItem ssi = ShopInventory.FirstOrDefault(item => item.ItemNumber == int.Parse(itemNumber));

            // If the item isn't null continue
            if (ssi != null)
            {
                // check the player has enough money to pay for the item(s)
                // Get the total value
                int totalValue = numberToBuy * ssi.Cost;

                if (smc.Currency.CheckCurrency(totalValue))
                {
                    // remove the money from the character
                    smc.Currency.RemoveCurrency(totalValue);

                    // add the item to the character
                    while (numberToBuy > 0)
                    {
                        numberToBuy--;
                        smc.ReceiveItem(ssi.Item, true);
                    }

                    // Return that the item was bought.
                    return(true);
                }
                else // They don't have enough to buy the item
                {
                    smc.sendMessageToPlayer(this.Formatter.Italic("You don't have enough money for that (needed " + totalValue + ", you have " + smc.Currency.AmountOfCurrency + ")"));
                    return(false);
                }
            }
            else // Return that the item isn't valid...
            {
                smc.sendMessageToPlayer(this.Formatter.ListItem("The item you've specified isn't valid, please check and try again"));
                return(false);
            }
        }
Beispiel #7
0
 /// <summary>
 /// Attack an item
 /// </summary>
 /// <param name="attackingCharacter">The attacking character</param>
 /// <param name="targetItem">The target item</param>
 public static void Attack(SMCharacter attackingCharacter, SMItem targetItem)
 {
     // Check that the target has hitpoints
     if (targetItem.HitPoints > 0)
     {
         // Use the skill
         attackingCharacter.UseSkill(GetSkillToUse(attackingCharacter), targetItem.ItemName, true);
     }
     else             // Report that the target can not be found
     {
         attackingCharacter.sendMessageToPlayer(targetItem.ItemName + " can not be found");
     }
 }
Beispiel #8
0
        /// <summary>
        /// Recover a given number of HP up to the maxhp attribute.
        /// </summary>
        /// <param name="Amount">The integer amount of HP to recover.</param>
        /// <param name="invokingCharacter">The character invoking the HP recovery.</param>
        public void RecoverHp(Int32 Amount, SMCharacter invokingCharacter)
        {
            // Workout how many HP the character is from its max
            Int32 missingHp = this.MaxHitPoints - this.HitPoints;

            // Do nothing if HP already at its max
            if (missingHp == 0)
            {
                invokingCharacter.sendMessageToPlayer(ResponseFormatterFactory.Get().Italic($"Your hit points are already full!"));
                return;
            }

            // Workout how many hp to recover to ensure we dont go over the characters max HP
            Int32 hpToGain = missingHp < Amount ? missingHp : Amount;

            // Recover the HP
            this.HitPoints += hpToGain;

            // Inform the player how many HP they recovered
            invokingCharacter.sendMessageToPlayer(ResponseFormatterFactory.Get().Italic($"You feel better \"{hpToGain}hp\" recovered."));

            return;
        }
Beispiel #9
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]");
                }
            }
        }
Beispiel #10
0
        public void AddResponse(NPCConversations npcc, NPCConversationStep npccs, SMCharacter invokingCharacter, List <ShortcutToken> stl, string responseOptions)
        {
            // Set up a list to hold them in the character (if there isn't one already)
            if (this.AwaitingCharacterResponses == null)
            {
                this.AwaitingCharacterResponses = new List <SMNPCAwaitingCharacterResponse>();
            }

            // Create the awaiting response token.
            SMNPCAwaitingCharacterResponse acr = new SMNPCAwaitingCharacterResponse();

            acr.ConversationID      = npcc.ConversationID;
            acr.ConversationStep    = npccs.StepID;
            acr.WaitingForCharacter = invokingCharacter;
            acr.RoomID = this.RoomID;

            // Work out the timeout conversation if there is one.
            string nextStepAfterTimeout = null;
            int    timeout = 10000;

            if (npccs.NextStep != null)
            {
                string[] getNextStep = npccs.NextStep.Split('.');
                nextStepAfterTimeout = getNextStep[0];
                timeout = int.Parse(getNextStep[1]);
            }

            // Set the conversation timeout
            acr.ConversationStepAfterTimeout = nextStepAfterTimeout;
            acr.UnixTimeStampTimeout         = Utility.Utils.GetUnixTimeOffset(timeout);

            // Add the item to the character, and send a message to the player regarding the available responses.
            this.AwaitingCharacterResponses.Add(acr);
            invokingCharacter.SetAwaitingResponse(this.UserID, stl, timeout, this.RoomID);

            if ((responseOptions != null) && (!responseOptions.Contains("{variable}")))
            {
                invokingCharacter.sendMessageToPlayer(responseOptions);
            }
        }
Beispiel #11
0
        public static string GetSkillToUse(SMCharacter attackingCharacter)
        {
            string skillToUse = "Brawl";

            if (!attackingCharacter.AreHandsEmpty())
            {
                // Get the equipped item from the character if any
                SMItem smi = attackingCharacter.GetEquippedItem();
                skillToUse = "Basic Attack";

                if ((smi != null) && (smi.RequiredSkills != null))
                {
                    // Check the player has the required skills
                    bool hasAllRequiredSkills = true;
                    bool isFirst = true;

                    foreach (SMRequiredSkill smrs in smi.RequiredSkills)
                    {
                        if (hasAllRequiredSkills)
                        {
                            hasAllRequiredSkills = attackingCharacter.HasRequiredSkill(smrs.SkillName, smrs.SkillLevel);
                            if (isFirst)
                            {
                                skillToUse = smrs.SkillName;
                            }
                        }
                    }

                    // If the player has all the required skills
                    if (!hasAllRequiredSkills)
                    {
                        // Tell the player they can't really wield that item.
                        attackingCharacter.sendMessageToPlayer(ResponseFormatterFactory.Get().General($"You are not skilled with the {smi.ItemFamily}, practicing gives you a chance to increase your skill"));
                    }
                }
            }
            return(skillToUse);
        }
Beispiel #12
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("");
                }
            }
        }
Beispiel #13
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);
                    }
                }
            }
        }
Beispiel #14
0
 public void ChatSendMessage(SMCharacter smc, string msg)
 {
     smc.sendMessageToPlayer(msg);
 }
Beispiel #15
0
        /// <summary>
        /// Inspect a person, object, etc.
        /// </summary>
        /// <param name="smc">The character doing the inspecting</param>
        /// <param name="thingToInspect">The thing that the person wants to inspect</param>
        public void InspectThing(SMCharacter smc, string thingToInspect)
        {
            // Check if it's a character first
            SMCharacter targetCharacter = this.GetPeople().FirstOrDefault(checkChar => (checkChar.GetFullName().ToLower() == thingToInspect.ToLower()) || (checkChar.FirstName.ToLower() == thingToInspect.ToLower()) || (checkChar.LastName.ToLower() == thingToInspect.ToLower()));

            if (targetCharacter != null)
            {
                string levelText = "";
                if (int.Parse(targetCharacter.CalculateLevel()) > 0)
                {
                    levelText = " (Level " + targetCharacter.CalculateLevel() + ")";
                }

                smc.sendMessageToPlayer(this.Formatter.Bold("Description of " + targetCharacter.GetFullName() + levelText + ":"));
                if ((targetCharacter.Description != null) && (targetCharacter.Description != ""))
                {
                    smc.sendMessageToPlayer(this.Formatter.Italic(targetCharacter.Description));
                }
                else
                {
                    smc.sendMessageToPlayer(this.Formatter.Italic("No description set..."));
                }

                List <string> inventory       = targetCharacter.GetInventoryList();
                string        inventoryOutput = String.Empty;

                if (inventory.Any())
                {
                    foreach (string item in inventory)
                    {
                        inventoryOutput += this.Formatter.ListItem(item);
                    }

                    inventoryOutput += this.Formatter.GetNewLines(1);
                }

                smc.sendMessageToPlayer(inventoryOutput);

                targetCharacter.sendMessageToPlayer(this.Formatter.Italic(smc.GetFullName() + " looks at you"));
                return;
            }

            // If not a character, check if it is an NPC...
            SMNPC targetNPC = this.GetNPCs().FirstOrDefault(checkChar => (checkChar.GetFullName().ToLower() == thingToInspect.ToLower()) || (checkChar.NPCType.ToLower() == thingToInspect.ToLower()));

            if (targetNPC != null)
            {
                string levelText = "";
                if (int.Parse(targetNPC.CalculateLevel()) > 0)
                {
                    levelText = " (Level " + targetNPC.CalculateLevel() + ")";
                }

                smc.sendMessageToPlayer(this.Formatter.Bold("Description of " + targetNPC.GetFullName() + levelText + ":"));
                if ((targetNPC.Description != null) && (targetNPC.Description != ""))
                {
                    smc.sendMessageToPlayer(this.Formatter.Italic(targetNPC.Description));
                }
                else
                {
                    smc.sendMessageToPlayer(this.Formatter.Italic("No description set..."));
                }

                List <string> inventory       = targetNPC.GetInventoryList();
                string        inventoryOutput = String.Empty;

                if (inventory.Any())
                {
                    foreach (string item in inventory)
                    {
                        inventoryOutput += this.Formatter.ListItem(item);
                    }

                    inventoryOutput += this.Formatter.GetNewLines(1);
                }

                smc.sendMessageToPlayer(inventoryOutput);

                targetNPC.GetRoom().ProcessNPCReactions("PlayerCharacter.ExaminesThem", smc, targetNPC.UserID);
                targetNPC.GetRoom().ProcessNPCReactions("PlayerCharacter.Examines", smc);
                return;
            }

            // If not an NPC, check the players equipped items and the items in the room...
            SMItem smi = smc.GetEquippedItem(thingToInspect);

            if (smi == null)
            {
                smi = SMItemHelper.GetItemFromList(this.RoomItems, thingToInspect);
            }

            if (smi != null)
            {
                string itemDeatils = this.Formatter.Bold("Description of \"" + smi.ItemName + "\":", 1);
                itemDeatils += this.Formatter.General(smi.ItemDescription, 1);

                if (smi.CanHoldOtherItems())
                {
                    itemDeatils += this.Formatter.Italic($"This \"{smi.ItemName}\" contains the following items:", 1);
                    itemDeatils += SMItemHelper.GetContainerContents(smi);
                }

                if (smi.Effects != null)
                {
                    smi.InitiateEffects(smc);
                }

                smc.sendMessageToPlayer(itemDeatils);
                return;
            }

            // Otherwise nothing found
            smc.sendMessageToPlayer(this.Formatter.Italic("Can not inspect that item."));
        }
Beispiel #16
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]");
                }
            }
        }
Beispiel #17
0
        /// <summary>
        /// Inspect a person, object, etc.
        /// </summary>
        /// <param name="smc">The character doing the inspecting</param>
        /// <param name="thingToInspect">The thing that the person wants to inspect</param>
        public void InspectThing(SMCharacter smc, string thingToInspect)
        {
            // Check if it's a character first
            SMCharacter targetCharacter = this.GetPeople().FirstOrDefault(checkChar => checkChar.GetFullName().ToLower() == thingToInspect.ToLower());

            if (targetCharacter != null)
            {
                smc.sendMessageToPlayer(OutputFormatterFactory.Get().Bold("Description of " + targetCharacter.GetFullName() + " (Level " + targetCharacter.CalculateLevel() + "):"));
                if ((targetCharacter.Description != null) || (targetCharacter.Description != ""))
                {
                    smc.sendMessageToPlayer(OutputFormatterFactory.Get().Italic(targetCharacter.Description));
                }
                else
                {
                    smc.sendMessageToPlayer(OutputFormatterFactory.Get().Italic("No description set..."));
                }
                smc.sendMessageToPlayer(OutputFormatterFactory.Get().CodeBlock(targetCharacter.GetInventoryList()));
                targetCharacter.sendMessageToPlayer(OutputFormatterFactory.Get().Italic(smc.GetFullName() + " looks at you"));
                return;
            }

            // If not a character, check if it is an NPC...
            SMNPC targetNPC = this.GetNPCs().FirstOrDefault(checkChar => checkChar.GetFullName().ToLower() == thingToInspect.ToLower());

            if (targetNPC != null)
            {
                smc.sendMessageToPlayer(OutputFormatterFactory.Get().Bold("Description of " + targetNPC.GetFullName() + " (Level " + targetNPC.CalculateLevel() + "):"));
                if ((targetNPC.Description != null) || (targetNPC.Description != ""))
                {
                    smc.sendMessageToPlayer(OutputFormatterFactory.Get().Italic(targetNPC.Description));
                }
                else
                {
                    smc.sendMessageToPlayer(OutputFormatterFactory.Get().Italic("No description set..."));
                }
                smc.sendMessageToPlayer(OutputFormatterFactory.Get().CodeBlock(targetNPC.GetInventoryList()));
                targetNPC.GetRoom().ProcessNPCReactions("PlayerCharacter.ExaminesThem", smc, targetNPC.UserID);
                targetNPC.GetRoom().ProcessNPCReactions("PlayerCharacter.Examines", smc);
                return;
            }

            // If not an NPC, check the players equipped items and the items in the room...
            SMItem smi = smc.GetEquippedItem(thingToInspect);

            if (smi == null)
            {
                smi = SMItemHelper.GetItemFromList(this.RoomItems, thingToInspect);
            }

            if (smi != null)
            {
                string itemDeatils = OutputFormatterFactory.Get().Bold("Description of \"" + smi.ItemName + "\":");
                itemDeatils += OutputFormatterFactory.Get().ListItem(smi.ItemDescription);

                if (smi.CanHoldOtherItems())
                {
                    itemDeatils += OutputFormatterFactory.Get().Italic($"This \"{smi.ItemName}\" contains the following items:");
                    itemDeatils += SMItemHelper.GetContainerContents(smi);
                }

                smc.sendMessageToPlayer(itemDeatils);
                return;
            }

            // Otherwise nothing found
            smc.sendMessageToPlayer(OutputFormatterFactory.Get().Italic("Can not inspect that item."));
        }
Beispiel #18
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]");
                }
            }
        }