mirror of
https://github.com/infinitefusion/infinitefusion-e18.git
synced 2025-12-08 21:54:58 +00:00
Created and implemented GameData::TrainerType, fixed free text entry text mispositioning
This commit is contained in:
@@ -16,44 +16,58 @@ class PokeBattle_Trainer
|
||||
attr_accessor :pokegear # Whether the Pokégear was obtained
|
||||
attr_writer :language
|
||||
|
||||
def trainerTypeName # Name of this trainer type (localized)
|
||||
return PBTrainers.getName(@trainertype) rescue _INTL("PkMn Trainer")
|
||||
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}",self.trainerTypeName,@name)
|
||||
return _INTL("{1} {2}", trainerTypeName, @name)
|
||||
end
|
||||
|
||||
def publicID(id=nil) # Portion of the ID which is visible on the Trainer Card
|
||||
return id ? id&0xFFFF : @id&0xFFFF
|
||||
#=============================================================================
|
||||
# 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
|
||||
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
|
||||
fid = 0
|
||||
loop do
|
||||
fid=rand(256)
|
||||
fid|=rand(256)<<8
|
||||
fid|=rand(256)<<16
|
||||
fid|=rand(256)<<24
|
||||
break if fid!=@id
|
||||
fid = rand(2 ** 16) | rand(2 ** 16) << 16
|
||||
break if fid != @id
|
||||
end
|
||||
return fid
|
||||
end
|
||||
|
||||
def setForeignID(other)
|
||||
@id=other.getForeignID
|
||||
@id = other.getForeignID
|
||||
end
|
||||
|
||||
def metaID
|
||||
@metaID=$PokemonGlobal.playerID if !@metaID
|
||||
@metaID=0 if !@metaID
|
||||
@metaID = $PokemonGlobal.playerID if !@metaID
|
||||
@metaID = 0 if !@metaID
|
||||
return @metaID
|
||||
end
|
||||
|
||||
#=============================================================================
|
||||
# Other properties
|
||||
#=============================================================================
|
||||
def outfit
|
||||
return @outfit || 0
|
||||
end
|
||||
@@ -63,31 +77,7 @@ class PokeBattle_Trainer
|
||||
end
|
||||
|
||||
def money=(value)
|
||||
@money=[[value,MAX_MONEY].min,0].max
|
||||
end
|
||||
|
||||
def moneyEarned # Money won when trainer is defeated
|
||||
data = pbGetTrainerTypeData(@trainertype)
|
||||
return data[3] if data && data[3]
|
||||
return 30
|
||||
end
|
||||
|
||||
def skill # Skill level (for AI)
|
||||
data = pbGetTrainerTypeData(@trainertype)
|
||||
return data[8] if data && data[8]
|
||||
return 30
|
||||
end
|
||||
|
||||
def skillCode
|
||||
data = pbGetTrainerTypeData(@trainertype)
|
||||
return data[9] if data && data[9]
|
||||
return ""
|
||||
end
|
||||
|
||||
def hasSkillCode(code)
|
||||
c = skillCode
|
||||
return true if c && c!="" && c[/#{code}/]
|
||||
return false
|
||||
@money = [[value, MAX_MONEY].min, 0].max
|
||||
end
|
||||
|
||||
def numbadges # Number of badges
|
||||
@@ -96,18 +86,9 @@ class PokeBattle_Trainer
|
||||
return ret
|
||||
end
|
||||
|
||||
def gender
|
||||
data = pbGetTrainerTypeData(@trainertype)
|
||||
return data[7] if data && data[7]
|
||||
return 2 # Gender unknown
|
||||
end
|
||||
|
||||
def male?; return self.gender==0; end
|
||||
alias isMale? male?
|
||||
|
||||
def female?; return self.gender==1; end
|
||||
alias isFemale? female?
|
||||
|
||||
#=============================================================================
|
||||
# Party
|
||||
#=============================================================================
|
||||
def pokemonParty
|
||||
return @party.find_all { |p| p && !p.egg? }
|
||||
end
|
||||
@@ -133,100 +114,103 @@ class PokeBattle_Trainer
|
||||
end
|
||||
|
||||
def firstParty
|
||||
return nil if @party.length==0
|
||||
return nil if @party.length == 0
|
||||
return @party[0]
|
||||
end
|
||||
|
||||
def firstPokemon
|
||||
p=self.pokemonParty
|
||||
return nil if p.length==0
|
||||
p = self.pokemonParty
|
||||
return nil if p.length == 0
|
||||
return p[0]
|
||||
end
|
||||
|
||||
def firstAblePokemon
|
||||
p=self.ablePokemonParty
|
||||
return nil if p.length==0
|
||||
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]
|
||||
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]
|
||||
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]
|
||||
p = self.ablePokemonParty
|
||||
return nil if p.length == 0
|
||||
return p[p.length - 1]
|
||||
end
|
||||
|
||||
def pokedexSeen(region=-1) # Number of Pokémon seen
|
||||
ret=0
|
||||
if region==-1
|
||||
#=============================================================================
|
||||
# Pokédex
|
||||
#=============================================================================
|
||||
def pokedexSeen(region = -1) # Number of Pokémon seen
|
||||
ret = 0
|
||||
if region == -1
|
||||
for i in 1..PBSpecies.maxValue
|
||||
ret+=1 if @seen[i]
|
||||
ret += 1 if @seen[i]
|
||||
end
|
||||
else
|
||||
regionlist=pbAllRegionalSpecies(region)
|
||||
regionlist = pbAllRegionalSpecies(region)
|
||||
for i in regionlist
|
||||
ret+=1 if i > 0 && @seen[i]
|
||||
ret += 1 if i > 0 && @seen[i]
|
||||
end
|
||||
end
|
||||
return ret
|
||||
end
|
||||
|
||||
def pokedexOwned(region=-1) # Number of Pokémon owned
|
||||
ret=0
|
||||
if region==-1
|
||||
def pokedexOwned(region = -1) # Number of Pokémon owned
|
||||
ret = 0
|
||||
if region == -1
|
||||
for i in 0..PBSpecies.maxValue
|
||||
ret+=1 if @owned[i]
|
||||
ret += 1 if @owned[i]
|
||||
end
|
||||
else
|
||||
regionlist=pbAllRegionalSpecies(region)
|
||||
regionlist = pbAllRegionalSpecies(region)
|
||||
for i in regionlist
|
||||
ret+=1 if @owned[i]
|
||||
ret += 1 if @owned[i]
|
||||
end
|
||||
end
|
||||
return ret
|
||||
end
|
||||
|
||||
def numFormsSeen(species)
|
||||
species=getID(PBSpecies,species)
|
||||
return 0 if species<=0
|
||||
ret=0
|
||||
array=@formseen[species]
|
||||
for i in 0...[array[0].length,array[1].length].max
|
||||
ret+=1 if array[0][i] || array[1][i]
|
||||
species = getID(PBSpecies, species)
|
||||
return 0 if species <= 0
|
||||
ret = 0
|
||||
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=getID(PBSpecies,species)
|
||||
return species>0 ? @seen[species] : false
|
||||
species = getID(PBSpecies, species)
|
||||
return species > 0 ? @seen[species] : false
|
||||
end
|
||||
alias hasSeen? seen?
|
||||
|
||||
def owned?(species)
|
||||
species=getID(PBSpecies,species)
|
||||
return species>0 ? @owned[species] : false
|
||||
species = getID(PBSpecies, species)
|
||||
return species > 0 ? @owned[species] : false
|
||||
end
|
||||
alias hasOwned? owned?
|
||||
|
||||
def setSeen(species)
|
||||
species=getID(PBSpecies,species)
|
||||
@seen[species]=true if species>0
|
||||
species = getID(PBSpecies, species)
|
||||
@seen[species] = true if species > 0
|
||||
end
|
||||
|
||||
def setOwned(species)
|
||||
species=getID(PBSpecies,species)
|
||||
@owned[species]=true if species>0
|
||||
species = getID(PBSpecies, species)
|
||||
@owned[species] = true if species > 0
|
||||
end
|
||||
|
||||
def clearPokedex
|
||||
@@ -238,18 +222,18 @@ class PokeBattle_Trainer
|
||||
@seen[i] = false
|
||||
@owned[i] = false
|
||||
@formlastseen[i] = []
|
||||
@formseen[i] = [[],[]]
|
||||
@formseen[i] = [[], []]
|
||||
end
|
||||
end
|
||||
|
||||
def initialize(name,trainertype)
|
||||
#=============================================================================
|
||||
# Initializing
|
||||
#=============================================================================
|
||||
def initialize(name, trainertype)
|
||||
@name = name
|
||||
@language = pbGetLanguage
|
||||
@trainertype = trainertype
|
||||
@id = rand(256)
|
||||
@id |= rand(256)<<8
|
||||
@id |= rand(256)<<16
|
||||
@id |= rand(256)<<24
|
||||
@id = rand(2 ** 16) | rand(2 ** 16) << 16
|
||||
@metaID = 0
|
||||
@outfit = 0
|
||||
@pokegear = false
|
||||
|
||||
@@ -44,33 +44,28 @@ end
|
||||
#===============================================================================
|
||||
#
|
||||
#===============================================================================
|
||||
def pbLoadTrainer(trainerid,trainername,partyid=0)
|
||||
if trainerid.is_a?(String) || trainerid.is_a?(Symbol)
|
||||
if !hasConst?(PBTrainers,trainerid)
|
||||
raise _INTL("Trainer type does not exist ({1}, {2}, ID {3})",trainerid,trainername,partyid)
|
||||
end
|
||||
trainerid = getID(PBTrainers,trainerid)
|
||||
def pbLoadTrainer(tr_type, tr_name, tr_id = 0)
|
||||
if !GameData::TrainerType.exists?(tr_type)
|
||||
raise _INTL("Trainer type {1} does not exist.", tr_type)
|
||||
end
|
||||
tr_type = GameData::TrainerType.get(tr_type).id
|
||||
success = false
|
||||
items = []
|
||||
party = []
|
||||
opponent = nil
|
||||
trainers = pbLoadTrainersData
|
||||
for trainer in trainers
|
||||
thistrainerid = trainer[0]
|
||||
name = trainer[1]
|
||||
thispartyid = trainer[4]
|
||||
next if thistrainerid!=trainerid || name!=trainername || thispartyid!=partyid
|
||||
next if trainer[0] != tr_type || trainer[1] != tr_name || trainer[4] != tr_id
|
||||
# Found the trainer we want, load it up
|
||||
items = trainer[2].clone
|
||||
name = pbGetMessageFromHash(MessageTypes::TrainerNames,name)
|
||||
tr_name = pbGetMessageFromHash(MessageTypes::TrainerNames, tr_name)
|
||||
for i in RIVAL_NAMES
|
||||
next if !isConst?(trainerid,PBTrainers,i[0]) || !$game_variables[i[1]].is_a?(String)
|
||||
name = $game_variables[i[1]]
|
||||
next if i[0] != tr_type || !$game_variables[i[1]].is_a?(String)
|
||||
tr_name = $game_variables[i[1]]
|
||||
break
|
||||
end
|
||||
loseText = pbGetMessageFromHash(MessageTypes::TrainerLoseText,trainer[5])
|
||||
opponent = PokeBattle_Trainer.new(name,thistrainerid)
|
||||
opponent = PokeBattle_Trainer.new(tr_name, tr_type)
|
||||
opponent.setForeignID($Trainer)
|
||||
# Load up each Pokémon in the trainer's party
|
||||
for poke in trainer[3]
|
||||
@@ -93,7 +88,11 @@ def pbLoadTrainer(trainerid,trainername,partyid=0)
|
||||
g = (poke[TrainerData::GENDER]) ? poke[TrainerData::GENDER] : (opponent.female?) ? 1 : 0
|
||||
pokemon.setGender(g)
|
||||
(poke[TrainerData::SHINY]) ? pokemon.makeShiny : pokemon.makeNotShiny
|
||||
n = (poke[TrainerData::NATURE]) ? poke[TrainerData::NATURE] : (pokemon.species+opponent.trainertype)%(PBNatures.maxValue+1)
|
||||
if poke[TrainerData::NATURE]
|
||||
n = poke[TrainerData::NATURE]
|
||||
else
|
||||
n = (pokemon.species + GameData::TrainerType.get(opponent.trainertype).id_number) % (PBNatures.maxValue + 1)
|
||||
end
|
||||
pokemon.setNature(n)
|
||||
for i in 0...6
|
||||
if poke[TrainerData::IV] && poke[TrainerData::IV].length>0
|
||||
@@ -125,18 +124,16 @@ def pbLoadTrainer(trainerid,trainername,partyid=0)
|
||||
end
|
||||
|
||||
def pbConvertTrainerData
|
||||
data = pbLoadTrainerTypesData
|
||||
trainertypes = []
|
||||
for i in 0...data.length
|
||||
record = data[i]
|
||||
trainertypes[record[0]] = record[2] if record
|
||||
tr_type_names = []
|
||||
GameData::TrainerType.each do |t|
|
||||
tr_type_names[t.id_number] = t.real_name
|
||||
end
|
||||
MessageTypes.setMessages(MessageTypes::TrainerTypes,trainertypes)
|
||||
MessageTypes.setMessages(MessageTypes::TrainerTypes, tr_type_names)
|
||||
pbSaveTrainerTypes
|
||||
pbSaveTrainerBattles
|
||||
end
|
||||
|
||||
def pbNewTrainer(trainerid,trainername,trainerparty,savechanges=true)
|
||||
def pbNewTrainer(tr_type, tr_name, tr_id, savechanges = true)
|
||||
pokemon = []
|
||||
for i in 0...6
|
||||
if i==0
|
||||
@@ -160,7 +157,7 @@ def pbNewTrainer(trainerid,trainername,trainerparty,savechanges=true)
|
||||
end
|
||||
end
|
||||
end
|
||||
trainer = [trainerid,trainername,[],pokemon,trainerparty]
|
||||
trainer = [tr_type,tr_name,[],pokemon,tr_id]
|
||||
if savechanges
|
||||
data = pbLoadTrainersData
|
||||
data.push(trainer)
|
||||
@@ -172,87 +169,67 @@ def pbNewTrainer(trainerid,trainername,trainerparty,savechanges=true)
|
||||
return trainer
|
||||
end
|
||||
|
||||
def pbTrainerTypeCheck(symbol)
|
||||
def pbTrainerTypeCheck(trainer_type)
|
||||
return true if !$DEBUG
|
||||
ret = false
|
||||
if hasConst?(PBTrainers,symbol)
|
||||
trtype = PBTrainers.const_get(symbol)
|
||||
data = pbGetTrainerTypeData(trtype)
|
||||
ret = true if data
|
||||
return true if GameData::TrainerType.exists?(trainer_type)
|
||||
if pbConfirmMessage(_INTL("Add new trainer type {1}?", trainer_type.to_s))
|
||||
pbTrainerTypeEditorNew(trainer_type.to_s)
|
||||
end
|
||||
if !ret
|
||||
if pbConfirmMessage(_INTL("Add new trainer type {1}?",symbol))
|
||||
pbTrainerTypeEditorNew(symbol.to_s)
|
||||
end
|
||||
pbMapInterpreter.command_end if pbMapInterpreter
|
||||
end
|
||||
return ret
|
||||
pbMapInterpreter.command_end if pbMapInterpreter
|
||||
return false
|
||||
end
|
||||
|
||||
def pbGetFreeTrainerParty(trainerid,trainername)
|
||||
if trainerid.is_a?(String) || trainerid.is_a?(Symbol)
|
||||
if !hasConst?(PBTrainers,trainerid)
|
||||
raise _INTL("Trainer type does not exist ({1}, {2}, ID {3})",trainerid,trainername,partyid)
|
||||
end
|
||||
trainerid = getID(PBTrainers,trainerid)
|
||||
def pbGetFreeTrainerParty(tr_type, tr_name)
|
||||
if !GameData::TrainerType.exists?(tr_type)
|
||||
raise _INTL("Trainer type {1} does not exist.", tr_type)
|
||||
end
|
||||
tr_type = GameData::TrainerType.get(tr_type).id
|
||||
trainers = pbLoadTrainersData
|
||||
usedparties = []
|
||||
used_ids = []
|
||||
for trainer in trainers
|
||||
thistrainerid = trainer[0]
|
||||
name = trainer[1]
|
||||
next if thistrainerid!=trainerid || name!=trainername
|
||||
usedparties.push(trainer[4])
|
||||
next if trainer[0] != tr_type || trainer[1] != tr_name
|
||||
used_ids.push(trainer[4])
|
||||
end
|
||||
ret = -1
|
||||
for i in 0...256
|
||||
next if usedparties.include?(i)
|
||||
ret = i
|
||||
break
|
||||
return i if !used_ids.include?(i)
|
||||
end
|
||||
return ret
|
||||
return -1
|
||||
end
|
||||
|
||||
def pbTrainerCheck(trainerid,trainername,maxbattles,startBattleId=0)
|
||||
# Called from trainer events to ensure the trainer exists
|
||||
def pbTrainerCheck(tr_type, tr_name, max_battles, tr_id = 0)
|
||||
return true if !$DEBUG
|
||||
if trainerid.is_a?(String) || trainerid.is_a?(Symbol)
|
||||
pbTrainerTypeCheck(trainerid)
|
||||
return false if !hasConst?(PBTrainers,trainerid)
|
||||
trainerid = PBTrainers.const_get(trainerid)
|
||||
end
|
||||
for i in 0...maxbattles
|
||||
trainer = pbLoadTrainer(trainerid,trainername,i+startBattleId)
|
||||
next if trainer
|
||||
traineridstring = "#{trainerid}"
|
||||
traineridstring = getConstantName(PBTrainers,trainerid) rescue "-"
|
||||
if pbConfirmMessage(_INTL("Add new battle {1} (of {2}) for ({3}, {4})?",
|
||||
i+1,maxbattles,traineridstring,trainername))
|
||||
pbNewTrainer(trainerid,trainername,i)
|
||||
end
|
||||
# Check for existence of trainer type
|
||||
pbTrainerTypeCheck(tr_type)
|
||||
return false if !GameData::TrainerType.exists?(tr_type)
|
||||
tr_type = GameData::TrainerType.get(tr_type).id
|
||||
# Check for existence of trainer with given ID number
|
||||
return true if pbLoadTrainer(tr_type, tr_name, tr_id)
|
||||
# Add new trainer
|
||||
if pbConfirmMessage(_INTL("Add new trainer variant {1} (of {2}) for {3} {4}?",
|
||||
tr_id, max_battles, tr_type.to_s, tr_name))
|
||||
pbNewTrainer(tr_type, tr_name, tr_id)
|
||||
end
|
||||
return true
|
||||
end
|
||||
|
||||
def pbMissingTrainer(trainerid, trainername, trainerparty)
|
||||
if trainerid.is_a?(String) || trainerid.is_a?(Symbol)
|
||||
if !hasConst?(PBTrainers,trainerid)
|
||||
raise _INTL("Trainer type does not exist ({1}, {2}, ID {3})",trainerid,trainername,partyid)
|
||||
end
|
||||
trainerid = getID(PBTrainers,trainerid)
|
||||
def pbMissingTrainer(tr_type, tr_name, tr_id)
|
||||
if !GameData::TrainerType.exists?(tr_type)
|
||||
raise _INTL("Trainer type {1} does not exist.", tr_type)
|
||||
end
|
||||
traineridstring = getConstantName(PBTrainers,trainerid) rescue "#{trainerid}"
|
||||
tr_type = GameData::TrainerType.get(tr_type).id
|
||||
if !$DEBUG
|
||||
raise _INTL("Can't find trainer ({1}, {2}, ID {3})",traineridstring,trainername,trainerparty)
|
||||
raise _INTL("Can't find trainer ({1}, {2}, ID {3})", tr_type.to_s, tr_name, tr_id)
|
||||
end
|
||||
message = ""
|
||||
if trainerparty!=0
|
||||
message = (_INTL("Add new trainer ({1}, {2}, ID {3})?",traineridstring,trainername,trainerparty))
|
||||
if tr_id != 0
|
||||
message = _INTL("Add new trainer ({1}, {2}, ID {3})?", tr_type.to_s, tr_name, tr_id)
|
||||
else
|
||||
message = (_INTL("Add new trainer ({1}, {2})?",traineridstring,trainername))
|
||||
message = _INTL("Add new trainer ({1}, {2})?", tr_type.to_s, tr_name)
|
||||
end
|
||||
cmd = pbMessage(message,[_INTL("Yes"),_INTL("No")],2)
|
||||
if cmd==0
|
||||
pbNewTrainer(trainerid,trainername,trainerparty)
|
||||
cmd = pbMessage(message, [_INTL("Yes"), _INTL("No")], 2)
|
||||
if cmd == 0
|
||||
pbNewTrainer(tr_type, tr_name, tr_id)
|
||||
end
|
||||
return cmd
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user