Ejemplo n.º 1
0
        public static void Serialize(XmlWriter xWrite, Map contents)
        {
            XmlSerializer           Writer = new XmlSerializer(contents.GetType());
            XmlSerializerNamespaces ns     = new XmlSerializerNamespaces();

            ns.Add("", "http://www.hybrasyl.com/XML/Maps");
            Writer.Serialize(xWrite, contents, ns);
        }
Ejemplo n.º 2
0
        public static Map Deserialize(XmlReader reader, Map contents = null)
        {
            //reader.Settings.IgnoreWhitespace = false;
            if (contents == null)
            {
                contents = new Map();
            }
            XmlSerializer XmlSerial = new XmlSerializer(contents.GetType());

            if (XmlSerial.CanDeserialize(reader))
            {
                var xContents = XmlSerial.Deserialize(reader);
                contents = (Map)xContents;
            }
            return(contents);
        }
Ejemplo n.º 3
0
        /// <summary>
        /// Create a new Hybrasyl map from an XMLMap object.
        /// </summary>
        /// <param name="newMap">An XSD.Map object representing the XML map file.</param>
        /// <param name="theWorld">A world object where the map will be placed</param>
        public Map(Maps.Map newMap, World theWorld)
        {
            Init();
            World = theWorld;

            // TODO: refactor Map class to not do this, but be a partial which overlays
            // TODO: XSD.Map
            Id         = newMap.Id;
            X          = newMap.X;
            Y          = newMap.Y;
            Name       = newMap.Name;
            EntityTree = new QuadTree <VisibleObject>(0, 0, X, Y);
            Music      = newMap.Music;

            foreach (var warpElement in newMap.Warps)
            {
                var warp = new Warp(this);
                warp.X = warpElement.X;
                warp.Y = warpElement.Y;

                if (warpElement.MapTarget != null)
                {
                    var maptarget = warpElement.MapTarget as Maps.WarpMapTarget;
                    // map warp
                    warp.DestinationMapName = maptarget.Value;
                    warp.WarpType           = WarpType.Map;
                    warp.DestinationX       = maptarget.X;
                    warp.DestinationY       = maptarget.Y;
                }
                else
                {
                    var worldmaptarget = warpElement.WorldMapTarget;
                    // worldmap warp
                    warp.DestinationMapName = worldmaptarget;
                    warp.WarpType           = WarpType.WorldMap;
                }
                if (warpElement.Restrictions?.Level != null)
                {
                    warp.MinimumLevel = warpElement.Restrictions.Level.Min;
                    warp.MaximumLevel = warpElement.Restrictions.Level.Max;
                }
                if (warpElement.Restrictions?.Ab != null)
                {
                    warp.MinimumAbility = warpElement.Restrictions.Ab.Min;
                    warp.MaximumAbility = warpElement.Restrictions.Ab.Max;
                }
                warp.MobUse = warpElement.Restrictions?.NoMobUse ?? true;
                Warps[new Tuple <byte, byte>(warp.X, warp.Y)] = warp;
            }

            foreach (var npcElement in newMap.Npcs)
            {
                var npcTemplate = World.WorldData.Get <Creatures.Npc>(npcElement.Name);
                if (npcTemplate == null)
                {
                    Logger.Error("map ${Name}: NPC ${npcElement.Name} is missing, will not be loaded");
                    continue;
                }
                var merchant = new Merchant
                {
                    X         = npcElement.X,
                    Y         = npcElement.Y,
                    Name      = npcElement.Name,
                    Sprite    = npcTemplate.Appearance.Sprite,
                    Direction = (Enums.Direction)npcElement.Direction,
                    Portrait  = npcTemplate.Appearance.Portrait,
                };
                if (npcTemplate.Roles != null)
                {
                    if (npcTemplate.Roles.Post != null)
                    {
                        merchant.Jobs ^= MerchantJob.Post;
                    }
                    if (npcTemplate.Roles.Bank != null)
                    {
                        merchant.Jobs ^= MerchantJob.Bank;
                    }
                    if (npcTemplate.Roles.Repair != null)
                    {
                        merchant.Jobs ^= MerchantJob.Repair;
                    }
                    if (npcTemplate.Roles.Train != null)
                    {
                        merchant.Jobs ^= MerchantJob.Train;
                    }
                    if (npcTemplate.Roles.Vend != null)
                    {
                        merchant.Jobs ^= MerchantJob.Vend;
                    }
                }
                InsertNpc(merchant);
            }

            foreach (var reactorElement in newMap.Reactors)
            {
                // TODO: implement reactor loading support
            }
            if (newMap.Signs != null)
            {
                foreach (var postElement in newMap.Signs.Signposts)
                {
                    var signpostElement = postElement as Maps.Signpost;
                    var signpost        = new Objects.Signpost(signpostElement.X, signpostElement.Y, signpostElement.Message);
                    InsertSignpost(signpost);
                }
                foreach (var postElement in newMap.Signs.MessageBoards)
                {
                    var boardElement = postElement as Maps.MessageBoard;
                    var board        = new Objects.Signpost(boardElement.X, boardElement.Y, string.Empty, true, boardElement.Name);
                    InsertSignpost(board);
                    Logger.InfoFormat("{0}: {1} - messageboard loaded", this.Name, board.Name);
                }
            }
            Load();
        }
