Пример #1
0
        //called from the MOVE command
        private static void ApplyRoomModifier(User.User player)
        {
            StringBuilder sb = new StringBuilder();

            //Todo:  Check the player bonuses to see if they are immune or have resistance to the modifier
            foreach (Dictionary <string, string> modifier in Rooms.Room.GetModifierEffects(player.Player.Location))
            {
                player.Player.ApplyEffectOnAttribute("Hitpoints", double.Parse(modifier["Value"]));

                double positiveValue = double.Parse(modifier["Value"]);
                if (positiveValue < 0)
                {
                    positiveValue *= -1;
                }

                sb.Append(String.Format(modifier["DescriptionSelf"], positiveValue));
                if (!player.Player.IsNPC)
                {
                    player.MessageHandler("\r" + sb.ToString());
                }
                sb.Clear();
                sb.Append(String.Format(modifier["DescriptionOthers"], player.Player.FirstName,
                                        player.Player.Gender.ToString() == "Male" ? "he" : "she", positiveValue));

                Room.GetRoom(player.Player.Location).InformPlayersInRoom("\r" + sb.ToString(), new List <string>(new string[] { player.UserID }));
            }
        }
Пример #2
0
        private static void DisplayTime(User.User player, List <string> commands)
        {
            //full, short or whatever combination we feel like allowing the player to grab
            BsonDocument time    = Calendar.Calendar.GetTime();
            string       message = "";

            if (commands.Count < 3)
            {
                commands.Add("FULL");
            }                                                             //let's add in the "full" for time full

            string amPm = time["Hour"].AsInt32 > 12 ? "PM" : "AM";

            if (!player.HourFormat24)
            {
                int hour = time["Hour"].AsInt32 > 12 ? time["Hour"].AsInt32 - 12 : time["Hour"].AsInt32;
            }

            switch (commands[2].ToUpper())
            {
            case "SHORT":
                message = String.Format("\rCurrent Time: {0:D2}:{1:D2}:{2:D2} {3}.\n", time["Hour"].AsInt32, time["Minute"].AsInt32, time["Second"].AsInt32, amPm);
                break;

            case "FULL":
            default:
                message = String.Format("\rCurrent Time: {0}, {1:D2}:{2:D2}:{3:D2} {4}.\n", time["TimeOfDay"].AsString.CamelCaseWord(), time["Hour"].AsInt32, time["Minute"].AsInt32, time["Second"].AsInt32, amPm);
                break;
            }

            player.MessageHandler(message);
        }
Пример #3
0
        //TODO: this needs more work done and also need to figure out a nice way to display it to the user
        private static void DisplayStats(User.User player, List<string> commands)
        {
            Character.Character character = player.Player as Character.Character;
            if (character != null) {
                StringBuilder sb = new StringBuilder();
                sb.AppendLine("You are currently " + character.ActionState.ToString().ToUpper() + " and " + character.StanceState.ToString().ToUpper());
                sb.AppendLine("\nName: " + character.FirstName.CamelCaseWord() + " " + character.LastName.CamelCaseWord());
                sb.AppendLine("Level : " + character.Level);
                sb.AppendLine("Class: " + character.Class);
                sb.AppendLine("Race: " + character.Race);
                sb.AppendLine("XP: " + (long)character.Experience);
                sb.AppendLine("Next Level XP required: " + (long)character.NextLevelExperience + " (Needed: " + (long)(character.NextLevelExperience - character.Experience) + ")");
                sb.AppendLine("\n[Attributes]");
                foreach (KeyValuePair<string, Character.Attribute> attrib in player.Player.GetAttributes()) {
                    sb.AppendLine(string.Format("{0,-12}: {1}/{2,-3}    Rank: {3}",attrib.Key.CamelCaseWord(), attrib.Value.Value, attrib.Value.Max, attrib.Value.Rank));
                }

                sb.AppendLine("\n[Sub Attributes]");
                foreach (KeyValuePair<string, double> attrib in player.Player.GetSubAttributes()) {
                    sb.AppendLine(attrib.Key.CamelCaseWord() + ": \t" + attrib.Value);
                }

                sb.AppendLine("Description/Bio: " + player.Player.Description);
                player.MessageHandler(sb.ToString());
            }
        }
Пример #4
0
        //TODO: this needs more work done and also need to figure out a nice way to display it to the user
        private static void DisplayStats(User.User player, List <string> commands)
        {
            Character.Character character = player.Player as Character.Character;
            if (character != null)
            {
                StringBuilder sb = new StringBuilder();
                sb.AppendLine("You are currently " + character.ActionState.ToString().ToUpper() + " and " + character.StanceState.ToString().ToUpper());
                sb.AppendLine("\nName: " + character.FirstName.CamelCaseWord() + " " + character.LastName.CamelCaseWord());
                sb.AppendLine("Level : " + character.Level);
                sb.AppendLine("Class: " + character.Class);
                sb.AppendLine("Race: " + character.Race);
                sb.AppendLine("XP: " + (long)character.Experience);
                sb.AppendLine("Next Level XP required: " + (long)character.NextLevelExperience + " (Needed: " + (long)(character.NextLevelExperience - character.Experience) + ")");
                sb.AppendLine("\n[Attributes]");
                foreach (KeyValuePair <string, Character.Attribute> attrib in player.Player.GetAttributes())
                {
                    sb.AppendLine(string.Format("{0,-12}: {1}/{2,-3}    Rank: {3}", attrib.Key.CamelCaseWord(), attrib.Value.Value, attrib.Value.Max, attrib.Value.Rank));
                }

                sb.AppendLine("\n[Sub Attributes]");
                foreach (KeyValuePair <string, double> attrib in player.Player.GetSubAttributes())
                {
                    sb.AppendLine(attrib.Key.CamelCaseWord() + ": \t" + attrib.Value);
                }

                sb.AppendLine("Description/Bio: " + player.Player.Description);
                player.MessageHandler(sb.ToString());
            }
        }
Пример #5
0
        private static bool BreakDoor(User.User player, List <string> commands)
        {
            Door door = FindDoor(player.Player.Location, commands);

            if (door == null)
            {
                return(false);
            }

            if (door.Destroyed)
            {
                player.MessageHandler(GetMessage("Messages", "AlreadyBroken", MessageType.Self));
                return(true);
            }

            double        attack  = CalculateAttack(player, 0);
            double        defense = CalculateDefense(door);
            double        damage  = attack - defense;
            List <string> message = door.ApplyDamage(damage);

            door.UpdateDoorStatus();
            player.MessageHandler(message[0].FontColor(Utils.FontForeColor.RED));
            Rooms.Room.GetRoom(player.Player.Location).InformPlayersInRoom(String.Format(message[1], player.Player.FirstName), new List <string>(new string[] { player.UserID }));
            return(true);
        }
Пример #6
0
        public void Submit(User submittingUser)
        {
            Guard.ArgumentNotNull(() => submittingUser, submittingUser);

            if (IsSubmitted)
            {
                throw new InvalidOperationException("IsSubmitted status must be false to transition to true");
            }

            if (Errors != null &&
                Errors.Any(e => e.ErrorLevel == ErrorLevel.Error))
            {
                throw new InvalidOperationException("A member upload cannot be submitted when it contains errors");
            }

            IsSubmitted = true;
            SubmittedByUser = submittingUser;
            SubmittedDate = SystemTime.UtcNow;

            foreach (ProducerSubmission producerSubmission in ProducerSubmissions)
            {
                producerSubmission.RegisteredProducer.SetCurrentSubmission(producerSubmission);
            }

            RaiseEvent(new SchemeMemberSubmissionEvent(this));
        }
