game data

This commit is contained in:
infinitefusion
2021-07-28 20:20:50 -04:00
parent 980517c0a2
commit dc7df58c17
1932 changed files with 275538 additions and 3 deletions

View File

@@ -0,0 +1,454 @@
#===============================================================================
# * Set the Controls Screen - by FL (Credits will be apreciated)
#===============================================================================
#
# This script is for Pokémon Essentials. It's make a "Set the controls"
# option screen allowing the player to map the actions to the keys in keyboard,
# customizing the controls.
#
#===============================================================================
#
# To this script works, put it between PSystem_Controls and PSystem_System.
#
# To this screen be displayed in the pause menu, in PScreen_PauseMenu script,
# before line 'commands[cmdDebug=commands.length]=_INTL("Debug") if $DEBUG' add:
#
# cmdControls=-1
# commands[cmdControls=commands.length]=_INTL("Controls")
#
# Before line 'elsif cmdOption>=0 && command==cmdOption' add:
#
# elsif cmdControls>=0 && command==cmdControls
# scene=PokemonControlsScene.new
# screen=PokemonControls.new(scene)
# pbFadeOutIn(99999) {
# screen.pbStartScreen
# }
#
# Using the last five lines you can start this scene in other places like at
# an event.
#
# Note that this script, by default, doesn't allows the player to redefine some
# commands like F8 (screenshot key), but if the player assign an action to
# this key, like the "Run" action, this key will do this action AND take
# screenshots when pressed. Remember that F12 will reset the game.
#
#===============================================================================
module Keys
# Available keys
CONTROLSLIST = {
# Mouse buttons
_INTL("Backspace") => 0x08,
_INTL("Tab") => 0x09,
_INTL("Clear") => 0x0C,
_INTL("Enter") => 0x0D,
_INTL("Shift") => 0x10,
_INTL("Ctrl") => 0x11,
_INTL("Alt") => 0x12,
_INTL("Pause") => 0x13,
_INTL("Caps Lock") => 0x14,
# IME keys
_INTL("Esc") => 0x1B,
# More IME keys
_INTL("Space") => 0x20,
_INTL("Page Up") => 0x21,
_INTL("Page Down") => 0x22,
_INTL("End") => 0x23,
_INTL("Home") => 0x24,
_INTL("Left") => 0x25,
_INTL("Up") => 0x26,
_INTL("Right") => 0x27,
_INTL("Down") => 0x28,
_INTL("Select") => 0x29,
_INTL("Print") => 0x2A,
_INTL("Execute") => 0x2B,
# _INTL("Print Screen") => 0x2C,
_INTL("Insert") => 0x2D,
_INTL("Delete") => 0x2E,
_INTL("Help") => 0x2F,
_INTL("0") => 0x30,
_INTL("1") => 0x31,
_INTL("2") => 0x32,
_INTL("3") => 0x33,
_INTL("4") => 0x34,
_INTL("5") => 0x35,
_INTL("6") => 0x36,
_INTL("7") => 0x37,
_INTL("8") => 0x38,
_INTL("9") => 0x39,
_INTL("A") => 0x41,
_INTL("B") => 0x42,
_INTL("C") => 0x43,
_INTL("D") => 0x44,
_INTL("E") => 0x45,
_INTL("F") => 0x46,
_INTL("G") => 0x47,
_INTL("H") => 0x48,
_INTL("I") => 0x49,
_INTL("J") => 0x4A,
_INTL("K") => 0x4B,
_INTL("L") => 0x4C,
_INTL("M") => 0x4D,
_INTL("N") => 0x4E,
_INTL("O") => 0x4F,
_INTL("P") => 0x50,
_INTL("Q") => 0x51,
_INTL("R") => 0x52,
_INTL("S") => 0x53,
_INTL("T") => 0x54,
_INTL("U") => 0x55,
_INTL("V") => 0x56,
_INTL("W") => 0x57,
_INTL("X") => 0x58,
_INTL("Y") => 0x59,
_INTL("Z") => 0x5A,
# Windows keys
_INTL("Numpad 0") => 0x60,
_INTL("Numpad 1") => 0x61,
_INTL("Numpad 2") => 0x62,
_INTL("Numpad 3") => 0x63,
_INTL("Numpad 4") => 0x64,
_INTL("Numpad 5") => 0x65,
_INTL("Numpad 6") => 0x66,
_INTL("Numpad 7") => 0x67,
_INTL("Numpad 8") => 0x68,
_INTL("Numpad 9") => 0x69,
_INTL("Multiply") => 0x6A,
_INTL("Add") => 0x6B,
_INTL("Separator") => 0x6C,
_INTL("Subtract") => 0x6D,
_INTL("Decimal") => 0x6E,
_INTL("Divide") => 0x6F,
_INTL("F1") => 0x70,
_INTL("F2") => 0x71,
_INTL("F3") => 0x72,
_INTL("F4") => 0x73,
_INTL("F5") => 0x74,
_INTL("F6") => 0x75,
_INTL("F7") => 0x76,
_INTL("F8") => 0x77,
_INTL("F9") => 0x78,
_INTL("F10") => 0x79,
_INTL("F11") => 0x7A,
_INTL("F12") => 0x7B,
_INTL("F13") => 0x7C,
_INTL("F14") => 0x7D,
_INTL("F15") => 0x7E,
_INTL("F16") => 0x7F,
_INTL("F17") => 0x80,
_INTL("F18") => 0x81,
_INTL("F19") => 0x82,
_INTL("F20") => 0x83,
_INTL("F21") => 0x84,
_INTL("F22") => 0x85,
_INTL("F23") => 0x86,
_INTL("F24") => 0x87,
_INTL("Num Lock") => 0x90,
_INTL("Scroll Lock") => 0x91,
# Multiple position Shift, Ctrl and Menu keys
_INTL(";:") => 0xBA,
_INTL("+") => 0xBB,
_INTL(",") => 0xBC,
_INTL("-") => 0xBD,
_INTL(".") => 0xBE,
_INTL("/?") => 0xBF,
_INTL("`~") => 0xC0,
_INTL("{") => 0xDB,
_INTL("\|") => 0xDC,
_INTL("}") => 0xDD,
_INTL("'\"") => 0xDE,
_INTL("AX") => 0xE1, # Japan only
_INTL("\|") => 0xE2
# Disc keys
}
# Here you can change the number of keys for each action and the
# default values
def self.defaultControls
return [
ControlConfig.new(_INTL("Down"),_INTL("Down")),
ControlConfig.new(_INTL("Left"),_INTL("Left")),
ControlConfig.new(_INTL("Right"),_INTL("Right")),
ControlConfig.new(_INTL("Up"),_INTL("Up")),
ControlConfig.new(_INTL("Action"),_INTL("C")),
ControlConfig.new(_INTL("Action"),_INTL("Enter")),
ControlConfig.new(_INTL("Action"),_INTL("Space")),
ControlConfig.new(_INTL("Cancel"),_INTL("X")),
ControlConfig.new(_INTL("Cancel"),_INTL("Esc")),
ControlConfig.new(_INTL("Run"),_INTL("Z")),
ControlConfig.new(_INTL("Scroll down"),_INTL("Page Down")),
ControlConfig.new(_INTL("Scroll up"),_INTL("Page Up")),
ControlConfig.new(_INTL("Registered/Sort"),_INTL("F5")),
ControlConfig.new(_INTL("Run toggle"),_INTL("S")),
ControlConfig.new(_INTL("Turbo"),_INTL("Ctrl"))
]
end
def self.getKeyName(keyCode)
ret = CONTROLSLIST.index(keyCode)
return ret ? ret : (keyCode==0 ? _INTL(" - ") : "?")
end
def self.getKeyCode(keyName)
ret = CONTROLSLIST[keyName]
raise "The button #{keyName} no longer exists! " if !ret
return ret
end
def self.detectKey
loop do
Graphics.update
Input.update
for keyCode in CONTROLSLIST.values
return keyCode if Input.triggerex?(keyCode)
end
end
end
end
class ControlConfig
attr_reader :controlAction
attr_accessor :keyCode
def initialize(controlAction,defaultKey)
@controlAction = controlAction
@keyCode = Keys.getKeyCode(defaultKey)
end
def keyName
return Keys.getKeyName(@keyCode)
end
end
module Input
class << self
alias :buttonToKeyOldFL :buttonToKey
# Here I redefine this method with my controlAction.
# Note that I don't declare action for all commands.
def buttonToKey(button)
$PokemonSystem = PokemonSystem.new if !$PokemonSystem
case button
when Input::DOWN
return $PokemonSystem.getGameControlCodes(_INTL("Down"))
when Input::LEFT
return $PokemonSystem.getGameControlCodes(_INTL("Left"))
when Input::RIGHT
return $PokemonSystem.getGameControlCodes(_INTL("Right"))
when Input::UP
return $PokemonSystem.getGameControlCodes(_INTL("Up"))
when Input::A # Z, Shift
return $PokemonSystem.getGameControlCodes(_INTL("Run"))
when Input::B # X, ESC
return $PokemonSystem.getGameControlCodes(_INTL("Cancel"))
when Input::C # C, ENTER, Space
return $PokemonSystem.getGameControlCodes(_INTL("Action"))
when Input::L # Page Up
return $PokemonSystem.getGameControlCodes(_INTL("Scroll up"))
when Input::R # Page Down
return $PokemonSystem.getGameControlCodes(_INTL("Scroll down"))
# when Input::SHIFT
# return [0x10] # Shift
#return [0x11] # Ctrl
# when Input::ALT
# return [0x12] # Alt
when Input::F5 # F5
return $PokemonSystem.getGameControlCodes(_INTL("Registered/Sort"))
when Input::Y
return $PokemonSystem.getGameControlCodes(_INTL("Run toggle"))
when Input::CTRL
return $PokemonSystem.getGameControlCodes(_INTL("Turbo"))
# 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 buttonToKeyOldFL(button)
end
end
end
end
class Window_PokemonControls < Window_DrawableCommand
attr_reader :readingInput
attr_reader :controls
attr_reader :changed
def initialize(controls,x,y,width,height)
@controls=controls
@nameBaseColor=Color.new(88,88,80)
@nameShadowColor=Color.new(168,184,184)
@selBaseColor=Color.new(24,112,216)
@selShadowColor=Color.new(136,168,208)
@readingInput=false
@changed=false
super(x,y,width,height)
end
def setNewInput(newInput)
@readingInput = false
return if @controls[@index].keyCode==newInput
for control in @controls # Remove the same input for the same array
control.keyCode = 0 if control.keyCode==newInput
end
@controls[@index].keyCode=newInput
@changed = true
refresh
end
def itemCount
return @controls.length+2
end
def drawItem(index,count,rect)
rect=drawCursor(index,rect)
optionname = ""
if index==(@controls.length+1)
optionname = _INTL("Exit")
elsif index==(@controls.length)
optionname = _INTL("Default")
else
optionname = @controls[index].controlAction
end
optionwidth=(rect.width*9/20)
pbDrawShadowText(self.contents,rect.x,rect.y,optionwidth,rect.height,
optionname,@nameBaseColor,@nameShadowColor)
self.contents.draw_text(rect.x,rect.y,optionwidth,rect.height,optionname)
return if index>=@controls.length
value=@controls[index].keyName
xpos=optionwidth+rect.x
pbDrawShadowText(self.contents,xpos,rect.y,optionwidth,rect.height,value,
@selBaseColor,@selShadowColor)
self.contents.draw_text(xpos,rect.y,optionwidth,rect.height,value)
end
def update
dorefresh=false
oldindex=self.index
super
dorefresh=self.index!=oldindex
if self.active && self.index<=@controls.length
if Input.trigger?(Input::C)
if self.index == @controls.length # Default
@controls = Keys.defaultControls
@changed = true
dorefresh = true
else
@readingInput = true
end
end
end
refresh if dorefresh
end
end
class PokemonControlsScene
def pbUpdate
pbUpdateSpriteHash(@sprites)
end
def pbStartScene
@sprites={}
@viewport=Viewport.new(0,0,Graphics.width,Graphics.height)
@viewport.z=99999
@sprites["title"]=Window_UnformattedTextPokemon.newWithSize(
_INTL("Controls"),0,0,Graphics.width,64,@viewport)
@sprites["textbox"]=Kernel.pbCreateMessageWindow
@sprites["textbox"].letterbyletter=false
gameControls = []
for control in $PokemonSystem.gameControls
gameControls.push(control.clone)
end
@sprites["controlwindow"]=Window_PokemonControls.new(gameControls,0,
@sprites["title"].height,Graphics.width,
Graphics.height-@sprites["title"].height-@sprites["textbox"].height)
@sprites["controlwindow"].viewport=@viewport
@sprites["controlwindow"].visible=true
@changed = false
pbDeactivateWindows(@sprites)
pbFadeInAndShow(@sprites) { pbUpdate }
end
def pbMain
pbActivateWindow(@sprites,"controlwindow"){
loop do
Graphics.update
Input.update
pbUpdate
exit = false
if @sprites["controlwindow"].readingInput
@sprites["textbox"].text=_INTL("Press a new key.")
@sprites["controlwindow"].setNewInput(Keys.detectKey)
@sprites["textbox"].text=""
@changed = true
else
if Input.trigger?(Input::B) || (Input.trigger?(Input::C) &&
@sprites["controlwindow"].index==(
@sprites["controlwindow"].itemCount-1))
exit = true
if(@sprites["controlwindow"].changed &&
Kernel.pbConfirmMessage(_INTL("Save changes?")))
@sprites["textbox"].text = "" # Visual effect
newControls = @sprites["controlwindow"].controls
emptyCommand = false
for control in newControls
emptyCommand = true if control.keyCode == 0
end
if emptyCommand
@sprites["textbox"].text=_INTL("Fill all fields!")
exit = false
else
$PokemonSystem.gameControls = newControls
end
end
end
end
break if exit
end
}
end
def pbEndScene
pbFadeOutAndHide(@sprites) { pbUpdate }
Kernel.pbDisposeMessageWindow(@sprites["textbox"])
pbDisposeSpriteHash(@sprites)
@viewport.dispose
end
end
class PokemonControls
def initialize(scene)
@scene=scene
end
def pbStartScreen
@scene.pbStartScene
@scene.pbMain
@scene.pbEndScene
end
end
class PokemonSystem
attr_accessor :gameControls
def gameControls
@gameControls = Keys.defaultControls if !@gameControls
return @gameControls
end
def getGameControlCodes(controlAction)
ret = []
for control in gameControls
ret.push(control.keyCode) if control.controlAction == controlAction
end
return ret
end
end

View File

@@ -0,0 +1,153 @@
# 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
if $game_variables
pbTurboToggle()
end
end
end
def pbTurboToggle()
if trigger?(Input::CTRL)
pbSEPlay("expfull") if FileTest.audio_exist?("Audio/SE/expfull")
pbTurbo()
end
end
def pbTurbo()
if Graphics.frame_rate==BASE_FRAMERATE
Graphics.frame_rate =TURBO_FRAMERATE
else
Graphics.frame_rate=BASE_FRAMERATE
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("{1} obtained {2}!\\me[Pkmn get]\\wtnp[80]\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("{1} obtained {2}!\\me[Pkmn get]\\wtnp[80]\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 { |w| weightSum += w }
# 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