Example #1
0
 internal void IncreaseAttributeMaxToValues(Character.Iactor specificUser)
 {
     foreach (var attrib in specificUser.GetAttributes())
     {
         attrib.Value.Max = attrib.Value.Value;
     }
 }
Example #2
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;
                    }
                }
            }
        }
Example #3
0
File: User.cs Project: vadian/Novus
 public User()
 {
     CurrentState = UserState.JUST_CONNECTED;
     _character = CharacterFactory.Factory.CreateCharacter(CharacterEnums.CharacterType.PLAYER);
     _userBuffer = new ClientHandling.MessageBuffer(UserID);
     LastDisconnected = DateTime.MinValue;
     LoginCompleted = false;
 }
Example #4
0
File: User.cs Project: vadian/Novus
 public User()
 {
     CurrentState     = UserState.JUST_CONNECTED;
     _character       = CharacterFactory.Factory.CreateCharacter(CharacterEnums.CharacterType.PLAYER);
     _userBuffer      = new ClientHandling.MessageBuffer(UserID);
     LastDisconnected = DateTime.MinValue;
     LoginCompleted   = false;
 }
Example #5
0
 private void MasterLooterLoots(User.User looter, List <string> commands, Character.Iactor npc)
 {
     if (string.Equals(looter.UserID, MasterLooter))
     {
         ((Character.NPC)npc).Loot(looter, commands, true);
     }
     else
     {
         looter.MessageHandler("Only the master looter can loot corpses killed by the group.");
     }
 }
Example #6
0
File: User.cs Project: vadian/Novus
        public User(bool npc = false)
        {
            if (!npc) {
                CurrentState = UserState.JUST_CONNECTED;
                _character = CharacterFactory.Factory.CreateCharacter(CharacterEnums.CharacterType.PLAYER);
                _userBuffer = new ClientHandling.MessageBuffer(UserID);
                LastDisconnected = DateTime.MinValue;
                LoginCompleted = false;
            }

            UserID = Guid.NewGuid().ToString();
        }
Example #7
0
File: User.cs Project: vadian/Novus
        public User(bool npc = false)
        {
            if (!npc)
            {
                CurrentState     = UserState.JUST_CONNECTED;
                _character       = CharacterFactory.Factory.CreateCharacter(CharacterEnums.CharacterType.PLAYER);
                _userBuffer      = new ClientHandling.MessageBuffer(UserID);
                LastDisconnected = DateTime.MinValue;
                LoginCompleted   = false;
            }

            UserID = Guid.NewGuid().ToString();
        }
Example #8
0
        private static double GetAndEvaluateExpression(string calculationName, Character.Iactor player)
        {
            MongoCollection col   = MongoUtils.MongoData.GetCollection("Calculations", "Combat");
            IMongoQuery     query = Query.EQ("_id", calculationName);
            BsonDocument    doc   = col.FindOneAs <BsonDocument>(query).AsBsonDocument;

            NCalc.Expression expression       = new NCalc.Expression(ReplaceStringWithNumber(player, doc["Expression"].AsString));
            double           expressionResult = (double)expression.Evaluate();

            //let's take into consideration some other factors.  Visibility, stance, etc.
            //TODO: add that here.  They only take away from chance to hit. But some of them can be negated.
            //if it's dark but player can see in the dark for example.
            return(expressionResult);
        }
Example #9
0
        private static void Loot(User.User player, List <string> commands)
        {
            Character.Iactor npc      = null;
            string[]         position = commands[0].Split('.'); //we are separating based on using the decimal operator after the name of the npc/item
            if (position.Count() > 1)
            {
                //ok so the player specified a specific NPC in the room list to loot and not just the first to match
                int pos;
                int.TryParse(position[position.Count() - 1], out pos);
                if (pos != 0)
                {
                    npc = Character.NPCUtils.GetAnNPCByID(GetObjectInPosition(pos, commands[2], player.Player.Location));
                }
            }
            else
            {
                npc = Character.NPCUtils.GetAnNPCByID(player.Player.CurrentTarget);
            }

            if (npc != null && npc.IsDead())
            {
                npc.Loot(player, commands);
            }
            else if (npc != null && !npc.IsDead())
            {
                player.MessageHandler("You can't loot what is not dead! Maybe you should try killing it first.");
            }

            //wasn't an npc we specified so it's probably a player
            if (npc == null)
            {
                User.User lootee = FindTargetByName(commands[commands.Count - 1], player.Player.Location);
                if (lootee != null && lootee.Player.IsDead())
                {
                    lootee.Player.Loot(player, commands);
                }
                else if (lootee != null && !lootee.Player.IsDead())
                {
                    player.MessageHandler("You can't loot what is not dead! Maybe you should try pickpocketing or killing it first.");
                }
                else
                {
                    player.MessageHandler("You can't loot what doesn't exist...unless you see dead people, but you don't.");
                }
            }

            return;
        }
