Rearranged and tidied up game data scripts

This commit is contained in:
Maruno17
2021-03-29 19:01:03 +01:00
parent cd62ba840c
commit 01a066a4d9
55 changed files with 263 additions and 276 deletions

View File

@@ -195,17 +195,17 @@ module GameData
# A bulk loader method for all data stored in .dat files in the Data folder.
#=============================================================================
def self.load_all
Type.load
Ability.load
Move.load
Item.load
BerryPlant.load
Species.load
Ribbon.load
Encounter.load
TrainerType.load
Trainer.load
Metadata.load
MapMetadata.load
Move.load
TrainerType.load
Type.load
Species.load
Trainer.load
Encounter.load
Ribbon.load
end
end

View File

@@ -1,58 +0,0 @@
module GameData
class Type
attr_reader :id
attr_reader :id_number
attr_reader :real_name
attr_reader :special_type
attr_reader :pseudo_type
attr_reader :weaknesses
attr_reader :resistances
attr_reader :immunities
DATA = {}
DATA_FILENAME = "types.dat"
SCHEMA = {
"Name" => [1, "s"],
"InternalName" => [2, "s"],
"IsPseudoType" => [3, "b"],
"IsSpecialType" => [4, "b"],
"Weaknesses" => [5, "*s"],
"Resistances" => [6, "*s"],
"Immunities" => [7, "*s"]
}
extend ClassMethods
include InstanceMethods
def initialize(hash)
@id = hash[:id]
@id_number = hash[:id_number] || -1
@real_name = hash[:name] || "Unnamed"
@pseudo_type = hash[:pseudo_type] || false
@special_type = hash[:special_type] || false
@weaknesses = hash[:weaknesses] || []
@weaknesses = [@weaknesses] if !@weaknesses.is_a?(Array)
@resistances = hash[:resistances] || []
@resistances = [@resistances] if !@resistances.is_a?(Array)
@immunities = hash[:immunities] || []
@immunities = [@immunities] if !@immunities.is_a?(Array)
end
# @return [String] the translated name of this item
def name
return pbGetMessage(MessageTypes::Types, @id_number)
end
def physical?; return !@special_type; end
def special?; return @special_type; end
def effectiveness(other_type)
return PBTypeEffectiveness::NORMAL_EFFECTIVE_ONE if !other_type
return PBTypeEffectiveness::SUPER_EFFECTIVE_ONE if @weaknesses.include?(other_type)
return PBTypeEffectiveness::NOT_EFFECTIVE_ONE if @resistances.include?(other_type)
return PBTypeEffectiveness::INEFFECTIVE if @immunities.include?(other_type)
return PBTypeEffectiveness::NORMAL_EFFECTIVE_ONE
end
end
end

View File

@@ -4,10 +4,10 @@
class PokemonTemp
attr_accessor :townMapData
attr_accessor :phoneData
attr_accessor :regionalDexes
attr_accessor :speciesShadowMovesets
attr_accessor :moveToAnim
attr_accessor :regionalDexes
attr_accessor :battleAnims
attr_accessor :moveToAnim
attr_accessor :mapInfos
end
@@ -15,10 +15,10 @@ def pbClearData
if $PokemonTemp
$PokemonTemp.townMapData = nil
$PokemonTemp.phoneData = nil
$PokemonTemp.regionalDexes = nil
$PokemonTemp.speciesShadowMovesets = nil
$PokemonTemp.moveToAnim = nil
$PokemonTemp.regionalDexes = nil
$PokemonTemp.battleAnims = nil
$PokemonTemp.moveToAnim = nil
$PokemonTemp.mapInfos = nil
end
MapFactoryHelper.clear
@@ -52,17 +52,6 @@ def pbLoadPhoneData
return $PokemonTemp.phoneData
end
#===============================================================================
# Method to get Regional Dexes data.
#===============================================================================
def pbLoadRegionalDexes
$PokemonTemp = PokemonTemp.new if !$PokemonTemp
if !$PokemonTemp.regionalDexes
$PokemonTemp.regionalDexes = load_data("Data/regional_dexes.dat")
end
return $PokemonTemp.regionalDexes
end
#===============================================================================
# Method to get Shadow Pokémon moveset data.
#===============================================================================
@@ -75,16 +64,19 @@ def pbLoadShadowMovesets
end
#===============================================================================
# Methods relating to battle animations data.
# Method to get Regional Dexes data.
#===============================================================================
def pbLoadMoveToAnim
def pbLoadRegionalDexes
$PokemonTemp = PokemonTemp.new if !$PokemonTemp
if !$PokemonTemp.moveToAnim
$PokemonTemp.moveToAnim = load_data("Data/move2anim.dat") || []
if !$PokemonTemp.regionalDexes
$PokemonTemp.regionalDexes = load_data("Data/regional_dexes.dat")
end
return $PokemonTemp.moveToAnim
return $PokemonTemp.regionalDexes
end
#===============================================================================
# Methods relating to battle animations data.
#===============================================================================
def pbLoadBattleAnimations
$PokemonTemp = PokemonTemp.new if !$PokemonTemp
if !$PokemonTemp.battleAnims
@@ -95,6 +87,14 @@ def pbLoadBattleAnimations
return $PokemonTemp.battleAnims
end
def pbLoadMoveToAnim
$PokemonTemp = PokemonTemp.new if !$PokemonTemp
if !$PokemonTemp.moveToAnim
$PokemonTemp.moveToAnim = load_data("Data/move2anim.dat") || []
end
return $PokemonTemp.moveToAnim
end
#===============================================================================
# Method relating to map infos data.
#===============================================================================

