Rearranged some script files

This commit is contained in:
Maruno17
2020-09-05 22:34:32 +01:00
parent 5d3189174c
commit 5073f86190
188 changed files with 250 additions and 239 deletions

View File

@@ -0,0 +1,292 @@
def pbSameThread(wnd)
return false if wnd==0
processid = [0].pack('l')
getCurrentThreadId = Win32API.new('kernel32','GetCurrentThreadId', '%w()','l')
getWindowThreadProcessId = Win32API.new('user32','GetWindowThreadProcessId', '%w(l p)','l')
threadid = getCurrentThreadId.call
wndthreadid = getWindowThreadProcessId.call(wnd,processid)
return (wndthreadid==threadid)
end
module Input
DOWN = 2
LEFT = 4
RIGHT = 6
UP = 8
TAB = 9
A = 11
B = 12
C = 13
X = 14
Y = 15
Z = 16
L = 17
R = 18
ENTER = 19
ESC = 20
SHIFT = 21
CTRL = 22
ALT = 23
BACKSPACE = 24
DELETE = 25
HOME = 26
ENDKEY = 27
F5 = F = 28
ONLYF5 = 29
F6 = 30
F7 = 31
F8 = 32
F9 = 33
LeftMouseKey = 1
RightMouseKey = 2
# GetAsyncKeyState or GetKeyState will work here
@GetKeyState = Win32API.new("user32","GetAsyncKeyState","i","i")
@GetForegroundWindow = Win32API.new("user32","GetForegroundWindow","","i")
# All key states to check
CheckKeyStates = [0x01,0x02,0x08,0x09,0x0D,0x10,0x11,0x12,0x1B,0x20,0x21,0x22,
0x23,0x24,0x25,0x26,0x27,0x28,0x2E,0x30,0x31,0x32,0x33,0x34,
0x35,0x36,0x37,0x38,0x39,0x41,0x42,0x43,0x44,0x45,0x46,0x47,
0x48,0x49,0x4A,0x4B,0x4C,0x4D,0x4E,0x4F,0x50,0x51,0x52,0x53,
0x54,0x55,0x56,0x57,0x58,0x59,0x5A,0x6A,0x6B,0x6D,0x6F,0x74,
0x75,0x76,0x77,0x78,0xBA,0xBB,0xBC,0xBD,0xBE,0xBF,0xDB,0xDC,
0xDD,0xDE] # 74 in total
# Returns whether a key is being pressed
def self.getstate(key)
return (@GetKeyState.call(key)&0x8000)>0
end
def self.updateKeyState(i)
gfw = pbSameThread(@GetForegroundWindow.call())
if !@stateUpdated[i]
newstate = self.getstate(i) && gfw
@keystate[i] = 0 if !@keystate[i]
@triggerstate[i] = (newstate && @keystate[i]==0)
@releasestate[i] = (!newstate && @keystate[i]>0)
@keystate[i] = (newstate) ? @keystate[i]+1 : 0
@stateUpdated[i] = true
end
end
def self.update
# $fullInputUpdate is true during keyboard text entry
toCheck = ($fullInputUpdate) ? 0...256 : CheckKeyStates
if @keystate
for i in toCheck
# just noting that the state should be updated
# instead of thunking to Win32 256 times
@stateUpdated[i] = false
# If there is a repeat count, update anyway
# (will normally apply only to a very few keys)
updateKeyState(i) if !@keystate[i] || @keystate[i]>0
end
else
@stateUpdated = []
@keystate = []
@triggerstate = []
@releasestate = []
for i in toCheck
@stateUpdated[i] = true
@keystate[i] = (self.getstate(i)) ? 1 : 0
@triggerstate[i] = false
@releasestate[i] = false
end
end
end
def self.buttonToKey(button)
case button
when Input::DOWN; return [0x28] # Down
when Input::LEFT; return [0x25] # Left
when Input::RIGHT; return [0x27] # Right
when Input::UP; return [0x26] # Up
when Input::TAB; return [0x09] # Tab
when Input::A; return [0x5A,0x57,0x59,0x10] # Z, W, Y, Shift
when Input::B; return [0x58,0x1B] # X, ESC
when Input::C; return [0x43,0x0D,0x20] # C, ENTER, Space
# when Input::X; return [0x41] # A
# when Input::Y; return [0x53] # S
# when Input::Z; return [0x44] # D
when Input::L; return [0x41,0x51,0x21] # A, Q, Page Up
when Input::R; return [0x53,0x22] # S, Page Down
when Input::ENTER; return [0x0D] # ENTER
when Input::ESC; return [0x1B] # ESC
when Input::SHIFT; return [0x10] # Shift
when Input::CTRL; return [0x11] # Ctrl
when Input::ALT; return [0x12] # Alt
when Input::BACKSPACE; return [0x08] # Backspace
when Input::DELETE; return [0x2E] # Delete
when Input::HOME; return [0x24] # Home
when Input::ENDKEY; return [0x23] # End
when Input::F5; return [0x46,0x74,0x09] # F, F5, Tab
when Input::ONLYF5; return [0x74] # F5
when Input::F6; return [0x75] # F6
when Input::F7; return [0x76] # F7
when Input::F8; return [0x77] # F8
when Input::F9; return [0x78] # F9
else; return []
end
end
def self.dir4
button = 0
repeatcount = 0
return 0 if self.press?(Input::DOWN) && self.press?(Input::UP)
return 0 if self.press?(Input::LEFT) && self.press?(Input::RIGHT)
for b in [Input::DOWN,Input::LEFT,Input::RIGHT,Input::UP]
rc = self.count(b)
if rc>0 && (repeatcount==0 || rc<repeatcount)
button = b
repeatcount = rc
end
end
return button
end
def self.dir8
buttons = []
for b in [Input::DOWN,Input::LEFT,Input::RIGHT,Input::UP]
rc = self.count(b)
buttons.push([b,rc]) if rc>0
end
if buttons.length==0
return 0
elsif buttons.length==1
return buttons[0][0]
elsif buttons.length==2
# since buttons sorted by button, no need to sort here
return 0 if (buttons[0][0]==Input::DOWN && buttons[1][0]==Input::UP)
return 0 if (buttons[0][0]==Input::LEFT && buttons[1][0]==Input::RIGHT)
end
buttons.sort! { |a,b| a[1]<=>b[1] }
updown = 0
leftright = 0
for b in buttons
updown = b[0] if updown==0 && (b[0]==Input::UP || b[0]==Input::DOWN)
leftright = b[0] if leftright==0 && (b[0]==Input::LEFT || b[0]==Input::RIGHT)
end
if updown==Input::DOWN
return 1 if leftright==Input::LEFT
return 3 if leftright==Input::RIGHT
return 2
elsif updown==Input::UP
return 7 if leftright==Input::LEFT
return 9 if leftright==Input::RIGHT
return 8
else
return 4 if leftright==Input::LEFT
return 6 if leftright==Input::RIGHT
return 0
end
end
def self.count(button)
for btn in self.buttonToKey(button)
c = self.repeatcount(btn)
return c if c>0
end
return 0
end
def self.release?(button)
rc = 0
for btn in self.buttonToKey(button)
c = self.repeatcount(btn)
return false if c>0
rc += 1 if self.releaseex?(btn)
end
return rc>0
end
def self.trigger?(button)
return self.buttonToKey(button).any? { |item| self.triggerex?(item) }
end
def self.repeat?(button)
return self.buttonToKey(button).any? { |item| self.repeatex?(item) }
end
def self.press?(button)
return self.count(button)>0
end
def self.triggerex?(key)
return false if !@triggerstate
updateKeyState(key)
return @triggerstate[key]
end
def self.repeatex?(key)
return false if !@keystate
updateKeyState(key)
return @keystate[key]==1 || (@keystate[key]>Graphics.frame_rate/2 && (@keystate[key]&1)==0)
end
def self.releaseex?(key)
return false if !@releasestate
updateKeyState(key)
return @releasestate[key]
end
def self.repeatcount(key)
return 0 if !@keystate
updateKeyState(key)
return @keystate[key]
end
def self.pressex?(key)
return self.repeatcount(key)>0
end
end
# Requires Win32API
module Mouse
gsm = Win32API.new('user32','GetSystemMetrics','i','i')
@GetCursorPos = Win32API.new('user32','GetCursorPos','p','i')
@SetCapture = Win32API.new('user32','SetCapture','p','i')
@ReleaseCapture = Win32API.new('user32','ReleaseCapture','','i')
module_function
def getMouseGlobalPos
pos = [0, 0].pack('ll')
return (@GetCursorPos.call(pos)!=0) ? pos.unpack('ll') : [nil,nil]
end
def screen_to_client(x, y)
return nil unless x and y
screenToClient = Win32API.new('user32','ScreenToClient',%w(l p),'i')
pos = [x, y].pack('ll')
return pos.unpack('ll') if screenToClient.call(Win32API.pbFindRgssWindow,pos)!=0
return nil
end
def setCapture
@SetCapture.call(Win32API.pbFindRgssWindow)
end
def releaseCapture
@ReleaseCapture.call
end
# Returns the position of the mouse relative to the game window.
def getMousePos(catch_anywhere=false)
resizeFactor = ($ResizeFactor) ? $ResizeFactor : 1
x, y = screen_to_client(*getMouseGlobalPos)
return nil unless x and y
width, height = Win32API.client_size
if catch_anywhere or (x>=0 and y>=0 and x<width and y<height)
return (x/resizeFactor).to_i, (y/resizeFactor).to_i
end
return nil
end
def del
return if @oldcursor==nil
@SetClassLong.call(Win32API.pbFindRgssWindow,-12,@oldcursor)
@oldcursor = nil
end
end

