Remove Scripts folder to convert to submodule

This commit is contained in:
chardub
2025-04-19 15:43:57 -04:00
parent 0807a7ea79
commit 58da1023c1
429 changed files with 0 additions and 165507 deletions

View File

@@ -1,604 +0,0 @@
#===============================================================================
# General purpose utilities
#===============================================================================
def _pbNextComb(comb,length)
i = comb.length-1
begin
valid = true
for j in i...comb.length
if j==i
comb[j] += 1
else
comb[j] = comb[i]+(j-i)
end
if comb[j]>=length
valid = false
break
end
end
return true if valid
i -= 1
end while i>=0
return false
end
# Iterates through the array and yields each combination of _num_ elements in
# the array.
def pbEachCombination(array,num)
return if array.length<num || num<=0
if array.length==num
yield array
return
elsif num==1
for x in array
yield [x]
end
return
end
currentComb = []
arr = []
for i in 0...num
currentComb[i] = i
end
begin
for i in 0...num
arr[i] = array[currentComb[i]]
end
yield arr
end while _pbNextComb(currentComb,array.length)
end
# Returns a language ID
def pbGetLanguage()
case System.user_language[0..1]
when "ja" then return 1 # Japanese
when "en" then return 2 # English
when "fr" then return 3 # French
when "it" then return 4 # Italian
when "de" then return 5 # German
when "es" then return 7 # Spanish
when "ko" then return 8 # Korean
end
return 2 # Use 'English' by default
end
# Converts a Celsius temperature to Fahrenheit.
def toFahrenheit(celsius)
return (celsius*9.0/5.0).round+32
end
# Converts a Fahrenheit temperature to Celsius.
def toCelsius(fahrenheit)
return ((fahrenheit-32)*5.0/9.0).round
end
#===============================================================================
# Constants utilities
#===============================================================================
# Unused
def isConst?(val,mod,constant)
begin
return false if !mod.const_defined?(constant.to_sym)
rescue
return false
end
return (val==mod.const_get(constant.to_sym))
end
# Unused
def hasConst?(mod,constant)
return false if !mod || constant.nil?
return mod.const_defined?(constant.to_sym) rescue false
end
# Unused
def getConst(mod,constant)
return nil if !mod || constant.nil?
return mod.const_get(constant.to_sym) rescue nil
end
# Unused
# def getID(mod,constant)
# return nil if !mod || constant.nil?
# if constant.is_a?(Symbol) || constant.is_a?(String)
# if (mod.const_defined?(constant.to_sym) rescue false)
# return mod.const_get(constant.to_sym) rescue 0
# end
# return 0
# end
# return constant
# end
def getConstantName(mod,value)
mod = Object.const_get(mod) if mod.is_a?(Symbol)
for c in mod.constants
return c.to_s if mod.const_get(c.to_sym)==value
end
raise _INTL("Value {1} not defined by a constant in {2}",value,mod.name)
end
def getConstantNameOrValue(mod,value)
mod = Object.const_get(mod) if mod.is_a?(Symbol)
for c in mod.constants
return c.to_s if mod.const_get(c.to_sym)==value
end
return value.inspect
end
#===============================================================================
# Event utilities
#===============================================================================
def pbTimeEvent(variableNumber,secs=86400)
if variableNumber && variableNumber>=0
if $game_variables
secs = 0 if secs<0
timenow = pbGetTimeNow
$game_variables[variableNumber] = [timenow.to_f,secs]
$game_map.refresh if $game_map
end
end
end
def pbTimeEventDays(variableNumber,days=0)
if variableNumber && variableNumber>=0
if $game_variables
days = 0 if days<0
timenow = pbGetTimeNow
time = timenow.to_f
expiry = (time%86400.0)+(days*86400.0)
$game_variables[variableNumber] = [time,expiry-time]
$game_map.refresh if $game_map
end
end
end
def pbTimeEventValid(variableNumber)
retval = false
if variableNumber && variableNumber>=0 && $game_variables
value = $game_variables[variableNumber]
if value.is_a?(Array)
timenow = pbGetTimeNow
retval = (timenow.to_f - value[0] > value[1]) # value[1] is age in seconds
retval = false if value[1]<=0 # zero age
end
if !retval
$game_variables[variableNumber] = 0
$game_map.refresh if $game_map
end
end
return retval
end
def pbExclaim(event,id=Settings::EXCLAMATION_ANIMATION_ID,tinting=false)
if event.is_a?(Array)
sprite = nil
done = []
for i in event
if !done.include?(i.id)
sprite = $scene.spriteset.addUserAnimation(id,i.x,i.y,tinting,2)
done.push(i.id)
end
end
else
sprite = $scene.spriteset.addUserAnimation(id,event.x,event.y,tinting,2)
end
while !sprite.disposed?
Graphics.update
Input.update
pbUpdateSceneMap
end
end
def pbNoticePlayer(event)
if !pbFacingEachOther(event,$game_player)
pbExclaim(event)
end
pbTurnTowardEvent($game_player,event)
pbMoveTowardPlayer(event)
end
#===============================================================================
# Player-related utilities, random name generator
#===============================================================================
# Unused
def pbGetPlayerGraphic
id = $Trainer.character_ID
return "" if id < 0 || id >= 8
meta = GameData::Metadata.get_player(id)
return "" if !meta
return GameData::TrainerType.player_front_sprite_filename(meta[0])
end
def pbGetTrainerTypeGender(trainer_type)
return GameData::TrainerType.get(trainer_type).gender
end
def pbChangePlayer(id)
return false if id < 0 || id >= 8
meta = GameData::Metadata.get_player(id)
return false if !meta
$Trainer.character_ID = id
$Trainer.trainer_type = meta[0]
$game_player.character_name = meta[1]
end
def pbTrainerName(name = nil, outfit = 0)
pbChangePlayer(0) if $Trainer.character_ID < 0
if name.nil?
name = pbEnterPlayerName(_INTL("Enter your name"), 0, Settings::MAX_PLAYER_NAME_SIZE)
if name.nil? || name.empty?
# player_metadata = GameData::Metadata.get_player($Trainer.character_ID)
# trainer_type = (player_metadata) ? player_metadata[0] : nil
# gender = pbGetTrainerTypeGender(trainer_type)
if $game_variables[52] == 0
name = "Green"
else
name = "Red"
end
end
end
$Trainer.name = name
$Trainer.outfit = outfit
$PokemonTemp.begunNewGame = true
end
def pbSuggestTrainerName(gender)
userName = pbGetUserName()
userName = userName.gsub(/\s+.*$/,"")
if userName.length>0 && userName.length<Settings::MAX_PLAYER_NAME_SIZE
userName[0,1] = userName[0,1].upcase
return userName
end
userName = userName.gsub(/\d+$/,"")
if userName.length>0 && userName.length<Settings::MAX_PLAYER_NAME_SIZE
userName[0,1] = userName[0,1].upcase
return userName
end
userName = System.user_name.capitalize
userName = userName[0, Settings::MAX_PLAYER_NAME_SIZE]
return userName
# Unreachable
# return getRandomNameEx(gender, nil, 1, Settings::MAX_PLAYER_NAME_SIZE)
end
def pbGetUserName
return System.user_name
end
def getRandomNameEx(type,variable,upper,maxLength=100)
return "" if maxLength<=0
name = ""
50.times {
name = ""
formats = []
case type
when 0 then formats = %w( F5 BvE FE FE5 FEvE ) # Names for males
when 1 then formats = %w( vE6 vEvE6 BvE6 B4 v3 vEv3 Bv3 ) # Names for females
when 2 then formats = %w( WE WEU WEvE BvE BvEU BvEvE ) # Neutral gender names
else return ""
end
format = formats[rand(formats.length)]
format.scan(/./) { |c|
case c
when "c" # consonant
set = %w( b c d f g h j k l m n p r s t v w x z )
name += set[rand(set.length)]
when "v" # vowel
set = %w( a a a e e e i i i o o o u u u )
name += set[rand(set.length)]
when "W" # beginning vowel
set = %w( a a a e e e i i i o o o u u u au au ay ay ea ea ee ee oo oo ou ou )
name += set[rand(set.length)]
when "U" # ending vowel
set = %w( a a a a a e e e i i i o o o o o u u ay ay ie ie ee ue oo )
name += set[rand(set.length)]
when "B" # beginning consonant
set1 = %w( b c d f g h j k l l m n n p r r s s t t v w y z )
set2 = %w( bl br ch cl cr dr fr fl gl gr kh kl kr ph pl pr sc sk sl
sm sn sp st sw th tr tw vl zh )
name += (rand(3)>0) ? set1[rand(set1.length)] : set2[rand(set2.length)]
when "E" # ending consonant
set1 = %w( b c d f g h j k k l l m n n p r r s s t t v z )
set2 = %w( bb bs ch cs ds fs ft gs gg ld ls nd ng nk rn kt ks
ms ns ph pt ps sk sh sp ss st rd rn rp rm rt rk ns th zh)
name += (rand(3)>0) ? set1[rand(set1.length)] : set2[rand(set2.length)]
when "f" # consonant and vowel
set = %w( iz us or )
name += set[rand(set.length)]
when "F" # consonant and vowel
set = %w( bo ba be bu re ro si mi zho se nya gru gruu glee gra glo ra do zo ri
di ze go ga pree pro po pa ka ki ku de da ma mo le la li )
name += set[rand(set.length)]
when "2"
set = %w( c f g k l p r s t )
name += set[rand(set.length)]
when "3"
set = %w( nka nda la li ndra sta cha chie )
name += set[rand(set.length)]
when "4"
set = %w( una ona ina ita ila ala ana ia iana )
name += set[rand(set.length)]
when "5"
set = %w( e e o o ius io u u ito io ius us )
name += set[rand(set.length)]
when "6"
set = %w( a a a elle ine ika ina ita ila ala ana )
name += set[rand(set.length)]
end
}
break if name.length<=maxLength
}
name = name[0,maxLength]
case upper
when 0 then name = name.upcase
when 1 then name[0, 1] = name[0, 1].upcase
end
if $game_variables && variable
$game_variables[variable] = name
$game_map.need_refresh = true if $game_map
end
return name
end
def getRandomName(maxLength=100)
return getRandomNameEx(2,nil,nil,maxLength)
end
#===============================================================================
# Regional and National Pokédexes utilities
#===============================================================================
# Returns the ID number of the region containing the player's current location,
# as determined by the current map's metadata.
def pbGetCurrentRegion(default = -1)
return default if !$game_map
map_metadata = GameData::MapMetadata.try_get($game_map.map_id)
map_pos = (map_metadata) ? map_metadata.town_map_position : nil
return (map_pos) ? map_pos[0] : default
end
# Returns the Regional Pokédex number of the given species in the given Regional
# Dex. The parameter "region" is zero-based. For example, if two regions are
# defined, they would each be specified as 0 and 1.
def pbGetRegionalNumber(region, species)
dex_list = pbLoadRegionalDexes[region]
return 0 if !dex_list || dex_list.length == 0
species_data = GameData::Species.try_get(species)
return 0 if !species_data
dex_list.each_with_index do |s, index|
return index + 1 if s == species_data.species
end
return 0
end
# Returns an array of all species in the given Regional Dex in that Dex's order.
def pbAllRegionalSpecies(region_dex)
return nil if region_dex < 0
dex_list = pbLoadRegionalDexes[region_dex]
return nil if !dex_list || dex_list.length == 0
return dex_list.clone
end
# Returns the number of species in the given Regional Dex. Returns 0 if that
# Regional Dex doesn't exist. If region_dex is a negative number, returns the
# number of species in the National Dex (i.e. all species).
def pbGetRegionalDexLength(region_dex)
if region_dex < 0
ret = 0
GameData::Species.each { |s| ret += 1 if s.form == 0 }
return ret
end
dex_list = pbLoadRegionalDexes[region_dex]
return (dex_list) ? dex_list.length : 0
end
#===============================================================================
# Other utilities
#===============================================================================
def pbTextEntry(helptext,minlength,maxlength,variableNumber)
$game_variables[variableNumber] = pbEnterText(helptext,minlength,maxlength)
$game_map.need_refresh = true if $game_map
end
def pbMoveTutorAnnotations(move, movelist = nil)
ret = []
$Trainer.party.each_with_index do |pkmn, i|
if pkmn.egg?
ret[i] = _INTL("NOT ABLE")
elsif pkmn.hasMove?(move)
ret[i] = _INTL("LEARNED")
else
species = pkmn.species
if movelist && movelist.any? { |j| j == species }
# Checked data from movelist given in parameter
ret[i] = _INTL("ABLE")
elsif pkmn.compatible_with_move?(move)
# Checked data from Pokémon's tutor moves in pokemon.txt
ret[i] = _INTL("ABLE")
else
ret[i] = _INTL("NOT ABLE")
end
end
end
return ret
end
def pbMoveTutorChoose(move,movelist=nil,bymachine=false,oneusemachine=false,selectedPokemonVariable=nil)
ret = false
move = GameData::Move.get(move).id
if movelist!=nil && movelist.is_a?(Array)
for i in 0...movelist.length
movelist[i] = GameData::Move.get(movelist[i]).id
end
end
pbFadeOutIn {
movename = GameData::Move.get(move).name
annot = pbMoveTutorAnnotations(move,movelist)
scene = PokemonParty_Scene.new
screen = PokemonPartyScreen.new(scene,$Trainer.party)
screen.pbStartScene(_INTL("Teach which Pokémon?"),false,annot)
loop do
chosen = screen.pbChoosePokemon
break if chosen<0
pokemon = $Trainer.party[chosen]
if selectedPokemonVariable != nil
pbSet(selectedPokemonVariable,pokemon)
end
if pokemon.egg?
pbMessage(_INTL("Eggs can't be taught any moves.")) { screen.pbUpdate }
elsif pokemon.shadowPokemon?
pbMessage(_INTL("Shadow Pokémon can't be taught any moves.")) { screen.pbUpdate }
elsif movelist && !movelist.any? { |j| j==pokemon.species }
pbMessage(_INTL("{1} can't learn {2}.",pokemon.name,movename)) { screen.pbUpdate }
elsif !pokemon.compatible_with_move?(move)
pbMessage(_INTL("{1} can't learn {2}.",pokemon.name,movename)) { screen.pbUpdate }
else
if pbLearnMove(pokemon,move,false,bymachine) { screen.pbUpdate }
pokemon.add_first_move(move) if oneusemachine
ret = true
break
end
end
end
screen.pbEndScene
}
return ret # Returns whether the move was learned by a Pokemon
end
def pbConvertItemToItem(variable, array)
item = GameData::Item.get(pbGet(variable))
pbSet(variable, nil)
for i in 0...(array.length/2)
next if item != array[2 * i]
pbSet(variable, array[2 * i + 1])
return
end
end
def pbConvertItemToPokemon(variable, array)
item = GameData::Item.get(pbGet(variable))
pbSet(variable, nil)
for i in 0...(array.length / 2)
next if item != array[2 * i]
pbSet(variable, GameData::Species.get(array[2 * i + 1]).id)
return
end
end
# Gets the value of a variable.
def pbGet(id)
return 0 if !id || !$game_variables
return $game_variables[id]
end
# Sets the value of a variable.
def pbSet(id,value)
return if !id || id<0
$game_variables[id] = value if $game_variables
$game_map.need_refresh = true if $game_map
end
# Runs a common event and waits until the common event is finished.
# Requires the script "Messages"
def pbCommonEvent(id)
return false if id<0
ce = $data_common_events[id]
return false if !ce
celist = ce.list
interp = Interpreter.new
interp.setup(celist,0)
begin
Graphics.update
Input.update
interp.update
pbUpdateSceneMap
end while interp.running?
return true
end
def pbHideVisibleObjects
visibleObjects = []
ObjectSpace.each_object(Sprite) { |o|
if !o.disposed? && o.visible
visibleObjects.push(o)
o.visible = false
end
}
ObjectSpace.each_object(Viewport) { |o|
if !pbDisposed?(o) && o.visible
visibleObjects.push(o)
o.visible = false
end
}
ObjectSpace.each_object(Plane) { |o|
if !o.disposed? && o.visible
visibleObjects.push(o)
o.visible = false
end
}
ObjectSpace.each_object(Tilemap) { |o|
if !o.disposed? && o.visible
visibleObjects.push(o)
o.visible = false
end
}
ObjectSpace.each_object(Window) { |o|
if !o.disposed? && o.visible
visibleObjects.push(o)
o.visible = false
end
}
return visibleObjects
end
def pbShowObjects(visibleObjects)
for o in visibleObjects
next if pbDisposed?(o)
o.visible = true
end
end
def pbLoadRpgxpScene(scene)
return if !$scene.is_a?(Scene_Map)
oldscene = $scene
$scene = scene
Graphics.freeze
oldscene.dispose
visibleObjects = pbHideVisibleObjects
Graphics.transition(20)
Graphics.freeze
while $scene && !$scene.is_a?(Scene_Map)
$scene.main
end
Graphics.transition(20)
Graphics.freeze
$scene = oldscene
$scene.createSpritesets
pbShowObjects(visibleObjects)
Graphics.transition(20)
end
def pbChooseLanguage
commands=[]
for lang in Settings::LANGUAGES
commands.push(lang[0])
end
return pbShowCommands(nil,commands)
end
def pbScreenCapture
t = pbGetTimeNow
filestart = t.strftime("[%Y-%m-%d] %H_%M_%S.%L")
capturefile = RTP.getSaveFileName(sprintf("%s.png", filestart))
Graphics.screenshot(capturefile)
pbSEPlay("Pkmn exp full") if FileTest.audio_exist?("Audio/SE/Pkmn exp full")
end

