Coded some Gen 9 ability/item/move effects

This commit is contained in:
Maruno17
2024-06-15 15:58:31 +01:00
parent 454d5a216a
commit 22b33ca6c2
35 changed files with 596 additions and 234 deletions

View File

@@ -18,7 +18,7 @@ class Battle::AI
desire_mult = -1
end
# If target has Contrary, use different calculations to score the stat change
if !ignore_contrary && !fixed_change && !@battle.moldBreaker && target.has_active_ability?(:CONTRARY)
if !ignore_contrary && !fixed_change && target.has_active_ability?(:CONTRARY) && !target.being_mold_broken?
if desire_mult > 0 && whole_effect
PBDebug.log_score_change(MOVE_USELESS_SCORE - score, "don't prefer raising target's stats (it has Contrary)")
return MOVE_USELESS_SCORE
@@ -62,7 +62,7 @@ class Battle::AI
end
# Calculate amount that stat will be raised by
increment = stat_changes[idx + 1]
increment *= 2 if !fixed_change && !@battle.moldBreaker && target.has_active_ability?(:SIMPLE)
increment *= 2 if !fixed_change && target.has_active_ability?(:SIMPLE) && !target.being_mold_broken?
increment = [increment, Battle::Battler::STAT_STAGE_MAXIMUM - target.stages[stat]].min # The actual stages gained
# Count this as a valid stat raise
real_stat_changes.push([stat, increment]) if increment > 0
@@ -324,7 +324,7 @@ class Battle::AI
desire_mult = 1
end
# If target has Contrary, use different calculations to score the stat change
if !ignore_contrary && !fixed_change && !@battle.moldBreaker && target.has_active_ability?(:CONTRARY)
if !ignore_contrary && !fixed_change && target.has_active_ability?(:CONTRARY) && !target.being_mold_broken?
if desire_mult > 0 && whole_effect
PBDebug.log_score_change(MOVE_USELESS_SCORE - score, "don't prefer lowering target's stats (it has Contrary)")
return MOVE_USELESS_SCORE
@@ -366,7 +366,7 @@ class Battle::AI
end
# Calculate amount that stat will be lowered by
decrement = stat_changes[idx + 1]
decrement *= 2 if !fixed_change && !@battle.moldBreaker && target.has_active_ability?(:SIMPLE)
decrement *= 2 if !fixed_change && target.has_active_ability?(:SIMPLE) && !target.being_mold_broken?
decrement = [decrement, Battle::Battler::STAT_STAGE_MAXIMUM + target.stages[stat]].min # The actual stages lost
# Count this as a valid stat drop
real_stat_changes.push([stat, decrement]) if decrement > 0

View File

