@page "/pokemonsleep/rate-pokemon" @inject IPokemonService PokemonService @inject IPokemonNatureService PokemonNatureService @inject IPokemonSubskillService PokemonSubskillService @inject NavigationManager Navigation @attribute [StreamRendering] @rendermode InteractiveServer Rate Pokémon

Pokémon Sleep

@if (PokemonList == null || NatureList == null || SubskillList == null) {

Loading...

} else {

Pokémon Rater

@if (SelectedPokemon != null) {
@if (SelectedPokemon.IsVariation) {
} else {
}
@if (SelectedPokemon.IsVariation) // If a Variant {

@SelectedPokemon.VariationName @SelectedPokemon.PokemonName

} else // Otherwise, Base Case {

@SelectedPokemon.PokemonName

}

Pokédex #@SelectedPokemon.PokemonId

@SelectedPokemon.SleepType

@SelectedPokemon.Speciality

Select Nature & Subskills

Final Score: @FinalScore

}
} @code { private List PokemonList; private List NatureList; private List SubskillList; private Dictionary isShiny = new Dictionary(); private int _selectedPokemonId; private int SelectedPokemonId { get => _selectedPokemonId; set { _selectedPokemonId = value; OnPokemonSelected(); } } private int SelectedNatureId; private int subskillSelect1; private int subskillSelect2; private int subskillSelect3; private int[] SelectedSubskills = new int[3]; private Pokemon SelectedPokemon; private int FinalScore; private string PokemonImageUrl => SelectedPokemon != null ? $"https://www.serebii.net/pokemonsleep/pokemon/{SelectedPokemon.Id}.png" : string.Empty; protected override async Task OnInitializedAsync() { PokemonList = await PokemonService.GetAllPokemonAsync(); NatureList = await PokemonNatureService.GetAllPokemonNaturesAsync(); SubskillList = await PokemonSubskillService.GetAllPokemonSubskillsAsync(); if (PokemonList is not null) { PokemonList.Sort((x, y) => x.PokemonId.CompareTo(y.PokemonId)); // Initialize dictionary with false (show base image first) foreach (var pokemon in PokemonList) { isShiny[pokemon.Id] = false; } } } private async void OnPokemonSelected() { if (SelectedPokemonId > 0) { SelectedPokemon = await PokemonService.GetPokemonByIdAsync(SelectedPokemonId); StateHasChanged(); // Force UI to refresh } } private void ToggleImage(int Id) { if (isShiny.ContainsKey(Id)) { isShiny[Id] = !isShiny[Id]; } } private void CalculateScore() { if (SelectedPokemon == null || SelectedNatureId == 0 || subskillSelect1 == 0 || subskillSelect2 == 0 || subskillSelect3 == 0 ) { return; } var nature = NatureList.FirstOrDefault(n => n.Id == SelectedNatureId); var subskill1 = SubskillList.FirstOrDefault(s => s.Id == subskillSelect1); var subskill2 = SubskillList.FirstOrDefault(s => s.Id == subskillSelect2); var subskill3 = SubskillList.FirstOrDefault(s => s.Id == subskillSelect3); if (nature == null || subskill1 == null || subskill2 == null || subskill3 == null) { return; } FinalScore = SelectedPokemon.Speciality switch { "Berries" => nature.BerryRating + subskill1.BerryRank + subskill2.BerryRank + subskill3.BerryRank, "Ingredients" => nature.IngredientRating + subskill1.IngredientRank + subskill2.IngredientRank + subskill3.IngredientRank, "Skills" => nature.SkillRating + subskill1.SkillRank + subskill2.SkillRank + subskill3.SkillRank, _ => 0 }; } }