From 00d1e431b4221d9d038113bad5c8071f5a49fb8d Mon Sep 17 00:00:00 2001 From: Maruno17 Date: Fri, 22 Nov 2024 00:38:20 +0000 Subject: [PATCH] Some bug fixes, added PriorityChange item handler --- .../002_MessageConfig.rb | 6 ++++ .../001_Hardcoded data/007_Evolution.rb | 2 +- .../010_Data/002_PBS data/015_Trainer.rb | 3 ++ .../004_Battle_ActionAttacksPriority.rb | 6 ++++ .../011_Battle/003_Move/002_Move_Usage.rb | 10 ++++--- Data/Scripts/011_Battle/005_AI/011_AIMove.rb | 3 ++ .../009_Battle_ItemEffects.rb | 11 ++++++++ .../005_Overworld_RoamingPokemon.rb | 2 +- .../001_Pokemon-related/001_FormHandlers.rb | 2 +- .../015_Trainers and player/001_Trainer.rb | 28 +++++++++---------- .../001_Editor screens/001_EditorScreens.rb | 2 +- 11 files changed, 53 insertions(+), 22 deletions(-) diff --git a/Data/Scripts/007_Objects and windows/002_MessageConfig.rb b/Data/Scripts/007_Objects and windows/002_MessageConfig.rb index 70f12291f..2affba22c 100644 --- a/Data/Scripts/007_Objects and windows/002_MessageConfig.rb +++ b/Data/Scripts/007_Objects and windows/002_MessageConfig.rb @@ -369,9 +369,15 @@ def get_text_colors_for_windowskin(windowskin, color, isDarkSkin) end # Special colour as listed above if isDarkSkin && color != 12 # Dark background, light text + if textcolors[2 * (color - 1)].is_a?(Color) + return textcolors[(2 * (color - 1)) + 1], textcolors[2 * (color - 1)] + end return Color.new(*textcolors[(2 * (color - 1)) + 1]), Color.new(*textcolors[2 * (color - 1)]) end # Light background, dark text + if textcolors[2 * (color - 1)].is_a?(Color) + return textcolors[2 * (color - 1)], textcolors[2 * (color - 1) + 1] + end return Color.new(*textcolors[2 * (color - 1)]), Color.new(*textcolors[(2 * (color - 1)) + 1]) end diff --git a/Data/Scripts/010_Data/001_Hardcoded data/007_Evolution.rb b/Data/Scripts/010_Data/001_Hardcoded data/007_Evolution.rb index b2726c3f3..4dfefee91 100644 --- a/Data/Scripts/010_Data/001_Hardcoded data/007_Evolution.rb +++ b/Data/Scripts/010_Data/001_Hardcoded data/007_Evolution.rb @@ -244,7 +244,7 @@ GameData::Evolution.register({ :id => :LevelDarkInParty, :parameter => Integer, :level_up_proc => proc { |pkmn, parameter| - next pkmn.level >= parameter && $player.has_pokemon_of_type?(:DARK) + next pkmn.level >= parameter && $player.has_pokemon_of_type?(:DARK, [pkmn]) } }) diff --git a/Data/Scripts/010_Data/002_PBS data/015_Trainer.rb b/Data/Scripts/010_Data/002_PBS data/015_Trainer.rb index 7b6dfeb83..d5580b4a5 100644 --- a/Data/Scripts/010_Data/002_PBS data/015_Trainer.rb +++ b/Data/Scripts/010_Data/002_PBS data/015_Trainer.rb @@ -136,6 +136,7 @@ module GameData trainer.party.push(pkmn) # Set Pokémon's properties if defined pkmn.form_simple = pkmn_data[:form] if pkmn_data[:form] + pkmn.time_form_set = pbGetTimeNow.to_i # To allow Furfrou/Hoopa alternate forms pkmn.item = pkmn_data[:item] if pkmn_data[:moves] && pkmn_data[:moves].length > 0 pkmn_data[:moves].each { |move| pkmn.learn_move(move) } @@ -180,6 +181,8 @@ module GameData elsif trainer.default_poke_ball pkmn.poke_ball = trainer.default_poke_ball end + pkmn.form # Called just to recalculate it in case a defined property has changed it, e.g. gender for Espurr + pkmn.reset_moves if !pkmn_data[:moves] || pkmn_data[:moves].empty? # In case form changed pkmn.calc_stats end return trainer diff --git a/Data/Scripts/011_Battle/001_Battle/004_Battle_ActionAttacksPriority.rb b/Data/Scripts/011_Battle/001_Battle/004_Battle_ActionAttacksPriority.rb index 2ea0188ab..1412af76f 100644 --- a/Data/Scripts/011_Battle/001_Battle/004_Battle_ActionAttacksPriority.rb +++ b/Data/Scripts/011_Battle/001_Battle/004_Battle_ActionAttacksPriority.rb @@ -162,6 +162,9 @@ class Battle if b.abilityActive? pri = Battle::AbilityEffects.triggerPriorityChange(b.ability, b, move, pri) end + if b.itemActive? + pri = Battle::ItemEffects.triggerPriorityChange(b.item, b, move, pri) + end entry[5] = pri @choices[b.index][4] = pri end @@ -199,6 +202,9 @@ class Battle if entry[0].abilityActive? pri = Battle::AbilityEffects.triggerPriorityChange(entry[0].ability, entry[0], move, pri) end + if entry[0].itemActive? + pri = Battle::ItemEffects.triggerPriorityChange(entry[0].item, entry[0], move, pri) + end needRearranging = true if pri != entry[5] entry[5] = pri choice[4] = pri diff --git a/Data/Scripts/011_Battle/003_Move/002_Move_Usage.rb b/Data/Scripts/011_Battle/003_Move/002_Move_Usage.rb index 15615ca75..d1bb0c1fe 100644 --- a/Data/Scripts/011_Battle/003_Move/002_Move_Usage.rb +++ b/Data/Scripts/011_Battle/003_Move/002_Move_Usage.rb @@ -266,10 +266,12 @@ class Battle::Move oldHP += b.damageState.hpLost end effectiveness = 0 - if Effectiveness.resistant?(b.damageState.typeMod) - effectiveness = 1 - elsif Effectiveness.super_effective?(b.damageState.typeMod) - effectiveness = 2 + if !self.is_a?(Battle::Move::FixedDamageMove) + if Effectiveness.resistant?(b.damageState.typeMod) + effectiveness = 1 + elsif Effectiveness.super_effective?(b.damageState.typeMod) + effectiveness = 2 + end end animArray.push([b, oldHP, effectiveness]) end diff --git a/Data/Scripts/011_Battle/005_AI/011_AIMove.rb b/Data/Scripts/011_Battle/005_AI/011_AIMove.rb index 06dd8d061..f80489ad6 100644 --- a/Data/Scripts/011_Battle/005_AI/011_AIMove.rb +++ b/Data/Scripts/011_Battle/005_AI/011_AIMove.rb @@ -71,6 +71,9 @@ class Battle::AI::AIMove ret = Battle::AbilityEffects.triggerPriorityChange(user.ability, user.battler, @move, ret) user.battler.effects[PBEffects::Prankster] = false # Untrigger this end + if user.item_active? + ret = Battle::ItemEffects.triggerPriorityChange(user.item, user.battler, @move, ret) + end return ret end diff --git a/Data/Scripts/011_Battle/007_Other battle code/009_Battle_ItemEffects.rb b/Data/Scripts/011_Battle/007_Other battle code/009_Battle_ItemEffects.rb index bad91f00a..69a614bce 100644 --- a/Data/Scripts/011_Battle/007_Other battle code/009_Battle_ItemEffects.rb +++ b/Data/Scripts/011_Battle/007_Other battle code/009_Battle_ItemEffects.rb @@ -12,6 +12,7 @@ module Battle::ItemEffects # Battler's stat stages StatLossImmunity = ItemHandlerHash.new # Priority and turn order + PriorityChange = ItemHandlerHash.new PriorityBracketChange = ItemHandlerHash.new PriorityBracketUse = ItemHandlerHash.new # Move usage failures @@ -91,6 +92,10 @@ module Battle::ItemEffects #----------------------------------------------------------------------------- + def self.triggerPriorityChange(item, battler, move, priority) + return trigger(PriorityChange, item, battler, move, priority, ret: priority) + end + def self.triggerPriorityBracketChange(item, battler, battle) return trigger(PriorityBracketChange, item, battler, battle, ret: 0) end @@ -647,6 +652,12 @@ Battle::ItemEffects::StatLossImmunity.add(:CLEARAMULET, } ) +#=============================================================================== +# PriorityChange handlers +#=============================================================================== + +# There aren't any! + #=============================================================================== # PriorityBracketChange handlers #=============================================================================== diff --git a/Data/Scripts/012_Overworld/002_Battle triggering/005_Overworld_RoamingPokemon.rb b/Data/Scripts/012_Overworld/002_Battle triggering/005_Overworld_RoamingPokemon.rb index e288621de..f7738fc5f 100644 --- a/Data/Scripts/012_Overworld/002_Battle triggering/005_Overworld_RoamingPokemon.rb +++ b/Data/Scripts/012_Overworld/002_Battle triggering/005_Overworld_RoamingPokemon.rb @@ -21,7 +21,7 @@ end def pbResetAllRoamers return if !$PokemonGlobal.roamPokemon $PokemonGlobal.roamPokemon.length.times do |i| - next if $PokemonGlobal.roamPokemon[i] != true || !$PokemonGlobal.roamPokemonCaught[i] + next if $PokemonGlobal.roamPokemon[i] != true || $PokemonGlobal.roamPokemonCaught[i] $PokemonGlobal.roamPokemon[i] = nil end end diff --git a/Data/Scripts/014_Pokemon/001_Pokemon-related/001_FormHandlers.rb b/Data/Scripts/014_Pokemon/001_Pokemon-related/001_FormHandlers.rb index 084ae0ad8..e40478d39 100644 --- a/Data/Scripts/014_Pokemon/001_Pokemon-related/001_FormHandlers.rb +++ b/Data/Scripts/014_Pokemon/001_Pokemon-related/001_FormHandlers.rb @@ -891,7 +891,7 @@ MultipleForms.register(:QUILAVA, { }) MultipleForms.copy(:QUILAVA, - :DEWOTT, :PETILILL, :RUFFLET, :GOOMY, :BERGMITE, :DARTRIX) + :DEWOTT, :PETILIL, :RUFFLET, :GOOMY, :BERGMITE, :DARTRIX) # Paldean forms # None! diff --git a/Data/Scripts/015_Trainers and player/001_Trainer.rb b/Data/Scripts/015_Trainers and player/001_Trainer.rb index a83d30d1a..47f8900dc 100644 --- a/Data/Scripts/015_Trainers and player/001_Trainer.rb +++ b/Data/Scripts/015_Trainers and player/001_Trainer.rb @@ -10,7 +10,7 @@ class Trainer def inspect str = super.chop - party_str = @party.map { |p| p.species_data.species }.inspect + party_str = @party.map { |pkmn| pkmn.species_data.species }.inspect str << sprintf(" %s @party=%s>", self.full_name, party_str) return str end @@ -56,11 +56,11 @@ class Trainer #----------------------------------------------------------------------------- def pokemon_party - return @party.find_all { |p| p && !p.egg? } + return @party.find_all { |pkmn| pkmn && !pkmn.egg? } end def able_party - return @party.find_all { |p| p && !p.egg? && !p.fainted? } + return @party.find_all { |pkmn| pkmn && !pkmn.egg? && !pkmn.fainted? } end def party_count @@ -69,13 +69,13 @@ class Trainer def pokemon_count ret = 0 - @party.each { |p| ret += 1 if p && !p.egg? } + @party.each { |pkmn| ret += 1 if pkmn && !pkmn.egg? } return ret end def able_pokemon_count ret = 0 - @party.each { |p| ret += 1 if p && !p.egg? && !p.fainted? } + @party.each { |pkmn| ret += 1 if pkmn && !pkmn.egg? && !pkmn.fainted? } return ret end @@ -105,13 +105,13 @@ class Trainer end def last_pokemon - p = pokemon_party - return (p.length > 0) ? p[p.length - 1] : nil + pkmn = pokemon_party + return (pkmn.length > 0) ? pkmn[pkmn.length - 1] : nil end def last_able_pokemon - p = able_party - return (p.length > 0) ? p[p.length - 1] : nil + pkmn = able_party + return (pkmn.length > 0) ? pkmn[pkmn.length - 1] : nil end def remove_pokemon_at_index(index) @@ -136,21 +136,21 @@ class Trainer # Returns true if there is a Pokémon of the given species in the trainer's # party. You may also specify a particular form it should be. def has_species?(species, form = -1) - return pokemon_party.any? { |p| p&.isSpecies?(species) && (form < 0 || p.form == form) } + return pokemon_party.any? { |pkmn| pkmn&.isSpecies?(species) && (form < 0 || pkmn.form == form) } end # Returns whether there is a fatefully met Pokémon of the given species in the # trainer's party. def has_fateful_species?(species) - return pokemon_party.any? { |p| p&.isSpecies?(species) && p.obtain_method == 4 } + return pokemon_party.any? { |pkmn| pkmn&.isSpecies?(species) && pkmn.obtain_method == 4 } end # Returns whether there is a Pokémon with the given type in the trainer's - # party. - def has_pokemon_of_type?(type) + # party. excluded_pokemon is an array of Pokemon objects to ignore. + def has_pokemon_of_type?(type, excluded_pokemon = []) return false if !GameData::Type.exists?(type) type = GameData::Type.get(type).id - return pokemon_party.any? { |p| p&.hasType?(type) } + return pokemon_party.any? { |pkmn| pkmn&.hasType?(type) && !excluded_pokemon.include?(pkmn) } end # Checks whether any Pokémon in the party knows the given move, and returns diff --git a/Data/Scripts/020_Debug/001_Editor screens/001_EditorScreens.rb b/Data/Scripts/020_Debug/001_Editor screens/001_EditorScreens.rb index b74e40bb7..84e8bb004 100644 --- a/Data/Scripts/020_Debug/001_Editor screens/001_EditorScreens.rb +++ b/Data/Scripts/020_Debug/001_Editor screens/001_EditorScreens.rb @@ -527,7 +527,7 @@ def pbTrainerBattleEditor :trainer_type => data[0], :real_name => data[1], :version => data[2], - :lose_text => data[3], + :real_lose_text => data[3], :pokemon => party, :items => items, :pbs_file_suffix => tr_data.pbs_file_suffix