Example #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;
     }
 }
Example #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);
        }
Example #3
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();
         }
     }
 }
Example #4
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();
         }
     }
 }
Example #5
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);
        }