Пример #7
0
        /// <summary>
        /// Informs all parties of the outcome of the combat round.
        /// </summary>
        /// <param name="player"></param>
        /// <param name="enemy"></param>
        /// <param name="room"></param>
        /// <param name="damage"></param>
        /// <param name="defense"></param>
        /// <param name="attack"></param>
        private static void SendRoundOutcomeMessage(User.User player, User.User enemy, Room room, double damage, double defense, double attack)
        {
            //TODO: Get the message based weapon type/special weapon (blunt, blade, axe, pole, etc.)
            //Get the weapon type and append it to the "Hit" or "Miss" type when getting the message
            //ex: HitSword, HitClub, MissAxe, MissUnarmed could even get really specific HitRustyShortSword, MissLegendaryDaggerOfBlindness
            //Make a method to figure out the type by having a lookup table in the DB that points to a weapon type string
            if (damage < 0)
            {
                player.MessageHandler(ParseMessage(GetMessage("Combat", "Hit", MessageType.Self), player, enemy, damage, defense, attack));
                enemy.MessageHandler(ParseMessage(GetMessage("Combat", "Hit", MessageType.Target), player, enemy, damage, defense, attack));
                string roomMessage = ParseMessage(GetMessage("Combat", "Hit", MessageType.Room), player, enemy, damage, defense, attack);

                room.InformPlayersInRoom(roomMessage, new List <string>(new string[] { player.UserID, enemy.UserID }));
                enemy.Player.ApplyEffectOnAttribute("Hitpoints", damage);

                Character.NPC npc = enemy.Player as Character.NPC;
                if (npc != null)
                {
                    npc.IncreaseXPReward(player.UserID, (damage * -1.0));
                }
            }
            else
            {
                player.MessageHandler(ParseMessage(GetMessage("Combat", "Miss", MessageType.Self), player, enemy, damage, defense, attack));
                enemy.MessageHandler(ParseMessage(GetMessage("Combat", "Miss", MessageType.Target), player, enemy, damage, defense, attack));
                string roomMessage = ParseMessage(GetMessage("Combat", "Miss", MessageType.Room), player, enemy, damage, defense, attack);
                room.InformPlayersInRoom(roomMessage, new List <string>(new string[] { player.UserID, enemy.UserID }));
            }
        }
Пример #8
0
        private static void Break(User.User player, List <string> commands)
        {
            string objectName = "";

            for (int i = commands.Count - 1; i > 0; i--)             //this should keep the words in the order we want
            {
                objectName += commands[i];
            }
            bool brokeIt = false;

            //let's see if it a door we want to break down first
            if (BreakDoor(player, commands))
            {
                brokeIt = true;
            }
            else if (BreakObject(player, objectName))
            {
                brokeIt = true;
            }

            if (!brokeIt)
            {
                //TODO: add this to the message collection in the DB
                player.MessageHandler(GetMessage("Messages", "NothingToBreak", MessageType.Self));
            }
        }
Пример #9
0
 //this is where attacks dones from scripts will call into
 //this can just set the round timer and apply the damages
 private static void SpecialAttack(User.User player)
 {
     if (!CheckIfCanAttack(player.Player.LastCombatTime))
     {
         return;
     }
 }
Пример #10
0
        static public void ExecuteCommand(Character.Iactor actor, string command, string message = null)
        {
            User.User player = new User.User(true);
            player.UserID = actor.ID;
            player.Player = actor;
            bool commandFound = false;

            if (CombatCommands.ContainsKey(command.ToUpper()))    //check to see if player provided a combat related command
            {
                CombatCommands[command.ToUpper()](player, new List <string>(new string[] { command, message }));
                commandFound = true;
            }

            if (!commandFound)
            {
                foreach (Dictionary <string, CommandDelegate> AvailableCommands in CommandsList)
                {
                    if (AvailableCommands.ContainsKey(command.ToUpper()))
                    {
                        AvailableCommands[command.ToUpper()](player, new List <string>(new string[] { command + " " + message, command, message }));
                        break;
                    }
                }
            }
        }
Пример #11
0
        private static void DisplayTime(User.User player, List<string> commands)
        {
            //full, short or whatever combination we feel like allowing the player to grab
            BsonDocument time = Calendar.Calendar.GetTime();
            string message = "";
            if (commands.Count < 3) { commands.Add("FULL"); } //let's add in the "full" for time full

            string amPm = time["Hour"].AsInt32 > 12 ? "PM" : "AM";

            if (!player.HourFormat24) {
                int hour = time["Hour"].AsInt32 > 12 ? time["Hour"].AsInt32 - 12 : time["Hour"].AsInt32;
            }

            switch (commands[2].ToUpper()) {
                case "SHORT":
                    message = String.Format("\rCurrent Time: {0:D2}:{1:D2}:{2:D2} {3}.\n", time["Hour"].AsInt32, time["Minute"].AsInt32, time["Second"].AsInt32, amPm);
                    break;
                case "FULL":
                default:
                    message = String.Format("\rCurrent Time: {0}, {1:D2}:{2:D2}:{3:D2} {4}.\n", time["TimeOfDay"].AsString.CamelCaseWord(), time["Hour"].AsInt32, time["Minute"].AsInt32, time["Second"].AsInt32, amPm);
                    break;
            }

            player.MessageHandler(message);
        }
Пример #12
0
 private static double WeaponSkill(User.User player)
 {
     //TODO: This is the logic for the weapon skill portion just need to get the weapon skill tree set up
     //if (Math.Pow(WeaponSkill, 2)) > 0.5) return 0.5d;
     //else return Math.Pow(WeaponSkill, 2);
     return(0.25d);
 }
Пример #13
0
        public static async Task <User.User> RetrieveUser(string email)
        {
            var user = new User.User();

            try
            {
                var dynamoDbClient = DynamoDBClientCreator.CreateClient();

                var request = new ScanRequest
                {
                    TableName                 = TableNames.user,
                    FilterExpression          = "email = :email",
                    ExpressionAttributeValues = new Dictionary <string, AttributeValue>()
                    {
                        { ":email", new AttributeValue(email) }
                    }
                };

                var response = await dynamoDbClient.ScanAsync(request).ConfigureAwait(true);

                var userItm = response.Items[0];

                user = User.User.deserialiseAsUser(userItm);
            }
            catch (Exception e)
            {
                LambdaLogger.Log("Unable to retrieve codes: " + e.ToString());
            }

            return(user);
        }
Пример #14
0
        private static void PerformSkill(User.User user, List <string> commands)
        {
            Skill skill = new Skill();

            skill.FillSkill(user, commands);
            skill.ExecuteScript();
        }
Пример #15
0
        private static double WeaponDamage(User.User player, bool offhand = false)
        {
            double             result  = 0.0d;
            List <Items.Iitem> weapons = player.Player.Equipment.GetWieldedWeapons();

            if (weapons.Count > 0)
            {
                Items.Iweapon weapon;
                if (!offhand)
                {
                    weapon = (Items.Iweapon)weapons.Where(w => w.WornOn.ToString().CamelCaseWord() == player.Player.MainHand.CamelCaseWord()).SingleOrDefault();
                }
                else
                {
                    weapon = (Items.Iweapon)weapons.Where(w => w.WornOn.ToString().CamelCaseWord() != player.Player.MainHand.CamelCaseWord()).SingleOrDefault();
                }

                result = RandomNumber.GetRandomNumber().NextNumber((int)weapon.CurrentMinDamage, (int)weapon.CurrentMaxDamage + 1);
            }
            else
            {
                result = 0.0d;
            }

            return(result);
        }
