示例#1
0
 /// <summary>
 /// Deletes an object with the specified resref from the database.
 /// </summary>
 /// <param name="resref">The resource reference to search for.</param>
 /// <param name="resourceType">The type of resource to remove.</param>
 /// <param name="connectionString">If you need to connect to a specific database, use this to pass the connection string. Otherwise, the default connection string will be used (WinterConnectionInformation.ActiveConnectionString)</param>
 public void DeleteFromDatabase(int resourceID, GameObjectTypeEnum resourceType, string connectionString = "")
 {
     if (resourceType == GameObjectTypeEnum.Area)
     {
         using (AreaRepository repo = new AreaRepository(connectionString))
         {
             repo.Delete(resourceID);
         }
     }
     else if (resourceType == GameObjectTypeEnum.Conversation)
     {
         using (ConversationRepository repo = new ConversationRepository(connectionString))
         {
             repo.Delete(resourceID);
         }
     }
     else if (resourceType == GameObjectTypeEnum.Creature)
     {
         using (CreatureRepository repo = new CreatureRepository(connectionString))
         {
             repo.Delete(resourceID);
         }
     }
     else if (resourceType == GameObjectTypeEnum.Item)
     {
         using (ItemRepository repo = new ItemRepository(connectionString))
         {
             repo.Delete(resourceID);
         }
     }
     else if (resourceType == GameObjectTypeEnum.Placeable)
     {
         using (PlaceableRepository repo = new PlaceableRepository(connectionString))
         {
             repo.Delete(resourceID);
         }
     }
     else if (resourceType == GameObjectTypeEnum.Script)
     {
         using (ScriptRepository repo = new ScriptRepository(connectionString))
         {
             repo.Delete(resourceID);
         }
     }
     else if (resourceType == GameObjectTypeEnum.Tileset)
     {
         using (TilesetRepository repo = new TilesetRepository(connectionString))
         {
             repo.Delete(resourceID);
         }
     }
     else if (resourceType == GameObjectTypeEnum.GameModule)
     {
         using (GameModuleRepository repo = new GameModuleRepository())
         {
             repo.Delete(resourceID);
         }
     }
     else
     {
         throw new NotSupportedException();
     }
 }
示例#2
0
        /// <summary>
        /// Updates a gameObject's entry in the database.
        /// An exception will be thrown if an object with a matching resref is not found.
        /// </summary>
        /// <param name="gameObjectBase">The game object to update. Its resref will be searched for in the database.</param>
        /// <param name="connectionString">If you need to connect to a specific database, use this to pass the connection string. Otherwise, the default connection string will be used (WinterConnectionInformation.ActiveConnectionString)</param>
        public void UpdateInDatabase(GameObjectBase gameObject, string connectionString = "")
        {
            if (gameObject.GameObjectType == GameObjectTypeEnum.Area)
            {
                using (AreaRepository repo = new AreaRepository(connectionString))
                {
                    repo.Update(gameObject as Area);

                }
            }
            else if (gameObject.GameObjectType == GameObjectTypeEnum.Conversation)
            {
                using (ConversationRepository repo = new ConversationRepository(connectionString))
                {
                    repo.Update(gameObject as Conversation);
                }
            }
            else if (gameObject.GameObjectType == GameObjectTypeEnum.Creature)
            {
                using (CreatureRepository repo = new CreatureRepository(connectionString))
                {
                    repo.Update(gameObject as Creature);
                }
            }
            else if (gameObject.GameObjectType == GameObjectTypeEnum.Item)
            {
                using (ItemRepository repo = new ItemRepository(connectionString))
                {
                    repo.Update(gameObject as Item);
                }
            }
            else if (gameObject.GameObjectType == GameObjectTypeEnum.Placeable)
            {
                using (PlaceableRepository repo = new PlaceableRepository(connectionString))
                {
                    repo.Update(gameObject as Placeable);
                }
            }
            else if (gameObject.GameObjectType == GameObjectTypeEnum.Script)
            {
                using (ScriptRepository repo = new ScriptRepository(connectionString))
                {
                    repo.Update(gameObject as Script);
                }
            }
            else if (gameObject.GameObjectType == GameObjectTypeEnum.Tileset)
            {
                using (TilesetRepository repo = new TilesetRepository(connectionString))
                {
                    repo.Update(gameObject as Tileset);
                }
            }
            else if (gameObject.GameObjectType == GameObjectTypeEnum.GameModule)
            {
                using (GameModuleRepository repo = new GameModuleRepository())
                {
                    repo.Update(gameObject as GameModule);
                }
            }
            else
            {
                throw new NotSupportedException();
            }
        }
