Merge branch 'dev' into ai

This commit is contained in:
Maruno17
2022-12-31 17:28:56 +00:00
75 changed files with 4599 additions and 3590 deletions

View File

@@ -427,9 +427,8 @@ class Battle
if battler_side.effects[PBEffects::StealthRock] && battler.takesIndirectDamage? &&
GameData::Type.exists?(:ROCK) && !battler.hasActiveItem?(:HEAVYDUTYBOOTS)
bTypes = battler.pbTypes(true)
eff = Effectiveness.calculate(:ROCK, bTypes[0], bTypes[1], bTypes[2])
eff = Effectiveness.calculate(:ROCK, *bTypes)
if !Effectiveness.ineffective?(eff)
eff = eff.to_f / Effectiveness::NORMAL_EFFECTIVE
battler.pbReduceHP(battler.totalhp * eff / 8, false)
pbDisplay(_INTL("Pointed stones dug into {1}!", battler.pbThis))
battler.pbItemHPHealCheck

View File

@@ -301,7 +301,7 @@ class Battle::Battler
# Returns the active types of this Pokémon. The array should not include the
# same type more than once, and should not include any invalid types.
def pbTypes(withType3 = false)
def pbTypes(withExtraType = false)
ret = @types.uniq
# Burn Up erases the Fire-type.
ret.delete(:FIRE) if @effects[PBEffects::BurnUp]
@@ -312,8 +312,8 @@ class Battle::Battler
ret.push(:NORMAL) if ret.length == 0
end
# Add the third type specially.
if withType3 && @effects[PBEffects::Type3] && !ret.include?(@effects[PBEffects::Type3])
ret.push(@effects[PBEffects::Type3])
if withExtraType && @effects[PBEffects::ExtraType] && !ret.include?(@effects[PBEffects::ExtraType])
ret.push(@effects[PBEffects::ExtraType])
end
return ret
end

View File

@@ -172,6 +172,7 @@ class Battle::Battler
@effects[PBEffects::Encore] = 0
@effects[PBEffects::EncoreMove] = nil
@effects[PBEffects::Endure] = false
@effects[PBEffects::ExtraType] = nil
@effects[PBEffects::FirstPledge] = nil
@effects[PBEffects::FlashFire] = false
@effects[PBEffects::Flinch] = false
@@ -271,7 +272,6 @@ class Battle::Battler
end
@effects[PBEffects::Truant] = false
@effects[PBEffects::TwoTurnAttack] = nil
@effects[PBEffects::Type3] = nil
@effects[PBEffects::Unburden] = false
@effects[PBEffects::Uproar] = 0
@effects[PBEffects::WaterSport] = false

View File

@@ -130,14 +130,14 @@ class Battle::Battler
if newType.is_a?(Battle::Battler)
newTypes = newType.pbTypes
newTypes.push(:NORMAL) if newTypes.length == 0
newType3 = newType.effects[PBEffects::Type3]
newType3 = nil if newTypes.include?(newType3)
newExtraType = newType.effects[PBEffects::ExtraType]
newExtraType = nil if newTypes.include?(newExtraType)
@types = newTypes.clone
@effects[PBEffects::Type3] = newType3
@effects[PBEffects::ExtraType] = newExtraType
else
newType = GameData::Type.get(newType).id
@types = [newType]
@effects[PBEffects::Type3] = nil
@effects[PBEffects::ExtraType] = nil
end
@effects[PBEffects::BurnUp] = false
@effects[PBEffects::Roost] = false
@@ -145,7 +145,7 @@ class Battle::Battler
def pbResetTypes
@types = @pokemon.types
@effects[PBEffects::Type3] = nil
@effects[PBEffects::ExtraType] = nil
@effects[PBEffects::BurnUp] = false
@effects[PBEffects::Roost] = false
end

View File

