Added conversion of berry plant data, removed all uses of ID numbers for abilities and berry plants, fixed mulch not being consumed, removed use of ID numbers in map of moves to animation IDs

This commit is contained in:
Maruno17
2021-06-19 18:48:33 +01:00
parent 6e188666a4
commit 49655165e1
9 changed files with 134 additions and 48 deletions

View File

@@ -146,6 +146,95 @@ SaveData.register_conversion(:v19_1_fix_phone_contacts) do
end end
end end
SaveData.register_conversion(:v19_1_1_fix_berry_plants) do
essentials_version 19.1.1
display_title 'Fixing berry plant data'
to_value :global_metadata do |global|
berry_conversion = {
389 => :CHERIBERRY,
390 => :CHESTOBERRY,
391 => :PECHABERRY,
392 => :RAWSTBERRY,
393 => :ASPEARBERRY,
394 => :LEPPABERRY,
395 => :ORANBERRY,
396 => :PERSIMBERRY,
397 => :LUMBERRY,
398 => :SITRUSBERRY,
399 => :FIGYBERRY,
400 => :WIKIBERRY,
401 => :MAGOBERRY,
402 => :AGUAVBERRY,
403 => :IAPAPABERRY,
404 => :RAZZBERRY,
405 => :BLUKBERRY,
406 => :NANABBERRY,
407 => :WEPEARBERRY,
408 => :PINAPBERRY,
409 => :POMEGBERRY,
410 => :KELPSYBERRY,
411 => :QUALOTBERRY,
412 => :HONDEWBERRY,
413 => :GREPABERRY,
414 => :TAMATOBERRY,
415 => :CORNNBERRY,
416 => :MAGOSTBERRY,
417 => :RABUTABERRY,
418 => :NOMELBERRY,
419 => :SPELONBERRY,
420 => :PAMTREBERRY,
421 => :WATMELBERRY,
422 => :DURINBERRY,
423 => :BELUEBERRY,
424 => :OCCABERRY,
425 => :PASSHOBERRY,
426 => :WACANBERRY,
427 => :RINDOBERRY,
428 => :YACHEBERRY,
429 => :CHOPLEBERRY,
430 => :KEBIABERRY,
431 => :SHUCABERRY,
432 => :COBABERRY,
433 => :PAYAPABERRY,
434 => :TANGABERRY,
435 => :CHARTIBERRY,
436 => :KASIBBERRY,
437 => :HABANBERRY,
438 => :COLBURBERRY,
439 => :BABIRIBERRY,
440 => :CHILANBERRY,
441 => :LIECHIBERRY,
442 => :GANLONBERRY,
443 => :SALACBERRY,
444 => :PETAYABERRY,
445 => :APICOTBERRY,
446 => :LANSATBERRY,
447 => :STARFBERRY,
448 => :ENIGMABERRY,
449 => :MICLEBERRY,
450 => :CUSTAPBERRY,
451 => :JABOCABERRY,
452 => :ROWAPBERRY
}
mulch_conversion = {
59 => :GROWTHMULCH,
60 => :DAMPMULCH,
61 => :STABLEMULCH,
62 => :GOOEYMULCH
}
global.eventvars.each do |var|
next if !var || !var.ia_a?(Array)
next if var.length < 6 || var.length > 8 # Neither old nor new berry plant
if !var[1].is_a?(Symbol) # Planted berry item
var[1] = berry_conversion[var[1]] || :ORANBERRY
end
if var[7] && !var[7].is_a?(Symbol) # Mulch
var[7] = mulch_conversion[var[7]]
end
end
end
end
SaveData.register_conversion(:v19_convert_bag) do SaveData.register_conversion(:v19_convert_bag) do
essentials_version 19 essentials_version 19
display_title 'Converting item IDs in Bag' display_title 'Converting item IDs in Bag'

View File

