Beispiel #1
0
        private void Open(object sender, ExecutedRoutedEventArgs executedRoutedEventArgs)
        {
            EndGnomeEdit();

            var dlg = new OpenFileDialog
            {
                Filter           = "Gnomoria saves|*.sav",
                DefaultExt       = ".sav",
                InitialDirectory = GnomanEmpire.SaveFolderPath() + "Worlds"
            };
            var result = dlg.ShowDialog(this);

            if (result == false)
            {
                return;
            }

            LoadButton.IsEnabled = false;
            Clear();

            ProgressBar.Visibility = Visibility.Visible;
            HeadingLabel.Content   = "Game loading...";

            File = new FileInfo(dlg.FileName);

            var worker = new BackgroundWorker();

            worker.DoWork             += LoaderLoad;
            worker.RunWorkerCompleted += LoaderComplete;
            worker.RunWorkerAsync();
        }
Beispiel #2
0
 public static Task OnAfter_GnomanEmpire_SaveGame(Task result, GnomanEmpire self, bool fallen)
 {
     return(result.ContinueWith((task) =>
     {
         GnomanEmpire.Instance.World.NotificationManager.AddNotification("Game saved within " + (DateTime.Now - SaveStart).TotalSeconds.ToString("0.00") + " sec", false);
     }));
 }
Beispiel #3
0
 public void init_gnomoria(string gnomoria_directory)
 {
     gnomoria_path = gnomoria_directory;
     gnomoria_game = GnomanEmpire.Instance;
     gnomoria_game.Content.RootDirectory = System.IO.Path.Combine(gnomoria_path, "Content");
     System.IO.Directory.SetCurrentDirectory(gnomoria_path);
     typeof(GnomanEmpire).GetMethod("Initialize", System.Reflection.BindingFlags.Instance | System.Reflection.BindingFlags.NonPublic).Invoke(gnomoria_game, null);
     save_directory = GnomanEmpire.SaveFolderPath("Worlds\\");
 }
        /// <summary>
        /// Creates a new static access to the given world.
        /// </summary>
        /// <param name="worldFile">The FileInfo of the world to load</param>
        public StaticGnomanEmpireAccess(FileInfo worldFile)
        {
            if (!_isGnomanEmpireInitialized) {
                InitializeGnomanEmpire();
            }

            GnomanEmpire.Instance.LoadGame(worldFile.FullName);
            Empire = GnomanEmpire.Instance;
        }
        public override void SetupPanel()
        {
            Label label = new Label(this.Manager);

            label.Init();
            label.Top   = label.Margins.Top;
            label.Left  = label.Margins.Left;
            label.Text  = "Import Tracked Items:";
            label.Width = this.ClientWidth - label.Margins.Horizontal;
            this.Add(label);

            ListBox gameSaveList = new ListBox(this.Manager);

            gameSaveList.Init();
            gameSaveList.Top           = label.Top + label.Height;
            gameSaveList.Left          = gameSaveList.Margins.Left;
            gameSaveList.Width         = 300;
            gameSaveList.Height        = this.ClientHeight - gameSaveList.Top - gameSaveList.Margins.Bottom;
            gameSaveList.HideSelection = false;

            string[] files = Directory.GetFiles(GnomanEmpire.SaveFolderPath("TrackedItems\\"), "*.json");

            foreach (string text in files)
            {
                gameSaveList.list_0.Add(text.Replace(GnomanEmpire.SaveFolderPath("TrackedItems\\"), "").Replace(".json", ""));
            }

            this.Add(gameSaveList);

            Button button = new Button(this.Manager);

            button.Top    = gameSaveList.Top;
            button.Left   = gameSaveList.Left + gameSaveList.Width + gameSaveList.Margins.Right + button.Margins.Left;
            button.Width  = this.ClientWidth - button.Left - button.Margins.Right;
            button.Text   = "Import";
            button.Click += delegate(object s, Game.GUI.Controls.EventArgs e)
            {
                if (gameSaveList.ItemIndex >= 0 && gameSaveList.ItemIndex < gameSaveList.list_0.Count)
                {
                    ModMain.instance.LoadTrackedItems(gameSaveList.list_0[gameSaveList.ItemIndex].ToString());
                }
                GnomanEmpire.Instance.GuiManager.MenuStack.PopWindow();
            };
            this.Add(button);

            Button button2 = new Button(this.Manager);

            button2.Top    = button.Top + button.Height + button.Margins.Bottom + button2.Margins.Top;
            button2.Left   = button.Left;
            button2.Width  = this.ClientWidth - button2.Left - button2.Margins.Right;
            button2.Text   = "Back";
            button2.Click += delegate(object s, Game.GUI.Controls.EventArgs e)
            {
                GnomanEmpire.Instance.GuiManager.MenuStack.PopWindow();
            };
            this.Add(button2);
        }
