public HybrasylMap(Map map) { Map = map; }
private void LoadData() { var random = new Random(); var elements = Enum.GetValues(typeof(Element)); try { using (var ctx = new hybrasylEntities(Constants.ConnectionString)) { var maps = ctx.maps.Include("warps").Include("worldwarps").Include("npcs").Include("spawns").ToList(); var worldmaps = ctx.worldmaps.Include("worldmap_points").ToList(); var items = ctx.items.ToList(); //var doors = ctx.doors.ToList(); var signposts = ctx.signposts.ToList(); Logger.InfoFormat("Adding {0} worldmaps", ctx.worldmaps.Count()); foreach (var wmap in worldmaps) { var worldmap = new WorldMap(); worldmap.World = this; worldmap.Id = wmap.id; worldmap.Name = wmap.name; worldmap.ClientMap = wmap.client_map; WorldMaps.Add(worldmap.Id, worldmap); foreach (var mappoint in wmap.worldmap_points) { var point = new MapPoint(); point.Parent = worldmap; point.Id = (Int64) mappoint.id; point.Name = (string) mappoint.name; point.DestinationMap = (ushort) mappoint.target_map_id; point.DestinationX = (byte) mappoint.target_x; point.DestinationY = (byte) mappoint.target_y; point.X = (int) mappoint.map_x; point.Y = (int) mappoint.map_y; point.XOffset = point.X%255; point.YOffset = point.Y%255; point.XQuadrant = (point.X - point.XOffset)/255; point.YQuadrant = (point.Y - point.YOffset)/255; worldmap.Points.Add(point); MapPoints.Add(point.Id, point); } } Logger.InfoFormat("Adding {0} maps", ctx.maps.Count()); foreach (var map in maps) { var newmap = new Map(); newmap.World = this; newmap.Id = (ushort) map.id; newmap.X = (byte) map.size_x; newmap.Y = (byte) map.size_y; newmap.Name = (string) map.name; newmap.Flags = (byte) map.flags; newmap.Music = (byte) (map.music ?? 0); newmap.EntityTree = new QuadTree<VisibleObject>(0, 0, map.size_x, map.size_y); if (newmap.Load()) { Maps.Add(newmap.Id, newmap); try { MapCatalog.Add(newmap.Name, newmap); } catch { Logger.WarnFormat("map name {0}, id {1} ignored for map catalog", newmap.Name, newmap.Id); } foreach (var warp in map.warps) { AddWarp(warp); } foreach (var worldwarp in map.worldwarps) { AddWorldWarp(worldwarp); } foreach (var npc in map.npcs) { newmap.InsertNpc(npc); if (npc.portrait != null) { Portraits[npc.name] = npc.portrait; } } foreach (var spawn in map.spawns) { AddSpawn(spawn); } } } // We have to handle signposts separately due to a bug in MySQL connector foreach (var signpost in signposts) { Map postmap; if (Maps.TryGetValue((ushort) signpost.map_id, out postmap)) postmap.InsertSignpost(signpost); else Logger.ErrorFormat("Signpost {0}: {1},{2}: Map {0} is missing ", signpost.id, signpost.map_x, signpost.map_y, signpost.map_id); } int variantId = Hybrasyl.Constants.VARIANT_ID_START; Logger.InfoFormat("Adding {0} items", items.Count); var variants = ctx.item_variant.ToList(); foreach (var item in items) { Logger.DebugFormat("Adding item {0}", item.name); item.Variants = new Dictionary<int, item>(); // Handle the case of item having random element, which is an optional bit of support // and not really intended for serious use if (item.element == Element.Random) { item.element = (Element)elements.GetValue(random.Next(elements.Length - 1 )); } if (item.has_consecratable_variants) { foreach (var variant in variants.Where(variant => variant.consecratable_variant == true)) { var newitem = variant.ResolveVariant(item); newitem.id = variantId; Items.Add(variantId, newitem); item.Variants[variant.id] = newitem; variantId++; } } if (item.has_elemental_variants) { foreach (var variant in variants.Where(variant => variant.elemental_variant == true)) { var newitem = variant.ResolveVariant(item); newitem.id = variantId; Items.Add(variantId, newitem); item.Variants[variant.id] = newitem; variantId++; } } if (item.has_enchantable_variants) { foreach (var variant in variants.Where(variant => variant.enchantable_variant == true)) { var newitem = variant.ResolveVariant(item); newitem.id = variantId; Items.Add(variantId, newitem); item.Variants[variant.id] = newitem; variantId++; } } if (item.has_smithable_variants) { foreach (var variant in variants.Where(variant => variant.smithable_variant == true)) { var newitem = variant.ResolveVariant(item); newitem.id = variantId; Items.Add(variantId, newitem); item.Variants[variant.id] = newitem; variantId++; } } if (item.has_tailorable_variants) { foreach (var variant in variants.Where(variant => variant.tailorable_variant == true)) { var newitem = variant.ResolveVariant(item); newitem.id = variantId; Items.Add(variantId, newitem); item.Variants[variant.id] = newitem; variantId++; } } Items.Add(item.id, item); try { ItemCatalog.Add(new Tuple<Sex, String>(item.sex, item.name), item); } catch { Logger.WarnFormat("probable duplicate item {0} not added to item catalog", item.name); } } Logger.InfoFormat("Added {0} item variants", variantId - Hybrasyl.Constants.VARIANT_ID_START); Logger.InfoFormat("{0} items (including variants) active", Items.Count); // Load national data Nations = ctx.nations.Include("spawn_points").ToDictionary(n => n.name, n => n); } } catch (Exception e) { Logger.ErrorFormat("Error initializing Hybrasyl data: {0} {1}", e, e.InnerException); Logger.ErrorFormat("Beware, server is now likely inconsistent and should be shut down"); } }