Code tidying with Rubocop

This commit is contained in:
Maruno17
2023-07-18 22:42:10 +01:00
parent 6053363715
commit a5734eaf46
68 changed files with 276 additions and 232 deletions

View File

@@ -139,8 +139,8 @@ class Battle::AI
# Find items usable on other Pokémon in the user's team
# NOTE: Currently only checks Revives.
usable_items = {}
@battle.eachInTeamFromBattlerIndex(@user.index) do |pkmn, i|
next if !pkmn.fainted? # Remove this line to check unfainted Pokémon too
@battle.eachInTeamFromBattlerIndex(@user.index) do |team_pkmn, i|
next if !team_pkmn.fainted? # Remove this line to check unfainted Pokémon too
items.each do |item|
usage = get_usability_of_item_on_pkmn(item, i, @user.side)
usage.each_pair do |key, vals|

View File

@@ -9,7 +9,7 @@ class Battle::AI
# Returns a value between 0.0 and 1.0. All move scores are lowered by this
# value multiplied by the highest-scoring move's score.
def move_score_threshold
return 0.6 + 0.35 * (([@trainer.skill, 100].min / 100.0) ** 0.5) # 0.635 to 0.95
return 0.6 + (0.35 * (([@trainer.skill, 100].min / 100.0)**0.5)) # 0.635 to 0.95
end
#-----------------------------------------------------------------------------
@@ -161,7 +161,7 @@ class Battle::AI
@target&.refresh_battler
if @target && @move.function_code == "UseLastMoveUsedByTarget"
if @target.battler.lastRegularMoveUsed &&
GameData::Move.exists?(@target.battler.lastRegularMoveUsed) &&
GameData::Move.exists?(@target.battler.lastRegularMoveUsed) &&
GameData::Move.get(@target.battler.lastRegularMoveUsed).has_flag?("CanMirrorMove")
@battle.moldBreaker = @user.has_mold_breaker?
mov = Battle::Move.from_pokemon_move(@battle, Pokemon::Move.new(@target.battler.lastRegularMoveUsed))
@@ -278,7 +278,7 @@ class Battle::AI
PBDebug.log_score_change(score - old_score, "function code modifier (generic)")
# Modify the score according to various other effects
score = Battle::AI::Handlers.apply_general_move_score_modifiers(
score, @move, @user, self, @battle)
score, @move, @user, self, @battle)
end
score = score.to_i
score = 0 if score < 0
@@ -307,7 +307,7 @@ class Battle::AI
PBDebug.log_score_change(score - old_score, "function code modifier (against target)")
# Modify the score according to various other effects against the target
score = Battle::AI::Handlers.apply_general_move_against_target_score_modifiers(
score, @move, @user, @target, self, @battle)
score, @move, @user, @target, self, @battle)
end
# Add the score against the target to the overall score
target_data = @move.pbTarget(@user.battler)

View File