Пример #16
0
        public static User.User FindTargetByName(string name, string location)
        {
            User.User enemy = null;
            foreach (User.User foe in MySockets.Server.GetAUserByFirstName(name))
            {
                if (foe.Player.Location == location)
                {
                    enemy = foe;
                    break;
                }
            }

            if (enemy == null)
            {
                //ok it's not a player lets look through the NPC list
                foreach (Character.NPC npc in Character.NPCUtils.GetAnNPCByName(name, location))
                {
                    User.User foe = new User.User(true);
                    foe.UserID = npc.ID;
                    foe.Player = npc;
                    enemy      = foe;
                    break;
                }
            }

            return(enemy);
        }
Пример #17
0
 private static bool BreakObject(User.User player, string objectName)
 {
     //TODO: finish this method now that we have objects in the game that can be destroyed
     //find item in the DB, check if destructible.
     //Calculate player attack and determine damage to item
     //return message.
     return(false);
 }
Пример #18
0
        private static double CalculateDamage(User.User player, User.User enemy, bool offHand, out double defense, out double attack)
        {
            defense = 0.0d;
            attack  = 0.0d;
            attack  = Math.Round(CalculateAttack(player, enemy.Player.Level, offHand), 2, MidpointRounding.AwayFromZero);
            defense = Math.Round(CalculateDefense(enemy), 2, MidpointRounding.AwayFromZero);

            return(Math.Round((attack + defense), 2, MidpointRounding.AwayFromZero));
        }
Пример #19
0
        private static void Lock(User.User player, List <string> commands)
        {
            Door door = FindDoor(player.Player.Location, commands);

            if (door != null)
            {
                LockDoor(player, door);
            }
            //ok not a door so then we'll check containers in the room
        }
Пример #20
0
        static public void ParseCommands(User.User player)
        {
            List <string> commands     = ParseCommandLine(player.InBufferPeek);
            bool          commandFound = false;

            foreach (Dictionary <string, CommandDelegate> AvailableCommands in CommandsList)
            {
                if (AvailableCommands.ContainsKey(commands[1].ToUpper()))
                {
                    AvailableCommands[commands[1].ToUpper()](player, commands);
                    commandFound = true;
                    break;
                }
            }

            //if all else fails auto-attack
            if (player.Player.InCombat && player.Player.CurrentTarget != null)
            {
                //auto attack! or we could remove this and let a player figure out on their own they're being attacked
                commands.Clear();
                commands.Add("KILL");
                commands.Add("target");
                commands.Insert(0, commands[0] + " " + commands[1]);
            }

            if (!commandFound && CombatCommands.ContainsKey(commands[1].ToUpper()))                //check to see if player provided a combat related command
            {
                CombatCommands[commands[1].ToUpper()](player, commands);
                commandFound = true;
                commands[0]  = player.InBuffer; //just removing the command from the queue now
                commands.Clear();
            }


            if (commands.Count == 0)
            {
                return;
            }

            //maybe this command shouldn't be a character method call...we'll see
            if (commands.Count >= 2 && commands[1].ToLower() == "save")
            {
                player.Player.Save();
                player.MessageHandler("Save succesful!\r\n");

                commandFound = true;
            }

            if (!commandFound && commands[0].Length > 0)
            {
                player.MessageHandler("I don't know what you're trying to do, but that's not going to happen.");
            }

            commands[0] = player.InBuffer;  //remove command from queue
        }
Пример #21
0
        private static User.User GetTarget(User.User player, List <string> commands)
        {
            User.User enemy = FindTarget(player, commands);

            if (!SendMessageIfTargetUnavailable(player, enemy))
            {
                return(null);
            }

            return(enemy);
        }
Пример #22
0
        private static void Inventory(User.User player, List <string> commands)
        {
            List <Items.Iitem> inventoryList = player.Player.Inventory.GetInventoryAsItemList();
            StringBuilder      sb            = new StringBuilder();

            Dictionary <string, int> grouping = new Dictionary <string, int>();

            //let's group repeat items for easier display this may be a candidate for a helper method
            foreach (Items.Iitem item in inventoryList)
            {
                Items.Icontainer container = item as Items.Icontainer;
                if (!grouping.ContainsKey(item.Name))
                {
                    if (!item.ItemType.ContainsKey(Items.ItemsType.CONTAINER))
                    {
                        grouping.Add(item.Name, 1);
                    }
                    else
                    {
                        grouping.Add(item.Name + " [" + (container.Opened ? "Opened" : "Closed") + "]", 1);
                        container = null;
                    }
                }
                else
                {
                    if (!item.ItemType.ContainsKey(Items.ItemsType.CONTAINER))
                    {
                        grouping[item.Name] += 1;
                    }
                    else
                    {
                        grouping[item.Name + " [" + (container.Opened ? "Opened" : "Closed") + "]"] += 1;
                        container = null;
                    }
                }
            }

            if (grouping.Count > 0)
            {
                sb.AppendLine("You are carrying:");
                foreach (KeyValuePair <string, int> pair in grouping)
                {
                    sb.AppendLine(pair.Key.CamelCaseString() + (pair.Value > 1 ? "[" + pair.Value + "]" : ""));
                }
                sb.AppendLine("\n\r");
            }
            else
            {
                sb.AppendLine("\n\r[ EMPTY ]\n\r");
            }

            player.MessageHandler(sb.ToString());
        }
Пример #23
0
        private static void DeActivate(User.User player, List <string> commands)
        {
            //used for turning off a lightSource that can be lit.
            Items.Iiluminate lightItem = null;

            //just making the command be display friendly for the messages
            string command = null;

            switch (commands[1])
            {
            case "TURNOFF": command = "turn off";
                break;

            case "SWITCHOFF": command = "switch off";
                break;

            default: command = commands[1];
                break;
            }

            commands.RemoveRange(0, 2);

            List <string> message = new List <string>();
            Room          room    = Room.GetRoom(player.Player.Location);

            lightItem = FindLightInEquipment(commands, player, room);

            if (lightItem != null)
            {
                if (lightItem.isLit)
                {
                    message = lightItem.Extinguish();
                    if (message.Count > 1)
                    {
                        message[1] = string.Format(message[1], player.Player.FirstName);
                    }
                }
                else
                {
                    message.Add("It's already off!");
                }
            }
            else
            {
                message.Add("You don't see anything to " + command + ".");
            }

            player.MessageHandler(message[0]);
            if (message.Count > 1)
            {
                room.InformPlayersInRoom(message[1], new List <string>(new string[] { player.UserID }));
            }
        }
Пример #24
0
        public static User.User GetAUserByFullName(string name)
        {
            if (string.IsNullOrEmpty(name))
            {
                return(null);
            }
            Dictionary <Socket, User.User> tempList = new Dictionary <Socket, User.User>(clientSocketList);

            User.User userFound = tempList.Where(c => c.Value.Player.FullName.ToLower() == name.ToLower()).FirstOrDefault().Value;

            return(userFound);
        }
Пример #25
0
        private static void WeaponHandAttack(User.User player, User.User enemy, bool offHand = false)
        {
            //Calculate the total damage
            double defense = 0.0d;
            double attack  = 0.0d;
            double damage  = CalculateDamage(player, enemy, offHand, out defense, out attack);
            Room   room    = Room.GetRoom(player.Player.Location);

            SendRoundOutcomeMessage(player, enemy, room, damage, defense, attack);

            UpdatePlayerState(player, enemy);
        }
Пример #26
0
        public UserForm(User user)
        {
            InitializeComponent();

            rBPermanentFailure.Checked = true;
            buttonGetAverage.Enabled = false;
            buttonFailAdmin.Enabled = false;
            this.user = user;

            //this.receiveRegNodeThread = new Thread(this.user.UdpSockReceiverRegNode);
            //this.receiveRegNodeThread.Start();
        }
