Fixed Battle Tower/Cups/Palace, fixed bug when using Metronome, fixed bad AI for Conversion/Conversion 2

This commit is contained in:
Maruno17
2021-05-04 20:36:49 +01:00
parent b563e73027
commit 3d88b85f56
10 changed files with 151 additions and 140 deletions

View File

@@ -24,8 +24,12 @@ module GameData
if optional_suffix && !optional_suffix.empty? if optional_suffix && !optional_suffix.empty?
ret = path + tr_type_data.id.to_s + optional_suffix + suffix ret = path + tr_type_data.id.to_s + optional_suffix + suffix
return ret if pbResolveBitmap(ret) return ret if pbResolveBitmap(ret)
ret = path + sprintf("%03d", tr_type_data.id_number) + optional_suffix + suffix
return ret if pbResolveBitmap(ret)
end end
ret = path + tr_type_data.id.to_s + suffix ret = path + tr_type_data.id.to_s + suffix
return ret if pbResolveBitmap(ret)
ret = path + sprintf("%03d", tr_type_data.id_number) + suffix
return (pbResolveBitmap(ret)) ? ret : nil return (pbResolveBitmap(ret)) ? ret : nil
end end

View File

@@ -1660,7 +1660,7 @@ class PokeBattle_Move_0B6 < PokeBattle_Move
def pbMoveFailed?(user,targets) def pbMoveFailed?(user,targets)
@metronomeMove = nil @metronomeMove = nil
move_keys = GameData::Move::DATA.keys.sort move_keys = GameData::Move::DATA.keys
# NOTE: You could be really unlucky and roll blacklisted moves 1000 times in # NOTE: You could be really unlucky and roll blacklisted moves 1000 times in
# a row. This is too unlikely to care about, though. # a row. This is too unlikely to care about, though.
1000.times do 1000.times do

View File

@@ -1311,23 +1311,25 @@ class PokeBattle_AI
end end
#--------------------------------------------------------------------------- #---------------------------------------------------------------------------
when "05E" when "05E"
if user.ability == :MULTITYPE || user.ability == :RKSSYSTEM if !user.canChangeType?
score -= 90 score -= 90
else else
types = [] has_possible_type = false
user.eachMove do |m| user.eachMoveWithIndex do |m,i|
next if m.id==@id break if Settings::MECHANICS_GENERATION >= 6 && i>0
next if GameData::Type.get(m.type).pseudo_type next if GameData::Type.get(m.type).pseudo_type
next if user.pbHasType?(m.type) next if user.pbHasType?(m.type)
types.push(m.type) if !types.include?(m.type) has_possible_type = true
break
end end
score -= 90 if types.length==0 score -= 90 if !has_possible_type
end end
#--------------------------------------------------------------------------- #---------------------------------------------------------------------------
when "05F" when "05F"
if user.ability == :MULTITYPE || user.ability == :RKSSYSTEM if !user.canChangeType?
score -= 90 score -= 90
elsif !target.lastMoveUsed || GameData::Move.get(target.lastMoveUsed).pseudo_type elsif !target.lastMoveUsed || !target.lastMoveUsedType ||
GameData::Type.get(target.lastMoveUsedType).pseudo_type
score -= 90 score -= 90
else else
aType = nil aType = nil
@@ -1339,13 +1341,14 @@ class PokeBattle_AI
if !aType if !aType
score -= 90 score -= 90
else else
types = [] has_possible_type = false
GameData::Type.each do |t| GameData::Type.each do |t|
next if t.pseudo_type || user.pbHasType?(t.id) || next if t.pseudo_type || user.pbHasType?(t.id) ||
!Effectiveness.resistant_type?(aType, t.id) !Effectiveness.resistant_type?(target.lastMoveUsedType, t.id)
types.push(t.id) has_possible_type = true
break
end end
score -= 90 if types.length==0 score -= 90 if !has_possible_type
end end
end end
#--------------------------------------------------------------------------- #---------------------------------------------------------------------------

View File

