Beispiel #1
0
        private int sectorWidth = 800; //default

        #endregion Fields

        #region Constructors

        public Map(MapInfo info, BlockInfo block, short instanceID)
        {
            this.MapInfo = info;
            this.Block = block;
            this.InstanceID = instanceID;
            this.Objects = new ConcurrentDictionary<ushort, MapObject>();
            this.Drops = new ConcurrentDictionary<ushort, Drop>();
            Load();
        }
Beispiel #2
0
        public void LoadMaps(List<ushort> toload = null)
        {
            MapsByID = new Dictionary<ushort, MapInfo>();
            MapsByName = new Dictionary<string, MapInfo>();
            using (var file = new SHNFile(folder + @"\MapInfo.shn"))
            {
                using (DataTableReaderEx reader = new DataTableReaderEx(file))
                {
                    while (reader.Read())
                    {
                        MapInfo info = MapInfo.Load(reader);
                        info.NPCs = new List<ShineNPC>();
                        if (MapsByID.ContainsKey(info.ID))
                        {
                            Log.WriteLine(LogLevel.Debug, "Duplicate map ID {0} ({1})", info.ID, info.FullName);
                            MapsByID.Remove(info.ID);
                            MapsByName.Remove(info.ShortName);
                        }
                        if (toload == null || toload.Contains(info.ID))
                        {
                            MapsByID.Add(info.ID, info);
                            MapsByName.Add(info.ShortName, info);
                        }
                    }
                }
            }

            Blocks = new Dictionary<ushort, BlockInfo>();
            foreach (var map in MapsByID.Values)
            {
                string renderpath = folder + @"\BlockInfo\" + map.ShortName + ".shbd";
                if (File.Exists(renderpath))
                {
                    BlockInfo info = new BlockInfo(renderpath, map.ID);
                    Blocks.Add(map.ID, info);
                }
            }

            using (var tables = new ShineReader(folder + @"\NPC.txt"))
            {
                NpcLinkTable = new Dictionary<string, LinkTable>();
                using (DataTableReaderEx reader = new DataTableReaderEx(tables["LinkTable"]))
                {
                    while (reader.Read())
                    {
                        LinkTable link = LinkTable.Load(reader);
                        if (Program.IsLoaded(GetMapidFromMapShortName(link.MapClient)))
                        {
                            NpcLinkTable.Add(link.argument, link);
                        }
                    }
                }

                using (DataTableReaderEx reader = new DataTableReaderEx(tables["ShineNPC"]))
                {
                    ShineNpcTable = new Dictionary<string, string>();
                    while (reader.Read())
                    {
                        ShineNPC npc = ShineNPC.Load(reader);
                        MapInfo mi = null;
                        if (Program.IsLoaded(GetMapidFromMapShortName(npc.Map)) && MapsByName.TryGetValue(npc.Map, out mi))
                        {
                            mi.NPCs.Add(npc);
                            try
                            {
                                ShineNpcTable.Add(npc.MobName + "\t" + npc.Map + "\t" + npc.Coord_X + "\t" + npc.Coord_Y, npc.Direct + "\t" + npc.NPCMenu + "\t" + npc.Role + "\t" + npc.RoleArg0);
                            }
                            catch(Exception ex)
                            {
                                Log.WriteLine(LogLevel.Exception, "ShineNPCTable :: {1} for {1} M: {2}", ex.Message, npc.MobName, npc.Map);
                            }
                        }
                    }
                }
            }

            Log.WriteLine(LogLevel.Info, "Loaded {0} maps.", MapsByID.Count);
        }
Beispiel #3
0
        public void LoadMaps(List<ushort> toload = null)
        {
            MapsByID = new Dictionary<ushort, MapInfo>();
            MapsByName = new Dictionary<string, MapInfo>();
            DataTable mapDataInf = null;
            DataTable linktableData = null;
            DataTable shineNpcData = null;
            using (DatabaseClient dbClient = Program.DatabaseManager.GetClient())
            {
                mapDataInf = dbClient.ReadDataTable("SELECT  *FROM mapinfo");
                linktableData = dbClient.ReadDataTable("SELECT *FROM LinkTable");
                shineNpcData = dbClient.ReadDataTable("SELECT *FROM ShineNpc");
            }
            if (mapDataInf != null)
            {
                foreach (DataRow row in mapDataInf.Rows)
                {
                    MapInfo info = MapInfo.Load(row);
                    info.NPCs = new List<ShineNpc>();
                    if (MapsByID.ContainsKey(info.ID))
                    {
                        Log.WriteLine(LogLevel.Debug, "Duplicate map ID {0} ({1})", info.ID, info.FullName);
                        MapsByID.Remove(info.ID);
                        MapsByName.Remove(info.ShortName);
                    }
                    if (toload == null || toload.Contains(info.ID))
                    {
                        MapsByID.Add(info.ID, info);
                        MapsByName.Add(info.ShortName, info);
                    }
                }
            }
            Blocks = new Dictionary<ushort, BlockInfo>();
            foreach (var map in MapsByID.Values)
            {
                DataTable blockData = null;
                using (DatabaseClient dbClient = Program.DatabaseManager.GetClient())
                {
                    blockData = dbClient.ReadDataTable("SELECT  *FROM blockinfo WHERE MapID='" + map.ID + "'");
                }
                if (blockData != null)
                {
                    if (blockData.Rows.Count > 0)
                    {
                        foreach (DataRow row in blockData.Rows)
                        {
                            BlockInfo info = new BlockInfo(row, map.ID);

                            Blocks.Add(map.ID, info);
                        }
                    }
                    else
                    {
                        Log.WriteLine(LogLevel.Warn, "No BlockInfo for Map {0}", map.ShortName);
                    }
                }
            }
            NpcLinkTable = new Dictionary<string, LinkTable>();
            if (linktableData != null)
            {
                foreach (DataRow row in linktableData.Rows)
                {
                    LinkTable link = LinkTable.Load(row);
                    if (Program.IsLoaded(GetMapidFromMapShortName(link.MapClient)))
                    {
                        NpcLinkTable.Add(link.argument, link);
                    }
                }
            }
            if (shineNpcData != null)
            {
                foreach (DataRow row in shineNpcData.Rows)
                {
                    ShineNpc npc = ShineNpc.Load(row);
                    MapInfo mi = null;
                    if (Program.IsLoaded(GetMapidFromMapShortName(npc.Map)) && MapsByName.TryGetValue(npc.Map, out mi))
                    {

                        mi.NPCs.Add(npc);
                    }
                }
            }
            Log.WriteLine(LogLevel.Info, "Loaded {0} maps.", MapsByID.Count);
        }