Пример #27
0
        public static void Drop(User.User player, List <string> commands)
        {
            //1.get the item name from the command, may have to join all the words after dropping the command
            StringBuilder itemName = new StringBuilder();
            Room          room     = Room.GetRoom(player.Player.Location);

            string full = commands[0];

            commands.RemoveAt(0);
            commands.RemoveAt(0);

            foreach (string word in commands)
            {
                itemName.Append(word + " ");
            }

            int itemPosition = 1;

            string[] position = commands[commands.Count - 1].Split('.'); //we are separating based on using the decimal operator after the name of the npc/item
            if (position.Count() > 1)
            {
                int.TryParse(position[position.Count() - 1], out itemPosition);
                itemName = itemName.Remove(itemName.Length - 2, 2);
            }

            //2.get the item from the DB
            List <Items.Iitem> items = Items.Items.GetByName(itemName.ToString().Trim(), player.UserID);

            Items.Iitem item = items[itemPosition - 1];

            //3.have player drop item
            string msgPlayer = null;

            if (item != null)
            {
                player.Player.Inventory.RemoveInventoryItem(item, player.Player.Equipment);
                item.Location = player.Player.Location;
                item.Owner    = item.Location.ToString();
                item.Save();

                //4.Inform room and player of action
                string msgOthers = string.Format("{0} drops {1}", player.Player.FirstName, item.Name);
                room.InformPlayersInRoom(msgOthers, new List <string>(new string[] { player.UserID }));
                msgPlayer = string.Format("You drop {0}", item.Name);
            }
            else
            {
                msgPlayer = "You are not carrying anything of the sorts.";
            }

            player.MessageHandler(msgPlayer);
        }
Пример #28
0
        static void Main()
        {
            Application.EnableVisualStyles();
            Application.SetCompatibleTextRenderingDefault(false);

            User user = new User();
            try {
                Application.Run(new UserForm(user));
            }
            catch (Exception ex) {
                string str = "sdg";
            }
        }
Пример #29
0
        //TODO: had a bug where I removed item form a container, shut down the game and then both container and player still had the same item (the player even had it duped)
        //needless to say this is bad and fail.
        public static void Get(User.User player, List <string> commands)
        {
            int    itemPosition      = 1;
            int    containerPosition = 1;
            string itemName          = "";
            string containerName     = "";

            List <string> commandAltered = ParseItemPositions(commands, "from", out itemPosition, out itemName);

            ParseContainerPosition(commandAltered, commands[3], out containerPosition, out containerName);

            string location = player.Player.Location;

            Items.Iitem retrievedItem = null;
            Items.Iitem containerItem = null;

            //using a recursive method we will dig down into each sub container and look for the appropriate item/container
            TraverseItems(player, containerName.ToString().Trim(), itemName.ToString().Trim(), containerPosition, itemPosition, out retrievedItem, out containerItem);

            string msg       = null;
            string msgOthers = null;

            if (retrievedItem != null)
            {
                Items.Icontainer container = containerItem as Items.Icontainer;
                if (containerItem != null)
                {
                    retrievedItem = container.RetrieveItem(retrievedItem.Id.ToString());
                    msg           = "You take " + retrievedItem.Name.ToLower() + " out of " + containerItem.Name.ToLower() + ".";

                    msgOthers = string.Format("{0} takes {1} out of {2}", player.Player.FirstName, retrievedItem.Name.ToLower(), containerItem.Name.ToLower());
                }
                else
                {
                    msg       = "You get " + retrievedItem.Name.ToLower();
                    msgOthers = string.Format("{0} grabs {1}.", player.Player.FirstName, retrievedItem.Name.ToLower());
                }

                retrievedItem.Location = null;
                retrievedItem.Owner    = player.UserID;
                retrievedItem.Save();
                player.Player.Inventory.AddItemToInventory(retrievedItem);
            }
            else
            {
                msg = "You can't seem to find " + itemName.ToString().Trim().ToLower() + " to grab it.";
            }

            Room.GetRoom(player.Player.Location).InformPlayersInRoom(msgOthers, new List <string>(new string[] { player.UserID }));
            player.MessageHandler(msg);
        }
Пример #30
0
        private static void OpenDoor(User.User player, Door door)
        {
            if (!player.Player.InCombat)
            {
                List <string> message = new List <string>();
                Room          room    = Room.GetRoom(player.Player.Location);
                if (!room.IsDark)
                {
                    if (door.Openable)
                    {
                        if (!door.Open && !door.Locked && !door.Destroyed)
                        {
                            door.Open = true;
                            door.UpdateDoorStatus();
                            message.Add(String.Format("You open {0} {1}.", GetArticle(door.Description[0]), door.Description));
                            message.Add(String.Format("{0} opens {1} {2}.", player.Player.FirstName, GetArticle(door.Description[0]), door.Description));
                        }
                        else if (door.Open && !door.Destroyed)
                        {
                            message.Add("It's already open.");
                        }
                        else if (door.Locked && !door.Destroyed)
                        {
                            message.Add("You can't open it because it is locked.");
                        }
                        else if (door.Destroyed)
                        {
                            message.Add("It's more than open it's in pieces!");
                        }
                    }
                    else
                    {
                        message.Add("It can't be opened.");
                    }
                }
                else
                {
                    message.Add("You can't see anything! Let alone what you are trying to open.");
                }

                player.MessageHandler(message[0]);
                if (message.Count > 1)
                {
                    room.InformPlayersInRoom(message[1], new List <string>(new string[] { player.UserID }));
                }
            }
            else
            {
                player.MessageHandler("You are in the middle of combat, there are more pressing matters at hand than opening something.");
            }
        }
Пример #31
0
        private static double PercentHit(User.User player, User.User enemy)
        {
            //TODO:
            //Calculate the attackers chance to succesfully perform a hit.
            //The defender then needs to calculate block.
            //So the damage a player can do is proportional to the chance of hitting he has, the higher chance of landing a full blow
            //the higher the damage will be.  The defender also does have a chance to dodge an attack which can cause damage to be zero (full dodge)
            //or be lowered some more (graze).  Dodging should happen rarely based on what level of dodge they have (Master may be only 25% chance to dodge)
            //obviously being a master dodger will require quite a bit of points dropped into dexterity and endurance.
            //Blocking lowers the damage amount, not the chance to hit.
            double chanceToHit = GetAndEvaluateExpression("HitChance", player.Player);

            return(chanceToHit);
        }
Пример #32
0
 private static void Emote(User.User player, List<string> commands)
 {
     string temp = "";
     if (commands[0].Trim().Length > 6) temp = commands[0].Substring(6).Trim();
     else {
         player.MessageHandler("You go to do something but what?.");
         return;
     }
     if (!player.Player.IsNPC) {
         player.MessageHandler(player.Player.FirstName + " " + temp + (temp.EndsWith(".") == false ? "." : ""));
     }
     Room room = Room.GetRoom(player.Player.Location);
     room.InformPlayersInRoom((room.IsDark == true ? "Someone" : player.Player.FirstName) + " " + temp + (temp.EndsWith(".") == false ? "." : ""), new List<string>(new string[] { player.UserID }));
 }
Пример #33
0
        private static void Close(User.User player, List <string> commands)
        {
            List <string> message = new List <string>();

            Door door = FindDoor(player.Player.Location, commands);

            if (door != null)
            {
                CloseDoor(player, door);
                return;
            }

            CloseContainer(player, commands);
        }
Пример #34
0
        private static void Who(User.User player, List <string> commands)
        {
            StringBuilder sb = new StringBuilder();

            sb.AppendLine("PlayerName");
            sb.AppendLine("----------");
            MySockets.Server.GetCurrentUserList()
            .Where(u => u.CurrentState == User.User.UserState.TALKING)
            .OrderBy(u => u.Player.FirstName)
            .ToList()
            .ForEach(u => sb.AppendLine(u.Player.FirstName + " " + u.Player.LastName));

            player.MessageHandler(sb.ToString());
        }
