Fixed error in Powder's backfire message, fixed move disruption affecting recharge moves when it shouldn't, fixed error when Shell Side Arm has no targets, fixed AI not unregistering Mega Evolution if it won't do so after all

This commit is contained in:
Maruno17
2023-06-19 23:55:49 +01:00
parent 539bc0fb50
commit 17e8be9dca
8 changed files with 70 additions and 54 deletions

View File

@@ -89,7 +89,7 @@ class Battle::Battler
@effects[PBEffects::Outrage] = 0 @effects[PBEffects::Outrage] = 0
@effects[PBEffects::Uproar] = 0 @effects[PBEffects::Uproar] = 0
@effects[PBEffects::Bide] = 0 @effects[PBEffects::Bide] = 0
@currentMove = nil @currentMove = nil if @effects[PBEffects::HyperBeam] == 0
# Reset counters for moves which increase them when used in succession # Reset counters for moves which increase them when used in succession
@effects[PBEffects::FuryCutter] = 0 @effects[PBEffects::FuryCutter] = 0
end end
@@ -314,7 +314,7 @@ class Battle::Battler
user.lastMoveFailed = true user.lastMoveFailed = true
if ![:Rain, :HeavyRain].include?(user.effectiveWeather) && user.takesIndirectDamage? if ![:Rain, :HeavyRain].include?(user.effectiveWeather) && user.takesIndirectDamage?
user.pbTakeEffectDamage((user.totalhp / 4.0).round, false) do |hp_lost| user.pbTakeEffectDamage((user.totalhp / 4.0).round, false) do |hp_lost|
@battle.pbDisplay(_INTL("{1} is hurt by its {2}!", battler.pbThis, battler.itemName)) @battle.pbDisplay(_INTL("{1} is hurt by Powder!", user.pbThis))
end end
@battle.pbGainExp # In case user is KO'd by this @battle.pbGainExp # In case user is KO'd by this
end end

View File

@@ -1121,6 +1121,7 @@ class Battle::Move::CategoryDependsOnHigherDamagePoisonTarget < Battle::Move::Po
def pbOnStartUse(user, targets) def pbOnStartUse(user, targets)
target = targets[0] target = targets[0]
return if !target
max_stage = Battle::Battler::STAT_STAGE_MAXIMUM max_stage = Battle::Battler::STAT_STAGE_MAXIMUM
stageMul = Battle::Battler::STAT_STAGE_MULTIPLIERS stageMul = Battle::Battler::STAT_STAGE_MULTIPLIERS
stageDiv = Battle::Battler::STAT_STAGE_DIVISORS stageDiv = Battle::Battler::STAT_STAGE_DIVISORS

View File

