AddMonster() публичный Метод

public AddMonster ( MapMonster monster ) : void
monster MapMonster
Результат void
        public static void Initialize()
        {
            XPRate = int.Parse(System.Configuration.ConfigurationManager.AppSettings["RateXp"]);

            DropRate = int.Parse(System.Configuration.ConfigurationManager.AppSettings["RateDrop"]);

            GoldRate = int.Parse(System.Configuration.ConfigurationManager.AppSettings["RateGold"]);

            FairyXpRate = int.Parse(System.Configuration.ConfigurationManager.AppSettings["RateFairyXp"]);

            foreach (ItemDTO itemDTO in DAOFactory.ItemDAO.LoadAll())
            {
                Item ItemGO = null;

                switch (itemDTO.ItemType)
                {
                case (byte)Domain.ItemType.Ammo:
                    ItemGO = _mapper.Map <NoFunctionItem>(itemDTO);
                    break;

                case (byte)Domain.ItemType.Armor:
                    ItemGO = _mapper.Map <WearableItem>(itemDTO);
                    break;

                case (byte)Domain.ItemType.Box:
                    ItemGO = _mapper.Map <BoxItem>(itemDTO);
                    break;

                case (byte)Domain.ItemType.Event:
                    ItemGO = _mapper.Map <MagicalItem>(itemDTO);
                    break;

                case (byte)Domain.ItemType.Fashion:
                    ItemGO = _mapper.Map <WearableItem>(itemDTO);
                    break;

                case (byte)Domain.ItemType.Food:
                    ItemGO = _mapper.Map <FoodItem>(itemDTO);
                    break;

                case (byte)Domain.ItemType.Jewelery:
                    ItemGO = _mapper.Map <WearableItem>(itemDTO);
                    break;

                case (byte)Domain.ItemType.Magical:
                    ItemGO = _mapper.Map <MagicalItem>(itemDTO);
                    break;

                case (byte)Domain.ItemType.Main:
                    ItemGO = _mapper.Map <NoFunctionItem>(itemDTO);
                    break;

                case (byte)Domain.ItemType.Map:
                    ItemGO = _mapper.Map <NoFunctionItem>(itemDTO);
                    break;

                case (byte)Domain.ItemType.Part:
                    ItemGO = _mapper.Map <NoFunctionItem>(itemDTO);
                    break;

                case (byte)Domain.ItemType.Potion:
                    ItemGO = _mapper.Map <PotionItem>(itemDTO);
                    break;

                case (byte)Domain.ItemType.Production:
                    ItemGO = _mapper.Map <ProduceItem>(itemDTO);
                    break;

                case (byte)Domain.ItemType.Quest1:
                    ItemGO = _mapper.Map <NoFunctionItem>(itemDTO);
                    break;

                case (byte)Domain.ItemType.Quest2:
                    ItemGO = _mapper.Map <NoFunctionItem>(itemDTO);
                    break;

                case (byte)Domain.ItemType.Sell:
                    ItemGO = _mapper.Map <NoFunctionItem>(itemDTO);
                    break;

                case (byte)Domain.ItemType.Shell:
                    ItemGO = _mapper.Map <MagicalItem>(itemDTO);
                    break;

                case (byte)Domain.ItemType.Snack:
                    ItemGO = _mapper.Map <SnackItem>(itemDTO);
                    break;

                case (byte)Domain.ItemType.Special:
                    ItemGO = _mapper.Map <SpecialItem>(itemDTO);
                    break;

                case (byte)Domain.ItemType.Specialist:
                    ItemGO = _mapper.Map <WearableItem>(itemDTO);
                    break;

                case (byte)Domain.ItemType.Teacher:
                    ItemGO = _mapper.Map <TeacherItem>(itemDTO);
                    break;

                case (byte)Domain.ItemType.Upgrade:
                    ItemGO = _mapper.Map <UpgradeItem>(itemDTO);
                    break;

                case (byte)Domain.ItemType.Weapon:
                    ItemGO = _mapper.Map <WearableItem>(itemDTO);
                    break;

                default:
                    ItemGO = _mapper.Map <NoFunctionItem>(itemDTO);
                    break;
                }
                _items.Add(ItemGO);
            }

            Logger.Log.Info(String.Format(Language.Instance.GetMessageFromKey("ITEM_LOADED"), _items.Count()));
            foreach (SkillDTO skillDTO in DAOFactory.SkillDAO.LoadAll())
            {
                Skill skill = _mapper.Map <Skill>(skillDTO);
                foreach (ComboDTO com in DAOFactory.ComboDAO.LoadBySkillVnum(skill.SkillVNum).ToList())
                {
                    skill.Combos.Add(_mapper.Map <ComboDTO>(com));
                }
                _skills.Add(skill);
            }
            foreach (NpcMonsterDTO npcmonsterDTO in DAOFactory.NpcMonsterDAO.LoadAll())
            {
                _npcs.Add(_mapper.Map <NpcMonster>(npcmonsterDTO));
            }
            Logger.Log.Info(String.Format(Language.Instance.GetMessageFromKey("NPCMONSTERS_LOADED"), _npcs.Count()));

            try
            {
                int i            = 0;
                int npccount     = 0;
                int recipescount = 0;
                int shopcount    = 0;
                int monstercount = 0;
                foreach (MapDTO map in DAOFactory.MapDAO.LoadAll())
                {
                    Guid guid   = Guid.NewGuid();
                    Map  newMap = new Map(Convert.ToInt16(map.MapId), guid, map.Data);
                    newMap.Music       = map.Music;
                    newMap.ShopAllowed = map.ShopAllowed;

                    // register for broadcast
                    _maps.TryAdd(guid, newMap);
                    i++;
                    npccount += newMap.Npcs.Count();

                    foreach (MapMonster n in newMap.Monsters)
                    {
                        newMap.AddMonster(n);
                    }
                    monstercount += newMap.Monsters.Count();
                    foreach (MapNpc n in newMap.Npcs.Where(n => n.Shop != null))
                    {
                        shopcount++;
                    }
                    foreach (MapNpc npcs in newMap.Npcs)
                    {
                        foreach (Recipe recipies in npcs.Recipes)
                        {
                            recipescount++;
                        }
                    }
                }
                if (i != 0)
                {
                    Logger.Log.Info(String.Format(Language.Instance.GetMessageFromKey("MAP_LOADED"), i));
                }
                else
                {
                    Logger.Log.Error(Language.Instance.GetMessageFromKey("NO_MAP"));
                }
                Logger.Log.Info(String.Format(Language.Instance.GetMessageFromKey("SKILLS_LOADED"), _skills.Count()));
                Logger.Log.Info(String.Format(Language.Instance.GetMessageFromKey("MONSTERS_LOADED"), monstercount));
                Logger.Log.Info(String.Format(Language.Instance.GetMessageFromKey("NPCS_LOADED"), npccount));
                Logger.Log.Info(String.Format(Language.Instance.GetMessageFromKey("SHOPS_LOADED"), shopcount));
                Logger.Log.Info(String.Format(Language.Instance.GetMessageFromKey("RECIPES_LOADED"), recipescount));
            }
            catch (Exception ex)
            {
                Logger.Log.Error("General Error", ex);
            }
        }
