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

@@ -530,7 +530,7 @@ class Battle
return 2 if counts[0] < counts[1] # Loss (foe has more able Pokémon)
return 1 if hpTotals[0] > hpTotals[1] # Win (player has more HP in total)
return 2 if hpTotals[0] < hpTotals[1] # Loss (foe has more HP in total)
return 5 # Draw
return 5 # Draw
end
# Unused
@@ -549,10 +549,10 @@ class Battle
return 2 if counts[0] < counts[1] # Loss (foe has more able Pokémon)
return 1 if hpTotals[0] > hpTotals[1] # Win (player has a bigger average HP %)
return 2 if hpTotals[0] < hpTotals[1] # Loss (foe has a bigger average HP %)
return 5 # Draw
return 5 # Draw
end
def pbDecisionOnDraw; return 5; end # Draw
def pbDecisionOnDraw; return 5; end # Draw
def pbJudge
fainted1 = pbAllFainted?(0)

View File

@@ -126,7 +126,7 @@ class Battle
if Settings::SCALED_EXP_FORMULA
exp /= 5
levelAdjust = ((2 * level) + 10.0) / (pkmn.level + level + 10.0)
levelAdjust = levelAdjust**5
levelAdjust **= 5
levelAdjust = Math.sqrt(levelAdjust)
exp *= levelAdjust
exp = exp.floor

View File

@@ -145,7 +145,8 @@ class Battle::Move
def nonLethal?(_user, _target); return false; end # For False Swipe
def preventsBattlerConsumingHealingBerry?(battler, targets); return false; end # For Bug Bite/Pluck
def ignoresSubstitute?(user) # user is the Pokémon using this move
# user is the Pokémon using this move.
def ignoresSubstitute?(user)
if Settings::MECHANICS_GENERATION >= 6
return true if soundMove?
return true if user&.hasActiveAbility?(:INFILTRATOR)

View File

@@ -318,7 +318,8 @@ class Battle::Move::TwoTurnMove < Battle::Move
return !@damagingTurn # Deliberately not "return @chargingTurn"
end
def pbDamagingMove? # Stops damage being dealt in the first (charging) turn
# Stops damage being dealt in the first (charging) turn.
def pbDamagingMove?
return false if !@damagingTurn
return super
end

View File

@@ -604,7 +604,8 @@ end
class Battle::Move::AttackTwoTurnsLater < Battle::Move
def targetsPosition?; return true; end
def pbDamagingMove? # Stops damage being dealt in the setting-up turn
# Stops damage being dealt in the setting-up turn.
def pbDamagingMove?
return false if !@battle.futureSight
return super
end

View File

@@ -606,7 +606,8 @@ class Battle::Move::MultiTurnAttackBideThenReturnDoubleDamage < Battle::Move::Fi
end
end
def pbDamagingMove? # Stops damage being dealt in the charging turns
# Stops damage being dealt in the charging turns.
def pbDamagingMove?
return false if !@damagingTurn
return super
end

View File

@@ -6,7 +6,7 @@ class Battle::Scene::PokemonDataBox < Sprite
attr_accessor :selected
# Time in seconds to fully fill the Exp bar (from empty).
EXP_BAR_FILL_TIME = 1.75
EXP_BAR_FILL_TIME = 1.75
# Time in seconds for this data box to flash when the Exp fully fills.
EXP_FULL_FLASH_DURATION = 0.2
# Maximum time in seconds to make a change to the HP bar.

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

View File

@@ -635,7 +635,7 @@ Battle::AI::Handlers::MoveEffectAgainstTargetScore.add("RaiseTargetAttack2Confus
score = ai.get_score_for_target_stat_raise(score, target, [:ATTACK, 2], false)
# Score for confusing the target
next Battle::AI::Handlers.apply_move_effect_against_target_score(
"ConfuseTarget", score, move, user, target, ai, battle)
"ConfuseTarget", score, move, user, target, ai, battle)
}
)
@@ -657,7 +657,7 @@ Battle::AI::Handlers::MoveEffectAgainstTargetScore.add("RaiseTargetSpAtk1Confuse
score = ai.get_score_for_target_stat_raise(score, target, [:SPECIAL_ATTACK, 1], false)
# Score for confusing the target
next Battle::AI::Handlers.apply_move_effect_against_target_score(
"ConfuseTarget", score, move, user, target, ai, battle)
"ConfuseTarget", score, move, user, target, ai, battle)
}
)

View File

@@ -463,7 +463,7 @@ Battle::AI::Handlers::MoveEffectScore.add("EnsureNextCriticalHit",
next Battle::AI::MOVE_USELESS_SCORE
end
# Prefer if user knows a damaging move which won't definitely critical hit
if user.check_for_move { |m| m.damagingMove? && m.function_code != "AlwaysCriticalHit"}
if user.check_for_move { |m| m.damagingMove? && m.function_code != "AlwaysCriticalHit" }
score += 15
end
next score
@@ -860,7 +860,7 @@ Battle::AI::Handlers::MoveEffectScore.add("ProtectUserFromDamagingMovesKingsShie
# Prefer if the foe's Attack can be lowered by this move
if b.battler.affectedByContactEffect? && b.check_for_move { |m| m.contactMove? }
drop_score = ai.get_score_for_target_stat_drop(
0, b, [:ATTACK, (Settings::MECHANICS_GENERATION >= 8) ? 1 : 2], false)
0, b, [:ATTACK, (Settings::MECHANICS_GENERATION >= 8) ? 1 : 2], false)
score += drop_score / 2 # Halved because we don't know what move b will use
end
# Prefer if the foe is in the middle of using a two turn attack

View File

@@ -387,7 +387,7 @@ Battle::AI::Handlers::MoveFailureAgainstTargetCheck.add("StartDamageTargetEachTu
Battle::AI::Handlers::MoveEffectAgainstTargetScore.add("StartDamageTargetEachTurnIfTargetAsleep",
proc { |score, move, user, target, ai, battle|
next Battle::AI::MOVE_USELESS_SCORE if target.statusCount <= 1
next score + 8 * target.statusCount
next score + (8 * target.statusCount)
}
)

View File

@@ -835,7 +835,7 @@ Battle::AI::Handlers::MoveEffectAgainstTargetScore.add("DisableTargetHealingMove
)
#===============================================================================
#.
#
#===============================================================================
Battle::AI::Handlers::MoveEffectAgainstTargetScore.add("DisableTargetSoundMoves",
proc { |score, move, user, target, ai, battle|

View File

@@ -185,7 +185,8 @@ class RPG::Animation
self.timings.push(timing)
end
def addAnimation(otherAnim, frame, x, y) # frame is zero-based
# frame is zero-based.
def addAnimation(otherAnim, frame, x, y)
if frame + otherAnim.frames.length >= self.frames.length
totalframes = frame + otherAnim.frames.length + 1
(totalframes - self.frames.length).times do