public static FactionSdo ConvertToFactionSdo(Faction faction) { var sdo = new FactionSdo { PopType = faction.PopType, FactionReputation = faction.FactionReputation, CitizenIds = new List <Guid>(), EntitiesWithFluffIds = new List <Guid>(), Leader = EntitySdo.ConvertToEntitySdo(faction.Leader), Name = faction.Name, Population = faction.Population }; foreach (var citizen in faction.Citizens) { sdo.CitizenIds.Add(citizen.Id); } foreach (var entity in faction.EntitiesWithFluff) { sdo.EntitiesWithFluffIds.Add(entity.Id); } return(sdo); }
public Faction(FactionSdo sdo) { Religions = new Dictionary <string, int>(); EntitiesWithFluff = new List <Entity>(); PopType = sdo.PopType; FactionReputation = sdo.FactionReputation; Citizens = new List <Entity>(); EntitiesWithFluff = new List <Entity>(); Name = sdo.Name; Population = sdo.Population; Leader = EntitySdo.ConvertToEntity(sdo.Leader); if (Leader == null) { Debug.Log($@"Leader missing for faction {Name}"); } foreach (var id in sdo.CitizenIds) { if (!WorldData.Instance.Entities.ContainsKey(id)) { continue; } var citizen = WorldData.Instance.Entities[id]; citizen.Faction = this; Citizens.Add(citizen); } foreach (var id in sdo.EntitiesWithFluffIds) { if (!WorldData.Instance.Entities.ContainsKey(id)) { continue; } var entity = WorldData.Instance.Entities[id]; EntitiesWithFluff.Add(entity); } if (Leader != null && !WorldData.Instance.Entities.ContainsKey(Leader.Id)) { WorldData.Instance.Entities[Leader.Id] = Leader; } if (!EntitiesWithFluff.Contains(Leader)) { EntitiesWithFluff.Add(Leader); } }
//todo make save game file right after world gen public void Save() { Debug.Log("Saving..."); try { var data = new SaveData { StartingSeed = WorldData.Instance.Seed, SeedState = Random.state, Map = ConvertMapForSaving(WorldData.Instance.Map), PlayerId = GameManager.Instance.Player.Id, CurrentCellId = GameManager.Instance.CurrentCell.Id, CurrentAreaId = GameManager.Instance.CurrentArea.Id, CurrentTileId = GameManager.Instance.CurrentTile.Id, CurrentState = GameManager.Instance.CurrentState, CurrentSceneName = GameManager.Instance.CurrentScene.name, Messages = Messenger.Instance.GetAllMessages(), ActiveOrders = ConvertActiveOrdersForSaving(GameManager.Instance.ActiveOrders), EntitySdos = EntitySdo.ConvertToEntitySdos(WorldData.Instance.Entities.Values.ToList()), FactionSdos = FactionSdo.ConvertToFactionSdos(WorldData.Instance.Factions.Values.ToList()), Items = ConvertItemsForSaving(WorldData.Instance.Items), PlayerStartingPlaceCellId = WorldData.Instance.PlayerStartingPlace.Id, AbilityMap = ConvertAbilityMapForSaving(InputController.Instance.AbilityMap) }; var saveGameFileNames = new SaveGameFileNames { FileNames = new SaveGameFileNames.SerializableFileNamesDictionary() }; var fileName = $@"{WorldData.Instance.SaveGameId}"; SaveFileNames.Add(fileName, GameManager.Instance.Player.Fluff.Name); foreach (var saveFileName in SaveFileNames.Keys) { saveGameFileNames.FileNames.Add(saveFileName, SaveFileNames[saveFileName]); } SaveGame.Save(FileNamesIdentifier, saveGameFileNames, Serializer); SaveGame.Save(fileName, data, Serializer); } catch (Exception e) { Debug.Log("Error saving! " + e.Message); throw; } }
private static Dictionary <Guid, Entity> ConvertEntitiesForPlaying(SaveData.SerializableEntitiesDictionary entitySdos) { return(EntitySdo.ConvertToEntities(entitySdos)); }
public static Entity ConvertToEntity(EntitySdo entitySdo) { Entity entity; entity = new Entity(entitySdo.Id, entitySdo.PrefabPath, entitySdo.IsPlayer); entity.PrefabPath = entitySdo.PrefabPath; entity.TotalBodyPartCoverage = entitySdo.TotalBodyPartCoverage; entity.Level = entitySdo.Level; entity.Xp = entitySdo.Xp; entity.Strength = entitySdo.Strength; entity.Agility = entitySdo.Agility; entity.Constitution = entitySdo.Constitution; entity.Intelligence = entitySdo.Intelligence; entity.MaxHp = entitySdo.MaxHp; entity.CurrentHp = entitySdo.CurrentHp; entity.Speed = entitySdo.Speed; entity.Defense = entitySdo.Defense; entity.Body = entitySdo.Body; entity.EntityType = entitySdo.EntityType; entity.Classification = entitySdo.Classification; entity.Fluff = entitySdo.Fluff; entity.Mobile = entitySdo.Mobile; entity.ToppingDropped = ToppingSdo.ConvertToTopping(entitySdo.ToppingDropped); entity.ToppingCounts = entitySdo.ToppingCounts; entity.EntityReputation = entitySdo.Reputation; entity.Abilities = new Entity.AbilityDictionary(); if (string.IsNullOrEmpty(entitySdo.CurrentCellId)) { entity.CurrentCell = null; entity.CurrentArea = null; entity.CurrentTile = null; } else { entity.CurrentCell = WorldData.Instance.MapDictionary[entitySdo.CurrentCellId]; entity.CurrentArea = entity.CurrentCell.GetAreaById(entitySdo.CurrentAreaId); entity.CurrentTile = entity.CurrentArea?.GetTileById(entitySdo.CurrentTileId); } entity.CurrentPosition = new Vector3(entitySdo.CurrentPosition.Y, entitySdo.CurrentPosition.X, entitySdo.CurrentPosition.Z); foreach (var itemId in entitySdo.InventoryItemIds) { if (itemId == Guid.Empty) { continue; } var item = WorldData.Instance.Items[itemId]; entity.Inventory.Add(item.Id, item); } foreach (var equipped in entitySdo.EquippedIds) { if (equipped.Value == Guid.Empty) { continue; } var item = WorldData.Instance.Items[equipped.Value]; if (entity.Equipped.ContainsKey(equipped.Key)) { entity.Equipped[equipped.Key] = item; } else { entity.Equipped.Add(equipped.Key, item); } } if (entitySdo.AbilityNames != null && entitySdo.AbilityNames.Count > 0) { foreach (var abilityName in entitySdo.AbilityNames) { var template = AbilityStore.GetAbilityByName(abilityName); var ability = AbilityStore.CreateAbility(template, entity); entity.Abilities.Add(abilityName, ability); } } return(entity); }
public static EntitySdo ConvertToEntitySdo(Entity entity) { EntitySdo sdo; sdo = new EntitySdo(); sdo.Id = entity.Id; sdo.IsPlayer = entity.IsPlayer(); sdo.PrefabPath = entity.PrefabPath; sdo.FactionName = entity.Faction?.Name; sdo.TotalBodyPartCoverage = entity.TotalBodyPartCoverage; sdo.CurrentPosition = entity.CurrentPosition; sdo.Level = entity.Level; sdo.Xp = entity.Xp; sdo.Strength = entity.Strength; sdo.Agility = entity.Agility; sdo.Constitution = entity.Constitution; sdo.Intelligence = entity.Intelligence; sdo.MaxHp = entity.MaxHp; sdo.CurrentHp = entity.CurrentHp; sdo.Speed = entity.Speed; sdo.Defense = entity.Defense; sdo.InventoryItemIds = new List <Guid>(); sdo.EquippedIds = new Dictionary <Entity.EquipmentSlot, Guid>(); sdo.Body = entity.Body; sdo.EntityType = entity.EntityType; sdo.Classification = entity.Classification; sdo.Fluff = entity.Fluff; sdo.CurrentCellId = entity.CurrentCell?.Id; sdo.CurrentAreaId = entity.CurrentArea?.Id; sdo.CurrentTileId = entity.CurrentTile?.Id; sdo.Mobile = entity.Mobile; sdo.ToppingDropped = ToppingSdo.ConvertToToppingSdo(entity.ToppingDropped); sdo.ToppingCounts = entity.ToppingCounts; sdo.BirthMotherId = entity.BirthMother?.Id ?? Guid.Empty; sdo.BirthFatherId = entity.BirthFather?.Id ?? Guid.Empty; sdo.ChildrenIds = new List <Guid>(); sdo.Reputation = entity.EntityReputation; sdo.AbilityNames = new List <string>(); foreach (var itemId in entity.Inventory.Keys) { sdo.InventoryItemIds.Add(itemId); } foreach (var slot in entity.Equipped.Keys) { sdo.EquippedIds.Add(new KeyValuePair <Entity.EquipmentSlot, Guid>(slot, entity.Equipped[slot]?.Id ?? Guid.Empty)); } if (entity.Children != null && entity.Children.Count > 0) { foreach (var child in entity.Children) { sdo.ChildrenIds.Add(child.Id); } } if (entity.Abilities != null && entity.Abilities.Count > 0) { foreach (var abilityName in entity.Abilities.Keys) { sdo.AbilityNames.Add(abilityName); } } return(sdo); }