public async Task <IActionResult> DualTypeChartAsDefender(string type1, string type2) { var types = new List <string>(); types.Add(type1); types.Add(type2); var noEffect = new List <string>(); var notVeryEffectiveRaw = new List <string>(); var superEffectiveRaw = new List <string>(); foreach (var t in types) { var apiType = await _pokeApi.RequestData($"type/{t}"); var resultsType = JsonConvert.DeserializeObject <TypesModel>(apiType); foreach (var rt in resultsType.DamageRelations.DoubleDamageFrom) { superEffectiveRaw.Add(rt.Name); } foreach (var rt in resultsType.DamageRelations.HalfDamageFrom) { notVeryEffectiveRaw.Add(rt.Name); } foreach (var rt in resultsType.DamageRelations.NoDamageFrom) { noEffect.Add(rt.Name); } } var json = TypesCalculator.CalculateDamage(superEffectiveRaw, notVeryEffectiveRaw, noEffect); return(Ok(json)); }
public async Task <IActionResult> PokemonTypeAsDefender(string name) { var api = await _pokeApi.RequestData($"pokemon/{name}"); var results = JsonConvert.DeserializeObject <PokemonModel>(api); var types = new List <string>(); var noEffect = new List <string>(); var notVeryEffectiveRaw = new List <string>(); var superEffectiveRaw = new List <string>(); foreach (var r in results.Types) { types.Add(r.TypesData.Name); var apiType = await _pokeApi.RequestData($"type/{r.TypesData.Name}"); var resultsType = JsonConvert.DeserializeObject <TypesModel>(apiType); foreach (var rt in resultsType.DamageRelations.DoubleDamageFrom) { superEffectiveRaw.Add(rt.Name); } foreach (var rt in resultsType.DamageRelations.HalfDamageFrom) { notVeryEffectiveRaw.Add(rt.Name); } foreach (var rt in resultsType.DamageRelations.NoDamageFrom) { noEffect.Add(rt.Name); } } var json = TypesCalculator.CalculateDamage(superEffectiveRaw, notVeryEffectiveRaw, noEffect); return(Ok(json)); }