@@ -2,60 +2,61 @@
# #
#=============================================================================== #===============================================================================
class PokeBattle_BattlePalace < PokeBattle_Battle class PokeBattle_BattlePalace < PokeBattle_Battle
@@BattlePalaceUsualTable = [ # Percentage chances of choosing attack, defense, support moves
61, 7, 32, @@BattlePalaceUsualTable = {
20, 25, 55, :HARDY => [61, 7, 32],
70, 15, 15, :LONELY => [20, 25, 55],
38, 31, 31, :BRAVE => [70, 15, 15],
20, 70, 10, :ADAMANT => [38, 31, 31],
30, 20, 50, :NAUGHTY => [20, 70, 10],
56, 22, 22, :BOLD => [30, 20, 50],
25, 15, 60, :DOCILE => [56, 22, 22],
69, 6, 25, :RELAXED => [25, 15, 60],
35, 10, 55, :IMPISH => [69, 6, 25],
62, 10, 28, :LAX => [35, 10, 55],
58, 37, 5, :TIMID => [62, 10, 28],
34, 11, 55, :HASTY => [58, 37, 5],
35, 5, 60, :SERIOUS => [34, 11, 55],
56, 22, 22, :JOLLY => [35, 5, 60],
35, 45, 20, :NAIVE => [56, 22, 22],
44, 50, 6, :MODEST => [35, 45, 20],
56, 22, 22, :MILD => [44, 50, 6],
30, 58, 12, :QUIET => [56, 22, 22],
30, 13, 57, :BASHFUL => [30, 58, 12],
40, 50, 10, :RASH => [30, 13, 57],
18, 70, 12, :CALM => [40, 50, 10],
88, 6, 6, :GENTLE => [18, 70, 12],
42, 50, 8, :SASSY => [88, 6, 6],
56, 22, 22 :CAREFUL => [42, 50, 8],
] :QUIRKY => [56, 22, 22]
@@BattlePalacePinchTable = [ }
61, 7, 32, @@BattlePalacePinchTable = {
84, 8, 8, :HARDY => [61, 7, 32],
32, 60, 8, :LONELY => [84, 8, 8],
70, 15, 15, :BRAVE => [32, 60, 8],
70, 22, 8, :ADAMANT => [70, 15, 15],
32, 58, 10, :NAUGHTY => [70, 22, 8],
56, 22, 22, :BOLD => [32, 58, 10],
75, 15, 10, :DOCILE => [56, 22, 22],
28, 55, 17, :RELAXED => [75, 15, 10],
29, 6, 65, :IMPISH => [28, 55, 17],
30, 20, 50, :LAX => [29, 6, 65],
88, 6, 6, :TIMID => [30, 20, 50],
29, 11, 60, :HASTY => [88, 6, 6],
35, 60, 5, :SERIOUS => [29, 11, 60],
56, 22, 22, :JOLLY => [35, 60, 5],
34, 60, 6, :NAIVE => [56, 22, 22],
34, 6, 60, :MODEST => [34, 60, 6],
56, 22, 22, :MILD => [34, 6, 60],
30, 58, 12, :QUIET => [56, 22, 22],
27, 6, 67, :BASHFUL => [30, 58, 12],
25, 62, 13, :RASH => [27, 6, 67],
90, 5, 5, :CALM => [25, 62, 13],
22, 20, 58, :GENTLE => [90, 5, 5],
42, 5, 53, :SASSY => [22, 20, 58],
56, 22, 22 :CAREFUL => [42, 5, 53],
] :QUIRKY => [56, 22, 22]
}
def initialize(*arg) def initialize(*arg)
super super
@@ -92,57 +93,38 @@ class PokeBattle_BattlePalace < PokeBattle_Battle
return true return true
end end
def pbPinchChange(idxPokemon)
thispkmn = @battlers[idxPokemon]
if !thispkmn.effects[PBEffects::Pinch] && thispkmn.status != :SLEEP &&
thispkmn.hp<=thispkmn.totalhp/2
nature = thispkmn.nature
thispkmn.effects[PBEffects::Pinch] = true
case nature
when :QUIET, :BASHFUL, :NAIVE, :QUIRKY, :HARDY, :DOCILE, :SERIOUS
pbDisplay(_INTL("{1} is eager for more!",thispkmn.pbThis))
when :CAREFUL, :RASH, :LAX, :SASSY, :MILD, :TIMID
pbDisplay(_INTL("{1} began growling deeply!",thispkmn.pbThis))
when :GENTLE, :ADAMANT, :HASTY, :LONELY, :RELAXED, :NAUGHTY
pbDisplay(_INTL("A glint appears in {1}'s eyes!",thispkmn.pbThis(true)))
when :JOLLY, :BOLD, :BRAVE, :CALM, :IMPISH, :MODEST
pbDisplay(_INTL("{1} is getting into position!",thispkmn.pbThis))
end
end
end
def pbRegisterMove(idxBattler,idxMove,_showMessages=true) def pbRegisterMove(idxBattler,idxMove,_showMessages=true)
this_battler = @battlers[idxBattler] this_battler = @battlers[idxBattler]
if idxMove==-2 if idxMove==-2
@choices[idxBattler][0] = :UseMove # Move @choices[idxBattler][0] = :UseMove # "Use move"
@choices[idxBattler][1] = -2 # "Incapable of using its power..." @choices[idxBattler][1] = -2 # "Incapable of using its power..."
@choices[idxBattler][2] = @struggle @choices[idxBattler][2] = @struggle
@choices[idxBattler][3] = -1 @choices[idxBattler][3] = -1
else else
@choices[idxBattler][0] = :UseMove # Move @choices[idxBattler][0] = :UseMove # "Use move"
@choices[idxBattler][1] = idxMove # Index of move @choices[idxBattler][1] = idxMove # Index of move to be used
@choices[idxBattler][2] = this_battler.moves[idxMove] # Move object @choices[idxBattler][2] = this_battler.moves[idxMove] # PokeBattle_Move object
@choices[idxBattler][3] = -1 # No target chosen @choices[idxBattler][3] = -1 # No target chosen yet
end end
end end
def pbAutoFightMenu(idxBattler) def pbAutoFightMenu(idxBattler)
this_battler = @battlers[idxBattler] this_battler = @battlers[idxBattler]
nature = this_battler.nature nature = this_battler.nature.id
randnum = @battleAI.pbAIRandom(100) randnum = @battleAI.pbAIRandom(100)
category = 0 category = 0
atkpercent = 0 atkpercent = 0
defpercent = 0 defpercent = 0
if this_battler.effects[PBEffects::Pinch] if this_battler.effects[PBEffects::Pinch]
atkpercent = @@BattlePalacePinchTable[nature*3] atkpercent = @@BattlePalacePinchTable[nature][0]
defpercent = atkpercent+@@BattlePalacePinchTable[nature*3+1] defpercent = atkpercent+@@BattlePalacePinchTable[nature][1]
else else
atkpercent = @@BattlePalaceUsualTable[nature*3] atkpercent = @@BattlePalaceUsualTable[nature][0]
defpercent = atkpercent+@@BattlePalaceUsualTable[nature*3+1] defpercent = atkpercent+@@BattlePalaceUsualTable[nature][1]
end end
if randnum<atkpercent if randnum<atkpercent
category = 0 category = 0
elsif randnum<defpercent elsif randnum<atkpercent+defpercent
category = 1 category = 1
else else
category = 2 category = 2
@@ -163,12 +145,28 @@ class PokeBattle_BattlePalace < PokeBattle_Battle
return true return true
end end
def pbPinchChange(battler)
return if !battler || battler.fainted?
return if battler.effects[PBEffects::Pinch] || battler.status == :SLEEP
return if battler.hp > battler.totalhp / 2
nature = battler.nature.id
battler.effects[PBEffects::Pinch] = true
case nature
when :QUIET, :BASHFUL, :NAIVE, :QUIRKY, :HARDY, :DOCILE, :SERIOUS
pbDisplay(_INTL("{1} is eager for more!", battler.pbThis))
when :CAREFUL, :RASH, :LAX, :SASSY, :MILD, :TIMID
pbDisplay(_INTL("{1} began growling deeply!", battler.pbThis))
when :GENTLE, :ADAMANT, :HASTY, :LONELY, :RELAXED, :NAUGHTY
pbDisplay(_INTL("A glint appears in {1}'s eyes!", battler.pbThis(true)))
when :JOLLY, :BOLD, :BRAVE, :CALM, :IMPISH, :MODEST
pbDisplay(_INTL("{1} is getting into position!", battler.pbThis))
end
end
def pbEndOfRoundPhase def pbEndOfRoundPhase
super super
return if @decision!=0 return if @decision != 0
for i in 0...4 eachBattler { |b| pbPinchChange(b) }
pbPinchChange(i) if !@battlers[i].fainted?
end
end end
end end