View File

@@ -0,0 +1,137 @@
# Loads data from a file "safely", similar to load_data. If an encrypted archive
# exists, the real file is deleted to ensure that the file is loaded from the
# encrypted archive.
def pbSafeLoad(file)
if (safeExists?("./Game.rgssad") || safeExists?("./Game.rgss2a")) && safeExists?(file)
File.delete(file) rescue nil
end
return load_data(file)
end
def pbLoadRxData(file) # :nodoc:
if $RPGVX
return load_data(file+".rvdata")
else
return load_data(file+".rxdata")
end
end
def pbChooseLanguage
commands=[]
for lang in LANGUAGES
commands.push(lang[0])
end
return pbShowCommands(nil,commands)
end
if !respond_to?("pbSetResizeFactor")
def pbSetResizeFactor(dummy,dummy2=false); end
def setScreenBorderName(border); end
$ResizeFactor = 1.0
$ResizeFactorMul = 100
$ResizeOffsetX = 0
$ResizeOffsetY = 0
$ResizeFactorSet = false
module Graphics
def self.snap_to_bitmap; return nil; end
end
end
#############
#############
def pbSetUpSystem
begin
trainer = nil
framecount = 0
game_system = nil
pokemonSystem = nil
havedata = false
File.open(RTP.getSaveFileName("Game.rxdata")) { |f|
trainer = Marshal.load(f)
framecount = Marshal.load(f)
game_system = Marshal.load(f)
pokemonSystem = Marshal.load(f)
}
raise "Corrupted file" if !trainer.is_a?(PokeBattle_Trainer)
raise "Corrupted file" if !framecount.is_a?(Numeric)
raise "Corrupted file" if !game_system.is_a?(Game_System)
raise "Corrupted file" if !pokemonSystem.is_a?(PokemonSystem)
havedata = true
rescue
game_system = Game_System.new
pokemonSystem = PokemonSystem.new
end
if !$INEDITOR
$game_system = game_system
$PokemonSystem = pokemonSystem
pbSetResizeFactor([$PokemonSystem.screensize,3].min)
else
pbSetResizeFactor(1.0)
end
# Load constants
begin
consts = pbSafeLoad("Data/Constants.rxdata")
consts = [] if !consts
rescue
consts = []
end
for script in consts
next if !script
eval(Zlib::Inflate.inflate(script[2]),nil,script[1])
end
if LANGUAGES.length>=2
pokemonSystem.language = pbChooseLanguage if !havedata
pbLoadMessages("Data/"+LANGUAGES[pokemonSystem.language][1])
end
end
def pbScreenCapture
t = pbGetTimeNow
filestart = t.strftime("[%Y-%m-%d] %H_%M_%S")
filestart = sprintf("%s.%03d",filestart,(t.to_f-t.to_i)*1000) # milliseconds
capturefile = RTP.getSaveFileName(sprintf("%s.png",filestart))
if capturefile && safeExists?("rubyscreen.dll")
Graphics.snap_to_bitmap(false).saveToPng(capturefile)
pbSEPlay("Pkmn exp full") if FileTest.audio_exist?("Audio/SE/Pkmn exp full")
end
end
def pbDebugF7
if $DEBUG
Console::setup_console
begin
debugBitmaps
rescue
end
pbSEPlay("Pkmn exp full") if FileTest.audio_exist?("Audio/SE/Pkmn exp full")
end
end
module Input
unless defined?(update_KGC_ScreenCapture)
class << Input
alias update_KGC_ScreenCapture update
end
end
def self.update
update_KGC_ScreenCapture
if trigger?(Input::F8)
pbScreenCapture
end
if trigger?(Input::F7)
pbDebugF7
end
end
end
pbSetUpSystem

