[wip] generate fusions dynamically

This commit is contained in:
infinitefusion
2023-08-05 22:10:03 -04:00
parent 41acb265da
commit 9f44271b99
30 changed files with 283 additions and 36 deletions

View File

@@ -24,12 +24,28 @@ module GameData
# @return [self]
def get(other)
validate other => [Symbol, self, String, Integer]
return other if other.is_a?(self)
other = other.to_sym if other.is_a?(String)
# if other.is_a?(Integer)
# p "Please switch to symbols, thanks."
# end
if other.to_s.match?(/\AB\d+H\d+\z/)
species = GameData::FusedSpecies.new(other)
return species
end
if other.is_a?(Integer) #assume it's a species
if other > NB_POKEMON
body_id = getBodyID(other)
head_id = getHeadID(other,body_id)
pokemon_id = getFusedPokemonIdFromDexNum(body_id,head_id)
return GameData::FusedSpecies.new(pokemon_id)
end
end
raise "Unknown ID #{other}." unless self::DATA.has_key?(other)
#if other == :Species
# end
return self::DATA[other]
end

View File

@@ -59,18 +59,19 @@ module GameData
# @param form [Integer]
# @return [self, nil]
def self.get_species_form(species, form)
return nil if !species || !form
validate species => [Symbol, self, String, Integer]
validate form => Integer
# if other.is_a?(Integer)
# p "Please switch to symbols, thanks."
# end
species = species.species if species.is_a?(self)
species = DATA[species].species if species.is_a?(Integer)
species = species.to_sym if species.is_a?(String)
trial = sprintf("%s_%d", species, form).to_sym
species_form = (DATA[trial].nil?) ? species : trial
return (DATA.has_key?(species_form)) ? DATA[species_form] : nil
return GameData::Species.get(species) rescue nil
# return nil if !species || !form
# validate species => [Symbol, self, String, Integer]
# validate form => Integer
# # if other.is_a?(Integer)
# # p "Please switch to symbols, thanks."
# # end
# species = species.species if species.is_a?(self)
# species = DATA[species].species if species.is_a?(Integer)
# species = species.to_sym if species.is_a?(String)
# trial = sprintf("%s_%d", species, form).to_sym
# species_form = (DATA[trial].nil?) ? species : trial
# return (DATA.has_key?(species_form)) ? DATA[species_form] : nil
end
def self.schema(compiling_forms = false)
@@ -191,22 +192,26 @@ module GameData
end
# @return [String] the translated name of this species
def name
return pbGetMessage(MessageTypes::Species, @id_number)
return @real_name
#return pbGetMessage(MessageTypes::Species, @id_number)
end
# @return [String] the translated name of this form of this species
def form_name
return pbGetMessage(MessageTypes::FormNames, @id_number)
return @real_form_name
#return pbGetMessage(MessageTypes::FormNames, @id_number)
end
# @return [String] the translated Pokédex category of this species
def category
return pbGetMessage(MessageTypes::Kinds, @id_number)
return @real_category
#return pbGetMessage(MessageTypes::Kinds, @id_number)
end
# @return [String] the translated Pokédex entry of this species
def pokedex_entry
return pbGetMessage(MessageTypes::Entries, @id_number)
return @real_pokedex_entry
#return pbGetMessage(MessageTypes::Entries, @id_number)
end
def is_fusion

View File

@@ -210,10 +210,10 @@ module GameData
species_data = GameData::Species.get(getHeadID(species_data))
end
if form > 0
ret = sprintf("Cries/%s_%d", species_data.species, form)
return ret if pbResolveAudioSE(ret)
end
# if form > 0
# ret = sprintf("Cries/%s_%d", species_data.species, form)
# return ret if pbResolveAudioSE(ret)
# end
ret = sprintf("Cries/%s", species_data.species)
return (pbResolveAudioSE(ret)) ? ret : nil
end

View File

@@ -126,7 +126,8 @@ class Pokemon
end
def species_data
return GameData::Species.get_species_form(@species, form_simple)
@species_data = GameData::Species.get(@species) if ! @species_data
return @species_data #GameData::Species.get(@species)
end
#=============================================================================
@@ -142,6 +143,7 @@ class Pokemon
new_species_data = GameData::Species.get(species_id)
return if @species == new_species_data.species
@species = new_species_data.species
p @species.name
@form = new_species_data.form if new_species_data.form != 0
@forced_form = nil
@level = nil # In case growth rate is different for the new species
@@ -1221,9 +1223,9 @@ class Pokemon
# @param withMoves [TrueClass, FalseClass] whether the Pokémon should have moves
# @param rechech_form [TrueClass, FalseClass] whether to auto-check the form
def initialize(species, level, owner = $Trainer, withMoves = true, recheck_form = true)
species_data = GameData::Species.get(species)
@species = species_data.species
@form = species_data.form
@species_data = GameData::Species.get(species)
@species = @species_data.species
@form = @species_data.form
@forced_form = nil
@time_form_set = nil
self.level = level
@@ -1253,7 +1255,7 @@ class Pokemon
@sheen = 0
@pokerus = 0
@name = nil
@happiness = species_data.happiness
@happiness = @species_data.happiness
@poke_ball = :POKEBALL
@markings = 0
@iv = {}