@@ -345,16 +345,16 @@ Battle::AI::Handlers::ShouldSwitch.add(:yawning,
end end
trapping = false trapping = false
ai.each_foe_battler(battler.side) do |b, i| ai.each_foe_battler(battler.side) do |b, i|
next if b.ability_active? && Battle::AbilityEffects.triggerCertainSwitching(b.ability, b, battle) next if b.ability_active? && Battle::AbilityEffects.triggerCertainSwitching(b.ability, b.battler, battle)
next if b.item_active? && Battle::ItemEffects.triggerCertainSwitching(b.item, b, battle) next if b.item_active? && Battle::ItemEffects.triggerCertainSwitching(b.item, b.battler, battle)
next if Settings::MORE_TYPE_EFFECTS && b.has_type?(:GHOST) next if Settings::MORE_TYPE_EFFECTS && b.has_type?(:GHOST)
next if b.battler.trappedInBattle? # Relevant trapping effects are checked above next if b.battler.trappedInBattle? # Relevant trapping effects are checked above
if battler.ability_active? if battler.ability_active?
trapping = Battle::AbilityEffects.triggerTrappingByTarget(battler.ability, b, battler.battler, battle) trapping = Battle::AbilityEffects.triggerTrappingByTarget(battler.ability, b.battler, battler.battler, battle)
break if trapping break if trapping
end end
if battler.item_active? if battler.item_active?
trapping = Battle::ItemEffects.triggerTrappingByTarget(battler.item, b, battler.battler, battle) trapping = Battle::ItemEffects.triggerTrappingByTarget(battler.item, b.battler, battler.battler, battle)
break if trapping break if trapping
end end
end end
@@ -390,16 +390,16 @@ Battle::AI::Handlers::ShouldSwitch.add(:asleep,
end end
trapping = false trapping = false
ai.each_foe_battler(battler.side) do |b, i| ai.each_foe_battler(battler.side) do |b, i|
next if b.ability_active? && Battle::AbilityEffects.triggerCertainSwitching(b.ability, b, battle) next if b.ability_active? && Battle::AbilityEffects.triggerCertainSwitching(b.ability, b.battler, battle)
next if b.item_active? && Battle::ItemEffects.triggerCertainSwitching(b.item, b, battle) next if b.item_active? && Battle::ItemEffects.triggerCertainSwitching(b.item, b.battler, battle)
next if Settings::MORE_TYPE_EFFECTS && b.has_type?(:GHOST) next if Settings::MORE_TYPE_EFFECTS && b.has_type?(:GHOST)
next if b.battler.trappedInBattle? # Relevant trapping effects are checked above next if b.battler.trappedInBattle? # Relevant trapping effects are checked above
if battler.ability_active? if battler.ability_active?
trapping = Battle::AbilityEffects.triggerTrappingByTarget(battler.ability, b, battler.battler, battle) trapping = Battle::AbilityEffects.triggerTrappingByTarget(battler.ability, b.battler, battler.battler, battle)
break if trapping break if trapping
end end
if battler.item_active? if battler.item_active?
trapping = Battle::ItemEffects.triggerTrappingByTarget(battler.item, b, battler.battler, battle) trapping = Battle::ItemEffects.triggerTrappingByTarget(battler.item, b.battler, battler.battler, battle)
break if trapping break if trapping
end end
end end

View File

@@ -22,25 +22,7 @@ class Battle::AI
# against it. # against it.
def pbGetMoveScores def pbGetMoveScores
choices = [] choices = []
# TODO: Delete this after testing AI.
if $tested_abilities && @user.ability_id
$tested_abilities[@user.ability_id] ||= 0
$tested_abilities[@user.ability_id] += 1
end
if $tested_items && @user.item_id
$tested_items[@user.item_id] ||= 0
$tested_items[@user.item_id] += 1
end
@user.battler.eachMoveWithIndex do |orig_move, idxMove| @user.battler.eachMoveWithIndex do |orig_move, idxMove|
# TODO: Delete this after testing AI.
if $tested_moves
$tested_moves[orig_move.id] ||= 0
$tested_moves[orig_move.id] += 1
end
# Unchoosable moves aren't considered # Unchoosable moves aren't considered
if !@battle.pbCanChooseMove?(@user.index, idxMove, false) if !@battle.pbCanChooseMove?(@user.index, idxMove, false)
if orig_move.pp == 0 && orig_move.total_pp > 0 if orig_move.pp == 0 && orig_move.total_pp > 0
@@ -366,7 +348,10 @@ class Battle::AI
end end
if badMoves if badMoves
PBDebug.log_ai("#{@user.name} wants to switch due to terrible moves") PBDebug.log_ai("#{@user.name} wants to switch due to terrible moves")
return if pbChooseToSwitchOut(true) if pbChooseToSwitchOut(true)
@battle.pbUnregisterMegaEvolution(@user.index)
return
end
PBDebug.log_ai("#{@user.name} won't switch after all") PBDebug.log_ai("#{@user.name} won't switch after all")
end end
end end

View File

@@ -271,7 +271,6 @@ module RPG
def update_sprite_position(sprite, index, is_new_sprite = false) def update_sprite_position(sprite, index, is_new_sprite = false)
return if !sprite || !sprite.bitmap || !sprite.visible return if !sprite || !sprite.bitmap || !sprite.visible
# TODO: FPS.
delta_t = Graphics.delta delta_t = Graphics.delta
lifetimes = (is_new_sprite) ? @new_sprite_lifetimes : @sprite_lifetimes lifetimes = (is_new_sprite) ? @new_sprite_lifetimes : @sprite_lifetimes
if lifetimes[index] >= 0 if lifetimes[index] >= 0
@@ -287,7 +286,6 @@ module RPG
if @weatherTypes[weather_type][0].category == :Rain && index.odd? # Splash if @weatherTypes[weather_type][0].category == :Rain && index.odd? # Splash
sprite.opacity = (lifetimes[index] < 0.2) ? 255 : 0 # 0.2 seconds sprite.opacity = (lifetimes[index] < 0.2) ? 255 : 0 # 0.2 seconds
else else
# TODO: FPS.
dist_x = @weatherTypes[weather_type][0].particle_delta_x * delta_t dist_x = @weatherTypes[weather_type][0].particle_delta_x * delta_t
dist_y = @weatherTypes[weather_type][0].particle_delta_y * delta_t dist_y = @weatherTypes[weather_type][0].particle_delta_y * delta_t
sprite.x += dist_x sprite.x += dist_x
@@ -301,7 +299,6 @@ module RPG
sprite.x += Graphics.width if sprite.x - @ox < -sprite.width sprite.x += Graphics.width if sprite.x - @ox < -sprite.width
sprite.y -= Graphics.height if sprite.y - @oy > Graphics.height sprite.y -= Graphics.height if sprite.y - @oy > Graphics.height
sprite.y += Graphics.height if sprite.y - @oy < -sprite.height sprite.y += Graphics.height if sprite.y - @oy < -sprite.height
# TODO: FPS.
sprite.opacity += @weatherTypes[weather_type][0].particle_delta_opacity * delta_t sprite.opacity += @weatherTypes[weather_type][0].particle_delta_opacity * delta_t
x = sprite.x - @ox x = sprite.x - @ox
y = sprite.y - @oy y = sprite.y - @oy
@@ -313,13 +310,11 @@ module RPG
end end
def recalculate_tile_positions def recalculate_tile_positions
# TODO: FPS.
delta_t = Graphics.delta delta_t = Graphics.delta
weather_type = @type weather_type = @type
if @fading && @fade_time >= [FADE_OLD_TONE_END - @time_shift, 0].max if @fading && @fade_time >= [FADE_OLD_TONE_END - @time_shift, 0].max
weather_type = @target_type weather_type = @target_type
end end
# TODO: FPS.
@tile_x += @weatherTypes[weather_type][0].tile_delta_x * delta_t @tile_x += @weatherTypes[weather_type][0].tile_delta_x * delta_t
@tile_y += @weatherTypes[weather_type][0].tile_delta_y * delta_t @tile_y += @weatherTypes[weather_type][0].tile_delta_y * delta_t
while @tile_x < @ox - @weatherTypes[weather_type][2][0].width while @tile_x < @ox - @weatherTypes[weather_type][2][0].width
@@ -416,7 +411,6 @@ module RPG
@sun_magnitude = weather_max if @sun_magnitude != weather_max && @sun_magnitude != -weather_max @sun_magnitude = weather_max if @sun_magnitude != weather_max && @sun_magnitude != -weather_max
@sun_magnitude *= -1 if (@sun_magnitude > 0 && @sun_strength > @sun_magnitude) || @sun_magnitude *= -1 if (@sun_magnitude > 0 && @sun_strength > @sun_magnitude) ||
(@sun_magnitude < 0 && @sun_strength < 0) (@sun_magnitude < 0 && @sun_strength < 0)
# TODO: FPS.
@sun_strength += @sun_magnitude.to_f * Graphics.delta / 0.4 # 0.4 seconds per half flash @sun_strength += @sun_magnitude.to_f * Graphics.delta / 0.4 # 0.4 seconds per half flash
tone_red += @sun_strength tone_red += @sun_strength
tone_green += @sun_strength tone_green += @sun_strength
@@ -430,7 +424,6 @@ module RPG
def update_fading def update_fading
return if !@fading return if !@fading
old_fade_time = @fade_time old_fade_time = @fade_time
# TODO: FPS.
@fade_time += Graphics.delta @fade_time += Graphics.delta
# Change tile bitmaps # Change tile bitmaps
if @type != @target_type if @type != @target_type
@@ -489,7 +482,6 @@ module RPG
update_screen_tone update_screen_tone
# Storm flashes # Storm flashes
if @type == :Storm && !@fading if @type == :Storm && !@fading
# TODO: FPS.
if @time_until_flash > 0 if @time_until_flash > 0
@time_until_flash -= Graphics.delta @time_until_flash -= Graphics.delta
if @time_until_flash <= 0 if @time_until_flash <= 0

View File

@@ -574,7 +574,6 @@ EventHandlers.add(:on_frame_update, :phone_call_counter,
if $PokemonGlobal.phone.time_to_next_call <= 0 if $PokemonGlobal.phone.time_to_next_call <= 0
$PokemonGlobal.phone.time_to_next_call = rand(20...40) * 60.0 # 20-40 minutes $PokemonGlobal.phone.time_to_next_call = rand(20...40) * 60.0 # 20-40 minutes
end end
# TODO: FPS. Can probably leave this alone.
$PokemonGlobal.phone.time_to_next_call -= Graphics.delta $PokemonGlobal.phone.time_to_next_call -= Graphics.delta
next if $PokemonGlobal.phone.time_to_next_call > 0 next if $PokemonGlobal.phone.time_to_next_call > 0
# Time for a random phone call; generate one # Time for a random phone call; generate one

View File

@@ -491,7 +491,6 @@ class MapScreenScene
end end
end end
end end
# TODO: FPS. Scroll speed with arrow keys. Can probably leave this alone.
if Input.press?(Input::UP) if Input.press?(Input::UP)
@mapsprites.each do |i| @mapsprites.each do |i|
i[1].y += 4 if i i[1].y += 4 if i

View File

@@ -1,13 +1,10 @@
# TODO: Be much more relevant with the choosing of held items. For example, # TODO: Be much more relevant with the choosing of held items. For example,
# only give a weather-boosting item to a Pokémon that can create the # only give a weather-boosting item to a Pokémon that can create the
# corresponding weather. # corresponding weather.
# TODO: Add alternate forms, which will give access to more abilities. Note that
# some alternate forms require fusion or specific held items or other
# things.
AI_MOVE_TESTING_THRESHOLD = 500 AI_MOVE_TESTING_THRESHOLD = 1500
AI_ABILITY_TESTING_THRESHOLD = 100 AI_ABILITY_TESTING_THRESHOLD = 500
AI_ITEM_TESTING_THRESHOLD = 100 AI_ITEM_TESTING_THRESHOLD = 500
#=============================================================================== #===============================================================================
# #
@@ -89,6 +86,31 @@ MEGA_STONES = [
:GALLADITE, :AUDINITE, :DIANCITE :GALLADITE, :AUDINITE, :DIANCITE
] ]
#===============================================================================
#
#===============================================================================
class Battle::AI
alias _ai_testing__pbGetMoveScores pbGetMoveScores
def pbGetMoveScores
if $tested_abilities && @user.ability_id
$tested_abilities[@user.ability_id] ||= 0
$tested_abilities[@user.ability_id] += 1
end
if $tested_items && @user.item_id
$tested_items[@user.item_id] ||= 0
$tested_items[@user.item_id] += 1
end
@user.battler.eachMoveWithIndex do |orig_move, idxMove|
if $tested_moves
$tested_moves[orig_move.id] ||= 0
$tested_moves[orig_move.id] += 1
end
end
return _ai_testing__pbGetMoveScores
end
end
#=============================================================================== #===============================================================================
# #
#=============================================================================== #===============================================================================
@@ -125,10 +147,23 @@ def debug_set_up_trainer
this_species = valid_species.sample this_species = valid_species.sample
this_level = 100 # rand(1, Settings::MAXIMUM_LEVEL) this_level = 100 # rand(1, Settings::MAXIMUM_LEVEL)
pkmn = Pokemon.new(this_species, this_level, trainer, false) pkmn = Pokemon.new(this_species, this_level, trainer, false)
# Set form for certain species
case pkmn.species
when :GRENINJA, :SLOWKING, :GEODUDE, :GRAVELER, :GOLEM, :PONYTA, :RAPIDASH,
:GRIMER, :MUK, :SLOWBRO, :RAICHU, :DIGLETT, :DUGTRIO, :STUNFISK
pkmn.form_simple = 1
when :DARMANITAN
pkmn.form_simple = 2
when :CALYREX
pkmn.form_simple = [1, 2].sample # So we test both versions of As One
when :NECROZMA
pkmn.form_simple = 3 # Ultra form
end
# Generate moveset for pkmn (from level-up moves first, then from tutor # Generate moveset for pkmn (from level-up moves first, then from tutor
# moves + egg moves, then from all moves) # moves + egg moves, then from all moves)
all_moves = pkmn.getMoveList.map { |m| m[1] } all_moves = pkmn.getMoveList.map { |m| m[1] }
all_moves.uniq! all_moves.uniq!
if !$shown_all_moves_tested_message
all_moves.reject! { |m| $tested_moves[m] && $tested_moves[m] > AI_MOVE_TESTING_THRESHOLD } all_moves.reject! { |m| $tested_moves[m] && $tested_moves[m] > AI_MOVE_TESTING_THRESHOLD }
if all_moves.length == 0 if all_moves.length == 0
all_moves = pkmn.species_data.tutor_moves.clone + pkmn.species_data.get_egg_moves.clone all_moves = pkmn.species_data.tutor_moves.clone + pkmn.species_data.get_egg_moves.clone
@@ -142,6 +177,7 @@ def debug_set_up_trainer
echoln "All moves have been tested at least #{AI_MOVE_TESTING_THRESHOLD} times!" echoln "All moves have been tested at least #{AI_MOVE_TESTING_THRESHOLD} times!"
$shown_all_moves_tested_message = true $shown_all_moves_tested_message = true
end end
end
moves = all_moves.sample(4) moves = all_moves.sample(4)
moves.each { |m| pkmn.learn_move(m) } moves.each { |m| pkmn.learn_move(m) }
# Generate held item for pkmn (compatible Mega Stone first, then compatible # Generate held item for pkmn (compatible Mega Stone first, then compatible
@@ -174,7 +210,11 @@ def debug_set_up_trainer
if $tested_abilities[abil] && $tested_abilities[abil] > AI_ABILITY_TESTING_THRESHOLD if $tested_abilities[abil] && $tested_abilities[abil] > AI_ABILITY_TESTING_THRESHOLD
abils = pkmn.getAbilityList abils = pkmn.getAbilityList
abils.reject! { |a| $tested_abilities[a[0]] && $tested_abilities[a[0]] > AI_ABILITY_TESTING_THRESHOLD } abils.reject! { |a| $tested_abilities[a[0]] && $tested_abilities[a[0]] > AI_ABILITY_TESTING_THRESHOLD }
pkmn.ability_index = abils.sample[1] if abils.length > 0 if abils.length > 0
pkmn.ability_index = abils.sample[1]
else
pkmn.ability = GameData::Ability.keys.sample
end
end end
trainer.party.push(pkmn) trainer.party.push(pkmn)
pokemon_array.push(pkmn) pokemon_array.push(pkmn)