randomizer - trainer teams

This commit is contained in:
infinitefusion
2022-05-01 10:11:56 -04:00
parent dd05aa1f1c
commit 2365dfeb51
7 changed files with 155 additions and 118 deletions

Binary file not shown.

View File

@@ -70,6 +70,10 @@ module GameData
return (self::DATA.has_key?(key)) ? self::DATA[key] : nil return (self::DATA.has_key?(key)) ? self::DATA[key] : nil
end end
def self.list_all()
return self::DATA
end
def initialize(hash) def initialize(hash)
@id = hash[:id] @id = hash[:id]
@id_number = hash[:id_number] @id_number = hash[:id_number]
@@ -110,6 +114,15 @@ module GameData
end end
end end
def replace_species_to_randomized(species,trainerId,pokemonIndex)
return species if $game_switches[SWITCH_FIRST_RIVAL_BATTLE]
if $PokemonGlobal.randomTrainersHash[trainerId] == nil
Kernel.pbMessage(_INTL("The trainers need to be re-shuffled."))
Kernel.pbShuffleTrainers()
end
new_species_dex = $PokemonGlobal.randomTrainersHash[trainerId][pokemonIndex]
return getSpecies(new_species_dex)
end
def replaceSingleSpeciesModeIfApplicable(species) def replaceSingleSpeciesModeIfApplicable(species)
if $game_switches[SWITCH_SINGLE_POKEMON_MODE] if $game_switches[SWITCH_SINGLE_POKEMON_MODE]
@@ -150,6 +163,8 @@ module GameData
return species return species
end end
def to_trainer def to_trainer
placeholder_species = [Settings::RIVAL_STARTER_PLACEHOLDER_SPECIES, placeholder_species = [Settings::RIVAL_STARTER_PLACEHOLDER_SPECIES,
Settings::VAR_1_PLACEHOLDER_SPECIES, Settings::VAR_1_PLACEHOLDER_SPECIES,
@@ -173,9 +188,11 @@ module GameData
rematchId = getRematchId(trainer.name, trainer.trainer_type) rematchId = getRematchId(trainer.name, trainer.trainer_type)
# Create each Pokémon owned by the trainer # Create each Pokémon owned by the trainer
index = 0
@pokemon.each do |pkmn_data| @pokemon.each do |pkmn_data|
#replace placeholder species infinite fusion edit #replace placeholder species infinite fusion edit
species = GameData::Species.get(pkmn_data[:species]).species species = GameData::Species.get(pkmn_data[:species]).species
species = replace_species_to_randomized(species,self.id,index) if isPlayingRandomized
if placeholder_species.include?(species) if placeholder_species.include?(species)
species = replace_species_with_placeholder(species) species = replace_species_with_placeholder(species)
end end
@@ -252,6 +269,8 @@ module GameData
end end
pkmn.poke_ball = pkmn_data[:poke_ball] if pkmn_data[:poke_ball] pkmn.poke_ball = pkmn_data[:poke_ball] if pkmn_data[:poke_ball]
pkmn.calc_stats pkmn.calc_stats
index +=1
end end
return trainer return trainer
end end

View File

@@ -45,7 +45,7 @@ def generate_random_species(max_bst)
while (species==0) # Loop Start while (species==0) # Loop Start
bonus+= 5 #+ de chance de pogner un bon poke a chaque loop (permet d'eviter infinite loop) bonus+= 5 #+ de chance de pogner un bon poke a chaque loop (permet d'eviter infinite loop)
species=rand(PBSpecies.maxValue)+1 species=rand(PBSpecies.maxValue)+1
bst = calcBaseStats(species) bst = calcBaseStatsSum(species)
species=0 if bst > max_bst+additional_bst species=0 if bst > max_bst+additional_bst
end end
return species return species

View File

@@ -117,20 +117,20 @@ end
####methodes utilitaires ####methodes utilitaires
def getBaseStats(species) # def getBaseStats(species)
basestatsum = $pkmn_dex[species][5][0] # HP # basestatsum = $pkmn_dex[species][5][0] # HP
basestatsum +=$pkmn_dex[species][5][1] # Attack # basestatsum +=$pkmn_dex[species][5][1] # Attack
basestatsum +=$pkmn_dex[species][5][2] # Defense # basestatsum +=$pkmn_dex[species][5][2] # Defense
basestatsum +=$pkmn_dex[species][5][3] # Speed # basestatsum +=$pkmn_dex[species][5][3] # Speed
basestatsum +=$pkmn_dex[species][5][4] # Special Attack # basestatsum +=$pkmn_dex[species][5][4] # Special Attack
basestatsum +=$pkmn_dex[species][5][5] # Special Defense # basestatsum +=$pkmn_dex[species][5][5] # Special Defense
return basestatsum # return basestatsum
end # end
#
def bstOk(newspecies,oldPokemonSpecies,bst_range=50) def bstOk(newspecies,oldPokemonSpecies,bst_range=50)
newBST = getBaseStats(newspecies) newBST = calcBaseStatsSum(newspecies)
originalBST = getBaseStats(oldPokemonSpecies) originalBST = calcBaseStatsSum(oldPokemonSpecies)
return newBST < originalBST-bst_range || newBST > originalBST+bst_range return newBST < originalBST-bst_range || newBST > originalBST+bst_range
end end
@@ -283,31 +283,24 @@ def Kernel.pbRandomizeTM()
end end
def getNewSpecies(oldSpecies,bst_range=50, ignoreRivalPlaceholder = false, maxDexNumber = PBSpecies.maxValue ) def getNewSpecies(oldSpecies,bst_range=50, ignoreRivalPlaceholder = false, maxDexNumber = PBSpecies.maxValue )
return oldSpecies if (oldSpecies == RIVAL_STARTER_PLACEHOLDER_SPECIES && !ignoreRivalPlaceholder) return oldSpecies if (oldSpecies == Settings::RIVAL_STARTER_PLACEHOLDER_SPECIES && !ignoreRivalPlaceholder)
return oldSpecies if oldSpecies >= NUM_ZAPMOLCUNO return oldSpecies if oldSpecies >= Settings::ZAPMOLCUNO_NB
newspecies = rand(maxDexNumber - 1) + 1 newspecies = rand(maxDexNumber - 1) + 1
newBST = Kernel.getBaseStats(newspecies)
originalBST = Kernel.getBaseStats(oldSpecies)
while bstOk(newspecies,oldSpecies,bst_range) while bstOk(newspecies,oldSpecies,bst_range)
newspecies = rand(maxDexNumber - 1) + 1 newspecies = rand(maxDexNumber - 1) + 1
newBST = Kernel.getBaseStats(newspecies)
end end
return newspecies return newspecies
end end
def getNewCustomSpecies(oldSpecies,customSpeciesList,bst_range=50, ignoreRivalPlaceholder = false) def getNewCustomSpecies(oldSpecies,customSpeciesList,bst_range=50, ignoreRivalPlaceholder = false)
return oldSpecies if (oldSpecies == RIVAL_STARTER_PLACEHOLDER_SPECIES && !ignoreRivalPlaceholder) return oldSpecies if (oldSpecies == Settings::RIVAL_STARTER_PLACEHOLDER_SPECIES && !ignoreRivalPlaceholder)
return oldSpecies if oldSpecies >= NUM_ZAPMOLCUNO return oldSpecies if oldSpecies >= Settings::ZAPMOLCUNO_NB
i = rand(customSpeciesList.length - 1) + 1 i = rand(customSpeciesList.length - 1) + 1
newspecies = customSpeciesList[i] newspecies = customSpeciesList[i]
newBST = Kernel.getBaseStats(newspecies)
originalBST = Kernel.getBaseStats(oldSpecies)
while bstOk(newspecies,oldSpecies,bst_range) while bstOk(newspecies,oldSpecies,bst_range)
i = rand(customSpeciesList.length - 1)#+1 i = rand(customSpeciesList.length - 1)#+1
newspecies = customSpeciesList[i] newspecies = customSpeciesList[i]
newBST = Kernel.getBaseStats(newspecies)
end end
return newspecies return newspecies
end end
@@ -321,29 +314,54 @@ end
def Kernel.pbShuffleTrainers(bst_range = 50) def Kernel.pbShuffleTrainers(bst_range = 50,customsOnly=false,customsList=nil)
if customsOnly && customsList == nil
customsOnly = false
end
randomTrainersHash = Hash.new randomTrainersHash = Hash.new
trainers_data = GameData::Trainer.list_all
trainers=load_data("Data/trainers.dat") trainers_data.each do |key, value|
i=0 trainer = trainers_data[key]
for trainer in trainers i=0
for poke in trainer[3] new_party = []
poke[TPSPECIES]=getNewSpecies(poke[TPSPECIES]) for poke in trainer.pokemon
old_poke = GameData::Species.get(poke[:species]).id_number
new_poke = customsOnly ? getNewCustomSpecies(old_poke,customsList) : getNewSpecies(old_poke)
new_party << new_poke
end end
randomTrainersHash[i] = (trainer) randomTrainersHash[trainer.id] = new_party
playShuffleSE(i) playShuffleSE(i)
i += 1 i += 1
if i % 2 == 0 if i % 2 == 0
n = (i.to_f/trainers.length)*100 n = (i.to_f/trainers.length)*100
Kernel.pbMessageNoSound(_INTL("\\ts[]Shuffling trainers...\\n {1}%\\^",sprintf('%.2f', n),PBSpecies.maxValue)) Kernel.pbMessageNoSound(_INTL("\\ts[]Shuffling trainers...\\n {1}%\\^",sprintf('%.2f', n),PBSpecies.maxValue))
end end
#Kernel.pbMessage(_INTL("pushing trainer {1}: {2} ",i,trainer))
end end
$PokemonGlobal.randomTrainersHash = randomTrainersHash $PokemonGlobal.randomTrainersHash = randomTrainersHash
end end
# def Kernel.pbShuffleTrainers(bst_range = 50)
# randomTrainersHash = Hash.new
#
# trainers=load_data("Data/trainers.dat")
# i=0
# for trainer in trainers
# for poke in trainer[3]
# poke[TPSPECIES]=getNewSpecies(poke[TPSPECIES])
# end
# randomTrainersHash[i] = (trainer)
# playShuffleSE(i)
# i += 1
# if i % 2 == 0
# n = (i.to_f/trainers.length)*100
# Kernel.pbMessageNoSound(_INTL("\\ts[]Shuffling trainers...\\n {1}%\\^",sprintf('%.2f', n),PBSpecies.maxValue))
# end
# #Kernel.pbMessage(_INTL("pushing trainer {1}: {2} ",i,trainer))
# end
# $PokemonGlobal.randomTrainersHash = randomTrainersHash
# end
def Kernel.pbShuffleTrainersCustom()(bst_range = 50) def Kernel.pbShuffleTrainersCustom(bst_range = 50)
randomTrainersHash = Hash.new randomTrainersHash = Hash.new
Kernel.pbMessage(_INTL("Parsing custom sprites folder")) Kernel.pbMessage(_INTL("Parsing custom sprites folder"))
@@ -359,32 +377,32 @@ def Kernel.pbShuffleTrainersCustom()(bst_range = 50)
bst_range=999 bst_range=999
else else
Kernel.pbMessage(_INTL("Trainer Pokémon will include auto-generated sprites.")) Kernel.pbMessage(_INTL("Trainer Pokémon will include auto-generated sprites."))
return Kernel.pbShuffleTrainers(bst_range) return Kernel.pbShuffleTrainers(bst_range) ##use regular shuffle if not enough sprites
end end
end end
Kernel.pbShuffleTrainers(bst_range,true ,customsList)
##use regular shuffle if not enough sprites
trainers=load_data("Data/trainers.dat")
i=0
for trainer in trainers
for poke in trainer[3]
poke[TPSPECIES]=getNewCustomSpecies(poke[TPSPECIES],customsList)
end
randomTrainersHash[i] = (trainer)
playShuffleSE(i)
i += 1
if i % 2 == 0
n = (i.to_f/trainers.length)*100
Kernel.pbMessageNoSound(_INTL("\\ts[]Shuffling trainers (custom sprites only)...\\n {1}%\\^",sprintf('%.2f', n),PBSpecies.maxValue))
end
#Kernel.pbMessage(_INTL("pushing trainer {1}: {2} ",i,trainer))
end
$PokemonGlobal.randomTrainersHash = randomTrainersHash
end end
# trainers=load_data("Data/trainers.dat")
# i=0
# for trainer in trainers
# for poke in trainer[3]
# poke[TPSPECIES]=getNewCustomSpecies(poke[TPSPECIES],customsList)
# end
# randomTrainersHash[i] = (trainer)
# playShuffleSE(i)
# i += 1
# if i % 2 == 0
# n = (i.to_f/trainers.length)*100
# Kernel.pbMessageNoSound(_INTL("\\ts[]Shuffling trainers (custom sprites only)...\\n {1}%\\^",sprintf('%.2f', n),PBSpecies.maxValue))
# end
# #Kernel.pbMessage(_INTL("pushing trainer {1}: {2} ",i,trainer))
# end
# $PokemonGlobal.randomTrainersHash = randomTrainersHash
#def getRandomCustomSprite() #def getRandomCustomSprite()
# filesList = Dir["./Graphics/CustomBattlers/*"] # filesList = Dir["./Graphics/CustomBattlers/*"]
# i = rand(filesList.length-1) # i = rand(filesList.length-1)

View File

@@ -126,61 +126,61 @@ def getBaseStatsFormattedForRandomizer(dex_num)
return statsArray return statsArray
end end
def Kernel.pbShuffleDexTrainers() # def Kernel.pbShuffleDexTrainers()
# create hash # # create hash
psuedoHash = Hash.new # psuedoHash = Hash.new
psuedoBSTHash = Hash.new # psuedoBSTHash = Hash.new
#
#Create array of all pokemon dex numbers # #Create array of all pokemon dex numbers
pokeArray = [] # pokeArray = []
for i in 1..PBSpecies.maxValue # for i in 1..PBSpecies.maxValue
pokeArray.push(i) # pokeArray.push(i)
end # end
#randomize hash # #randomize hash
pokeArrayRand = pokeArray.dup # pokeArrayRand = pokeArray.dup
pokeArrayRand.shuffle! # pokeArrayRand.shuffle!
pokeArray.insert(0,nil) # pokeArray.insert(0,nil)
# fill random hash # # fill random hash
#random hash will have to be accessed by number, not internal name # #random hash will have to be accessed by number, not internal name
for i in 1...pokeArrayRand.length # for i in 1...pokeArrayRand.length
psuedoHash[i]=pokeArrayRand[i] # psuedoHash[i]=pokeArrayRand[i]
end # end
#
#use pokeArrayRand to fill in the BST hash also # #use pokeArrayRand to fill in the BST hash also
#loop through the actual dex, and use the first mon in pokeArrayRand with # #loop through the actual dex, and use the first mon in pokeArrayRand with
#BST in the same 100 range # #BST in the same 100 range
for i in 1..PBSpecies.maxValue # for i in 1..PBSpecies.maxValue
if i % 20 == 0 # if i % 20 == 0
n = (i.to_f/PBSpecies.maxValue)*100 # n = (i.to_f/PBSpecies.maxValue)*100
#Kernel.pbMessage(_INTL("\\ts[]Shuffling...\\n {1}%\\^",sprintf('%.2f', n),PBSpecies.maxValue)) # #Kernel.pbMessage(_INTL("\\ts[]Shuffling...\\n {1}%\\^",sprintf('%.2f', n),PBSpecies.maxValue))
end # end
#
baseStats=calcBaseStats(i) # baseStats=calcBaseStats(i)
baseStat_target = 0 # baseStat_target = 0
for k in 0...baseStats.length # for k in 0...baseStats.length
baseStat_target+=baseStats[k] # baseStat_target+=baseStats[k]
end # end
baseStat_target = (baseStat_target/50).floor # baseStat_target = (baseStat_target/50).floor
for j in 1...pokeArrayRand.length # for j in 1...pokeArrayRand.length
baseStats=calcBaseStats([pokeArrayRand[j]]) # baseStats=calcBaseStats([pokeArrayRand[j]])
baseStat_temp = 0 # baseStat_temp = 0
for l in 0...baseStats.length # for l in 0...baseStats.length
baseStat_temp+=baseStats[l] # baseStat_temp+=baseStats[l]
end # end
baseStat_temp = (baseStat_temp/50).floor # baseStat_temp = (baseStat_temp/50).floor
#if a match, add to hash, remove from array, and cycle to next poke in dex # #if a match, add to hash, remove from array, and cycle to next poke in dex
if baseStat_temp == baseStat_target # if baseStat_temp == baseStat_target
psuedoBSTHash[i]=pokeArrayRand[j] # psuedoBSTHash[i]=pokeArrayRand[j]
pokeArrayRand.delete(pokeArrayRand[j]) # pokeArrayRand.delete(pokeArrayRand[j])
break # break
end # end
end # end
end # end
#
#add hashes to global data0 # #add hashes to global data0
#$PokemonGlobal.psuedoHash = psuedoHash # #$PokemonGlobal.psuedoHash = psuedoHash
$PokemonGlobal.pseudoBSTHashTrainers = psuedoBSTHash # $PokemonGlobal.pseudoBSTHashTrainers = psuedoBSTHash
end # end
def getRandomizedTo(species) def getRandomizedTo(species)
return species if !$PokemonGlobal.psuedoBSTHash return species if !$PokemonGlobal.psuedoBSTHash

View File

@@ -64,7 +64,7 @@ def pbWonderTrade(lvl, except = [], except2 = [], premiumWonderTrade = true)
poke = $Trainer.party[pbGet(1)] poke = $Trainer.party[pbGet(1)]
$PokemonBag.pbStoreItem(poke.item, 1) if poke.item != nil $PokemonBag.pbStoreItem(poke.item, 1) if poke.item != nil
myPoke = poke.species myPoke = poke.species
chosenBST = calcBaseStats(myPoke) chosenBST = calcBaseStatsSum(myPoke)
# The following excecption fields are for hardcoding the blacklisted pokemon # The following excecption fields are for hardcoding the blacklisted pokemon
# without adding them in the events. # without adding them in the events.
#except+=[] #except+=[]
@@ -78,7 +78,7 @@ def pbWonderTrade(lvl, except = [], except2 = [], premiumWonderTrade = true)
bonus += 5 #+ de chance de pogner un bon poke a chaque loop (permet d'eviter infinite loop) bonus += 5 #+ de chance de pogner un bon poke a chaque loop (permet d'eviter infinite loop)
species = rand(PBSpecies.maxValue) + 1 species = rand(PBSpecies.maxValue) + 1
bst = calcBaseStats(species) bst = calcBaseStatsSum(species)
# Redo the loop if pokemon is too evolved for its level # Redo the loop if pokemon is too evolved for its level
#species=0 if lvl < pbGetMinimumLevel(species)# && pbGetPreviousForm(species) != species # && pbGetPreviousForm(species)!=species #species=0 if lvl < pbGetMinimumLevel(species)# && pbGetPreviousForm(species) != species # && pbGetPreviousForm(species)!=species
# Redo the loop if the species is an exception. # Redo the loop if the species is an exception.
@@ -146,7 +146,7 @@ def pbGRS(minBST, chosenBST, luck, rare, except2)
bonus += 5 #+ de chance de pogner un bon poke a chaque loop (permet d'eviter infinite loop) bonus += 5 #+ de chance de pogner un bon poke a chaque loop (permet d'eviter infinite loop)
species = rand(PBSpecies.maxValue) + 1 species = rand(PBSpecies.maxValue) + 1
bst = calcBaseStats(species) bst = calcBaseStatsSum(species)
# Redo the loop if pokemon is too evolved for its level # Redo the loop if pokemon is too evolved for its level
#species=0 if lvl < pbGetMinimumLevel(species)# && pbGetPreviousForm(species) != species # && pbGetPreviousForm(species)!=species #species=0 if lvl < pbGetMinimumLevel(species)# && pbGetPreviousForm(species) != species # && pbGetPreviousForm(species)!=species
# Redo the loop if the species is an exception. # Redo the loop if the species is an exception.
@@ -172,7 +172,7 @@ end
def calcBaseStats(species) def calcBaseStatsSum(species)
stats = GameData::Species.get(species).base_stats stats = GameData::Species.get(species).base_stats
sum = 0 sum = 0
sum += stats[:HP] sum += stats[:HP]

Binary file not shown.