View File

@@ -80,12 +80,16 @@ class Player < Trainer
end
def set_seen_fusion(species)
initFusionDexArray() if @seen_fusion.length < NB_POKEMON+2
bodyId = getBodyID(species)
headId = getHeadID(species, bodyId)
@seen_fusion[headId][bodyId] = true
end
def set_seen_normalDex(species)
initStandardDexArray() if @seen_standard.length < NB_POKEMON
dex_num = getDexNumberForSpecies(species)
@seen_standard[dex_num] = true
end

View File

@@ -328,7 +328,9 @@ module Compiler
enumer = GameData.const_get(enumer.to_sym)
begin
if nil_or_empty?(ret) || !enumer.exists?(ret.to_sym)
raise _INTL("Undefined value {1} in {2}\r\n{3}", ret, enumer.name, FileLineData.linereport)
if enumer != GameData::Species
raise _INTL("Undefined value {1} in {2}\r\n{3}", ret, enumer.name, FileLineData.linereport)
end
end
rescue NameError
raise _INTL("Incorrect value {1} in {2}\r\n{3}", ret, enumer.name, FileLineData.linereport)

View File

@@ -458,7 +458,7 @@ def getDexNumFromFilename(filename)
head = splitPoke[0].to_i
body = splitPoke[1].to_i
return nil if (body * NB_POKEMON) + head > (NB_POKEMON * NB_POKEMON) + 420
return nil if (body * NB_POKEMON) + head > (NB_POKEMON * NB_POKEMON) + NB_POKEMON
return (body * NB_POKEMON) + head
end

View File

@@ -0,0 +1,188 @@
module GameData
class FusedSpecies < GameData::Species
attr_reader :growth_rate
def initialize(id)
if id.is_a?(Integer)
body_id = getBodyID(id)
head_id = getHeadID(id,body_id)
pokemon_id = getFusedPokemonIdFromDexNum(body_id,head_id)
return GameData::FusedSpecies.new(pokemon_id)
end
head_id = get_head_id_from_symbol(id)
body_id = get_body_id_from_symbol(id)
@body_pokemon = GameData::Species.get(head_id)
@head_pokemon = GameData::Species.get(body_id)
@id = id
@id_number = calculate_dex_number()
@species = @id
@form = 0
@real_name = calculate_name() #todo
@real_form_name = nil
@real_category = "???" #todo
@real_pokedex_entry = calculate_dex_entry() #todo
@pokedex_form = @form
#todo type exceptions
@type1 = @head_pokemon.type1
@type2 = @body_pokemon.type2
#Stats
@base_stats = calculate_base_stats()
@evs = calculate_evs() #todo
adjust_stats_with_evs()
@base_exp = calculate_base_exp()
@growth_rate = calculate_growth_rate() #todo
@gender_ratio = calculate_gender() #todo
@catch_rate = calculate_catch_rate()
@happiness = calculate_base_happiness()
@moves = calculate_moveset()
#todo : all below
@tutor_moves = [] # hash[:tutor_moves] || []
@egg_moves = [] # hash[:egg_moves] || []
@abilities = [] # hash[:abilities] || []
@hidden_abilities = [] # hash[:hidden_abilities] || []
@wild_item_common = [] # hash[:wild_item_common]
@wild_item_uncommon = [] # hash[:wild_item_uncommon]
@wild_item_rare = [] # hash[:wild_item_rare]
@egg_groups = [:Undiscovered] # hash[:egg_groups] || [:Undiscovered]
@hatch_steps = 1 # hash[:hatch_steps] || 1
@incense = nil #hash[:incense]
@evolutions = [] # hash[:evolutions] || []
@height = 1 # hash[:height] || 1
@weight = 1 #hash[:weight] || 1
@color = :Red #hash[:color] || :Red
@shape = :Head #hash[:shape] || :Head
@habitat = :None #hash[:habitat] || :None
@generation = 0 #hash[:generation] || 0
@mega_stone = nil
@mega_move = nil
@unmega_form = 0
@mega_message = 0
@back_sprite_x = 0 # hash[:back_sprite_x] || 0
@back_sprite_y = 0 # hash[:back_sprite_y] || 0
@front_sprite_x = 0 # hash[:front_sprite_x] || 0
@front_sprite_y = 0 # hash[:front_sprite_y] || 0
@front_sprite_altitude = 0 # hash[:front_sprite_altitude] || 0
@shadow_x = 0 # hash[:shadow_x] || 0
@shadow_size = 2 # hash[:shadow_size] || 2
@alwaysUseGeneratedSprite = false
end
def get_body_id_from_symbol(id)
return id.to_s.match(/\d+/)[0].to_i
end
def get_head_id_from_symbol(id)
return id.to_s.match(/(?<=H)\d+/)[0].to_i
end
def adjust_stats_with_evs
GameData::Stat.each_main do |s|
@base_stats[s.id] = 1 if !@base_stats[s.id] || @base_stats[s.id] <= 0
@evs[s.id] = 0 if !@evs[s.id] || @evs[s.id] < 0
end
end
#FUSION CALCULATIONS
def calculate_dex_number()
return (@head_pokemon.id_number * NB_POKEMON) + @body_pokemon.id_number
end
def calculate_base_stats()
head_stats = @head_pokemon.base_stats
body_stats = @body_pokemon.base_stats
fused_stats = {}
#Head dominant stats
fused_stats[:HP] = calculate_fused_stats(head_stats[:HP], body_stats[:HP])
fused_stats[:SPECIAL_DEFENSE] = calculate_fused_stats(head_stats[:SPECIAL_DEFENSE], body_stats[:SPECIAL_DEFENSE])
fused_stats[:SPECIAL_ATTACK] = calculate_fused_stats(head_stats[:SPECIAL_ATTACK], body_stats[:SPECIAL_ATTACK])
#Body dominant stats
fused_stats[:ATTACK] = calculate_fused_stats(body_stats[:ATTACK], head_stats[:ATTACK])
fused_stats[:DEFENSE] = calculate_fused_stats(body_stats[:DEFENSE], head_stats[:DEFENSE])
fused_stats[:SPEED] = calculate_fused_stats(body_stats[:SPEED], head_stats[:SPEED])
return fused_stats
end
def calculate_base_exp()
head_exp = @head_pokemon.base_exp
body_exp = @body_pokemon.base_exp
return average_values(head_exp, body_exp)
end
def calculate_catch_rate
return get_lowest_value(@body_pokemon.catch_rate, @head_pokemon.catch_rate)
end
def calculate_base_happiness
return @head_pokemon.happiness
end
def calculate_moveset
return combine_arrays(@body_pokemon.moves, @head_pokemon.moves)
end
#todo
def calculate_name()
return @body_pokemon.name + "/" + @head_pokemon.name
end
#todo
def calculate_evs()
return {}
end
#todo
def calculate_growth_rate
return :Medium
end
#todo
def calculate_dex_entry
return "this is a fused pokemon bro"
end
#todo
def calculate_gender
return :Genderless
end
#UTILS
#
def calculate_fused_stats(dominantStat, otherStat)
return ((2 * dominantStat) / 3) + (otherStat / 3).floor
end
def average_values(value1, value2)
return ((value1 + value2) / 2).floor
end
def average_map_values(map1, map2)
averaged_map = map1.merge(map2) do |key, value1, value2|
((value1 + value2) / 2.0).floor
end
return averaged_map
end
def get_highest_value(value1, value2)
return value1 > value2 ? value1 : value2
end
def get_lowest_value(value1, value2)
return value1 < value2 ? value1 : value2
end
def combine_arrays(array1, array2)
return array1 + array2
end
end
end