View File

@@ -0,0 +1,681 @@
#===============================================================================
# Load Pokémon sprites
#===============================================================================
def pbLoadPokemonBitmap(pokemon,back=false)
return pbLoadPokemonBitmapSpecies(pokemon,pokemon.species,back)
end
# NOTE: Returns an AnimatedBitmap, not a Bitmap
def pbLoadPokemonBitmapSpecies(pokemon,species,back=false)
ret = nil
if pokemon.egg?
bitmapFileName = sprintf("Graphics/Battlers/%segg_%d",getConstantName(PBSpecies,species),pokemon.form) rescue nil
if !pbResolveBitmap(bitmapFileName)
bitmapFileName = sprintf("Graphics/Battlers/%03degg_%d",species,pokemon.form)
if !pbResolveBitmap(bitmapFileName)
bitmapFileName = sprintf("Graphics/Battlers/%segg",getConstantName(PBSpecies,species)) rescue nil
if !pbResolveBitmap(bitmapFileName)
bitmapFileName = sprintf("Graphics/Battlers/%03degg",species)
if !pbResolveBitmap(bitmapFileName)
bitmapFileName = sprintf("Graphics/Battlers/egg")
end
end
end
end
bitmapFileName = pbResolveBitmap(bitmapFileName)
else
bitmapFileName = pbCheckPokemonBitmapFiles([species,back,(pokemon.female?),
pokemon.shiny?,(pokemon.form rescue 0),pokemon.shadowPokemon?])
# Alter bitmap if supported
alterBitmap = (MultipleForms.getFunction(species,"alterBitmap") rescue nil)
end
if bitmapFileName && alterBitmap
animatedBitmap = AnimatedBitmap.new(bitmapFileName)
copiedBitmap = animatedBitmap.copy
animatedBitmap.dispose
copiedBitmap.each { |bitmap| alterBitmap.call(pokemon,bitmap) }
ret = copiedBitmap
elsif bitmapFileName
ret = AnimatedBitmap.new(bitmapFileName)
end
return ret
end
# NOTE: Returns an AnimatedBitmap, not a Bitmap
def pbLoadSpeciesBitmap(species,female=false,form=0,shiny=false,shadow=false,back=false,egg=false)
ret = nil
if egg
bitmapFileName = sprintf("Graphics/Battlers/%segg_%d",getConstantName(PBSpecies,species),form) rescue nil
if !pbResolveBitmap(bitmapFileName)
bitmapFileName = sprintf("Graphics/Battlers/%03degg_%d",species,form)
if !pbResolveBitmap(bitmapFileName)
bitmapFileName = sprintf("Graphics/Battlers/%segg",getConstantName(PBSpecies,species)) rescue nil
if !pbResolveBitmap(bitmapFileName)
bitmapFileName = sprintf("Graphics/Battlers/%03degg",species)
if !pbResolveBitmap(bitmapFileName)
bitmapFileName = sprintf("Graphics/Battlers/egg")
end
end
end
end
bitmapFileName = pbResolveBitmap(bitmapFileName)
else
bitmapFileName = pbCheckPokemonBitmapFiles([species,back,female,shiny,form,shadow])
end
if bitmapFileName
ret = AnimatedBitmap.new(bitmapFileName)
end
return ret
end
def pbCheckPokemonBitmapFiles(params)
factors = []
factors.push([5,params[5],false]) if params[5] && params[5]!=false # shadow
factors.push([2,params[2],false]) if params[2] && params[2]!=false # gender
factors.push([3,params[3],false]) if params[3] && params[3]!=false # shiny
factors.push([4,params[4],0]) if params[4] && params[4]!=0 # form
factors.push([0,params[0],0]) # species
trySpecies = 0
tryGender = false
tryShiny = false
tryBack = params[1]
tryForm = 0
tryShadow = false
for i in 0...2**factors.length
factors.each_with_index do |factor,index|
newVal = ((i/(2**index))%2==0) ? factor[1] : factor[2]
case factor[0]
when 0; trySpecies = newVal
when 2; tryGender = newVal
when 3; tryShiny = newVal
when 4; tryForm = newVal
when 5; tryShadow = newVal
end
end
for j in 0...2 # Try using the species' internal name and then its ID number
next if trySpecies==0 && j==0
trySpeciesText = (j==0) ? getConstantName(PBSpecies,trySpecies) : sprintf("%03d",trySpecies)
bitmapFileName = sprintf("Graphics/Battlers/%s%s%s%s%s%s",
trySpeciesText,
(tryGender) ? "f" : "",
(tryShiny) ? "s" : "",
(tryBack) ? "b" : "",
(tryForm!=0) ? "_"+tryForm.to_s : "",
(tryShadow) ? "_shadow" : "") rescue nil
ret = pbResolveBitmap(bitmapFileName)
return ret if ret
end
end
return nil
end
def pbLoadPokemonShadowBitmap(pokemon)
bitmapFileName = pbCheckPokemonShadowBitmapFiles(pokemon.species,pokemon.form)
return AnimatedBitmap.new(pbResolveBitmap(bitmapFileName)) if bitmapFileName
return nil
end
def pbLoadPokemonShadowBitmapSpecies(pokemon,species)
bitmapFileName = pbCheckPokemonShadowBitmapFiles(species,pokemon.form)
return AnimatedBitmap.new(pbResolveBitmap(bitmapFileName)) if bitmapFileName
return nil
end
def pbCheckPokemonShadowBitmapFiles(species,form,fullmetrics=nil)
if form>0
bitmapFileName = sprintf("Graphics/Battlers/%s_%d_battleshadow",getConstantName(PBSpecies,species),form) rescue nil
ret = pbResolveBitmap(bitmapFileName)
return bitmapFileName if ret
bitmapFileName = sprintf("Graphics/Battlers/%03d_%d_battleshadow",species,form)
ret = pbResolveBitmap(bitmapFileName)
return bitmapFileName if ret
end
bitmapFileName = sprintf("Graphics/Battlers/%s_battleshadow",getConstantName(PBSpecies,species)) rescue nil
ret = pbResolveBitmap(bitmapFileName)
return bitmapFileName if ret
bitmapFileName = sprintf("Graphics/Battlers/%03d_battleshadow",species)
ret = pbResolveBitmap(bitmapFileName)
return bitmapFileName if ret
# Load metrics and use that graphic
fullmetrics = pbLoadSpeciesMetrics if !fullmetrics
size = (fullmetrics[MetricBattlerShadowSize][pbGetFSpeciesFromForm(species,form)] || 2)
bitmapFileName = sprintf("Graphics/Pictures/Battle/battler_shadow_%d",size)
return bitmapFileName if pbResolveBitmap(bitmapFileName)
return nil
end
#===============================================================================
# Load Pokémon icons
#===============================================================================
def pbLoadPokemonIcon(pokemon)
return AnimatedBitmap.new(pbPokemonIconFile(pokemon)).deanimate
end
def pbPokemonIconFile(pokemon)
return pbCheckPokemonIconFiles([pokemon.species,pokemon.female?,
pokemon.shiny?,(pokemon.form rescue 0),pokemon.shadowPokemon?],
pokemon.egg?)
end
def pbCheckPokemonIconFiles(params,egg=false)
species = params[0]
if egg
bitmapFileName = sprintf("Graphics/Icons/icon%segg_%d",getConstantName(PBSpecies,species),params[3]) rescue nil
if !pbResolveBitmap(bitmapFileName)
bitmapFileName = sprintf("Graphics/Icons/icon%03degg_%d",species,params[3])
if !pbResolveBitmap(bitmapFileName)
bitmapFileName = sprintf("Graphics/Icons/icon%segg",getConstantName(PBSpecies,species)) rescue nil
if !pbResolveBitmap(bitmapFileName)
bitmapFileName = sprintf("Graphics/Icons/icon%03degg",species)
if !pbResolveBitmap(bitmapFileName)
bitmapFileName = sprintf("Graphics/Icons/iconEgg")
end
end
end
end
return pbResolveBitmap(bitmapFileName)
end
factors = []
factors.push([4,params[4],false]) if params[4] && params[4]!=false # shadow
factors.push([1,params[1],false]) if params[1] && params[1]!=false # gender
factors.push([2,params[2],false]) if params[2] && params[2]!=false # shiny
factors.push([3,params[3],0]) if params[3] && params[3]!=0 # form
factors.push([0,params[0],0]) # species
trySpecies = 0
tryGender = false
tryShiny = false
tryForm = 0
tryShadow = false
for i in 0...2**factors.length
factors.each_with_index do |factor,index|
newVal = ((i/(2**index))%2==0) ? factor[1] : factor[2]
case factor[0]
when 0; trySpecies = newVal
when 1; tryGender = newVal
when 2; tryShiny = newVal
when 3; tryForm = newVal
when 4; tryShadow = newVal
end
end
for j in 0...2 # Try using the species' internal name and then its ID number
next if trySpecies==0 && j==0
trySpeciesText = (j==0) ? getConstantName(PBSpecies,trySpecies) : sprintf("%03d",trySpecies)
bitmapFileName = sprintf("Graphics/Icons/icon%s%s%s%s%s",
trySpeciesText,
(tryGender) ? "f" : "",
(tryShiny) ? "s" : "",
(tryForm!=0) ? "_"+tryForm.to_s : "",
(tryShadow) ? "_shadow" : "") rescue nil
ret = pbResolveBitmap(bitmapFileName)
return ret if ret
end
end
return nil
end
#===============================================================================
# Load Pokémon footprint graphics
#===============================================================================
def pbPokemonFootprintFile(pokemon,form=0) # Used by the Pokédex
return nil if !pokemon
if pokemon.is_a?(Numeric)
bitmapFileName = sprintf("Graphics/Icons/Footprints/footprint%s_%d",
getConstantName(PBSpecies,pokemon),form) rescue nil
if !pbResolveBitmap(bitmapFileName)
bitmapFileName = sprintf("Graphics/Icons/Footprints/footprint%03d_%d",
pokemon,form) rescue nil
if !pbResolveBitmap(bitmapFileName)
bitmapFileName = sprintf("Graphics/Icons/Footprints/footprint%s",
getConstantName(PBSpecies,pokemon)) rescue nil
if !pbResolveBitmap(bitmapFileName)
bitmapFileName = sprintf("Graphics/Icons/Footprints/footprint%03d",pokemon)
end
end
end
else
bitmapFileName = sprintf("Graphics/Icons/Footprints/footprint%s_%d",
getConstantName(PBSpecies,pokemon.species),(pokemon.form rescue 0)) rescue nil
if !pbResolveBitmap(bitmapFileName)
bitmapFileName = sprintf("Graphics/Icons/Footprints/footprint%03d_%d",
pokemon.species,(pokemon.form rescue 0)) rescue nil
if !pbResolveBitmap(bitmapFileName)
bitmapFileName = sprintf("Graphics/Icons/Footprints/footprint%s",
getConstantName(PBSpecies,pokemon.species)) rescue nil
if !pbResolveBitmap(bitmapFileName)
bitmapFileName = sprintf("Graphics/Icons/Footprints/footprint%03d",
pokemon.species)
end
end
end
end
return pbResolveBitmap(bitmapFileName)
end
#===============================================================================
# Load item icons
#===============================================================================
def pbItemIconFile(item)
return nil if !item
bitmapFileName = nil
if item==0
bitmapFileName = sprintf("Graphics/Icons/itemBack")
else
bitmapFileName = sprintf("Graphics/Icons/item%s",getConstantName(PBItems,item)) rescue nil
if !pbResolveBitmap(bitmapFileName)
bitmapFileName = sprintf("Graphics/Icons/item%03d",item)
if !pbResolveBitmap(bitmapFileName) && pbIsMachine?(item)
move = pbGetMachine(item)
type = pbGetMoveData(move,MOVE_TYPE)
bitmapFileName = sprintf("Graphics/Icons/itemMachine%s",getConstantName(PBTypes,type)) rescue nil
if !pbResolveBitmap(bitmapFileName)
bitmapFileName = sprintf("Graphics/Icons/itemMachine%03d",type)
end
end
bitmapFileName = "Graphics/Icons/item000" if !pbResolveBitmap(bitmapFileName)
end
end
return bitmapFileName
end
def pbHeldItemIconFile(item) # Used in the party screen
return nil if !item || item==0
namebase = (pbIsMail?(item)) ? "mail" : "item"
bitmapFileName = sprintf("Graphics/Pictures/Party/icon_%s_%s",namebase,getConstantName(PBItems,item)) rescue nil
if !pbResolveBitmap(bitmapFileName)
bitmapFileName = sprintf("Graphics/Pictures/Party/icon_%s_%03d",namebase,item)
if !pbResolveBitmap(bitmapFileName)
bitmapFileName = sprintf("Graphics/Pictures/Party/icon_%s",namebase)
end
end
return bitmapFileName
end
#===============================================================================
# Load mail background graphics
#===============================================================================
def pbMailBackFile(item)
return nil if !item
bitmapFileName = sprintf("Graphics/Pictures/Mail/mail_%s",getConstantName(PBItems,item)) rescue nil
if !pbResolveBitmap(bitmapFileName)
bitmapFileName = sprintf("Graphics/Pictures/Mail/mail_%03d",item)
end
return bitmapFileName
end
#===============================================================================
# Load NPC charsets
#===============================================================================
def pbTrainerCharFile(type) # Used by the phone
return nil if !type
bitmapFileName = sprintf("Graphics/Characters/trchar%s",getConstantName(PBTrainers,type)) rescue nil
if !pbResolveBitmap(bitmapFileName)
bitmapFileName = sprintf("Graphics/Characters/trchar%03d",type)
end
return bitmapFileName
end
def pbTrainerCharNameFile(type) # Used by Battle Frontier and compiler
return nil if !type
bitmapFileName = sprintf("trchar%s",getConstantName(PBTrainers,type)) rescue nil
if !pbResolveBitmap(sprintf("Graphics/Characters/"+bitmapFileName))
bitmapFileName = sprintf("trchar%03d",type)
end
return bitmapFileName
end
#===============================================================================
# Load trainer sprites
#===============================================================================
def pbTrainerSpriteFile(type)
return nil if !type
bitmapFileName = sprintf("Graphics/Trainers/trainer%s",
getConstantName(PBTrainers,type)) rescue nil
if !pbResolveBitmap(bitmapFileName)
bitmapFileName = sprintf("Graphics/Trainers/trainer%03d",type)
end
return bitmapFileName
end
def pbTrainerSpriteBackFile(type)
return nil if !type
bitmapFileName = sprintf("Graphics/Trainers/trback%s",
getConstantName(PBTrainers,type)) rescue nil
if !pbResolveBitmap(bitmapFileName)
bitmapFileName = sprintf("Graphics/Trainers/trback%03d",type)
end
return bitmapFileName
end
def pbPlayerSpriteFile(type)
return nil if !type
outfit = ($Trainer) ? $Trainer.outfit : 0
bitmapFileName = sprintf("Graphics/Trainers/trainer%s_%d",
getConstantName(PBTrainers,type),outfit) rescue nil
if !pbResolveBitmap(bitmapFileName)
bitmapFileName = sprintf("Graphics/Trainers/trainer%03d_%d",type,outfit)
if !pbResolveBitmap(bitmapFileName)
bitmapFileName = pbTrainerSpriteFile(type)
end
end
return bitmapFileName
end
def pbPlayerSpriteBackFile(type)
return nil if !type
outfit = ($Trainer) ? $Trainer.outfit : 0
bitmapFileName = sprintf("Graphics/Trainers/trback%s_%d",
getConstantName(PBTrainers,type),outfit) rescue nil
if !pbResolveBitmap(bitmapFileName)
bitmapFileName = sprintf("Graphics/Trainers/trback%03d_%d",type,outfit)
if !pbResolveBitmap(bitmapFileName)
bitmapFileName = pbTrainerSpriteBackFile(type)
end
end
return bitmapFileName
end
#===============================================================================
# Load player's head icons (used in the Town Map)
#===============================================================================
def pbTrainerHeadFile(type)
return nil if !type
bitmapFileName = sprintf("Graphics/Pictures/mapPlayer%s",getConstantName(PBTrainers,type)) rescue nil
if !pbResolveBitmap(bitmapFileName)
bitmapFileName = sprintf("Graphics/Pictures/mapPlayer%03d",type)
end
return bitmapFileName
end
def pbPlayerHeadFile(type)
return nil if !type
outfit = ($Trainer) ? $Trainer.outfit : 0
bitmapFileName = sprintf("Graphics/Pictures/mapPlayer%s_%d",
getConstantName(PBTrainers,type),outfit) rescue nil
if !pbResolveBitmap(bitmapFileName)
bitmapFileName = sprintf("Graphics/Pictures/mapPlayer%03d_%d",type,outfit)
if !pbResolveBitmap(bitmapFileName)
bitmapFileName = pbTrainerHeadFile(type)
end
end
return bitmapFileName
end
#===============================================================================
# Analyse audio files
#===============================================================================
def pbResolveAudioSE(file)
return nil if !file
if RTP.exists?("Audio/SE/"+file,["",".wav",".mp3",".ogg"])
return RTP.getPath("Audio/SE/"+file,["",".wav",".mp3",".ogg"])
end
return nil
end
def pbCryFrameLength(pokemon,form=0,pitch=nil)
return 0 if !pokemon
pitch = 100 if !pitch
pitch = pitch.to_f/100
return 0 if pitch<=0
playtime = 0.0
if pokemon.is_a?(Numeric)
pkmnwav = pbResolveAudioSE(pbCryFile(pokemon,form))
playtime = getPlayTime(pkmnwav) if pkmnwav
elsif !pokemon.egg?
if pokemon.respond_to?("chatter") && pokemon.chatter
playtime = pokemon.chatter.time
pitch = 1.0
else
pkmnwav = pbResolveAudioSE(pbCryFile(pokemon))
playtime = getPlayTime(pkmnwav) if pkmnwav
end
end
playtime /= pitch # sound is lengthened the lower the pitch
# 4 is added to provide a buffer between sounds
return (playtime*Graphics.frame_rate).ceil+4
end
#===============================================================================
# Load/play Pokémon cry files
#===============================================================================
def pbPlayCry(pokemon,volume=90,pitch=nil)
return if !pokemon
if pokemon.is_a?(Numeric) || pokemon.is_a?(String) || pokemon.is_a?(Symbol)
pbPlayCrySpecies(pokemon,0,volume,pitch)
elsif pokemon.is_a?(PokeBattle_Pokemon)
pbPlayCryPokemon(pokemon,volume,pitch)
end
end
def pbPlayCrySpecies(pokemon,form=0,volume=90,pitch=nil)
return if !pokemon
pokemon = getID(PBSpecies,pokemon)
return if !pokemon.is_a?(Numeric)
pkmnwav = pbCryFile(pokemon,form)
if pkmnwav
pitch ||= 100
pbSEPlay(RPG::AudioFile.new(pkmnwav,volume,pitch)) rescue nil
end
end
def pbPlayCryPokemon(pokemon,volume=90,pitch=nil)
return if !pokemon || pokemon.egg?
if pokemon.respond_to?("chatter") && pokemon.chatter
pokemon.chatter.play
return
end
pkmnwav = pbCryFile(pokemon)
if pkmnwav
pitch ||= (pokemon.hp*25/pokemon.totalhp)+75
pbSEPlay(RPG::AudioFile.new(pkmnwav,volume,pitch)) rescue nil
end
end
def pbCryFile(pokemon,form=0)
return nil if !pokemon
pokemon = getID(PBSpecies,pokemon)
if pokemon.is_a?(Numeric)
filename = sprintf("Cries/%sCry_%d",getConstantName(PBSpecies,pokemon),form) rescue nil
if !pbResolveAudioSE(filename)
filename = sprintf("Cries/%03dCry_%d",pokemon,form)
if !pbResolveAudioSE(filename)
filename = sprintf("Cries/%sCry",getConstantName(PBSpecies,pokemon)) rescue nil
if !pbResolveAudioSE(filename)
filename = sprintf("Cries/%03dCry",pokemon)
end
end
end
return filename if pbResolveAudioSE(filename)
elsif !pokemon.egg?
form = (pokemon.form rescue 0)
filename = sprintf("Cries/%sCry_%d",getConstantName(PBSpecies,pokemon.species),form) rescue nil
if !pbResolveAudioSE(filename)
filename = sprintf("Cries/%03dCry_%d",pokemon.species,form)
if !pbResolveAudioSE(filename)
filename = sprintf("Cries/%sCry",getConstantName(PBSpecies,pokemon.species)) rescue nil
if !pbResolveAudioSE(filename)
filename = sprintf("Cries/%03dCry",pokemon.species)
end
end
end
return filename if pbResolveAudioSE(filename)
end
return nil
end
#===============================================================================
# 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-specific metadata
music = pbGetMetadata($game_map.map_id,MetadataMapWildBattleBGM)
ret = pbStringToAudioFile(music) if music && music!=""
end
if !ret
# Check global metadata
music = pbGetMetadata(0,MetadataWildBattleBGM)
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 = nil
if !ret
# Check map-specific metadata
music = pbGetMetadata($game_map.map_id,MetadataMapWildVictoryME)
ret = pbStringToAudioFile(music) if music && music!=""
end
if !ret
# Check global metadata
music = pbGetMetadata(0,MetadataWildVictoryME)
ret = pbStringToAudioFile(music) if music && music!=""
end
ret = pbStringToAudioFile("Battle victory") if !ret
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-specific metadata
music = pbGetMetadata($game_map.map_id,MetadataMapWildCaptureME)
ret = pbStringToAudioFile(music) if music && music!=""
end
if !ret
# Check global metadata
music = pbGetMetadata(0,MetadataWildCaptureME)
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(trainerType)
data = pbGetTrainerTypeData(trainerType)
if data && data[6] && data[6]!=""
bgm = pbStringToAudioFile(data[6])
pbMEPlay(bgm)
end
end
def pbGetTrainerBattleBGM(trainer) # can be a PokeBattle_Trainer 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|
data = pbGetTrainerTypeData(t.trainertype)
music = data[4] if data && data[4]
end
ret = pbStringToAudioFile(music) if music && music!=""
if !ret
# Check map-specific metadata
music = pbGetMetadata($game_map.map_id,MetadataMapTrainerBattleBGM)
if music && music!=""
ret = pbStringToAudioFile(music)
end
end
if !ret
# Check global metadata
music = pbGetMetadata(0,MetadataTrainerBattleBGM)
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
data = pbGetTrainerTypeData(trainertype)
ret = pbStringToAudioFile(data[4]) if data && data[4]
if !ret
# Check map-specific metadata
music = pbGetMetadata($game_map.map_id,MetadataMapTrainerBattleBGM)
ret = pbStringToAudioFile(music) if music && music!=""
end
if !ret
# Check global metadata
music = pbGetMetadata(0,MetadataTrainerBattleBGM)
ret = pbStringToAudioFile(music) if music && music!=""
end
ret = pbStringToAudioFile("Battle trainer") if !ret
return ret
end
def pbGetTrainerVictoryME(trainer) # can be a PokeBattle_Trainer or an array of them
if $PokemonGlobal.nextBattleME
return $PokemonGlobal.nextBattleME.clone
end
music = nil
trainerarray = (trainer.is_a?(Array)) ? trainer : [trainer]
trainerarray.each do |t|
data = pbGetTrainerTypeData(t.trainertype)
music = data[5] if data && data[5]
end
ret = nil
if music && music!=""
ret = pbStringToAudioFile(music)
end
if !ret
# Check map-specific metadata
music = pbGetMetadata($game_map.map_id,MetadataMapTrainerVictoryME)
if music && music!=""
ret = pbStringToAudioFile(music)
end
end
if !ret
# Check global metadata
music = pbGetMetadata(0,MetadataTrainerVictoryME)
if music && music!=""
ret = pbStringToAudioFile(music)
end
end
ret = pbStringToAudioFile("Battle victory") if !ret
ret.name = "../../Audio/ME/"+ret.name
return ret
end

