Created and implemented GameData::Type

This commit is contained in:
Maruno17
2020-12-12 21:26:46 +00:00
parent c8790bafc9
commit bc13517cb7
50 changed files with 698 additions and 784 deletions

View File

@@ -22,7 +22,7 @@ class PokeBattle_AI
moveData = GameData::Move.get(target.lastMoveUsed)
moveType = moveData.type
typeMod = pbCalcTypeMod(moveType,target,battler)
if PBTypes.superEffective?(typeMod) && moveData.base_damage > 50
if PBTypeEffectiveness.superEffective?(typeMod) && moveData.base_damage > 50
switchChance = (moveData.base_damage > 70) ? 30 : 20
shouldSwitch = (pbAIRandom(100) < switchChance)
end
@@ -107,18 +107,18 @@ class PokeBattle_AI
end
end
# moveType is the type of the target's last used move
if moveType>=0 && PBTypes.ineffective?(pbCalcTypeMod(moveType,battler,battler))
if moveType>=0 && PBTypeEffectiveness.ineffective?(pbCalcTypeMod(moveType,battler,battler))
weight = 65
typeMod = pbCalcTypeModPokemon(pkmn,battler.pbDirectOpposing(true))
if PBTypes.superEffective?(typeMod.to_f/PBTypeEffectivenesss::NORMAL_EFFECTIVE)
if PBTypeEffectiveness.superEffective?(typeMod.to_f/PBTypeEffectivenesss::NORMAL_EFFECTIVE)
# Greater weight if new Pokemon's type is effective against target
weight = 85
end
list.unshift(i) if pbAIRandom(100)<weight # Put this Pokemon first
elsif moveType>=0 && PBTypes.resistant?(pbCalcTypeMod(moveType,battler,battler))
elsif moveType>=0 && PBTypeEffectiveness.resistant?(pbCalcTypeMod(moveType,battler,battler))
weight = 40
typeMod = pbCalcTypeModPokemon(pkmn,battler.pbDirectOpposing(true))
if PBTypes.superEffective?(typeMod.to_f/PBTypeEffectivenesss::NORMAL_EFFECTIVE)
if PBTypeEffectiveness.superEffective?(typeMod.to_f/PBTypeEffectivenesss::NORMAL_EFFECTIVE)
# Greater weight if new Pokemon's type is effective against target
weight = 60
end

View File