View File

@@ -14,8 +14,8 @@
# PokemonFusion
#
NB_POKEMON = 420 #351 #aussi CONST_NB_POKE
NB_POKEMON = 809#420 #351 #aussi CONST_NB_POKE
CONST_NB_POKE = NB_POKEMON
def pbPokemonBitmapFile(species)
# Used by the Pokédex
# Load normal bitmap

View File

@@ -146,8 +146,24 @@ def getDexNumberForSpecies(species)
return dexNum
end
def getFusedPokemonIdFromDexNum(body_dex, head_dex)
return ("B" + body_dex.to_s + "H" + head_dex.to_s).to_sym
end
def getPokemon(dexNum)
return GameData::Species.get(dexNum)
if dexNum.is_a?(Integer)
if dexNum > NB_POKEMON
body_id = getBodyID(dexNum)
head_id = getHeadID(dexNum,body_id)
pokemon_id = getFusedPokemonIdFromDexNum(body_id,head_id)
else
pokemon_id = dexNum
end
else
pokemon_id = dexNum
end
return GameData::Species.get(pokemon_id)
end
def getSpecies(dexnum)
@@ -238,19 +254,30 @@ def getRandomCustomFusion(returnRandomPokemonIfNoneFound = true, customPokeList
return randPoke
end
def getBodyID(species)
dexNum = getDexNumberForSpecies(species)
if species.is_a?(Integer)
dexNum = species
else
dexNum = getDexNumberForSpecies(species)
end
if dexNum % NB_POKEMON == 0
return (dexNum / NB_POKEMON) - 1
end
return (dexNum / NB_POKEMON).round
end
def getHeadID(species, bodyId = nil)
if species.is_a?(Integer)
fused_dexNum = species
else
fused_dexNum = getDexNumberForSpecies(species)
end
if bodyId == nil
bodyId = getBodyID(species)
end
fused_dexNum = getDexNumberForSpecies(species)
body_dexNum = getDexNumberForSpecies(bodyId)
calculated_number = (fused_dexNum - (body_dexNum * NB_POKEMON)).round

View File

@@ -1393,6 +1393,9 @@ def pbDNASplicing(pokemon, scene, supersplicers = false, superSplicer = false)
end
def selectFusion(pokemon, poke2, supersplicers = false)
p pokemon
p poke2
return nil if !pokemon.is_a?(Pokemon) || !poke2.is_a?(Pokemon)
return nil if pokemon.egg? || poke2.egg?