public void CreateMineField() { if (Id == 91) { var zoneId = GetNextZoneId(); var mineZone = new MineZone(zoneId, new Vector(15000, -1), new Vector(28500, 6500), this); mineZone.Spawn(); Zones.Add(zoneId, mineZone); zoneId = GetNextZoneId(); mineZone = new MineZone(zoneId, new Vector(14500, 20000), new Vector(27000, 26000), this); mineZone.Spawn(); Zones.Add(zoneId, mineZone); } else if (Id == 93) { var zoneId = GetNextZoneId(); var mineZone = new MineZone(zoneId, new Vector(700, 20500), new Vector(10700, 25700), this); mineZone.Spawn(); Zones.Add(zoneId, mineZone); zoneId = GetNextZoneId(); mineZone = new MineZone(zoneId, new Vector(5000, 5500), new Vector(10000, 20400), this); mineZone.Spawn(); Zones.Add(zoneId, mineZone); } }
private void VForm_FormClosing(object sender, FormClosingEventArgs e) { VisualizerGlobal.ZoomLevel = 1; VisualizerGlobal.MapInfo.Respawns.Clear(); VisualizerGlobal.MapInfo.MineZones.Clear(); for (int i = 0; i < RespawnPanel.Controls.Count; i++) { try { RespawnEntry RespawnControl = (RespawnEntry)RespawnPanel.Controls[i]; MirDatabase.RespawnInfo NewRespawnZone = new MirDatabase.RespawnInfo(); NewRespawnZone.Location = new Point(RespawnControl.X, RespawnControl.Y); NewRespawnZone.MonsterIndex = RespawnControl.MonsterIndex; NewRespawnZone.Spread = RespawnControl.Range; NewRespawnZone.Count = Convert.ToUInt16(RespawnControl.Count.Text); NewRespawnZone.Delay = Convert.ToUInt16(RespawnControl.Delay.Text); NewRespawnZone.RoutePath = RespawnControl.RoutePath; NewRespawnZone.Direction = RespawnControl.Direction; NewRespawnZone.RandomDelay = RespawnControl.RandomDelay; VisualizerGlobal.MapInfo.Respawns.Add(NewRespawnZone); } catch (Exception) { continue; } } for (int i = 0; i < MiningPanel.Controls.Count; i++) { try { MineEntry MineControl = (MineEntry)MiningPanel.Controls[i]; MineZone NewMineZone = new MineZone(); NewMineZone.Location = new Point(MineControl.X, MineControl.Y); NewMineZone.Mine = MineControl.MineIndex; NewMineZone.Size = MineControl.Range; VisualizerGlobal.MapInfo.MineZones.Add(NewMineZone); } catch (Exception) { continue; } } }
private void VForm_FormClosing(object sender, FormClosingEventArgs e) { VisualizerGlobal.ZoomLevel = 1; VisualizerGlobal.MapInfo.Respawns.Clear(); VisualizerGlobal.MapInfo.MineZones.Clear(); for (int i = 0; i < RespawnPanel.Controls.Count; i++) { try { RespawnEntry RespawnControl = (RespawnEntry)RespawnPanel.Controls[i]; MirDatabase.RespawnInfo NewRespawnZone = new MirDatabase.RespawnInfo(); NewRespawnZone.Location = new Point(RespawnControl.X, RespawnControl.Y); NewRespawnZone.MonsterIndex = RespawnControl.MonsterIndex; NewRespawnZone.Spread = RespawnControl.Range; NewRespawnZone.Count = Convert.ToUInt16(RespawnControl.Count.Text); NewRespawnZone.Delay = Convert.ToUInt16(RespawnControl.Delay.Text); NewRespawnZone.RoutePath = RespawnControl.RoutePath; VisualizerGlobal.MapInfo.Respawns.Add(NewRespawnZone); } catch (Exception) { continue; } } for (int i = 0; i < MiningPanel.Controls.Count; i++) { try { MineEntry MineControl = (MineEntry)MiningPanel.Controls[i]; MineZone NewMineZone = new MineZone(); NewMineZone.Location = new Point(MineControl.X, MineControl.Y); NewMineZone.Mine = MineControl.MineIndex; NewMineZone.Size = MineControl.Range; VisualizerGlobal.MapInfo.MineZones.Add(NewMineZone); } catch (Exception) { continue; } } }
public static void Start(Envir envirToUpdate) { if (Path == string.Empty) { return; } EditEnvir = envirToUpdate; if (EditEnvir == null) { return; } var lines = File.ReadAllLines(Path); _endIndex = EditEnvir.MapIndex; // Last map index number for (int i = 0; i < lines.Length; i++) { if (lines[i].StartsWith("[")) // Read map info { lines[i] = System.Text.RegularExpressions.Regex.Replace(lines[i], @"\s+", " "); // Clear white-space lines[i] = lines[i].Replace(" ;", ";"); // Remove space before semi-colon // Trim comment at the end of the line if (lines[i].Contains(';')) { lines[i] = lines[i].Substring(0, lines[i].IndexOf(";", System.StringComparison.Ordinal)); } MirDatabase.MapInfo newMapInfo = new MirDatabase.MapInfo { Index = ++_endIndex }; var a = lines[i].Split(']'); // Split map info into [0] = MapFile MapName 0 || [1] = Attributes string[] b = a[0].Split(' '); newMapInfo.FileName = b[0].TrimStart('['); // Assign MapFile from variable and trim leading '[' char newMapInfo.Title = b[1]; // Assign MapName from variable List <string> mapAttributes = new List <string>(); // Group of all attributes associated with that map mapAttributes.AddRange(a[1].Split(' ')); newMapInfo.NoTeleport = mapAttributes.Any(s => s.Contains("NOTELEPORT".ToUpper())); newMapInfo.NoRandom = mapAttributes.Any(s => s.Contains("NORANDOMMOVE".ToUpper())); newMapInfo.NoEscape = mapAttributes.Any(s => s.Contains("NOESCAPE".ToUpper())); newMapInfo.NoRecall = mapAttributes.Any(s => s.Contains("NORECALL".ToUpper())); newMapInfo.NoDrug = mapAttributes.Any(s => s.Contains("NODRUG".ToUpper())); newMapInfo.NoPosition = mapAttributes.Any(s => s.Contains("NOPOSITIONMOVE".ToUpper())); newMapInfo.NoThrowItem = mapAttributes.Any(s => s.Contains("NOTHROWITEM".ToUpper())); newMapInfo.NoDropPlayer = mapAttributes.Any(s => s.Contains("NOPLAYERDROP".ToUpper())); newMapInfo.NoDropMonster = mapAttributes.Any(s => s.Contains("NOMONSTERDROP".ToUpper())); newMapInfo.NoNames = mapAttributes.Any(s => s.Contains("NONAMES".ToUpper())); newMapInfo.NoFight = mapAttributes.Any(s => s.Contains("NOFIGHT".ToUpper())); newMapInfo.NoMount = mapAttributes.Any(s => s.Contains("NOMOUNT".ToUpper())); newMapInfo.NeedBridle = mapAttributes.Any(s => s.Contains("NEEDBRIDLE".ToUpper())); newMapInfo.Fight = mapAttributes.Any(s => s.Contains("FIGHT".ToUpper())); newMapInfo.NoTownTeleport = mapAttributes.Any(s => s.Contains("NOTOWNTELEPORT".ToUpper())); newMapInfo.Fire = mapAttributes.Any(x => x.StartsWith("FIRE(".ToUpper())); if (newMapInfo.Fire) { int index = mapAttributes.FindIndex(x => x.StartsWith("FIRE(".ToUpper())); newMapInfo.FireDamage = Convert.ToInt16(mapAttributes[index].TrimStart("FIRE(".ToCharArray()).TrimEnd(')')); } newMapInfo.Lightning = mapAttributes.Any(x => x.StartsWith("LIGHTNING(".ToUpper())); if (newMapInfo.Lightning) { int index = mapAttributes.FindIndex(x => x.StartsWith("LIGHTNING(".ToUpper())); newMapInfo.LightningDamage = Convert.ToInt16(mapAttributes[index].TrimStart("LIGHTNING(".ToCharArray()).TrimEnd(')')); } newMapInfo.NoReconnect = mapAttributes.Any(x => x.StartsWith("NORECONNECT(".ToUpper())); if (newMapInfo.NoReconnect) { int index = mapAttributes.FindIndex(x => x.StartsWith("NORECONNECT(".ToUpper())); newMapInfo.NoReconnectMap = newMapInfo.NoReconnectMap == string.Empty ? "0" : mapAttributes[index].TrimStart("NORECONNECT(".ToCharArray()).TrimEnd(')'); } if (mapAttributes.Any(x => x.StartsWith("MINIMAP(".ToUpper()))) { int index = mapAttributes.FindIndex(x => x.StartsWith("MINIMAP(".ToUpper())); newMapInfo.MiniMap = Convert.ToUInt16(mapAttributes[index].TrimStart("MINIMAP(".ToCharArray()).TrimEnd(')')); } if (mapAttributes.Any(x => x.StartsWith("BIGMAP(".ToUpper()))) { int index = mapAttributes.FindIndex(x => x.StartsWith("BIGMAP(".ToUpper())); newMapInfo.BigMap = Convert.ToUInt16(mapAttributes[index].TrimStart("BIGMAP(".ToCharArray()).TrimEnd(')')); } if (mapAttributes.Any(s => s.Contains("MINE(".ToUpper()))) { int index = mapAttributes.FindIndex(x => x.StartsWith("MINE(".ToUpper())); newMapInfo.MineIndex = Convert.ToByte(mapAttributes[index].TrimStart("MINE(".ToCharArray()).TrimEnd(')')); } if (mapAttributes.Any(s => s.Contains("MAPLIGHT(".ToUpper()))) { int index = mapAttributes.FindIndex(x => x.StartsWith("MAPLIGHT(".ToUpper())); newMapInfo.MapDarkLight = Convert.ToByte(mapAttributes[index].TrimStart("MAPLIGHT(".ToCharArray()).TrimEnd(')')); } if (mapAttributes.Any(s => s.Contains("MUSIC(".ToUpper()))) { int index = mapAttributes.FindIndex(x => x.StartsWith("MUSIC(".ToUpper())); newMapInfo.Music = Convert.ToUInt16(mapAttributes[index].TrimStart("MUSIC(".ToCharArray()).TrimEnd(')')); } if (mapAttributes.Any(x => x.StartsWith("LIGHT(".ToUpper()))) // Check if there is a LIGHT attribute and get its value { int index = mapAttributes.FindIndex(x => x.StartsWith("LIGHT(".ToUpper())); switch (mapAttributes[index].TrimStart("LIGHT(".ToCharArray()).TrimEnd(')')) { case "Dawn": newMapInfo.Light = LightSetting.Dawn; break; case "Day": newMapInfo.Light = LightSetting.Day; break; case "Evening": newMapInfo.Light = LightSetting.Evening; break; case "Night": newMapInfo.Light = LightSetting.Night; break; case "Normal": newMapInfo.Light = LightSetting.Normal; break; default: newMapInfo.Light = LightSetting.Normal; break; } } else { newMapInfo.Light = LightSetting.Normal; } // Check for light type if (mapAttributes.Any(s => s.Contains("DAY".ToUpper()))) // DAY = Day { newMapInfo.Light = LightSetting.Day; } else if (mapAttributes.Any(s => s.Contains("DARK".ToUpper()))) // DARK = Night { newMapInfo.Light = LightSetting.Night; } EditEnvir.MapInfoList.Add(newMapInfo); // Add map to list } else if (lines[i].StartsWith(";")) { continue; } else { errors.Add("Error on Line " + i + ": " + lines[i] + ""); } } for (int j = 0; j < EditEnvir.MapInfoList.Count; j++) { for (int k = 0; k < lines.Length; k++) { try { if (lines[k].StartsWith(EditEnvir.MapInfoList[j].FileName + " ")) { MirDatabase.MovementInfo newMovement = new MirDatabase.MovementInfo(); if (lines[k].Contains("NEEDHOLE")) { newMovement.NeedHole = true; lines[k] = lines[k].Replace("NEEDHOLE", ""); } if (lines[k].Contains("NEEDMOVE")) { newMovement.NeedMove = true; lines[k] = lines[k].Replace("NEEDMOVE", ""); } if (lines[k].Contains("NEEDCONQUEST")) { int conqLocation = lines[k].IndexOf(" NEEDCONQUEST"); string conq = lines[k].Substring(conqLocation); int conqIndex = int.Parse(conq.Replace("NEEDCONQUEST(", "").Replace(")", "")); //get value newMovement.ConquestIndex = conqIndex; lines[k] = lines[k].Remove(conqLocation); } if (lines[k].Contains("SHOWONBIGMAP")) { newMovement.ShowOnBigMap = true; lines[k] = lines[k].Replace("SHOWONBIGMAP", ""); } if (lines[k].Contains("ICON")) { int iconLocation = lines[k].IndexOf(" ICON"); string icon = lines[k].Substring(iconLocation); int iconIndex = int.Parse(icon.Replace("ICON(", "").Replace(")", "")); //get value newMovement.Icon = iconIndex; lines[k] = lines[k].Remove(iconLocation); } lines[k] = lines[k].Replace('.', ','); // Replace point with comma lines[k] = lines[k].Replace(":", ","); // Replace colon with comma lines[k] = lines[k].Replace(", ", ","); // Remove space after comma lines[k] = lines[k].Replace(" ,", ","); // Remove space before comma lines[k] = System.Text.RegularExpressions.Regex.Replace(lines[k], @"\s+", " "); // Clear whitespace lines[k] = lines[k].Replace(" ;", ";"); // Remove space before semi-colon // Trim comment at the end of the line if (lines[k].Contains(';')) { lines[k] = lines[k].Substring(0, lines[k].IndexOf(";", System.StringComparison.Ordinal)); } var c = lines[k].Split(' '); // START - Get values from line if (c.Length == 7) // Every value has a space { c[1] = c[1] + "," + c[2]; c[2] = c[5] + "," + c[6]; c[3] = c[4]; } else if (c.Length == 6) // One value has a space { if (c[2] == "->") // Space in to XY { c[2] = c[4] + "," + c[5]; } else if (c[3] == "->") // Space in from XY { c[1] = c[1] + "," + c[2]; c[2] = c[5]; c[3] = c[4]; } } else if (c.Length == 5) // Proper format { c[2] = c[4]; } else // Unreadable value count { continue; } // END - Get values from line string[] d = c[1].Split(','); string[] e = c[2].Split(','); var toMapIndex = EditEnvir.MapInfoList.FindIndex(a => a.FileName == c[3]); //check existing maps for the connection info var toMap = -1; if (toMapIndex >= 0) { toMap = EditEnvir.MapInfoList[toMapIndex].Index; //get real index } if (toMap < 0) { toMapIndex = EditEnvir.MapInfoList.FindIndex(a => a.FileName.ToString() == c[3]); if (toMapIndex >= 0) { toMap = EditEnvir.MapInfoList[toMapIndex].Index; } } if (toMap < 0) { continue; } newMovement.MapIndex = toMap; newMovement.Source = new Point(int.Parse(d[0]), int.Parse(d[1])); newMovement.Destination = new Point(int.Parse(e[0]), int.Parse(e[1])); //NeedHole //NeedMove //ConquestIndex EditEnvir.MapInfoList[j].Movements.Add(newMovement); } } catch (Exception) { continue; } } } for (int j = 0; j < EditEnvir.MapInfoList.Count; j++) { for (int k = 0; k < lines.Length; k++) { if (!lines[k].StartsWith("MINEZONE")) { continue; } var line = lines[k].Split(' '); try { if (line[1] == EditEnvir.MapInfoList[j].FileName) { MineZone newMineInfo = new MineZone { Mine = Convert.ToByte(line[3]), Location = new Point(Convert.ToInt16(line[4]), Convert.ToInt16(line[5])), Size = Convert.ToUInt16(line[6]) }; EditEnvir.MapInfoList[j].MineZones.Add(newMineInfo); } } catch (Exception) { continue; } } } for (int j = 0; j < EditEnvir.MapInfoList.Count; j++) { for (int k = 0; k < lines.Length; k++) { //STARTZONE(0,150,150,50) || SAFEZONE(0,150,150,50) if (!lines[k].StartsWith("SAFEZONE") && !lines[k].StartsWith("STARTZONE")) { continue; } var line = lines[k].Replace(")", "").Split(','); // STARTZONE(0,150,150,50) -> STARTZONE(0 || 150 || 150 || 50 var head = line[0].Split('('); // STARTZONE(0 -> STARTZONE || 0 try { if (head[1] == EditEnvir.MapInfoList[j].FileName) { MirDatabase.SafeZoneInfo newSafeZone = new MirDatabase.SafeZoneInfo { Info = EditEnvir.MapInfoList[j], StartPoint = head[0].Equals("STARTZONE"), Location = new Point(Convert.ToInt16(line[2]), Convert.ToInt16(line[3])), Size = Convert.ToUInt16(line[1]) }; if (!EditEnvir.MapInfoList[j].SafeZones.Exists(sz => sz.StartPoint == newSafeZone.StartPoint && sz.Location.X == newSafeZone.Location.X && sz.Location.Y == newSafeZone.Location.Y)) { EditEnvir.MapInfoList[j].SafeZones.Add(newSafeZone); } } } catch (Exception) { continue; } } } }
private void ImportMapInfoButton_Click(object sender, EventArgs e) { OpenFileDialog ofd = new OpenFileDialog(); ofd.Filter = "Text File|*.txt"; ofd.ShowDialog(); if (ofd.FileName == string.Empty) return; MirForms.ConvertMapInfo.Path = ofd.FileName; MirForms.ConvertMapInfo.Start(Envir); for (int i = 0; i < MirForms.ConvertMapInfo.MapInfo.Count; i++) { MapInfo mi = new MapInfo { Index = ++Envir.MapIndex, FileName = MirForms.ConvertMapInfo.MapInfo[i].MapFile, Title = MirForms.ConvertMapInfo.MapInfo[i].MapName.Replace('*', ' '), NoTeleport = MirForms.ConvertMapInfo.MapInfo[i].NoTeleport, NoReconnect = MirForms.ConvertMapInfo.MapInfo[i].NoReconnect, NoRandom = MirForms.ConvertMapInfo.MapInfo[i].NoRandom, NoEscape = MirForms.ConvertMapInfo.MapInfo[i].NoEscape, NoRecall = MirForms.ConvertMapInfo.MapInfo[i].NoRecall, NoDrug = MirForms.ConvertMapInfo.MapInfo[i].NoDrug, NoPosition = MirForms.ConvertMapInfo.MapInfo[i].NoPositionMove, NoThrowItem = MirForms.ConvertMapInfo.MapInfo[i].NoThrowItem, NoDropPlayer = MirForms.ConvertMapInfo.MapInfo[i].NoPlayerDrop, NoDropMonster = MirForms.ConvertMapInfo.MapInfo[i].NoMonsterDrop, NoNames = MirForms.ConvertMapInfo.MapInfo[i].NoNames, Fight = MirForms.ConvertMapInfo.MapInfo[i].Fight, NoFight = MirForms.ConvertMapInfo.MapInfo[i].NoFight, Fire = MirForms.ConvertMapInfo.MapInfo[i].Fire, Lightning = MirForms.ConvertMapInfo.MapInfo[i].Lightning, Light = MirForms.ConvertMapInfo.MapInfo[i].Light, MiniMap = MirForms.ConvertMapInfo.MapInfo[i].MiniMapNumber, BigMap = MirForms.ConvertMapInfo.MapInfo[i].BigMapNumber, Music = MirForms.ConvertMapInfo.MapInfo[i].MusicNumber, MineIndex = (byte)MirForms.ConvertMapInfo.MapInfo[i].MineIndex, }; if (mi.NoReconnect == true) mi.NoReconnectMap = MirForms.ConvertMapInfo.MapInfo[i].ReconnectMap; if (mi.Fire == true) mi.FireDamage = MirForms.ConvertMapInfo.MapInfo[i].FireDamage; if (mi.Lightning == true) mi.LightningDamage = MirForms.ConvertMapInfo.MapInfo[i].LightningDamage; if (MirForms.ConvertMapInfo.MapInfo[i].MapLight == true) mi.MapDarkLight = MirForms.ConvertMapInfo.MapInfo[i].MapLightValue; Envir.MapInfoList.Add(mi); } for (int j = 0; j < MirForms.ConvertMapInfo.MapMovements.Count; j++) { try { MovementInfo newmoveinfo = new MovementInfo(); newmoveinfo.MapIndex = Convert.ToInt16(MirForms.ConvertMapInfo.MapMovements[j].toMap); newmoveinfo.Source = new Point (Convert.ToInt16(MirForms.ConvertMapInfo.MapMovements[j].fromX), (Convert.ToInt16(MirForms.ConvertMapInfo.MapMovements[j].fromY))); newmoveinfo.Destination = new Point (Convert.ToInt16(MirForms.ConvertMapInfo.MapMovements[j].toX), (Convert.ToInt16(MirForms.ConvertMapInfo.MapMovements[j].toY))); newmoveinfo.NeedHole = false; newmoveinfo.NeedMove = false; Envir.MapInfoList[Envir.MapInfoList.FindIndex(a => a.Index == (MirForms.ConvertMapInfo.MapMovements[j].fromIndex))].Movements.Add(newmoveinfo); } catch (Exception) { continue; } } for (int i = 0; i < MirForms.ConvertMapInfo.MineInfo.Count; i++) { MineZone mz = new MineZone(); try { mz.Location = MirForms.ConvertMapInfo.MineInfo[i].Location; mz.Size = (ushort)MirForms.ConvertMapInfo.MineInfo[i].Range; mz.Mine = (byte)MirForms.ConvertMapInfo.MineInfo[i].MineIndex; Envir.MapInfoList[MirForms.ConvertMapInfo.MineInfo[i].MapIndex - 1].MineZones.Add(mz); } catch (Exception) { continue; } } MirForms.ConvertMapInfo.End(); UpdateInterface(); MessageBox.Show("Map Info Import Complete"); }