Beispiel #6
0
 public static void On_GnomanEmpire_LoadGame(GnomanEmpire self, string file, bool fallen)
 {
     var dc = new DataCollection();
     dc.ToString();
     //var seri = new System.Web.Script.Serialization.JavaScriptSerializer();
     //var text = seri.Serialize(dc);
     var text = Newtonsoft.Json.JsonConvert.SerializeObject(dc, Newtonsoft.Json.Formatting.Indented);
     System.IO.File.WriteAllText(@"C:\Users\Faark\Documents\Visual Studio 2010\Projects\GnomoriaModding\Release\Data.js", text);
 }
Beispiel #7
0
 public static void GnomanEmpire_Update(GnomanEmpire self, GameTime gt)
 {
     shortRec.AddFrame(gt.ElapsedGameTime);
     longRec.AddFrame(gt.ElapsedGameTime);
     if (nextDisplayUpdate < gt.TotalGameTime)
     {
         nextDisplayUpdate = gt.TotalGameTime + UpdateDisplayEvery;
         UpdateDisplayedFps();
     }
 }
Beispiel #8
0
 public static void GnomanEmpire_Update(GnomanEmpire self, GameTime gt)
 {
     shortRec.AddFrame(gt.ElapsedGameTime);
     longRec.AddFrame(gt.ElapsedGameTime);
     if (nextDisplayUpdate < gt.TotalGameTime)
     {
         nextDisplayUpdate = gt.TotalGameTime + UpdateDisplayEvery;
         UpdateDisplayedFps();
     }
 }
Beispiel #9
0
        public static void On_GnomanEmpire_LoadGame(GnomanEmpire self, string file, bool fallen)
        {
            var dc = new DataCollection();

            dc.ToString();
            //var seri = new System.Web.Script.Serialization.JavaScriptSerializer();
            //var text = seri.Serialize(dc);
            var text = Newtonsoft.Json.JsonConvert.SerializeObject(dc, Newtonsoft.Json.Formatting.Indented);

            System.IO.File.WriteAllText(@"C:\Users\Faark\Documents\Visual Studio 2010\Projects\GnomoriaModding\Release\Data.js", text);
        }
Beispiel #10
0
        public void load(string filename)
        {
            var    gnomoria_save_path = GnomanEmpire.SaveFolderPath("Worlds\\");
            string world_save_file;

            if (!try_extractRelativePath(filename, gnomoria_save_path, out world_save_file))
            {
                throw new Exception("Error: Can only open saves in your Gnomoria worlds save folder!");
            }
            System.IO.Directory.SetCurrentDirectory(gnomoria_path);
            gnomoria_game.LoadGame(world_save_file, false);
        }