@@ -1,31 +1,29 @@
module GameData module GameData
class Ability class Ability
attr_reader :id attr_reader :id
attr_reader :id_number
attr_reader :real_name attr_reader :real_name
attr_reader :real_description attr_reader :real_description
DATA = {} DATA = {}
DATA_FILENAME = "abilities.dat" DATA_FILENAME = "abilities.dat"
extend ClassMethods extend ClassMethodsSymbols
include InstanceMethods include InstanceMethods
def initialize(hash) def initialize(hash)
@id = hash[:id] @id = hash[:id]
@id_number = hash[:id_number] || -1
@real_name = hash[:name] || "Unnamed" @real_name = hash[:name] || "Unnamed"
@real_description = hash[:description] || "???" @real_description = hash[:description] || "???"
end end
# @return [String] the translated name of this ability # @return [String] the translated name of this ability
def name def name
return pbGetMessage(MessageTypes::Abilities, @id_number) return pbGetMessageFromHash(MessageTypes::Abilities, @real_name)
end end
# @return [String] the translated description of this ability # @return [String] the translated description of this ability
def description def description
return pbGetMessage(MessageTypes::AbilityDescs, @id_number) return pbGetMessageFromHash(MessageTypes::AbilityDescs, @real_description)
end end
end end
end end

View File

@@ -1,7 +1,6 @@
module GameData module GameData
class BerryPlant class BerryPlant
attr_reader :id attr_reader :id
attr_reader :id_number
attr_reader :hours_per_stage attr_reader :hours_per_stage
attr_reader :drying_per_hour attr_reader :drying_per_hour
attr_reader :minimum_yield attr_reader :minimum_yield
@@ -12,12 +11,11 @@ module GameData
NUMBER_OF_REPLANTS = 9 NUMBER_OF_REPLANTS = 9
extend ClassMethods extend ClassMethodsSymbols
include InstanceMethods include InstanceMethods
def initialize(hash) def initialize(hash)
@id = hash[:id] @id = hash[:id]
@id_number = hash[:id_number] || -1
@hours_per_stage = hash[:hours_per_stage] || 3 @hours_per_stage = hash[:hours_per_stage] || 3
@drying_per_hour = hash[:drying_per_hour] || 15 @drying_per_hour = hash[:drying_per_hour] || 15
@minimum_yield = hash[:minimum_yield] || 2 @minimum_yield = hash[:minimum_yield] || 2

View File

@@ -128,7 +128,7 @@ module GameData
else else
pkmn.reset_moves pkmn.reset_moves
end end
pkmn.ability_index = pkmn_data[:ability_index] pkmn.ability_index = pkmn_data[:ability_index] || 0
pkmn.ability = pkmn_data[:ability] pkmn.ability = pkmn_data[:ability]
pkmn.gender = pkmn_data[:gender] || ((trainer.male?) ? 0 : 1) pkmn.gender = pkmn_data[:gender] || ((trainer.male?) ? 0 : 1)
pkmn.shiny = (pkmn_data[:shininess]) ? true : false pkmn.shiny = (pkmn_data[:shininess]) ? true : false
@@ -137,7 +137,8 @@ module GameData
else # Make the nature random but consistent for the same species used by the same trainer type else # Make the nature random but consistent for the same species used by the same trainer type
species_num = GameData::Species.keys.index(species) || 1 species_num = GameData::Species.keys.index(species) || 1
tr_type_num = GameData::TrainerType.keys.index(@trainer_type) || 1 tr_type_num = GameData::TrainerType.keys.index(@trainer_type) || 1
pkmn.nature = (species_num + tr_type_num) % GameData::Nature.count idx = (species_num + tr_type_num) % GameData::Nature.count
pkmn.nature = GameData::Nature.get(GameData::Nature.keys[idx]).id
end end
GameData::Stat.each_main do |s| GameData::Stat.each_main do |s|
if pkmn_data[:iv] if pkmn_data[:iv]

View File

