public object Convert(IList <object> values, Type targetType, object parameter, CultureInfo culture) { var species = (PBESpecies)values[0]; if (!PBEDataUtils.HasForms(species, true)) { return(AvaloniaProperty.UnsetValue); } PBEForm form = true ? 0 : (PBEForm)values[1]; // TODO IPBELocalizedString localized = PBEDataProvider.Instance.GetFormName(species, form); return(StringRenderer.Render(localized.FromPBECultureInfo(), parameter?.ToString())); }
public async Task Info([Remainder] string input) { // Inputs for forms should be like "Giratina (Origin Forme)" Match m = Regex.Match(input, @"^(\S+) \((.+)\)$"); string speciesName; string?formName; if (m.Success) { speciesName = m.Groups[1].Value; formName = m.Groups[2].Value; } else { speciesName = input; formName = null; } if (!PBEDataProvider.Instance.GetSpeciesByName(speciesName, out PBESpecies? nSpecies)) { await Context.Channel.SendMessageAsync($"{Context.User.Mention} ― Invalid species!"); return; } PBESpecies species = nSpecies.Value; speciesName = PBEDataProvider.Instance.GetSpeciesName(species).English; PBEForm form; if (formName is null) { form = 0; } else { if (!PBEDataProvider.Instance.GetFormByName(species, formName, out PBEForm? nForm)) { IReadOnlyList <PBEForm> forms = PBEDataUtils.GetForms(species, false); string str = $"{Context.User.Mention} ― Invalid form for {speciesName}"; if (forms.Count > 0) { str += ", valid forms are:\n**" + string.Join("\n", forms.Select(f => PBEDataProvider.Instance.GetFormName(species, f).English)) + "**"; } else { str += "! It has no forms!"; } await Context.Channel.SendMessageAsync(str); return; } form = nForm.Value; } formName = PBEDataUtils.HasForms(species, false) ? $" ({PBEDataProvider.Instance.GetFormName(species, form).English})" : string.Empty; IPBEPokemonData pData = PBEDataProvider.Instance.GetPokemonData(species, form); string types = $"{Utils.TypeEmotes[pData.Type1]}"; if (pData.Type2 != PBEType.None) { types += $" {Utils.TypeEmotes[pData.Type2]}"; } string ratio; switch (pData.GenderRatio) { case PBEGenderRatio.M7_F1: ratio = "87.5% Male, 12.5% Female"; break; case PBEGenderRatio.M3_F1: ratio = "75% Male, 25% Female"; break; case PBEGenderRatio.M1_F1: ratio = "50% Male, 50% Female"; break; case PBEGenderRatio.M1_F3: ratio = "25% Male, 75% Female"; break; case PBEGenderRatio.M0_F1: ratio = "100% Female"; break; case PBEGenderRatio.M1_F0: ratio = "100% Male"; break; case PBEGenderRatio.M0_F0: ratio = "Genderless Species"; break; default: throw new InvalidDataException(nameof(pData.GenderRatio)); } string weaknesses = string.Empty, resistances = string.Empty, immunities = string.Empty; for (PBEType atk = PBEType.None + 1; atk < PBEType.MAX; atk++) { float d = PBETypeEffectiveness.GetEffectiveness(atk, pData); if (d <= 0) { if (immunities != string.Empty) { immunities += ' '; } immunities += Utils.TypeEmotes[atk]; } else if (d < 1) { if (resistances != string.Empty) { resistances += ' '; } resistances += Utils.TypeEmotes[atk]; } if (d > 1) { if (weaknesses != string.Empty) { weaknesses += ' '; } weaknesses += Utils.TypeEmotes[atk]; } } if (weaknesses == string.Empty) { weaknesses = "No Weaknesses"; } if (resistances == string.Empty) { resistances = "No Resistances"; } if (immunities == string.Empty) { immunities = "No Immunities"; } EmbedBuilder embed = new EmbedBuilder() .WithAuthor(Context.User) .WithColor(Utils.GetColor(pData.Type1, pData.Type2)) .WithTitle($"{speciesName}{formName} ― {PBEDefaultDataProvider.Instance.GetSpeciesCategory(species).English}") .WithUrl(Utils.URL) .WithDescription(PBEDefaultDataProvider.Instance.GetSpeciesEntry(species).English.Replace('\n', ' ')) .AddField("Types", types, true) .AddField("Gender Ratio", ratio, true) .AddField("Weight", $"{pData.Weight:N1} kg", true) .AddField("Abilities", string.Join(", ", pData.Abilities.Select(a => PBEDataProvider.Instance.GetAbilityName(a).English)), false) .AddField("HP", pData.BaseStats.HP, true) .AddField("Attack", pData.BaseStats.Attack, true) .AddField("Defense", pData.BaseStats.Defense, true) .AddField("Special Attack", pData.BaseStats.SpAttack, true) .AddField("Special Defense", pData.BaseStats.SpDefense, true) .AddField("Speed", pData.BaseStats.Speed, true) .AddField("Type Weaknesses", weaknesses, true) .AddField("Type Resistances", resistances, true) .AddField("Type Immunities", immunities, true) .WithImageUrl(Utils.GetPokemonSprite(species, form, PBEDataProvider.GlobalRandom.RandomShiny(), PBEDataProvider.GlobalRandom.RandomGender(pData.GenderRatio), false, false)); await Context.Channel.SendMessageAsync(string.Empty, embed : embed.Build()); }
public static string CustomPokemonToString(PBEBattlePokemon pkmn, bool useKnownInfo) { var sb = new StringBuilder(); string GetTeamNickname(PBEBattlePokemon p) { return($"{p.Trainer.Name}'s {(useKnownInfo ? p.KnownNickname : p.Nickname)}"); } void AddStatChanges() { PBEStat[] statChanges = pkmn.GetChangedStats(); if (statChanges.Length > 0) { var statStrs = new List <string>(7); if (Array.IndexOf(statChanges, PBEStat.Attack) != -1) { statStrs.Add($"[A] x{PBEBattle.GetStatChangeModifier(pkmn.AttackChange, false):0.00}"); } if (Array.IndexOf(statChanges, PBEStat.Defense) != -1) { statStrs.Add($"[D] x{PBEBattle.GetStatChangeModifier(pkmn.DefenseChange, false):0.00}"); } if (Array.IndexOf(statChanges, PBEStat.SpAttack) != -1) { statStrs.Add($"[SA] x{PBEBattle.GetStatChangeModifier(pkmn.SpAttackChange, false):0.00}"); } if (Array.IndexOf(statChanges, PBEStat.SpDefense) != -1) { statStrs.Add($"[SD] x{PBEBattle.GetStatChangeModifier(pkmn.SpDefenseChange, false):0.00}"); } if (Array.IndexOf(statChanges, PBEStat.Speed) != -1) { statStrs.Add($"[S] x{PBEBattle.GetStatChangeModifier(pkmn.SpeedChange, false):0.00}"); } if (Array.IndexOf(statChanges, PBEStat.Accuracy) != -1) { statStrs.Add($"[AC] x{PBEBattle.GetStatChangeModifier(pkmn.AccuracyChange, true):0.00}"); } if (Array.IndexOf(statChanges, PBEStat.Evasion) != -1) { statStrs.Add($"[E] x{PBEBattle.GetStatChangeModifier(pkmn.EvasionChange, true):0.00}"); } sb.AppendLine($"Stat changes: {string.Join(", ", statStrs)}"); } } void AddStatus1() { if (pkmn.Status1 != PBEStatus1.None) { sb.AppendLine($"Main status: {pkmn.Status1}"); if (pkmn.Status1 == PBEStatus1.Asleep) { sb.AppendLine($"Asleep turns: {pkmn.Status1Counter}"); } else if (pkmn.Status1 == PBEStatus1.BadlyPoisoned) { sb.AppendLine($"Toxic counter: {pkmn.Status1Counter}"); } } } void AddStatus2(PBEStatus2 status2) { status2 &= ~PBEStatus2.Flinching; // Don't show flinching sb.AppendLine($"Volatile status: {status2}"); if (status2.HasFlag(PBEStatus2.Disguised)) { sb.AppendLine($"Disguised as: {pkmn.DisguisedAsPokemon.Nickname}"); } if (pkmn.Battle.BattleFormat != PBEBattleFormat.Single) { if (status2.HasFlag(PBEStatus2.Infatuated)) { sb.AppendLine($"Infatuated with: {GetTeamNickname(pkmn.InfatuatedWithPokemon)}"); } if (status2.HasFlag(PBEStatus2.LeechSeed)) { sb.AppendLine($"Seeded position: {pkmn.SeededTeam.CombinedName}'s {pkmn.SeededPosition}"); } if (status2.HasFlag(PBEStatus2.LockOn)) { sb.AppendLine($"Taking aim at: {GetTeamNickname(pkmn.LockOnPokemon)}"); } } } if (useKnownInfo) { var pData = PBEPokemonData.GetData(pkmn.KnownSpecies, pkmn.KnownForm); string formStr = PBEDataUtils.HasForms(pkmn.KnownSpecies, false) ? $" ({PBELocalizedString.GetFormName(pkmn.KnownSpecies, pkmn.KnownForm)})" : string.Empty; sb.AppendLine($"{pkmn.KnownNickname}/{pkmn.KnownSpecies}{formStr} {(pkmn.KnownStatus2.HasFlag(PBEStatus2.Transformed) ? pkmn.Gender.ToSymbol() : pkmn.KnownGender.ToSymbol())} Lv.{pkmn.Level}"); sb.AppendLine($"HP: {pkmn.HPPercentage:P2}"); sb.Append($"Known types: {PBELocalizedString.GetTypeName(pkmn.KnownType1)}"); if (pkmn.KnownType2 != PBEType.None) { sb.Append($"/{PBELocalizedString.GetTypeName(pkmn.KnownType2)}"); } sb.AppendLine(); if (pkmn.FieldPosition != PBEFieldPosition.None) { sb.AppendLine($"Position: {pkmn.Team.CombinedName}'s {pkmn.FieldPosition}"); } AddStatus1(); if (pkmn.FieldPosition != PBEFieldPosition.None) { if (pkmn.KnownStatus2 != PBEStatus2.None) { AddStatus2(pkmn.KnownStatus2); } } PBEDataUtils.GetStatRange(pData, PBEStat.HP, pkmn.Level, pkmn.Battle.Settings, out ushort lowHP, out ushort highHP); PBEDataUtils.GetStatRange(pData, PBEStat.Attack, pkmn.Level, pkmn.Battle.Settings, out ushort lowAttack, out ushort highAttack); PBEDataUtils.GetStatRange(pData, PBEStat.Defense, pkmn.Level, pkmn.Battle.Settings, out ushort lowDefense, out ushort highDefense); PBEDataUtils.GetStatRange(pData, PBEStat.SpAttack, pkmn.Level, pkmn.Battle.Settings, out ushort lowSpAttack, out ushort highSpAttack); PBEDataUtils.GetStatRange(pData, PBEStat.SpDefense, pkmn.Level, pkmn.Battle.Settings, out ushort lowSpDefense, out ushort highSpDefense); PBEDataUtils.GetStatRange(pData, PBEStat.Speed, pkmn.Level, pkmn.Battle.Settings, out ushort lowSpeed, out ushort highSpeed); sb.AppendLine($"Stat range: [HP] {lowHP}-{highHP}, [A] {lowAttack}-{highAttack}, [D] {lowDefense}-{highDefense}, [SA] {lowSpAttack}-{highSpAttack}, [SD] {lowSpDefense}-{highSpDefense}, [S] {lowSpeed}-{highSpeed}, [W] {pkmn.KnownWeight:0.0}"); if (pkmn.FieldPosition != PBEFieldPosition.None) { AddStatChanges(); } if (pkmn.KnownAbility == PBEAbility.MAX) { sb.AppendLine($"Possible abilities: {string.Join(", ", pData.Abilities.Select(a => PBELocalizedString.GetAbilityName(a).ToString()))}"); } else { sb.AppendLine($"Known ability: {PBELocalizedString.GetAbilityName(pkmn.KnownAbility)}"); } sb.AppendLine($"Known item: {(pkmn.KnownItem == (PBEItem)ushort.MaxValue ? "???" : PBELocalizedString.GetItemName(pkmn.KnownItem).ToString())}"); sb.Append("Known moves: "); for (int i = 0; i < pkmn.Battle.Settings.NumMoves; i++) { PBEBattleMoveset.PBEBattleMovesetSlot slot = pkmn.KnownMoves[i]; PBEMove move = slot.Move; int pp = slot.PP; int maxPP = slot.MaxPP; if (i > 0) { sb.Append(", "); } sb.Append(move == PBEMove.MAX ? "???" : PBELocalizedString.GetMoveName(move).ToString()); if (move != PBEMove.None && move != PBEMove.MAX) { sb.Append($" ({pp}{(maxPP == 0 ? ")" : $"/{maxPP})")}"); } } }
private string CreateKnownPokemonEmbed(PBEBattlePokemon pkmn) { IPBEPokemonData pData = PBEDataProvider.Instance.GetPokemonData(pkmn.KnownSpecies, pkmn.KnownForm); var sb = new StringBuilder(); string formStr = PBEDataUtils.HasForms(pkmn.KnownSpecies, false) ? $" ({PBEDataProvider.Instance.GetFormName(pkmn.KnownSpecies, pkmn.KnownForm).English})" : string.Empty; sb.AppendLine($"{GetTrainerName(pkmn.Trainer)}'s {pkmn.KnownNickname}/{pkmn.KnownSpecies}{formStr} {(pkmn.KnownStatus2.HasFlag(PBEStatus2.Transformed) ? pkmn.Gender.ToSymbol() : pkmn.KnownGender.ToSymbol())} Lv.{pkmn.Level}{(pkmn.KnownShiny ? $" {_shinyEmoji}" : string.Empty)}"); sb.AppendLine($"**HP:** {pkmn.HPPercentage:P2}"); sb.Append($"**Known types:** {Utils.TypeEmotes[pkmn.KnownType1]}"); if (pkmn.KnownType2 != PBEType.None) { sb.Append($" {Utils.TypeEmotes[pkmn.KnownType2]}"); } sb.AppendLine(); if (pkmn.Status1 != PBEStatus1.None) { sb.AppendLine($"**Main status:** {Utils.Status1Emotes[pkmn.Status1]}"); if (pkmn.Status1 == PBEStatus1.Asleep) { sb.AppendLine($"**{Utils.Status1Emotes[PBEStatus1.Asleep]} turns:** {pkmn.Status1Counter}"); } else if (pkmn.Status1 == PBEStatus1.BadlyPoisoned) { sb.AppendLine($"**{Utils.Status1Emotes[PBEStatus1.BadlyPoisoned]} counter:** {pkmn.Status1Counter}"); } } if (pkmn.KnownStatus2 != PBEStatus2.None) { sb.AppendLine($"**Volatile status:** {pkmn.KnownStatus2}"); if (pkmn.KnownStatus2.HasFlag(PBEStatus2.Confused)) { sb.AppendLine($"**Confusion turns:** {pkmn.ConfusionCounter}"); } } PBEDataUtils.GetStatRange(pData, PBEStat.HP, pkmn.Level, PBESettings.DefaultSettings, out ushort lowHP, out ushort highHP); PBEDataUtils.GetStatRange(pData, PBEStat.Attack, pkmn.Level, PBESettings.DefaultSettings, out ushort lowAttack, out ushort highAttack); PBEDataUtils.GetStatRange(pData, PBEStat.Defense, pkmn.Level, PBESettings.DefaultSettings, out ushort lowDefense, out ushort highDefense); PBEDataUtils.GetStatRange(pData, PBEStat.SpAttack, pkmn.Level, PBESettings.DefaultSettings, out ushort lowSpAttack, out ushort highSpAttack); PBEDataUtils.GetStatRange(pData, PBEStat.SpDefense, pkmn.Level, PBESettings.DefaultSettings, out ushort lowSpDefense, out ushort highSpDefense); PBEDataUtils.GetStatRange(pData, PBEStat.Speed, pkmn.Level, PBESettings.DefaultSettings, out ushort lowSpeed, out ushort highSpeed); sb.AppendLine($"**Stat range:** [HP] {lowHP}-{highHP}, [A] {lowAttack}-{highAttack}, [D] {lowDefense}-{highDefense}, [SA] {lowSpAttack}-{highSpAttack}, [SD] {lowSpDefense}-{highSpDefense}, [S] {lowSpeed}-{highSpeed}, [W] {pkmn.KnownWeight:0.0}"); AddStatChanges(pkmn, sb); if (pkmn.KnownAbility == PBEAbility.MAX) { sb.AppendLine($"**Possible abilities:** {string.Join(", ", pData.Abilities.Select(a => PBEDataProvider.Instance.GetAbilityName(a).English))}"); } else { sb.AppendLine($"**Known ability:** {PBEDataProvider.Instance.GetAbilityName(pkmn.KnownAbility).English}"); } sb.AppendLine($"**Known item:** {(pkmn.KnownItem == (PBEItem)ushort.MaxValue ? "???" : PBEDataProvider.Instance.GetItemName(pkmn.KnownItem).English)}"); sb.Append("**Known moves:** "); for (int i = 0; i < PBESettings.DefaultNumMoves; i++) { PBEBattleMoveset.PBEBattleMovesetSlot slot = pkmn.KnownMoves[i]; PBEMove move = slot.Move; if (move != PBEMove.None) { int pp = slot.PP; int maxPP = slot.MaxPP; if (i > 0) { sb.Append(", "); } if (move == PBEMove.MAX) { sb.Append("???"); } else { sb.Append($"{Utils.TypeEmotes[pkmn.GetMoveType(move, useKnownInfo: true)]} {PBEDataProvider.Instance.GetMoveName(move).English} ({pp}{(maxPP == 0 ? ")" : $"/{maxPP})")}"); } } }
private static void CreatePokemonEmbed(PBEBattlePokemon pkmn, bool addReactionChars, out string outStr, out EmbedFieldBuilder[] outFields) { var sb = new StringBuilder(); string formStr = PBEDataUtils.HasForms(pkmn.Species, false) ? $" ({PBEDataProvider.Instance.GetFormName(pkmn).English})" : string.Empty; sb.AppendLine($"{pkmn.Nickname}/{PBEDataProvider.Instance.GetSpeciesName(pkmn.Species).English}{formStr} {pkmn.Gender.ToSymbol()} Lv.{pkmn.Level}{(pkmn.Shiny ? $" {_shinyEmoji}" : string.Empty)}"); sb.AppendLine($"**HP:** {pkmn.HP}/{pkmn.MaxHP} ({pkmn.HPPercentage:P2})"); sb.Append($"**Types:** {Utils.TypeEmotes[pkmn.Type1]}"); if (pkmn.Type2 != PBEType.None) { sb.Append($" {Utils.TypeEmotes[pkmn.Type2]}"); } sb.AppendLine(); if (pkmn.Status1 != PBEStatus1.None) { sb.AppendLine($"**Main status:** {Utils.Status1Emotes[pkmn.Status1]}"); } if (pkmn.FieldPosition != PBEFieldPosition.None) { if (pkmn.Status1 == PBEStatus1.Asleep) { sb.AppendLine($"**{Utils.Status1Emotes[PBEStatus1.Asleep]} turns:** {pkmn.Status1Counter}"); } else if (pkmn.Status1 == PBEStatus1.BadlyPoisoned) { sb.AppendLine($"**{Utils.Status1Emotes[PBEStatus1.BadlyPoisoned]} counter:** {pkmn.Status1Counter}"); } if (pkmn.Status2 != PBEStatus2.None) { sb.AppendLine($"**Volatile status:** {pkmn.Status2}"); if (pkmn.Status2.HasFlag(PBEStatus2.Confused)) { sb.AppendLine($"**Confusion turns:** {pkmn.ConfusionCounter}"); } if (pkmn.Status2.HasFlag(PBEStatus2.Disguised)) { formStr = PBEDataUtils.HasForms(pkmn.KnownSpecies, false) ? $" ({PBEDataProvider.Instance.GetFormName(pkmn.KnownSpecies, pkmn.KnownForm).English})" : string.Empty; sb.AppendLine($"**Disguised as:** {pkmn.KnownNickname}/{PBEDataProvider.Instance.GetSpeciesName(pkmn.KnownSpecies).English}{formStr} {pkmn.KnownGender.ToSymbol()}"); } if (pkmn.Status2.HasFlag(PBEStatus2.Substitute)) { sb.AppendLine($"**Substitute HP:** {pkmn.SubstituteHP}"); } } } sb.AppendLine($"**Stats:** [A] {pkmn.Attack}, [D] {pkmn.Defense}, [SA] {pkmn.SpAttack}, [SD] {pkmn.SpDefense}, [S] {pkmn.Speed}, [W] {pkmn.Weight:0.0}"); if (pkmn.FieldPosition != PBEFieldPosition.None) { AddStatChanges(pkmn, sb); } sb.AppendLine($"**Ability:** {PBEDataProvider.Instance.GetAbilityName(pkmn.Ability).English}"); sb.AppendLine($"**Item:** {PBEDataProvider.Instance.GetItemName(pkmn.Item).English}"); if (pkmn.Moves.Contains(PBEMoveEffect.Frustration) || pkmn.Moves.Contains(PBEMoveEffect.Return)) { sb.AppendLine($"**Friendship:** {pkmn.Friendship} ({pkmn.Friendship / (double)byte.MaxValue:P2})"); } if (pkmn.Moves.Contains(PBEMoveEffect.HiddenPower)) { sb.AppendLine($"**{PBEDataProvider.Instance.GetMoveName(PBEMove.HiddenPower).English}:** {Utils.TypeEmotes[pkmn.IndividualValues.GetHiddenPowerType()]}|{pkmn.IndividualValues.GetHiddenPowerBasePower(PBESettings.DefaultSettings)}"); } outStr = sb.ToString(); sb.Clear(); outFields = new EmbedFieldBuilder[2]; EmbedFieldBuilder field = new EmbedFieldBuilder() .WithName("**Moves:**") .WithIsInline(true); outFields[0] = field; for (int i = 0; i < PBESettings.DefaultNumMoves; i++) { PBEBattleMoveset.PBEBattleMovesetSlot slot = pkmn.Moves[i]; PBEMove move = slot.Move; if (move != PBEMove.None) { PBEType moveType = pkmn.GetMoveType(move); sb.Append($"{Utils.TypeEmotes[moveType]} {PBEDataProvider.Instance.GetMoveName(move).English} ({slot.PP}/{slot.MaxPP})"); if (i < PBESettings.DefaultNumMoves - 1) { sb.AppendLine(); } } } field.WithValue(sb.ToString()); sb.Clear(); field = new EmbedFieldBuilder() .WithName("**Usable moves:**") .WithIsInline(true); outFields[1] = field; PBEMove[] usableMoves = pkmn.GetUsableMoves(); for (int i = 0; i < usableMoves.Length; i++) { PBEMove move = usableMoves[i]; PBEType moveType = pkmn.GetMoveType(move); if (addReactionChars) { sb.Append($"{_moveEmotes[i][moveType]} "); } else { sb.Append($"{Utils.TypeEmotes[moveType]} "); } sb.Append(PBEDataProvider.Instance.GetMoveName(move).English); if (i < usableMoves.Length - 1) { sb.AppendLine(); } } field.WithValue(sb.ToString()); }