示例#1
0
 public void ProcessAIForNPCs()
 {
     if (!ProcessingAI)
     {
         ProcessingAI = true;
         LoadNPCs();
         //loop through each NPC and call the Update() method
         foreach (string id in _npcList)
         {
             Iactor actor = CharacterFactory.Factory.CreateCharacter(CharacterType.NPC);
             actor.Load(id);
             Inpc npc = actor as Inpc;
             if (DateTime.Now.ToUniversalTime() > npc.NextAiAction)
             {
                 npc.Update();
                 //in case the Rot Ai state cleaned this guy out of the DB.
                 if (GetAnNPCByID(id) != null)
                 {
                     actor.Save();
                 }
             }
         }
         ProcessingAI = false;
     }
 }
示例#2
0
        public static List <Iactor> GetAnNPCByName(string name, string location = null)
        {
            List <Iactor> npcList = null;

            MongoUtils.MongoData.ConnectToDatabase();
            MongoDatabase   character     = MongoUtils.MongoData.GetDatabase("Characters");
            MongoCollection npcCollection = character.GetCollection("NPCCharacters");
            IMongoQuery     query;

            if (string.IsNullOrEmpty(location))
            {
                query = Query.EQ("FirstName", name.CamelCaseWord());
            }
            else
            {
                query = Query.And(Query.EQ("FirstName", name.CamelCaseWord()), Query.EQ("Location", location));
            }

            var results = npcCollection.FindAs <BsonDocument>(query);

            if (results != null)
            {
                npcList = new List <Iactor>();
                foreach (BsonDocument found in results)
                {
                    Iactor npc = CharacterFactory.Factory.CreateCharacter(CharacterType.NPC);
                    npc.Load(found["_id"].AsObjectId.ToString());
                    npcList.Add(npc);
                }
            }

            return(npcList);
        }
示例#3
0
文件: Character.cs 项目: vadian/Novus
        public static string GetAttributeColorized(this Iactor character, string name)
        {
            string result = "";

            name = name.CamelCaseWord();

            double value = character.GetAttributeValue(name);
            double max   = character.GetAttributeMax(name);

            if (value >= max * HighHealth)
            {
                result = value.ToString().FontColor(Utils.FontForeColor.GREEN);
            }
            else if (value < max * HighHealth && value >= max * LowHealth)
            {
                result = value.ToString().FontColor(Utils.FontForeColor.YELLOW);
            }
            else if (value < max * LowHealth && value > 0)
            {
                result = value.ToString().FontColor(Utils.FontForeColor.RED);
            }
            else
            {
                result = value.ToString().FontColor(Utils.FontForeColor.RED).FontStyle(Utils.FontStyles.BOLD);
            }

            return(result);
        }
示例#4
0
 public Items.Wearable GetMainHandWeapon(Iactor player)
 {
     if (player.MainHand != null)
     {
         return((Items.Wearable)Enum.Parse(typeof(Items.Wearable), player.MainHand));
     }
     return(Items.Wearable.NONE);
 }
示例#5
0
 public void CleanupBonuses()
 {
     if (_npcList != null)
     {
         foreach (string id in _npcList)
         {
             Iactor actor = CharacterFactory.Factory.CreateCharacter(CharacterType.NPC);
             actor.Load(id);
             actor.CleanupBonuses();
             actor.Save();
         }
     }
 }
示例#6
0
 public void RegenerateAttributes()
 {
     if (_npcList != null)
     {
         foreach (string id in _npcList)
         {
             Iactor actor = CharacterFactory.Factory.CreateCharacter(CharacterType.NPC);
             actor.Load(id);
             foreach (KeyValuePair <string, Attribute> attrib in actor.GetAttributes())
             {
                 actor.ApplyRegen(attrib.Key);
             }
             actor.Save();
         }
     }
 }