@@ -30,58 +30,51 @@ class Battle::Move
# Type effectiveness calculation
#=============================================================================
def pbCalcTypeModSingle(moveType, defType, user, target)
ret = Effectiveness.calculate_one(moveType, defType)
ret = Effectiveness.calculate(moveType, defType)
if Effectiveness.ineffective_type?(moveType, defType)
# Ring Target
if target.hasActiveItem?(:RINGTARGET)
ret = Effectiveness::NORMAL_EFFECTIVE_ONE
ret = Effectiveness::NORMAL_EFFECTIVE_MULTIPLIER
end
# Foresight
if (user.hasActiveAbility?(:SCRAPPY) || target.effects[PBEffects::Foresight]) &&
defType == :GHOST
ret = Effectiveness::NORMAL_EFFECTIVE_ONE
ret = Effectiveness::NORMAL_EFFECTIVE_MULTIPLIER
end
# Miracle Eye
if target.effects[PBEffects::MiracleEye] && defType == :DARK
ret = Effectiveness::NORMAL_EFFECTIVE_ONE
ret = Effectiveness::NORMAL_EFFECTIVE_MULTIPLIER
end
elsif Effectiveness.super_effective_type?(moveType, defType)
# Delta Stream's weather
if target.effectiveWeather == :StrongWinds && defType == :FLYING
ret = Effectiveness::NORMAL_EFFECTIVE_ONE
ret = Effectiveness::NORMAL_EFFECTIVE_MULTIPLIER
end
end
# Grounded Flying-type Pokémon become susceptible to Ground moves
if !target.airborne? && defType == :FLYING && moveType == :GROUND
ret = Effectiveness::NORMAL_EFFECTIVE_ONE
ret = Effectiveness::NORMAL_EFFECTIVE_MULTIPLIER
end
return ret
end
def pbCalcTypeMod(moveType, user, target)
return Effectiveness::NORMAL_EFFECTIVE if !moveType
return Effectiveness::NORMAL_EFFECTIVE if moveType == :GROUND &&
target.pbHasType?(:FLYING) &&
target.hasActiveItem?(:IRONBALL)
# Determine types
tTypes = target.pbTypes(true)
ret = Effectiveness::NORMAL_EFFECTIVE_MULTIPLIER
return ret if !moveType
return ret if moveType == :GROUND && target.pbHasType?(:FLYING) && target.hasActiveItem?(:IRONBALL)
# Get effectivenesses
typeMods = [Effectiveness::NORMAL_EFFECTIVE_ONE] * 3 # 3 types max
if moveType == :SHADOW
if target.shadowPokemon?
typeMods[0] = Effectiveness::NOT_VERY_EFFECTIVE_ONE
ret = Effectiveness::NOT_VERY_EFFECTIVE_MULTIPLIER
else
typeMods[0] = Effectiveness::SUPER_EFFECTIVE_ONE
ret = Effectiveness::SUPER_EFFECTIVE_MULTIPLIER
end
else
tTypes.each_with_index do |type, i|
typeMods[i] = pbCalcTypeModSingle(moveType, type, user, target)
target.pbTypes(true).each do |type|
ret *= pbCalcTypeModSingle(moveType, type, user, target)
end
ret *= 2 if target.effects[PBEffects::TarShot] && moveType == :FIRE
end
# Multiply all effectivenesses together
ret = 1
typeMods.each { |m| ret *= m }
ret *= 2 if target.effects[PBEffects::TarShot] && moveType == :FIRE
return ret
end
@@ -453,7 +446,7 @@ class Battle::Move
end
end
# Type effectiveness
multipliers[:final_damage_multiplier] *= target.damageState.typeMod.to_f / Effectiveness::NORMAL_EFFECTIVE
multipliers[:final_damage_multiplier] *= target.damageState.typeMod
# Burn
if user.status == :BURN && physicalMove? && damageReducedByBurn? &&
!user.hasActiveAbility?(:GUTS)

View File

