private bool UseAttack(bool useBestAttack) { PokemonMove bestMove = null; int bestIndex = 0; double bestPower = 0; PokemonMove worstMove = null; int worstIndex = 0; double worstPower = 0; for (int i = 0; i < ActivePokemon.Moves.Length; ++i) { PokemonMove move = ActivePokemon.Moves[i]; if (move.CurrentPoints == 0) { continue; } MovesManager.MoveData moveData = MovesManager.Instance.GetMoveData(move.Id); if (move.Id + 1 == DreamEater && _client.ActiveBattle.OpponentStatus != "slp") { continue; } if (move.Id + 1 == Explosion || move.Id + 1 == Selfdestruct || (move.Id + 1 == DoubleEdge && ActivePokemon.BattleCurrentHealth < _client.ActiveBattle.CurrentHealth / 3)) { continue; } if (!IsMoveOffensive(move, moveData)) { continue; } PokemonType attackType = PokemonTypeExtensions.FromName(moveData.Type); PokemonType playerType1 = TypesManager.Instance.Type1[ActivePokemon.Id]; PokemonType playerType2 = TypesManager.Instance.Type2[ActivePokemon.Id]; PokemonType opponentType1 = TypesManager.Instance.Type1[_client.ActiveBattle.OpponentId]; PokemonType opponentType2 = TypesManager.Instance.Type2[_client.ActiveBattle.OpponentId]; double accuracy = (moveData.Accuracy < 0 ? 101.0 : moveData.Accuracy); double power = moveData.RealPower * accuracy; if (attackType == playerType1 || attackType == playerType2) { power *= 1.5; } power *= TypesManager.Instance.GetMultiplier(attackType, opponentType1); power *= TypesManager.Instance.GetMultiplier(attackType, opponentType2); if (attackType == PokemonType.Ground && PokemonManager.Instance.IsLavitatingPokemon(_client.ActiveBattle.OpponentId)) { power = 0; } power = ApplySpecialEffects(move, power); if (move.Id + 1 == Synchronoise) { if (playerType1 != opponentType1 && playerType1 != opponentType2 && (playerType2 == PokemonType.None || playerType2 != opponentType1) && (playerType2 == PokemonType.None || playerType2 != opponentType2)) { power = 0; } } if (power < 0.01) { continue; } if (bestMove == null || power > bestPower) { bestMove = move; bestPower = power; bestIndex = i; } if (worstMove == null || power < worstPower) { worstMove = move; worstPower = power; worstIndex = i; } } if (useBestAttack && bestMove != null) { _client.UseAttack(bestIndex + 1); return(true); } if (!useBestAttack && worstMove != null) { _client.UseAttack(worstIndex + 1); return(true); } return(false); }
private bool UseAttack(bool useBestAttack) { PokemonMove bestMove = null; int bestIndex = 0; double bestPower = 0; PokemonMove worstMove = null; int worstIndex = 0; double worstPower = 0; for (int i = 0; i < ActivePokemon.Moves.Length; ++i) { PokemonMove move = ActivePokemon.Moves[i]; if (move.CurrentPoints == 0) { continue; } MovesManager.MoveData moveData = MovesManager.Instance.GetMoveData(move.Id); if (move.Id == DreamEater && _client.ActiveBattle.WildPokemon.Status != "SLEEP") { continue; } if (move.Id == Explosion || move.Id == Selfdestruct || (move.Id == DoubleEdge && ActivePokemon.CurrentHealth < _client.ActiveBattle.WildPokemon.CurrentHealth / 3)) { continue; } if (!IsMoveOffensive(move, moveData)) { continue; } PokemonType attackType = PokemonTypeExtensions.FromName(moveData.Type); PokemonType playerType1 = TypesManager.Instance.Type1[ActivePokemon.Id]; PokemonType playerType2 = TypesManager.Instance.Type2[ActivePokemon.Id]; PokemonType opponentType1 = _client.ActiveBattle.WildPokemon.Type1; PokemonType opponentType2 = _client.ActiveBattle.WildPokemon.Type2; double accuracy = (moveData.Accuracy < 0 ? 101.0 : moveData.Accuracy); double power = moveData.Power * accuracy; if (attackType == playerType1 || attackType == playerType2) { power *= 1.5; } power *= TypesManager.Instance.GetMultiplier(attackType, opponentType1); power *= TypesManager.Instance.GetMultiplier(attackType, opponentType2); if (attackType == PokemonType.Ground && _levitatingPokemons.Contains(_client.ActiveBattle.WildPokemon.Id)) { power = 0; } power = ApplySpecialEffects(move, power); if (move.Id == Synchronoise) { if (playerType1 != opponentType1 && playerType1 != opponentType2 && (playerType2 == PokemonType.None || playerType2 != opponentType1) && (playerType2 == PokemonType.None || playerType2 != opponentType2)) { power = 0; } } if (move.Id == DragonRage) { if (opponentType1 == PokemonType.Fairy || opponentType2 == PokemonType.Fairy) { power = 0; } } if (power < 0.01) { continue; } if (bestMove == null || power > bestPower) { bestMove = move; bestPower = power; bestIndex = i; } if (worstMove == null || power < worstPower) { worstMove = move; worstPower = power; worstIndex = i; } } switch (useBestAttack) { case true when bestMove != null: _client.UseAttack(bestIndex); return(true); case false when worstMove != null: _client.UseAttack(worstIndex); return(true); default: return(false); } }
private ResultUsingMove UseAttack(bool useBestAttack, int activePoke, int oppenentPoke) { var activePokemon = ActivePokemons[activePoke]; if (!IsPokemonUsable(activePokemon)) { if (Pokemons.FindAll(x => !x.Sent && (IsPokemonUsable(x) || x.Health > 0)).Count <= 0) { if (activePokemon.Health <= 0) { _client.UseAttack(0, activePoke + 1); return(ResultUsingMove.Success); } else { return(ResultUsingMove.NoLongerUsable); } } return(ResultUsingMove.Fainted); } PSXAPI.Response.Payload.BattleMove bestMove = null; int bestIndex = 0; double bestPower = 0; PSXAPI.Response.Payload.BattleMove worstMove = null; int worstIndex = 0; double worstPower = 0; if (activePoke < 0) { return(ResultUsingMove.NoLongerUsable); } for (int i = 0; i < activePokemon.Moves.Length; i++) { var move = activePokemon.Moves[i]; if (move is null) { continue; } if (move.pp == 0 || move.disabled) { continue; } MovesManager.MoveData moveData = MovesManager.Instance.GetMoveData(move.id); if (moveData is null) { continue; } if (moveData.ID == DreamEater && ActiveOpponentPokemons[oppenentPoke].Status != "slp") { continue; } if (moveData.ID == Explosion || moveData.ID == Selfdestruct || (moveData.ID == DoubleEdge && activePokemon.Health < ActiveOpponentPokemons[oppenentPoke].Health / 3)) { continue; } if (!IsMoveOffensive(moveData)) { continue; } PokemonType attackType = PokemonTypeExtensions.FromName(moveData.Type); PokemonType playerType1 = TypesManager.Instance.Type1[activePokemon.ID]; PokemonType playerType2 = TypesManager.Instance.Type2[activePokemon.ID]; PokemonType opponentType1 = TypesManager.Instance.Type1[ActiveOpponentPokemons[oppenentPoke].ID]; PokemonType opponentType2 = TypesManager.Instance.Type2[ActiveOpponentPokemons[oppenentPoke].ID]; double accuracy = (moveData.Accuracy < 0 ? 101.0 : moveData.Accuracy); double power = moveData.RealPower * accuracy; if (attackType == playerType1 || attackType == playerType2) { power *= 1.5; } power *= TypesManager.Instance.GetMultiplier(attackType, opponentType1); power *= TypesManager.Instance.GetMultiplier(attackType, opponentType2); if (attackType == PokemonType.Ground && PokemonManager.Instance.IsLavitatingPokemon(ActiveOpponentPokemons[oppenentPoke].ID)) { power = 0; } power = ApplySpecialEffects(moveData, ActiveOpponentPokemons[oppenentPoke], activePokemon, power); if (moveData.ID == Synchronoise) { if (playerType1 != opponentType1 && playerType1 != opponentType2 && (playerType2 == PokemonType.None || playerType2 != opponentType1) && (playerType2 == PokemonType.None || playerType2 != opponentType2)) { power = 0; } } if (power < 0.01) { continue; } if (bestMove == null || power > bestPower) { bestMove = move; bestPower = power; bestIndex = i; } if (worstMove == null || power < worstPower) { worstMove = move; worstPower = power; worstIndex = i; } } if (ActivePokemons.Length <= 1) { IsBusy = true; } if (useBestAttack && bestMove != null) { _client.UseAttack(bestIndex + 1, activePoke + 1, ActiveOpponentPokemons.Length == 1 ? oppenentPoke : oppenentPoke + 1); return(ResultUsingMove.Success); } if (!useBestAttack && worstMove != null) { _client.UseAttack(worstIndex + 1, activePoke + 1, ActiveOpponentPokemons.Length == 1 ? oppenentPoke : oppenentPoke + 1); return(ResultUsingMove.Success); } return(ResultUsingMove.NoLongerUsable); }
private bool UseAttack(bool useBestAttack) { PokemonMove bestMove = null; var bestIndex = 0; double bestPower = 0; PokemonMove worstMove = null; var worstIndex = 0; double worstPower = 0; for (var i = 0; i < ActivePokemon.Moves.Length; ++i) { var move = ActivePokemon.Moves[i]; if (move.CurrentPoints == 0) { continue; } if (move.Name is null || move.Data is null) { continue; } var moveData = MovesManager.Instance.GetMoveData(move.Id); if (move.Id == DreamEater && (_client.ActiveBattle.FullWildPokemon != null ? _client.ActiveBattle.FullWildPokemon.Status.ToUpperInvariant() != "SLEEP" : _client.ActiveBattle.WildPokemon.Status.ToUpperInvariant() != "SLEEP")) { continue; } if (move.Id == Explosion || move.Id == Selfdestruct || (move.Id == DoubleEdge && ActivePokemon.CurrentHealth < (_client.ActiveBattle.FullWildPokemon?.MaxHealth / 3 ?? _client.ActiveBattle.WildPokemon.MaxHealth / 3))) { continue; } var attackType = PokemonTypeExtensions.FromName(moveData.Type); var playerType1 = TypesManager.Instance.Type1[ActivePokemon.Id]; var playerType2 = TypesManager.Instance.Type2[ActivePokemon.Id]; var opponentType1 = TypesManager.Instance.Type1[_client.ActiveBattle.WildPokemon.Id]; var opponentType2 = TypesManager.Instance.Type2[_client.ActiveBattle.WildPokemon.Id]; if (!IsMoveOffensive(move, moveData, opponentType1, opponentType2)) { continue; } var accuracy = moveData.Accuracy < 0 ? 101.0 : moveData.Accuracy; var power = moveData.Power * accuracy; if (attackType == playerType1 || attackType == playerType2) { power *= 1.5; } power *= TypesManager.Instance.GetMultiplier(attackType, opponentType1); power *= TypesManager.Instance.GetMultiplier(attackType, opponentType2); if (attackType == PokemonType.Ground && LevitatingPokemons.Contains(_client.ActiveBattle.WildPokemon.Id)) { power = 0; } power = ApplySpecialEffects(move, power); if (move.Id == Synchronoise) { if (playerType1 != opponentType1 && playerType1 != opponentType2 && (playerType2 == PokemonType.None || playerType2 != opponentType1) && (playerType2 == PokemonType.None || playerType2 != opponentType2)) { power = 0; } } if (power < 0.01) { continue; } if (bestMove == null || power > bestPower) { bestMove = move; bestPower = power; bestIndex = i; } if (worstMove == null || power < worstPower) { worstMove = move; worstPower = power; worstIndex = i; } } if (useBestAttack && bestMove != null) { _client.UseAttack(bestIndex); return(true); } if (!useBestAttack && worstMove != null) { _client.UseAttack(worstIndex); return(true); } return(false); }