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

View File

@@ -458,7 +458,7 @@ def pbTrainerBattleEditor
data[0],
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[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[3]
]
@@ -491,10 +491,10 @@ module TrainerPokemonProperty
def self.set(settingname,initsetting)
initsetting = [0,10] if !initsetting
oldsetting = []
for i in 0...TPEV
if i==TPMOVES
for i in 0...TrainerData::EV
if i==TrainerData::MOVES
for j in 0...4
oldsetting.push((initsetting[TPMOVES]) ? initsetting[TPMOVES][j] : nil)
oldsetting.push((initsetting[TrainerData::MOVES]) ? initsetting[TrainerData::MOVES][j] : nil)
end
else
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.")]
]
pbPropertyList(settingname,oldsetting,properties,false)
return nil if !oldsetting[TPSPECIES] || oldsetting[TPSPECIES]==0
return nil if !oldsetting[TrainerData::SPECIES] || oldsetting[TrainerData::SPECIES]==0
ret = []
moves = []
for i in 0...oldsetting.length
if i>=TPMOVES && i<TPMOVES+4
ret.push(nil) if i==TPMOVES
if i>=TrainerData::MOVES && i<TrainerData::MOVES+4
ret.push(nil) if i==TrainerData::MOVES
moves.push(oldsetting[i])
else
ret.push(oldsetting[i])
end
end
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
ret.pop while ret.last.nil? && ret.size>0
return ret
end
def self.format(value)
return "-" if !value || !value[TPSPECIES] || value[TPSPECIES]<=0
return sprintf("%s,%d",PBSpecies.getName(value[TPSPECIES]),value[TPLEVEL])
return "-" if !value || !value[TrainerData::SPECIES] || value[TrainerData::SPECIES]<=0
return sprintf("%s,%d",PBSpecies.getName(value[TrainerData::SPECIES]),value[TrainerData::LEVEL])
end
end

View File

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

View File

@@ -605,7 +605,7 @@ class TrainerBattleLister
if !@includeNew || index>0
@trainers[(@includeNew) ? index-1 : index][3].each_with_index do |p,i|
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
@pkmnList.text = text

View File

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