@@ -89,7 +89,7 @@ Battle::AI::Handlers::GeneralMoveAgainstTargetScore.add(:target_can_Magic_Coat_o
if move.statusMove? && move.move.canMagicCoat? && target.opposes?(user) &&
(target.faster_than?(user) || !target.battler.semiInvulnerable?)
old_score = score
if !battle.moldBreaker && target.has_active_ability?(:MAGICBOUNCE)
if target.has_active_ability?(:MAGICBOUNCE) && !target.being_mold_broken?
score = Battle::AI::MOVE_USELESS_SCORE
PBDebug.log_score_change(score - old_score, "useless because target will Magic Bounce it")
elsif target.has_move_with_function?("BounceBackProblemCausingStatusMoves") &&
@@ -108,7 +108,7 @@ Battle::AI::Handlers::GeneralMoveScore.add(:any_foe_can_Magic_Coat_or_Bounce_mov
old_score = score
ai.each_foe_battler(user.side) do |b, i|
next if user.faster_than?(b) && b.battler.semiInvulnerable?
if b.has_active_ability?(:MAGICBOUNCE) && !battle.moldBreaker
if b.has_active_ability?(:MAGICBOUNCE) && !b.being_mold_broken?
score = Battle::AI::MOVE_USELESS_SCORE
PBDebug.log_score_change(score - old_score, "useless because a foe will Magic Bounce it")
break
@@ -336,7 +336,7 @@ Battle::AI::Handlers::GeneralMoveAgainstTargetScore.add(:external_flinching_effe
user.faster_than?(target) && target.effects[PBEffects::Substitute] == 0
if user.has_active_item?([:KINGSROCK, :RAZORFANG]) ||
user.has_active_ability?(:STENCH)
if battle.moldBreaker || !target.has_active_ability?([:INNERFOCUS, :SHIELDDUST])
if !target.has_active_ability?([:INNERFOCUS, :SHIELDDUST]) || target.being_mold_broken?
old_score = score
score += 8
score += 5 if move.move.multiHitMove?

View File

@@ -274,6 +274,10 @@ class Battle::AI::AIBattler
return battler.hasMoldBreaker?
end
def being_mold_broken?
return battler.beingMoldBroken?
end
#-----------------------------------------------------------------------------
def item_id; return battler.item_id; end

View File

@@ -110,13 +110,13 @@ class Battle::AI::AIMove
@move.pbOnStartUse(user.battler, [target.battler]) # Calculate category
end
atk, atk_stage = @move.pbGetAttackStats(user.battler, target.battler)
if !target.has_active_ability?(:UNAWARE) || @ai.battle.moldBreaker
if !target.has_active_ability?(:UNAWARE) || target.being_mold_broken?
atk_stage = max_stage if is_critical && atk_stage < max_stage
atk = (atk.to_f * stage_mul[atk_stage] / stage_div[atk_stage]).floor
end
##### Calculate target's defense stat #####
defense, def_stage = @move.pbGetDefenseStats(user.battler, target.battler)
if !user.has_active_ability?(:UNAWARE) || @ai.battle.moldBreaker
if !user.has_active_ability?(:UNAWARE) || user.being_mold_broken?
def_stage = max_stage if is_critical && def_stage > max_stage
defense = (defense.to_f * stage_mul[def_stage] / stage_div[def_stage]).floor
end
@@ -171,24 +171,22 @@ class Battle::AI::AIMove
)
end
end
if !@ai.battle.moldBreaker
user_battler.allAllies.each do |b|
next if !b.abilityActive?
Battle::AbilityEffects.triggerDamageCalcFromAlly(
b.ability, user_battler, target_battler, @move, multipliers, base_dmg, calc_type
)
end
if target.ability_active?
case target.ability_id
when :FILTER, :SOLIDROCK
if Effectiveness.super_effective_type?(calc_type, *target.pbTypes(true))
multipliers[:final_damage_multiplier] *= 0.75
end
else
Battle::AbilityEffects.triggerDamageCalcFromTarget(
target.ability, user_battler, target_battler, @move, multipliers, base_dmg, calc_type
)
user_battler.allAllies.each do |b|
next if !b.abilityActive? || b.beingMoldBroken?
Battle::AbilityEffects.triggerDamageCalcFromAlly(
b.ability, user_battler, target_battler, @move, multipliers, base_dmg, calc_type
)
end
if target.ability_active? && !target.being_mold_broken?
case target.ability_id
when :FILTER, :SOLIDROCK
if Effectiveness.super_effective_type?(calc_type, *target.pbTypes(true))
multipliers[:final_damage_multiplier] *= 0.75
end
else
Battle::AbilityEffects.triggerDamageCalcFromTarget(
target.ability, user_battler, target_battler, @move, multipliers, base_dmg, calc_type
)
end
end
if target.ability_active?
@@ -196,13 +194,11 @@ class Battle::AI::AIMove
target.ability, user_battler, target_battler, @move, multipliers, base_dmg, calc_type
)
end
if !@ai.battle.moldBreaker
target_battler.allAllies.each do |b|
next if !b.abilityActive?
Battle::AbilityEffects.triggerDamageCalcFromTargetAlly(
b.ability, user_battler, target_battler, @move, multipliers, base_dmg, calc_type
)
end
target_battler.allAllies.each do |b|
next if !b.abilityActive? || b.beingMoldBroken?
Battle::AbilityEffects.triggerDamageCalcFromTargetAlly(
b.ability, user_battler, target_battler, @move, multipliers, base_dmg, calc_type
)
end
# Item effects that alter damage
if user.item_active?
@@ -445,7 +441,7 @@ class Battle::AI::AIMove
b.ability, modifiers, user_battler, target_battler, @move, calc_type
)
end
if !@ai.battle.moldBreaker && target.ability_active?
if target.ability_active? && !target.being_mold_broken?
Battle::AbilityEffects.triggerAccuracyCalcFromTarget(
target.ability, modifiers, user_battler, target_battler, @move, calc_type
)
@@ -510,7 +506,7 @@ class Battle::AI::AIMove
user_battler, target_battler, crit_stage)
return -1 if crit_stage < 0
end
if !@ai.battle.moldBreaker && target.ability_active?
if target.ability_active? && !target.being_mold_broken?
crit_stage = Battle::AbilityEffects.triggerCriticalCalcFromTarget(target_battler.ability,
user_battler, target_battler, crit_stage)
return -1 if crit_stage < 0
@@ -556,7 +552,7 @@ class Battle::AI::AIMove
# Additional effect will be negated
return -999 if user.has_active_ability?(:SHEERFORCE)
return -999 if target && user.index != target.index &&
target.has_active_ability?(:SHIELDDUST) && !@ai.battle.moldBreaker
target.has_active_ability?(:SHIELDDUST) && !target.being_mold_broken?
# Additional effect will always trigger
return 0 if chance > 100
# Calculate the chance