Split PokeBattle_Trainer into PlayerTrainer and NPCTrainer

This commit is contained in:
Maruno17
2021-01-24 17:55:39 +00:00
parent 7de034957b
commit 4098b1cd11
60 changed files with 748 additions and 648 deletions

View File

@@ -1,240 +0,0 @@
class PokeBattle_Trainer
attr_accessor :name
attr_accessor :id
attr_writer :metaID
attr_accessor :trainertype
attr_writer :outfit
attr_accessor :badges
attr_reader :money
attr_accessor :seen
attr_accessor :owned
attr_accessor :formseen
attr_accessor :formlastseen
attr_accessor :shadowcaught
attr_accessor :party
attr_accessor :pokedex # Whether the Pokédex was obtained
attr_accessor :pokegear # Whether the Pokégear was obtained
attr_writer :language
def trainerTypeName; return GameData::TrainerType.get(@trainertype).name; end
def moneyEarned; return GameData::TrainerType.get(@trainertype).base_money; end
def gender; return GameData::TrainerType.get(@trainertype).gender; end
def male?; return GameData::TrainerType.get(@trainertype).male?; end
def female?; return GameData::TrainerType.get(@trainertype).female?; end
alias isMale? male?
alias isFemale? female?
def skill; return GameData::TrainerType.get(@trainertype).skill_level; end
def skillCode; return GameData::TrainerType.get(@trainertype).skill_code; end
def hasSkillCode(code)
c = skillCode
return c && c != "" && c[/#{code}/]
end
def fullname
return _INTL("{1} {2}", trainerTypeName, @name)
end
#=============================================================================
# Unique ID number
#=============================================================================
def publicID(id = nil) # Portion of the ID which is visible on the Trainer Card
return id ? id & 0xFFFF : @id & 0xFFFF
end
def secretID(id = nil) # Other portion of the ID
return id ? id >> 16 : @id >> 16
end
def getForeignID # Random ID other than this Trainer's ID
fid = 0
loop do
fid = rand(2 ** 16) | rand(2 ** 16) << 16
break if fid != @id
end
return fid
end
def setForeignID(other)
@id = other.getForeignID
end
def metaID
@metaID = $PokemonGlobal.playerID if !@metaID
@metaID = 0 if !@metaID
return @metaID
end
#=============================================================================
# Other properties
#=============================================================================
def outfit
return @outfit || 0
end
def language
return @language || pbGetLanguage
end
def money=(value)
@money = [[value, MAX_MONEY].min, 0].max
end
def numbadges # Number of badges
ret = 0
@badges.each { |b| ret += 1 if b }
return ret
end
#=============================================================================
# Party
#=============================================================================
def pokemonParty
return @party.find_all { |p| p && !p.egg? }
end
def ablePokemonParty
return @party.find_all { |p| p && !p.egg? && !p.fainted? }
end
def partyCount
return @party.length
end
def pokemonCount
ret = 0
@party.each { |p| ret += 1 if p && !p.egg? }
return ret
end
def ablePokemonCount
ret = 0
@party.each { |p| ret += 1 if p && !p.egg? && !p.fainted? }
return ret
end
def firstParty
return nil if @party.length == 0
return @party[0]
end
def firstPokemon
p = self.pokemonParty
return nil if p.length == 0
return p[0]
end
def firstAblePokemon
p = self.ablePokemonParty
return nil if p.length == 0
return p[0]
end
def lastParty
return nil if @party.length == 0
return @party[@party.length - 1]
end
def lastPokemon
p = self.pokemonParty
return nil if p.length == 0
return p[p.length - 1]
end
def lastAblePokemon
p = self.ablePokemonParty
return nil if p.length == 0
return p[p.length - 1]
end
def party_full?
return @party.length >= MAX_PARTY_SIZE
end
#=============================================================================
# Pokédex
#=============================================================================
def pokedexSeen(region = -1) # Number of Pokémon seen
ret = 0
if region == -1
GameData::Species.each { |s| ret += 1 if s.form == 0 && @seen[s.species] }
else
pbAllRegionalSpecies(region).each { |s| ret += 1 if s && @seen[s] }
end
return ret
end
def pokedexOwned(region = -1) # Number of Pokémon owned
ret = 0
if region == -1
GameData::Species.each { |s| ret += 1 if s.form == 0 && @owned[s.species] }
else
pbAllRegionalSpecies(region).each { |s| ret += 1 if s && @owned[s] }
end
return ret
end
def numFormsSeen(species)
species_data = GameData::Species.try_get(species)
return 0 if !species_data
species = species_data.species
ret = 0
@formseen[species] = [[], []] if !@formseen[species]
array = @formseen[species]
for i in 0...[array[0].length, array[1].length].max
ret += 1 if array[0][i] || array[1][i]
end
return ret
end
def seen?(species)
species_data = GameData::Species.try_get(species)
return (species_data) ? @seen[species_data.species] : false
end
alias hasSeen? seen?
def owned?(species)
species_data = GameData::Species.try_get(species)
return (species_data) ? @owned[species_data.species] : false
end
alias hasOwned? owned?
def setSeen(species)
species_data = GameData::Species.try_get(species)
@seen[species_data.species] = true if species_data
end
def setOwned(species)
species_data = GameData::Species.try_get(species)
@owned[species_data.species] = true if species_data
end
def clearPokedex
@seen = {}
@owned = {}
@formseen = {}
@formlastseen = {}
end
#=============================================================================
# Initializing
#=============================================================================
def initialize(name, trainertype)
@name = name
@language = pbGetLanguage
@trainertype = trainertype
@id = rand(2 ** 16) | rand(2 ** 16) << 16
@metaID = 0
@outfit = 0
@pokegear = false
@pokedex = false
clearPokedex
@shadowcaught = {}
@badges = []
for i in 0...8
@badges[i] = false
end
@money = INITIAL_MONEY
@party = []
end
end

View File

@@ -0,0 +1,311 @@
#===============================================================================
# Basic trainer class (use a child class rather than this one)
#===============================================================================
class Trainer
attr_accessor :trainer_type
attr_accessor :name
attr_accessor :id
attr_accessor :language
attr_accessor :party
def full_name
return _INTL("{1} {2}", trainer_type_name, @name)
end
#=============================================================================
# Portion of the ID which is visible on the Trainer Card
def public_ID(id = nil)
return id ? id & 0xFFFF : @id & 0xFFFF
end
# Other portion of the ID
def secret_ID(id = nil)
return id ? id >> 16 : @id >> 16
end
# Random ID other than this Trainer's ID
def make_foreign_ID
loop do
ret = rand(2 ** 16) | rand(2 ** 16) << 16
return ret if ret != @id
end
return 0
end
#=============================================================================
def trainer_type_name; return GameData::TrainerType.get(@trainer_type).name; end
def base_money; return GameData::TrainerType.get(@trainer_type).base_money; end
def gender; return GameData::TrainerType.get(@trainer_type).gender; end
def male?; return GameData::TrainerType.get(@trainer_type).male?; end
def female?; return GameData::TrainerType.get(@trainer_type).female?; end
alias isMale? male?
alias isFemale? female?
def skill_level; return GameData::TrainerType.get(@trainer_type).skill_level; end
def skill_code; return GameData::TrainerType.get(@trainer_type).skill_code; end
def has_skill_code?(code)
c = skill_code
return c && c != "" && c[/#{code}/]
end
#=============================================================================
def pokemon_party
return @party.find_all { |p| p && !p.egg? }
end
def able_party
return @party.find_all { |p| p && !p.egg? && !p.fainted? }
end
def party_count
return @party.length
end
def pokemon_count
ret = 0
@party.each { |p| ret += 1 if p && !p.egg? }
return ret
end
def able_pokemon_count
ret = 0
@party.each { |p| ret += 1 if p && !p.egg? && !p.fainted? }
return ret
end
def party_full?
return party_count >= MAX_PARTY_SIZE
end
# Returns true if there are no usable Pokémon in the player's party.
def all_fainted?
return able_pokemon_count == 0
end
def first_party
return @party[0]
end
def first_pokemon
return pokemon_party[0]
end
def first_able_pokemon
return able_party[0]
end
def last_party
return (@party.length > 0) ? @party[@party.length - 1] : nil
end
def last_pokemon
p = pokemon_party
return (p.length > 0) ? p[p.length - 1] : nil
end
def last_able_pokemon
p = able_party
return (p.length > 0) ? p[p.length - 1] : nil
end
def remove_pokemon_at_index(index)
return false if index < 0 || index >= party_count
have_able = false
@party.each_with_index do |pkmn, i|
have_able = true if i != index && pkmn.able?
break if have_able
end
return false if !have_able
@party.delete_at(index)
return true
end
# Checks whether the trainer would still have an unfainted Pokémon if the
# Pokémon given by _index_ were removed from the party.
def has_other_able_pokemon?(index)
@party.each_with_index { |pkmn, i| return true if i != index && pkmn.able? }
return false
end
# Returns true if there is a Pokémon of the given species in the trainer's
# party. You may also specify a particular form it should be.
def has_species?(species, form = -1)
return pokemon_party.any? { |p| p && p.isSpecies?(species) && (form < 0 || p.form == form) }
end
# Returns whether there is a fatefully met Pokémon of the given species in the
# trainer's party.
def has_fateful_species?(species)
return pokemon_party.any? { |p| p && p.isSpecies?(species) && p.obtain_method == 4 }
end
# Returns whether there is a Pokémon with the given type in the trainer's
# party.
def has_pokemon_of_type?(type)
return false if !GameData::Type.exists?(type)
type = GameData::Type.get(type).id
return pokemon_party.any? { |p| p && p.hasType(type) }
end
# Checks whether any Pokémon in the party knows the given move, and returns
# the first Pokémon it finds with that move, or nil if no Pokémon has that move.
def get_pokemon_with_move(move)
pokemon_party.each { |pkmn| return pkmn if pkmn.hasMove?(move) }
return nil
end
# Fully heal all Pokémon in the party.
def heal_party
@party.each { |pkmn| pkmn.heal }
end
#=============================================================================
def initialize(name, trainer_type)
@trainer_type = trainer_type
@name = name
@id = rand(2 ** 16) | rand(2 ** 16) << 16
@language = pbGetLanguage
@party = []
end
end
#===============================================================================
# Trainer class for NPC trainers
#===============================================================================
class NPCTrainer < Trainer
attr_accessor :items
attr_accessor :lose_text
def initialize(name, trainer_type)
super
@items = []
@lose_text = GameData::TrainerType.get(@trainer_type).lose_text
end
end
#===============================================================================
# Trainer class for the player
#===============================================================================
class PlayerTrainer < Trainer
attr_writer :character_ID
attr_accessor :outfit
attr_accessor :badges
attr_reader :money
attr_accessor :seen
attr_accessor :owned
attr_accessor :seen_forms
attr_accessor :last_seen_forms
attr_accessor :owned_shadow
attr_accessor :pokedex # Whether the Pokédex was obtained
attr_accessor :pokegear # Whether the Pokégear was obtained
attr_accessor :mystery_gift_unlocked # Whether MG can be used from load screen
attr_accessor :mystery_gifts # Variable that stores downloaded MG data
def character_ID
@character_ID = $PokemonGlobal.playerID || 0 if !@character_ID
return @character_ID
end
def money=(value)
@money = value.clamp(0, MAX_MONEY)
end
def badge_count
ret = 0
@badges.each { |b| ret += 1 if b }
return ret
end
#=============================================================================
def seen?(species)
species_data = GameData::Species.try_get(species)
return (species_data) ? @seen[species_data.species] : false
end
alias hasSeen? seen?
def owned?(species)
species_data = GameData::Species.try_get(species)
return (species_data) ? @owned[species_data.species] : false
end
alias hasOwned? owned?
def set_seen(species)
species_data = GameData::Species.try_get(species)
@seen[species_data.species] = true if species_data
end
def set_owned(species)
species_data = GameData::Species.try_get(species)
@owned[species_data.species] = true if species_data
end
def seen_count(region = -1)
ret = 0
if region == -1
GameData::Species.each { |s| ret += 1 if s.form == 0 && @seen[s.species] }
else
pbAllRegionalSpecies(region).each { |s| ret += 1 if s && @seen[s] }
end
return ret
end
def seen_any?(region = -1)
if region == -1
GameData::Species.each { |s| return true if s.form == 0 && @seen[s.species] }
else
pbAllRegionalSpecies(region).each { |s| return true if s && @seen[s] }
end
return false
end
def owned_count(region = -1)
ret = 0
if region == -1
GameData::Species.each { |s| ret += 1 if s.form == 0 && @owned[s.species] }
else
pbAllRegionalSpecies(region).each { |s| ret += 1 if s && @owned[s] }
end
return ret
end
def seen_forms_count(species)
species_data = GameData::Species.try_get(species)
return 0 if !species_data
species = species_data.species
ret = 0
@seen_forms[species] = [[], []] if !@seen_forms[species]
array = @seen_forms[species]
for i in 0...[array[0].length, array[1].length].max
ret += 1 if array[0][i] || array[1][i]
end
return ret
end
def clear_pokedex
@seen = {}
@owned = {}
@seen_forms = {}
@last_seen_forms = {}
@owned_shadow = {}
end
#=============================================================================
def initialize(name, trainer_type)
super
@character_ID = nil
@outfit = 0
@badges = [false] * 8
@money = INITIAL_MONEY
clear_pokedex
@pokegear = false
@pokedex = false
@mystery_gift_unlocked = false
@mystery_gifts = []
end
end

View File

@@ -0,0 +1,125 @@
#===============================================================================
# Deprecated
#===============================================================================
class PlayerTrainer
alias fullname full_name
alias publicID public_ID
alias secretID secret_ID
alias getForeignID make_foreign_ID
alias trainerTypeName trainer_type_name
alias moneyEarned base_money
alias skill skill_level
alias skillCode skill_code
alias hasSkillCode has_skill_code?
alias pokemonParty pokemon_party
alias ablePokemonParty able_party
alias partyCount party_count
alias pokemonCount pokemon_count
alias ablePokemonCount able_pokemon_count
alias firstParty first_party
alias firstPokemon first_pokemon
alias firstAblePokemon first_able_pokemon
alias lastParty last_party
alias lastPokemon last_pokemon
alias lastAblePokemon last_able_pokemon
alias formseen seen_forms
alias formlastseen last_seen_forms
alias shadowcaught owned_shadow
alias numbadges badge_count
alias pokedexSeen seen_count
alias pokedexOwned owned_count
alias numFormsSeen seen_forms_count
alias clearPokedex clear_pokedex
alias metaID character_ID
alias mysterygiftaccess mystery_gift_unlocked
alias mysterygift mystery_gifts
alias setSeen set_seen
alias setOwned set_owned
end
class PokeBattle_Trainer
attr_reader :trainertype, :name, :id, :metaID, :outfit, :language
attr_reader :party, :badges, :money
attr_reader :seen, :owned, :formseen, :formlastseen, :shadowcaught
attr_reader :pokedex, :pokegear
attr_reader :mysterygiftaccess, :mysterygift
def self.copy(trainer)
ret = PlayerTrainer.new
ret.trainer_type = trainer.trainertype
ret.name = trainer.name
ret.id = trainer.id
ret.character_ID = trainer.metaID if trainer.metaID
ret.outfit = trainer.outfit if trainer.outfit
ret.language = trainer.language if trainer.language
trainer.party.each { |p| ret.party.push(Pokemon.copy(p)) }
ret.badges = trainer.badges.clone
ret.money = trainer.money
trainer.seen.each_with_index { |value, i| ret.set_seen(i) if value }
trainer.owned.each_with_index { |value, i| ret.set_owned(i) if value }
ret.formseen.each_with_index do |value, i|
ret.seen_forms[GameData::Species.get(i).species] = [value[0].clone, value[1].clone] if value
end
trainer.formlastseen.each_with_index do |value, i|
ret.last_seen_forms[GameData::Species.get(i).species] = value.clone if value
end
if trainer.shadowcaught
trainer.shadowcaught.each_with_index do |value, i|
ret.owned_shadow[GameData::Species.get(i).species] = true if value
end
end
ret.pokedex = trainer.pokedex
ret.pokegear = trainer.pokegear
ret.mystery_gift_unlocked = trainer.mysterygiftaccess if trainer.mysterygiftaccess
ret.mystery_gifts = trainer.mysterygift.clone if trainer.mysterygift
return ret
end
end
# @deprecated Use {PlayerTrainer#remove_pokemon_at_index} instead. This alias is slated to be removed in v20.
def pbRemovePokemonAt(index)
Deprecation.warn_method('pbRemovePokemonAt', 'v20', 'PlayerTrainer#remove_pokemon_at_index')
return $Trainer.remove_pokemon_at_index(index)
end
# @deprecated Use {PlayerTrainer#has_other_able_pokemon?} instead. This alias is slated to be removed in v20.
def pbCheckAble(index)
Deprecation.warn_method('pbCheckAble', 'v20', 'PlayerTrainer#has_other_able_pokemon?')
return $Trainer.has_other_able_pokemon?(index)
end
# @deprecated Use {PlayerTrainer#all_fainted?} instead. This alias is slated to be removed in v20.
def pbAllFainted
Deprecation.warn_method('pbAllFainted', 'v20', 'PlayerTrainer#all_fainted?')
return $Trainer.all_fainted?
end
# @deprecated Use {PlayerTrainer#has_species?} instead. This alias is slated to be removed in v20.
def pbHasSpecies?(species, form = -1)
Deprecation.warn_method('pbHasSpecies?', 'v20', 'PlayerTrainer#has_species?')
return $Trainer.has_species?(species, form)
end
# @deprecated Use {PlayerTrainer#has_fateful_species?} instead. This alias is slated to be removed in v20.
def pbHasFatefulSpecies?(species)
Deprecation.warn_method('pbHasSpecies?', 'v20', 'PlayerTrainer#has_fateful_species?')
return $Trainer.has_fateful_species?(species)
end
# @deprecated Use {PlayerTrainer#has_pokemon_of_type?} instead. This alias is slated to be removed in v20.
def pbHasType?(type)
Deprecation.warn_method('pbHasType?', 'v20', 'PlayerTrainer#has_pokemon_of_type?')
return $Trainer.has_pokemon_of_type?(type)
end
# @deprecated Use {PlayerTrainer#get_pokemon_with_move} instead. This alias is slated to be removed in v20.
def pbCheckMove(move)
Deprecation.warn_method('pbCheckMove', 'v20', 'PlayerTrainer#get_pokemon_with_move')
return $Trainer.get_pokemon_with_move(move)
end
# @deprecated Use {PlayerTrainer#heal_party} instead. This alias is slated to be removed in v20.
def pbHealAll
Deprecation.warn_method('pbHealAll', 'v20', 'PlayerTrainer#heal_party')
$Trainer.heal_party
end