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
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
essentials_version 19
display_title 'Converting item IDs in Bag'

View File

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

View File

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

View File

@@ -128,7 +128,7 @@ module GameData
else
pkmn.reset_moves
end
pkmn.ability_index = pkmn_data[:ability_index]
pkmn.ability_index = pkmn_data[:ability_index] || 0
pkmn.ability = pkmn_data[:ability]
pkmn.gender = pkmn_data[:gender] || ((trainer.male?) ? 0 : 1)
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
species_num = GameData::Species.keys.index(species) || 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
GameData::Stat.each_main do |s|
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
# move has no animations defined for it.
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
if (idxUser&1)==0 # On player's side
anim = move2anim[0][id_number]
anim = move2anim[0][real_move_id]
else # On opposing side
anim = move2anim[1][id_number]
anim = move2anim[1][real_move_id]
noFlip = true if anim
anim = move2anim[0][id_number] if !anim
anim = move2anim[0][real_move_id] if !anim
end
return [anim+hitNum,noFlip] if anim
return nil

View File

@@ -142,7 +142,7 @@ class BerryPlantSprite
if secondsalive+timeDiff>=timeperstage*numlifestages
# Should replant
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
# Replant
berryData[0]=2 # replants start in sprouting stage
@@ -215,7 +215,7 @@ class BerryPlantSprite
berryData[4]=0 # reset total waterings count
berryData[5]+=1 # add to replanted count
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
end
else
@@ -272,18 +272,18 @@ def pbBerryPlant
berryData=interp.getVariable
if !berryData
if Settings::NEW_BERRY_PLANTS
berryData=[0,nil,0,0,0,0,0,0]
berryData=[0,nil,0,0,0,0,0,nil]
else
berryData=[0,nil,false,0,0,0]
end
end
# Stop the event turning towards the player
case berryData[0]
when 1 then thisEvent.turn_down # X planted
when 2 then thisEvent.turn_down # X sprouted
when 3 then thisEvent.turn_left # X taller
when 4 then thisEvent.turn_right # X flowering
when 5 then thisEvent.turn_up # X berries
when 1 then thisEvent.turn_down # X planted
when 2 then thisEvent.turn_down # X sprouted
when 3 then thisEvent.turn_left # X taller
when 4 then thisEvent.turn_right # X flowering
when 5 then thisEvent.turn_up # X berries
end
watering = [:SPRAYDUCK, :SQUIRTBOTTLE, :WAILMERPAIL, :SPRINKLOTAD]
berry=berryData[1]
@@ -291,13 +291,13 @@ def pbBerryPlant
when 0 # empty
if Settings::NEW_BERRY_PLANTS
# 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."),[
_INTL("Fertilize"),
_INTL("Plant Berry"),
_INTL("Exit")],-1)
if cmd==0 # Fertilize
ret=0
ret=nil
pbFadeOutIn {
scene = PokemonBag_Scene.new
screen = PokemonBagScreen.new(scene,$PokemonBag)
@@ -306,6 +306,7 @@ def pbBerryPlant
if ret
if GameData::Item.get(ret).is_mulch?
berryData[7]=ret
$PokemonBag.pbDeleteItem(ret, 1)
pbMessage(_INTL("The {1} was scattered on the soil.\1",GameData::Item.get(ret).name))
if pbConfirmMessage(_INTL("Want to plant a Berry?"))
pbFadeOutIn {
@@ -468,7 +469,7 @@ def pbBerryPlant
$Trainer.name,itemname,pocket,PokemonBag.pocketNames()[pocket]))
if Settings::NEW_BERRY_PLANTS
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
pbMessage(_INTL("The soil returned to its soft and loamy state."))
berryData=[0,nil,false,0,0,0]
@@ -531,7 +532,7 @@ def pbPickBerry(berry, qty = 1)
$Trainer.name,itemname,pocket,PokemonBag.pocketNames()[pocket]))
if Settings::NEW_BERRY_PLANTS
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
pbMessage(_INTL("The soil returned to its soft and loamy state."))
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
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)
end

View File

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

View File

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