@@ -383,14 +383,14 @@ class PokeBattle_Scene
# Returns the animation ID to use for a given move/user. Returns nil if that # Returns the animation ID to use for a given move/user. Returns nil if that
# move has no animations defined for it. # move has no animations defined for it.
def pbFindMoveAnimDetails(move2anim,moveID,idxUser,hitNum=0) def pbFindMoveAnimDetails(move2anim,moveID,idxUser,hitNum=0)
id_number = GameData::Move.get(moveID).id_number real_move_id = GameData::Move.get(moveID).id
noFlip = false noFlip = false
if (idxUser&1)==0 # On player's side if (idxUser&1)==0 # On player's side
anim = move2anim[0][id_number] anim = move2anim[0][real_move_id]
else # On opposing side else # On opposing side
anim = move2anim[1][id_number] anim = move2anim[1][real_move_id]
noFlip = true if anim noFlip = true if anim
anim = move2anim[0][id_number] if !anim anim = move2anim[0][real_move_id] if !anim
end end
return [anim+hitNum,noFlip] if anim return [anim+hitNum,noFlip] if anim
return nil return nil

View File

@@ -142,7 +142,7 @@ class BerryPlantSprite
if secondsalive+timeDiff>=timeperstage*numlifestages if secondsalive+timeDiff>=timeperstage*numlifestages
# Should replant # Should replant
if berryData[5]>=maxreplants # Too many replants if berryData[5]>=maxreplants # Too many replants
return [0,0,0,0,0,0,0,0] return [0,nil,0,0,0,0,0,nil]
end end
# Replant # Replant
berryData[0]=2 # replants start in sprouting stage berryData[0]=2 # replants start in sprouting stage
@@ -215,7 +215,7 @@ class BerryPlantSprite
berryData[4]=0 # reset total waterings count berryData[4]=0 # reset total waterings count
berryData[5]+=1 # add to replanted count berryData[5]+=1 # add to replanted count
if berryData[5] > GameData::BerryPlant::NUMBER_OF_REPLANTS # Too many replants if berryData[5] > GameData::BerryPlant::NUMBER_OF_REPLANTS # Too many replants
berryData = [0,0,false,0,0,0] berryData = [0,nil,false,0,0,0]
break break
end end
else else
@@ -272,7 +272,7 @@ def pbBerryPlant
berryData=interp.getVariable berryData=interp.getVariable
if !berryData if !berryData
if Settings::NEW_BERRY_PLANTS if Settings::NEW_BERRY_PLANTS
berryData=[0,nil,0,0,0,0,0,0] berryData=[0,nil,0,0,0,0,0,nil]
else else
berryData=[0,nil,false,0,0,0] berryData=[0,nil,false,0,0,0]
end end
@@ -291,13 +291,13 @@ def pbBerryPlant
when 0 # empty when 0 # empty
if Settings::NEW_BERRY_PLANTS if Settings::NEW_BERRY_PLANTS
# Gen 4 planting mechanics # Gen 4 planting mechanics
if !berryData[7] || berryData[7]==0 # No mulch used yet if !berryData[7] # No mulch used yet
cmd=pbMessage(_INTL("It's soft, earthy soil."),[ cmd=pbMessage(_INTL("It's soft, earthy soil."),[
_INTL("Fertilize"), _INTL("Fertilize"),
_INTL("Plant Berry"), _INTL("Plant Berry"),
_INTL("Exit")],-1) _INTL("Exit")],-1)
if cmd==0 # Fertilize if cmd==0 # Fertilize
ret=0 ret=nil
pbFadeOutIn { pbFadeOutIn {
scene = PokemonBag_Scene.new scene = PokemonBag_Scene.new
screen = PokemonBagScreen.new(scene,$PokemonBag) screen = PokemonBagScreen.new(scene,$PokemonBag)
@@ -306,6 +306,7 @@ def pbBerryPlant
if ret if ret
if GameData::Item.get(ret).is_mulch? if GameData::Item.get(ret).is_mulch?
berryData[7]=ret berryData[7]=ret
$PokemonBag.pbDeleteItem(ret, 1)
pbMessage(_INTL("The {1} was scattered on the soil.\1",GameData::Item.get(ret).name)) pbMessage(_INTL("The {1} was scattered on the soil.\1",GameData::Item.get(ret).name))
if pbConfirmMessage(_INTL("Want to plant a Berry?")) if pbConfirmMessage(_INTL("Want to plant a Berry?"))
pbFadeOutIn { pbFadeOutIn {
@@ -468,7 +469,7 @@ def pbBerryPlant
$Trainer.name,itemname,pocket,PokemonBag.pocketNames()[pocket])) $Trainer.name,itemname,pocket,PokemonBag.pocketNames()[pocket]))
if Settings::NEW_BERRY_PLANTS if Settings::NEW_BERRY_PLANTS
pbMessage(_INTL("The soil returned to its soft and earthy state.")) pbMessage(_INTL("The soil returned to its soft and earthy state."))
berryData=[0,nil,0,0,0,0,0,0] berryData=[0,nil,0,0,0,0,0,nil]
else else
pbMessage(_INTL("The soil returned to its soft and loamy state.")) pbMessage(_INTL("The soil returned to its soft and loamy state."))
berryData=[0,nil,false,0,0,0] berryData=[0,nil,false,0,0,0]
@@ -531,7 +532,7 @@ def pbPickBerry(berry, qty = 1)
$Trainer.name,itemname,pocket,PokemonBag.pocketNames()[pocket])) $Trainer.name,itemname,pocket,PokemonBag.pocketNames()[pocket]))
if Settings::NEW_BERRY_PLANTS if Settings::NEW_BERRY_PLANTS
pbMessage(_INTL("The soil returned to its soft and earthy state.")) pbMessage(_INTL("The soil returned to its soft and earthy state."))
berryData=[0,nil,0,0,0,0,0,0] berryData=[0,nil,0,0,0,0,0,nil]
else else
pbMessage(_INTL("The soil returned to its soft and loamy state.")) pbMessage(_INTL("The soil returned to its soft and loamy state."))
berryData=[0,nil,false,0,0,0] berryData=[0,nil,false,0,0,0]