View File

@@ -1,279 +0,0 @@
#===============================================================================
# Nicknaming and storing Pokémon
#===============================================================================
def pbBoxesFull?
return ($Trainer.party_full? && $PokemonStorage.full?)
end
def pbNickname(pkmn)
species_name = pkmn.speciesName
if pbConfirmMessage(_INTL("Would you like to give a nickname to {1}?", species_name))
pkmn.name = pbEnterPokemonName(_INTL("{1}'s nickname?", species_name),
0, Pokemon::MAX_NAME_SIZE, "", pkmn)
end
end
def pbStorePokemon(pkmn)
if pbBoxesFull?
pbMessage(_INTL("There's no more room for Pokémon!\1"))
pbMessage(_INTL("The Pokémon Boxes are full and can't accept any more!"))
return
end
pkmn.record_first_moves
if $Trainer.party_full?
oldcurbox = $PokemonStorage.currentBox
storedbox = $PokemonStorage.pbStoreCaught(pkmn)
curboxname = $PokemonStorage[oldcurbox].name
boxname = $PokemonStorage[storedbox].name
creator = nil
creator = pbGetStorageCreator if $Trainer.seen_storage_creator
if storedbox != oldcurbox
if creator
pbMessage(_INTL("Box \"{1}\" on {2}'s PC was full.\1", curboxname, creator))
else
pbMessage(_INTL("Box \"{1}\" on the PC was full.\1", curboxname))
end
pbMessage(_INTL("{1} was transferred to box \"{2}.\"", pkmn.name, boxname))
else
if creator
pbMessage(_INTL("{1} was transferred to {2}'s PC.\1", pkmn.name, creator))
else
pbMessage(_INTL("{1} was transferred to the PC.\1", pkmn.name))
end
pbMessage(_INTL("It was stored in box \"{1}.\"", boxname))
end
else
$Trainer.party[$Trainer.party.length] = pkmn
end
end
def pbNicknameAndStore(pkmn)
if pbBoxesFull?
pbMessage(_INTL("There's no more room for Pokémon!\1"))
pbMessage(_INTL("The Pokémon Boxes are full and can't accept any more!"))
return
end
$Trainer.pokedex.set_seen(pkmn.species)
$Trainer.pokedex.set_owned(pkmn.species)
pbNickname(pkmn)
promptCaughtPokemonAction(pkmn)
#pbStorePokemon(pkmn)
end
#===============================================================================
# Giving Pokémon to the player (will send to storage if party is full)
#===============================================================================
def pbAddPokemon(pkmn, level = 1, see_form = true, dontRandomize=false, variableToSave=nil)
return false if !pkmn
if pbBoxesFull?
pbMessage(_INTL("There's no more room for Pokémon!\1"))
pbMessage(_INTL("The Pokémon Boxes are full and can't accept any more!"))
return false
end
pkmn = Pokemon.new(pkmn, level) if !pkmn.is_a?(Pokemon)
tryRandomizeGiftPokemon(pkmn,dontRandomize)
species_name = pkmn.speciesName
pbMessage(_INTL("{1} obtained {2}!\\me[Pkmn get]\\wtnp[20]\1", $Trainer.name, species_name))
pbNicknameAndStore(pkmn)
$Trainer.pokedex.register(pkmn) if see_form
pbSet(variableToSave,pkmn) if variableToSave
return true
end
def pbAddPokemonSilent(pkmn, level = 1, see_form = true)
return false if !pkmn || pbBoxesFull?
pkmn = Pokemon.new(pkmn, level) if !pkmn.is_a?(Pokemon)
$Trainer.pokedex.register(pkmn) if see_form
$Trainer.pokedex.set_owned(pkmn.species)
pkmn.record_first_moves
if $Trainer.party_full?
$PokemonStorage.pbStoreCaught(pkmn)
else
$Trainer.party[$Trainer.party.length] = pkmn
end
return true
end
#===============================================================================
# Giving Pokémon/eggs to the player (can only add to party)
#===============================================================================
def pbAddToParty(pkmn, level = 1, see_form = true, dontRandomize=false)
return false if !pkmn || $Trainer.party_full?
pkmn = Pokemon.new(pkmn, level) if !pkmn.is_a?(Pokemon)
tryRandomizeGiftPokemon(pkmn,dontRandomize)
species_name = pkmn.speciesName
pbMessage(_INTL("{1} obtained {2}!\\me[Pkmn get]\\wtnp[80]\1", $Trainer.name, species_name))
pbNicknameAndStore(pkmn)
$Trainer.pokedex.register(pkmn) if see_form
return true
end
def pbAddToPartySilent(pkmn, level = nil, see_form = true)
return false if !pkmn || $Trainer.party_full?
pkmn = Pokemon.new(pkmn, level) if !pkmn.is_a?(Pokemon)
$Trainer.pokedex.register(pkmn) if see_form
$Trainer.pokedex.set_owned(pkmn.species)
pkmn.record_first_moves
$Trainer.party[$Trainer.party.length] = pkmn
return true
end
def pbAddForeignPokemon(pkmn, level = 1, owner_name = nil, nickname = nil, owner_gender = 0, see_form = true)
return false if !pkmn
pkmn = Pokemon.new(pkmn, level) if !pkmn.is_a?(Pokemon)
# Set original trainer to a foreign one
pkmn.owner = Pokemon::Owner.new_foreign(owner_name || "", owner_gender)
# Set nickname
pkmn.name = nickname[0, Pokemon::MAX_NAME_SIZE] if !nil_or_empty?(nickname)
# Recalculate stats
pkmn.calc_stats
if owner_name
pbMessage(_INTL("\\me[Pkmn get]{1} received a Pokémon from {2}.\1", $Trainer.name, owner_name))
else
pbMessage(_INTL("\\me[Pkmn get]{1} received a Pokémon.\1", $Trainer.name))
end
pbStorePokemon(pkmn)
$Trainer.pokedex.register(pkmn) if see_form
$Trainer.pokedex.set_owned(pkmn.species)
return true
end
def pbGenerateEgg(pkmn, text = "")
return false if !pkmn #|| $Trainer.party_full?
pkmn = Pokemon.new(pkmn, Settings::EGG_LEVEL) if !pkmn.is_a?(Pokemon)
# Set egg's details
pkmn.name = _INTL("Egg")
pkmn.steps_to_hatch = pkmn.species_data.hatch_steps
pkmn.obtain_text = text
pkmn.calc_stats
# Add egg to party
if $Trainer.party.length<6
$Trainer.party[$Trainer.party.length] = pkmn
else
$PokemonStorage.pbStoreCaught(pkmn)
Kernel.pbMessage(_INTL("The egg was transfered to the PC."))
end
return true
end
alias pbAddEgg pbGenerateEgg
alias pbGenEgg pbGenerateEgg
#===============================================================================
# Analyse Pokémon in the party
#===============================================================================
# Returns the first unfainted, non-egg Pokémon in the player's party.
def pbFirstAblePokemon(variable_ID)
$Trainer.party.each_with_index do |pkmn, i|
next if !pkmn.able?
pbSet(variable_ID, i)
return pkmn
end
pbSet(variable_ID, -1)
return nil
end
#===============================================================================
# Return a level value based on Pokémon in a party
#===============================================================================
def pbBalancedLevel(party)
return 1 if party.length == 0
# Calculate the mean of all levels
sum = 0
party.each { |p| sum += p.level }
return 1 if sum == 0
mLevel = GameData::GrowthRate.max_level
average = sum.to_f / party.length.to_f
# Calculate the standard deviation
varianceTimesN = 0
party.each do |pkmn|
deviation = pkmn.level - average
varianceTimesN += deviation * deviation
end
# NOTE: This is the "population" standard deviation calculation, since no
# sample is being taken.
stdev = Math.sqrt(varianceTimesN / party.length)
mean = 0
weights = []
# Skew weights according to standard deviation
party.each do |pkmn|
weight = pkmn.level.to_f / sum.to_f
if weight < 0.5
weight -= (stdev / mLevel.to_f)
weight = 0.001 if weight <= 0.001
else
weight += (stdev / mLevel.to_f)
weight = 0.999 if weight >= 0.999
end
weights.push(weight)
end
weightSum = 0
weights.each { |w| weightSum += w }
# Calculate the weighted mean, assigning each weight to each level's
# contribution to the sum
party.each_with_index { |pkmn, i| mean += pkmn.level * weights[i] }
mean /= weightSum
mean = mean.round
mean = 1 if mean < 1
# Add 2 to the mean to challenge the player
mean += 2
# Adjust level to maximum
mean = mLevel if mean > mLevel
return mean
end
#===============================================================================
# Calculates a Pokémon's size (in millimeters)
#===============================================================================
def pbSize(pkmn)
baseheight = pkmn.height
hpiv = pkmn.iv[:HP] & 15
ativ = pkmn.iv[:ATTACK] & 15
dfiv = pkmn.iv[:DEFENSE] & 15
saiv = pkmn.iv[:SPECIAL_ATTACK] & 15
sdiv = pkmn.iv[:SPECIAL_DEFENSE] & 15
spiv = pkmn.iv[:SPEED] & 15
m = pkmn.personalID & 0xFF
n = (pkmn.personalID >> 8) & 0xFF
s = (((ativ ^ dfiv) * hpiv) ^ m) * 256 + (((saiv ^ sdiv) * spiv) ^ n)
xyz = []
if s < 10; xyz = [ 290, 1, 0]
elsif s < 110; xyz = [ 300, 1, 10]
elsif s < 310; xyz = [ 400, 2, 110]
elsif s < 710; xyz = [ 500, 4, 310]
elsif s < 2710; xyz = [ 600, 20, 710]
elsif s < 7710; xyz = [ 700, 50, 2710]
elsif s < 17710; xyz = [ 800, 100, 7710]
elsif s < 32710; xyz = [ 900, 150, 17710]
elsif s < 47710; xyz = [1000, 150, 32710]
elsif s < 57710; xyz = [1100, 100, 47710]
elsif s < 62710; xyz = [1200, 50, 57710]
elsif s < 64710; xyz = [1300, 20, 62710]
elsif s < 65210; xyz = [1400, 5, 64710]
elsif s < 65410; xyz = [1500, 2, 65210]
else; xyz = [1700, 1, 65510]
end
return (((s - xyz[2]) / xyz[1] + xyz[0]).floor * baseheight / 10).floor
end
#===============================================================================
# Returns true if the given species can be legitimately obtained as an egg
#===============================================================================
def pbHasEgg?(species)
species_data = GameData::Species.try_get(species)
return false if !species_data
species = species_data.species
# species may be unbreedable, so check its evolution's compatibilities
evoSpecies = species_data.get_evolutions(true)
compatSpecies = (evoSpecies && evoSpecies[0]) ? evoSpecies[0][0] : species
species_data = GameData::Species.try_get(compatSpecies)
compat = species_data.egg_groups
return false if compat.include?(:Undiscovered) || compat.include?(:Ditto)
baby = GameData::Species.get(species).get_baby_species
return true if species == baby # Is a basic species
baby = GameData::Species.get(species).get_baby_species(true)
return true if species == baby # Is an egg species without incense
return false
end

