Esempio n. 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;
     }
 }
Esempio n. 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);
        }
Esempio n. 3
0
        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);
        }
Esempio n. 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);
 }
Esempio n. 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();
         }
     }
 }
Esempio n. 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();
         }
     }
 }
Esempio n. 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);
        }
Esempio n. 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);
        }
Esempio n. 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);
        }
Esempio n. 10
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;
 }
Esempio n. 11
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;
        }