Пример #2
0
        public void Initialize()
        {
            // parse rates
            XPRate      = int.Parse(System.Configuration.ConfigurationManager.AppSettings["RateXp"]);
            DropRate    = int.Parse(System.Configuration.ConfigurationManager.AppSettings["RateDrop"]);
            GoldRate    = int.Parse(System.Configuration.ConfigurationManager.AppSettings["RateGold"]);
            FairyXpRate = int.Parse(System.Configuration.ConfigurationManager.AppSettings["RateFairyXp"]);

            // load explicite type of ItemDTO
            foreach (ItemDTO itemDTO in DAOFactory.ItemDAO.LoadAll())
            {
                Item ItemGO = null;

                switch (itemDTO.ItemType)
                {
                case ItemType.Ammo:
                    ItemGO = new NoFunctionItem(itemDTO);
                    break;

                case ItemType.Armor:
                    ItemGO = new WearableItem(itemDTO);
                    break;

                case ItemType.Box:
                    ItemGO = new BoxItem(itemDTO);
                    break;

                case ItemType.Event:
                    ItemGO = new MagicalItem(itemDTO);
                    break;

                case ItemType.Fashion:
                    ItemGO = new WearableItem(itemDTO);
                    break;

                case ItemType.Food:
                    ItemGO = new FoodItem(itemDTO);
                    break;

                case ItemType.Jewelery:
                    ItemGO = new WearableItem(itemDTO);
                    break;

                case ItemType.Magical:
                    ItemGO = new MagicalItem(itemDTO);
                    break;

                case ItemType.Main:
                    ItemGO = new NoFunctionItem(itemDTO);
                    break;

                case ItemType.Map:
                    ItemGO = new NoFunctionItem(itemDTO);
                    break;

                case ItemType.Part:
                    ItemGO = new NoFunctionItem(itemDTO);
                    break;

                case ItemType.Potion:
                    ItemGO = new PotionItem(itemDTO);
                    break;

                case ItemType.Production:
                    ItemGO = new ProduceItem(itemDTO);
                    break;

                case ItemType.Quest1:
                    ItemGO = new NoFunctionItem(itemDTO);
                    break;

                case ItemType.Quest2:
                    ItemGO = new NoFunctionItem(itemDTO);
                    break;

                case ItemType.Sell:
                    ItemGO = new NoFunctionItem(itemDTO);
                    break;

                case ItemType.Shell:
                    ItemGO = new MagicalItem(itemDTO);
                    break;

                case ItemType.Snack:
                    ItemGO = new SnackItem(itemDTO);
                    break;

                case ItemType.Special:
                    ItemGO = new SpecialItem(itemDTO);
                    break;

                case ItemType.Specialist:
                    ItemGO = new WearableItem(itemDTO);
                    break;

                case ItemType.Teacher:
                    ItemGO = new TeacherItem(itemDTO);
                    break;

                case ItemType.Upgrade:
                    ItemGO = new UpgradeItem(itemDTO);
                    break;

                case ItemType.Weapon:
                    ItemGO = new WearableItem(itemDTO);
                    break;

                default:
                    ItemGO = new NoFunctionItem(itemDTO);
                    break;
                }
                _items.Add(ItemGO);
            }
            Logger.Log.Info(String.Format(Language.Instance.GetMessageFromKey("ITEMS_LOADED"), _items.Count()));

            // intialize monsterdrops
            _monsterDrops = new ThreadSafeSortedList <short, List <DropDTO> >();
            foreach (var monsterDropGrouping in DAOFactory.DropDAO.LoadAll().GroupBy(d => d.MonsterVNum))
            {
                if (monsterDropGrouping.Key.HasValue)
                {
                    _monsterDrops[monsterDropGrouping.Key.Value] = monsterDropGrouping.OrderBy(d => d.DropChance).ToList();
                }
                else
                {
                    _generalDrops = monsterDropGrouping.ToList();
                }
            }
            Logger.Log.Info(String.Format(Language.Instance.GetMessageFromKey("DROPS_LOADED"), _monsterDrops.GetAllItems().Sum(i => i.Count())));

            // initialiize monsterskills
            _monsterSkills = new ThreadSafeSortedList <short, List <NpcMonsterSkill> >();
            foreach (var monsterSkillGrouping in DAOFactory.NpcMonsterSkillDAO.LoadAll().GroupBy(n => n.NpcMonsterVNum))
            {
                _monsterSkills[monsterSkillGrouping.Key] = monsterSkillGrouping.Select(n => n as NpcMonsterSkill).ToList();
            }
            Logger.Log.Info(String.Format(Language.Instance.GetMessageFromKey("MONSTERSKILLS_LOADED"), _monsterSkills.GetAllItems().Sum(i => i.Count())));

            // initialize npcmonsters
            foreach (NpcMonsterDTO npcmonsterDTO in DAOFactory.NpcMonsterDAO.LoadAll())
            {
                _npcs.Add(npcmonsterDTO as NpcMonster);
            }
            Logger.Log.Info(String.Format(Language.Instance.GetMessageFromKey("NPCMONSTERS_LOADED"), _npcs.Count()));

            // intialize receipes
            _recipes = new ThreadSafeSortedList <int, List <Recipe> >();
            foreach (var recipeGrouping in DAOFactory.RecipeDAO.LoadAll().GroupBy(r => r.MapNpcId))
            {
                _recipes[recipeGrouping.Key] = recipeGrouping.Select(r => r as Recipe).ToList();
            }
            Logger.Log.Info(String.Format(Language.Instance.GetMessageFromKey("RECIPES_LOADED"), _recipes.GetAllItems().Sum(i => i.Count())));

            // initialize shopitems
            _shopItems = new ThreadSafeSortedList <int, List <ShopItemDTO> >();
            foreach (var shopItemGrouping in DAOFactory.ShopItemDAO.LoadAll().GroupBy(s => s.ShopId))
            {
                _shopItems[shopItemGrouping.Key] = shopItemGrouping.ToList();
            }
            Logger.Log.Info(String.Format(Language.Instance.GetMessageFromKey("SHOPITEMS_LOADED"), _shopItems.GetAllItems().Sum(i => i.Count())));

            // initialize shopskills
            _shopSkills = new ThreadSafeSortedList <int, List <ShopSkillDTO> >();
            foreach (var shopSkillGrouping in DAOFactory.ShopSkillDAO.LoadAll().GroupBy(s => s.ShopId))
            {
                _shopSkills[shopSkillGrouping.Key] = shopSkillGrouping.ToList();
            }
            Logger.Log.Info(String.Format(Language.Instance.GetMessageFromKey("SHOPSKILLS_LOADED"), _shopSkills.GetAllItems().Sum(i => i.Count())));

            // initialize shops
            _shops = new ThreadSafeSortedList <int, Shop>();
            foreach (var shopGrouping in DAOFactory.ShopDAO.LoadAll())
            {
                _shops[shopGrouping.MapNpcId] = shopGrouping as Shop;
            }
            Logger.Log.Info(String.Format(Language.Instance.GetMessageFromKey("SHOPS_LOADED"), _shops.GetAllItems().Count()));

            // initialize teleporters
            _teleporters = new ThreadSafeSortedList <int, List <TeleporterDTO> >();
            foreach (var teleporterGrouping in DAOFactory.TeleporterDAO.LoadAll().GroupBy(t => t.MapNpcId))
            {
                _teleporters[teleporterGrouping.Key] = teleporterGrouping.Select(t => t).ToList();
            }
            Logger.Log.Info(String.Format(Language.Instance.GetMessageFromKey("TELEPORTERS_LOADED"), _teleporters.GetAllItems().Sum(i => i.Count())));

            // initialize skills
            foreach (SkillDTO skillDTO in DAOFactory.SkillDAO.LoadAll())
            {
                Skill skill = skillDTO as Skill;
                skill.Combos.AddRange(DAOFactory.ComboDAO.LoadBySkillVnum(skill.SkillVNum).ToList());
                _skills.Add(skill);
            }
            Logger.Log.Info(String.Format(Language.Instance.GetMessageFromKey("SKILLS_LOADED"), _skills.Count()));

            // intialize mapnpcs
            _mapNpcs = new ThreadSafeSortedList <short, List <MapNpc> >();
            foreach (var mapNpcGrouping in DAOFactory.MapNpcDAO.LoadAll().GroupBy(t => t.MapId))
            {
                _mapNpcs[mapNpcGrouping.Key] = mapNpcGrouping.Select(t => t as MapNpc).ToList();
            }
            Logger.Log.Info(String.Format(Language.Instance.GetMessageFromKey("MAPNPCS_LOADED"), _mapNpcs.GetAllItems().Sum(i => i.Count())));

            try
            {
                int i            = 0;
                int monstercount = 0;

                foreach (MapDTO map in DAOFactory.MapDAO.LoadAll())
                {
                    Guid guid   = Guid.NewGuid();
                    Map  newMap = new Map(map.MapId, guid, map.Data);
                    newMap.Music       = map.Music;
                    newMap.ShopAllowed = map.ShopAllowed;

                    // register for broadcast
                    _maps.TryAdd(guid, newMap);
                    newMap.SetMapMapMonsterReference();
                    newMap.SetMapMapNpcReference();
                    i++;

                    newMap.LoadMonsters();
                    foreach (MapMonster mapMonster in newMap.Monsters)
                    {
                        mapMonster.Map = newMap;
                        newMap.AddMonster(mapMonster);
                    }
                    monstercount += newMap.Monsters.Count();
                }
                if (i != 0)
                {
                    Logger.Log.Info(String.Format(Language.Instance.GetMessageFromKey("MAPS_LOADED"), i));
                }
                else
                {
                    Logger.Log.Error(Language.Instance.GetMessageFromKey("NO_MAP"));
                }
                Logger.Log.Info(String.Format(Language.Instance.GetMessageFromKey("MAPMONSTERS_LOADED"), monstercount));
            }
            catch (Exception ex)
            {
                Logger.Log.Error("General Error", ex);
            }
        }