示例#7
0
        public bool UnequipItem(Items.Iitem item, Iactor player)
        {
            bool result = false;

            if (equipped.ContainsKey(item.WornOn))
            {
                player.Inventory.inventory.Add(item); //unequipped stuff goes to inventory
                equipped.Remove(item.WornOn);

                //if their main hand is now empty, we will make the other hand the main hand
                if (!string.IsNullOrEmpty(player.MainHand) && string.Equals(item.WornOn.ToString(), player.MainHand, StringComparison.InvariantCultureIgnoreCase))
                {
                    player.MainHand = Items.Wearable.WIELD_RIGHT.ToString();
                    if (item.WornOn == Items.Wearable.WIELD_RIGHT)
                    {
                        player.MainHand = Items.Wearable.WIELD_LEFT.ToString();
                    }
                }
                result = true;
            }
            return(result);
        }
示例#8
0
        public static Iactor GetAnNPCByID(string id)
        {
            if (string.IsNullOrEmpty(id))
            {
                return(null);
            }

            MongoUtils.MongoData.ConnectToDatabase();
            MongoDatabase   character     = MongoUtils.MongoData.GetDatabase("Characters");
            MongoCollection npcCollection = character.GetCollection("NPCCharacters");
            IMongoQuery     query         = Query.EQ("_id", ObjectId.Parse(id));

            BsonDocument results = npcCollection.FindOneAs <BsonDocument>(query);
            Iactor       npc     = null;

            if (results != null)
            {
                npc = CharacterFactory.Factory.CreateCharacter(CharacterType.NPC);
                npc.Load(results["_id"].AsObjectId.ToString());
            }

            return(npc);
        }
示例#9
0
        //this creates a new type of NPC as long as it hasn't hit the max world amount permissible
        public static Iactor CreateNPC(int MobTypeID, string state = null)
        {
            MongoUtils.MongoData.ConnectToDatabase();
            MongoDatabase   character     = MongoUtils.MongoData.GetDatabase("World");
            MongoCollection npcCollection = character.GetCollection("NPCs");
            IMongoQuery     query         = Query.EQ("_id", MobTypeID);
            BsonDocument    doc           = npcCollection.FindOneAs <BsonDocument>(query);

            Iactor actor = null;

            if (doc["Current"].AsInt32 < doc["Max"].AsInt32)
            {
                actor = CharacterFactory.Factory.CreateNPCCharacter(MobTypeID);
                Inpc npc = actor as Inpc;
                if (state != null)                  //give it a starting state, so it can be something other than Wander
                {
                    npc.Fsm.state = npc.Fsm.GetStateFromName(state.CamelCaseWord());
                }
                doc["Current"] = doc["Current"].AsInt32 + 1;
                npcCollection.Save(doc);
            }

            return(actor);
        }
示例#10
0
文件: Equipment.cs 项目: vadian/Novus
 public Items.Wearable GetMainHandWeapon(Iactor player)
 {
     if (player.MainHand != null) {
         return (Items.Wearable)Enum.Parse(typeof(Items.Wearable), player.MainHand);
     }
     return Items.Wearable.NONE;
 }
示例#11
0
文件: Equipment.cs 项目: vadian/Novus
        public bool UnequipItem(Items.Iitem item, Iactor player)
        {
            bool result = false;
            if (equipped.ContainsKey(item.WornOn)) {
                player.Inventory.inventory.Add(item); //unequipped stuff goes to inventory
                equipped.Remove(item.WornOn);

                //if their main hand is now empty, we will make the other hand the main hand
                if (!string.IsNullOrEmpty(player.MainHand) && string.Equals(item.WornOn.ToString(), player.MainHand, StringComparison.InvariantCultureIgnoreCase)){
                    player.MainHand = Items.Wearable.WIELD_RIGHT.ToString();
                    if (item.WornOn == Items.Wearable.WIELD_RIGHT) {
                        player.MainHand = Items.Wearable.WIELD_LEFT.ToString();
                    }
                }
                result = true;
            }
            return result;
        }