public void InsertSignpost(Objects.Signpost post) { World.Insert(post); Insert(post, post.X, post.Y); Signposts[new Tuple <byte, byte>(post.X, post.Y)] = post; Logger.InfoFormat("Inserted signpost {0}@{1},{2}", post.Map.Name, post.X, post.Y); }
/// <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(); }
/// <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(); }
/// <summary> /// Create a new Hybrasyl map from an XMLMap object. /// </summary> /// <param name="mapElement"></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: XmlMap (which would then just be 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 { // TODO: Messageboards Logger.InfoFormat("{0}: messageboard ignored", Name); } } foreach (var spawnElement in newMap.Spawns) { // TODO: implement spawning } Load(); }