View File

@@ -0,0 +1,132 @@
module GameData
class Type
attr_reader :id
attr_reader :id_number
attr_reader :real_name
attr_reader :special_type
attr_reader :pseudo_type
attr_reader :weaknesses
attr_reader :resistances
attr_reader :immunities
DATA = {}
DATA_FILENAME = "types.dat"
SCHEMA = {
"Name" => [1, "s"],
"InternalName" => [2, "s"],
"IsPseudoType" => [3, "b"],
"IsSpecialType" => [4, "b"],
"Weaknesses" => [5, "*s"],
"Resistances" => [6, "*s"],
"Immunities" => [7, "*s"]
}
extend ClassMethods
include InstanceMethods
def initialize(hash)
@id = hash[:id]
@id_number = hash[:id_number] || -1
@real_name = hash[:name] || "Unnamed"
@pseudo_type = hash[:pseudo_type] || false
@special_type = hash[:special_type] || false
@weaknesses = hash[:weaknesses] || []
@weaknesses = [@weaknesses] if !@weaknesses.is_a?(Array)
@resistances = hash[:resistances] || []
@resistances = [@resistances] if !@resistances.is_a?(Array)
@immunities = hash[:immunities] || []
@immunities = [@immunities] if !@immunities.is_a?(Array)
end
# @return [String] the translated name of this item
def name
return pbGetMessage(MessageTypes::Types, @id_number)
end
def physical?; return !@special_type; end
def special?; return @special_type; end
def effectiveness(other_type)
return Effectiveness::NORMAL_EFFECTIVE_ONE if !other_type
return Effectiveness::SUPER_EFFECTIVE_ONE if @weaknesses.include?(other_type)
return Effectiveness::NOT_VERY_EFFECTIVE_ONE if @resistances.include?(other_type)
return Effectiveness::INEFFECTIVE if @immunities.include?(other_type)
return Effectiveness::NORMAL_EFFECTIVE_ONE
end
end
end
#===============================================================================
module Effectiveness
INEFFECTIVE = 0
NOT_VERY_EFFECTIVE_ONE = 1
NORMAL_EFFECTIVE_ONE = 2
SUPER_EFFECTIVE_ONE = 4
NORMAL_EFFECTIVE = NORMAL_EFFECTIVE_ONE ** 3
module_function
def ineffective?(value)
return value == INEFFECTIVE
end
def not_very_effective?(value)
return value > INEFFECTIVE && value < NORMAL_EFFECTIVE
end
def resistant?(value)
return value < NORMAL_EFFECTIVE
end
def normal?(value)
return value == NORMAL_EFFECTIVE
end
def super_effective?(value)
return value > NORMAL_EFFECTIVE
end
def ineffective_type?(attack_type, defend_type1, defend_type2 = nil, defend_type3 = nil)
value = calculate(attack_type, target_type1, target_type2, target_type3)
return ineffective?(value)
end
def not_very_effective_type?(attack_type, defend_type1, defend_type2 = nil, defend_type3 = nil)
value = calculate(attack_type, target_type1, target_type2, target_type3)
return not_very_effective?(value)
end
def resistant_type?(attack_type, defend_type1, defend_type2 = nil, defend_type3 = nil)
value = calculate(attack_type, target_type1, target_type2, target_type3)
return resistant?(value)
end
def normal_type?(attack_type, defend_type1, defend_type2 = nil, defend_type3 = nil)
value = calculate(attack_type, target_type1, target_type2, target_type3)
return normal?(value)
end
def super_effective_type?(attack_type, defend_type1, defend_type2 = nil, defend_type3 = nil)
value = calculate(attack_type, target_type1, target_type2, target_type3)
return super_effective?(value)
end
def calculate_one(attack_type, defend_type)
return GameData::Type.get(defend_type).effectiveness(attack_type)
end
def calculate(attack_type, defend_type1, defend_type2 = nil, defend_type3 = nil)
mod1 = calculate_one(attack_type, defend_type1)
mod2 = NORMAL_EFFECTIVE_ONE
mod3 = NORMAL_EFFECTIVE_ONE
if defend_type2 && defend_type1 != defend_type2
mod2 = calculate_one(attack_type, defend_type2)
end
if defend_type3 && defend_type1 != defend_type3 && defend_type2 != defend_type3
mod3 = calculate_one(attack_type, defend_type3)
end
return mod1 * mod2 * mod3
end
end

