public int CharacterPower(string characterId) { string comics = client.FindCharacterComics(characterId).Data.Count; int power = Int32.Parse(comics); return(power); }
/// <summary> /// Limited to the top 5 comics ordered by Name Ascending /// </summary> /// <param name="character"></param> /// <returns></returns> public static List <Comic> GetComics(Character character) { var creds = new Credentials(); var client = new MarvelRestClient(creds.PublicKey, creds.PrivateKey); var filter = new ComicRequestFilter(); filter.OrderBy(OrderResult.NameAscending); filter.Limit = 5; var comicResponse = client.FindCharacterComics(character.Id.ToString(), filter); return(ResultsToList(comicResponse)); }
public override async Task <FunctionResponse> ProcessMessageAsync(FunctionRequest request) { // Initialize the marvel api client var client = new MarvelRestClient(PUBLICKEY, PRIVATEKEY); // Initialize an avengers team var team = new Types.AvengerTeam(); // Initialize character request filter var characterRequestFilter = new CharacterRequestFilter(); // Query marvel api for desired avengers // TODO: refine this logic to assemble stronger team characterRequestFilter.OrderBy(OrderResult.NameAscending); characterRequestFilter.Limit = 1; var characterResponse = client.FindCharacters(characterRequestFilter); foreach (var character in characterResponse.Data.Results) { // Initialize a comic listing filter to determine power for each avenger var comicRequestFilter = new ComicRequestFilter(); comicRequestFilter.AddCharacter(character.Id); // Form avenger object var currentAvenger = new Types.Avenger(); currentAvenger.name = character.Name; currentAvenger.id = character.Id; currentAvenger.power = client.FindCharacterComics(character.Id.ToString(), comicRequestFilter).Data.Total; // Add avenger to team team.AddAvengerToTeam(currentAvenger); } var message = GameLogic.Methods.FormatBattlefieldId(request.RoundNumber, DateTime.UtcNow.ToString(), "AVENGERS", "DEFEND"); await Methods.PostBattlefield(new Types.Item { Id = message, Value = JsonConvert.SerializeObject(team.avengerTeam) }); return(new FunctionResponse()); }