Moved trainer data constants into module TrainerData

This commit is contained in:
Maruno17
2020-10-17 00:45:39 +01:00
parent c30e302ccf
commit 2b4f1e1aba
5 changed files with 113 additions and 113 deletions

View File

@@ -1,43 +1,43 @@
#=============================================================================== #===============================================================================
# Trainers data # Trainer data
#=============================================================================== #===============================================================================
TPSPECIES = 0 module TrainerData
TPLEVEL = 1 SPECIES = 0
TPITEM = 2 LEVEL = 1
TPMOVES = 3 ITEM = 2
TPABILITY = 4 MOVES = 3
TPGENDER = 5 ABILITY = 4
TPFORM = 6 GENDER = 5
TPSHINY = 7 FORM = 6
TPNATURE = 8 SHINY = 7
TPIV = 9 NATURE = 8
TPHAPPINESS = 10 IV = 9
TPNAME = 11 HAPPINESS = 10
TPSHADOW = 12 NAME = 11
TPBALL = 13 SHADOW = 12
TPEV = 14 BALL = 13
TPLOSETEXT = 15 EV = 14
LOSETEXT = 15
module TrainersMetadata SCHEMA = {
InfoTypes = {
"Items" => [0, "eEEEEEEE", :PBItems, :PBItems, :PBItems, :PBItems, "Items" => [0, "eEEEEEEE", :PBItems, :PBItems, :PBItems, :PBItems,
:PBItems, :PBItems, :PBItems, :PBItems], :PBItems, :PBItems, :PBItems, :PBItems],
"Pokemon" => [TPSPECIES, "ev", :PBSpecies,nil], # Species, level "Pokemon" => [SPECIES, "ev", :PBSpecies, nil], # Species, level
"Item" => [TPITEM, "e", :PBItems], "Item" => [ITEM, "e", :PBItems],
"Moves" => [TPMOVES, "eEEE", :PBMoves, :PBMoves, :PBMoves, :PBMoves], "Moves" => [MOVES, "eEEE", :PBMoves, :PBMoves, :PBMoves, :PBMoves],
"Ability" => [TPABILITY, "u"], "Ability" => [ABILITY, "u"],
"Gender" => [TPGENDER, "e", { "M" => 0, "m" => 0, "Male" => 0, "male" => 0, "0" => 0, "Gender" => [GENDER, "e", { "M" => 0, "m" => 0, "Male" => 0, "male" => 0, "0" => 0,
"F" => 1, "f" => 1, "Female" => 1, "female" => 1, "1" => 1 }], "F" => 1, "f" => 1, "Female" => 1, "female" => 1, "1" => 1 }],
"Form" => [TPFORM, "u"], "Form" => [FORM, "u"],
"Shiny" => [TPSHINY, "b"], "Shiny" => [SHINY, "b"],
"Nature" => [TPNATURE, "e", :PBNatures], "Nature" => [NATURE, "e", :PBNatures],
"IV" => [TPIV, "uUUUUU"], "IV" => [IV, "uUUUUU"],
"Happiness" => [TPHAPPINESS, "u"], "Happiness" => [HAPPINESS, "u"],
"Name" => [TPNAME, "s"], "Name" => [NAME, "s"],
"Shadow" => [TPSHADOW, "b"], "Shadow" => [SHADOW, "b"],
"Ball" => [TPBALL, "u"], "Ball" => [BALL, "u"],
"EV" => [TPEV, "uUUUUU"], "EV" => [EV, "uUUUUU"],
"LoseText" => [TPLOSETEXT, "s"] "LoseText" => [LOSETEXT, "s"]
} }
end end
@@ -74,47 +74,47 @@ def pbLoadTrainer(trainerid,trainername,partyid=0)
opponent.setForeignID($Trainer) opponent.setForeignID($Trainer)
# Load up each Pokémon in the trainer's party # Load up each Pokémon in the trainer's party
for poke in trainer[3] for poke in trainer[3]
species = pbGetSpeciesFromFSpecies(poke[TPSPECIES])[0] species = pbGetSpeciesFromFSpecies(poke[TrainerData::SPECIES])[0]
level = poke[TPLEVEL] level = poke[TrainerData::LEVEL]
pokemon = Pokemon.new(species,level,opponent,false) pokemon = Pokemon.new(species,level,opponent,false)
if poke[TPFORM] if poke[TrainerData::FORM]
pokemon.forcedForm = poke[TPFORM] if MultipleForms.hasFunction?(pokemon.species,"getForm") pokemon.forcedForm = poke[TrainerData::FORM] if MultipleForms.hasFunction?(pokemon.species,"getForm")
pokemon.formSimple = poke[TPFORM] pokemon.formSimple = poke[TrainerData::FORM]
end end
pokemon.setItem(poke[TPITEM]) if poke[TPITEM] pokemon.setItem(poke[TrainerData::ITEM]) if poke[TrainerData::ITEM]
if poke[TPMOVES] && poke[TPMOVES].length>0 if poke[TrainerData::MOVES] && poke[TrainerData::MOVES].length>0
for move in poke[TPMOVES] for move in poke[TrainerData::MOVES]
pokemon.pbLearnMove(move) pokemon.pbLearnMove(move)
end end
else else
pokemon.resetMoves pokemon.resetMoves
end end
pokemon.setAbility(poke[TPABILITY] || 0) pokemon.setAbility(poke[TrainerData::ABILITY] || 0)
g = (poke[TPGENDER]) ? poke[TPGENDER] : (opponent.female?) ? 1 : 0 g = (poke[TrainerData::GENDER]) ? poke[TrainerData::GENDER] : (opponent.female?) ? 1 : 0
pokemon.setGender(g) pokemon.setGender(g)
(poke[TPSHINY]) ? pokemon.makeShiny : pokemon.makeNotShiny (poke[TrainerData::SHINY]) ? pokemon.makeShiny : pokemon.makeNotShiny
n = (poke[TPNATURE]) ? poke[TPNATURE] : (pokemon.species+opponent.trainertype)%(PBNatures.maxValue+1) n = (poke[TrainerData::NATURE]) ? poke[TrainerData::NATURE] : (pokemon.species+opponent.trainertype)%(PBNatures.maxValue+1)
pokemon.setNature(n) pokemon.setNature(n)
for i in 0...6 for i in 0...6
if poke[TPIV] && poke[TPIV].length>0 if poke[TrainerData::IV] && poke[TrainerData::IV].length>0
pokemon.iv[i] = (i<poke[TPIV].length) ? poke[TPIV][i] : poke[TPIV][0] pokemon.iv[i] = (i<poke[TrainerData::IV].length) ? poke[TrainerData::IV][i] : poke[TrainerData::IV][0]
else else
pokemon.iv[i] = [level/2, Pokemon::IV_STAT_LIMIT].min pokemon.iv[i] = [level/2, Pokemon::IV_STAT_LIMIT].min
end end
if poke[TPEV] && poke[TPEV].length>0 if poke[TrainerData::EV] && poke[TrainerData::EV].length>0
pokemon.ev[i] = (i<poke[TPEV].length) ? poke[TPEV][i] : poke[TPEV][0] pokemon.ev[i] = (i<poke[TrainerData::EV].length) ? poke[TrainerData::EV][i] : poke[TrainerData::EV][0]
else else
pokemon.ev[i] = [level*3/2, Pokemon::EV_LIMIT/6].min pokemon.ev[i] = [level*3/2, Pokemon::EV_LIMIT/6].min
end end
end end
pokemon.happiness = poke[TPHAPPINESS] if poke[TPHAPPINESS] pokemon.happiness = poke[TrainerData::HAPPINESS] if poke[TrainerData::HAPPINESS]
pokemon.name = poke[TPNAME] if poke[TPNAME] && poke[TPNAME]!="" pokemon.name = poke[TrainerData::NAME] if poke[TrainerData::NAME] && poke[TrainerData::NAME]!=""
if poke[TPSHADOW] # if this is a Shadow Pokémon if poke[TrainerData::SHADOW] # if this is a Shadow Pokémon
pokemon.makeShadow rescue nil pokemon.makeShadow rescue nil
pokemon.pbUpdateShadowMoves(true) rescue nil pokemon.pbUpdateShadowMoves(true) rescue nil
pokemon.makeNotShiny pokemon.makeNotShiny
end end
pokemon.ballused = poke[TPBALL] if poke[TPBALL] pokemon.ballused = poke[TrainerData::BALL] if poke[TrainerData::BALL]
pokemon.calcStats pokemon.calcStats
party.push(pokemon) party.push(pokemon)
end end

