Beispiel #1
0
		// /// <summary>
		// /// List of Lootgenerators related by mobfaction
		// /// </summary>
		//static readonly HybridDictionary m_mobFactionGenerators = new HybridDictionary();		

		/// <summary>
		/// Initializes the LootMgr. This function must be called
		/// before the LootMgr can be used!
		/// </summary>
		public static bool Init()
		{
			if (log.IsInfoEnabled)
				log.Info("Loading LootGenerators...");

			IList<LootGenerator> m_lootGenerators;
			try
			{
				m_lootGenerators = GameServer.Database.SelectAllObjects<LootGenerator>();
			}
			catch (Exception e)
			{
				if (log.IsErrorEnabled)
					log.Error("LootMgr: LootGenerators could not be loaded", e);
				return false;
			}

			if (m_lootGenerators != null) // did we find any loot generators
			{
				foreach (LootGenerator dbGenerator in m_lootGenerators)
				{
					ILootGenerator generator = GetGeneratorInCache(dbGenerator);
					if (generator == null)
					{
						Type generatorType = null;
						foreach (Assembly asm in ScriptMgr.Scripts)
						{
							generatorType = asm.GetType(dbGenerator.LootGeneratorClass);
							if (generatorType != null)
								break;
						}
						if (generatorType == null)
						{
							generatorType = Assembly.GetAssembly(typeof(GameServer)).GetType(dbGenerator.LootGeneratorClass);
						}

						if (generatorType == null)
						{
							if (log.IsErrorEnabled)
								log.Error("Could not find LootGenerator: " + dbGenerator.LootGeneratorClass + "!!!");
							continue;
						}
						generator = (ILootGenerator)Activator.CreateInstance(generatorType);

						PutGeneratorInCache(dbGenerator, generator);
					}
					RegisterLootGenerator(generator, dbGenerator.MobName, dbGenerator.MobGuild, dbGenerator.MobFaction, dbGenerator.RegionID);
				}
			}
			if (log.IsDebugEnabled)
			{
				log.Debug("Found " + m_globalGenerators.Count + " Global LootGenerators");
				log.Debug("Found " + m_mobNameGenerators.Count + " Mobnames registered by LootGenerators");
				log.Debug("Found " + m_mobGuildGenerators.Count + " Guildnames registered by LootGenerators");
			}

			// no loot generators loaded...
			if (m_globalGenerators.Count == 0 && m_mobNameGenerators.Count == 0 && m_globalGenerators.Count == 0)
			{
				ILootGenerator baseGenerator = new LootGeneratorMoney();
				RegisterLootGenerator(baseGenerator, null, null, null, 0);
				if (log.IsInfoEnabled)
					log.Info("No LootGenerator found, adding LootGeneratorMoney for all mobs as default.");
			}

			if (log.IsInfoEnabled)
				log.Info("LootGenerator initialized: true");
			return true;
		}
Beispiel #2
0
        // /// <summary>
        // /// List of Lootgenerators related by mobfaction
        // /// </summary>
        //static readonly HybridDictionary m_mobFactionGenerators = new HybridDictionary();

        /// <summary>
        /// Initializes the LootMgr. This function must be called
        /// before the LootMgr can be used!
        /// </summary>
        public static bool Init()
        {
            if (log.IsInfoEnabled)
            {
                log.Info("Loading LootGenerators...");
            }

            IList <LootGenerator> m_lootGenerators;

            try
            {
                m_lootGenerators = GameServer.Database.SelectAllObjects <LootGenerator>();
            }
            catch (Exception e)
            {
                if (log.IsErrorEnabled)
                {
                    log.Error("LootMgr: LootGenerators could not be loaded", e);
                }
                return(false);
            }

            if (m_lootGenerators != null)             // did we find any loot generators
            {
                foreach (LootGenerator dbGenerator in m_lootGenerators)
                {
                    ILootGenerator generator = GetGeneratorInCache(dbGenerator);
                    if (generator == null)
                    {
                        Type generatorType = null;
                        foreach (Assembly asm in ScriptMgr.Scripts)
                        {
                            generatorType = asm.GetType(dbGenerator.LootGeneratorClass);
                            if (generatorType != null)
                            {
                                break;
                            }
                        }
                        if (generatorType == null)
                        {
                            generatorType = Assembly.GetAssembly(typeof(GameServer)).GetType(dbGenerator.LootGeneratorClass);
                        }

                        if (generatorType == null)
                        {
                            if (log.IsErrorEnabled)
                            {
                                log.Error("Could not find LootGenerator: " + dbGenerator.LootGeneratorClass + "!!!");
                            }
                            continue;
                        }
                        generator = (ILootGenerator)Activator.CreateInstance(generatorType);

                        PutGeneratorInCache(dbGenerator, generator);
                    }
                    RegisterLootGenerator(generator, dbGenerator.MobName, dbGenerator.MobGuild, dbGenerator.MobFaction, dbGenerator.RegionID);
                }
            }
            if (log.IsDebugEnabled)
            {
                log.Debug("Found " + m_globalGenerators.Count + " Global LootGenerators");
                log.Debug("Found " + m_mobNameGenerators.Count + " Mobnames registered by LootGenerators");
                log.Debug("Found " + m_mobGuildGenerators.Count + " Guildnames registered by LootGenerators");
            }

            // no loot generators loaded...
            if (m_globalGenerators.Count == 0 && m_mobNameGenerators.Count == 0 && m_globalGenerators.Count == 0)
            {
                ILootGenerator baseGenerator = new LootGeneratorMoney();
                RegisterLootGenerator(baseGenerator, null, null, null, 0);
                if (log.IsInfoEnabled)
                {
                    log.Info("No LootGenerator found, adding LootGeneratorMoney for all mobs as default.");
                }
            }

            if (log.IsInfoEnabled)
            {
                log.Info("LootGenerator initialized: true");
            }
            return(true);
        }