Rewrote evolution methods to make them modular

This commit is contained in:
Maruno17
2020-09-10 22:22:06 +01:00
parent aaf5949c13
commit 6f353ba813
9 changed files with 474 additions and 363 deletions

View File

@@ -798,7 +798,7 @@ def pbPokemonEditor
_INTL("Urban"),_INTL("Rare")]),
_INTL("The habitat of this species.")],
[_INTL("RegionalNumbers"),ReadOnlyProperty,_INTL("Regional Dex numbers for the Pokémon. These are edited elsewhere.")],
[_INTL("Kind"),StringProperty._INTL("Kind of Pokémon species.")],
[_INTL("Kind"),StringProperty,_INTL("Kind of Pokémon species.")],
[_INTL("Pokédex"),StringProperty,_INTL("Description of the Pokémon as displayed in the Pokédex.")],
[_INTL("FormName"),StringProperty,_INTL("Name of this form of the Pokémon.")],
[_INTL("WildItemCommon"),ItemProperty,_INTL("Item commonly held by wild Pokémon of this species.")],

View File

@@ -829,33 +829,21 @@ def pbSavePokemonData
pokedata.write("Evolutions = ")
count = 0
for form in pbGetEvolvedFormData(i)
evonib = form[0]
level = form[1]
poke = form[2]
next if poke==0
cpoke = getConstantName(PBSpecies,poke) rescue pbGetSpeciesConst(poke)
evoname = getConstantName(PBEvolution,evonib) rescue pbGetEvolutionConst(evonib)
next if !cpoke || cpoke==""
method = form[0]
parameter = form[1]
new_species = form[2]
next if new_species==0
cnew_species = getConstantName(PBSpecies,new_species) rescue pbGetSpeciesConst(new_species)
evoname = getConstantName(PBEvolution,method) rescue pbGetEvolutionConst(method)
next if !cnew_species || cnew_species==""
pokedata.write(",") if count>0
pokedata.write(sprintf("%s,%s,",cpoke,evoname))
case PBEvolution::EVOPARAM[evonib]
when 1
pokedata.write("#{level}")
when 2
clevel = getConstantName(PBItems,level) rescue pbGetItemConst(level)
pokedata.write("#{clevel}")
when 3
clevel = getConstantName(PBMoves,level) rescue pbGetMoveConst(level)
pokedata.write("#{clevel}")
when 4
clevel = getConstantName(PBSpecies,level) rescue pbGetSpeciesConst(level)
pokedata.write("#{clevel}")
when 5
clevel = getConstantName(PBTypes,level) rescue pbGetTypeConst(level)
pokedata.write("#{clevel}")
when 6
clevel = getConstantName(PBAbilities,level) rescue pbGetAbilityConst(level)
pokedata.write("#{clevel}")
pokedata.write(sprintf("%s,%s,",cnew_species,evoname))
param_type = PBEvolution.getFunction(method, "parameterType")
if param_type
cparameter = getConstantName(param_type,parameter) rescue ""
pokedata.write("#{cparameter}")
else
pokedata.write("#{parameter}")
end
count += 1
end
@@ -1230,8 +1218,9 @@ def pbSavePokemonFormsData
if shape!=nil
pokedata.write("Shape = #{shape}\r\n")
end
if habitat!=nil
pokedata.write("Habitat = "+["","Grassland","Forest","WatersEdge","Sea","Cave","Mountain","RoughTerrain","Urban","Rare"][habitat]+"\r\n") if habitat>0
if habitat!=nil && habitat>0
habitat_name = getConstantName(PBHabitats,habitat) rescue pbGetHabitatConst(habitat)
pokedata.write("Habitat = #{habitat_name}\r\n")
end
if kind!=nil
pokedata.write("Kind = #{kind}\r\n")
@@ -1267,25 +1256,25 @@ def pbSavePokemonFormsData
end
origevos = []
for form in pbGetEvolvedFormData(species)
evonib = form[0]
level = form[1]
poke = form[2]
next if poke==0
cpoke = getConstantName(PBSpecies,poke) rescue pbGetSpeciesConst(poke)
evoname = getConstantName(PBEvolution,evonib) rescue pbGetEvolutionConst(evonib)
next if !cpoke || cpoke==""
origevos.push([evonib,level,poke])
method = form[0]
parameter = form[1]
new_species = form[2]
next if new_species==0
cnew_species = getConstantName(PBSpecies,new_species) rescue pbGetSpeciesConst(new_species)
evoname = getConstantName(PBEvolution,method) rescue pbGetEvolutionConst(method)
next if !cnew_species || cnew_species==""
origevos.push([method,parameter,new_species])
end
evos = []
for form in pbGetEvolvedFormData(i)
evonib = form[0]
level = form[1]
poke = form[2]
next if poke==0
cpoke = getConstantName(PBSpecies,poke) rescue pbGetSpeciesConst(poke)
evoname = getConstantName(PBEvolution,evonib) rescue pbGetEvolutionConst(evonib)
next if !cpoke || cpoke==""
evos.push([evonib,level,poke])
method = form[0]
parameter = form[1]
new_species = form[2]
next if new_species==0
cnew_species = getConstantName(PBSpecies,new_species) rescue pbGetSpeciesConst(new_species)
evoname = getConstantName(PBEvolution,method) rescue pbGetEvolutionConst(method)
next if !cnew_species || cnew_species==""
evos.push([method,parameter,new_species])
end
diff = false
if evos.length!=origevos.length
@@ -1302,28 +1291,19 @@ def pbSavePokemonFormsData
if diff
pokedata.write("Evolutions = ")
for k in 0...evos.length
cpoke = getConstantName(PBSpecies,poke) rescue pbGetSpeciesConst(poke)
evoname = getConstantName(PBEvolution,evonib) rescue pbGetEvolutionConst(evonib)
next if !cpoke || cpoke==""
pokedata.write(sprintf("%s,%s,",cpoke,evoname))
case PBEvolution::EVOPARAM[evonib]
when 1
pokedata.write("#{level}")
when 2
clevel = getConstantName(PBItems,level) rescue pbGetItemConst(level)
pokedata.write("#{clevel}")
when 3
clevel = getConstantName(PBMoves,level) rescue pbGetMoveConst(level)
pokedata.write("#{clevel}")
when 4
clevel = getConstantName(PBSpecies,level) rescue pbGetSpeciesConst(level)
pokedata.write("#{clevel}")
when 5
clevel = getConstantName(PBTypes,level) rescue pbGetTypeConst(level)
pokedata.write("#{clevel}")
when 6
clevel = getConstantName(PBAbilities,level) rescue pbGetAbilityConst(level)
pokedata.write("#{clevel}")
method = form[0]
parameter = form[1]
new_species = form[2]
cnew_species = getConstantName(PBSpecies,new_species) rescue pbGetSpeciesConst(new_species)
evoname = getConstantName(PBEvolution,method) rescue pbGetEvolutionConst(method)
next if !cnew_species || cnew_species==""
pokedata.write(sprintf("%s,%s,",cnew_species,evoname))
param_type = PBEvolution.getFunction(method, "parameterType")
if param_type
cparameter = getConstantName(param_type,parameter) rescue ""
pokedata.write("#{cparameter}")
else
pokedata.write("#{parameter}")
end
pokedata.write(",") if k<evos.length-1
end