View File

@@ -458,7 +458,7 @@ def pbTrainerBattleEditor
data[0], data[0],
data[1], data[1],
[data[10],data[11],data[12],data[13],data[14],data[15],data[16],data[17]].find_all { |i| i && i!=0 }, # Item list [data[10],data[11],data[12],data[13],data[14],data[15],data[16],data[17]].find_all { |i| i && i!=0 }, # Item list
[data[4],data[5],data[6],data[7],data[8],data[9]].find_all { |i| i && i[TPSPECIES]!=0 }, # Pokémon list [data[4],data[5],data[6],data[7],data[8],data[9]].find_all { |i| i && i[TrainerData::SPECIES]!=0 }, # Pokémon list
data[2], data[2],
data[3] data[3]
] ]
@@ -491,10 +491,10 @@ module TrainerPokemonProperty
def self.set(settingname,initsetting) def self.set(settingname,initsetting)
initsetting = [0,10] if !initsetting initsetting = [0,10] if !initsetting
oldsetting = [] oldsetting = []
for i in 0...TPEV for i in 0...TrainerData::EV
if i==TPMOVES if i==TrainerData::MOVES
for j in 0...4 for j in 0...4
oldsetting.push((initsetting[TPMOVES]) ? initsetting[TPMOVES][j] : nil) oldsetting.push((initsetting[TrainerData::MOVES]) ? initsetting[TrainerData::MOVES][j] : nil)
end end
else else
oldsetting.push(initsetting[i]) oldsetting.push(initsetting[i])
@@ -522,27 +522,27 @@ module TrainerPokemonProperty
[_INTL("EVs"), EVsProperty.new(Pokemon::EV_STAT_LIMIT), _INTL("Effort values for each of the Pokémon's stats.")] [_INTL("EVs"), EVsProperty.new(Pokemon::EV_STAT_LIMIT), _INTL("Effort values for each of the Pokémon's stats.")]
] ]
pbPropertyList(settingname,oldsetting,properties,false) pbPropertyList(settingname,oldsetting,properties,false)
return nil if !oldsetting[TPSPECIES] || oldsetting[TPSPECIES]==0 return nil if !oldsetting[TrainerData::SPECIES] || oldsetting[TrainerData::SPECIES]==0
ret = [] ret = []
moves = [] moves = []
for i in 0...oldsetting.length for i in 0...oldsetting.length
if i>=TPMOVES && i<TPMOVES+4 if i>=TrainerData::MOVES && i<TrainerData::MOVES+4
ret.push(nil) if i==TPMOVES ret.push(nil) if i==TrainerData::MOVES
moves.push(oldsetting[i]) moves.push(oldsetting[i])
else else
ret.push(oldsetting[i]) ret.push(oldsetting[i])
end end
end end
moves.compact! moves.compact!
ret[TPMOVES] = moves if moves.length>0 ret[TrainerData::MOVES] = moves if moves.length>0
# Remove unnecessarily nils from the end of ret # Remove unnecessarily nils from the end of ret
ret.pop while ret.last.nil? && ret.size>0 ret.pop while ret.last.nil? && ret.size>0
return ret return ret
end end
def self.format(value) def self.format(value)
return "-" if !value || !value[TPSPECIES] || value[TPSPECIES]<=0 return "-" if !value || !value[TrainerData::SPECIES] || value[TrainerData::SPECIES]<=0
return sprintf("%s,%d",PBSpecies.getName(value[TPSPECIES]),value[TPLEVEL]) return sprintf("%s,%d",PBSpecies.getName(value[TrainerData::SPECIES]),value[TrainerData::LEVEL])
end end
end end

