コード例 #1
0
        public T ReadObject <T>(params object[] keys) where T : class
        {
            if (!DoesHandleType(typeof(T)))
            {
                throw new ArgumentException("typeof(T)");
            }

            if (m_map != null)
            {
                return(m_map as T);
            }

            if (keys.Length <= 0 || keys.Length > 2 || !(keys[0] is IConvertible) || (keys.Length == 2 && !(keys[1] is string)))
            {
                throw new ArgumentException("DLMSource needs a int key and can have a decryptionKey as string, use ReadObject(int) or ReadObject(int, string)");
            }


            int id = Convert.ToInt32(keys[0]);

            if (keys[1] is string)
            {
                m_reader.DecryptionKey = (string)keys[1];
            }

            m_map = m_reader.ReadMap();

            if (m_map.Id != id)
            {
                throw new ArgumentException("id != map.id");
            }

            return(m_map as T);
        }
コード例 #2
0
ファイル: MapRecord.cs プロジェクト: Mixi59/Stump
        public MapRecord(DlmMap map)
        {
            Id = map.Id;

            Id                      = map.Id;
            Version                 = map.Version;
            RelativeId              = map.RelativeId;
            MapType                 = map.MapType;
            SubAreaId               = map.SubAreaId;
            ClientTopNeighbourId    = map.TopNeighbourId;
            ClientBottomNeighbourId = map.BottomNeighbourId;
            ClientLeftNeighbourId   = map.LeftNeighbourId;
            ClientRightNeighbourId  = map.RightNeighbourId;
            ShadowBonusOnEntities   = map.ShadowBonusOnEntities;
            UseLowpassFilter        = map.UseLowPassFilter;
            UseReverb               = map.UseReverb;
            PresetId                = map.PresetId;
            Cells                   =
                map.Cells.Select(
                    x =>
                    new Cell
            {
                Id            = x.Id,
                Floor         = x.Floor,
                Data          = x.Data,
                MapChangeData = x.MapChangeData,
                MoveZone      = x.MoveZone,
                Speed         = x.Speed
            }).ToArray();
            bool any = Cells.Any(x => x.Walkable);

            BeforeSave(false);
        }
コード例 #3
0
        public static Map FromDlm(DlmMap dlmMap)
        {
            Map map = new Map();

            map.Id        = dlmMap.Id;
            map.SubAreaId = (ushort)dlmMap.SubAreaId;
            map.TopMap    = dlmMap.TopNeighbourId;
            map.DownMap   = dlmMap.BottomNeighbourId;
            map.LeftMap   = dlmMap.LeftNeighbourId;
            map.RightMap  = dlmMap.RightNeighbourId;

            map.BlueCells = dlmMap.Cells.Where(x => x.Blue).ToList().ConvertAll <short>(x => x.Id);
            map.RedCells  = dlmMap.Cells.Where(x => x.Red).ToList().ConvertAll <short>(x => x.Id);

            map.Version = dlmMap.Version;

            map.CellsLosMov = new Dictionary <short, short>();

            foreach (var cell in dlmMap.Cells)
            {
                map.CellsLosMov.Add(cell.Id, cell.LosMov);
            }

            return(map);
        }
コード例 #4
0
        public Map(int id, string decryptionKey)
        {
            // decryption key not used ? oO
            m_map = DataProvider.Instance.Get <DlmMap>(id, GenericDecryptionKey);
            IEnumerable <Cell> cells = m_map.Cells.Select(entry => new Cell(this, entry));

            Cells = new CellList(cells.ToArray());
        }
コード例 #5
0
        public Map(int id, string decryptionKey)
        {
            // decryption key not used ? oO
            m_map      = MapsManager.Instance.GetDlmMap(id, GenericDecryptionKey);
            m_position = ObjectDataManager.Instance.GetOrDefault <MapPosition>(id);
            IEnumerable <Cell> cells = m_map.Cells.Select(entry => new Cell(this, entry));

            m_cells = new CellList(cells.ToArray());

            InitializeElements();
            LoadSubMaps();

            m_interactives         = new ObservableCollectionMT <InteractiveObject>();
            m_readOnlyInteractives = new ReadOnlyObservableCollectionMT <InteractiveObject>(m_interactives);
        }