Пример #35
0
 public static void Drink(User.User player, List<string> commands)
 {
     Items.Iitem item = GetItem(commands, player.Player.Location.ToString());
     if (item == null) {
         player.MessageHandler("You don't seem to be carrying that to drink it.");
         return;
     }
     if (item.ItemType.ContainsKey(Items.ItemsType.DRINKABLE)) {
         Consume(player, commands, "drink", item);
     }
     else {
         player.MessageHandler("You can't drink that!");
     }
 }
Пример #36
0
        /// <summary>
        /// Informs everyone of the state change the player just went through as a result of combat, either killed or knocked out
        /// </summary>
        /// <param name="player"></param>
        /// <param name="enemy"></param>
        ///
        private static void SendDeadOrUnconciousMessage(User.User player, User.User enemy, bool dead = false)
        {
            player.Player.ClearTarget();
            string status = dead == true ? "Killed" : "KnockedUnconcious";

            player.MessageHandler(ParseMessage(GetMessage("Combat", status, MessageType.Self), player, enemy));
            player.MessageHandler(ParseMessage(GetMessage("Combat", status, MessageType.Target), player, enemy));
            Room.GetRoom(player.Player.Location).InformPlayersInRoom(ParseMessage(GetMessage("Combat", status, MessageType.Room), player, enemy), new List <string>(new string[] { player.UserID, enemy.UserID }));
            if (dead)
            {
                SetKiller(enemy, player);
            }
            SetCombatTimer(player, enemy);
        }
Пример #37
0
        /// <summary>
        /// Переводит подьзователя из серверной модели в клиентскую
        /// </summary>
        /// <param name="modelUser">Пользователь в серверной модели</param>
        /// <returns>Пользователь в клиентской модели</returns>
        public static Client.User Convert(Model.User modelUser)
        {
            if (modelUser == null)
            {
                throw new ArgumentNullException(nameof(modelUser));
            }

            var clientUser = new Client.User
            {
                Id    = modelUser.Id.ToString(),
                Login = modelUser.Login
            };

            return(clientUser);
        }
Пример #38
0
        //replaces the placeholder with the actual value, so edits can all be made on the DB, if you add anymore place holders this is where you would do the replace
        public static string ParseMessage(string message, User.User attacker, User.User target, double damage = 0, double defense = 0, double attack = 0)
        {
            message = message.Replace("{attacker}", attacker.Player.FirstName)
                             .Replace("{damage}", (damage * -1).ToString().FontColor(Utils.FontForeColor.RED))
                             .Replace("{attack}", attack.ToString())
                             .Replace("{defense}", defense.ToString());

            if (target != null){
                message = message.Replace("{target}", target.Player.FirstName)
                                 .Replace("{him-her}", target.Player.Gender == "Male" ? "him" : "her")
                                 .Replace("{he-she}", target.Player.Gender == "Male" ? "he" : "she");
            }

            return message;
        }
Пример #39
0
        public static void ParseCommands(User.User player)
        {
            List<string> commands = ParseCommandLine(player.InBufferPeek);
             bool commandFound = false;

             foreach (Dictionary<string, CommandDelegate> AvailableCommands in CommandsList) {
                 if (AvailableCommands.ContainsKey(commands[1].ToUpper())) {
                     AvailableCommands[commands[1].ToUpper()](player, commands);
                     commandFound = true;
                     break;
                 }
             }

             //if all else fails auto-attack
             if (player.Player.InCombat && player.Player.CurrentTarget != null) {
                 //auto attack! or we could remove this and let a player figure out on their own they're being attacked
                 commands.Clear();
                 commands.Add("KILL");
                 commands.Add("target");
                 commands.Insert(0, commands[0] + " " + commands[1]);
             }

             if (!commandFound && CombatCommands.ContainsKey(commands[1].ToUpper())) { //check to see if player provided a combat related command
                 CombatCommands[commands[1].ToUpper()](player, commands);
                 commandFound = true;
                 commands[0] = player.InBuffer; //just removing the command from the queue now
                 commands.Clear();
             }

             if (commands.Count == 0) return;

             //maybe this command shouldn't be a character method call...we'll see
             if (commands.Count >= 2 && commands[1].ToLower() == "save") {
                 player.Player.Save();
                 player.MessageHandler("Save succesful!\r\n");

                 commandFound = true;
             }

             if (!commandFound && commands[0].Length > 0) {
                 player.MessageHandler("I don't know what you're trying to do, but that's not going to happen.");
             }

             commands[0] = player.InBuffer; //remove command from queue
        }
Пример #40
0
        public static void Drop(User.User player, List<string> commands)
        {
            //1.get the item name from the command, may have to join all the words after dropping the command
            StringBuilder itemName = new StringBuilder();
            Room room = Room.GetRoom(player.Player.Location);

            string full = commands[0];
            commands.RemoveAt(0);
            commands.RemoveAt(0);

            foreach (string word in commands) {
                itemName.Append(word + " ");
            }

            int itemPosition = 1;
            string[] position = commands[commands.Count - 1].Split('.'); //we are separating based on using the decimal operator after the name of the npc/item
            if (position.Count() > 1) {
                int.TryParse(position[position.Count() - 1], out itemPosition);
                itemName = itemName.Remove(itemName.Length - 2, 2);
            }

            //2.get the item from the DB
            List<Items.Iitem> items = Items.Items.GetByName(itemName.ToString().Trim(), player.UserID);
            Items.Iitem item = items[itemPosition - 1];

            //3.have player drop item
            string msgPlayer = null;

            if (item != null) {
                player.Player.Inventory.RemoveInventoryItem(item, player.Player.Equipment);
                item.Location = player.Player.Location;
                item.Owner = item.Location.ToString();
                item.Save();

                //4.Inform room and player of action
                string msgOthers = string.Format("{0} drops {1}", player.Player.FirstName, item.Name);
                room.InformPlayersInRoom(msgOthers, new List<string>(new string[] { player.UserID }));
                msgPlayer = string.Format("You drop {0}", item.Name);
            }
            else {
                msgPlayer = "You are not carrying anything of the sorts.";
            }

            player.MessageHandler(msgPlayer);
        }
Пример #41
0
        private static void Equipment(User.User player, List<string> commands)
        {
            Dictionary<Items.Wearable, Items.Iitem> equipmentList = player.Player.Equipment.GetEquipment();
            StringBuilder sb = new StringBuilder();

            if (equipmentList.Count > 0) {
                sb.AppendLine("You are equipping:");
                foreach (KeyValuePair<Items.Wearable, Items.Iitem> pair in equipmentList) {
                    sb.AppendLine("[" + pair.Key.ToString().Replace("_", " ").CamelCaseWord() + "] " + pair.Value.Name);
                }
                sb.AppendLine("\n\r");
            }
            else {
                sb.AppendLine("\n\r[ EMPTY ]\n\r");
            }

            player.MessageHandler(sb.ToString());
        }
Пример #42
0
        public static void ExecuteCommandUser(User.User actor, string command, string message = null)
        {
            bool commandFound = false;

             if (CombatCommands.ContainsKey(command.ToUpper())) { //check to see if player provided a combat related command
                 CombatCommands[command.ToUpper()](actor, new List<string>(new string[] { command, message }));
                 commandFound = true;
             }

             if (!commandFound) {
                 foreach (Dictionary<string, CommandDelegate> AvailableCommands in CommandsList) {
                     if (AvailableCommands.ContainsKey(command.ToUpper())) {
                         AvailableCommands[command.ToUpper()](actor, new List<string>(new string[] { command + " " + message, command, message }));
                         break;
                     }
                 }
             }
        }
