@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 ScoreBackgroundColor; private string ScoreColor; 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 }; ScoreBackgroundColor = FinalScore switch { 8 => "#16C47F", 7 => "#33CB8F", 6 => "#50D39F", 5 => "#6DDAAF", 4 => "#8BE2BF", 3 => "#A8E9CF", 2 => "#C5F0DF", 1 => "#E2F8EF", 0 => "#FFFFFF", -1 => "#FFE7E7", -2 => "#FED0D0", -3 => "#FEB8B8", -4 => "#FDA0A0", -5 => "#FD8888", -6 => "#FC7171", -7 => "#FC5959", -8 => "#FB4141", _ => "#FFFFFF" }; ScoreColor = FinalScore switch { 8 => "#FFFFFF", 7 => "#FFFFFF", 6 => "#FFFFFF", 5 => "#FFFFFF", 4 => "#FFFFFF", 3 => "#FFFFFF", 2 => "#FFFFFF", 1 => "#FFFFFF", 0 => "#000", -1 => "#FFFFFF", -2 => "#FFFFFF", -3 => "#FFFFFF", -4 => "#FFFFFF", -5 => "#FFFFFF", -6 => "#FFFFFF", -7 => "#FFFFFF", -8 => "#FFFFFF", _ => "#FFFFFF" }; } }