View File

@@ -467,67 +467,67 @@ def pbSaveTrainerBattles
end end
# Pokémon # Pokémon
for poke in trainer[3] for poke in trainer[3]
species = getConstantName(PBSpecies,poke[TPSPECIES]) rescue pbGetSpeciesConst(poke[TPSPECIES]) rescue "" species = getConstantName(PBSpecies,poke[TrainerData::SPECIES]) rescue pbGetSpeciesConst(poke[TrainerData::SPECIES]) rescue ""
f.write(sprintf("Pokemon = %s,%d\r\n",species,poke[TPLEVEL])) f.write(sprintf("Pokemon = %s,%d\r\n",species,poke[TrainerData::LEVEL]))
if poke[TPNAME] && poke[TPNAME]!="" if poke[TrainerData::NAME] && poke[TrainerData::NAME]!=""
f.write(sprintf(" Name = %s\r\n",poke[TPNAME])) f.write(sprintf(" Name = %s\r\n",poke[TrainerData::NAME]))
end end
if poke[TPFORM] if poke[TrainerData::FORM]
f.write(sprintf(" Form = %d\r\n",poke[TPFORM])) f.write(sprintf(" Form = %d\r\n",poke[TrainerData::FORM]))
end end
if poke[TPGENDER] if poke[TrainerData::GENDER]
f.write(sprintf(" Gender = %s\r\n",(poke[TPGENDER]==1) ? "female" : "male")) f.write(sprintf(" Gender = %s\r\n",(poke[TrainerData::GENDER]==1) ? "female" : "male"))
end end
if poke[TPSHINY] if poke[TrainerData::SHINY]
f.write(" Shiny = yes\r\n") f.write(" Shiny = yes\r\n")
end end
if poke[TPSHADOW] if poke[TrainerData::SHADOW]
f.write(" Shadow = yes\r\n") f.write(" Shadow = yes\r\n")
end end
if poke[TPMOVES] && poke[TPMOVES].length>0 if poke[TrainerData::MOVES] && poke[TrainerData::MOVES].length>0
movestring = "" movestring = ""
for i in 0...poke[TPMOVES].length for i in 0...poke[TrainerData::MOVES].length
movename = getConstantName(PBMoves,poke[TPMOVES][i]) rescue pbGetMoveConst(poke[TPMOVES][i]) rescue nil movename = getConstantName(PBMoves,poke[TrainerData::MOVES][i]) rescue pbGetMoveConst(poke[TrainerData::MOVES][i]) rescue nil
next if !movename next if !movename
movestring.concat(",") if i>0 movestring.concat(",") if i>0
movestring.concat(movename) movestring.concat(movename)
end end
f.write(sprintf(" Moves = %s\r\n",movestring)) if movestring!="" f.write(sprintf(" Moves = %s\r\n",movestring)) if movestring!=""
end end
if poke[TPABILITY] if poke[TrainerData::ABILITY]
f.write(sprintf(" Ability = %d\r\n",poke[TPABILITY])) f.write(sprintf(" Ability = %d\r\n",poke[TrainerData::ABILITY]))
end end
if poke[TPITEM] && poke[TPITEM]>0 if poke[TrainerData::ITEM] && poke[TrainerData::ITEM]>0
item = getConstantName(PBItems,poke[TPITEM]) rescue pbGetItemConst(poke[TPITEM]) rescue nil item = getConstantName(PBItems,poke[TrainerData::ITEM]) rescue pbGetItemConst(poke[TrainerData::ITEM]) rescue nil
f.write(sprintf(" Item = %s\r\n",item)) if item f.write(sprintf(" Item = %s\r\n",item)) if item
end end
if poke[TPNATURE] if poke[TrainerData::NATURE]
nature = getConstantName(PBNatures,poke[TPNATURE]) rescue nil nature = getConstantName(PBNatures,poke[TrainerData::NATURE]) rescue nil
f.write(sprintf(" Nature = %s\r\n",nature)) if nature f.write(sprintf(" Nature = %s\r\n",nature)) if nature
end end
if poke[TPIV] && poke[TPIV].length>0 if poke[TrainerData::IV] && poke[TrainerData::IV].length>0
f.write(sprintf(" IV = %d",poke[TPIV][0])) f.write(sprintf(" IV = %d",poke[TrainerData::IV][0]))
if poke[TPIV].length>1 if poke[TrainerData::IV].length>1
for i in 1...6 for i in 1...6
f.write(sprintf(",%d",(i<poke[TPIV].length) ? poke[TPIV][i] : poke[TPIV][0])) f.write(sprintf(",%d",(i<poke[TrainerData::IV].length) ? poke[TrainerData::IV][i] : poke[TrainerData::IV][0]))
end end
end end
f.write("\r\n") f.write("\r\n")
end end
if poke[TPEV] && poke[TPEV].length>0 if poke[TrainerData::EV] && poke[TrainerData::EV].length>0
f.write(sprintf(" EV = %d",poke[TPEV][0])) f.write(sprintf(" EV = %d",poke[TrainerData::EV][0]))
if poke[TPEV].length>1 if poke[TrainerData::EV].length>1
for i in 1...6 for i in 1...6
f.write(sprintf(",%d",(i<poke[TPEV].length) ? poke[TPEV][i] : poke[TPEV][0])) f.write(sprintf(",%d",(i<poke[TrainerData::EV].length) ? poke[TrainerData::EV][i] : poke[TrainerData::EV][0]))
end end
end end
f.write("\r\n") f.write("\r\n")
end end
if poke[TPHAPPINESS] if poke[TrainerData::HAPPINESS]
f.write(sprintf(" Happiness = %d\r\n",poke[TPHAPPINESS])) f.write(sprintf(" Happiness = %d\r\n",poke[TrainerData::HAPPINESS]))
end end
if poke[TPBALL] if poke[TrainerData::BALL]
f.write(sprintf(" Ball = %d\r\n",poke[TPBALL])) f.write(sprintf(" Ball = %d\r\n",poke[TrainerData::BALL]))
end end
end end
end end