View File

@@ -1184,7 +1184,6 @@ end
class EvolutionsProperty
def initialize(methods)
@methods = methods
@evoparams = PBEvolution::EVOPARAM
end
def set(_settingname,oldsetting)
@@ -1207,14 +1206,11 @@ class EvolutionsProperty
commands.push(_INTL("[ADD EVOLUTION]"))
else
level = realcmds[i][1]
case @evoparams[realcmds[i][0]]
when 0; level = ""
when 2; level = sprintf("#{PBItems.getName(level)}")
when 3; level = sprintf("#{PBMoves.getName(level)}")
when 4; level = sprintf("#{PBSpecies.getName(level)}")
when 5; level = sprintf("#{PBTypes.getName(level)}")
when 6; level = sprintf("#{PBAbilities.getName(level)}")
param_type = PBEvolution.getFunction(realcmds[i][0], "parameterType")
if param_type
level = (Object.const_get(param_type).getName(level) rescue getConstantName(param_type, level) rescue level)
end
level = "" if !level
commands.push(_INTL("{1}: {2}, {3}",
PBSpecies.getName(realcmds[i][2]),@methods[realcmds[i][0]],level.to_s))
end
@@ -1242,30 +1238,29 @@ class EvolutionsProperty
if newspecies>0
newmethod = pbMessage(_INTL("Choose an evolution method."),@methods,-1)
if newmethod>0
newparam = 0
if @evoparams[newmethod]==2 # Items
newparam = -1
allow_zero = false
param_type = PBEvolution.getFunction(newmethod, "parameterType")
case param_type
when :PBItems
newparam = pbChooseItemList
elsif @evoparams[newmethod]==3 # Moves
when :PBMoves
newparam = pbChooseMoveList
elsif @evoparams[newmethod]==4 # Species
when :PBSpecies
newparam = pbChooseSpeciesList
elsif @evoparams[newmethod]==5 # Types
when :PBTypes
allow_zero = true
newparam = pbChooseTypeList
elsif @evoparams[newmethod]==6 # Abilities
when :PBAbilities
newparam = pbChooseAbilityList
elsif @evoparams[newmethod]!=0
else
allow_zero = true
params = ChooseNumberParams.new
params.setRange(0,65535)
params.setDefaultValue(-1)
params.setCancelValue(-1)
newparam = pbMessageChooseNumber(_INTL("Choose a parameter."),params)
end
if @evoparams[newmethod]==0 ||
(@evoparams[newmethod]==1 && newparam && newparam>=0) ||
(@evoparams[newmethod]==2 && newparam && newparam>0) ||
(@evoparams[newmethod]==3 && newparam && newparam>0) ||
(@evoparams[newmethod]==4 && newparam && newparam>0) ||
(@evoparams[newmethod]==5 && newparam && newparam>=0) ||
(@evoparams[newmethod]==6 && newparam && newparam>0)
if newparam && (newparam>0 || (allow_zero && newparam == 0))
havemove = -1
for i in 0...realcmds.length
havemove = realcmds[i][3] if realcmds[i][0]==newmethod &&
@@ -1320,57 +1315,53 @@ class EvolutionsProperty
realcmds[cmd[1]] = nil
realcmds.compact!
oldsel = havemove
else
elsif newmethod != entry[0]
entry[0] = newmethod
entry[1] = 0 if @evoparams[entry[0]]==0
entry[1] = 0
oldsel = entry[3]
end
refreshlist = true
end
elsif cmd2==2 # Change parameter
if @evoparams[entry[0]]==0
pbMessage(_INTL("This evolution method doesn't use a parameter."))
newparam = -1
allow_zero = false
param_type = PBEvolution.getFunction(entry[0], "parameterType")
case param_type
when :PBItems
newparam = pbChooseItemList(entry[1])
when :PBMoves
newparam = pbChooseMoveList(entry[1])
when :PBSpecies
newparam = pbChooseSpeciesList(entry[1])
when :PBTypes
allow_zero = true
newparam = pbChooseTypeList(entry[1])
when :PBAbilities
newparam = pbChooseAbilityList(entry[1])
else
newparam = -1
if @evoparams[entry[0]]==2 # Items
newparam = pbChooseItemList(entry[1])
elsif @evoparams[entry[0]]==3 # Moves
newparam = pbChooseMoveList(entry[1])
elsif @evoparams[entry[0]]==4 # Species
newparam = pbChooseSpeciesList(entry[1])
elsif @evoparams[entry[0]]==5 # Types
newparam = pbChooseTypeList(entry[1])
elsif @evoparams[entry[0]]==6 # Abilities
newparam = pbChooseAbilityList(entry[1])
allow_zero = true
params = ChooseNumberParams.new
params.setRange(0,65535)
params.setDefaultValue(entry[1])
params.setCancelValue(-1)
newparam = pbMessageChooseNumber(_INTL("Choose a parameter."),params)
end
if newparam && (newparam>0 || (allow_zero && newparam == 0))
havemove = -1
for i in 0...realcmds.length
havemove = realcmds[i][3] if realcmds[i][0]==entry[0] &&
realcmds[i][1]==newparam &&
realcmds[i][2]==entry[2]
end
if havemove>=0
realcmds[cmd[1]] = nil
realcmds.compact!
oldsel = havemove
else
params = ChooseNumberParams.new
params.setRange(0,65535)
params.setDefaultValue(entry[1])
params.setCancelValue(-1)
newparam = pbMessageChooseNumber(_INTL("Choose a parameter."),params)
end
if (@evoparams[entry[0]]==1 && newparam && newparam>=0) ||
(@evoparams[entry[0]]==2 && newparam && newparam>0) ||
(@evoparams[entry[0]]==3 && newparam && newparam>0) ||
(@evoparams[entry[0]]==4 && newparam && newparam>0) ||
(@evoparams[entry[0]]==5 && newparam && newparam>=0) ||
(@evoparams[entry[0]]==6 && newparam && newparam>0)
havemove = -1
for i in 0...realcmds.length
havemove = realcmds[i][3] if realcmds[i][0]==entry[0] &&
realcmds[i][1]==newparam &&
realcmds[i][2]==entry[2]
end
if havemove>=0
realcmds[cmd[1]] = nil
realcmds.compact!
oldsel = havemove
else
entry[1] = newparam
oldsel = entry[3]
end
refreshlist = true
entry[1] = newparam
oldsel = entry[3]
end
refreshlist = true
end
elsif cmd2==3 # Delete
realcmds[cmd[1]] = nil
@@ -1409,14 +1400,11 @@ class EvolutionsProperty
for i in 0...value.length
ret << "," if i>0
param = value[i][1]
case @evoparams[value[i][0]]
when 0; param = ""
when 2; param = sprintf("#{PBItems.getName(param)}")
when 3; param = sprintf("#{PBMoves.getName(param)}")
when 4; param = sprintf("#{PBSpecies.getName(param)}")
when 5; param = sprintf("#{PBTypes.getName(param)}")
when 6; param = sprintf("#{PBAbilities.getName(param)}")
param_type = PBEvolution.getFunction(value[i][0], "parameterType")
if param_type
param = (Object.const_get(param_type).getName(param) rescue getConstantName(param_type, param) rescue param)
end
param = "" if !param
ret << sprintf("#{PBSpecies.getName(value[i][2])},#{@methods[value[i][0]]},#{param}")
end
return ret