Beispiel #11
0
        public Statistics(GnomanEmpire gnomanEmpire)
        {
            Globals.Logger.Info("Creating statistics...");
            if (gnomanEmpire == null)
            {
                Globals.Logger.Error("World is not loaded");
                return;
            }

            worldName = gnomanEmpire.World.AIDirector.PlayerFaction.Name;

            var names = Enum.GetNames(typeof(MineralID));

            for (int i = 0; i < names.Length; i++)
            {
                minerals[i] = new MineralStatistic((MineralID)Enum.Parse(typeof(MineralID), names[i]));
            }

            for (var level = 0; level < gnomanEmpire.Map.MapDepth; level++)
            {
                for (var height = 0; height < gnomanEmpire.Map.MapHeight; height++)
                {
                    for (var width = 0; width < gnomanEmpire.Map.MapWidth; width++)
                    {
                        var cell = gnomanEmpire.Map.GetCell(level, height, width);
                        if (!cell.HasEmbeddedWall())
                        {
                            continue;
                        }
                        var embeddedWall = cell.EmbeddedWall;
                        var mineral      = embeddedWall as Mineral;
                        if (mineral == null)
                        {
                            continue;
                        }

                        int index2 = 0;
                        foreach (string i in Enum.GetNames(typeof(MineralID)))
                        {
                            if (mineral.MaterialID == ((MineralID)Enum.Parse(typeof(MineralID), i)).GetHashCode())
                            {
                                minerals[index2].Count++;
                            }
                            index2++;
                        }
                    }
                }
            }

            Globals.Logger.Info("Statistics has been created");
        }
Beispiel #12
0
        public Result Initialize()
        {
            Result result = new Result(false, "");

            try
            {
                Console.WriteLine("[Game Model] Initialize: 7z Setup");
                SevenZip.SevenZipExtractor.SetLibraryPath("7z.dll");

                Console.WriteLine("[Game Model] Initialize: Running reflection");
                MethodInfo initMethod = typeof(GnomanEmpire).GetMethod("Initialize", BindingFlags.NonPublic | BindingFlags.Instance);
                initMethod.Invoke(GnomanEmpire.Instance, null);

                // Stop the music playing (it starts automatically when the Game object is initialized)
                GnomanEmpire.Instance.AudioManager.SetMusicVolume(0);
                GnomanEmpire.Instance.AudioManager.SetSFXVolume(0);

                // Exit the full screen mode if needed
                if (GnomanEmpire.Instance.Graphics.IsFullScreen)
                {
                    GnomanEmpire.Instance.Graphics.ToggleFullScreen();
                }

                Console.WriteLine("[Game Model] Initialize: Setting SaveFolderPath");
                mSaveGameFolder = GnomanEmpire.SaveFolderPath("Worlds\\");
                mSettingsFolder = GnomanEmpire.SaveFolderPath();

                Console.WriteLine("[Game Model] Initialize: Initializing Character Skills");
                InitializeCharacterAttributes();
                InitializeCharacterSkills();

                result.Success = true;
            }
            catch (System.Reflection.TargetInvocationException ex)
            {
                Console.WriteLine("[Game Model] Initialize: Exception encountered \"{0}\"", ex.InnerException.Message);
                result.ErrorMessage = "InvocationException: " + ex.InnerException.ToString();
            }
            catch (Exception ex)
            {
                Console.WriteLine("[Game Model] Initialize: Exception encountered \"{0}\"", ex.Message);
                result.ErrorMessage = ex.Message;
            }

            return(result);
        }
Beispiel #13
0
 public static void On_GnomanEmpire_PlayGame(GnomanEmpire self)
 {
     lbl = new Game.GUI.Controls.Label(self.GuiManager.Manager);
     lbl.Init();
     lbl.Top    = 200;
     lbl.Left   = 5;
     lbl.Width  = 1000;
     lbl.Height = 100;
     refresh();
     self.GuiManager.Add(lbl);
     btn = new Game.GUI.Controls.Button(self.GuiManager.Manager);
     btn.Init();
     btn.Top    = 300;
     btn.Left   = 5;
     btn.Text   = "Dump";
     btn.Click += new Game.GUI.Controls.EventHandler(btn_Click);
     self.GuiManager.Add(btn);
 }