示例#3
0
        /// <summary>
        /// Adds a game object to the database.
        /// </summary>
        /// <param name="gameObject">The game object to add to the database. This will be type-converted and added to the correct table when run.</param>
        /// <param name="connectionString">If you need to connect to a specific database, use this to pass the connection string. Otherwise, the default connection string will be used (WinterConnectionInformation.ActiveConnectionString)</param>
        public GameObjectBase AddToDatabase(GameObjectBase gameObject, string connectionString = "")
        {
            GameObjectBase resultGameObject;
            try
            {
                if (gameObject.GameObjectType == GameObjectTypeEnum.Area)
                {
                    using (AreaRepository repo = new AreaRepository(connectionString))
                    {
                        resultGameObject = repo.Add(gameObject as Area);
                    }
                }
                else if (gameObject.GameObjectType == GameObjectTypeEnum.Conversation)
                {
                    using (ConversationRepository repo = new ConversationRepository())
                    {
                        resultGameObject = repo.Add(gameObject as Conversation);
                    }
                }
                else if (gameObject.GameObjectType == GameObjectTypeEnum.Creature)
                {
                    using (CreatureRepository repo = new CreatureRepository(connectionString))
                    {
                        resultGameObject = repo.Add(gameObject as Creature);
                    }
                }
                else if (gameObject.GameObjectType == GameObjectTypeEnum.Item)
                {
                    using (ItemRepository repo = new ItemRepository(connectionString))
                    {
                        resultGameObject = repo.Add(gameObject as Item);
                    }
                }
                else if (gameObject.GameObjectType == GameObjectTypeEnum.Placeable)
                {
                    using (PlaceableRepository repo = new PlaceableRepository(connectionString))
                    {
                        resultGameObject = repo.Add(gameObject as Placeable);
                    }
                }
                else if (gameObject.GameObjectType == GameObjectTypeEnum.Script)
                {
                    using (ScriptRepository repo = new ScriptRepository(connectionString))
                    {
                        resultGameObject = repo.Add(gameObject as Script);
                    }
                }
                else if (gameObject.GameObjectType == GameObjectTypeEnum.Tileset)
                {
                    using (TilesetRepository repo = new TilesetRepository(connectionString))
                    {
                        resultGameObject = repo.Add(gameObject as Tileset);
                    }
                }
                else if (gameObject.GameObjectType == GameObjectTypeEnum.GameModule)
                {
                    using (GameModuleRepository repo = new GameModuleRepository())
                    {
                        resultGameObject = repo.Add(gameObject as GameModule);
                    }
                }
                else
                {
                    throw new NotSupportedException();
                }
            }
            catch
            {
                throw;
            }

            return resultGameObject;
        }
示例#4
0
        /// <summary>
        /// Creates a new module in the temporary directory.
        /// Note that this module will not become permanent until a call to SaveModule() is made.
        /// </summary>
        /// <returns>True if successful, false if unsuccessful</returns>
        public bool CreateModule()
        {
            try
            {
                using (FileArchiveManager manager = new FileArchiveManager())
                {
                    TemporaryDirectoryPath = manager.CreateUniqueDirectory();
                }

                // Build a new database file and structure.
                using (DatabaseRepository repo = new DatabaseRepository())
                {
                    repo.CreateNewDatabase(TemporaryDirectoryPath, "WinterEngineDB", true);
                }

                EntityCreationScripts creationScripts = new EntityCreationScripts();
                creationScripts.Initialize();

                // Add the module details to the correct table.
                using (GameModuleRepository repo = new GameModuleRepository())
                {
                    GameObjectFactory factory = new GameObjectFactory();
                    GameModule module = factory.CreateObject(GameObjectTypeEnum.GameModule, ModuleName, ModuleTag, ModuleResref) as GameModule;

                    repo.Add(module);
                }

                LoadSystemContentPacks();

                return true;
            }
            catch(Exception ex)
            {
                throw new Exception("Error creating module.", ex);
            }
        }