View File

@@ -456,7 +456,10 @@ class Pokemon
# @return [GameData::Nature, nil] a Nature object corresponding to this Pokémon's nature # @return [GameData::Nature, nil] a Nature object corresponding to this Pokémon's nature
def nature def nature
@nature = GameData::Nature.get(@personalID % GameData::Nature.count).id if !@nature if !@nature
idx = @personalID % GameData::Nature.count
@nature = GameData::Nature.get(GameData::Nature.keys[idx]).id
end
return GameData::Nature.try_get(@nature) return GameData::Nature.try_get(@nature)
end end

View File

@@ -212,30 +212,26 @@ module Compiler
ability_names = [] ability_names = []
ability_descriptions = [] ability_descriptions = []
pbCompilerEachPreppedLine(path) { |line, line_no| pbCompilerEachPreppedLine(path) { |line, line_no|
line = pbGetCsvRecord(line, line_no, [0, "vnss"]) line = pbGetCsvRecord(line, line_no, [0, "snss"])
ability_number = line[0]
ability_symbol = line[1].to_sym ability_symbol = line[1].to_sym
if GameData::Ability::DATA[ability_number] if GameData::Ability::DATA[ability_symbol]
raise _INTL("Ability ID number '{1}' is used twice.\r\n{2}", ability_number, FileLineData.linereport)
elsif GameData::Ability::DATA[ability_symbol]
raise _INTL("Ability ID '{1}' is used twice.\r\n{2}", ability_symbol, FileLineData.linereport) raise _INTL("Ability ID '{1}' is used twice.\r\n{2}", ability_symbol, FileLineData.linereport)
end end
# Construct ability hash # Construct ability hash
ability_hash = { ability_hash = {
:id => ability_symbol, :id => ability_symbol,
:id_number => ability_number,
:name => line[2], :name => line[2],
:description => line[3] :description => line[3]
} }
# Add ability's data to records # Add ability's data to records
GameData::Ability.register(ability_hash) GameData::Ability.register(ability_hash)
ability_names[ability_number] = ability_hash[:name] ability_names.push(ability_hash[:name])
ability_descriptions[ability_number] = ability_hash[:description] ability_descriptions.push(ability_hash[:description])
} }
# Save all data # Save all data
GameData::Ability.save GameData::Ability.save
MessageTypes.setMessages(MessageTypes::Abilities, ability_names) MessageTypes.setMessagesAsHash(MessageTypes::Abilities, ability_names)
MessageTypes.setMessages(MessageTypes::AbilityDescs, ability_descriptions) MessageTypes.setMessagesAsHash(MessageTypes::AbilityDescs, ability_descriptions)
Graphics.update Graphics.update
end end
@@ -350,13 +346,11 @@ module Compiler
if line[/^\s*(\w+)\s*=\s*(.*)$/] # Of the format XXX = YYY if line[/^\s*(\w+)\s*=\s*(.*)$/] # Of the format XXX = YYY
key = $1 key = $1
value = $2 value = $2
item_symbol = parseItem(key) item_id = parseItem(key)
item_number = GameData::Item.get(item_symbol).id_number
line = pbGetCsvRecord(value, line_no, [0, "vuuv"]) line = pbGetCsvRecord(value, line_no, [0, "vuuv"])
# Construct berry plant hash # Construct berry plant hash
berry_plant_hash = { berry_plant_hash = {
:id => item_symbol, :id => item_id,
:id_number => item_number,
:hours_per_stage => line[0], :hours_per_stage => line[0],
:drying_per_hour => line[1], :drying_per_hour => line[1],
:minimum_yield => line[2], :minimum_yield => line[2],
@@ -1419,7 +1413,7 @@ module Compiler
pbanims = PBAnimations.new pbanims = PBAnimations.new
end end
changed = false changed = false
move2anim = [[],[]] move2anim = [{}, {}]
=begin =begin
anims = load_data("Data/Animations.rxdata") anims = load_data("Data/Animations.rxdata")
for anim in anims for anim in anims
@@ -1438,13 +1432,13 @@ module Compiler
next if !pbanims[i] next if !pbanims[i]
if pbanims[i].name[/^OppMove\:\s*(.*)$/] if pbanims[i].name[/^OppMove\:\s*(.*)$/]
if GameData::Move.exists?($~[1]) if GameData::Move.exists?($~[1])
moveid = GameData::Move.get($~[1]).id_number moveid = GameData::Move.get($~[1]).id
changed = true if !move2anim[0][moveid] || move2anim[1][moveid] != i changed = true if !move2anim[0][moveid] || move2anim[1][moveid] != i
move2anim[1][moveid] = i move2anim[1][moveid] = i
end end
elsif pbanims[i].name[/^Move\:\s*(.*)$/] elsif pbanims[i].name[/^Move\:\s*(.*)$/]
if GameData::Move.exists?($~[1]) if GameData::Move.exists?($~[1])
moveid = GameData::Move.get($~[1]).id_number moveid = GameData::Move.get($~[1]).id
changed = true if !move2anim[0][moveid] || move2anim[0][moveid] != i changed = true if !move2anim[0][moveid] || move2anim[0][moveid] != i
move2anim[0][moveid] = i move2anim[0][moveid] = i
end end

View File

@@ -158,13 +158,15 @@ module Compiler
File.open("PBS/abilities.txt", "wb") { |f| File.open("PBS/abilities.txt", "wb") { |f|
add_PBS_header_to_file(f) add_PBS_header_to_file(f)
f.write("\#-------------------------------\r\n") f.write("\#-------------------------------\r\n")
idx = 1
GameData::Ability.each do |a| GameData::Ability.each do |a|
f.write(sprintf("%d,%s,%s,%s\r\n", f.write(sprintf("%s,%s,%s,%s\r\n",
a.id_number, idx,
csvQuote(a.id.to_s), csvQuote(a.id.to_s),
csvQuote(a.real_name), csvQuote(a.real_name),
csvQuoteAlways(a.real_description) csvQuoteAlways(a.real_description)
)) ))
idx += 1
end end
} }
Graphics.update Graphics.update