Ejemplo n.º 4
0
        /// <summary>
        /// Create a new Hybrasyl map from an XMLMap object.
        /// </summary>
        /// <param name="newMap">An XSD.Map object representing the XML map file.</param>
        /// <param name="theWorld">A world object where the map will be placed</param>
        public Map(Maps.Map newMap, World theWorld)
        {
            Init();
            World = theWorld;

            // TODO: refactor Map class to not do this, but be a partial which overlays
            // TODO: XSD.Map
            Id         = newMap.Id;
            X          = newMap.X;
            Y          = newMap.Y;
            Name       = newMap.Name;
            EntityTree = new QuadTree <VisibleObject>(0, 0, X, Y);
            Music      = newMap.Music;

            foreach (var warpElement in newMap.Warps)
            {
                var warp = new Warp(this);
                warp.X = warpElement.X;
                warp.Y = warpElement.Y;

                if (warpElement.MapTarget != null)
                {
                    var maptarget = warpElement.MapTarget as Maps.WarpMapTarget;
                    // map warp
                    warp.DestinationMapName = maptarget.Value;
                    warp.WarpType           = WarpType.Map;
                    warp.DestinationX       = maptarget.X;
                    warp.DestinationY       = maptarget.Y;
                }
                else
                {
                    var worldmaptarget = warpElement.WorldMapTarget;
                    // worldmap warp
                    warp.DestinationMapName = worldmaptarget;
                    warp.WarpType           = WarpType.WorldMap;
                }

                warp.MinimumLevel   = warpElement.Restrictions.Level.Min;
                warp.MaximumLevel   = warpElement.Restrictions.Level.Max;
                warp.MinimumAbility = warpElement.Restrictions.Ab.Min;
                warp.MaximumAbility = warpElement.Restrictions.Ab.Max;
                warp.MobUse         = warpElement.Restrictions.NoMobUse;
                Warps[new Tuple <byte, byte>(warp.X, warp.Y)] = warp;
            }

            foreach (var npcElement in newMap.Npcs)
            {
                var merchant = new Merchant
                {
                    X         = npcElement.X,
                    Y         = npcElement.Y,
                    Name      = npcElement.Name,
                    Sprite    = npcElement.Appearance.Sprite,
                    Direction = (Enums.Direction)npcElement.Appearance.Direction,
                    Portrait  = npcElement.Appearance.Portrait,
                    // Wow this is terrible
                    Jobs = ((MerchantJob)(int)npcElement.Jobs)
                };
                InsertNpc(merchant);
            }

            foreach (var reactorElement in newMap.Reactors)
            {
                // TODO: implement reactor loading support
            }

            foreach (var postElement in newMap.Signs.Signposts)
            {
                var signpostElement = postElement as Maps.Signpost;
                var signpost        = new Objects.Signpost(signpostElement.X, signpostElement.Y, signpostElement.Message);
                InsertSignpost(signpost);
            }
            foreach (var postElement in newMap.Signs.MessageBoards)
            {
                var boardElement = postElement as Maps.MessageBoard;
                var board        = new Objects.Signpost(boardElement.X, boardElement.Y, string.Empty, true, boardElement.Name);
                InsertSignpost(board);
                Logger.InfoFormat("{0}: {1} - messageboard loaded", this.Name, board.Name);
            }
            Load();
        }