View File

@@ -1,146 +0,0 @@
#===============================================================================
# Load various wild battle music
#===============================================================================
def pbGetWildBattleBGM(_wildParty) # wildParty is an array of Pokémon objects
if $PokemonGlobal.nextBattleBGM
return $PokemonGlobal.nextBattleBGM.clone
end
ret = nil
if !ret
# Check map metadata
map_metadata = GameData::MapMetadata.try_get($game_map.map_id)
music = (map_metadata) ? map_metadata.wild_battle_BGM : nil
ret = pbStringToAudioFile(music) if music && music != ""
end
if !ret
# Check global metadata
music = GameData::Metadata.get.wild_battle_BGM
ret = pbStringToAudioFile(music) if music && music!=""
end
ret = pbStringToAudioFile("Battle wild") if !ret
return ret
end
def pbGetWildVictoryME
if $PokemonGlobal.nextBattleME
return $PokemonGlobal.nextBattleME.clone
end
ret = pbStringToAudioFile(Settings::WILD_VICTORY_MUSIC)
ret.name = "../../Audio/ME/"+ret.name
return ret
end
def pbGetWildCaptureME
if $PokemonGlobal.nextBattleCaptureME
return $PokemonGlobal.nextBattleCaptureME.clone
end
ret = nil
if !ret
# Check map metadata
map_metadata = GameData::MapMetadata.try_get($game_map.map_id)
music = (map_metadata) ? map_metadata.wild_capture_ME : nil
ret = pbStringToAudioFile(music) if music && music != ""
end
if !ret
# Check global metadata
music = GameData::Metadata.get.wild_capture_ME
ret = pbStringToAudioFile(music) if music && music!=""
end
ret = pbStringToAudioFile("Battle capture success") if !ret
ret.name = "../../Audio/ME/"+ret.name
return ret
end
#===============================================================================
# Load/play various trainer battle music
#===============================================================================
def pbPlayTrainerIntroME(trainer_type)
trainer_type_data = GameData::TrainerType.get(trainer_type)
return if nil_or_empty?(trainer_type_data.intro_ME)
bgm = pbStringToAudioFile(trainer_type_data.intro_ME)
pbMEPlay(bgm)
end
def pbGetTrainerBattleBGM(trainer) # can be a Player, NPCTrainer or an array of them
if $PokemonGlobal.nextBattleBGM
return $PokemonGlobal.nextBattleBGM.clone
end
ret = nil
music = nil
trainerarray = (trainer.is_a?(Array)) ? trainer : [trainer]
trainerarray.each do |t|
trainer_type_data = GameData::TrainerType.get(t.trainer_type)
music = trainer_type_data.battle_BGM if trainer_type_data.battle_BGM
end
ret = pbStringToAudioFile(music) if music && music!=""
if !ret
# Check map metadata
map_metadata = GameData::MapMetadata.try_get($game_map.map_id)
music = (map_metadata) ? map_metadata.trainer_battle_BGM : nil
ret = pbStringToAudioFile(music) if music && music != ""
end
if !ret
# Check global metadata
music = GameData::Metadata.get.trainer_battle_BGM
if music && music!=""
ret = pbStringToAudioFile(music)
end
end
ret = pbStringToAudioFile("Battle trainer") if !ret
return ret
end
def pbGetTrainerBattleBGMFromType(trainertype)
if $PokemonGlobal.nextBattleBGM
return $PokemonGlobal.nextBattleBGM.clone
end
trainer_type_data = GameData::TrainerType.get(trainertype)
ret = trainer_type_data.battle_BGM if trainer_type_data.battle_BGM
if !ret
# Check map metadata
map_metadata = GameData::MapMetadata.try_get($game_map.map_id)
music = (map_metadata) ? map_metadata.trainer_battle_BGM : nil
ret = pbStringToAudioFile(music) if music && music != ""
end
if !ret
# Check global metadata
music = GameData::Metadata.get.trainer_battle_BGM
ret = pbStringToAudioFile(music) if music && music!=""
end
ret = pbStringToAudioFile("Battle trainer") if !ret
return ret
end
def pbGetTrainerVictoryME(trainer) # can be a Player, NPCTrainer or an array of them
begin
if $PokemonGlobal.nextBattleME
return $PokemonGlobal.nextBattleME.clone
end
if trainer.is_a?(Array)
npcTrainer=trainer[0]
else
npcTrainer=trainer
end
if is_gym_leader(npcTrainer)
ret = pbStringToAudioFile(Settings::LEADER_VICTORY_MUSIC)
else
ret = pbStringToAudioFile(Settings::TRAINER_VICTORY_MUSIC)
end
ret.name = "../../Audio/ME/"+ret.name
return ret
rescue
ret = pbStringToAudioFile(Settings::TRAINER_VICTORY_MUSIC)
ret.name = "../../Audio/ME/"+ret.name
return ret
end
end
GYM_LEADERS=[:LEADER_Brock,:LEADER_Misty, :LEADER_Surge, :LEADER_Erika, :LEADER_Koga, :LEADER_Sabrina, :LEADER_Blaine,
:LEADER_Giovanni, :ELITEFOUR_Lorelei, :ELITEFOUR_Bruno, :ELITEFOUR_Agatha, :ELITEFOUR_Lance, :CHAMPION,
:LEADER_Whitney, :LEADER_Kurt, :LEADER_Falkner, :LEADER_Clair, :LEADER_Morty, :LEADER_Pryce, :LEADER_Chuck,
:LEADER_Jasmine, :CHAMPION_Sinnoh]
def is_gym_leader(trainer)
return GYM_LEADERS.include?(trainer.trainer_type)
end