void analyse_data() { try { List <Library> libraries = new List <Library>(); if (fLibrary == null) { libraries.AddRange(Session.Libraries); } else { libraries.Add(fLibrary); } fBreakdown = new Dictionary <string, int>(); set_labels(libraries); foreach (Library lib in libraries) { add_library(lib); } } catch (Exception ex) { LogSystem.Trace(ex); } }
private void ContextClear_Click(object sender, EventArgs e) { try { List <TileData> obsolete = new List <TileData>(); foreach (TileData td in fMap.Tiles) { if (!MapView.LayoutData.TileSquares.ContainsKey(td)) { continue; } Rectangle rect = MapView.LayoutData.TileSquares[td]; if (MapView.Selection.IntersectsWith(rect)) { obsolete.Add(td); } } foreach (TileData td in obsolete) { fMap.Tiles.Remove(td); } MapView.Selection = Rectangle.Empty; MapView.MapChanged(); } catch (Exception ex) { LogSystem.Trace(ex); } }
private void ContextSelect_Click(object sender, EventArgs e) { try { MapView.SelectedTiles.Clear(); foreach (TileData td in fMap.Tiles) { if (!MapView.LayoutData.TileSquares.ContainsKey(td)) { continue; } Rectangle rect = MapView.LayoutData.TileSquares[td]; if (MapView.Selection.IntersectsWith(rect)) { MapView.SelectedTiles.Add(td); } } MapView.Selection = Rectangle.Empty; } catch (Exception ex) { LogSystem.Trace(ex); } }
public static Project LoadBackup(string filename) { Project p = null; try { Assembly ass = Assembly.GetEntryAssembly(); string dir = Tools.FileName.Directory(ass.Location) + "Backup\\"; if (!Directory.Exists(dir)) { Directory.CreateDirectory(dir); } string backup_name = dir + Tools.FileName.Name(filename); if (File.Exists(backup_name)) { p = Serialisation <Project> .Load(backup_name, SerialisationMode.Binary); if (p != null) { string str = "There was a problem opening this project; it has been recovered from its most recent backup version."; MessageBox.Show(str, "Masterplan", MessageBoxButtons.OK, MessageBoxIcon.Information); } } } catch (Exception ex) { LogSystem.Trace(ex); } return(p); }
private void ContextCreate_Click(object sender, EventArgs e) { try { if (MapView.Selection != Rectangle.Empty) { MapArea area = new MapArea(); area.Name = "New Area"; area.Region = MapView.Selection; MapAreaForm dlg = new MapAreaForm(area, fMap); if (dlg.ShowDialog() == DialogResult.OK) { fMap.Areas.Add(dlg.Area); update_areas(); MapView.Selection = Rectangle.Empty; } } } catch (Exception ex) { LogSystem.Trace(ex); } }
public static Library LoadLibrary(string filename) { try { if (Program.SplashScreen != null) { Program.SplashScreen.CurrentSubAction = Tools.FileName.Name(filename); Program.SplashScreen.Progress += 1; } Library lib = Serialisation <Library> .Load(filename, SerialisationMode.Binary); if (lib != null) { lib.Name = Tools.FileName.Name(filename); lib.Update(); Session.Libraries.Add(lib); } else { LogSystem.Trace("Could not load " + Tools.FileName.Name(filename)); } return(lib); } catch (Exception ex) { LogSystem.Trace(ex); } return(null); }
private void Import_iPlay4e_Party_Click(object sender, EventArgs e) { try { HeroIPlay4eForm heroIPlay4eForm = new HeroIPlay4eForm("", false); if (heroIPlay4eForm.ShowDialog() == System.Windows.Forms.DialogResult.OK) { System.Windows.Forms.Cursor.Current = Cursors.WaitCursor; List <Hero> heros = AppImport.ImportParty(heroIPlay4eForm.Key); System.Windows.Forms.Cursor.Current = Cursors.Default; foreach (Hero hero in heros) { this.add_hero(hero); } this.update_view(); if (heros.Count == 0) { MessageBox.Show("No characters were found (make sure they are public).", "Masterplan", MessageBoxButtons.OK, MessageBoxIcon.Asterisk); } } } catch (Exception exception) { LogSystem.Trace(exception); } }
private static void save_preferences() { try { string str = FileName.Directory(Assembly.GetEntryAssembly().Location); string str1 = string.Concat(str, "Preferences.xml"); Serialisation <Preferences> .Save(str1, Session.Preferences, SerialisationMode.XML); } catch (Exception exception) { LogSystem.Trace(exception); } }
private static void Main(string[] args) { Application.EnableVisualStyles(); Application.SetCompatibleTextRenderingDefault(false); try { Program.init_logging(); Program.SplashScreen = new ProgressScreen("Masterplan", 0) { CurrentAction = "Loading..." }; Program.SplashScreen.Show(); Program.load_preferences(); Program.load_libraries(); string[] strArrays = args; for (int i = 0; i < (int)strArrays.Length; i++) { Program.handle_arg(strArrays[i]); } Program.SplashScreen.CurrentAction = "Starting Masterplan..."; Program.SplashScreen.Actions = 0; try { Application.Run(new MainForm()); } catch (Exception exception) { LogSystem.Trace(exception); } List <Form> forms = new List <Form>(); foreach (Form openForm in Application.OpenForms) { forms.Add(openForm); } foreach (Form form in forms) { form.Close(); } Program.save_preferences(); if (Program.IsBeta) { Program.check_for_logs(); } } catch (Exception exception1) { LogSystem.Trace(exception1); } }
private static void load_libraries() { try { Program.SplashScreen.CurrentAction = "Loading libraries..."; string str = FileName.Directory(Assembly.GetEntryAssembly().Location); string str1 = string.Concat(str, "Libraries\\"); if (!Directory.Exists(str1)) { Directory.CreateDirectory(str1); } string[] files = Directory.GetFiles(str, "*.library"); for (int i = 0; i < (int)files.Length; i++) { string str2 = files[i]; try { string str3 = string.Concat(str1, FileName.Name(str2), ".library"); if (!File.Exists(str3)) { File.Move(str2, str3); } } catch (Exception exception) { LogSystem.Trace(exception); } } string[] strArrays = Directory.GetFiles(str1, "*.library"); Program.SplashScreen.Actions = (int)strArrays.Length; string[] strArrays1 = strArrays; for (int j = 0; j < (int)strArrays1.Length; j++) { Session.LoadLibrary(strArrays1[j]); } Session.Libraries.Sort(); } catch (Exception exception1) { LogSystem.Trace(exception1); } }
public static void CreateBackup(string filename) { try { Assembly ass = Assembly.GetEntryAssembly(); string dir = Tools.FileName.Directory(ass.Location) + "Backup\\"; if (!Directory.Exists(dir)) { Directory.CreateDirectory(dir); } string new_name = dir + Tools.FileName.Name(filename); File.Copy(filename, new_name, true); } catch (Exception ex) { LogSystem.Trace(ex); } }
private static void load_preferences() { try { string str = FileName.Directory(Assembly.GetEntryAssembly().Location); string str1 = string.Concat(str, "Preferences.xml"); if (File.Exists(str1)) { Program.SplashScreen.CurrentAction = "Loading user preferences"; Preferences preference = Serialisation <Preferences> .Load(str1, SerialisationMode.XML); if (preference != null) { Session.Preferences = preference; } } } catch (Exception exception) { LogSystem.Trace(exception); } }
private void Import_iPlay4e_Click(object sender, EventArgs e) { try { HeroIPlay4eForm heroIPlay4eForm = new HeroIPlay4eForm("", true); if (heroIPlay4eForm.ShowDialog() == System.Windows.Forms.DialogResult.OK) { Hero hero = new Hero() { Key = heroIPlay4eForm.Key }; System.Windows.Forms.Cursor.Current = Cursors.WaitCursor; bool flag = AppImport.ImportIPlay4e(hero); System.Windows.Forms.Cursor.Current = Cursors.Default; if (!flag) { string str = string.Concat("The character could not be found.", Environment.NewLine); str = string.Concat(str, Environment.NewLine); str = string.Concat(str, "Make sure:"); str = string.Concat(str, Environment.NewLine); str = string.Concat(str, "* The key is correct"); str = string.Concat(str, Environment.NewLine); str = string.Concat(str, "* The character is public"); MessageBox.Show(str, "Masterplan", MessageBoxButtons.OK, MessageBoxIcon.Asterisk); } else { this.add_hero(hero); this.update_view(); } } } catch (Exception exception) { LogSystem.Trace(exception); } }
void populate_tiles() { List <Library> libraries = new List <Library>(); libraries.AddRange(Session.Libraries); libraries.Add(Session.Project.Library); List <string> sets = new List <string>(); switch (Session.Preferences.TileView) { case TileView.Library: { foreach (Library lib in libraries) { if (!fTileSets[lib.ID]) { continue; } if (!sets.Contains(lib.Name)) { sets.Add(lib.Name); } } sets.Sort(); } break; case TileView.Size: { List <int> areas = new List <int>(); foreach (Library lib in libraries) { foreach (Tile t in lib.Tiles) { if (!areas.Contains(t.Area)) { areas.Add(t.Area); } } } areas.Sort(); foreach (int area in areas) { sets.Add("Size: " + area); } } break; case TileView.Category: { foreach (TileCategory cat in Enum.GetValues(typeof(TileCategory))) { sets.Add(cat.ToString()); } } break; } int size = 32; switch (Session.Preferences.TileSize) { case TileSize.Small: size = 16; break; case TileSize.Medium: size = 32; break; case TileSize.Large: size = 64; break; } TileList.BeginUpdate(); TileList.Groups.Clear(); foreach (string set in sets) { TileList.Groups.Add(set, set); } TileList.ShowGroups = (TileList.Groups.Count != 0); List <ListViewItem> item_list = new List <ListViewItem>(); List <Image> image_list = new List <Image>(); foreach (Library lib in libraries) { if (!fTileSets[lib.ID]) { continue; } foreach (Tile t in lib.Tiles) { if (!match(t, SearchBox.Text)) { continue; } ListViewItem lvi = new ListViewItem(t.ToString()); lvi.Tag = t; switch (Session.Preferences.TileView) { case TileView.Library: lvi.Group = TileList.Groups[lib.Name]; break; case TileView.Size: lvi.Group = TileList.Groups["Size: " + t.Area]; break; case TileView.Category: lvi.Group = TileList.Groups[t.Category.ToString()]; break; } // Get tile image Image img = (t.Image != null) ? t.Image : t.BlankImage; if (img == null) { continue; } try { Bitmap bmp = new Bitmap(size, size); if (t.Size.Width > t.Size.Height) { int height = (t.Size.Height * size) / t.Size.Width; Rectangle rect = new Rectangle(0, (size - height) / 2, size, height); Graphics g = Graphics.FromImage(bmp); g.DrawImage(img, rect); } else { int width = (t.Size.Width * size) / t.Size.Height; Rectangle rect = new Rectangle((size - width) / 2, 0, width, size); Graphics g = Graphics.FromImage(bmp); g.DrawImage(img, rect); } image_list.Add(bmp); lvi.ImageIndex = image_list.Count - 1; item_list.Add(lvi); } catch (Exception ex) { LogSystem.Trace(ex); } } } TileList.LargeImageList = new ImageList(); TileList.LargeImageList.ColorDepth = ColorDepth.Depth32Bit; TileList.LargeImageList.ImageSize = new Size(size, size); TileList.LargeImageList.Images.AddRange(image_list.ToArray()); TileList.Items.Clear(); TileList.Items.AddRange(item_list.ToArray()); if (TileList.Items.Count == 0) { ListViewItem lvi = TileList.Items.Add("(no tiles)"); lvi.ForeColor = SystemColors.GrayText; } TileList.EndUpdate(); }
private static void build_warren(EventHandler callback) { MapBuilder.begin_map(); int num = 0; while (MapBuilder.fMap.Areas.Count < MapBuilder.fData.MaxAreaCount && MapBuilder.fEndpoints.Count != 0 && num != 100) { int num1 = Session.Random.Next() % MapBuilder.fEndpoints.Count; Endpoint item = MapBuilder.fEndpoints[num1]; bool flag = true; switch (Session.Random.Next() % 10) { case 0: case 1: case 2: { try { flag = MapBuilder.add_area(item); break; } catch (Exception exception) { LogSystem.Trace(exception); flag = false; break; } } case 3: case 4: case 5: case 6: case 7: { try { flag = MapBuilder.add_corridor(item, false); break; } catch (Exception exception1) { LogSystem.Trace(exception1); flag = false; break; } } case 8: { try { if (item.Category != TileCategory.Doorway) { flag = MapBuilder.add_doorway(item); } break; } catch (Exception exception2) { LogSystem.Trace(exception2); flag = false; break; } } case 9: { try { flag = MapBuilder.add_stairway(item); break; } catch (Exception exception3) { LogSystem.Trace(exception3); flag = false; break; } } } if (!flag) { num++; } else { MapBuilder.fEndpoints.Remove(item); num = 0; callback(null, null); } } List <TileData> tileDatas = new List <TileData>(); foreach (TileData tile in MapBuilder.fMap.Tiles) { Tile tile1 = Session.FindTile(tile.TileID, SearchType.Global); if (tile1 != null) { if (tile1.Category != TileCategory.Doorway) { continue; } Rectangle _rect = MapBuilder.get_rect(tile1, tile); int num2 = 0; int left = _rect.Left; while (left != _rect.Right) { int top = _rect.Top - 1; if (MapBuilder.tile_at_point(new Point(left, top)) != null) { left++; } else { num2++; break; } } int left1 = _rect.Left; while (left1 != _rect.Right) { int bottom = _rect.Bottom + 1; if (MapBuilder.tile_at_point(new Point(left1, bottom)) != null) { left1++; } else { num2++; break; } } int top1 = _rect.Top; while (top1 != _rect.Bottom) { int left2 = _rect.Left - 1; if (MapBuilder.tile_at_point(new Point(left2, top1)) != null) { top1++; } else { num2++; break; } } int top2 = _rect.Top; while (top2 != _rect.Bottom) { int right = _rect.Right + 1; if (MapBuilder.tile_at_point(new Point(right, top2)) != null) { top2++; } else { num2++; break; } } if (num2 == 2) { continue; } tileDatas.Add(tile); } else { tileDatas.Add(tile); } } foreach (TileData tileData in tileDatas) { MapBuilder.fMap.Tiles.Remove(tileData); callback(null, null); } }
private static void run_creature_stats() { List <Creature> creatures = Session.Creatures; bool[] flagArray = new bool[] { false, true }; bool[] flagArray1 = new bool[] { false, true }; string str = string.Concat(Environment.GetFolderPath(Environment.SpecialFolder.Desktop), "\\Creatures.csv"); StreamWriter streamWriter = new StreamWriter(str); try { try { streamWriter.Write("Level,Flag,Role,Minion,Leader,Tier,TierX,Creatures,Powers"); foreach (string condition in Conditions.GetConditions()) { streamWriter.Write(string.Concat(",", condition)); } foreach (DamageType value in Enum.GetValues(typeof(DamageType))) { streamWriter.Write(string.Concat(",", value)); } streamWriter.WriteLine(); for (int i = 1; i <= 40; i++) { bool[] flagArray2 = flagArray; for (int j = 0; j < (int)flagArray2.Length; j++) { bool flag = flagArray2[j]; bool[] flagArray3 = flagArray1; for (int k = 0; k < (int)flagArray3.Length; k++) { bool flag1 = flagArray3[k]; foreach (RoleType roleType in Enum.GetValues(typeof(RoleType))) { foreach (RoleFlag roleFlag in Enum.GetValues(typeof(RoleFlag))) { List <Creature> _creatures = Program.get_creatures(creatures, i, flag, flag1, roleType, roleFlag); List <CreaturePower> creaturePowers = new List <CreaturePower>(); foreach (Creature _creature in _creatures) { creaturePowers.AddRange(_creature.CreaturePowers); } if (creaturePowers.Count == 0) { continue; } string str1 = ""; if (i >= 11) { str1 = (i >= 21 ? "epic" : "paragon"); } else { str1 = "heroic"; } string str2 = ""; if (i < 4) { str2 = "early heroic"; } else if (i < 8) { str2 = "mid heroic"; } else if (i < 11) { str2 = "late heroic"; } else if (i < 14) { str2 = "early paragon"; } else if (i < 18) { str2 = "mid paragon"; } else if (i < 21) { str2 = "late paragon"; } else if (i < 24) { str2 = "early epic"; } else if (i >= 28) { str2 = (i >= 31 ? "epic plus" : "late epic"); } else { str2 = "mid epic"; } object[] count = new object[] { i, ",", roleFlag, ",", roleType, ",", flag, ",", flag1, ",", str1, ",", str2, ",", _creatures.Count, ",", creaturePowers.Count }; streamWriter.Write(string.Concat(count)); foreach (string condition1 in Conditions.GetConditions()) { int num = 0; string lower = condition1.ToLower(); foreach (CreaturePower creaturePower in creaturePowers) { if (!creaturePower.Details.ToLower().Contains(lower)) { continue; } num++; } double count1 = 0; if (creaturePowers.Count != 0) { count1 = (double)num / (double)creaturePowers.Count; } streamWriter.Write(string.Concat(",", count1)); } foreach (DamageType damageType in Enum.GetValues(typeof(DamageType))) { int num1 = 0; string lower1 = damageType.ToString().ToLower(); foreach (CreaturePower creaturePower1 in creaturePowers) { if (!creaturePower1.Details.ToLower().Contains(lower1)) { continue; } num1++; } double count2 = 0; if (creaturePowers.Count != 0) { count2 = (double)num1 / (double)creaturePowers.Count; } streamWriter.Write(string.Concat(",", count2)); } streamWriter.WriteLine(); } } } } } } catch (Exception exception) { LogSystem.Trace(exception); } } finally { streamWriter.Close(); } }