Пример #43
0
        public static void ReportBug(User.User player, List<string> commands)
        {
            MongoUtils.MongoData.ConnectToDatabase();
            MongoDatabase db = MongoUtils.MongoData.GetDatabase("Logs");
            MongoCollection col = db.GetCollection("Bugs");
            BsonDocument doc = new BsonDocument();

            doc.Add("ReportedBy", BsonValue.Create(player.UserID));
            doc.Add("DateTime", BsonValue.Create(DateTime.Now.ToUniversalTime()));
            doc.Add("Resolved", BsonValue.Create(false));
            doc.Add("Issue", BsonValue.Create(commands[0].Substring("bug".Length + 1)));

            col.Save(doc);

            if (player.Player != null) { //could be an internal bug being reported
                player.MessageHandler("Your bug has been reported, thank you.");
            }
        }
Пример #44
0
        private static void Examine(User.User player, List<string> commands)
        {
            string message = "";
            bool foundIt = false;
            if (commands.Count > 2) {
                //order is room, door, items, player, NPCs

                //rooms should have a list of items that belong to the room (non removable) but which can be interacted with by the player.  For example a loose brick, oven, fridge, closet, etc.
                //in turn these objects can have items that can be removed from the room I.E. food, clothing, weapons, etc.

                Room room = Room.GetRoom(player.Player.Location);
                Door door = FindDoor(player.Player.Location, commands);

                if (door != null) {
                    message = door.Examine;
                    foundIt = true;
                }

                //TODO: For items and players we need to be able to use the dot operator to discern between multiple of the same name.
                //look for items in room, then inventory, finally equipment.  What about another players equipment?
                //maybe the command could be "examine [itemname] [playername]" or "examine [itemname] equipment/inventory"
                if (!foundIt) {
                   message = FindAnItem(commands, player, room, out foundIt);

                }

                if (!foundIt) {
                    message = FindAPlayer(commands, room, out foundIt);

                }
                if (!foundIt) {
                    message = FindAnNpc(commands, room, out foundIt);

                }
            }

            if (!foundIt) {
                message = "Examine what?";
            }

            player.MessageHandler(message);
        }
Пример #45
0
        private static void DisplayDate(User.User player, List<string> commands)
        {
            //full, short or whatever combination we feel like allowing the player to grab
            Dictionary<string, string> dateInfo = Calendar.Calendar.GetDate();
            string message = "";
            if (commands.Count < 3) { commands.Add("FULL"); } //let's add in the "full" for date full
            string inth = "";
            if (dateInfo["DayInMonth"].Substring(dateInfo["DayInMonth"].Length - 1) == "1") inth = "st";
            else if (dateInfo["DayInMonth"].Substring(dateInfo["DayInMonth"].Length - 1) == "2") inth = "nd";
            else if (dateInfo["DayInMonth"].Substring(dateInfo["DayInMonth"].Length - 1) == "3") inth = "rd";
            else inth = "th";
            switch (commands[2].ToUpper()) {
                case "SHORT":
                    message = String.Format("\r{0}, {1}{2} of {3}, {4}.\n", dateInfo["DayInWeek"], dateInfo["DayInMonth"], inth, dateInfo["Month"], dateInfo["Year"]);
                    break;
                case "FULL":
                default:
                    message = String.Format("\r{0}, on the {1}{2} day of the month of {3}, {4} the year of the {5}.\n", dateInfo["DayInWeek"], dateInfo["DayInMonth"], inth, dateInfo["Month"], dateInfo["Year"], dateInfo["YearOf"]);
                    break;
            }

            player.MessageHandler(message);
        }
Пример #46
0
        public static User.User FindTargetByName(string name, string location)
        {
            User.User enemy = null;
            foreach (User.User foe in MySockets.Server.GetAUserByFirstName(name)) {
                if (foe.Player.Location == location) {
                    enemy = foe;
                    break;
                }
            }

            if (enemy == null) {
                //ok it's not a player lets look through the NPC list
                foreach (Character.NPC npc in Character.NPCUtils.GetAnNPCByName(name, location)) {
                    User.User foe = new User.User(true);
                    foe.UserID = npc.ID;
                    foe.Player = npc;
                    enemy = foe;
                    break;
                }
            }

            return enemy;
        }
Пример #47
0
        //called from the MOVE command
        private static void ApplyRoomModifier(User.User player)
        {
            StringBuilder sb = new StringBuilder();
            //Todo:  Check the player bonuses to see if they are immune or have resistance to the modifier
            foreach (Dictionary<string, string> modifier in Rooms.Room.GetModifierEffects(player.Player.Location)) {
                player.Player.ApplyEffectOnAttribute("Hitpoints", double.Parse(modifier["Value"]));

                double positiveValue = double.Parse(modifier["Value"]);
                if (positiveValue < 0) {
                    positiveValue *= -1;
                }

                sb.Append(String.Format(modifier["DescriptionSelf"], positiveValue));
                if (!player.Player.IsNPC) {
                    player.MessageHandler("\r" + sb.ToString());
                }
                sb.Clear();
                sb.Append(String.Format(modifier["DescriptionOthers"], player.Player.FirstName,
                           player.Player.Gender.ToString() == "Male" ? "he" : "she", positiveValue));

                Room.GetRoom(player.Player.Location).InformPlayersInRoom("\r" + sb.ToString(), new List<string>(new string[] { player.UserID }));
            }
        }
Пример #48
0
        private static void Help(User.User player, List<string> commands)
        {
            StringBuilder sb = new StringBuilder();
            MongoCollection helpCollection = MongoUtils.MongoData.GetCollection("Commands", "Help");

            if (commands.Count < 3 || commands.Contains("all")) { //display just the names
                MongoCursor cursor = helpCollection.FindAllAs<BsonDocument>();
                foreach (BsonDocument doc in cursor) {
                    sb.AppendLine(doc["_id"].ToString());
                }
            }
            else { //user specified a specific command so we will display the explanation and example
                BsonDocument doc = helpCollection.FindOneAs<BsonDocument>(Query.Matches("_id", commands[2].ToUpper()));
                sb.AppendLine(doc["_id"].ToString());
                sb.AppendLine(doc["explanation"].AsString);
                sb.AppendLine(doc["Example"].AsString);
            }

            player.MessageHandler(sb.ToString());
        }
Пример #49
0
        private static void LookIn(User.User player, List<string> commands)
        {
            commands.RemoveAt(2); //remove "in"
            string itemNameToGet = Items.Items.ParseItemName(commands);
            bool itemFound = false;
            Room room = Room.GetRoom(player.Player.Location);

            string location;
            if (string.Equals(commands[commands.Count - 1], "inventory", StringComparison.InvariantCultureIgnoreCase)) {
                location = null;
                commands.RemoveAt(commands.Count - 1); //get rid of "inventory" se we can parse an index specifier if there is one
            }
            else {
                location = player.Player.Location;
            }

            int itemPosition = 1;
            string[] position = commands[commands.Count - 1].Split('.'); //we are separating based on using the decimal operator after the name of the npc/item
            if (position.Count() > 1) {
                int.TryParse(position[position.Count() - 1], out itemPosition);
               itemNameToGet = itemNameToGet.Remove(itemNameToGet.Length - 2, 2);
            }

            int index = 1;

            if (!string.IsNullOrEmpty(location)) {//player didn't specify it was in his inventory check room first
                foreach (string itemID in room.GetObjectsInRoom(Room.RoomObjects.Items)) {
                    Items.Iitem inventoryItem = Items.Items.GetByID(itemID);
                    inventoryItem = KeepOpening(itemNameToGet, inventoryItem, itemPosition, index);

                    if (inventoryItem.Name.Contains(itemNameToGet)) {
                        Items.Icontainer container = inventoryItem as Items.Icontainer;
                        player.MessageHandler(container.LookIn());
                        itemFound = true;
                        break;

                    }
                }
            }

            if (!itemFound) { //so we didn't find one in the room that matches
                var playerInventory = player.Player.Inventory.GetInventoryAsItemList();
                foreach (Items.Iitem inventoryItem in playerInventory) {
                    if (inventoryItem.Name.Contains(itemNameToGet)) {
                        //if player didn't specify an index number loop through all items until we find the first one we want otherwise we will
                        // keep going through each item that matches until we hit the index number
                        if (index == itemPosition) {
                            Items.Icontainer container = inventoryItem as Items.Icontainer;
                            player.MessageHandler(container.LookIn());
                            itemFound = true;
                            break;
                        }
                        else {
                            index++;
                        }
                    }
                }
            }
        }
