#nullable enable using System; using System.Collections.Generic; using System.Linq; using System.Text; using Model.Entity.Data; using Model.Entity.Parts; using Model.Types; using YamlDotNet.Serialization; namespace Model.Entity; public class EntityModel { public static readonly string GameVersion = "0.0.6.8900a"; private static Dictionary _database= null!; private static List _entityModels= null!; private static List _entityModelsOnlyHotkey = null!; private static Dictionary>? _entityModelsByHotkey= null!; public EntityModel(string data, string entity, bool isSpeculative = false) { DataType = data; EntityType = entity; IsSpeculative = isSpeculative; } public string DataType { get; set; } // TODO Serilization currently being used for build orders public string EntityType { get; set; } public List EntityParts { get; set; } = new(); public bool IsSpeculative { get; set; } public string Descriptive { get; set; } = DescriptiveType.None; public string AsYaml() { var stringBuilder = new StringBuilder(); var serializer = new Serializer(); stringBuilder.AppendLine(serializer.Serialize(this)); return stringBuilder.ToString(); } public EntityModel Clone() { return (EntityModel)MemberwiseClone(); } public void Copy(EntityModel entity) { DataType = entity.DataType; EntityType = entity.EntityType; EntityParts = entity.EntityParts.ToList(); } public EntityModel AddPart(IEntityPartInterface unitPart) { EntityParts.Add(unitPart); return this; } public static Dictionary GetDictionary() { if (_database == null) _database = DATA.Get(); return _database; } public static EntityModel Get(string entity) { if (_database == null) _database = DATA.Get(); return _database[entity]; } public static List GetList() { if (_entityModels == null) _entityModels = DATA.Get().Values.ToList(); return _entityModels; } public static List GetListOnlyHotkey() { if (_entityModelsOnlyHotkey == null) { _entityModelsOnlyHotkey = new List(); foreach (var entity in DATA.Get().Values) if (entity.Hotkey() != null) _entityModelsOnlyHotkey.Add(entity); } return _entityModelsOnlyHotkey; } public static Dictionary> GetEntitiesByHotkey() { if (_entityModelsByHotkey == null) { _entityModelsByHotkey = new Dictionary>(); foreach (var entity in GetList()) { var entityHotkey = entity.Hotkey(); if (entityHotkey != null) { if (!_entityModelsByHotkey.ContainsKey(entityHotkey.Hotkey)) _entityModelsByHotkey[entityHotkey.Hotkey] = new List(); _entityModelsByHotkey[entityHotkey.Hotkey].Add(entity); } } } return _entityModelsByHotkey; } public static EntityModel? GetFrom(string hotkey, string hotkeyGroup, bool holdSpace, string faction, string immortal) { if (string.IsNullOrEmpty(hotkey)) return null; if (!GetEntitiesByHotkey().ContainsKey(hotkey)) return null; var foundList = from entity in GetEntitiesByHotkey()[hotkey] where entity.Hotkey()?.HotkeyGroup == hotkeyGroup && entity.Hotkey()?.HoldSpace == holdSpace && entity.Faction()?.Faction == faction && (entity.VanguardAdded()?.ImmortalId == immortal || entity.VanguardAdded() == null) && (entity.Replaceds().Count == 0 || (from replace in entity.Replaceds() where replace.ImmortalId == immortal select replace).ToList().Count == 0) select entity; if (!foundList.Any()) return null; var found = (foundList ?? Array.Empty()).First(); return found; } public EntityInfoModel Info() { return ((EntityInfoModel)EntityParts.Find(x => x.GetType() == typeof(EntityInfoModel))!)!; } public EntitySupplyModel Supply() { return ((EntitySupplyModel)EntityParts.Find(x => x.GetType() == typeof(EntitySupplyModel))!)!; } public EntityTierModel Tier() { return ((EntityTierModel)EntityParts.Find(x => x.GetType() == typeof(EntityTierModel))!)!; } public EntityProductionModel? Production() { return ((EntityProductionModel)EntityParts.Find(x => x.GetType() == typeof(EntityProductionModel))!)!; } public EntityMovementModel Movement() { return ((EntityMovementModel)EntityParts.Find(x => x.GetType() == typeof(EntityMovementModel))!)!; } public EntityVitalityModel Vitality() { return ((EntityVitalityModel)EntityParts.Find(x => x.GetType() == typeof(EntityVitalityModel))!)!; } public List Requirements() { return EntityParts.FindAll(x => x.GetType() == typeof(EntityRequirementModel)) .Cast().ToList(); } public List Weapons() { return EntityParts.FindAll(x => x.GetType() == typeof(EntityWeaponModel)) .Cast().ToList(); } public List Replaceds() { return EntityParts.FindAll(x => x.GetType() == typeof(EntityVanguardReplacedModel)) .Cast().ToList(); } public EntityVanguardAddedModel VanguardAdded() { return ((EntityVanguardAddedModel)EntityParts.Find(x => x.GetType() == typeof(EntityVanguardAddedModel))!)!; } public EntityHotkeyModel Hotkey() { return ((EntityHotkeyModel)EntityParts.Find(x => x.GetType() == typeof(EntityHotkeyModel))!); } public EntityFactionModel Faction() { return ((EntityFactionModel)EntityParts.Find(x => x.GetType() == typeof(EntityFactionModel))!); } public EntityHarvestModel Harvest() { return ((EntityHarvestModel)EntityParts.Find(x => x.GetType() == typeof(EntityHarvestModel))!); } public List IdAbilities() { return EntityParts.FindAll(x => x.GetType() == typeof(EntityIdAbilityModel)) .Cast().ToList(); } public List IdArmies() { return EntityParts.FindAll(x => x.GetType() == typeof(EntityIdArmyModel)) .Cast().ToList(); } public List IdPassives() { return EntityParts.FindAll(x => x.GetType() == typeof(EntityIdPassiveModel)) .Cast().ToList(); } public List IdUpgrades() { return EntityParts.FindAll(x => x.GetType() == typeof(EntityIdUpgradeModel)) .Cast().ToList(); } public List IdVanguards() { return EntityParts.FindAll(x => x.GetType() == typeof(EntityIdVanguardModel)) .Cast().ToList(); } public List IdPyreSpells() { return EntityParts.FindAll(x => x.GetType() == typeof(EntityIdPyreSpellModel)) .Cast().ToList(); } public List Mechanics() { return EntityParts.FindAll(x => x.GetType() == typeof(EntityMechanicModel)) .Cast().ToList(); } public List Passives() { return EntityParts.FindAll(x => x.GetType() == typeof(EntityPassiveModel)) .Cast().ToList(); } public List Strategies() { return EntityParts.FindAll(x => x.GetType() == typeof(EntityStrategyModel)) .Cast().ToList(); } }