View File

@@ -30,13 +30,17 @@ module PokeBattle_RecordedBattleModule
if trainer.is_a?(Array) if trainer.is_a?(Array)
ret = [] ret = []
for i in 0...trainer.length for i in 0...trainer.length
if trainer[i].is_a?(Player)
ret.push([trainer[i].trainer_type,trainer[i].name.clone,trainer[i].id,trainer[i].badges.clone]) ret.push([trainer[i].trainer_type,trainer[i].name.clone,trainer[i].id,trainer[i].badges.clone])
else # NPCTrainer
ret.push([trainer[i].trainer_type,trainer[i].name.clone,trainer[i].id])
end
end end
return ret return ret
elsif trainer[i].is_a?(Player)
return [[trainer.trainer_type,trainer.name.clone,trainer.id,trainer.badges.clone]]
else else
return [ return [[trainer.trainer_type,trainer.name.clone,trainer.id]]
[trainer.trainer_type,trainer.name.clone,trainer.id,trainer.badges.clone]
]
end end
end end
@@ -144,22 +148,21 @@ module BattlePlayerHelper
def self.pbCreateTrainerInfo(trainer) def self.pbCreateTrainerInfo(trainer)
return nil if !trainer return nil if !trainer
if trainer.length>1
ret = [] ret = []
ret[0]=Player.new(trainer[0][1],trainer[0][0]) trainer.each do |tr|
ret[0].id = trainer[0][2] if tr.length == 4 # Player
ret[0].badges = trainer[0][3] t = Player.new(tr[1], tr[0])
ret[1] = Player.new(trainer[1][1],trainer[1][0]) t.id = tr[2]
ret[1].id = trainer[1][2] t.badges = tr[3]
ret[1].badges = trainer[1][3] ret.push(t)
return ret else # NPCTrainer
else t = NPCTrainer.new(tr[1], tr[0])
ret = Player.new(trainer[0][1],trainer[0][0]) t.id = tr[2]
ret.id = trainer[0][2] ret.push(t)
ret.badges = trainer[0][3]
return ret
end end
end end
return ret
end
end end