Beispiel #14
0
 public static void On_GnomanEmpire_PlayGame(GnomanEmpire self)
 {
     lbl = new Game.GUI.Controls.Label(self.GuiManager.Manager);
     lbl.Init();
     lbl.Top = 200;
     lbl.Left = 5;
     lbl.Width = 1000;
     lbl.Height = 100;
     refresh();
     self.GuiManager.Add(lbl);
     btn = new Game.GUI.Controls.Button(self.GuiManager.Manager);
     btn.Init();
     btn.Top = 300;
     btn.Left = 5;
     btn.Text = "Dump";
     btn.Click += new Game.GUI.Controls.EventHandler(btn_Click);
     self.GuiManager.Add(btn);
 }
Beispiel #15
0
        internal void SaveTrackedItems(string name)
        {
            string path = GnomanEmpire.SaveFolderPath("TrackedItems\\") + name.Trim() + ".json";

            var groups = GnomanEmpire.Instance.Region.Fortress.StockManager.TrackedItemGroups;

            TrackedItemsModel model = new TrackedItemsModel();

            model.gameVersion = Game.Common.GameSaveHeader.CurrentVersion;

            foreach (TrackedItemGroup group in groups)
            {
                TrackedItemsModel.Group groupModel = new TrackedItemsModel.Group();
                groupModel.name = group.Name;

                // Export items
                foreach (string item in group.itemGroup_0.AllowedItems)
                {
                    groupModel.items.Add(item);
                }

                // Export allowed materials
                foreach (KeyValuePair <string, HashSet <string> > keyValuePair in group.dictionary_0)
                {
                    TrackedItemsModel.AllowedMaterialsForItem materialModel = new TrackedItemsModel.AllowedMaterialsForItem();

                    materialModel.item = keyValuePair.Key;

                    foreach (string material in keyValuePair.Value)
                    {
                        materialModel.materials.Add(material);
                    }

                    groupModel.allowedMaterials.Add(materialModel);
                }

                model.groups.Add(groupModel);
            }

            string json = Newtonsoft.Json.JsonConvert.SerializeObject(model, Newtonsoft.Json.Formatting.Indented);

            System.IO.File.WriteAllText(path, json);
        }
Beispiel #16
0
        internal void LoadTrackedItems(string name)
        {
            string path = GnomanEmpire.SaveFolderPath("TrackedItems\\") + name.Trim() + ".json";
            string json = System.IO.File.ReadAllText(path);

            TrackedItemsModel model = Newtonsoft.Json.JsonConvert.DeserializeObject <TrackedItemsModel>(json);

            var groups = GnomanEmpire.Instance.Region.Fortress.StockManager.TrackedItemGroups;
            var hud    = GnomanEmpire.Instance.GuiManager.InGameHUD_0.GClass0_0;

            for (int i = groups.Count - 1; i >= 0; i--)
            {
                groups.RemoveAt(i);
                hud.RemoveStockTrackLabel(i);
            }

            foreach (TrackedItemsModel.Group groupModel in model.groups)
            {
                var group = new TrackedItemGroup();
                group.Name.Value = groupModel.name;

                // Import items

                foreach (string item in groupModel.items)
                {
                    group.AddAllowedItem(item);
                }

                // Import allowed materials

                foreach (TrackedItemsModel.AllowedMaterialsForItem allowedMaterials in groupModel.allowedMaterials)
                {
                    HashSet <string> materials = new HashSet <string>(allowedMaterials.materials);

                    group.dictionary_0.Add(allowedMaterials.item, materials);
                }

                groups.Add(group);

                hud.AddStockTrackLabel(group, false);
            }
        }
