From 680c1de3927c96b3641bbc0fea6363e8e74691fd Mon Sep 17 00:00:00 2001 From: Maruno17 Date: Sun, 24 Oct 2021 23:06:47 +0100 Subject: [PATCH] =?UTF-8?q?AI=20now=20keeps=20their=20last=20defined=20Pok?= =?UTF-8?q?=C3=A9mon=20for=20last,=20tweaks=20to=20some=20battle=20effects?= =?UTF-8?q?=20based=20on=20mechanics=20generation?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../001_Battler/004_Battler_Statuses.rb | 2 +- .../002_Move/003_Move_Usage_Calculations.rb | 2 +- .../002_Move/006_MoveEffects_BattlerStats.rb | 14 +++++++++++++- .../003_Battle/002_PokeBattle_Battle.rb | 12 ++++++++++++ .../003_Battle/006_Battle_Action_Switching.rb | 10 ++++++---- .../011_Battle/003_BattleHandlers_Abilities.rb | 3 ++- Data/Scripts/011_Battle/004_AI/003_AI_Switch.rb | 4 ++++ .../011_Battle/004_AI/005_AI_Move_EffectScores.rb | 15 ++++++++++----- 8 files changed, 49 insertions(+), 13 deletions(-) diff --git a/Data/Scripts/011_Battle/001_Battler/004_Battler_Statuses.rb b/Data/Scripts/011_Battle/001_Battler/004_Battler_Statuses.rb index 11772615d..c4d8ec7fb 100644 --- a/Data/Scripts/011_Battle/001_Battler/004_Battler_Statuses.rb +++ b/Data/Scripts/011_Battle/001_Battler/004_Battler_Statuses.rb @@ -452,7 +452,7 @@ class PokeBattle_Battler return false end # Terrains immunity - if affectedByTerrain? && @battle.field.terrain == :Misty + if affectedByTerrain? && @battle.field.terrain == :Misty && Settings::MECHANICS_GENERATION >= 7 @battle.pbDisplay(_INTL("{1} surrounds itself with misty terrain!",pbThis(true))) if showMessages return false end diff --git a/Data/Scripts/011_Battle/002_Move/003_Move_Usage_Calculations.rb b/Data/Scripts/011_Battle/002_Move/003_Move_Usage_Calculations.rb index fb4312ec3..2af8f84db 100644 --- a/Data/Scripts/011_Battle/002_Move/003_Move_Usage_Calculations.rb +++ b/Data/Scripts/011_Battle/002_Move/003_Move_Usage_Calculations.rb @@ -313,7 +313,7 @@ class PokeBattle_Move end # Parental Bond's second attack if user.effects[PBEffects::ParentalBond]==1 - multipliers[:base_damage_multiplier] /= 4 + multipliers[:base_damage_multiplier] /= (Settings::MECHANICS_GENERATION >= 7) ? 4 : 2 end # Other if user.effects[PBEffects::MeFirst] diff --git a/Data/Scripts/011_Battle/002_Move/006_MoveEffects_BattlerStats.rb b/Data/Scripts/011_Battle/002_Move/006_MoveEffects_BattlerStats.rb index 51eabbc0f..2aaa1bc4e 100644 --- a/Data/Scripts/011_Battle/002_Move/006_MoveEffects_BattlerStats.rb +++ b/Data/Scripts/011_Battle/002_Move/006_MoveEffects_BattlerStats.rb @@ -18,6 +18,18 @@ class PokeBattle_Move_RaiseUserAttack2 < PokeBattle_StatUpMove end end +#=============================================================================== +# If this move KO's the target, increases the user's Attack by 2 stages. +# (Fell Stinger (Gen 6-)) +#=============================================================================== +class PokeBattle_Move_RaiseUserAttack2IfTargetFaints < PokeBattle_Move + def pbEffectAfterAllHits(user, target) + return if !target.damageState.fainted + return if !user.pbCanRaiseStatStage?(:ATTACK, user, self) + user.pbRaiseStatStage(:ATTACK, 2, user) + end +end + #=============================================================================== # Increases the user's Attack by 3 stages. #=============================================================================== @@ -30,7 +42,7 @@ end #=============================================================================== # If this move KO's the target, increases the user's Attack by 3 stages. -# (Fell Stinger) +# (Fell Stinger (Gen 7+)) #=============================================================================== class PokeBattle_Move_RaiseUserAttack3IfTargetFaints < PokeBattle_Move def pbEffectAfterAllHits(user,target) diff --git a/Data/Scripts/011_Battle/003_Battle/002_PokeBattle_Battle.rb b/Data/Scripts/011_Battle/003_Battle/002_PokeBattle_Battle.rb index 322f0c007..ddb92fe30 100644 --- a/Data/Scripts/011_Battle/003_Battle/002_PokeBattle_Battle.rb +++ b/Data/Scripts/011_Battle/003_Battle/002_PokeBattle_Battle.rb @@ -342,6 +342,18 @@ class PokeBattle_Battle return pbAbleCount(idxBattler)==0 end + def pbTeamAbleNonActiveCount(idxBattler = 0) + inBattleIndices = [] + eachSameSideBattler(idxBattler) { |b| inBattleIndices.push(b.pokemonIndex) } + count = 0 + eachInTeamFromBattlerIndex(idxBattler) do |pkmn, i| + next if !pkmn || !pkmn.able? + next if inBattleIndices.include?(idxParty) + count += 1 + end + return count + end + # For the given side of the field (0=player's, 1=opponent's), returns an array # containing the number of able Pokémon in each team. def pbAbleTeamCounts(side) diff --git a/Data/Scripts/011_Battle/003_Battle/006_Battle_Action_Switching.rb b/Data/Scripts/011_Battle/003_Battle/006_Battle_Action_Switching.rb index c6fdac306..5e2c6babf 100644 --- a/Data/Scripts/011_Battle/003_Battle/006_Battle_Action_Switching.rb +++ b/Data/Scripts/011_Battle/003_Battle/006_Battle_Action_Switching.rb @@ -16,9 +16,11 @@ class PokeBattle_Battle return false end if !pbIsOwner?(idxBattler,idxParty) - owner = pbGetOwnerFromPartyIndex(idxBattler,idxParty) - partyScene.pbDisplay(_INTL("You can't switch {1}'s Pokémon with one of yours!", - owner.name)) if partyScene + if partyScene + owner = pbGetOwnerFromPartyIndex(idxBattler,idxParty) + partyScene.pbDisplay(_INTL("You can't switch {1}'s Pokémon with one of yours!", + owner.name)) + end return false end if party[idxParty].fainted? @@ -129,7 +131,7 @@ class PokeBattle_Battle end # For choosing a replacement Pokémon when prompted in the middle of other - # things happening (U-turn, Baton Pass, in def pbSwitch). + # things happening (U-turn, Baton Pass, in def pbEORSwitch). def pbSwitchInBetween(idxBattler,checkLaxOnly=false,canCancel=false) return pbPartyScreen(idxBattler,checkLaxOnly,canCancel) if pbOwnedByPlayer?(idxBattler) return @battleAI.pbDefaultChooseNewEnemy(idxBattler,pbParty(idxBattler)) diff --git a/Data/Scripts/011_Battle/003_BattleHandlers_Abilities.rb b/Data/Scripts/011_Battle/003_BattleHandlers_Abilities.rb index c956a1b41..8e42041f8 100644 --- a/Data/Scripts/011_Battle/003_BattleHandlers_Abilities.rb +++ b/Data/Scripts/011_Battle/003_BattleHandlers_Abilities.rb @@ -519,7 +519,8 @@ BattleHandlers::AbilityOnStatLoss.add(:DEFIANT, BattleHandlers::PriorityChangeAbility.add(:GALEWINGS, proc { |ability,battler,move,pri| - next pri+1 if battler.hp==battler.totalhp && move.type == :FLYING + next pri + 1 if (Settings::MECHANICS_GENERATION <= 6 || battler.hp == battler.totalhp) && + move.type == :FLYING } ) diff --git a/Data/Scripts/011_Battle/004_AI/003_AI_Switch.rb b/Data/Scripts/011_Battle/004_AI/003_AI_Switch.rb index 6d0638293..5269bb07d 100644 --- a/Data/Scripts/011_Battle/004_AI/003_AI_Switch.rb +++ b/Data/Scripts/011_Battle/004_AI/003_AI_Switch.rb @@ -91,7 +91,9 @@ class PokeBattle_AI end if shouldSwitch list = [] + idxPartyStart, idxPartyEnd = @battle.pbTeamIndexRangeFromBattlerIndex(idxBattler) @battle.pbParty(idxBattler).each_with_index do |pkmn,i| + next if i == idxPartyEnd - 1 # Don't choose to switch in ace next if !@battle.pbCanSwitch?(idxBattler,i) # If perish count is 1, it may be worth it to switch # even with Spikes, since Perish Song's effect will end @@ -147,7 +149,9 @@ class PokeBattle_AI #============================================================================= def pbDefaultChooseNewEnemy(idxBattler,party) enemies = [] + idxPartyStart, idxPartyEnd = @battle.pbTeamIndexRangeFromBattlerIndex(idxBattler) party.each_with_index do |_p,i| + next if i == idxPartyEnd - 1 && enemies.length > 0 # Ignore ace if possible enemies.push(i) if @battle.pbCanSwitchLax?(idxBattler,i) end return -1 if enemies.length==0 diff --git a/Data/Scripts/011_Battle/004_AI/005_AI_Move_EffectScores.rb b/Data/Scripts/011_Battle/004_AI/005_AI_Move_EffectScores.rb index f157ab473..0f561b6fd 100644 --- a/Data/Scripts/011_Battle/004_AI/005_AI_Move_EffectScores.rb +++ b/Data/Scripts/011_Battle/004_AI/005_AI_Move_EffectScores.rb @@ -2021,8 +2021,9 @@ class PokeBattle_AI score -= 100 if @battle.trainerBattle? #--------------------------------------------------------------------------- when "SwitchOutUserStatusMove" - if !@battle.pbCanChooseNonActive?(user.index) - score -= 80 + if !@battle.pbCanChooseNonActive?(user.index) || + @battle.pbTeamAbleNonActiveCount(user.index) > 1 # Don't switch in ace + score -= 100 else score += 40 if user.effects[PBEffects::Confusion]>0 total = 0 @@ -2042,6 +2043,12 @@ class PokeBattle_AI end end #--------------------------------------------------------------------------- + when "SwitchOutUserDamagingMove" + if !@battle.pbCanChooseNonActive?(user.index) || + @battle.pbTeamAbleNonActiveCount(user.index) > 1 # Don't switch in ace + score -= 100 + end + #--------------------------------------------------------------------------- when "SwitchOutTargetStatusMove" if target.effects[PBEffects::Ingrain] || (skill>=PBTrainerAI.highSkill && target.hasActiveAbility?(:SUCTIONCUPS)) @@ -2069,7 +2076,7 @@ class PokeBattle_AI #--------------------------------------------------------------------------- when "SwitchOutUserPassOnEffects" if !@battle.pbCanChooseNonActive?(user.index) - score -= 80 + score -= 100 else score -= 40 if user.effects[PBEffects::Confusion]>0 total = 0 @@ -2089,8 +2096,6 @@ class PokeBattle_AI end end #--------------------------------------------------------------------------- - when "SwitchOutUserDamagingMove" - #--------------------------------------------------------------------------- when "TrapTargetInBattle" score -= 90 if target.effects[PBEffects::MeanLook]>=0 #---------------------------------------------------------------------------