private void OpenScene(int level) { Omniscience.Initialize(); VolatileSceneObjects = new GameObject("VolatileSceneObjects").transform; VolatileSceneObjects.transform.SetParent(Scene); InventoryGUIController.Instance.Close(); InventoryOpen = false; SpawnPlayer(); SpawnEnemies(level); SceneActive = true; }
//#endregion /// <summary> /// God of time, there can only be one of. /// </summary> private Cronos() { MyOmniscience = new Omniscience(); //set all the config paths ConfigurationDirectory.Instance.KnowledgeFilesDirectory = ConfigurationManager.AppSettings["KnowledgeFilesDirectory"]; ConfigurationDirectory.Instance.CentralDecisionTreeRepository = ConfigurationManager.AppSettings["CentralDecisionTreeRepository"]; ConfigurationDirectory.Instance.CharacterFilesDirectory = ConfigurationManager.AppSettings["CharacterFilesDirectory"]; ConfigurationDirectory.Instance.LogFilesDirectory = ConfigurationManager.AppSettings["LogFilesDirectory"]; ConfigurationDirectory.Instance.NodeSubstitutionsFile = ConfigurationManager.AppSettings["NodeSubstitutionsFile"]; ConfigurationDirectory.Instance.SubTreeRepository = "..\\..\\..\\..\\RNPC\\Subtrees\\"; ConfigurationDirectory.Instance.NodeSubstitutionsFile = "..\\..\\..\\..\\DTO\\Learning\\Resources\\DecisionTreeSubstitutions.xml"; ConfigurationDirectory.Instance.CentralDecisionTreeRepository = "..\\..\\..\\..\\RNPC\\XMLTreeFiles\\"; ConfigurationDirectory.Instance.CharacterFilesDirectory = "C:\\Sysdev\\RNPC\\logs\\Characters\\"; ConfigurationDirectory.Instance.KnowledgeFilesDirectory = "C:\\Sysdev\\RNPC\\Knowledge\\"; ConfigurationDirectory.Instance.LogFilesDirectory = "C:\\Sysdev\\RNPC\\logs\\"; }
/// <summary> /// This write the content of the all-knowledge to file on disk /// </summary> /// <param name="knowledgeToSave">knowledge class with content</param> /// <param name="saveOmniscienceBackup">use backup in case of error</param> public void WriteToFile(Omniscience knowledgeToSave, bool saveOmniscienceBackup = false) { var serializer = FsPickler.CreateBinarySerializer(); DESCryptoServiceProvider cryptic = new DESCryptoServiceProvider { Key = Encoding.ASCII.GetBytes("ZCR0N0S1"), IV = Encoding.ASCII.GetBytes("ZCR0N0S1") }; try { using (var file = File.Create(GetFilelocation())) { CryptoStream crStream = new CryptoStream(file, cryptic.CreateEncryptor(), CryptoStreamMode.Write); serializer.Serialize(crStream, knowledgeToSave); crStream.Close(); if (!saveOmniscienceBackup) { return; } try { using (var backupFile = File.Create(GetBackupFilelocation())) { CryptoStream crBackupStream = new CryptoStream(backupFile, cryptic.CreateEncryptor(), CryptoStreamMode.Write); serializer.Serialize(crBackupStream, knowledgeToSave); crBackupStream.Close(); } } catch (Exception e) { throw new RnpcFileAccessException("Error when trying to write the **backup** Omniscience to file.", e); } } } catch (Exception e) { throw new RnpcFileAccessException("Error when trying to write Omniscience to file.", e); } }
public void WakeUp() { if (FileController == null) { FileController = new OmniscienceFileController(); } var allKnowledge = FileController.ReadFromFile(MyOmniscience.BackupMemoryFiles); if (allKnowledge == null) { throw new RnpcOmniscienceException("The Omniscience file for Cronos could not be properly loaded."); } MyOmniscience = allKnowledge; foreach (var character in MyOmniscience.MyFollowers) { character.WakeUp(new MemoryFileController(ConfigurationDirectory.Instance.KnowledgeFilesDirectory), MyOmniscience.BackupMemoryFiles); } }
public void WriteToFile_OmniscienceFile_FileWritten() { //ARRANGE OmniscienceFileController controller = new OmniscienceFileController(); if (controller.FileExists()) { controller.DeleteFile(); } var referenceData = MemoryContentInitializer.CreateItemsAndLinkThem(new ItemLinkFactory()); Dictionary <Guid, MemoryItem> dataDictionary = new Dictionary <Guid, MemoryItem>(); foreach (var item in referenceData) { dataDictionary.Add(Guid.NewGuid(), item); } Omniscience allKnowledge = new Omniscience(dataDictionary); for (int i = 0; i < 50; i++) { Person newPerson = new Person("NPC" + i, Gender.Agender, Sex.Undefined, Orientation.Asexual, Guid.Empty); var newNpc = new global::RNPC.Core.Character(newPerson, Archetype.None); for (int j = 0; j < referenceData.Count; j++) { if (RandomValueGenerator.GeneratePercentileIntegerValue() < 34) { newNpc.AddContentToLongTermMemory(dataDictionary.ElementAt(j).Value); } } allKnowledge.AddFollower(newNpc); } //ACT controller.WriteToFile(allKnowledge); //ASSERT controller.FileExists(); }
public static void Initialize() { Instance = new Omniscience(); }