Beispiel #17
0
        /// <summary>
        /// Load a saved game file into memory. Must be done at least once before calling the other Load methods.
        /// </summary>
        /// <param name="saveGame">The complete file path of the saved game to load.</param>
        /// <returns>A Result object with a true/false success and an error message.</returns>
        public Result LoadGame(string saveGame)
        {
            Result result = new Result(false, "");

            try
            {
                Console.WriteLine("[Game Model] LoadGame: Loading world {0}", saveGame);
                GnomanEmpire.Instance.LoadGame(saveGame, false);
                Console.WriteLine("[Game Model] LoadGame Instance.LoadGame successful, now setting _gnomanEmpire");
                _gnomanEmpire = GnomanEmpire.Instance;

                result.Success = true;
            }
            catch (Exception ex)
            {
                result.ErrorMessage = ex.Message;
            }

            return(result);
        }
Beispiel #18
0
        public static void GnomLoad(GnomanEmpire self, string file, bool fallen)
        {
            var toSkillLevel = 300;
            var trysPerSkillLevel = 10000000;
            var stats = new int[toSkillLevel][];

            for (var i = 1; i < toSkillLevel; i++)
            {
                stats[i] = new int[6];

                for (var v = 0; v < trysPerSkillLevel; v++)
                {
                    float num2 = 7.5f * (((float)i)/100.0f) / 3.0f;
                    double num3 = GnomanEmpire.MappedNormalDistribution(0f, 6f, num2, Math.Max(num2 - 0f, 6f - num2) * 0.25f);
                    int quality = (int)MathHelper.Clamp((float)num3, 0f, 5f);
                    stats[i][quality]++;
                }
            }

            return;
        }
        public static void GnomLoad(GnomanEmpire self, string file, bool fallen)
        {
            var toSkillLevel      = 300;
            var trysPerSkillLevel = 10000000;
            var stats             = new int[toSkillLevel][];

            for (var i = 1; i < toSkillLevel; i++)
            {
                stats[i] = new int[6];

                for (var v = 0; v < trysPerSkillLevel; v++)
                {
                    float  num2    = 7.5f * (((float)i) / 100.0f) / 3.0f;
                    double num3    = GnomanEmpire.MappedNormalDistribution(0f, 6f, num2, Math.Max(num2 - 0f, 6f - num2) * 0.25f);
                    int    quality = (int)MathHelper.Clamp((float)num3, 0f, 5f);
                    stats[i][quality]++;
                }
            }

            return;
        }
Beispiel #20
0
        public Statistics(GnomanEmpire gnomanEmpire)
        {
            Globals.Logger.Info("Creating statistics...");
            if (gnomanEmpire == null)
            {
                Globals.Logger.Error("World is not loaded");
                return;
            }

            worldName = gnomanEmpire.World.AIDirector.PlayerFaction.Name;

            var names = Enum.GetNames(typeof(MineralID));
            for (int i = 0; i < names.Length; i++)
                minerals[i] = new MineralStatistic((MineralID)Enum.Parse(typeof(MineralID), names[i]));

            for (var level = 0; level < gnomanEmpire.Map.MapDepth; level++)
                for (var height = 0; height < gnomanEmpire.Map.MapHeight; height++)
                    for (var width = 0; width < gnomanEmpire.Map.MapWidth; width++)
                    {
                        var cell = gnomanEmpire.Map.GetCell(level, height, width);
                        if (!cell.HasEmbeddedWall()) continue;
                        var embeddedWall = cell.EmbeddedWall;
                        var mineral = embeddedWall as Mineral;
                        if (mineral == null) continue;

                        int index2 = 0;
                        foreach (string i in Enum.GetNames(typeof(MineralID)))
                        {
                            if (mineral.MaterialID == ((MineralID)Enum.Parse(typeof(MineralID), i)).GetHashCode())
                                minerals[index2].Count++;
                            index2++;
                        }
                    }

            Globals.Logger.Info("Statistics has been created");
        }