View File

@@ -232,6 +232,17 @@ def pbGetGenderConst(i)
return ret
end
def pbGetHabitatConst(i)
ret = MakeshiftConsts.get(53,i,PBHabitats)
if !ret
ret = ["","Grassland","Forest","WatersEdge","Sea","Cave","Mountain",
"RoughTerrain","Urban","Rare"]
i = 0 if i>=ret.length || i<0
ret = ret[i]
end
return ret
end
def pbGetAbilityConst(i)
return MakeshiftConsts.get(MessageTypes::Abilities,i,PBAbilities)
end
@@ -267,11 +278,11 @@ def pbChooseSpeciesList(default=0)
cname = getConstantName(PBSpecies,i) rescue nil
commands.push([i,PBSpecies.getName(i)]) if cname
end
return pbChooseList(commands,default,-1)
return pbChooseList(commands,default,0,-1)
end
# Displays an alphabetically sorted list of all moves, and returns the ID of the
# move selected (or 0 if the selection was canceled). "default", if specified,
# move selected (or -1 if the selection was canceled). "default", if specified,
# is the ID of the move to initially select.
def pbChooseMoveList(default=0)
commands = []
@@ -279,7 +290,7 @@ def pbChooseMoveList(default=0)
cname = getConstantName(PBMoves,i) rescue nil
commands.push([i,PBMoves.getName(i)]) if cname
end
return pbChooseList(commands,default)
return pbChooseList(commands,default,0)
end
def pbChooseMoveListForSpecies(species,defaultMoveID=0)
@@ -319,9 +330,9 @@ def pbChooseMoveListForSpecies(species,defaultMoveID=0)
end
# Displays an alphabetically sorted list of all types, and returns the ID of the
# type selected (or 0 if the selection was canceled). "default", if specified,
# type selected (or -1 if the selection was canceled). "default", if specified,
# is the ID of the type to initially select.
def pbChooseTypeList(default=0)
def pbChooseTypeList(default=-1)
commands = []
for i in 0..PBTypes.maxValue
cname = getConstantName(PBTypes,i) rescue nil
@@ -330,9 +341,9 @@ def pbChooseTypeList(default=0)
return pbChooseList(commands,default)
end
# Displays a list of all items, and returns the ID of the item selected (or 0 if
# the selection was canceled). "default", if specified, is the ID of the item to
# initially select. Pressing Input::A will toggle the list sorting between
# Displays a list of all items, and returns the ID of the item selected (or -1
# if the selection was canceled). "default", if specified, is the ID of the item
# to initially select. Pressing Input::A will toggle the list sorting between
# numerical and alphabetical.
def pbChooseItemList(default=0)
commands = []
@@ -340,11 +351,11 @@ def pbChooseItemList(default=0)
cname = getConstantName(PBItems,i) rescue nil
commands.push([i,PBItems.getName(i)]) if cname
end
return pbChooseList(commands,default,-1)
return pbChooseList(commands,default,0,-1)
end
# Displays a list of all abilities, and returns the ID of the ability selected
# (or 0 if the selection was canceled). "default", if specified, is the ID of
# (or -1 if the selection was canceled). "default", if specified, is the ID of
# the ability to initially select. Pressing Input::A will toggle the list
# sorting between numerical and alphabetical.
def pbChooseAbilityList(default=0)
@@ -353,7 +364,7 @@ def pbChooseAbilityList(default=0)
cname = getConstantName(PBAbilities,i) rescue nil
commands.push([i,PBAbilities.getName(i)]) if cname
end
return pbChooseList(commands,default,-1)
return pbChooseList(commands,default,0,-1)
end
def pbChooseBallList(defaultMoveID=-1)
@@ -475,7 +486,7 @@ def pbCommands3(cmdwindow,commands,cmdIfCancel,defaultindex=-1,noresize=false)
return ret
end
def pbChooseList(commands,default=0,sortType=1)
def pbChooseList(commands,default=0,cancelValue=-1,sortType=1)
cmdwin = pbListWindow([])
itemID = default
itemIndex = 0
@@ -493,7 +504,7 @@ def pbChooseList(commands,default=0,sortType=1)
end
realcommands = []
for command in commands
if sortType<0 || sortType==0
if sortType<=0
realcommands.push(sprintf("%03d: %s",command[0],command[1]))
else
realcommands.push(command[1])
@@ -503,7 +514,7 @@ def pbChooseList(commands,default=0,sortType=1)
end
cmd = pbCommandsSortable(cmdwin,realcommands,-1,itemIndex,(sortType<0))
if cmd[0]==0 # Chose an option or cancelled
itemID = (cmd[1]<0) ? 0 : commands[cmd[1]][0]
itemID = (cmd[1]<0) ? cancelValue : commands[cmd[1]][0]
break
elsif cmd[0]==1 # Toggle sorting
itemID = commands[cmd[1]][0]
@@ -512,7 +523,7 @@ def pbChooseList(commands,default=0,sortType=1)
end
end
cmdwin.dispose
return (itemID>0) ? itemID : 0
return itemID
end
def pbCommandsSortable(cmdwindow,commands,cmdIfCancel,defaultindex=-1,sortable=false)