SetMapMapNpcReference() public method

public SetMapMapNpcReference ( ) : void
return void
コード例 #1
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);
            }
        }