public void LoadBackgrounds(WzImage mapImage, Board mapBoard) { WzSubProperty bgParent = (WzSubProperty)mapImage["back"]; WzSubProperty bgProp; int i = 0; while ((bgProp = (WzSubProperty)bgParent[(i++).ToString()]) != null) { int x = InfoTool.GetInt(bgProp["x"]); int y = InfoTool.GetInt(bgProp["y"]); int rx = InfoTool.GetInt(bgProp["rx"]); int ry = InfoTool.GetInt(bgProp["ry"]); int cx = InfoTool.GetInt(bgProp["cx"]); int cy = InfoTool.GetInt(bgProp["cy"]); int a = InfoTool.GetInt(bgProp["a"]); BackgroundType type = (BackgroundType)InfoTool.GetInt(bgProp["type"]); bool front = InfoTool.GetBool(bgProp["front"]); bool? flip_t = InfoTool.GetOptionalBool(bgProp["f"]); bool flip = flip_t.HasValue ? flip_t.Value : false; string bS = InfoTool.GetString(bgProp["bS"]); bool ani = InfoTool.GetBool(bgProp["ani"]); string no = InfoTool.GetInt(bgProp["no"]).ToString(); BackgroundInfo bgInfo = BackgroundInfo.Get(bS, ani, no); if (bgInfo == null) { continue; } IList list = front ? mapBoard.BoardItems.FrontBackgrounds : mapBoard.BoardItems.BackBackgrounds; list.Add((BackgroundInstance)bgInfo.CreateInstance(mapBoard, x, y, i, rx, ry, cx, cy, type, a, front, flip)); } }
public void LoadToolTips(WzImage mapImage, Board mapBoard) { WzSubProperty tooltipsParent = (WzSubProperty)mapImage["ToolTip"]; if (tooltipsParent == null) { return; } WzImage tooltipsStringImage = (WzImage)Program.WzManager.String["ToolTipHelp.img"]; if (!tooltipsStringImage.Parsed) { tooltipsStringImage.ParseImage(); } WzSubProperty tooltipStrings = (WzSubProperty)tooltipsStringImage["Mapobject"][mapBoard.MapInfo.id.ToString()]; if (tooltipStrings == null) { return; } for (int i = 0; true; i++) { string num = i.ToString(); WzSubProperty tooltipString = (WzSubProperty)tooltipStrings[num]; WzSubProperty tooltipProp = (WzSubProperty)tooltipsParent[num]; WzSubProperty tooltipChar = (WzSubProperty)tooltipsParent[num + "char"]; if (tooltipString == null && tooltipProp == null) { break; } if (tooltipString == null ^ tooltipProp == null) { continue; } string title = InfoTool.GetOptionalString(tooltipString["Title"]); string desc = InfoTool.GetOptionalString(tooltipString["Desc"]); int x1 = InfoTool.GetInt(tooltipProp["x1"]); int x2 = InfoTool.GetInt(tooltipProp["x2"]); int y1 = InfoTool.GetInt(tooltipProp["y1"]); int y2 = InfoTool.GetInt(tooltipProp["y2"]); Microsoft.Xna.Framework.Rectangle tooltipPos = new Microsoft.Xna.Framework.Rectangle(x1, y1, x2 - x1, y2 - y1); ToolTipInstance tt = new ToolTipInstance(mapBoard, tooltipPos, title, desc, i); mapBoard.BoardItems.ToolTips.Add(tt); if (tooltipChar != null) { x1 = InfoTool.GetInt(tooltipChar["x1"]); x2 = InfoTool.GetInt(tooltipChar["x2"]); y1 = InfoTool.GetInt(tooltipChar["y1"]); y2 = InfoTool.GetInt(tooltipChar["y2"]); tooltipPos = new Microsoft.Xna.Framework.Rectangle(x1, y1, x2 - x1, y2 - y1); ToolTipChar ttc = new ToolTipChar(mapBoard, tooltipPos, tt); mapBoard.BoardItems.CharacterToolTips.Add(ttc); } } }
public static void GetMapDimensions(WzImage mapImage, out Rectangle VR, out Point mapCenter, out Point mapSize, out Point minimapCenter, out Point minimapSize, out bool hasVR, out bool hasMinimap) { System.Drawing.Rectangle?vr = MapInfo.GetVR(mapImage); hasVR = vr.HasValue; hasMinimap = mapImage["miniMap"] != null; if (!hasMinimap) { // No minimap, generate sizes from VR if (vr == null) { // No minimap and no VR, our only chance of getting sizes is by generating a VR, if that fails we're screwed if (!GetMapVR(mapImage, ref vr)) { throw new NoVRException(); } } minimapSize = new Point(vr.Value.Width + 10, vr.Value.Height + 10); //leave 5 pixels on each side minimapCenter = new Point(5 - vr.Value.Left, 5 - vr.Value.Top); mapSize = new Point(minimapSize.X, minimapSize.Y); mapCenter = new Point(minimapCenter.X, minimapCenter.Y); } else { WzImageProperty miniMap = mapImage["miniMap"]; minimapSize = new Point(InfoTool.GetInt(miniMap["width"]), InfoTool.GetInt(miniMap["height"])); minimapCenter = new Point(InfoTool.GetInt(miniMap["centerX"]), InfoTool.GetInt(miniMap["centerY"])); int topOffs = 0, botOffs = 0, leftOffs = 0, rightOffs = 0; int leftTarget = 69 - minimapCenter.X, topTarget = 86 - minimapCenter.Y, rightTarget = minimapSize.X - 69 - 69, botTarget = minimapSize.Y - 86 - 86; if (vr == null) { // We have no VR info, so set all VRs according to their target vr = new System.Drawing.Rectangle(leftTarget, topTarget, rightTarget, botTarget); } else { if (vr.Value.Left < leftTarget) { leftOffs = leftTarget - vr.Value.Left; } if (vr.Value.Top < topTarget) { topOffs = topTarget - vr.Value.Top; } if (vr.Value.Right > rightTarget) { rightOffs = vr.Value.Right - rightTarget; } if (vr.Value.Bottom > botTarget) { botOffs = vr.Value.Bottom - botTarget; } } mapSize = new Point(minimapSize.X + leftOffs + rightOffs, minimapSize.Y + topOffs + botOffs); mapCenter = new Point(minimapCenter.X + leftOffs, minimapCenter.Y + topOffs); } VR = new Rectangle(vr.Value.X, vr.Value.Y, vr.Value.Width, vr.Value.Height); }
public static void CreateMapFromImage(WzImage mapImage, string mapName, string streetName, PageCollection Tabs, MultiBoard multiBoard, EventHandler rightClickHandler) { if (!mapImage.Parsed) { mapImage.ParseImage(); } VerifyMapPropsKnown(mapImage); MapInfo info = new MapInfo(mapImage, mapName, streetName); MapType type = GetMapType(mapImage); if (type == MapType.RegularMap) { info.id = int.Parse(WzInfoTools.RemoveLeadingZeros(WzInfoTools.RemoveExtension(mapImage.Name))); } info.mapType = type; Point center = new Point(); Point size = new Point(); if (mapImage["miniMap"] == null) { if (info.VR == null) { if (!GetMapVR(mapImage, ref info.VR)) { MessageBox.Show("Error - map does not contain size information and HaCreator was unable to generate it. An error has been logged.", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); ErrorLogger.Log(ErrorLevel.IncorrectStructure, "no size @map " + info.id.ToString()); return; } } size = new Point(info.VR.Value.Width + 10, info.VR.Value.Height + 10); //leave 5 pixels on each side center = new Point(5 - info.VR.Value.Left, 5 - info.VR.Value.Top); } else { IWzImageProperty miniMap = mapImage["miniMap"]; size = new Point(InfoTool.GetInt(miniMap["width"]), InfoTool.GetInt(miniMap["height"])); center = new Point(InfoTool.GetInt(miniMap["centerX"]), InfoTool.GetInt(miniMap["centerY"])); } CreateMap(mapName, WzInfoTools.RemoveLeadingZeros(WzInfoTools.RemoveExtension(mapImage.Name)), CreateStandardMapMenu(rightClickHandler), size, center, 8, Tabs, multiBoard); Board mapBoard = multiBoard.SelectedBoard; mapBoard.MapInfo = info; if (mapImage["miniMap"] != null) { mapBoard.MiniMap = ((WzCanvasProperty)mapImage["miniMap"]["canvas"]).PngProperty.GetPNG(false); } LoadLayers(mapImage, mapBoard); LoadLife(mapImage, mapBoard); LoadFootholds(mapImage, mapBoard); LoadRopes(mapImage, mapBoard); LoadChairs(mapImage, mapBoard); LoadPortals(mapImage, mapBoard); LoadReactors(mapImage, mapBoard); LoadToolTips(mapImage, mapBoard); LoadBackgrounds(mapImage, mapBoard); mapBoard.BoardItems.Sort(); }
public void LoadLife(WzImage mapImage, Board mapBoard) { WzImageProperty lifeParent = mapImage["life"]; if (lifeParent == null) { return; } foreach (WzSubProperty life in lifeParent.WzProperties) { string id = InfoTool.GetString(life["id"]); int x = InfoTool.GetInt(life["x"]); int y = InfoTool.GetInt(life["y"]); int cy = InfoTool.GetInt(life["cy"]); int? mobTime = InfoTool.GetOptionalInt(life["mobTime"]); int? info = InfoTool.GetOptionalInt(life["info"]); int? team = InfoTool.GetOptionalInt(life["team"]); int rx0 = InfoTool.GetInt(life["rx0"]); int rx1 = InfoTool.GetInt(life["rx1"]); MapleBool flip = InfoTool.GetOptionalBool(life["f"]); MapleBool hide = InfoTool.GetOptionalBool(life["hide"]); string type = InfoTool.GetString(life["type"]); string limitedname = InfoTool.GetOptionalString(life["limitedname"]); switch (type) { case "m": MobInfo mobInfo = MobInfo.Get(id); if (mobInfo == null) { continue; } mapBoard.BoardItems.Mobs.Add((MobInstance)mobInfo.CreateInstance(mapBoard, x, cy, x - rx0, rx1 - x, cy - y, limitedname, mobTime, flip, hide, info, team)); break; case "n": NpcInfo npcInfo = NpcInfo.Get(id); if (npcInfo == null) { continue; } mapBoard.BoardItems.NPCs.Add((NpcInstance)npcInfo.CreateInstance(mapBoard, x, cy, x - rx0, rx1 - x, cy - y, limitedname, mobTime, flip, hide, info, team)); break; default: throw new Exception("invalid life type " + type); } } }
public void LoadRopes(WzImage mapImage, Board mapBoard) { WzSubProperty ropeParent = (WzSubProperty)mapImage["ladderRope"]; foreach (WzSubProperty rope in ropeParent.WzProperties) { int x = InfoTool.GetInt(rope["x"]); int y1 = InfoTool.GetInt(rope["y1"]); int y2 = InfoTool.GetInt(rope["y2"]); bool uf = InfoTool.GetBool(rope["uf"]); int page = InfoTool.GetInt(rope["page"]); bool l = InfoTool.GetBool(rope["l"]); mapBoard.BoardItems.Ropes.Add(new Rope(mapBoard, x, y1, y2, l, page, uf)); } }
public void LoadReactors(WzImage mapImage, Board mapBoard) { WzSubProperty reactorParent = (WzSubProperty)mapImage["reactor"]; if (reactorParent == null) { return; } foreach (WzSubProperty reactor in reactorParent.WzProperties) { int x = InfoTool.GetInt(reactor["x"]); int y = InfoTool.GetInt(reactor["y"]); int reactorTime = InfoTool.GetInt(reactor["reactorTime"]); string name = InfoTool.GetOptionalString(reactor["name"]); string id = InfoTool.GetString(reactor["id"]); bool flip = InfoTool.GetBool(reactor["f"]); mapBoard.BoardItems.Reactors.Add((ReactorInstance)Program.InfoManager.Reactors[id].CreateInstance(mapBoard, x, y, reactorTime, name, flip)); } }
private static TileInfo Load(WzCanvasProperty parentObject, string tS, string u, string no, int?mag) { WzImageProperty zProp = parentObject["z"]; int z = zProp == null ? 0 : InfoTool.GetInt(zProp); TileInfo result = new TileInfo(parentObject.PngProperty.GetPNG(false), WzInfoTools.VectorToSystemPoint((WzVectorProperty)parentObject["origin"]), tS, u, no, mag.HasValue ? mag.Value : 1, z, parentObject); WzConvexProperty footholds = (WzConvexProperty)parentObject["foothold"]; if (footholds != null) { foreach (WzVectorProperty foothold in footholds.WzProperties) { result.footholdOffsets.Add(WzInfoTools.VectorToXNAPoint(foothold)); } } if (UserSettings.FixFootholdMispositions) { FixFootholdMispositions(result); } return(result); }
public void LoadPortals(WzImage mapImage, Board mapBoard) { WzSubProperty portalParent = (WzSubProperty)mapImage["portal"]; foreach (WzSubProperty portal in portalParent.WzProperties) { int x = InfoTool.GetInt(portal["x"]); int y = InfoTool.GetInt(portal["y"]); string pt = Program.InfoManager.PortalTypeById[InfoTool.GetInt(portal["pt"])]; int tm = InfoTool.GetInt(portal["tm"]); string tn = InfoTool.GetString(portal["tn"]); string pn = InfoTool.GetString(portal["pn"]); string image = InfoTool.GetOptionalString(portal["image"]); string script = InfoTool.GetOptionalString(portal["script"]); int? verticalImpact = InfoTool.GetOptionalInt(portal["verticalImpact"]); int? horizontalImpact = InfoTool.GetOptionalInt(portal["horizontalImpact"]); int? hRange = InfoTool.GetOptionalInt(portal["hRange"]); int? vRange = InfoTool.GetOptionalInt(portal["vRange"]); int? delay = InfoTool.GetOptionalInt(portal["delay"]); MapleBool hideTooltip = InfoTool.GetOptionalBool(portal["hideTooltip"]); MapleBool onlyOnce = InfoTool.GetOptionalBool(portal["onlyOnce"]); mapBoard.BoardItems.Portals.Add(PortalInfo.GetPortalInfoByType(pt).CreateInstance(mapBoard, x, y, pn, tn, tm, script, delay, hideTooltip, onlyOnce, horizontalImpact, verticalImpact, image, hRange, vRange)); } }
private static void LoadBackgrounds(WzImage mapImage, Board mapBoard) { WzSubProperty bgParent = (WzSubProperty)mapImage["back"]; WzSubProperty bgProp; int i = 0; while ((bgProp = (WzSubProperty)bgParent[(i++).ToString()]) != null) { int x = InfoTool.GetInt(bgProp["x"]); int y = InfoTool.GetInt(bgProp["y"]); int rx = InfoTool.GetInt(bgProp["rx"]); int ry = InfoTool.GetInt(bgProp["ry"]); int cx = InfoTool.GetInt(bgProp["cx"]); int cy = InfoTool.GetInt(bgProp["cy"]); int a = InfoTool.GetInt(bgProp["a"]); BackgroundType type = (BackgroundType)InfoTool.GetInt(bgProp["type"]); bool front = InfoTool.GetBool(bgProp["front"]); bool flip = InfoTool.GetBool(bgProp["f"]); string bS = InfoTool.GetString(bgProp["bS"]); bool ani = InfoTool.GetBool(bgProp["ani"]); string no = InfoTool.GetInt(bgProp["no"]).ToString(); WzImage bsImg = Program.InfoManager.BackgroundSets[bS]; if (bsImg == null) { continue; } IWzImageProperty bgInfoProp = bsImg[ani ? "ani" : "back"][no]; if (bgInfoProp.HCTag == null) { bgInfoProp.HCTag = BackgroundInfo.Load(bgInfoProp, bS, ani, no); } BackgroundInfo bgInfo = (BackgroundInfo)bgInfoProp.HCTag; IList list = front ? mapBoard.BoardItems.FrontBackgrounds : mapBoard.BoardItems.BackBackgrounds; list.Add((BackgroundInstance)bgInfo.CreateInstance(mapBoard, x, y, i, rx, ry, cx, cy, type, a, front, flip, false)); } }
public void LoadFootholds(WzImage mapImage, Board mapBoard) { List <FootholdAnchor> anchors = new List <FootholdAnchor>(); WzSubProperty footholdParent = (WzSubProperty)mapImage["foothold"]; int layer; FootholdAnchor a; FootholdAnchor b; Dictionary <int, FootholdLine> fhs = new Dictionary <int, FootholdLine>(); foreach (WzSubProperty layerProp in footholdParent.WzProperties) { layer = int.Parse(layerProp.Name); Layer l = mapBoard.Layers[layer]; foreach (WzSubProperty platProp in layerProp.WzProperties) { int zM = int.Parse(platProp.Name); l.zMList.Add(zM); foreach (WzSubProperty fhProp in platProp.WzProperties) { a = new FootholdAnchor(mapBoard, InfoTool.GetInt(fhProp["x1"]), InfoTool.GetInt(fhProp["y1"]), layer, zM, false); b = new FootholdAnchor(mapBoard, InfoTool.GetInt(fhProp["x2"]), InfoTool.GetInt(fhProp["y2"]), layer, zM, false); int num = int.Parse(fhProp.Name); int next = InfoTool.GetInt(fhProp["next"]); int prev = InfoTool.GetInt(fhProp["prev"]); MapleBool cantThrough = InfoTool.GetOptionalBool(fhProp["cantThrough"]); MapleBool forbidFallDown = InfoTool.GetOptionalBool(fhProp["forbidFallDown"]); int? piece = InfoTool.GetOptionalInt(fhProp["piece"]); int? force = InfoTool.GetOptionalInt(fhProp["force"]); if (a.X != b.X || a.Y != b.Y) { FootholdLine fh = new FootholdLine(mapBoard, a, b, forbidFallDown, cantThrough, piece, force); fh.num = num; fh.prev = prev; fh.next = next; mapBoard.BoardItems.FootholdLines.Add(fh); fhs[num] = fh; anchors.Add(a); anchors.Add(b); } } } anchors.Sort(new Comparison <FootholdAnchor>(FootholdAnchor.FHAnchorSorter)); for (int i = 0; i < anchors.Count - 1; i++) { a = anchors[i]; b = anchors[i + 1]; if (a.X == b.X && a.Y == b.Y) { FootholdAnchor.MergeAnchors(a, b); // Transfer lines from b to a anchors.RemoveAt(i + 1); // Remove b i--; // Fix index after we removed b } } foreach (FootholdAnchor anchor in anchors) { if (anchor.connectedLines.Count > 2) { foreach (FootholdLine line in anchor.connectedLines) { if (IsAnchorPrevOfFoothold(anchor, line)) { if (fhs.ContainsKey(line.prev)) { line.prevOverride = fhs[line.prev]; } } else { if (fhs.ContainsKey(line.next)) { line.nextOverride = fhs[line.next]; } } } } mapBoard.BoardItems.FHAnchors.Add(anchor); } anchors.Clear(); } }
private static void LoadLife(WzImage mapImage, Board mapBoard) { IWzImageProperty lifeParent = mapImage["life"]; if (lifeParent == null) { return; } foreach (WzSubProperty life in lifeParent.WzProperties) { string id = InfoTool.GetString(life["id"]); int x = InfoTool.GetInt(life["x"]); //int y = InfoTool.GetInt(life["y"]); int cy = InfoTool.GetInt(life["cy"]); int? mobTime = InfoTool.GetOptionalInt(life["mobTime"]); int? info = InfoTool.GetOptionalInt(life["info"]); int? team = InfoTool.GetOptionalInt(life["team"]); int rx0 = InfoTool.GetInt(life["rx0"]); int rx1 = InfoTool.GetInt(life["rx1"]); MapleBool flip = InfoTool.GetOptionalBool(life["f"]); MapleBool hide = InfoTool.GetOptionalBool(life["hide"]); string type = InfoTool.GetString(life["type"]); string limitedname = InfoTool.GetOptionalString(life["limitedname"]); switch (type) { case "m": WzImage mobImage = (WzImage)Program.WzManager["mob"][id + ".img"]; if (!mobImage.Parsed) { mobImage.ParseImage(); } if (mobImage.HCTag == null) { mobImage.HCTag = MobInfo.Load(mobImage); } MobInfo mobInfo = (MobInfo)mobImage.HCTag; //mapBoard.BoardItems.Mobs.Add((MobInstance)mobInfo.CreateInstance(mapBoard, x, cy, rx0, rx1, mobTime, flip, hide, false)); mapBoard.BoardItems.Mobs.Add((LifeInstance)mobInfo.CreateInstance(mapBoard, x, cy, rx0, rx1, limitedname, mobTime, flip, hide, info, team, false)); break; case "n": WzImage npcImage = (WzImage)Program.WzManager["npc"][id + ".img"]; if (!npcImage.Parsed) { npcImage.ParseImage(); } if (npcImage.HCTag == null) { npcImage.HCTag = NpcInfo.Load(npcImage); } NpcInfo npcInfo = (NpcInfo)npcImage.HCTag; //mapBoard.BoardItems.NPCs.Add((NpcInstance)npcInfo.CreateInstance(mapBoard, x, cy, rx0, rx1, mobTime, flip, hide, false)); mapBoard.BoardItems.NPCs.Add((LifeInstance)npcInfo.CreateInstance(mapBoard, x, cy, rx0, rx1, limitedname, mobTime, flip, hide, info, team, false)); break; default: throw new Exception("invalid life type " + type); } } }
private static bool GetMapVR(WzImage mapImage, ref System.Drawing.Rectangle?VR) { WzSubProperty fhParent = (WzSubProperty)mapImage["foothold"]; if (fhParent == null) { VR = null; return(false); } int mostRight = int.MinValue, mostLeft = int.MaxValue, mostTop = int.MaxValue, mostBottom = int.MinValue; foreach (WzSubProperty fhLayer in fhParent.WzProperties) { foreach (WzSubProperty fhCat in fhLayer.WzProperties) { foreach (WzSubProperty fh in fhCat.WzProperties) { int x1 = InfoTool.GetInt(fh["x1"]); int x2 = InfoTool.GetInt(fh["x2"]); int y1 = InfoTool.GetInt(fh["y1"]); int y2 = InfoTool.GetInt(fh["y2"]); if (x1 > mostRight) { mostRight = x1; } if (x1 < mostLeft) { mostLeft = x1; } if (x2 > mostRight) { mostRight = x2; } if (x2 < mostLeft) { mostLeft = x2; } if (y1 > mostBottom) { mostBottom = y1; } if (y1 < mostTop) { mostTop = y1; } if (y2 > mostBottom) { mostBottom = y2; } if (y2 < mostTop) { mostTop = y2; } } } } if (mostRight == int.MinValue || mostLeft == int.MaxValue || mostTop == int.MaxValue || mostBottom == int.MinValue) { VR = null; return(false); } int VRLeft = mostLeft - 10; int VRRight = mostRight + 10; int VRBottom = mostBottom + 110; int VRTop = Math.Min(mostBottom - 600, mostTop - 360); VR = new System.Drawing.Rectangle(VRLeft, VRTop, VRRight - VRLeft, VRBottom - VRTop); return(true); }
private static bool GetMapVR(WzImage mapImage, ref System.Drawing.Rectangle?VR) { WzSubProperty fhParent = (WzSubProperty)mapImage["foothold"]; if (fhParent == null) { VR = null; return(false); } int mostRight = int.MinValue, mostLeft = int.MaxValue, mostTop = int.MaxValue, mostBottom = int.MinValue; foreach (WzSubProperty fhLayer in fhParent.WzProperties) { foreach (WzSubProperty fhCat in fhLayer.WzProperties) { foreach (WzSubProperty fh in fhCat.WzProperties) { int x1 = InfoTool.GetInt(fh["x1"]); int x2 = InfoTool.GetInt(fh["x2"]); int y1 = InfoTool.GetInt(fh["y1"]); int y2 = InfoTool.GetInt(fh["y2"]); if (x1 > mostRight) { mostRight = x1; } if (x1 < mostLeft) { mostLeft = x1; } if (x2 > mostRight) { mostRight = x2; } if (x2 < mostLeft) { mostLeft = x2; } if (y1 > mostBottom) { mostBottom = y1; } if (y1 < mostTop) { mostTop = y1; } if (y2 > mostBottom) { mostBottom = y2; } if (y2 < mostTop) { mostTop = y2; } } } } if (mostRight == int.MinValue || mostLeft == int.MaxValue || mostTop == int.MaxValue || mostBottom == int.MinValue) { VR = null; return(false); } int VRLeft = mostLeft - 10; int VRRight = mostRight + 10; int VRBottom = mostBottom + 110; int VRTop = Math.Min(mostBottom - 600, mostTop - 360); VR = new System.Drawing.Rectangle(VRLeft, VRTop, VRRight - VRLeft, VRBottom - VRTop); return(true); /* * int left = int.MaxValue, top = int.MaxValue, right = int.MinValue, bottom = int.MinValue; * for (int layer = 0; layer <= 7; layer++) * { * WzSubProperty layerProp = (WzSubProperty)mapImage[layer.ToString()]; * foreach (IWzImageProperty obj in layerProp["obj"].WzProperties) * { * int x = InfoTool.GetInt(obj["x"]); * int y = InfoTool.GetInt(obj["y"]); * if (x < left) left = x; * if (x > right) right = x; * if (y < top) top = y; * if (y > bottom) bottom = y; * } * foreach (IWzImageProperty tile in layerProp["tile"].WzProperties) * { * int x = InfoTool.GetInt(tile["x"]); * int y = InfoTool.GetInt(tile["y"]); * if (x < left) left = x; * if (x > right) right = x; * if (y < top) top = y; * if (y > bottom) bottom = y; * } * } * size = new XNA.Point(right - left + 200, bottom - top + 200); * center = new XNA.Point(100 - left, 100 - top);*/ }
private static void LoadFootholds(WzImage mapImage, Board mapBoard) { List <FootholdAnchor> anchors = new List <FootholdAnchor>(); WzSubProperty footholdParent = (WzSubProperty)mapImage["foothold"]; int layer; FootholdAnchor a; FootholdAnchor b; FootholdAnchor c; FootholdAnchor d; foreach (WzSubProperty layerProp in footholdParent.WzProperties) { layer = int.Parse(layerProp.Name); foreach (WzSubProperty platProp in layerProp.WzProperties) { foreach (WzSubProperty fhProp in platProp.WzProperties) { a = new FootholdAnchor(mapBoard, InfoTool.GetInt(fhProp["x1"]), InfoTool.GetInt(fhProp["y1"]), layer, false); b = new FootholdAnchor(mapBoard, InfoTool.GetInt(fhProp["x2"]), InfoTool.GetInt(fhProp["y2"]), layer, false); int num = int.Parse(fhProp.Name); int next = InfoTool.GetInt(fhProp["next"]); int prev = InfoTool.GetInt(fhProp["prev"]); if (a.X != b.X || a.Y != b.Y) { FootholdLine fh = new FootholdLine(mapBoard, a, b); fh.num = num; fh.prev = prev; fh.next = next; mapBoard.BoardItems.FootholdLines.Add(fh); anchors.Add(a); anchors.Add(b); } } } anchors.Sort(new Comparison <FootholdAnchor>(FootholdAnchor.FHAnchorSorter)); int groupStart = 0; //inclusive int groupEnd = 0; //inclusive for (int i = 0; i < anchors.Count - 1; i++) { a = anchors[i]; b = anchors[i + 1]; if (a.Y != b.Y && a.X != b.X && a.LayerNumber == b.LayerNumber) { groupEnd = i; if (groupEnd - groupStart == 1) //there are 2 objects in the group, since groupEnd and groupStart are inclusive { c = anchors[groupStart]; d = anchors[groupEnd]; CheckAnchorPairMerge(c, d); } else if (groupEnd - groupStart != 0) { for (int j = groupStart; j <= groupEnd; j++) { c = anchors[j]; for (int k = groupStart; k <= groupEnd; k++) { if (c.removed) { break; } d = anchors[k]; if (d.removed) { continue; } CheckAnchorPairMerge(c, d); } } } groupStart = groupEnd + 1; } } groupEnd = anchors.Count - 1; if (groupEnd - groupStart == 1) //there are 2 objects in the group, since groupEnd and groupStart are inclusive { c = anchors[groupStart]; d = anchors[groupEnd]; CheckAnchorPairMerge(c, d); } else if (groupEnd - groupStart != 0) { for (int j = groupStart; j <= groupEnd; j++) { c = anchors[j]; for (int k = groupStart; k <= groupEnd; k++) { if (c.removed) { break; } d = anchors[k]; if (d.removed) { continue; } CheckAnchorPairMerge(c, d); } } } //FootholdAnchor.MergeAnchors(ref anchors); /*if (mapBoard.BoardItems.FHAnchors.Count + anchors.Count > mapBoard.BoardItems.FHAnchors.Capacity) * mapBoard.BoardItems.FHAnchors.Capacity = mapBoard.BoardItems.FHAnchors.Count + anchors.Count; * anchors.ForEach(X => if mapBoard.BoardItems.FHAnchors.Add(X)); * anchors.Clear();*/ mapBoard.BoardItems.FHAnchors.Capacity = mapBoard.BoardItems.FHAnchors.Count + anchors.Count * 2; foreach (FootholdAnchor anchor in anchors) { if (!anchor.removed) { mapBoard.BoardItems.FHAnchors.Add(anchor); } } anchors.Clear(); } }
public void LoadMisc(WzImage mapImage, Board mapBoard) { // All of the following properties are extremely esoteric features that only appear in a handful of maps. // They are implemented here for the sake of completeness, and being able to repack their maps without corruption. WzImageProperty clock = mapImage["clock"]; WzImageProperty ship = mapImage["shipObj"]; WzImageProperty area = mapImage["area"]; WzImageProperty healer = mapImage["healer"]; WzImageProperty pulley = mapImage["pulley"]; WzImageProperty BuffZone = mapImage["BuffZone"]; WzImageProperty swimArea = mapImage["swimArea"]; if (clock != null) { Clock clockInstance = new Clock(mapBoard, new Rectangle(InfoTool.GetInt(clock["x"]), InfoTool.GetInt(clock["y"]), InfoTool.GetInt(clock["width"]), InfoTool.GetInt(clock["height"]))); mapBoard.BoardItems.Add(clockInstance, false); } if (ship != null) { string objPath = InfoTool.GetString(ship["shipObj"]); string[] objPathParts = objPath.Split("/".ToCharArray()); string oS = WzInfoTools.RemoveExtension(objPathParts[objPathParts.Length - 4]); string l0 = objPathParts[objPathParts.Length - 3]; string l1 = objPathParts[objPathParts.Length - 2]; string l2 = objPathParts[objPathParts.Length - 1]; ObjectInfo objInfo = ObjectInfo.Get(oS, l0, l1, l2); ShipObject shipInstance = new ShipObject(objInfo, mapBoard, InfoTool.GetInt(ship["x"]), InfoTool.GetInt(ship["y"]), InfoTool.GetOptionalInt(ship["z"]), InfoTool.GetOptionalInt(ship["x0"]), InfoTool.GetInt(ship["tMove"]), InfoTool.GetInt(ship["shipKind"]), InfoTool.GetBool(ship["f"])); mapBoard.BoardItems.Add(shipInstance, false); } if (area != null) { foreach (WzImageProperty prop in area.WzProperties) { int x1 = InfoTool.GetInt(prop["x1"]); int x2 = InfoTool.GetInt(prop["x2"]); int y1 = InfoTool.GetInt(prop["y1"]); int y2 = InfoTool.GetInt(prop["y2"]); Area currArea = new Area(mapBoard, new Rectangle(Math.Min(x1, x2), Math.Min(y1, y2), Math.Abs(x2 - x1), Math.Abs(y2 - y1)), prop.Name); mapBoard.BoardItems.Add(currArea, false); } } if (healer != null) { string objPath = InfoTool.GetString(healer["healer"]); string[] objPathParts = objPath.Split("/".ToCharArray()); string oS = WzInfoTools.RemoveExtension(objPathParts[objPathParts.Length - 4]); string l0 = objPathParts[objPathParts.Length - 3]; string l1 = objPathParts[objPathParts.Length - 2]; string l2 = objPathParts[objPathParts.Length - 1]; ObjectInfo objInfo = ObjectInfo.Get(oS, l0, l1, l2); Healer healerInstance = new Healer(objInfo, mapBoard, InfoTool.GetInt(healer["x"]), InfoTool.GetInt(healer["yMin"]), InfoTool.GetInt(healer["yMax"]), InfoTool.GetInt(healer["healMin"]), InfoTool.GetInt(healer["healMax"]), InfoTool.GetInt(healer["fall"]), InfoTool.GetInt(healer["rise"])); mapBoard.BoardItems.Add(healerInstance, false); } if (pulley != null) { string objPath = InfoTool.GetString(pulley["pulley"]); string[] objPathParts = objPath.Split("/".ToCharArray()); string oS = WzInfoTools.RemoveExtension(objPathParts[objPathParts.Length - 4]); string l0 = objPathParts[objPathParts.Length - 3]; string l1 = objPathParts[objPathParts.Length - 2]; string l2 = objPathParts[objPathParts.Length - 1]; ObjectInfo objInfo = ObjectInfo.Get(oS, l0, l1, l2); Pulley pulleyInstance = new Pulley(objInfo, mapBoard, InfoTool.GetInt(pulley["x"]), InfoTool.GetInt(pulley["y"])); mapBoard.BoardItems.Add(pulleyInstance, false); } if (BuffZone != null) { foreach (WzImageProperty zone in BuffZone.WzProperties) { int x1 = InfoTool.GetInt(zone["x1"]); int x2 = InfoTool.GetInt(zone["x2"]); int y1 = InfoTool.GetInt(zone["y1"]); int y2 = InfoTool.GetInt(zone["y2"]); int id = InfoTool.GetInt(zone["ItemID"]); int interval = InfoTool.GetInt(zone["Interval"]); int duration = InfoTool.GetInt(zone["Duration"]); BuffZone currZone = new BuffZone(mapBoard, new Rectangle(Math.Min(x1, x2), Math.Min(y1, y2), Math.Abs(x2 - x1), Math.Abs(y2 - y1)), id, interval, duration, zone.Name); mapBoard.BoardItems.Add(currZone, false); } } if (swimArea != null) { foreach (WzImageProperty prop in swimArea.WzProperties) { int x1 = InfoTool.GetInt(prop["x1"]); int x2 = InfoTool.GetInt(prop["x2"]); int y1 = InfoTool.GetInt(prop["y1"]); int y2 = InfoTool.GetInt(prop["y2"]); SwimArea currArea = new SwimArea(mapBoard, new Rectangle(Math.Min(x1, x2), Math.Min(y1, y2), Math.Abs(x2 - x1), Math.Abs(y2 - y1)), prop.Name); mapBoard.BoardItems.Add(currArea, false); } } // Some misc items are not implemented here; these are copied byte-to-byte from the original. See VerifyMapPropsKnown for details. }
public void LoadLayers(WzImage mapImage, Board mapBoard) { for (int layer = 0; layer <= 7; layer++) { WzSubProperty layerProp = (WzSubProperty)mapImage[layer.ToString()]; WzImageProperty tSprop = layerProp["info"]["tS"]; string tS = null; if (tSprop != null) { tS = InfoTool.GetString(tSprop); } foreach (WzImageProperty obj in layerProp["obj"].WzProperties) { int x = InfoTool.GetInt(obj["x"]); int y = InfoTool.GetInt(obj["y"]); int z = InfoTool.GetInt(obj["z"]); int zM = InfoTool.GetInt(obj["zM"]); string oS = InfoTool.GetString(obj["oS"]); string l0 = InfoTool.GetString(obj["l0"]); string l1 = InfoTool.GetString(obj["l1"]); string l2 = InfoTool.GetString(obj["l2"]); string name = InfoTool.GetOptionalString(obj["name"]); MapleBool r = InfoTool.GetOptionalBool(obj["r"]); MapleBool hide = InfoTool.GetOptionalBool(obj["hide"]); MapleBool reactor = InfoTool.GetOptionalBool(obj["reactor"]); MapleBool flow = InfoTool.GetOptionalBool(obj["flow"]); int? rx = InfoTool.GetOptionalTranslatedInt(obj["rx"]); int? ry = InfoTool.GetOptionalTranslatedInt(obj["ry"]); int? cx = InfoTool.GetOptionalTranslatedInt(obj["cx"]); int? cy = InfoTool.GetOptionalTranslatedInt(obj["cy"]); string tags = InfoTool.GetOptionalString(obj["tags"]); WzImageProperty questParent = obj["quest"]; List <ObjectInstanceQuest> questInfo = null; if (questParent != null) { questInfo = new List <ObjectInstanceQuest>(); foreach (WzIntProperty info in questParent.WzProperties) { questInfo.Add(new ObjectInstanceQuest(int.Parse(info.Name), (QuestState)info.Value)); } } bool flip = InfoTool.GetBool(obj["f"]); ObjectInfo objInfo = ObjectInfo.Get(oS, l0, l1, l2); if (objInfo == null) { continue; } Layer l = mapBoard.Layers[layer]; mapBoard.BoardItems.TileObjs.Add((LayeredItem)objInfo.CreateInstance(l, mapBoard, x, y, z, zM, r, hide, reactor, flow, rx, ry, cx, cy, name, tags, questInfo, flip, false)); l.zMList.Add(zM); } WzImageProperty tileParent = layerProp["tile"]; foreach (WzImageProperty tile in tileParent.WzProperties) { int x = InfoTool.GetInt(tile["x"]); int y = InfoTool.GetInt(tile["y"]); int zM = InfoTool.GetInt(tile["zM"]); string u = InfoTool.GetString(tile["u"]); int no = InfoTool.GetInt(tile["no"]); Layer l = mapBoard.Layers[layer]; TileInfo tileInfo = TileInfo.Get(tS, u, no.ToString()); mapBoard.BoardItems.TileObjs.Add((LayeredItem)tileInfo.CreateInstance(l, mapBoard, x, y, int.Parse(tile.Name), zM, false, false)); l.zMList.Add(zM); } } }
private void ExtractSettingsImage(WzImage settingsImage, Type settingsHolderType) { if (!settingsImage.Parsed) { settingsImage.ParseImage(); } foreach (FieldInfo fieldInfo in settingsHolderType.GetFields(BindingFlags.Public | BindingFlags.Static)) { string settingName = fieldInfo.Name; WzImageProperty settingProp = settingsImage[settingName]; byte[] argb; if (settingProp == null) { SaveField(settingsImage, fieldInfo); } else if (fieldInfo.FieldType.BaseType != null && fieldInfo.FieldType.BaseType.FullName == "System.Enum") { fieldInfo.SetValue(null, InfoTool.GetInt(settingProp)); } else { switch (fieldInfo.FieldType.FullName) { //case "Microsoft.Xna.Framework.Graphics.Color": case "Microsoft.Xna.Framework.Color": if (xnaColorType == null) { throw new InvalidDataException("XNA color detected, but XNA type activator is null"); } argb = BitConverter.GetBytes((uint)((WzDoubleProperty)settingProp).Value); fieldInfo.SetValue(null, Activator.CreateInstance(xnaColorType, argb[0], argb[1], argb[2], argb[3])); break; case "System.Drawing.Color": argb = BitConverter.GetBytes((uint)((WzDoubleProperty)settingProp).Value); fieldInfo.SetValue(null, System.Drawing.Color.FromArgb(argb[3], argb[2], argb[1], argb[0])); break; case "System.Int32": fieldInfo.SetValue(null, InfoTool.GetInt(settingProp)); break; case "System.Double": fieldInfo.SetValue(null, ((WzDoubleProperty)settingProp).Value); break; case "System.Boolean": fieldInfo.SetValue(null, InfoTool.GetBool(settingProp)); //bool a = (bool)fieldInfo.GetValue(null); break; case "System.Single": fieldInfo.SetValue(null, ((WzFloatProperty)settingProp).Value); break; /*case "WzMapleVersion": * fieldInfo.SetValue(null, (WzMapleVersion)InfoTool.GetInt(settingProp)); * break; * case "ItemTypes": * fieldInfo.SetValue(null, (ItemTypes)InfoTool.GetInt(settingProp)); * break;*/ case "System.Drawing.Size": fieldInfo.SetValue(null, new System.Drawing.Size(((WzVectorProperty)settingProp).X.Value, ((WzVectorProperty)settingProp).Y.Value)); break; case "System.String": fieldInfo.SetValue(null, InfoTool.GetString(settingProp)); break; case "System.Drawing.Bitmap": fieldInfo.SetValue(null, ((WzCanvasProperty)settingProp).PngProperty.GetImage(false)); break; default: throw new Exception("unrecognized setting type"); } } } }
private static void LoadLayers(WzImage mapImage, Board mapBoard) { for (int layer = 0; layer <= 7; layer++) { WzSubProperty layerProp = (WzSubProperty)mapImage[layer.ToString()]; IWzImageProperty tSprop = layerProp["info"]["tS"]; string tS = null; if (tSprop != null) { tS = InfoTool.GetString(tSprop); } foreach (IWzImageProperty obj in layerProp["obj"].WzProperties) { int x = InfoTool.GetInt(obj["x"]); int y = InfoTool.GetInt(obj["y"]); int z = InfoTool.GetInt(obj["z"]); //int zM = InfoTool.GetInt(obj["zM"]); string oS = InfoTool.GetString(obj["oS"]); string l0 = InfoTool.GetString(obj["l0"]); string l1 = InfoTool.GetString(obj["l1"]); string l2 = InfoTool.GetString(obj["l2"]); string name = InfoTool.GetOptionalString(obj["name"]); MapleBool r = InfoTool.GetOptionalBool(obj["r"]); MapleBool hide = InfoTool.GetOptionalBool(obj["hide"]); MapleBool reactor = InfoTool.GetOptionalBool(obj["reactor"]); MapleBool flow = InfoTool.GetOptionalBool(obj["flow"]); int? rx = InfoTool.GetOptionalTranslatedInt(obj["rx"]); int? ry = InfoTool.GetOptionalTranslatedInt(obj["ry"]); int? cx = InfoTool.GetOptionalTranslatedInt(obj["cx"]); int? cy = InfoTool.GetOptionalTranslatedInt(obj["cy"]); string tags = InfoTool.GetOptionalString(obj["tags"]); IWzImageProperty questParent = obj["quest"]; List <ObjectInstanceQuest> questInfo = null; if (questParent != null) { foreach (WzCompressedIntProperty info in questParent.WzProperties) { questInfo.Add(new ObjectInstanceQuest(int.Parse(info.Name), (QuestState)info.Value)); } } bool flip = InfoTool.GetBool(obj["f"]); IWzImageProperty objInfoProp = Program.InfoManager.ObjectSets[oS][l0][l1][l2]; if (objInfoProp.HCTag == null) { objInfoProp.HCTag = ObjectInfo.Load((WzSubProperty)objInfoProp, oS, l0, l1, l2); } ObjectInfo objInfo = (ObjectInfo)objInfoProp.HCTag; mapBoard.BoardItems.TileObjs.Add((LayeredItem)objInfo.CreateInstance(mapBoard.Layers[layer], mapBoard, x, y, z, r, hide, reactor, flow, rx, ry, cx, cy, name, tags, questInfo, flip, false, false)); } IWzImageProperty tileParent = layerProp["tile"]; for (int i = 0; i < tileParent.WzProperties.Count; i++) //foreach (IWzImageProperty tile in layerProp["tile"].WzProperties) { IWzImageProperty tile = tileParent.WzProperties[i]; int x = InfoTool.GetInt(tile["x"]); int y = InfoTool.GetInt(tile["y"]); //int zM = InfoTool.GetInt(tile["zM"]); string u = InfoTool.GetString(tile["u"]); int no = InfoTool.GetInt(tile["no"]); IWzImageProperty tileInfoProp = Program.InfoManager.TileSets[tS][u][no.ToString()]; if (tileInfoProp.HCTag == null) { tileInfoProp.HCTag = TileInfo.Load((WzCanvasProperty)tileInfoProp, tS, u, no.ToString()); } TileInfo tileInfo = (TileInfo)tileInfoProp.HCTag; mapBoard.BoardItems.TileObjs.Add((LayeredItem)tileInfo.CreateInstance(mapBoard.Layers[layer], mapBoard, x, y, i /*zM*/, false, false, false)); } } }