diff --git a/.gitignore b/.gitignore index ca65433d..ab1bd6b2 100644 --- a/.gitignore +++ b/.gitignore @@ -2,6 +2,7 @@ Audio/ Graphics/ Plugins/ +Screenshots/ # Data folder, but not Data/Scripts folder or messages_core.dat Data/* diff --git a/Data/Scripts/011_Battle/001_Battle/006_Battle_ActionUseItem.rb b/Data/Scripts/011_Battle/001_Battle/006_Battle_ActionUseItem.rb index 71bf5718..9fafeea8 100644 --- a/Data/Scripts/011_Battle/001_Battle/006_Battle_ActionUseItem.rb +++ b/Data/Scripts/011_Battle/001_Battle/006_Battle_ActionUseItem.rb @@ -55,7 +55,7 @@ class Battle end else items = pbGetOwnerItems(idxBattler) - items.delete_at(items.index(item)) + items.delete_at(items.index(item)) if items end end diff --git a/Data/Scripts/011_Battle/001_Battle/008_Battle_ActionOther.rb b/Data/Scripts/011_Battle/001_Battle/008_Battle_ActionOther.rb index f6fe0b96..f1bb5c0f 100644 --- a/Data/Scripts/011_Battle/001_Battle/008_Battle_ActionOther.rb +++ b/Data/Scripts/011_Battle/001_Battle/008_Battle_ActionOther.rb @@ -81,7 +81,9 @@ class Battle @mega_rings.each { |item| return GameData::Item.get(item).name if $bag.has?(item) } else trainer_items = pbGetOwnerItems(idxBattler) - @mega_rings.each { |item| return GameData::Item.get(item).name if trainer_items&.include?(item) } + if trainer_items + @mega_rings.each { |item| return GameData::Item.get(item).name if trainer_items.include?(item) } + end end end return _INTL("Mega Ring") diff --git a/Data/Scripts/011_Battle/005_AI/002_AI_Switch.rb b/Data/Scripts/011_Battle/005_AI/002_AI_Switch.rb index 3867794b..7df74a9e 100644 --- a/Data/Scripts/011_Battle/005_AI/002_AI_Switch.rb +++ b/Data/Scripts/011_Battle/005_AI/002_AI_Switch.rb @@ -633,6 +633,7 @@ Battle::AI::Handlers::ShouldNotSwitch.add(:lethal_entry_hazards, Battle::AI::Handlers::ShouldNotSwitch.add(:battler_has_super_effective_move, proc { |battler, reserves, ai, battle| next false if battler.effects[PBEffects::PerishSong] == 1 + next false if battler.rough_end_of_round_damage >= battler.hp * 2 / 3 next false if battle.rules["suddendeath"] has_super_effective_move = false battler.battler.eachMove do |move| @@ -676,3 +677,29 @@ Battle::AI::Handlers::ShouldNotSwitch.add(:battler_has_very_raised_stats, next false } ) + +#=============================================================================== +# Don't bother switching if the battler has Wonder Guard and is immune to the +# foe's damaging attacks. +#=============================================================================== +Battle::AI::Handlers::ShouldNotSwitch.add(:battler_is_immune_via_wonder_guard, + proc { |battler, reserves, ai, battle| + next false if battler.effects[PBEffects::PerishSong] == 1 + next false if battler.rough_end_of_round_damage >= battler.hp / 2 + next false if !battler.has_active_ability?(:WONDERGUARD) + super_effective_foe = false + ai.each_foe_battler(battler.side) do |b| + next if !b.check_for_move do |m| + next false if !m.damagingMove? + eff = battler.effectiveness_of_type_against_battler(m.pbCalcType(b.battler), b, m) + next Effectiveness.super_effective?(eff) + end + super_effective_foe = true + break + end + if !super_effective_foe + PBDebug.log_ai("#{battler.name} won't switch after all because it has Wonder Guard and can't be damaged by foes") + end + next !super_effective_foe + } +) diff --git a/Data/Scripts/011_Battle/006_AI MoveEffects/004_AI_MoveEffects_MoveAttributes.rb b/Data/Scripts/011_Battle/006_AI MoveEffects/004_AI_MoveEffects_MoveAttributes.rb index 3a03769a..91e0363a 100644 --- a/Data/Scripts/011_Battle/006_AI MoveEffects/004_AI_MoveEffects_MoveAttributes.rb +++ b/Data/Scripts/011_Battle/006_AI MoveEffects/004_AI_MoveEffects_MoveAttributes.rb @@ -115,7 +115,7 @@ Battle::AI::Handlers::MoveEffectAgainstTargetScore.copy("OHKO", Battle::AI::Handlers::MoveEffectAgainstTargetScore.add("DamageTargetAlly", proc { |score, move, user, target, ai, battle| target.battler.allAllies.each do |b| - next if !b.near?(target.battler) || !b.battler.takesIndirectDamage? + next if !b.near?(target.battler) || !b.takesIndirectDamage? score += 10 if ai.trainer.has_skill_flag?("HPAware") score += 10 if b.hp <= b.totalhp / 16 diff --git a/Data/Scripts/012_Overworld/002_Battle triggering/001_Overworld_BattleStarting.rb b/Data/Scripts/012_Overworld/002_Battle triggering/001_Overworld_BattleStarting.rb index 185c26b0..a0cb644f 100644 --- a/Data/Scripts/012_Overworld/002_Battle triggering/001_Overworld_BattleStarting.rb +++ b/Data/Scripts/012_Overworld/002_Battle triggering/001_Overworld_BattleStarting.rb @@ -189,7 +189,8 @@ module BattleCreationHelperMethods ally = NPCTrainer.new($PokemonGlobal.partner[1], $PokemonGlobal.partner[0]) ally.id = $PokemonGlobal.partner[2] ally.party = $PokemonGlobal.partner[3] - ally_items[1] = ally.items.clone + data = GameData::Trainer.try_get($PokemonGlobal.partner[0], $PokemonGlobal.partner[1], $PokemonGlobal.partner[2]) + ally_items[1] = data&.items.clone || [] trainer_array.push(ally) pokemon_array = [] $player.party.each { |pkmn| pokemon_array.push(pkmn) } diff --git a/README.md b/README.md index a685d154..24232ce6 100644 --- a/README.md +++ b/README.md @@ -33,10 +33,10 @@ You will need Ruby installed to run these scripts. The intention is to replace t The .gitignore file lists the files that will not be included in this repo. These are: -* The Audio/, Graphics/ and Plugins/ folders and everything in them. +* The Audio/, Graphics/, Plugins/ and Screenshots/ folders and everything in them. * Everything in the Data/ folder, except for: * The Data/Scripts/ folder and everything in there. * Scripts.rxdata (a special version that just loads the individual script files). * messages_core.dat, which contains common messages and is useful for translation projects. -* A few files in the main project folder (two of the Game.xxx files, and the RGSS dll file). +* A few files in the main project folder (two of the Game.xxx files, the RGSS dll file and errorlog.txt). * Temporary files.