private async Task LoadDataAsync() { using (var reader = new StreamReader(DataConstants.AssemblyLocation + "/Data/AiFormations.json")) { _formationTemplates = new List <AiFormationTemplate>(); var entityData = await _aiEntityBaseRepo.GetDataAsync(); JContainer templateList = JsonConvert.DeserializeObject <JContainer>(reader.ReadToEnd()); foreach (var tObject in templateList) { var template = tObject.ToObject <AiFormationTemplate>(); var entityBases = new List <AiEntityBase[]>(); if (tObject["entityBaseIds"] != null) { var entityBaseIds = tObject["entityBaseIds"].ToObject <int?[][]>(); foreach (var row in entityBaseIds) { var fRow = new AiEntityBase[row.Length]; for (int i = 0; i < row.Length; i++) { if (row[i].HasValue) { var foundEntity = entityData.FirstOrDefault(e => e.Id == row[i].Value); if (foundEntity != null) { fRow[i] = foundEntity; } } else { fRow[i] = null; } } entityBases.Add(fRow); } template.EntityBases = entityBases.ToArray(); } _formationTemplates.Add(template); } } }
/// <summary> /// Creates a CombatEntity using an EnemyEntityBase. The result is an ai-controlled CombatEntity. /// </summary> /// <param name="entityBase">The base to use for the resultant CombatEntity.</param> /// <returns></returns> public CombatEntity Create(AiEntityBase entityBase) { var secondaryStats = StatsCalculator.GetSecondaryStats(entityBase.Stats); secondaryStats += entityBase.SecondaryStats; int health = entityBase.Resources.MaxHealth + StatsCalculator.GetHealth(entityBase.Stats); int mana = entityBase.Resources.MaxMana + StatsCalculator.GetMana(entityBase.Stats); var resources = new ResourceStats { CurrentHealth = health, CurrentMana = mana, MaxHealth = health, MaxMana = mana, UnmodifiedMaxHealth = health, UnmodifiedMaxMana = mana }; var iconUris = new CharacterIconSet(entityBase.IconUris); var entity = new CombatEntity { Id = _id++, Name = entityBase.Name, OwnerId = GameplayConstants.AiId, IconUris = iconUris, Abilities = entityBase.Abilities, ComboCounter = 0, OwnerName = entityBase.FactionName, Stats = entityBase.Stats.Copy(), SecondaryStats = entityBase.SecondaryStats, StatusEffects = new List <AppliedStatusEffect>(), UnmodifiedStats = entityBase.Stats, Resources = resources }; _statusEffectManager.Apply(entity, entity, entityBase.StatusEffects); return(entity); }