示例#5
0
        private void LoadModule(object sender, CancelEventArgs e)
        {
            string path = OpenFile.FileName;
            ViewModel.ModuleFileName = Path.GetFileNameWithoutExtension(path);

            ModuleManager manager = new ModuleManager();
            manager.OpenModule(path);

            using (GameModuleRepository repo = new GameModuleRepository())
            {
                GameModule gameModule = repo.GetModule();
                ViewModel.ModuleMaxLevel = gameModule.MaxLevel;
                numericMaxLevel.Maximum = gameModule.MaxLevel;
            }

            using (ContentPackageRepository repo = new ContentPackageRepository())
            {
                ViewModel.ContentPackageList = repo.GetAll();
            }

            // Set the bounds of the server max level to the maximum that the module allows.
            if (ViewModel.ModuleMaxLevel < ViewModel.ServerSettings.MaxLevel)
            {
                ViewModel.ServerSettings.MaxLevel = ViewModel.ModuleMaxLevel;
            }

            buttonStartStop.IsEnabled = true;
            buttonSendMessage.IsEnabled = true;
        }
示例#6
0
        private void PopulateToolsetViewModel()
        {
            ClearViewModelPopulation();

            using (GameModuleRepository repo = new GameModuleRepository())
            {
                ViewModel.ActiveModule = repo.GetModule();
            }

            using (ContentPackageResourceRepository repo = new ContentPackageResourceRepository())
            {
                ViewModel.TilesetSpriteSheetsList = repo.GetAllUIObjects(ContentPackageResourceTypeEnum.Tileset, false);
            }

            using (ItemRepository repo = new ItemRepository())
            {
                ViewModel.ItemList = repo.GetAllUIObjects();
            }

            using (ScriptRepository repo = new ScriptRepository())
            {
                ViewModel.ScriptList = repo.GetAllUIObjects();
            }

            using (GenderRepository repo = new GenderRepository())
            {
                ViewModel.GenderList = repo.GetAllUIObjects();
            }

            using (ConversationRepository repo = new ConversationRepository())
            {
                ViewModel.ConversationList = repo.GetAllUIObjects();
            }

            using (RaceRepository repo = new RaceRepository())
            {
                ViewModel.RaceList = repo.GetAllUIObjects();
            }

            using (FactionRepository repo = new FactionRepository())
            {
                ViewModel.FactionList = repo.GetAllUIObjects();
            }

            using (TilesetRepository repo = new TilesetRepository())
            {
                ViewModel.TilesetList = repo.GetAllUIObjects();
            }

            using (AbilityRepository repo = new AbilityRepository())
            {
                ViewModel.AbilityList = repo.GetAll();
            }

            using (SkillRepository repo = new SkillRepository())
            {
                ViewModel.SkillList = repo.GetAll();
            }

            using (LevelRequirementRepository repo = new LevelRequirementRepository())
            {
                ViewModel.LevelRequirementList = repo.GetAll();
            }
        }
示例#7
0
        private async void SaveModulePropertiesAsync(object sender, JavascriptMethodEventArgs e)
        {
            try
            {
                await TaskEx.Run(() =>
                {
                    GameModule updatedModule = JsonConvert.DeserializeObject<GameModule>(e.Arguments[0]);
                    List<LevelRequirement> levelRequirements = JsonConvert.DeserializeObject<List<LevelRequirement>>(e.Arguments[1]);

                    using (GameModuleRepository repo = new GameModuleRepository())
                    {
                        repo.Update(updatedModule);
                    }

                    using (LevelRequirementRepository repo = new LevelRequirementRepository())
                    {
                        levelRequirements.ForEach(x => repo.Update(x));
                    }

                    PopulateToolsetViewModel();
                });

                AsyncJavascriptCallback("SaveModuleProperties_Callback");
            }
            catch (Exception ex)
            {
                throw new Exception("Error saving module properties", ex);
            }
        }