@@ -232,15 +232,14 @@ class Battle::AI
target_speed = target.rough_stat(:SPEED)
each_foe_battler(target.side) do |b, i|
b_speed = b.rough_stat(:SPEED)
next if b_speed <= target_speed # Target already outspeeds the foe b
next if b_speed > target_speed * 2.5 # Much too slow to reasonably catch up
if b_speed > target_speed
if b_speed < target_speed * (increment + 2) / 2
score += 15 * inc_mult # Target will become faster than b
else
score += 8 * inc_mult
end
break
if b_speed < target_speed * (increment + 2) / 2
score += 15 * inc_mult # Target will become faster than the foe b
else
score += 8 * inc_mult
end
break
end
# Prefer if the target has Electro Ball or Power Trip/Stored Power
moves_that_prefer_high_speed = [
@@ -524,15 +523,14 @@ class Battle::AI
target_speed = target.rough_stat(:SPEED)
each_foe_battler(target.side) do |b, i|
b_speed = b.rough_stat(:SPEED)
next if target_speed < b_speed # Target is already slower than foe b
next if target_speed > b_speed * 2.5 # Much too fast to reasonably be overtaken
if target_speed > b_speed
if target_speed < b_speed * 2 / (decrement + 2)
score += 15 * dec_mult # Target will become slower than b
else
score += 8 * dec_mult
end
break
if target_speed < b_speed * 2 / (decrement + 2)
score += 15 * dec_mult # Target will become slower than foe b
else
score += 8 * dec_mult
end
break
end
# Prefer if any ally has Electro Ball
each_foe_battler(target.side) do |b, i|

View File

@@ -489,7 +489,7 @@ Battle::AI::Handlers::GeneralMoveAgainstTargetScore.add(:damaging_a_biding_targe
hits_possible = target.effects[PBEffects::Bide] - 1
eor_dmg *= hits_possible
hits_possible += 1 if user.faster_than?(target)
next score if dmg * hits_possible + eor_dmg > target.hp * 1.1
next score if (dmg * hits_possible) + eor_dmg > target.hp * 1.1
end
old_score = score
score -= 20

View File

@@ -189,7 +189,7 @@ class Battle::AI
# Type power boosters
:BLACKBELT, :BLACKGLASSES, :CHARCOAL, :DRAGONFANG, :HARDSTONE,
:MAGNET, :METALCOAT, :MIRACLESEED, :MYSTICWATER, :NEVERMELTICE,
:POISONBARB, :SHARPBEAK, :SILKSCARF,:SILVERPOWDER, :SOFTSAND,
:POISONBARB, :SHARPBEAK, :SILKSCARF, :SILVERPOWDER, :SOFTSAND,
:SPELLTAG, :TWISTEDSPOON,
:ODDINCENSE, :ROCKINCENSE, :ROSEINCENSE, :SEAINCENSE, :WAVEINCENSE,
# Plates
@@ -218,8 +218,7 @@ class Battle::AI
:BUGMEMORY, :DARKMEMORY, :DRAGONMEMORY, :ELECTRICMEMORY,
:FAIRYMEMORY, :FIGHTINGMEMORY, :FIREMEMORY, :FLYINGMEMORY,
:GHOSTMEMORY, :GRASSMEMORY, :GROUNDMEMORY, :ICEMEMORY, :POISONMEMORY,
:PSYCHICMEMORY, :ROCKMEMORY, :STEELMEMORY, :WATERMEMORY
],
:PSYCHICMEMORY, :ROCKMEMORY, :STEELMEMORY, :WATERMEMORY],
0 => [:SMOKEBALL],
-5 => [:FULLINCENSE, :LAGGINGTAIL, :RINGTARGET],
-6 => [:MACHOBRACE, :POWERANKLET, :POWERBAND, :POWERBELT, :POWERBRACER,
@@ -852,7 +851,7 @@ Battle::AI::Handlers::ItemRanking.addIf(:type_boosting_items,
:PSYCHIC => [:TWISTEDSPOON, :MINDPLATE, :ODDINCENSE],
:ROCK => [:HARDSTONE, :STONEPLATE, :ROCKINCENSE],
:STEEL => [:METALCOAT, :IRONPLATE],
:WATER => [:MYSTICWATER, :SPLASHPLATE, :SEAINCENSE, :WAVEINCENSE],
:WATER => [:MYSTICWATER, :SPLASHPLATE, :SEAINCENSE, :WAVEINCENSE]
}
boosted_type = nil
boosters.each_pair do |type, items|
@@ -891,7 +890,7 @@ Battle::AI::Handlers::ItemRanking.addIf(:gems,
:PSYCHICGEM => :PSYCHIC,
:ROCKGEM => :ROCK,
:STEELGEM => :STEEL,
:WATERGEM => :WATER,
:WATERGEM => :WATER
}[item]
next score if boosted_type && battler.has_damaging_move_of_type?(boosted_type)
next 0

View File

@@ -238,14 +238,15 @@ class Battle::AI::AIMove
end
# Mud Sport and Water Sport
if @ai.trainer.medium_skill?
if calc_type == :ELECTRIC
case calc_type
when :ELECTRIC
if @ai.battle.allBattlers.any? { |b| b.effects[PBEffects::MudSport] }
multipliers[:power_multiplier] /= 3
end
if @ai.battle.field.effects[PBEffects::MudSportField] > 0
multipliers[:power_multiplier] /= 3
end
elsif calc_type == :FIRE
when :FIRE
if @ai.battle.allBattlers.any? { |b| b.effects[PBEffects::WaterSport] }
multipliers[:power_multiplier] /= 3
end