View File

@@ -605,7 +605,7 @@ class TrainerBattleLister
if !@includeNew || index>0 if !@includeNew || index>0
@trainers[(@includeNew) ? index-1 : index][3].each_with_index do |p,i| @trainers[(@includeNew) ? index-1 : index][3].each_with_index do |p,i|
text += "\r\n" if i>0 text += "\r\n" if i>0
text += sprintf("%s Lv.%d",PBSpecies.getName(p[TPSPECIES]),p[TPLEVEL]) text += sprintf("%s Lv.%d",PBSpecies.getName(p[TrainerData::SPECIES]),p[TrainerData::LEVEL])
end end
end end
@pkmnList.text = text @pkmnList.text = text

View File

@@ -1388,7 +1388,7 @@ end
# Compile individual trainers # Compile individual trainers
#=============================================================================== #===============================================================================
def pbCompileTrainers def pbCompileTrainers
trainer_info_types = TrainersMetadata::InfoTypes trainer_info_types = TrainerData::SCHEMA
mLevel = PBExperience.maxLevel mLevel = PBExperience.maxLevel
trainerindex = -1 trainerindex = -1
trainers = [] trainers = []
@@ -1481,8 +1481,8 @@ def pbCompileTrainers
when "Pokemon" when "Pokemon"
pokemonindex += 1 pokemonindex += 1
trainers[trainerindex][3][pokemonindex] = [] trainers[trainerindex][3][pokemonindex] = []
trainers[trainerindex][3][pokemonindex][TPSPECIES] = record[0] trainers[trainerindex][3][pokemonindex][TrainerData::SPECIES] = record[0]
trainers[trainerindex][3][pokemonindex][TPLEVEL] = record[1] trainers[trainerindex][3][pokemonindex][TrainerData::LEVEL] = record[1]
else else
if pokemonindex<0 if pokemonindex<0
raise _INTL("Pokémon hasn't been defined yet!\r\n{1}",FileLineData.linereport) raise _INTL("Pokémon hasn't been defined yet!\r\n{1}",FileLineData.linereport)
@@ -1532,29 +1532,29 @@ def pbCompileTrainers
for i in 0...record.length for i in 0...record.length
next if record[i]==nil next if record[i]==nil
case i case i
when TPLEVEL when TrainerData::LEVEL
if record[i]>mLevel if record[i]>mLevel
raise _INTL("Bad level: {1} (must be 1-{2})\r\n{3}",record[i],mLevel,FileLineData.linereport) raise _INTL("Bad level: {1} (must be 1-{2})\r\n{3}",record[i],mLevel,FileLineData.linereport)
end end
when TPABILITY+3 when TrainerData::ABILITY+3
if record[i]>5 if record[i]>5
raise _INTL("Bad ability flag: {1} (must be 0 or 1 or 2-5)\r\n{2}",record[i],FileLineData.linereport) raise _INTL("Bad ability flag: {1} (must be 0 or 1 or 2-5)\r\n{2}",record[i],FileLineData.linereport)
end end
when TPIV+3 when TrainerData::IV+3
if record[i]>31 if record[i]>31
raise _INTL("Bad IV: {1} (must be 0-31)\r\n{2}",record[i],FileLineData.linereport) raise _INTL("Bad IV: {1} (must be 0-31)\r\n{2}",record[i],FileLineData.linereport)
end end
record[i] = [record[i]] record[i] = [record[i]]
when TPEV+3 when TrainerData::EV+3
if record[i]>Pokemon::EV_STAT_LIMIT if record[i]>Pokemon::EV_STAT_LIMIT
raise _INTL("Bad EV: {1} (must be 0-{2})\r\n{3}", record[i], Pokemon::EV_STAT_LIMIT, FileLineData.linereport) raise _INTL("Bad EV: {1} (must be 0-{2})\r\n{3}", record[i], Pokemon::EV_STAT_LIMIT, FileLineData.linereport)
end end
record[i] = [record[i]] record[i] = [record[i]]
when TPHAPPINESS+3 when TrainerData::HAPPINESS+3
if record[i]>255 if record[i]>255
raise _INTL("Bad happiness: {1} (must be 0-255)\r\n{2}",record[i],FileLineData.linereport) raise _INTL("Bad happiness: {1} (must be 0-255)\r\n{2}",record[i],FileLineData.linereport)
end end
when TPNAME+3 when TrainerData::NAME+3
if record[i].length>Pokemon::MAX_NAME_SIZE if record[i].length>Pokemon::MAX_NAME_SIZE
raise _INTL("Bad nickname: {1} (must be 1-{2} characters)\r\n{3}", record[i], Pokemon::MAX_NAME_SIZE, FileLineData.linereport) raise _INTL("Bad nickname: {1} (must be 1-{2} characters)\r\n{3}", record[i], Pokemon::MAX_NAME_SIZE, FileLineData.linereport)
end end
@@ -1563,13 +1563,13 @@ def pbCompileTrainers
# Write data to trainer array # Write data to trainer array
for i in 0...record.length for i in 0...record.length
next if record[i]==nil next if record[i]==nil
if i>=TPMOVES && i<TPMOVES+4 if i>=TrainerData::MOVES && i<TrainerData::MOVES+4
if !trainers[trainerindex][3][pokemonindex][TPMOVES] if !trainers[trainerindex][3][pokemonindex][TrainerData::MOVES]
trainers[trainerindex][3][pokemonindex][TPMOVES] = [] trainers[trainerindex][3][pokemonindex][TrainerData::MOVES] = []
end end
trainers[trainerindex][3][pokemonindex][TPMOVES].push(record[i]) trainers[trainerindex][3][pokemonindex][TrainerData::MOVES].push(record[i])
else else
d = (i>=TPMOVES+4) ? i-3 : i d = (i>=TrainerData::MOVES+4) ? i-3 : i
trainers[trainerindex][3][pokemonindex][d] = record[i] trainers[trainerindex][3][pokemonindex][d] = record[i]
end end
end end