Пример #50
0
        private static void Look(User.User player, List<string> commands)
        {
            List<CharacterEnums.CharacterActionState> NonAllowableStates = new List<CharacterEnums.CharacterActionState> { CharacterEnums.CharacterActionState.Dead,
                CharacterEnums.CharacterActionState.Rotting, CharacterEnums.CharacterActionState.Sleeping, CharacterEnums.CharacterActionState.Unconcious };

            StringBuilder sb = new StringBuilder();

            if (!NonAllowableStates.Contains(player.Player.ActionState)) {
                if (commands.Count > 2 && commands[2] == "in") {
                    LookIn(player, commands);
                    return;
                }

                //let's build the description the player will see
                Room room = Room.GetRoom(player.Player.Location);
                room.GetRoomExits();
                List<Exits> exitList = room.RoomExits;

                sb.AppendLine(("- " + room.Title + " -\t\t\t").FontStyle(Utils.FontStyles.BOLD));
                //TODO: add a "Descriptive" flag, that we will use to determine if we need to display the room description.  Should be a player level
                //config we can probably store them in a dictionary called Settings and make a method that turns them on or off.  User would just type
                //Set Descriptions and the method would toggle the bit and then display back to the user the current setting ON/OFF
                sb.AppendLine(room.Description);
                sb.Append(HintCheck(player));

                foreach (Exits exit in exitList) {
                    sb.AppendLine(GetExitDescription(exit, room));
                }

                sb.Append(DisplayPlayersInRoom(room, player.UserID));
                sb.Append(DisplayItemsInRoom(room));
            }
            else {
                sb.Append(string.Format("You can't look around when you are {0}!", player.Player.Action));
            }

               player.MessageHandler(sb.ToString());
        }
Пример #51
0
        private static string FindAnItem(List<string> commands, User.User player, Room room, out bool foundIt)
        {
            foundIt = false;
            string message = null;

            List<string> itemsInRoom = room.GetObjectsInRoom(Room.RoomObjects.Items);

            foreach (string id in itemsInRoom) {
                Items.Iitem item = Items.ItemFactory.CreateItem(ObjectId.Parse(id));
                if (commands[2].ToLower().Contains(item.Name.ToLower())) {
                    message = item.Examine();
                    foundIt = true;
                    break;
                }
            }

            if (!foundIt) { //not in room check inventory
                List<Items.Iitem> inventory = player.Player.Inventory.GetInventoryAsItemList();
                foreach (Items.Iitem item in inventory) {
                    if (commands[2].ToLower().Contains(item.Name.ToLower())) {
                        message = item.Examine();
                        foundIt = true;
                        break;
                    }
                }
            }

            if (!foundIt) { //check equipment
                Dictionary<Items.Wearable, Items.Iitem> equipment = player.Player.Equipment.GetEquipment();
                foreach (Items.Iitem item in equipment.Values) {
                    if (commands[2].ToLower().Contains(item.Name.ToLower())) {
                        message = item.Examine();
                        foundIt = true;
                        break;
                    }
                }
            }

            return message;
        }
Пример #52
0
        private static void Unlock(User.User player, List<string> commands)
        {
            List<string> message = new List<string>();

            Door door = FindDoor(player.Player.Location, commands);
            if (door != null) {
                UnlockDoor(player, door);
            }
            //ok not a door so then we'll check containers in the room
        }
Пример #53
0
        private static void UnlockDoor(User.User player, Door door)
        {
            if (!player.Player.InCombat) {
                List<string> message = new List<string>();
                Room room = Room.GetRoom(player.Player.Location);
                bool hasKey = false;
                if (!room.IsDark) {
                    if (door.Lockable) {
                        if (door.RequiresKey) {
                            //let's see if the player has the key in his inventory or a skeleton key (opens any door)
                            List<Items.Iitem> inventory = player.Player.Inventory.GetInventoryAsItemList();
                            List<Items.Iitem> keyList = inventory.Where(i => i.ItemType.ContainsKey(Items.ItemsType.KEY)).ToList();
                            Items.Ikey key = null;
                            foreach (Items.Iitem keys in keyList) {
                                key = keys as Items.Ikey;
                                if (key.DoorID == door.Id || key.SkeletonKey) {
                                    hasKey = true;
                                    break;
                                }
                            }
                        }
                        if (!door.Open && !door.Destroyed && ((door.RequiresKey && hasKey) || !door.RequiresKey)) {
                            door.Locked = false;
                            door.UpdateDoorStatus();
                            //I may end up putting these strings in the general collection and then each method just supplies the verb
                            message.Add(String.Format("You unlock {0} {1}.", GetArticle(door.Description[0]), door.Description));
                            message.Add(String.Format("{0} unlocks {1} {2}.", player.Player.FirstName, GetArticle(door.Description[0]), door.Description));
                        }
                        else if (door.Destroyed) {
                            message.Add("Why would you want to unlock something that is in pieces?");
                        }
                        else if (!hasKey) {
                            message.Add("You don't have the key to unlock this door.");
                        }
                        else {
                            message.Add("It can't be unlocked, the door is open.");
                        }
                    }
                    else {
                        message.Add("It can't be unlocked.");
                    }
                }
                else {
                    message.Add("You can't see anything! Let alone what you are trying to unlock.");
                }

                player.MessageHandler(message[0]);
                if (message.Count > 1) {
                    room.InformPlayersInRoom(message[1], new List<string>(new string[] { player.UserID }));
                }
            }
            else {
                player.MessageHandler("You are in the middle of combat there are more pressing matters at hand than unlocking something.");
            }
        }
Пример #54
0
        private static void Inventory(User.User player, List<string> commands)
        {
            List<Items.Iitem> inventoryList = player.Player.Inventory.GetInventoryAsItemList();
            StringBuilder sb = new StringBuilder();

            Dictionary<string, int> grouping = new Dictionary<string, int>();

            //let's group repeat items for easier display this may be a candidate for a helper method
            foreach (Items.Iitem item in inventoryList) {
                Items.Icontainer container = item as Items.Icontainer;
                if (!grouping.ContainsKey(item.Name)) {
                    if (!item.ItemType.ContainsKey(Items.ItemsType.CONTAINER)) {
                        grouping.Add(item.Name, 1);
                    }
                    else{
                        grouping.Add(item.Name + " [" + (container.Opened ? "Opened" : "Closed") + "]", 1);
                        container = null;
                    }
                }
                else {
                    if (!item.ItemType.ContainsKey(Items.ItemsType.CONTAINER)) {
                        grouping[item.Name] += 1;
                    }
                    else {
                        grouping[item.Name + " [" + (container.Opened ? "Opened" : "Closed") + "]"] += 1;
                        container = null;
                    }
                }
            }

            if (grouping.Count > 0) {
                sb.AppendLine("You are carrying:");
                foreach (KeyValuePair<string, int> pair in grouping) {
                    sb.AppendLine(pair.Key.CamelCaseString() + (pair.Value > 1 ? "[" + pair.Value + "]" : ""));
                }
                sb.AppendLine("\n\r");
            }
            else{
                sb.AppendLine("\n\r[ EMPTY ]\n\r");
            }

            player.MessageHandler(sb.ToString());
        }