View File

@@ -1,83 +0,0 @@
module PBTypeEffectiveness
INEFFECTIVE = 0
NOT_EFFECTIVE_ONE = 1
NORMAL_EFFECTIVE_ONE = 2
SUPER_EFFECTIVE_ONE = 4
NORMAL_EFFECTIVE = NORMAL_EFFECTIVE_ONE ** 3
def self.ineffective?(value)
return value == INEFFECTIVE
end
def self.notVeryEffective?(value)
return value > INEFFECTIVE && value < NORMAL_EFFECTIVE
end
def self.resistant?(value)
return value < NORMAL_EFFECTIVE
end
def self.normalEffective?(value)
return value == NORMAL_EFFECTIVE
end
def self.superEffective?(value)
return value > NORMAL_EFFECTIVE
end
end
module PBTypes
def self.regularTypesCount
ret = 0
GameData::Type.each { |t| ret += 1 if !t.pseudo_type && t.id != :SHADOW }
return ret
end
def self.isPhysicalType?(type); return GameData::Type.get(type).physical?; end
def self.isSpecialType?(type); return GameData::Type.get(type).special?; end
def self.isPseudoType?(type); return GameData::Type.get(type).pseudo_type; end
def self.getEffectiveness(attack_type, target_type)
return GameData::Type.get(target_type).effectiveness(attack_type)
end
def self.getCombinedEffectiveness(attack_type, target_type1, target_type2 = nil, target_type3 = nil)
mod1 = self.getEffectiveness(attack_type, target_type1)
mod2 = PBTypeEffectiveness::NORMAL_EFFECTIVE_ONE
mod3 = PBTypeEffectiveness::NORMAL_EFFECTIVE_ONE
if target_type2 && target_type1 != target_type2
mod2 = self.getEffectiveness(attack_type, target_type2)
end
if target_type3 && target_type1 != target_type3 && target_type2 != target_type3
mod3 = self.getEffectiveness(attack_type, target_type3)
end
return mod1 * mod2 * mod3
end
def self.ineffective?(attack_type, target_type1, target_type2 = nil, target_type3 = nil)
value = self.getCombinedEffectiveness(attack_type, target_type1, target_type2, target_type3)
return PBTypeEffectiveness.ineffective?(value)
end
def self.notVeryEffective?(attack_type, target_type1, target_type2 = nil, target_type3 = nil)
value = self.getCombinedEffectiveness(attack_type, target_type1, target_type2, target_type3)
return PBTypeEffectiveness.notVeryEffective?(value)
end
def self.resistant?(attack_type, target_type1, target_type2 = nil, target_type3 = nil)
value = self.getCombinedEffectiveness(attack_type, target_type1, target_type2, target_type3)
return PBTypeEffectiveness.resistant?(value)
end
def self.normalEffective?(attack_type, target_type1, target_type2 = nil, target_type3 = nil)
value = self.getCombinedEffectiveness(attack_type, target_type1, target_type2, target_type3)
return PBTypeEffectiveness.normalEffective?(value)
end
def self.superEffective?(attack_type, target_type1, target_type2 = nil, target_type3 = nil)
value = self.getCombinedEffectiveness(attack_type, target_type1, target_type2, target_type3)
return PBTypeEffectiveness.superEffective?(value)
end
end