View File

@@ -748,9 +748,10 @@ class PokemonParty_Scene
end end
when Input::UP when Input::UP
if currentsel >= Settings::MAX_PARTY_SIZE if currentsel >= Settings::MAX_PARTY_SIZE
begin
currentsel -= 1 currentsel -= 1
end while currentsel > 0 && !@party[currentsel] while currentsel > 0 && currentsel < Settings::MAX_PARTY_SIZE && !@party[currentsel]
currentsel -= 1
end
else else
begin begin
currentsel -= 2 currentsel -= 2

View File

@@ -22,10 +22,10 @@ class PBPokemon
itm = GameData::Item.try_get(item) itm = GameData::Item.try_get(item)
@item = itm ? itm.id : nil @item = itm ? itm.id : nil
@nature = nature @nature = nature
@move1 = move1 ? move1 : 0 @move1 = move1 ? move1 : nil
@move2 = move2 ? move2 : 0 @move2 = move2 ? move2 : nil
@move3 = move3 ? move3 : 0 @move3 = move3 ? move3 : nil
@move4 = move4 ? move4 : 0 @move4 = move4 ? move4 : nil
@ev = ev @ev = ev
end end
@@ -55,7 +55,9 @@ class PBPokemon
move_data = GameData::Move.try_get(moves[i]) move_data = GameData::Move.try_get(moves[i])
moveid.push(move_data.id) if move_data moveid.push(move_data.id) if move_data
end end
moveid=[GameData::Move.get(1)] if moveid.length==0 if moveid.length==0
GameData::Move.each { |mov| moveid.push(mov.id); break }
end
return self.new(species, item, nature, moveid[0], moveid[1], moveid[2], moveid[3], ev_array) return self.new(species, item, nature, moveid[0], moveid[1], moveid[2], moveid[3], ev_array)
end end
@@ -154,9 +156,7 @@ class PBPokemon
pokemon=Pokemon.new(@species,level,trainer,false) pokemon=Pokemon.new(@species,level,trainer,false)
pokemon.item = @item pokemon.item = @item
pokemon.personalID = rand(2**16) | rand(2**16) << 16 pokemon.personalID = rand(2**16) | rand(2**16) << 16
pokemon.personalID -= pokemon.personalID % 25 pokemon.nature = nature
pokemon.personalID += nature
pokemon.personalID &= 0xFFFFFFFF
pokemon.happiness=0 pokemon.happiness=0
pokemon.moves[0] = Pokemon::Move.new(self.convertMove(@move1)) pokemon.moves[0] = Pokemon::Move.new(self.convertMove(@move1))
pokemon.moves[1] = Pokemon::Move.new(self.convertMove(@move2)) pokemon.moves[1] = Pokemon::Move.new(self.convertMove(@move2))
@@ -468,7 +468,7 @@ class BattleChallenge
end end
def start(*args) def start(*args)
ensureType(@id) t = ensureType(@id)
@currentChallenge=@id # must appear before pbStart @currentChallenge=@id # must appear before pbStart
@bc.pbStart(t,@numRounds) @bc.pbStart(t,@numRounds)
end end
@@ -680,8 +680,9 @@ end
def pbBattleChallengeGraphic(event) def pbBattleChallengeGraphic(event)
nextTrainer=pbBattleChallenge.nextTrainer nextTrainer=pbBattleChallenge.nextTrainer
bttrainers=pbGetBTTrainers(pbBattleChallenge.currentChallenge) bttrainers=pbGetBTTrainers(pbBattleChallenge.currentChallenge)
filename=GameData::TrainerType.charset_filename_brief((bttrainers[nextTrainer][0] rescue 0)) filename=GameData::TrainerType.charset_filename_brief((bttrainers[nextTrainer][0] rescue nil))
begin begin
filename = "NPC 01" if nil_or_empty?(filename)
bitmap=AnimatedBitmap.new("Graphics/Characters/"+filename) bitmap=AnimatedBitmap.new("Graphics/Characters/"+filename)
bitmap.dispose bitmap.dispose
event.character_name=filename event.character_name=filename