@@ -71,7 +71,7 @@ class PokeBattle_AI
if target.pbCanParalyze?(user,false) &&
!(skill>=PBTrainerAI.mediumSkill &&
move.id == :THUNDERWAVE &&
PBTypes.ineffective?(pbCalcTypeMod(move.type,user,target)))
PBTypeEffectiveness.ineffective?(pbCalcTypeMod(move.type,user,target)))
score += 30
if skill>=PBTrainerAI.mediumSkill
aspeed = pbRoughStat(user,PBStats::SPEED,skill)
@@ -323,7 +323,7 @@ class PokeBattle_AI
when "021"
foundMove = false
user.eachMove do |m|
next if !isConst?(m.type,PBTypes,:ELECTRIC) || !m.damagingMove?
next if m.type != :ELECTRIC || !m.damagingMove?
foundMove = true
break
end
@@ -1280,7 +1280,7 @@ class PokeBattle_AI
else
lastMoveData = GameData::Move.get(target.lastRegularMoveUsed)
if moveBlacklist.include?(lastMoveData.function_code) ||
isConst?(lastMoveData.type, PBTypes,:SHADOW)
lastMoveData.type == :SHADOW
score -= 90
end
user.eachMove do |m|
@@ -1301,7 +1301,7 @@ class PokeBattle_AI
else
lastMoveData = GameData::Move.get(target.lastRegularMoveUsed)
if moveBlacklist.include?(lastMoveData.function_code) ||
isConst?(lastMoveData.type, PBTypes,:SHADOW)
lastMoveData.type == :SHADOW
score -= 90
end
user.eachMove do |m|
@@ -1328,23 +1328,23 @@ class PokeBattle_AI
when "05F"
if user.ability == :MULTITYPE || user.ability == :RKSSYSTEM
score -= 90
elsif !target.lastMoveUsed ||
PBTypes.isPseudoType?(GameData::Move.get(target.lastMoveUsed).type)
elsif !target.lastMoveUsed || GameData::Move.get(target.lastMoveUsed).pseudo_type
score -= 90
else
aType = -1
aType = nil
target.eachMove do |m|
next if m.id!=target.lastMoveUsed
aType = m.pbCalcType(user)
break
end
if aType<0
if !aType
score -= 90
else
types = []
for i in 0..PBTypes.maxValue
next if user.pbHasType?(i)
types.push(i) if PBTypes.resistant?(aType,i)
GameData::Type.each do |t|
next if t.pseudo_type || user.pbHasType?(t.id) ||
!PBTypes.resistant?(aType, t.id)
types.push(t.id)
end
score -= 90 if types.length==0
end
@@ -1532,7 +1532,7 @@ class PokeBattle_AI
elsif skill>=PBTrainerAI.mediumSkill && target.lastMoveUsed
moveData = GameData::Move.get(target.lastMoveUsed)
if moveData.base_damage > 0 &&
(MOVE_CATEGORY_PER_MOVE && moveData.caegory == 1) ||
(MOVE_CATEGORY_PER_MOVE && moveData.category == 1) ||
(!MOVE_CATEGORY_PER_MOVE && !PBTypes.isSpecialType?(moveData.type))
score -= 60
end
@@ -1780,7 +1780,7 @@ class PokeBattle_AI
score += 60
elsif moveData.category != 2 && # Damaging move
moveData.target == PBTargets::NearOther &&
PBTypes.ineffective?(pbCalcTypeMod(moveData.type, target, user))
PBTypeEffectiveness.ineffective?(pbCalcTypeMod(moveData.type, target, user))
score += 60
end
end
@@ -2147,7 +2147,7 @@ class PokeBattle_AI
score -= 90
else
user.eachMove do |m|
next if !m.damagingMove? || !isConst?(m.type,PBTypes,:FIRE)
next if !m.damagingMove? || m.type != :FIRE
score += 20
end
end
@@ -2160,7 +2160,7 @@ class PokeBattle_AI
score -= 90
else
user.eachMove do |m|
next if !m.damagingMove? || !isConst?(m.type,PBTypes,:WATER)
next if !m.damagingMove? || m.type != :WATER
score += 20
end
end

View File