Example #10
0
        //TODO:
        //This method exists in the Skill class, should probably combine them into a math library or something
        private static string ReplaceStringWithNumber(Character.Iactor player, string expression)
        {
            //would like to make this a bit more generic so if new attributes are inserted we don't have to change this method
            //I think easiest way is to have the expression be separated by spaces, but just so it works with anything let's get rid of
            //any mathematical signs and then we should just have the name of the attributes we want.
            string temp = expression;

            string[] operators = new string[] { "+", "-", "/", "*", "(", ")", "[", "]", "{", "}", "^", "SQRT", "POW", "MAX" };
            foreach (string operand in operators)
            {
                temp = temp.Replace(operand, " ");
            }

            //need to get rid of repeats and empty spaces
            string[] attributeList = temp.Split(' ');

            //if you cocked your head to the side at this assignment, read over the code again.
            temp = expression;

            foreach (string attributeName in attributeList)
            {
                if (!string.IsNullOrEmpty(attributeName))
                {
                    if (player.GetAttributes().ContainsKey(attributeName))
                    {
                        temp = temp.Replace(attributeName, player.GetAttributeValue("attributeName").ToString());
                    }
                    else if (player.GetSubAttributes().ContainsKey(attributeName))
                    {
                        temp = temp.Replace(attributeName, player.GetSubAttributes()[attributeName].ToString());
                    }
                    else if (attributeName.Contains("Rank"))
                    {
                        temp = temp.Replace(attributeName, player.GetAttributeRank(attributeName.Substring(0, attributeName.Length - 4)).ToString());
                    }
                    else if (attributeName.Contains("Bonus"))  //this part does not exist in the Skill class method
                    {
                        string bonusName        = attributeName.Replace("Bonus", "");
                        double replacementValue = player.GetBonus((CharacterEnums.BonusTypes)Enum.Parse(typeof(CharacterEnums.BonusTypes), bonusName));
                        temp = temp.Replace(attributeName, replacementValue.ToString());
                    }
                }
            }

            return(temp);
        }
Example #11
0
        /// <summary>
        /// Finds a possible target that matches by name or ID, for either player or NPC.
        /// </summary>
        /// <param name="player"></param>
        /// <param name="commands"></param>
        /// <returns></returns>
        private static User.User FindTarget(User.User player, List <string> commands)
        {
            User.User enemy = null;

            if (commands.Count > 2 && !string.Equals(commands[2], "target", StringComparison.InvariantCultureIgnoreCase))
            {
                enemy = FindTargetByName(commands[2], player.Player.Location);
            }
            //couldn't find the target by name, now let's see if our current Target is around
            if (enemy == null)
            {
                enemy = MySockets.Server.GetAUser(player.Player.CurrentTarget);
            }

            //didn't find a player character so let's look for an npc
            if (enemy == null)
            {
                Character.Iactor npc      = null;
                string[]         position = commands[0].Split('.'); //we are separating based on using the decimal operator after the name of the npc/item
                if (position.Count() > 1)
                {
                    //ok so the player specified a specific NPC in the room list to examine and not just the first to match
                    int pos;
                    int.TryParse(position[position.Count() - 1], out pos);
                    if (pos != 0)
                    {
                        npc = Character.NPCUtils.GetAnNPCByID(GetObjectInPosition(pos, commands[2], player.Player.Location));
                    }
                }
                else
                {
                    npc = Character.NPCUtils.GetAnNPCByID(player.Player.CurrentTarget);
                }

                if (npc != null)
                {
                    User.User temp = new User.User(true);
                    temp.UserID = npc.ID;
                    temp.Player = npc;
                    enemy       = temp;
                }
            }

            return(enemy);
        }
Example #12
0
        public static void CreateNPC(int mobTypeID, string location, int amount)
        {
            amount = amount * Rooms.Room.GetRoom(location).GetObjectsInRoom(Room.RoomObjects.Players).Count;

            for (int i = 0; i < amount; i++)
            {
                Character.Iactor actor = Character.NPCUtils.CreateNPC(mobTypeID);
                if (actor != null)
                {
                    actor.Location = location;
                    //meh this whole AI stuff may need to be changed depending on how AI will handle triggers
                    actor.LastCombatTime = DateTime.MinValue.ToUniversalTime();
                    Character.Inpc npc = actor as Character.Inpc;
                    npc.Fsm.state = AI.FindTarget.GetState();
                    actor.Save();
                }
            }
        }