コード例 #6
0
ファイル: Helper.cs プロジェクト: Zaetic/Symbioz-2.38-RED
        public static void GetElements(DlmMap map, Elements elements, out List <MapInteractiveElement> interactiveElements)
        {
            interactiveElements = new List <MapInteractiveElement>();
            foreach (var layer in map.Layers)
            {
                foreach (var cell in layer.Cells)
                {
                    foreach (var element in cell.Elements)
                    {
                        if (element is DlmGraphicalElement)
                        {
                            DlmGraphicalElement graphicalElement = element as DlmGraphicalElement;

                            if (graphicalElement.Identifier != 0)
                            {
                                var gfxElement = elements.ReadElement((int)graphicalElement.ElementId);

                                if (gfxElement.Type != EleGraphicalElementTypes.ENTITY)
                                {
                                    NormalGraphicalElementData normalElement    = gfxElement as NormalGraphicalElementData;
                                    MapInteractiveElement      interactiveTable = new MapInteractiveElement();
                                    interactiveTable.ElementId = (int)graphicalElement.Identifier;
                                    interactiveTable.MapId     = map.Id;
                                    interactiveTable.CellId    = (ushort)cell.Id;
                                    if (normalElement != null)
                                    {
                                        interactiveTable.GfxId = normalElement.Gfx;
                                    }
                                    interactiveTable.GfxBonesId = -1;
                                    interactiveElements.Add(interactiveTable);
                                }
                                else
                                {
                                    EntityGraphicalElementData entityElement    = gfxElement as EntityGraphicalElementData;
                                    MapInteractiveElement      interactiveTable = new MapInteractiveElement();
                                    interactiveTable.ElementId  = (int)graphicalElement.Identifier;
                                    interactiveTable.MapId      = map.Id;
                                    interactiveTable.CellId     = (ushort)cell.Id;
                                    interactiveTable.GfxBonesId = ushort.Parse(entityElement.EntityLook.Replace("{", "").Replace("}", ""));
                                    interactiveTable.GfxId      = -1;
                                    interactiveElements.Add(interactiveTable);
                                }
                            }
                        }
                    }
                }
            }
        }
コード例 #7
0
        public MapData(DlmMap map, MapPosition position = null)
        {
            Id                = map.Id;
            Version           = map.Version;
            Encrypted         = map.Encrypted;
            EncryptionVersion = map.EncryptionVersion;
            RelativeId        = map.RelativeId;
            MapType           = map.MapType;
            SubAreaId         = map.SubAreaId;
            BottomNeighbourId = map.BottomNeighbourId;
            LeftNeighbourId   = map.LeftNeighbourId;
            RightNeighbourId  = map.RightNeighbourId;
            TopNeighbourId    = map.TopNeighbourId;
            Cells             = new CellDataList(map.Cells.Select(x => new CellData(x)).ToArray());
            if (position != null)
            {
                X        = position.posX;
                Y        = position.posY;
                WorldMap = position.worldMap;
                Outdoor  = position.outdoor;
            }
            else
            {
                X        = (Id & 0x3FE00) >> 9; // 9 higher bits
                Y        = Id & 0x01FF;         // 9 lower bits
                WorldMap = Id & 0x3FFC0000 >> 18;

                if ((X & 0x100) == 0x100) // 9th bit is the sign. 1 means it's minus
                {
                    X = -(X & 0xFF);      // just take the 8 first bits and take the opposite number
                }
                if ((Y & 0x100) == 0x100) // 9th bit is the sign. 1 means it's minus
                {
                    Y = -(Y & 0xFF);      // just take the 8 first bits and take the opposite number
                }
            }
        }
コード例 #8
0
 public IdentifiableElement(DlmGraphicalElement element, DlmMap map)
 {
     Element = element;
     Map     = map;
 }