@@ -280,7 +280,7 @@ end
#===============================================================================
class Battle::Move::FreezeTargetSuperEffectiveAgainstWater < Battle::Move::FreezeTarget
def pbCalcTypeModSingle(moveType, defType, user, target)
return Effectiveness::SUPER_EFFECTIVE_ONE if defType == :WATER
return Effectiveness::SUPER_EFFECTIVE_MULTIPLIER if defType == :WATER
return super
end
end
@@ -771,7 +771,7 @@ class Battle::Move::SetUserTypesToTargetTypes < Battle::Move
return true
end
if user.pbTypes == target.pbTypes &&
user.effects[PBEffects::Type3] == target.effects[PBEffects::Type3]
user.effects[PBEffects::ExtraType] == target.effects[PBEffects::ExtraType]
@battle.pbDisplay(_INTL("But it failed!")) if show_message
return true
end
@@ -880,7 +880,7 @@ class Battle::Move::AddGhostTypeToTarget < Battle::Move
end
def pbEffectAgainstTarget(user, target)
target.effects[PBEffects::Type3] = :GHOST
target.effects[PBEffects::ExtraType] = :GHOST
typeName = GameData::Type.get(:GHOST).name
@battle.pbDisplay(_INTL("{1} transformed into the {2} type!", target.pbThis, typeName))
end
@@ -901,7 +901,7 @@ class Battle::Move::AddGrassTypeToTarget < Battle::Move
end
def pbEffectAgainstTarget(user, target)
target.effects[PBEffects::Type3] = :GRASS
target.effects[PBEffects::ExtraType] = :GRASS
typeName = GameData::Type.get(:GRASS).name
@battle.pbDisplay(_INTL("{1} transformed into the {2} type!", target.pbThis, typeName))
end
@@ -1263,7 +1263,7 @@ class Battle::Move::HitsTargetInSkyGroundsTarget < Battle::Move
def hitsFlyingTargets?; return true; end
def pbCalcTypeModSingle(moveType, defType, user, target)
return Effectiveness::NORMAL_EFFECTIVE_ONE if moveType == :GROUND && defType == :FLYING
return Effectiveness::NORMAL_EFFECTIVE_MULTIPLIER if moveType == :GROUND && defType == :FLYING
return super
end

View File

@@ -1111,8 +1111,7 @@ class Battle::Move::EffectivenessIncludesFlyingType < Battle::Move
def pbCalcTypeModSingle(moveType, defType, user, target)
ret = super
if GameData::Type.exists?(:FLYING)
flyingEff = Effectiveness.calculate_one(:FLYING, defType)
ret *= flyingEff.to_f / Effectiveness::NORMAL_EFFECTIVE_ONE
ret *= Effectiveness.calculate(:FLYING, defType)
end
return ret
end

View File

@@ -455,7 +455,7 @@ class Battle::Move::TwoTurnAttackInvulnerableInSkyTargetCannotAct < Battle::Move
end
def pbCalcTypeMod(movetype, user, target)
return Effectiveness::INEFFECTIVE if target.pbHasType?(:FLYING)
return Effectiveness::INEFFECTIVE_MULTIPLIER if target.pbHasType?(:FLYING)
return super
end

View File