View File

@@ -0,0 +1,505 @@
#===============================================================================
# Nicknaming and storing Pokémon
#===============================================================================
def pbBoxesFull?
return ($Trainer.party.length==6 && $PokemonStorage.full?)
end
def pbNickname(pokemon)
speciesname = PBSpecies.getName(pokemon.species)
if pbConfirmMessage(_INTL("Would you like to give a nickname to {1}?",speciesname))
helptext = _INTL("{1}'s nickname?",speciesname)
newname = pbEnterPokemonName(helptext,0,PokeBattle_Pokemon::MAX_POKEMON_NAME_SIZE,"",pokemon)
pokemon.name = newname if newname!=""
end
end
def pbStorePokemon(pokemon)
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
pokemon.pbRecordFirstMoves
if $Trainer.party.length<6
$Trainer.party[$Trainer.party.length] = pokemon
else
oldcurbox = $PokemonStorage.currentBox
storedbox = $PokemonStorage.pbStoreCaught(pokemon)
curboxname = $PokemonStorage[oldcurbox].name
boxname = $PokemonStorage[storedbox].name
creator = nil
creator = pbGetStorageCreator if $PokemonGlobal.seenStorageCreator
if storedbox!=oldcurbox
if creator
pbMessage(_INTL("Box \"{1}\" on {2}'s PC was full.\1",curboxname,creator))
else
pbMessage(_INTL("Box \"{1}\" on someone's PC was full.\1",curboxname))
end
pbMessage(_INTL("{1} was transferred to box \"{2}.\"",pokemon.name,boxname))
else
if creator
pbMessage(_INTL("{1} was transferred to {2}'s PC.\1",pokemon.name,creator))
else
pbMessage(_INTL("{1} was transferred to someone's PC.\1",pokemon.name))
end
pbMessage(_INTL("It was stored in box \"{1}.\"",boxname))
end
end
end
def pbNicknameAndStore(pokemon)
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.seen[pokemon.species] = true
$Trainer.owned[pokemon.species] = true
pbNickname(pokemon)
pbStorePokemon(pokemon)
end
#===============================================================================
# Giving Pokémon to the player (will send to storage if party is full)
#===============================================================================
def pbAddPokemon(pokemon,level=nil,seeform=true)
return if !pokemon
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
pokemon = getID(PBSpecies,pokemon)
if pokemon.is_a?(Integer) && level.is_a?(Integer)
pokemon = pbNewPkmn(pokemon,level)
end
speciesname = PBSpecies.getName(pokemon.species)
pbMessage(_INTL("\\me[Pkmn get]{1} obtained {2}!\1",$Trainer.name,speciesname))
pbNicknameAndStore(pokemon)
pbSeenForm(pokemon) if seeform
return true
end
def pbAddPokemonSilent(pokemon,level=nil,seeform=true)
return false if !pokemon || pbBoxesFull?
pokemon = getID(PBSpecies,pokemon)
if pokemon.is_a?(Integer) && level.is_a?(Integer)
pokemon = pbNewPkmn(pokemon,level)
end
$Trainer.seen[pokemon.species] = true
$Trainer.owned[pokemon.species] = true
pbSeenForm(pokemon) if seeform
pokemon.pbRecordFirstMoves
if $Trainer.party.length<6
$Trainer.party[$Trainer.party.length] = pokemon
else
$PokemonStorage.pbStoreCaught(pokemon)
end
return true
end
#===============================================================================
# Giving Pokémon/eggs to the player (can only add to party)
#===============================================================================
def pbAddToParty(pokemon,level=nil,seeform=true)
return false if !pokemon || $Trainer.party.length>=6
pokemon = getID(PBSpecies,pokemon)
if pokemon.is_a?(Integer) && level.is_a?(Integer)
pokemon = pbNewPkmn(pokemon,level)
end
speciesname = PBSpecies.getName(pokemon.species)
pbMessage(_INTL("\\me[Pkmn get]{1} obtained {2}!\1",$Trainer.name,speciesname))
pbNicknameAndStore(pokemon)
pbSeenForm(pokemon) if seeform
return true
end
def pbAddToPartySilent(pokemon,level=nil,seeform=true)
return false if !pokemon || $Trainer.party.length>=6
pokemon = getID(PBSpecies,pokemon)
if pokemon.is_a?(Integer) && level.is_a?(Integer)
pokemon = pbNewPkmn(pokemon,level)
end
$Trainer.seen[pokemon.species] = true
$Trainer.owned[pokemon.species] = true
pbSeenForm(pokemon) if seeform
pokemon.pbRecordFirstMoves
$Trainer.party[$Trainer.party.length] = pokemon
return true
end
def pbAddForeignPokemon(pokemon,level=nil,ownerName=nil,nickname=nil,ownerGender=0,seeform=true)
return false if !pokemon || $Trainer.party.length>=6
pokemon = getID(PBSpecies,pokemon)
if pokemon.is_a?(Integer) && level.is_a?(Integer)
pokemon = pbNewPkmn(pokemon,level)
end
# Set original trainer to a foreign one (if ID isn't already foreign)
if pokemon.trainerID==$Trainer.id
pokemon.trainerID = $Trainer.getForeignID
pokemon.ot = ownerName if ownerName && ownerName!=""
pokemon.otgender = ownerGender
end
# Set nickname
pokemon.name = nickname[0,PokeBattle_Pokemon::MAX_POKEMON_NAME_SIZE] if nickname && nickname!=""
# Recalculate stats
pokemon.calcStats
if ownerName
pbMessage(_INTL("\\me[Pkmn get]{1} received a Pokémon from {2}.\1",$Trainer.name,ownerName))
else
pbMessage(_INTL("\\me[Pkmn get]{1} received a Pokémon.\1",$Trainer.name))
end
pbStorePokemon(pokemon)
$Trainer.seen[pokemon.species] = true
$Trainer.owned[pokemon.species] = true
pbSeenForm(pokemon) if seeform
return true
end
def pbGenerateEgg(pokemon,text="")
return false if !pokemon || $Trainer.party.length>=6
pokemon = getID(PBSpecies,pokemon)
if pokemon.is_a?(Integer)
pokemon = pbNewPkmn(pokemon,EGG_LEVEL)
end
# Get egg steps
eggSteps = pbGetSpeciesData(pokemon.species,pokemon.form,SpeciesStepsToHatch)
# Set egg's details
pokemon.name = _INTL("Egg")
pokemon.eggsteps = eggSteps
pokemon.obtainText = text
pokemon.calcStats
# Add egg to party
$Trainer.party[$Trainer.party.length] = pokemon
return true
end
alias pbAddEgg pbGenerateEgg
alias pbGenEgg pbGenerateEgg
#===============================================================================
# Removing Pokémon from the party (fails if trying to remove last able Pokémon)
#===============================================================================
def pbRemovePokemonAt(index)
return false if index<0 || index>=$Trainer.party.length
haveAble = false
for i in 0...$Trainer.party.length
next if i==index
haveAble = true if $Trainer.party[i].hp>0 && !$Trainer.party[i].egg?
end
return false if !haveAble
$Trainer.party.delete_at(index)
return true
end
#===============================================================================
# Recording Pokémon forms as seen
#===============================================================================
def pbSeenForm(pkmn,gender=0,form=0)
$Trainer.formseen = [] if !$Trainer.formseen
$Trainer.formlastseen = [] if !$Trainer.formlastseen
if pkmn.is_a?(PokeBattle_Pokemon)
gender = pkmn.gender
form = (pkmn.form rescue 0)
species = pkmn.species
else
species = getID(PBSpecies,pkmn)
end
return if !species || species<=0
fSpecies = pbGetFSpeciesFromForm(species,form)
species, form = pbGetSpeciesFromFSpecies(fSpecies)
gender = 0 if gender>1
dexForm = pbGetSpeciesData(species,form,SpeciesPokedexForm)
form = dexForm if dexForm>0
fSpecies = pbGetFSpeciesFromForm(species,form)
formName = pbGetMessage(MessageTypes::FormNames,fSpecies)
form = 0 if !formName || formName==""
$Trainer.formseen[species] = [[],[]] if !$Trainer.formseen[species]
$Trainer.formseen[species][gender][form] = true
$Trainer.formlastseen[species] = [] if !$Trainer.formlastseen[species]
$Trainer.formlastseen[species] = [gender,form] if $Trainer.formlastseen[species]==[]
end
def pbUpdateLastSeenForm(pkmn)
$Trainer.formlastseen = [] if !$Trainer.formlastseen
form = (pkmn.form rescue 0)
dexForm = pbGetSpeciesData(pkmn.species,pkmn.form,SpeciesPokedexForm)
form = dexForm if dexForm>0
formName = pbGetMessage(MessageTypes::FormNames,pkmn.fSpecies)
form = 0 if !formName || formName==""
$Trainer.formlastseen[pkmn.species] = [] if !$Trainer.formlastseen[pkmn.species]
$Trainer.formlastseen[pkmn.species] = [pkmn.gender,form]
end
#===============================================================================
# Choose a Pokémon in the party
#===============================================================================
# Choose a Pokémon/egg from the party.
# Stores result in variable _variableNumber_ and the chosen Pokémon's name in
# variable _nameVarNumber_; result is -1 if no Pokémon was chosen
def pbChoosePokemon(variableNumber,nameVarNumber,ableProc=nil,allowIneligible=false)
chosen = 0
pbFadeOutIn {
scene = PokemonParty_Scene.new
screen = PokemonPartyScreen.new(scene,$Trainer.party)
if ableProc
chosen=screen.pbChooseAblePokemon(ableProc,allowIneligible)
else
screen.pbStartScene(_INTL("Choose a Pokémon."),false)
chosen = screen.pbChoosePokemon
screen.pbEndScene
end
}
pbSet(variableNumber,chosen)
if chosen>=0
pbSet(nameVarNumber,$Trainer.party[chosen].name)
else
pbSet(nameVarNumber,"")
end
end
def pbChooseNonEggPokemon(variableNumber,nameVarNumber)
pbChoosePokemon(variableNumber,nameVarNumber,proc { |pkmn| !pkmn.egg? })
end
def pbChooseAblePokemon(variableNumber,nameVarNumber)
pbChoosePokemon(variableNumber,nameVarNumber,proc { |pkmn| !pkmn.egg? && pkmn.hp>0 })
end
# Same as pbChoosePokemon, but prevents choosing an egg or a Shadow Pokémon.
def pbChooseTradablePokemon(variableNumber,nameVarNumber,ableProc=nil,allowIneligible=false)
chosen = 0
pbFadeOutIn {
scene = PokemonParty_Scene.new
screen = PokemonPartyScreen.new(scene,$Trainer.party)
if ableProc
chosen=screen.pbChooseTradablePokemon(ableProc,allowIneligible)
else
screen.pbStartScene(_INTL("Choose a Pokémon."),false)
chosen = screen.pbChoosePokemon
screen.pbEndScene
end
}
pbSet(variableNumber,chosen)
if chosen>=0
pbSet(nameVarNumber,$Trainer.party[chosen].name)
else
pbSet(nameVarNumber,"")
end
end
def pbChoosePokemonForTrade(variableNumber,nameVarNumber,wanted)
wanted = getID(PBSpecies,wanted)
pbChooseTradablePokemon(variableNumber,nameVarNumber,proc { |pkmn|
next pkmn.species==wanted
})
end
#===============================================================================
# Analyse Pokémon in the party
#===============================================================================
# Returns the first unfainted, non-egg Pokémon in the player's party.
def pbFirstAblePokemon(variableNumber)
for i in 0...$Trainer.party.length
p = $Trainer.party[i]
if p && !p.egg? && p.hp>0
pbSet(variableNumber,i)
return $Trainer.party[i]
end
end
pbSet(variableNumber,-1)
return nil
end
# Checks whether the player would still have an unfainted Pokémon if the
# Pokémon given by _pokemonIndex_ were removed from the party.
def pbCheckAble(pokemonIndex)
for i in 0...$Trainer.party.length
next if i==pokemonIndex
p = $Trainer.party[i]
return true if p && !p.egg? && p.hp>0
end
return false
end
# Returns true if there are no usable Pokémon in the player's party.
def pbAllFainted
return $Trainer.ablePokemonCount==0
end
# Returns true if there is a Pokémon of the given species in the player's party.
# You may also specify a particular form it should be.
def pbHasSpecies?(species,form=-1)
species = getID(PBSpecies,species)
for pokemon in $Trainer.pokemonParty
return true if pokemon.species==species && (form<0 || form==pokemon.form)
end
return false
end
# Returns true if there is a fatefully met Pokémon of the given species in the
# player's party.
def pbHasFatefulSpecies?(species)
species = getID(PBSpecies,species)
for pokemon in $Trainer.pokemonParty
return true if pokemon.species==species && pokemon.obtainMode==4
end
return false
end
# Returns true if there is a Pokémon with the given type in the player's party.
def pbHasType?(type)
type = getID(PBTypes,type)
for pokemon in $Trainer.pokemonParty
return true if pokemon.hasType?(type)
end
return false
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 pbCheckMove(move)
move = getID(PBMoves,move)
return nil if !move || move<=0
for i in $Trainer.pokemonParty
for j in i.moves
return i if j.id==move
end
end
return nil
end
#===============================================================================
# Fully heal all Pokémon in the party
#===============================================================================
def pbHealAll
$Trainer.party.each { |pkmn| pkmn.heal }
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 = PBExperience.maxLevel
average = sum.to_f/party.length.to_f
# Calculate the standard deviation
varianceTimesN = 0
for i in 0...party.length
deviation = party[i].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
for i in 0...party.length
weight = party[i].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 { |weight| weightSum += weight }
# Calculate the weighted mean, assigning each weight to each level's
# contribution to the sum
for i in 0...party.length
mean += party[i].level*weights[i]
end
mean /= weightSum
# Round to nearest number
mean = mean.round
# Adjust level to minimum
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 = pbGetSpeciesData(pkmn.species,pkmn.form,SpeciesHeight)
hpiv = pkmn.iv[0]&15
ativ = pkmn.iv[1]&15
dfiv = pkmn.iv[2]&15
spiv = pkmn.iv[3]&15
saiv = pkmn.iv[4]&15
sdiv = pkmn.iv[5]&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 = getID(PBSpecies,species)
return false if !species
# species may be unbreedable, so check its evolution's compatibilities
evoSpecies = pbGetEvolvedFormData(species,true)
compatSpecies = (evoSpecies && evoSpecies[0]) ? evoSpecies[0][2] : species
compat = pbGetSpeciesData(compatSpecies,0,SpeciesCompatibility)
compat = [compat] if !compat.is_a?(Array)
return false if compat.include?(getConst(PBEggGroups,:Undiscovered))
return false if compat.include?(getConst(PBEggGroups,:Ditto))
baby = pbGetBabySpecies(species)
return true if species==baby # Is a basic species
baby = pbGetBabySpecies(species,0,0)
return true if species==baby # Is an egg species without incense
return false
end

File diff suppressed because it is too large Load Diff