コード例 #9
0
        public static void LoadSpawns()
        {
            // Since 2.36 version there is the same interactive on different maps because of the 16/9 mode, we have to find the correct one

            Console.WriteLine("Generating interactive spawns");
            var worldDatabase = Program.ConnectToWorld();

            if (worldDatabase == null)
            {
                return;
            }

            worldDatabase.Database.Execute("DELETE FROM interactives_spawns");
            worldDatabase.Database.Execute("ALTER TABLE interactives_spawns AUTO_INCREMENT=1");
            string eleFilePath  = Path.Combine(Program.FindDofusPath(), "content", "maps", "elements.ele");
            string mapsfilePath = Path.Combine(Program.FindDofusPath(), "content", "maps", "maps0.d2p");

            var eleFile                   = new EleReader(eleFilePath);
            var eleInstance               = eleFile.ReadElements();
            var d2pFile                   = new D2pFile(mapsfilePath);
            var entries                   = d2pFile.ReadAllFiles();
            var i                         = 0;
            var ids                       = new List <int>();
            var failures                  = new List <int>();
            var spawns                    = new Dictionary <int, InteractiveSpawn>();
            var elementsGlobal            = new Dictionary <int, DlmGraphicalElement>();
            var identifiableElementsByMap = new Dictionary <int, List <IdentifiableElement> >();

            int fails = 0;

            Console.WriteLine("Loading maps ... ");
            Program.InitializeCounter();
            foreach (var mapBytes in entries.Values)
            {
                DlmReader mapFile;
                DlmMap    map = null;
                try
                {
                    mapFile = new DlmReader(mapBytes)
                    {
                        DecryptionKey = Program.MapDecryptionKey
                    };
                    map = mapFile.ReadMap();
                }
                catch (Exception)
                {
                    fails++;
                    continue;
                }
                var elements = (from layer in map.Layers
                                from cell in layer.Cells
                                from element in cell.Elements.OfType <DlmGraphicalElement>()
                                where element.Identifier != 0
                                let point = new MapPoint(cell.Id)
                                            select new IdentifiableElement(element, map)).ToList();

                identifiableElementsByMap.Add(map.Id, elements);
                Program.UpdateCounter(i++, entries.Count);
            }
            Program.EndCounter();

            var identifiableElements = identifiableElementsByMap.Values.SelectMany(x => x).
                                       GroupBy(x => x.Element.Identifier).ToDictionary(x => x.Key, x => x.ToList());


            Program.InitializeCounter();
            i = 0;
            // every elements grouped by the same id
            foreach (var keyPair in identifiableElements)
            {
                var likelyElement = keyPair.Value.Where(x => !x.Ignore)
                                    .OrderByDescending(x => DistanceFromBorder(new MapPoint(x.Element.Cell.Id)))
                                    .ThenBy(x => Math.Abs(x.Element.PixelOffset.X) + Math.Abs(x.Element.PixelOffset.Y)).First();


                var eleElement = eleInstance.GraphicalDatas[(int)likelyElement.Element.ElementId];
                InteractiveSpawn spawn;

                spawn = new InteractiveSpawn
                {
                    Id        = (int)likelyElement.Element.Identifier,
                    MapId     = likelyElement.Map.Id,
                    CellId    = likelyElement.Element.Cell.Id,
                    Animated  = eleElement is AnimatedGraphicalElementData || eleElement is EntityGraphicalElementData,
                    ElementId = (int)likelyElement.Element.ElementId
                };

                if (ids.Contains(spawn.Id))
                {
                    Console.WriteLine($"Id {spawn.Id} already added");
                    failures.Add(spawn.Id);
                    continue;
                }

                ids.Add(spawn.Id);
                worldDatabase.Database.Insert("interactives_spawns", "Id", false, spawn);
                spawns.Add(spawn.Id, spawn);
                elementsGlobal.Add(spawn.Id, likelyElement.Element);

                Program.UpdateCounter(i++, identifiableElements.Count);
            }

            Program.EndCounter();

            if (fails > 0)
            {
                Console.WriteLine($"{fails} failes !");
            }

            Program.ExecutePatch("./Patchs/interactives_spawns_patch.sql", worldDatabase.Database);
        }