@@ -24,16 +24,62 @@ class Battle::AI
#=============================================================================
# Move's type effectiveness
#=============================================================================
def pbCalcTypeModSingle(moveType, defType, user, target)
ret = Effectiveness.calculate(moveType, defType)
if Effectiveness.ineffective_type?(moveType, defType)
# Ring Target
if target.hasActiveItem?(:RINGTARGET)
ret = Effectiveness::NORMAL_EFFECTIVE_MULTIPLIER
end
# Foresight
if (user.hasActiveAbility?(:SCRAPPY) || target.effects[PBEffects::Foresight]) &&
defType == :GHOST
ret = Effectiveness::NORMAL_EFFECTIVE_MULTIPLIER
end
# Miracle Eye
if target.effects[PBEffects::MiracleEye] && defType == :DARK
ret = Effectiveness::NORMAL_EFFECTIVE_MULTIPLIER
end
elsif Effectiveness.super_effective_type?(moveType, defType)
# Delta Stream's weather
if target.effectiveWeather == :StrongWinds && defType == :FLYING
ret = Effectiveness::NORMAL_EFFECTIVE_MULTIPLIER
end
end
# Grounded Flying-type Pokémon become susceptible to Ground moves
if !target.airborne? && defType == :FLYING && moveType == :GROUND
ret = Effectiveness::NORMAL_EFFECTIVE_MULTIPLIER
end
return ret
end
def pbCalcTypeMod(moveType, user, target)
ret = Effectiveness::NORMAL_EFFECTIVE_MULTIPLIER
return ret if !moveType
return ret if moveType == :GROUND && target.pbHasType?(:FLYING) && target.hasActiveItem?(:IRONBALL)
# Get effectivenesses
if moveType == :SHADOW
if target.shadowPokemon?
ret = Effectiveness::NOT_VERY_EFFECTIVE_MULTIPLIER
else
ret = Effectiveness::SUPER_EFFECTIVE_MULTIPLIER
end
else
target.pbTypes(true).each do |type|
ret *= pbCalcTypeModSingle(moveType, type, user, target)
end
end
return ret
end
# For switching. Determines the effectiveness of a potential switch-in against
# an opposing battler.
def pbCalcTypeModPokemon(pkmn, target_battler)
mod1 = Effectiveness.calculate(pkmn.types[0], target_battler.types[0], target_battler.types[1])
mod2 = Effectiveness::NORMAL_EFFECTIVE
if pkmn.types.length > 1
mod2 = Effectiveness.calculate(pkmn.types[1], target_battler.types[0], target_battler.types[1])
mod2 = mod2.to_f / Effectiveness::NORMAL_EFFECTIVE
ret = Effectiveness::NORMAL_EFFECTIVE_MULTIPLIER
pkmn.types.each do |thisType|
ret *= Effectiveness.calculate(thisType, *target_battler.types)
end
return mod1 * mod2
return ret
end
#=============================================================================

View File

@@ -28,6 +28,7 @@ module PBEffects
Encore = 23
EncoreMove = 24
Endure = 25
ExtraType = 111
FirstPledge = 26
FlashFire = 27
Flinch = 28
@@ -113,7 +114,6 @@ module PBEffects
TrappingUser = 108
Truant = 109
TwoTurnAttack = 110
Type3 = 111
Unburden = 112
Uproar = 113
WaterSport = 114

View File

@@ -30,7 +30,7 @@ class Battle::DamageState
def initialize; reset; end
def reset
@typeMod = Effectiveness::INEFFECTIVE
@typeMod = Effectiveness::INEFFECTIVE_MULTIPLIER
@unaffected = false
@protected = false
@missed = false

View File

@@ -2607,7 +2607,7 @@ Battle::AbilityEffects::OnSwitchIn.add(:ANTICIPATION,
if Settings::MECHANICS_GENERATION >= 6 && m.function == "TypeDependsOnUserIVs" # Hidden Power
moveType = pbHiddenPower(b.pokemon)[0]
end
eff = Effectiveness.calculate(moveType, types[0], types[1], types[2])
eff = Effectiveness.calculate(moveType, types)
next if Effectiveness.ineffective?(eff)
next if !Effectiveness.super_effective?(eff) &&
!["OHKO", "OHKOIce", "OHKOHitsUndergroundTarget"].include?(m.function)

View File

@@ -10,7 +10,7 @@ class Battle::SuccessState
def initialize; clear; end
def clear(full = true)
@typeMod = Effectiveness::NORMAL_EFFECTIVE
@typeMod = Effectiveness::NORMAL_EFFECTIVE_MULTIPLIER
@useState = 0
@protected = false
@skill = 0 if full