AI now keeps their last defined Pokémon for last, tweaks to some battle effects based on mechanics generation

This commit is contained in:
Maruno17
2021-10-24 23:06:47 +01:00
parent 18049c22b9
commit 680c1de392
8 changed files with 49 additions and 13 deletions

View File

@@ -452,7 +452,7 @@ class PokeBattle_Battler
return false return false
end end
# Terrains immunity # 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 @battle.pbDisplay(_INTL("{1} surrounds itself with misty terrain!",pbThis(true))) if showMessages
return false return false
end end

View File

@@ -313,7 +313,7 @@ class PokeBattle_Move
end end
# Parental Bond's second attack # Parental Bond's second attack
if user.effects[PBEffects::ParentalBond]==1 if user.effects[PBEffects::ParentalBond]==1
multipliers[:base_damage_multiplier] /= 4 multipliers[:base_damage_multiplier] /= (Settings::MECHANICS_GENERATION >= 7) ? 4 : 2
end end
# Other # Other
if user.effects[PBEffects::MeFirst] if user.effects[PBEffects::MeFirst]

View File

@@ -18,6 +18,18 @@ class PokeBattle_Move_RaiseUserAttack2 < PokeBattle_StatUpMove
end end
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. # 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. # 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 class PokeBattle_Move_RaiseUserAttack3IfTargetFaints < PokeBattle_Move
def pbEffectAfterAllHits(user,target) def pbEffectAfterAllHits(user,target)

View File

@@ -342,6 +342,18 @@ class PokeBattle_Battle
return pbAbleCount(idxBattler)==0 return pbAbleCount(idxBattler)==0
end 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 # 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. # containing the number of able Pokémon in each team.
def pbAbleTeamCounts(side) def pbAbleTeamCounts(side)

View File

@@ -16,9 +16,11 @@ class PokeBattle_Battle
return false return false
end end
if !pbIsOwner?(idxBattler,idxParty) if !pbIsOwner?(idxBattler,idxParty)
if partyScene
owner = pbGetOwnerFromPartyIndex(idxBattler,idxParty) owner = pbGetOwnerFromPartyIndex(idxBattler,idxParty)
partyScene.pbDisplay(_INTL("You can't switch {1}'s Pokémon with one of yours!", partyScene.pbDisplay(_INTL("You can't switch {1}'s Pokémon with one of yours!",
owner.name)) if partyScene owner.name))
end
return false return false
end end
if party[idxParty].fainted? if party[idxParty].fainted?
@@ -129,7 +131,7 @@ class PokeBattle_Battle
end end
# For choosing a replacement Pokémon when prompted in the middle of other # 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) def pbSwitchInBetween(idxBattler,checkLaxOnly=false,canCancel=false)
return pbPartyScreen(idxBattler,checkLaxOnly,canCancel) if pbOwnedByPlayer?(idxBattler) return pbPartyScreen(idxBattler,checkLaxOnly,canCancel) if pbOwnedByPlayer?(idxBattler)
return @battleAI.pbDefaultChooseNewEnemy(idxBattler,pbParty(idxBattler)) return @battleAI.pbDefaultChooseNewEnemy(idxBattler,pbParty(idxBattler))

View File

@@ -519,7 +519,8 @@ BattleHandlers::AbilityOnStatLoss.add(:DEFIANT,
BattleHandlers::PriorityChangeAbility.add(:GALEWINGS, BattleHandlers::PriorityChangeAbility.add(:GALEWINGS,
proc { |ability,battler,move,pri| 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
} }
) )

View File

@@ -91,7 +91,9 @@ class PokeBattle_AI
end end
if shouldSwitch if shouldSwitch
list = [] list = []
idxPartyStart, idxPartyEnd = @battle.pbTeamIndexRangeFromBattlerIndex(idxBattler)
@battle.pbParty(idxBattler).each_with_index do |pkmn,i| @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) next if !@battle.pbCanSwitch?(idxBattler,i)
# If perish count is 1, it may be worth it to switch # If perish count is 1, it may be worth it to switch
# even with Spikes, since Perish Song's effect will end # even with Spikes, since Perish Song's effect will end
@@ -147,7 +149,9 @@ class PokeBattle_AI
#============================================================================= #=============================================================================
def pbDefaultChooseNewEnemy(idxBattler,party) def pbDefaultChooseNewEnemy(idxBattler,party)
enemies = [] enemies = []
idxPartyStart, idxPartyEnd = @battle.pbTeamIndexRangeFromBattlerIndex(idxBattler)
party.each_with_index do |_p,i| 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) enemies.push(i) if @battle.pbCanSwitchLax?(idxBattler,i)
end end
return -1 if enemies.length==0 return -1 if enemies.length==0

View File

@@ -2021,8 +2021,9 @@ class PokeBattle_AI
score -= 100 if @battle.trainerBattle? score -= 100 if @battle.trainerBattle?
#--------------------------------------------------------------------------- #---------------------------------------------------------------------------
when "SwitchOutUserStatusMove" when "SwitchOutUserStatusMove"
if !@battle.pbCanChooseNonActive?(user.index) if !@battle.pbCanChooseNonActive?(user.index) ||
score -= 80 @battle.pbTeamAbleNonActiveCount(user.index) > 1 # Don't switch in ace
score -= 100
else else
score += 40 if user.effects[PBEffects::Confusion]>0 score += 40 if user.effects[PBEffects::Confusion]>0
total = 0 total = 0
@@ -2042,6 +2043,12 @@ class PokeBattle_AI
end end
end end
#--------------------------------------------------------------------------- #---------------------------------------------------------------------------
when "SwitchOutUserDamagingMove"
if !@battle.pbCanChooseNonActive?(user.index) ||
@battle.pbTeamAbleNonActiveCount(user.index) > 1 # Don't switch in ace
score -= 100
end
#---------------------------------------------------------------------------
when "SwitchOutTargetStatusMove" when "SwitchOutTargetStatusMove"
if target.effects[PBEffects::Ingrain] || if target.effects[PBEffects::Ingrain] ||
(skill>=PBTrainerAI.highSkill && target.hasActiveAbility?(:SUCTIONCUPS)) (skill>=PBTrainerAI.highSkill && target.hasActiveAbility?(:SUCTIONCUPS))
@@ -2069,7 +2076,7 @@ class PokeBattle_AI
#--------------------------------------------------------------------------- #---------------------------------------------------------------------------
when "SwitchOutUserPassOnEffects" when "SwitchOutUserPassOnEffects"
if !@battle.pbCanChooseNonActive?(user.index) if !@battle.pbCanChooseNonActive?(user.index)
score -= 80 score -= 100
else else
score -= 40 if user.effects[PBEffects::Confusion]>0 score -= 40 if user.effects[PBEffects::Confusion]>0
total = 0 total = 0
@@ -2089,8 +2096,6 @@ class PokeBattle_AI
end end
end end
#--------------------------------------------------------------------------- #---------------------------------------------------------------------------
when "SwitchOutUserDamagingMove"
#---------------------------------------------------------------------------
when "TrapTargetInBattle" when "TrapTargetInBattle"
score -= 90 if target.effects[PBEffects::MeanLook]>=0 score -= 90 if target.effects[PBEffects::MeanLook]>=0
#--------------------------------------------------------------------------- #---------------------------------------------------------------------------