Example #13
0
        internal void AdjustRacePoints(Character.Iactor specificUser, BsonDocument document)
        {
            var races = document["Races"].AsBsonArray;

            foreach (BsonDocument doc in races)
            {
                if (doc["Name"].AsString == specificUser.Race)
                {
                    specificUser.ApplyEffectOnAttribute("Strength", doc["Strength"].AsDouble);
                    specificUser.ApplyEffectOnAttribute("Dexterity", doc["Dexterity"].AsDouble);
                    specificUser.ApplyEffectOnAttribute("Endurance", doc["Endurance"].AsDouble);
                    specificUser.ApplyEffectOnAttribute("Charisma", doc["Charisma"].AsDouble);
                    specificUser.ApplyEffectOnAttribute("Intelligence", doc["Intelligence"].AsDouble);
                    specificUser.ApplyEffectOnAttribute("Hitpoints", doc["Hitpoints"].AsDouble);
                    break;
                }
            }
        }
Example #14
0
        internal void AssignStatPoints(Character.Iactor specificUser)
        {
            MongoUtils.MongoData.ConnectToDatabase();
            MongoDatabase   db       = MongoUtils.MongoData.GetDatabase("Characters");
            MongoCollection col      = db.GetCollection("General");
            var             document = col.FindOneAs <BsonDocument>(Query.EQ("_id", "Class"));

            //This is where we adjust the attributes
            AdjustClassPoints(specificUser, document);

            document = col.FindOneAs <BsonDocument>(Query.EQ("_id", "Race"));
            AdjustRacePoints(specificUser, document);
            //not sure about these two below
            //AdjustSkinPoints(specificUser, document); endurance/dexterity?
            //AdjustBuildPoints(specificUser, document); strength/dexterity/endurance?

            //increase the max to reflect the new values
            IncreaseAttributeMaxToValues(specificUser);
        }
Example #15
0
File: AI.cs Project: vadian/Novus
        public void InterpretMessage(string message, Character.Iactor actor)
        {
            Character.NPC npc    = actor as Character.NPC;
            MessageParser parser = new MessageParser(message, actor, npc.Triggers);

            parser.FindTrigger();

            //Here's the rub. This call is a sequential call up to this point, maybe we want to
            //kick off a separate thread so that then it won't hold up the players actions and
            //then we can even execute states that operate on a delay.

            if (parser.TriggerToExecute != null)
            {
                IState state = GetStateFromName(parser.TriggerToExecute.StateToExecute);
                if (state != null)
                {
                    ChangeState(state, npc);
                    npc.NextAiAction = DateTime.Now.ToUniversalTime().AddSeconds(-1); //this state will execute next now
                    state.Execute(npc, parser.TriggerToExecute);
                }
            }
        }
Example #16
0
        private bool LightSourcePresent()
        {
            //foreach player/npc/item in room check to see if it is lightsource and on
            bool lightSource = false;

            //check th eplayers and see if anyones equipment is a lightsource
            foreach (string id in players)
            {
                User.User temp = MySockets.Server.GetAUser(id);
                Dictionary <Items.Wearable, Items.Iitem> equipped = temp.Player.Equipment.GetEquipment();
                foreach (Items.Iitem item in equipped.Values)
                {
                    Items.Iiluminate light = item as Items.Iiluminate;
                    if (light != null && light.isLit)
                    {
                        lightSource = true;
                        break;
                    }
                }
                if (lightSource)
                {
                    break;
                }
            }

            //check the NPCS and do the same as we did with the players
            if (!lightSource)
            {
                foreach (string id in npcs)
                {
                    Character.Iactor actor = Character.NPCUtils.GetAnNPCByID(id);
                    Dictionary <Items.Wearable, Items.Iitem> equipped = actor.Equipment.GetEquipment();
                    foreach (Items.Iitem item in equipped.Values)
                    {
                        Items.Iiluminate light = item as Items.Iiluminate;
                        if (light != null && light.isLit)
                        {
                            lightSource = true;
                            break;
                        }
                    }
                    if (lightSource)
                    {
                        break;
                    }
                }
            }

            //finally check for items in the room (just ones laying in the room, if a container is open check in container)
            if (!lightSource)
            {
                foreach (string id in items)
                {
                    Items.Iitem      item      = Items.Items.GetByID(id);
                    Items.Icontainer container = item as Items.Icontainer;
                    Items.Iiluminate light     = item as Items.Iiluminate; //even if container check this first. Container may have light enchanment.
                    if (light != null && light.isLit)
                    {
                        lightSource = true;
                        break;
                    }
                    if (container != null && (container.Contents != null && container.Contents.Count > 0) && container.Opened)  //let's look in the container only if it's open
                    {
                        foreach (string innerId in container.Contents)
                        {
                            Items.Iitem innerItem = Items.Items.GetByID(id);
                            light = innerItem as Items.Iiluminate;
                            if (light != null && light.isLit)
                            {
                                lightSource = true;
                                break;
                            }
                        }
                    }

                    if (lightSource)
                    {
                        break;
                    }
                }
            }
            return(lightSource);
        }
Example #17
0
 public MessageParser(string message, Character.Iactor actor, List <ITrigger> triggers)
 {
     MessageFull = message;
     Actor       = actor;
     Triggers    = triggers;
 }