Beispiel #21
0
 public static void OnBefore_GnomanEmpire_SaveGame(GnomanEmpire self, bool fallen)
 {
     SaveStart = DateTime.Now;
 }
Beispiel #22
0
        // load game completed
        void _worker_LoadGameCompleted(object sender, RunWorkerCompletedEventArgs e)
        {
            _empire = GnomanEmpire.Instance;
            _dirty = false;
            //lblSaveGameTitle.Content = _empire.World.AIDirector.PlayerFaction.Name;
            Dictionary<uint, Faction> factions = _empire.World.AIDirector.Factions;
            foreach (KeyValuePair<uint,Faction> faction in factions)
            {
                if (faction.Value.ID == Game.Faction.PlayerFactionID)
                    lblSaveGameTitle.Content = faction.Value.Name;
            }

            _savedDifficulty = (Game.GameMode)_empire.World.GameMode;
            cmbDifficulty.SelectedItem = _savedDifficulty;

            _worker.DoWork -= new DoWorkEventHandler(_worker_LoadGame);
            _worker.RunWorkerCompleted -= new RunWorkerCompletedEventHandler(_worker_LoadGameCompleted);
            EnableState();
        }
 public static Task OnAfter_GnomanEmpire_SaveGame(Task result, GnomanEmpire self, bool fallen)
 {
     return result.ContinueWith((task) =>
     {
         GnomanEmpire.Instance.World.NotificationManager.AddNotification("Game saved within " + (DateTime.Now - SaveStart).TotalSeconds.ToString("0.00") + " sec", false);
     });
 }
 public static void OnBefore_GnomanEmpire_SaveGame(GnomanEmpire self, bool fallen)
 {
     SaveStart = DateTime.Now;
 }
 public static void On_GnomanEmpire_FinishLoadingGame(GnomanEmpire self)
 {
     GnomanEmpire.Instance.World.NotificationManager.AddNotification("Game loaded within " + (LoadEnd - LoadStart).TotalSeconds.ToString("0.00") + " sec", false);
 }
 public static void OnAfter_GnomanEmpire_LoadGame(GnomanEmpire self, string file, bool fallen)
 {
     LoadEnd = DateTime.Now;
 }
 public static void OnBefore_GnomanEmpire_LoadGame(GnomanEmpire self, string file, bool fallen)
 {
     LoadStart = DateTime.Now;
 }
Beispiel #28
0
        /// <summary>
        /// Load a saved game file into memory. Must be done at least once before calling the other Load methods.
        /// </summary>
        /// <param name="saveGame">The complete file path of the saved game to load.</param>
        /// <returns>A Result object with a true/false success and an error message.</returns>
        public Result LoadGame(string saveGame)
        {
            Result result = new Result(false, "");

            try
            {
                Console.WriteLine("[Game Model] LoadGame: Loading world {0}", saveGame);
                GnomanEmpire.Instance.LoadGame(saveGame, false);
                Console.WriteLine("[Game Model] LoadGame Instance.LoadGame successful, now setting _gnomanEmpire");
                _gnomanEmpire = GnomanEmpire.Instance;

                result.Success = true;
            }
            catch (Exception ex)
            {
                result.ErrorMessage = ex.Message;
            }

            return result;
        }
Beispiel #29
0
 public static void OnBefore_GnomanEmpire_LoadGame(GnomanEmpire self, string file, bool fallen)
 {
     LoadStart = DateTime.Now;
 }
Beispiel #30
0
 public static void OnAfter_GnomanEmpire_LoadGame(GnomanEmpire self, string file, bool fallen)
 {
     LoadEnd = DateTime.Now;
 }
Beispiel #31
0
 public static void On_GnomanEmpire_FinishLoadingGame(GnomanEmpire self)
 {
     GnomanEmpire.Instance.World.NotificationManager.AddNotification("Game loaded within " + (LoadEnd - LoadStart).TotalSeconds.ToString("0.00") + " sec", false);
 }