Пример #55
0
 //called from the LOOK command
 private static string HintCheck(User.User player)
 {
     StringBuilder sb = new StringBuilder();
     //let's display the room hints if the player passes the check
     foreach (RoomModifier mod in Rooms.Room.GetModifiers(player.Player.Location)) {
         foreach (Dictionary<string, string> dic in mod.Hints) {
             if (player.Player.GetAttributeValue(dic["Attribute"]) >= int.Parse(dic["ValueToPass"])) {
                 sb.AppendLine(dic["Display"]);
             }
         }
     }
     return sb.ToString();
 }
Пример #56
0
 private static void LevelUp(User.User player, List<string> commands)
 {
     Character.Character temp = player.Player as Character.Character;
     //if we leveled up we should have gotten points to spend assigned before we eve get here
     if (temp != null && (temp.PointsToSpend > 0 || temp.IsLevelUp)) {
         if (temp.Experience >= temp.NextLevelExperience || temp.Leveled) {
             player.Player.Level += 1;
             temp.Leveled = false;
         }
         player.CurrentState = User.User.UserState.LEVEL_UP;
     }
     else {
         player.MessageHandler("You do not have enough Experience, or points to spend to perform this action.");
     }
 }
Пример #57
0
 private static void Say(User.User player, List<string> commands)
 {
     string temp ="";
     if (commands[0].Length > 4)	temp = commands[0].Substring(4);
     else{
         if (player.Player.IsNPC) {
             player.MessageHandler("You decide to stay quiet since you had nothing to say.");
             return;
         }
     }
     Room room = Room.GetRoom(player.Player.Location);
     player.MessageHandler("You say \"" + temp + "\"");
     room.InformPlayersInRoom((room.IsDark == true ? "Someone" : player.Player.FirstName) + " says \"" + temp + "\"",
         new List<string>(new string[] { player.UserID }));
 }
Пример #58
0
        //a tell is a private message basically, location is not a factor
        private static void Tell(User.User player, List<string> commands)
        {
            List<User.User> toPlayerList = MySockets.Server.GetAUserByFirstName(commands[2]).ToList();
            User.User toPlayer = null;
            string message = "";

            if (commands[2].ToUpper() == "SELF") {
                player.MessageHandler("You go to tell yourself something when you realize you already know it.");
                return;
            }

            if (toPlayerList.Count < 1) {
                message = "There is no one named " + commands[2].CamelCaseWord() + " to tell something.";
            }
            else if (toPlayerList.Count > 1) { //let's narrow it down by including a last name (if provided)
                toPlayer = toPlayerList.Where(p => String.Compare(p.Player.LastName, commands[3], true) == 0).SingleOrDefault();
            }
            else {
                toPlayer = toPlayerList[0];
                if (toPlayer.UserID == player.UserID) {
                    player.MessageHandler("You tell yourself something important.");
                    return;
                }
            }

               bool fullName = true;
            if (toPlayer == null) {
                message = "There is no one named " + commands[2].CamelCaseWord() + " to tell something.";
            }
            else {
                int startAt = commands[0].ToLower().IndexOf(toPlayer.Player.FirstName.ToLower() + " " + toPlayer.Player.LastName.ToLower());
                if (startAt == -1 || startAt > 11) {
                    startAt = commands[0].ToLower().IndexOf(toPlayer.Player.FirstName.ToLower());
                    fullName = false;
                }

                if (startAt > 11) startAt = 11 + toPlayer.Player.FirstName.Length + 1;
                else startAt += toPlayer.Player.FirstName.Length + 1;
                if (fullName) startAt += toPlayer.Player.LastName.Length + 1;

                if (commands[0].Length > startAt) {
                    message = commands[0].Substring(startAt);
                    player.MessageHandler("You tell " + toPlayer.Player.FirstName + " \"" + message + "\"");
                    toPlayer.MessageHandler(player.Player.FirstName + " tells you \"" + message + "\"");
                }
                else {
                    player.MessageHandler("You have nothing to tell them.");
                }
            }
        }
Пример #59
0
        //a whisper is a private message but with a chance that other players may hear what was said, other player has to be in the same room
        //TODO: need to add the ability for others to listen in on the whisper if they have the skill
        private static void Whisper(User.User player, List<string> commands)
        {
            List<User.User> toPlayerList = new List<User.User>();
            Room room = Room.GetRoom(player.Player.Location);
            if (commands.Count > 2){
                if (commands[2].ToUpper() == "SELF") {
                    player.MessageHandler("You turn your head towards your own shoulder and whisper quietly to yourself.");
                    room.InformPlayersInRoom((room.IsDark == true ? "Someone" : player.Player.FirstName) + " whispers into " + player.Player.Gender == "MALE" ? "his" : "her" + " own shoulder.",
                        new List<string>(new string[] { player.UserID })); ;
                    return;
                }

                toPlayerList = MySockets.Server.GetAUserByFirstName(commands[2]).Where(p => p.Player.Location == player.Player.Location).ToList();
            }

            User.User toPlayer = null;
            string message = "";

            if (toPlayerList.Count < 1) {
                player.MessageHandler("You whisper to no one. Creepy.");
                return;
            }
            else if (toPlayerList.Count > 1) { //let's narrow it down by including a last name (if provided)
                toPlayer = toPlayerList.Where(p => String.Compare(p.Player.LastName, commands[3], true) == 0).SingleOrDefault();
            }
            else {
                if (toPlayerList.Count == 1) {
                    toPlayer = toPlayerList[0];
                }
                if (commands.Count == 2 || toPlayer.UserID == player.UserID) {
                        player.MessageHandler("You realize you have nothing to whisper about.");
                        return;
                    }
            }

            bool fullName = true;
            if (toPlayer == null) {
                message = "You try and whisper to " + commands[2].CamelCaseWord() + " but they're not around.";
            }
            else {
                int startAt = commands[0].ToLower().IndexOf(toPlayer.Player.FirstName.ToLower() + " " + toPlayer.Player.LastName.ToLower());
                if (startAt == -1 || startAt > 11) {
                    startAt = commands[0].ToLower().IndexOf(toPlayer.Player.FirstName.ToLower());
                    fullName = false;
                }

                if (startAt > 11) startAt = 11 + toPlayer.Player.FirstName.Length + 1;
                else startAt += toPlayer.Player.FirstName.Length + 1;
                if (fullName) startAt += toPlayer.Player.LastName.Length + 1;

                if (commands[0].Length > startAt) {
                    message = commands[0].Substring(startAt);
                    player.MessageHandler("You whisper to " + toPlayer.Player.FirstName + " \"" + message + "\"");
                    toPlayer.MessageHandler((room.IsDark == true ? "Someone" : player.Player.FirstName) + " whispers to you \"" + message + "\"");
                    //this is where we would display what was whispered to players with high perception?
                    room.InformPlayersInRoom((room.IsDark == true ? "Someone" : player.Player.FirstName) + " whispers something to " + toPlayer.Player.FirstName, new List<string>(new string[] { player.UserID, toPlayer.UserID }));
                }
            }
        }
Пример #60
0
        private static void Who(User.User player, List<string> commands)
        {
            StringBuilder sb = new StringBuilder();
            sb.AppendLine("PlayerName");
            sb.AppendLine("----------");
            MySockets.Server.GetCurrentUserList()
                .Where(u => u.CurrentState == User.User.UserState.TALKING)
                .OrderBy(u => u.Player.FirstName)
                .ToList()
                .ForEach(u => sb.AppendLine(u.Player.FirstName + " " + u.Player.LastName));

            player.MessageHandler(sb.ToString());
        }