Exemplo n.º 1
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!"));
            }
        }
Exemplo n.º 2
0
        public static SMNPC GetNewNPC(string NPCType, bool unique = false)
        {
            SMNPC newNPC = new SMNPC();

            // ... if they're not, spawn them into the room.
            string newNPCPath = FilePathSystem.GetFilePath("NPCs", NPCType);

            // If that NPC Exits
            if (File.Exists(newNPCPath))
            {
                // Read the data in
                using (StreamReader r = new StreamReader(newNPCPath))
                {
                    // Read the data in
                    string json = r.ReadToEnd();

                    // Deserialise the JSON to an object and add it to the list of NPCS in memory
                    newNPC = JsonConvert.DeserializeObject <SMNPC>(json);

                    if (!unique)
                    {
                        newNPC.UserID = Guid.NewGuid().ToString();
                    }
                }
            }

            return(newNPC);
        }
Exemplo n.º 3
0
        public void Spawn()
        {
            if (this.NPCSpawns != null)
            {
                // Only one thing at a time can spawn at the moment.
                bool         spawnedThisRound = false;
                List <SMNPC> smnpcl           = new List <SMNPC>();

                // loop around the spawns
                foreach (SMSpawn sms in this.NPCSpawns)
                {
                    // random number between 1 and 100
                    int randomChance = (new Random().Next(1, 100));

                    if (!spawnedThisRound)
                    {
                        // Check if we should try spawning
                        if (randomChance < sms.SpawnFrequency)
                        {
                            // Check if it's a unique person
                            if (sms.Unique)
                            {
                                // Check if the unique NPC is already somewhere in the world...
                                smnpcl = (List <SMNPC>)HttpContext.Current.Application["SMNPCs"];
                                if (smnpcl.Count(npc => (npc.GetFullName().ToLower() == sms.TypeOfNPC.ToLower()) && (npc.RoomID.ToLower() != "isspawned")) == 0)
                                {
                                    // ... if they're not, spawn them into the room.
                                    SMNPC newNPC = NPCHelper.GetNewNPC(sms.TypeOfNPC, true);
                                    newNPC.RoomID = this.RoomID;
                                    smnpcl.Add(newNPC);
                                    HttpContext.Current.Application["SMNPCs"] = smnpcl;

                                    this.Announce(this.Formatter.Italic(newNPC.GetFullName() + " walks in"));
                                    spawnedThisRound = true;
                                }
                            }
                            else
                            {
                                // Check how many there are of this type in the room already
                                int numberOfNPCsOfType = this.GetNPCs().Count(npc => npc.NPCType == sms.TypeOfNPC);

                                // If there are less NPCs than the max number of the type...
                                if (numberOfNPCsOfType < sms.MaxNumber)
                                {
                                    // .. add one
                                    SMNPC newNPC = NPCHelper.GetNewNPC(sms.TypeOfNPC);
                                    newNPC.RoomID = this.RoomID;
                                    smnpcl        = (List <SMNPC>)HttpContext.Current.Application["SMNPCs"];
                                    smnpcl.Add(newNPC);
                                    HttpContext.Current.Application["SMNPCs"] = smnpcl;

                                    this.Announce(this.Formatter.Italic(newNPC.PronounSingular.ToUpper() + " " + newNPC.GetFullName() + " " + newNPC.WalkingType + "s in"));
                                }
                            }
                        }
                    }
                }
            }
        }
Exemplo n.º 4
0
        public static void StartAnNPCReactionCheck(SMNPC npc, string actionType, SMCharacter invokingCharacter, SMItem itemIn = null)
        {
            HttpContext ctx = HttpContext.Current;

            Thread npcReactionThread = new Thread(new ThreadStart(() =>
            {
                HttpContext.Current = ctx;
                npc.RespondToAction("PlayerCharacter.GivesItemToThem", invokingCharacter, itemIn);
            }));

            npcReactionThread.Start();
        }
Exemplo n.º 5
0
        /// <summary>
        /// Saves the character to application memory.
        /// </summary>
        public override void SaveToApplication()
        {
            List <SMNPC> smcs = (List <SMNPC>)HttpContext.Current.Application["SMNPCs"];

            SMNPC characterInMem = smcs.FirstOrDefault(smc => smc.UserID == this.UserID);

            if (characterInMem != null)
            {
                smcs.Remove(characterInMem);
            }

            smcs.Add(this);
            HttpContext.Current.Application["SMNPCs"] = smcs;
        }
Exemplo n.º 6
0
        /// <summary>
        /// Character "EMOTE" method
        /// </summary>
        /// <param name="emoting">What the character is "Emoting"</param>
        /// <param name="charSpeaking">The character who is emoting</param>
        public void ChatEmote(string speech, SMCharacter charSpeaking, SMNPC charNPCSpeak = null)
        {
            // Construct the message
            // Precursor items for generic NPCs
            string precursor = "";

            if ((charNPCSpeak != null) && (charNPCSpeak.IsGeneric))
            {
                precursor = charNPCSpeak.PronounSingular.ToUpper() + " ";
            }

            // Output the message
            string message = this.Formatter.Italic(precursor + charSpeaking.GetFullName() + " " + speech, 0);

            // Send the message to all people connected to the room
            foreach (SMCharacter smc in this.GetPeople())
            {
                this.ChatSendMessage(smc, message);
            }
        }
Exemplo n.º 7
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."));
        }
Exemplo n.º 8
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."));
        }