Example #1
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(XSD.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 XSD.WarpMaptarget;
                    // map warp
                    warp.DestinationMapName = maptarget.Value;
                    warp.WarpType           = WarpType.Map;
                    warp.DestinationX       = maptarget.X;
                    warp.DestinationY       = maptarget.Y;
                }
                else
                {
                    var worldmaptarget = warpElement.WorldMapTarget as XSD.WorldMapPointTarget;
                    // worldmap warp
                    warp.DestinationMapName = worldmaptarget.Value;
                    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 == null;
                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.Signposts.Items)
            {
                if (postElement is XSD.Signpost)
                {
                    var signpostElement = postElement as XSD.Signpost;
                    var signpost        = new Objects.Signpost(signpostElement.X, signpostElement.Y, signpostElement.Message);
                    InsertSignpost(signpost);
                }
                else
                {
                    var boardElement = postElement as XSD.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);
                }
            }

            foreach (var spawnElement in newMap.Spawns)
            {
                // TODO: implement spawning
            }

            Load();
        }
Example #2
0
        private void AddSingleWarp(int sourceId, int sourceX, int sourceY, int targetId, int targetX, int targetY,
            int maxLev = 99, int minLev = 0, int minAb = 0, bool mobUse = false)
        {
            var warp = new Warp();
            warp.X = (byte) sourceX;
            warp.Y = (byte) sourceY;
            warp.DestinationMap = (ushort) targetId;
            warp.DestinationX = (byte) targetX;
            warp.DestinationY = (byte) targetY;
            warp.MinimumLevel = (byte) (minLev);
            warp.MaximumLevel = (byte) (maxLev);
            warp.MinimumAbility = (byte) (minAb);
            warp.MobsCanUse = (bool) (mobUse);
            Maps[(ushort) sourceId].Warps.Add(warp);

            Logger.DebugFormat("Added warp: {0} {1},{2}", Maps[(ushort) sourceId].Name, warp.X, warp.Y);
        }
Example #3
0
        //public Dictionary<string, Xml.Spawn> Spawns { get; set; }

        /// <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(Xml.Map newMap, World theWorld)
        {
            Init();
            World      = theWorld;
            SpawnDebug = false;
            //  Spawns = new List<Xml.Spawn>();

            // 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;
            AllowCasting = newMap.AllowCasting;
            EntityTree   = new QuadTree <VisibleObject>(0, 0, X, Y);
            Music        = newMap.Music;

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

                if (warpElement.MapTarget != null)
                {
                    // map warp
                    warp.DestinationMapName = warpElement.MapTarget.Value;
                    warp.WarpType           = WarpType.Map;
                    warp.DestinationX       = warpElement.MapTarget.X;
                    warp.DestinationY       = warpElement.MapTarget.Y;
                }
                else if (warpElement.WorldMapTarget != string.Empty)
                {
                    // worldmap warp
                    warp.DestinationMapName = warpElement.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 <Xml.Npc>(npcElement.Name);
                if (npcTemplate == null)
                {
                    GameLog.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 = npcElement.Direction,
                    Portrait  = npcTemplate.Appearance.Portrait,
                    AllowDead = npcTemplate.AllowDead
                };
                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)
                    {
                        if (npcTemplate.Roles.Train.Any(x => x.Type == "Skill"))
                        {
                            merchant.Jobs ^= MerchantJob.Skills;
                        }
                        if (npcTemplate.Roles.Train.Any(x => x.Type == "Spell"))
                        {
                            merchant.Jobs ^= MerchantJob.Spells;
                        }
                    }
                    if (npcTemplate.Roles.Vend != null)
                    {
                        merchant.Jobs ^= MerchantJob.Vend;
                    }

                    merchant.Roles = npcTemplate.Roles;
                }
                InsertNpc(merchant);
                // Keep the actual spawned object around in the index for later use
                World.WorldData.Set(merchant.Name, merchant);
            }

            foreach (var reactorElement in newMap.Reactors)
            {
                var reactor = new Reactor(reactorElement.X, reactorElement.Y, this,
                                          reactorElement.Script, reactorElement.Description, reactorElement.Blocking);
                reactor.AllowDead = reactorElement.AllowDead;
                InsertReactor(reactor);
                GameLog.Debug($"{reactor.Id} placed in {reactor.Map.Name}, description was {reactor.Description}");
            }
            foreach (var sign in newMap.Signs)
            {
                Signpost post;
                if (sign.Type == Xml.BoardType.Sign)
                {
                    post = new Signpost(sign.X, sign.Y, sign.Message);
                }
                else
                {
                    post = new Signpost(sign.X, sign.Y, sign.Message, true, sign.BoardKey);
                }
                InsertSignpost(post);
            }
            Load();
        }
Example #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;
                }
                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();
        }