@@ -35,30 +35,29 @@ class PokeBattle_AI
end
# Foresight
if user.hasActiveAbility?(:SCRAPPY) || target.effects[PBEffects::Foresight]
ret = PBTypeEffectiveness::NORMAL_EFFECTIVE_ONE if isConst?(defType,PBTypes,:GHOST) &&
ret = PBTypeEffectiveness::NORMAL_EFFECTIVE_ONE if defType == :GHOST &&
PBTypes.ineffective?(moveType,defType)
end
# Miracle Eye
if target.effects[PBEffects::MiracleEye]
ret = PBTypeEffectiveness::NORMAL_EFFECTIVE_ONE if isConst?(defType,PBTypes,:DARK) &&
ret = PBTypeEffectiveness::NORMAL_EFFECTIVE_ONE if defType == :DARK &&
PBTypes.ineffective?(moveType,defType)
end
# Delta Stream's weather
if @battle.pbWeather==PBWeather::StrongWinds
ret = PBTypeEffectiveness::NORMAL_EFFECTIVE_ONE if isConst?(defType,PBTypes,:FLYING) &&
ret = PBTypeEffectiveness::NORMAL_EFFECTIVE_ONE if defType == :FLYING &&
PBTypes.superEffective?(moveType,defType)
end
# Grounded Flying-type Pokémon become susceptible to Ground moves
if !target.airborne?
ret = PBTypeEffectiveness::NORMAL_EFFECTIVE_ONE if isConst?(defType,PBTypes,:FLYING) &&
isConst?(moveType,PBTypes,:GROUND)
ret = PBTypeEffectiveness::NORMAL_EFFECTIVE_ONE if defType == :FLYING && moveType == :GROUND
end
return ret
end
def pbCalcTypeMod(moveType,user,target)
return PBTypeEffectiveness::NORMAL_EFFECTIVE if moveType<0
return PBTypeEffectiveness::NORMAL_EFFECTIVE if isConst?(moveType,PBTypes,:GROUND) &&
return PBTypeEffectiveness::NORMAL_EFFECTIVE if moveType == :GROUND &&
target.pbHasType?(:FLYING) && target.hasActiveItem?(:IRONBALL)
# Determine types
tTypes = target.pbTypes(true)
@@ -91,21 +90,22 @@ class PokeBattle_AI
type = pbRoughType(move,user,skill)
typeMod = pbCalcTypeMod(type,user,target)
# Type effectiveness
return true if PBTypes.ineffective?(typeMod) || score<=0
return true if PBTypeEffectiveness.ineffective?(typeMod) || score<=0
# Immunity due to ability/item/other effects
if skill>=PBTrainerAI.mediumSkill
if isConst?(move.type,PBTypes,:GROUND)
case move.type
when :GROUND
return true if target.airborne? && !move.hitsFlyingTargets?
elsif isConst?(move.type,PBTypes,:FIRE)
when :FIRE
return true if target.hasActiveAbility?(:FLASHFIRE)
elsif isConst?(move.type,PBTypes,:WATER)
when :WATER
return true if target.hasActiveAbility?([:DRYSKIN,:STORMDRAIN,:WATERABSORB])
elsif isConst?(move.type,PBTypes,:GRASS)
when :GRASS
return true if target.hasActiveAbility?(:SAPSIPPER)
elsif isConst?(move.type,PBTypes,:ELECTRIC)
when :ELECTRIC
return true if target.hasActiveAbility?([:LIGHTNINGROD,:MOTORDRIVE,:VOLTABSORB])
end
return true if PBTypes.notVeryEffective?(typeMod) &&
return true if PBTypeEffectiveness.notVeryEffective?(typeMod) &&
target.hasActiveAbility?(:WONDERGUARD)
return true if move.damagingMove? && user.index!=target.index && !target.opposes?(user) &&
target.hasActiveAbility?(:TELEPATHY)
@@ -227,15 +227,14 @@ class PokeBattle_AI
when "0E1" # Final Gambit
baseDmg = user.hp
when "144" # Flying Press
type = getConst(PBTypes,:FLYING) || -1
if type>=0
if GameData::Type.exists?(:FLYING)
if skill>=PBTrainerAI.highSkill
targetTypes = target.pbTypes(true)
mult = PBTypes.getCombinedEffectiveness(type,
mult = PBTypes.getCombinedEffectiveness(:FLYING,
targetTypes[0],targetTypes[1],targetTypes[2])
baseDmg = (baseDmg.to_f*mult/PBTypeEffectiveness::NORMAL_EFFECTIVE).round
else
mult = PBTypes.getCombinedEffectiveness(type,
mult = PBTypes.getCombinedEffectiveness(:FLYING,
target.type1,target.type2,target.effects[PBEffects::Type3])
baseDmg = (baseDmg.to_f*mult/PBTypeEffectiveness::NORMAL_EFFECTIVE).round
end
@@ -347,8 +346,8 @@ class PokeBattle_AI
end
# Global abilities
if skill>=PBTrainerAI.mediumSkill
if (@battle.pbCheckGlobalAbility(:DARKAURA) && isConst?(type,PBTypes,:DARK)) ||
(@battle.pbCheckGlobalAbility(:FAIRYAURA) && isConst?(type,PBTypes,:FAIRY))
if (@battle.pbCheckGlobalAbility(:DARKAURA) && type == :DARK) ||
(@battle.pbCheckGlobalAbility(:FAIRYAURA) && type == :FAIRY)
if @battle.pbCheckGlobalAbility(:AURABREAK)
multipliers[BASE_DMG_MULT] *= 2/3
else
@@ -365,13 +364,13 @@ class PokeBattle_AI
# Helping Hand - n/a
# Charge
if skill>=PBTrainerAI.mediumSkill
if user.effects[PBEffects::Charge]>0 && isConst?(type,PBTypes,:ELECTRIC)
if user.effects[PBEffects::Charge]>0 && type == :ELECTRIC
multipliers[BASE_DMG_MULT] *= 2
end
end
# Mud Sport and Water Sport
if skill>=PBTrainerAI.mediumSkill
if isConst?(type,PBTypes,:ELECTRIC)
if type == :ELECTRIC
@battle.eachBattler do |b|
next if !b.effects[PBEffects::MudSport]
multipliers[BASE_DMG_MULT] /= 3
@@ -381,7 +380,7 @@ class PokeBattle_AI
multipliers[BASE_DMG_MULT] /= 3
end
end
if isConst?(type,PBTypes,:FIRE)
if type == :FIRE
@battle.eachBattler do |b|
next if !b.effects[PBEffects::WaterSport]
multipliers[BASE_DMG_MULT] /= 3
@@ -396,21 +395,15 @@ class PokeBattle_AI
if user.affectedByTerrain? && skill>=PBTrainerAI.mediumSkill
case @battle.field.terrain
when PBBattleTerrains::Electric
if isConst?(type,PBTypes,:ELECTRIC)
multipliers[BASE_DMG_MULT] *= 1.5
end
multipliers[BASE_DMG_MULT] *= 1.5 if type == :ELECTRIC
when PBBattleTerrains::Grassy
if isConst?(type,PBTypes,:GRASS)
multipliers[BASE_DMG_MULT] *= 1.5
end
multipliers[BASE_DMG_MULT] *= 1.5 if type == :GRASS
when PBBattleTerrains::Psychic
if isConst?(type,PBTypes,:PSYCHIC)
multipliers[BASE_DMG_MULT] *= 1.5
end
multipliers[BASE_DMG_MULT] *= 1.5 if type == :PSYCHIC
end
end
if target.affectedByTerrain? && skill>=PBTrainerAI.mediumSkill
if @battle.field.terrain==PBBattleTerrains::Misty && isConst?(type,PBTypes,:DRAGON)
if @battle.field.terrain==PBBattleTerrains::Misty && type == :DRAGON
multipliers[BASE_DMG_MULT] /= 2
end
end
@@ -438,15 +431,15 @@ class PokeBattle_AI
if skill>=PBTrainerAI.mediumSkill
case @battle.pbWeather
when PBWeather::Sun, PBWeather::HarshSun
if isConst?(type,PBTypes,:FIRE)
if type == :FIRE
multipliers[FINAL_DMG_MULT] *= 1.5
elsif isConst?(type,PBTypes,:WATER)
elsif type == :WATER
multipliers[FINAL_DMG_MULT] /= 2
end
when PBWeather::Rain, PBWeather::HeavyRain
if isConst?(type,PBTypes,:FIRE)
if type == :FIRE
multipliers[FINAL_DMG_MULT] /= 2
elsif isConst?(type,PBTypes,:WATER)
elsif type == :WATER
multipliers[FINAL_DMG_MULT] *= 1.5
end
when PBWeather::Sandstorm
@@ -459,7 +452,7 @@ class PokeBattle_AI
# Random variance - n/a
# STAB
if skill>=PBTrainerAI.mediumSkill
if type>=0 && user.pbHasType?(type)
if type && user.pbHasType?(type)
if user.hasActiveAbility?(:ADAPTABILITY)
multipliers[FINAL_DMG_MULT] *= 2
else
@@ -547,7 +540,7 @@ class PokeBattle_AI
if c>=0
c += 1 if move.highCriticalRate?
c += user.effects[PBEffects::FocusEnergy]
c += 1 if user.inHyperMode? && isConst?(move.type,PBTypes,:SHADOW)
c += 1 if user.inHyperMode? && move.type == :SHADOW
end
if c>=0
c = 4 if c>4