Fixed crash when using upgradeRibbon, fixed crash when trading Pokémon, fixed crash when trying to play Triple Triad, fixed crash when generating Battle Frontier data

This commit is contained in:
Maruno17
2021-12-11 13:25:23 +00:00
parent b9d69b780b
commit 241851a75b
4 changed files with 16 additions and 17 deletions

View File

@@ -740,20 +740,20 @@ class Pokemon
# Replaces one ribbon with the next one along, if possible. If none of the
# given ribbons are owned, give the first one.
# @return [Symbol, String, GameData::Ribbon] ID of the ribbon that was gained
def upgradeRibbon(*arg)
for i in 0...arg.length - 1
this_ribbon_data = GameData::Ribbon.try_get(i)
def upgradeRibbon(*args)
args.each_with_index do |ribbon, i|
this_ribbon_data = GameData::Ribbon.try_get(ribbon)
next if !this_ribbon_data
for j in 0...@ribbons.length
next if @ribbons[j] != this_ribbon_data.id
next_ribbon_data = GameData::Ribbon.try_get(arg[i + 1])
next_ribbon_data = GameData::Ribbon.try_get(args[i + 1])
next if !next_ribbon_data
@ribbons[j] = next_ribbon_data.id
return @ribbons[j]
end
end
first_ribbon_data = GameData::Ribbon.try_get(arg[0])
last_ribbon_data = GameData::Ribbon.try_get(arg[arg.length - 1])
first_ribbon_data = GameData::Ribbon.try_get(args.first)
last_ribbon_data = GameData::Ribbon.try_get(args.last)
if first_ribbon_data && last_ribbon_data && !hasRibbon?(last_ribbon_data.id)
giveRibbon(first_ribbon_data.id)
return first_ribbon_data.id

View File

@@ -200,18 +200,17 @@ end
def pbStartTrade(pokemonIndex,newpoke,nickname,trainerName,trainerGender=0)
$stats.trade_count += 1
myPokemon = $player.party[pokemonIndex]
opponent = NPCTrainer.new(trainerName,trainerGender)
opponent.id = $player.make_foreign_ID
yourPokemon = nil
resetmoves = true
if newpoke.is_a?(Pokemon)
newpoke.owner = Pokemon::Owner.new_from_trainer(opponent)
newpoke.owner = Pokemon::Owner.new_foreign(trainerName, trainerGender)
yourPokemon = newpoke
resetmoves = false
else
species_data = GameData::Species.try_get(newpoke)
raise _INTL("Species does not exist ({1}).", newpoke) if !species_data
yourPokemon = Pokemon.new(species_data.id, myPokemon.level, opponent)
raise _INTL("Species {1} does not exist.", newpoke) if !species_data
yourPokemon = Pokemon.new(species_data.id, myPokemon.level)
yourPokemon.owner = Pokemon::Owner.new_foreign(trainerName, trainerGender)
end
yourPokemon.name = nickname
yourPokemon.obtain_method = 2 # traded
@@ -221,7 +220,7 @@ def pbStartTrade(pokemonIndex,newpoke,nickname,trainerName,trainerGender=0)
$player.pokedex.set_owned(yourPokemon.species)
pbFadeOutInWithMusic {
evo = PokemonTrade_Scene.new
evo.pbStartScreen(myPokemon, yourPokemon, $player.name, opponent.name)
evo.pbStartScreen(myPokemon, yourPokemon, $player.name, trainerName)
evo.pbTrade
evo.pbEndScreen
}

View File

@@ -730,7 +730,7 @@ class TriadScreen
square = TriadSquare.new
if @elements
loop do
trial_type = type_keys[type_keys.sample]
trial_type = type_keys.sample
type_data = GameData::Type.get(trial_type)
next if type_data.pseudo_type
square.type = type_data.id
@@ -774,7 +774,7 @@ class TriadScreen
species_keys = GameData::Species.keys
candidates = []
while candidates.length < 200
card = species_keys[species_keys.sample]
card = species_keys.sample
card_data = GameData::Species.get(card)
card = card_data.id # Make sure it's a symbol
triad = TriadCard.new(card)

View File

@@ -132,10 +132,10 @@ def isBattlePokemonDuplicate(pk, pk2)
moves1.push((pk.moves[i]) ? pk.moves[i].id : nil)
moves2.push((pk2.moves[i]) ? pk2.moves[i].id : nil)
end
moves1.sort!
moves2.sort!
moves1.compact.sort
moves2.compact.sort
# Accept as same if moves are same and there are MAX_MOVES number of moves each
return true if moves1 == moves2 && moves1[Pokemon::MAX_MOVES - 1]
return true if moves1 == moves2 && moves1.length == Pokemon::MAX_MOVES
same_evs = true
GameData::Stat.each_main { |s| same_evs = false if pk.ev[s.id] != pk2.ev[s.id] }
return pk.item_id == pk2.item_id && pk.nature_id == pk2.nature_id && same_evs