mirror of
https://github.com/infinitefusion/infinitefusion-e18.git
synced 2025-12-07 13:15:01 +00:00
Created and implemented GameData::Type
This commit is contained in:
62
Data/Scripts/011_Data/001_Game data/009_Type.rb
Normal file
62
Data/Scripts/011_Data/001_Game data/009_Type.rb
Normal file
@@ -0,0 +1,62 @@
|
||||
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
|
||||
|
||||
#===============================================================================
|
||||
# Deprecated methods
|
||||
#===============================================================================
|
||||
@@ -72,7 +72,7 @@ module SpeciesData
|
||||
|
||||
def self.requiredValues(compilingForms = false)
|
||||
ret = {
|
||||
"Type1" => [TYPE1, "e", :PBTypes],
|
||||
"Type1" => [TYPE1, "e", :Type],
|
||||
"BaseStats" => [BASE_STATS, "vvvvvv"],
|
||||
"BaseEXP" => [BASE_EXP, "v"],
|
||||
"EffortPoints" => [EFFORT_POINTS, "uuuuuu"],
|
||||
@@ -99,7 +99,7 @@ module SpeciesData
|
||||
|
||||
def self.optionalValues(compilingForms = false)
|
||||
ret = {
|
||||
"Type2" => [TYPE2, "e", :PBTypes],
|
||||
"Type2" => [TYPE2, "e", :Type],
|
||||
"Abilities" => [ABILITIES, "eE", :Ability, :Ability],
|
||||
"HiddenAbility" => [HIDDEN_ABILITY, "eEEE", :Ability, :Ability,
|
||||
:Ability, :Ability],
|
||||
|
||||
@@ -4,87 +4,84 @@ module PBTypeEffectiveness
|
||||
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
|
||||
|
||||
|
||||
|
||||
class PBTypes
|
||||
@@TypeData = nil
|
||||
|
||||
def PBTypes.loadTypeData
|
||||
if !@@TypeData
|
||||
@@TypeData = load_data("Data/types.dat")
|
||||
@@TypeData[0].freeze
|
||||
@@TypeData[1].freeze
|
||||
@@TypeData[2].freeze
|
||||
@@TypeData.freeze
|
||||
end
|
||||
return @@TypeData
|
||||
end
|
||||
|
||||
def PBTypes.regularTypesCount
|
||||
ret = 0
|
||||
for i in 0..PBTypes.maxValue
|
||||
next if PBTypes.isPseudoType?(i) || isConst?(i,PBTypes,:SHADOW)
|
||||
ret += 1
|
||||
end
|
||||
GameData::Type.each { |t| ret += 1 if !t.pseudo_type && t.id != :SHADOW }
|
||||
return ret
|
||||
end
|
||||
|
||||
def PBTypes.isPseudoType?(type)
|
||||
return PBTypes.loadTypeData[0].include?(type)
|
||||
return GameData::Type.get(type).pseudo_type
|
||||
end
|
||||
|
||||
def PBTypes.isSpecialType?(type)
|
||||
return PBTypes.loadTypeData[1].include?(type)
|
||||
return GameData::Type.get(type).special?
|
||||
end
|
||||
|
||||
def PBTypes.getEffectiveness(attackType,targetType)
|
||||
return PBTypeEffectiveness::NORMAL_EFFECTIVE_ONE if !targetType || targetType<0
|
||||
return PBTypes.loadTypeData[2][attackType*(PBTypes.maxValue+1)+targetType]
|
||||
def PBTypes.getEffectiveness(attack_type, target_type)
|
||||
return GameData::Type.get(target_type).effectiveness(attack_type)
|
||||
end
|
||||
|
||||
def PBTypes.getCombinedEffectiveness(attackType,targetType1,targetType2=nil,targetType3=nil)
|
||||
mod1 = PBTypes.getEffectiveness(attackType,targetType1)
|
||||
def PBTypes.getCombinedEffectiveness(attack_type, target_type1, target_type2 = nil, target_type3 = nil)
|
||||
mod1 = PBTypes.getEffectiveness(attack_type, target_type1)
|
||||
mod2 = PBTypeEffectiveness::NORMAL_EFFECTIVE_ONE
|
||||
mod3 = PBTypeEffectiveness::NORMAL_EFFECTIVE_ONE
|
||||
if targetType2!=nil && targetType2>=0 && targetType1!=targetType2
|
||||
mod2 = PBTypes.getEffectiveness(attackType,targetType2)
|
||||
if target_type2 && target_type1 != target_type2
|
||||
mod2 = PBTypes.getEffectiveness(attack_type, target_type2)
|
||||
end
|
||||
if targetType3!=nil && targetType3>=0 &&
|
||||
targetType1!=targetType3 && targetType2!=targetType3
|
||||
mod3 = PBTypes.getEffectiveness(attackType,targetType3)
|
||||
if target_type3 && target_type1 != target_type3 && target_type2 != target_type3
|
||||
mod3 = PBTypes.getEffectiveness(attack_type, target_type3)
|
||||
end
|
||||
return mod1*mod2*mod3
|
||||
return mod1 * mod2 * mod3
|
||||
end
|
||||
|
||||
def PBTypes.ineffective?(attackType,targetType1=nil,targetType2=nil,targetType3=nil)
|
||||
return attackType==PBTypeEffectiveness::INEFFECTIVE if !targetType1
|
||||
e = PBTypes.getCombinedEffectiveness(attackType,targetType1,targetType2,targetType3)
|
||||
return e==PBTypeEffectiveness::INEFFECTIVE
|
||||
def PBTypes.ineffective?(attack_type, target_type1, target_type2 = nil, target_type3 = nil)
|
||||
value = PBTypes.getCombinedEffectiveness(attack_type, target_type1, target_type2, target_type3)
|
||||
return PBTypeEffectiveness.ineffective?(value)
|
||||
end
|
||||
|
||||
def PBTypes.notVeryEffective?(attackType,targetType1=nil,targetType2=nil,targetType3=nil)
|
||||
return attackType>PBTypeEffectiveness::INEFFECTIVE && attackType<PBTypeEffectiveness::NORMAL_EFFECTIVE if !targetType1
|
||||
e = PBTypes.getCombinedEffectiveness(attackType,targetType1,targetType2,targetType3)
|
||||
return e>PBTypeEffectiveness::INEFFECTIVE && e<PBTypeEffectiveness::NORMAL_EFFECTIVE
|
||||
def PBTypes.notVeryEffective?(attack_type, target_type1, target_type2 = nil, target_type3 = nil)
|
||||
value = PBTypes.getCombinedEffectiveness(attack_type, target_type1, target_type2, target_type3)
|
||||
return PBTypeEffectiveness.notVeryEffective?(value)
|
||||
end
|
||||
|
||||
def PBTypes.resistant?(attackType,targetType1=nil,targetType2=nil,targetType3=nil)
|
||||
return attackType<PBTypeEffectiveness::NORMAL_EFFECTIVE if !targetType1
|
||||
e = PBTypes.getCombinedEffectiveness(attackType,targetType1,targetType2,targetType3)
|
||||
return e<PBTypeEffectiveness::NORMAL_EFFECTIVE
|
||||
def PBTypes.resistant?(attack_type, target_type1, target_type2 = nil, target_type3 = nil)
|
||||
value = PBTypes.getCombinedEffectiveness(attack_type, target_type1, target_type2, target_type3)
|
||||
return PBTypeEffectiveness.resistant?(value)
|
||||
end
|
||||
|
||||
def PBTypes.normalEffective?(attackType,targetType1=nil,targetType2=nil,targetType3=nil)
|
||||
return attackType==PBTypeEffectiveness::NORMAL_EFFECTIVE if !targetType1
|
||||
e = PBTypes.getCombinedEffectiveness(attackType,targetType1,targetType2,targetType3)
|
||||
return e==PBTypeEffectiveness::NORMAL_EFFECTIVE
|
||||
def PBTypes.normalEffective?(attack_type, target_type1, target_type2 = nil, target_type3 = nil)
|
||||
value = PBTypes.getCombinedEffectiveness(attack_type, target_type1, target_type2, target_type3)
|
||||
return PBTypeEffectiveness.normalEffective?(value)
|
||||
end
|
||||
|
||||
def PBTypes.superEffective?(attackType,targetType1=nil,targetType2=nil,targetType3=nil)
|
||||
return attackType>PBTypeEffectiveness::NORMAL_EFFECTIVE if !targetType1
|
||||
e = PBTypes.getCombinedEffectiveness(attackType,targetType1,targetType2,targetType3)
|
||||
return e>PBTypeEffectiveness::NORMAL_EFFECTIVE
|
||||
def PBTypes.superEffective?(attack_type, target_type1, target_type2 = nil, target_type3 = nil)
|
||||
value = PBTypes.getCombinedEffectiveness(attack_type, target_type1, target_type2, target_type3)
|
||||
return PBTypeEffectiveness.superEffective?(value)
|
||||
end
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user