View File

@@ -1,5 +1,5 @@
def pbRandomMove def pbRandomMove
keys = GameData::Move::DATA.keys.sort keys = GameData::Move::DATA.keys
loop do loop do
move_id = keys[rand(keys.length)] move_id = keys[rand(keys.length)]
move = GameData::Move.get(move_id) move = GameData::Move.get(move_id)
@@ -249,7 +249,7 @@ def pbRandomPokemonFromRule(rule,trainer)
iteration+=1 iteration+=1
species=nil species=nil
level=rule.ruleset.suggestedLevel level=rule.ruleset.suggestedLevel
keys = GameData::Species::DATA.keys.sort keys = GameData::Species::DATA.keys
loop do loop do
loop do loop do
species = keys[rand(keys.length)] species = keys[rand(keys.length)]
@@ -910,9 +910,10 @@ def pbTrainerInfo(pokemonlist,trfile,rules)
if GameData::TrainerType.exists?(:YOUNGSTER) && rand(30) == 0 if GameData::TrainerType.exists?(:YOUNGSTER) && rand(30) == 0
trainerid = :YOUNGSTER trainerid = :YOUNGSTER
else else
tr_type_values = GameData::TrainerType::DATA.values tr_typekeys = GameData::TrainerType::DATA.keys
loop do loop do
tr_type_data = tr_type_values[rand(tr_type_values.length)] tr_type = tr_typekeys[rand(tr_typekeys.length)]
tr_type_data = GameData::TrainerType.get(tr_type)
next if tr_type_data.base_money >= 100 next if tr_type_data.base_money >= 100
trainerid = tr_type_data.id trainerid = tr_type_data.id
end end

View File

@@ -89,19 +89,19 @@ end
# Unused # Unused
def hasConst?(mod,constant) def hasConst?(mod,constant)
return false if !mod || nil_or_empty?(constant) return false if !mod || constant.nil?
return mod.const_defined?(constant.to_sym) rescue false return mod.const_defined?(constant.to_sym) rescue false
end end
# Unused # Unused
def getConst(mod,constant) def getConst(mod,constant)
return nil if !mod || nil_or_empty?(constant) return nil if !mod || constant.nil?
return mod.const_get(constant.to_sym) rescue nil return mod.const_get(constant.to_sym) rescue nil
end end
# Unused # Unused
def getID(mod,constant) def getID(mod,constant)
return nil if !mod || nil_or_empty?(constant) return nil if !mod || constant.nil?
if constant.is_a?(Symbol) || constant.is_a?(String) if constant.is_a?(Symbol) || constant.is_a?(String)
if (mod.const_defined?(constant.to_sym) rescue false) if (mod.const_defined?(constant.to_sym) rescue false)
return mod.const_get(constant.to_sym) rescue 0 return mod.const_get(constant.to_sym) rescue 0

View File

@@ -925,7 +925,7 @@ module Compiler
end end
new_format = true new_format = true
values = $~[1].split(',').collect! { |v| v.strip.to_i } values = $~[1].split(',').collect! { |v| v.strip.to_i }
values[1] = 0 if nil_or_empty?(values[1]) values[1] = 0 if !values[1]
map_number = values[0] map_number = values[0]
map_version = values[1] map_version = values[1]
# Add map encounter's data to records # Add map encounter's data to records