begin
class SpriteMetafile < Sprite
VIEWPORT=0
TONE=1
SRC_RECT=2
VISIBLE=3
X=4
Y=5
Z=6
OX=7
OY=8
ZOOM_X=9
ZOOM_Y=10
ANGLE=11
MIRROR=12
BUSH_DEPTH=13
OPACITY=14
BLEND_TYPE=15
COLOR=16
FLASHCOLOR=17
FLASHDURATION=18
BITMAP=19
def length
return @metafile.length
end
def [](i)
return @metafile[i]
end
def initialize(viewport=nil)
@metafile=[]
@values=[
viewport,
Tone.new(0,0,0,0),
Rect.new(0,0,0,0),
true,
0,0,0,0,0,100,100,
0,false,0,255,0,
Color.new(0,0,0,0),
Color.new(0,0,0,0),
0
]
@clonedValues=cloneValues
end
def disposed?
return false
end
def dispose
end
def flash(color,duration)
if duration>0
@values[FLASHCOLOR]=color.clone
@values[FLASHDURATION]=duration
end
end
def x
return @values[X]
end
def x=(value)
@values[X]=value
end
def y
return @values[Y]
end
def y=(value)
@values[Y]=value
end
def bitmap
return nil
end
def bitmap=(value)
if value && !value.disposed?
@values[SRC_RECT].set(0,0,value.width,value.height)
end
end
def src_rect
return @values[SRC_RECT]
end
def src_rect=(value)
@values[SRC_RECT]=value
end
def visible
return @values[VISIBLE]
end
def visible=(value)
@values[VISIBLE]=value
end
def z
return @values[Z]
end
def z=(value)
@values[Z]=value
end
def ox
return @values[OX]
end
def ox=(value)
@values[OX]=value
end
def oy
return @values[OY]
end
def oy=(value)
@values[OY]=value
end
def zoom_x
return @values[ZOOM_X]
end
def zoom_x=(value)
@values[ZOOM_X]=value
end
def zoom_y
return @values[ZOOM_Y]
end
def zoom_y=(value)
@values[ZOOM_Y]=value
end
def angle
return @values[ANGLE]
end
def angle=(value)
@values[ANGLE]=value
end
def mirror
return @values[MIRROR]
end
def mirror=(value)
@values[MIRROR]=value
end
def bush_depth
return @values[BUSH_DEPTH]
end
def bush_depth=(value)
@values[BUSH_DEPTH]=value
end
def opacity
return @values[OPACITY]
end
def opacity=(value)
@values[OPACITY]=value
end
def blend_type
return @values[BLEND_TYPE]
end
def blend_type=(value)
@values[BLEND_TYPE]=value
end
def color
return @values[COLOR]
end
def color=(value)
@values[COLOR]=value.clone
end
def tone
return @values[TONE]
end
def tone=(value)
@values[TONE]=value.clone
end
def cloneValues
vals=[]
for i in 0...@values.length
begin
vals[i]=@values[i].clone
rescue TypeError
vals[i]=@values[i]
end
end
return vals
end
def update
for i in 0...@values.length
if @values[i]!=@clonedValues[i]
@metafile.push([i,@values[i]])
end
end
@metafile.push([-1,nil])
@clonedValues=cloneValues
end
end
class SpriteMetafilePlayer
def initialize(metafile,sprite=nil)
@metafile=metafile
@sprites=[]
@playing=false
@index=0
@sprites.push(sprite) if sprite
end
def add(sprite)
@sprites.push(sprite)
end
def playing?
return @playing
end
def play
@playing=true
@index=0
end
def update
if @playing
for j in @index...@metafile.length
@index=j+1
break if @metafile[j][0]<0
code=@metafile[j][0]
value=@metafile[j][1]
for sprite in @sprites
sprite.x=value if code==SpriteMetafile::X
sprite.y=value if code==SpriteMetafile::Y
sprite.src_rect=value if code==SpriteMetafile::SRC_RECT
sprite.visible=value if code==SpriteMetafile::VISIBLE
sprite.z=value if code==SpriteMetafile::Z
sprite.ox=value if code==SpriteMetafile::OX
sprite.oy=value if code==SpriteMetafile::OY
sprite.zoom_x=value if code==SpriteMetafile::ZOOM_X
sprite.zoom_y=value if code==SpriteMetafile::ZOOM_Y
sprite.angle=value if code==SpriteMetafile::ANGLE
sprite.mirror=value if code==SpriteMetafile::MIRROR
sprite.bush_depth=value if code==SpriteMetafile::BUSH_DEPTH
sprite.opacity=value if code==SpriteMetafile::OPACITY
sprite.blend_type=value if code==SpriteMetafile::BLEND_TYPE
sprite.color=value if code==SpriteMetafile::COLOR
sprite.tone=value if code==SpriteMetafile::TONE
end
end
@playing=false if @index==@metafile.length
end
end
end
def pbSaveSpriteState(sprite)
state=[]
return state if !sprite||sprite.disposed?
state[SpriteMetafile::BITMAP]=sprite.x
state[SpriteMetafile::X]=sprite.x
state[SpriteMetafile::Y]=sprite.y
state[SpriteMetafile::SRC_RECT]=sprite.src_rect.clone
state[SpriteMetafile::VISIBLE]=sprite.visible
state[SpriteMetafile::Z]=sprite.z
state[SpriteMetafile::OX]=sprite.ox
state[SpriteMetafile::OY]=sprite.oy
state[SpriteMetafile::ZOOM_X]=sprite.zoom_x
state[SpriteMetafile::ZOOM_Y]=sprite.zoom_y
state[SpriteMetafile::ANGLE]=sprite.angle
state[SpriteMetafile::MIRROR]=sprite.mirror
state[SpriteMetafile::BUSH_DEPTH]=sprite.bush_depth
state[SpriteMetafile::OPACITY]=sprite.opacity
state[SpriteMetafile::BLEND_TYPE]=sprite.blend_type
state[SpriteMetafile::COLOR]=sprite.color.clone
state[SpriteMetafile::TONE]=sprite.tone.clone
return state
end
def pbRestoreSpriteState(sprite,state)
return if !state||!sprite||sprite.disposed?
sprite.x=state[SpriteMetafile::X]
sprite.y=state[SpriteMetafile::Y]
sprite.src_rect=state[SpriteMetafile::SRC_RECT]
sprite.visible=state[SpriteMetafile::VISIBLE]
sprite.z=state[SpriteMetafile::Z]
sprite.ox=state[SpriteMetafile::OX]
sprite.oy=state[SpriteMetafile::OY]
sprite.zoom_x=state[SpriteMetafile::ZOOM_X]
sprite.zoom_y=state[SpriteMetafile::ZOOM_Y]
sprite.angle=state[SpriteMetafile::ANGLE]
sprite.mirror=state[SpriteMetafile::MIRROR]
sprite.bush_depth=state[SpriteMetafile::BUSH_DEPTH]
sprite.opacity=state[SpriteMetafile::OPACITY]
sprite.blend_type=state[SpriteMetafile::BLEND_TYPE]
sprite.color=state[SpriteMetafile::COLOR]
sprite.tone=state[SpriteMetafile::TONE]
end
def pbSaveSpriteStateAndBitmap(sprite)
return [] if !sprite||sprite.disposed?
state=pbSaveSpriteState(sprite)
state[SpriteMetafile::BITMAP]=sprite.bitmap
return state
end
def pbRestoreSpriteStateAndBitmap(sprite,state)
return if !state||!sprite||sprite.disposed?
sprite.bitmap=state[SpriteMetafile::BITMAP]
pbRestoreSpriteState(sprite,state)
return state
end
#####################
class PokemonEvolutionScene
def pbGenerateMetafiles
sprite=SpriteMetafile.new
sprite2=SpriteMetafile.new
sprite.opacity=255
sprite2.opacity=0
sprite.ox=64
sprite.oy=64
sprite2.ox=64
sprite2.oy=64
for j in 0...26
sprite.color.red=100
sprite.color.green=0
sprite.color.blue=0
sprite.color.alpha=j*10
sprite.color=sprite.color
sprite2.color=sprite.color
sprite.update
sprite2.update
end
anglechange=0
sevenseconds=40*7
for j in 0...sevenseconds
sprite.angle+=anglechange
sprite.angle%=360
anglechange+=1 if j%2==0
if j>=sevenseconds-10
sprite2.angle=sprite.angle
sprite2.opacity+=26
end
sprite.update
sprite2.update
end
sprite.angle=360-sprite.angle
sprite2.angle=360-sprite2.angle
for j in 0...sevenseconds
sprite2.angle+=anglechange
sprite2.angle%=360
anglechange-=1 if j%2==0
if j<10
sprite.angle=sprite2.angle
sprite.opacity-=26
end
sprite.update
sprite2.update
end
for j in 0...26
sprite2.color.red=100
sprite2.color.green=0
sprite2.color.blue=0
sprite2.color.alpha=(26-j)*10
sprite2.color=sprite2.color
sprite.color=sprite2.color
sprite.update
sprite2.update
end
@metafile1=sprite
@metafile2=sprite2
end
def pbStartScreen(pokemon,newspecies)
@sprites={}
@viewport=Viewport.new(0,0,480,320)
@viewport.z=99999
@pokemon=pokemon
@newspecies=newspecies
@sprites["background"]=ColoredPlane.new(Color.new(248,248,248),@viewport)
rsprite1=Sprite.new(@viewport)
rsprite2=Sprite.new(@viewport)
rsprite1.bitmap=pbLoadPokemonBitmap(@pokemon,false)
rsprite2.bitmap=pbLoadPokemonBitmapSpecies(@pokemon,@newspecies,false)
rsprite1.ox=rsprite1.bitmap.width/2
rsprite1.oy=rsprite1.bitmap.height/2
rsprite2.ox=rsprite2.bitmap.width/2
rsprite2.oy=rsprite2.bitmap.height/2
rsprite1.x=240
rsprite1.y=120
rsprite2.x=240
rsprite2.y=120
rsprite2.opacity=0
@sprites["rsprite1"]=rsprite1
@sprites["rsprite2"]=rsprite2
pbGenerateMetafiles
@sprites["msgwindow"]=Kernel.pbCreateMessageWindow(@viewport)
pbFadeInAndShow(@sprites)
end
def pbEndScreen
Kernel.pbDisposeMessageWindow(@sprites["msgwindow"])
pbFadeOutAndHide(@sprites)
pbDisposeSpriteHash(@sprites)
@viewport.dispose
end
def pbEvolution(cancancel=true)
metaplayer1=SpriteMetafilePlayer.new(@metafile1,@sprites["rsprite1"])
metaplayer2=SpriteMetafilePlayer.new(@metafile2,@sprites["rsprite2"])
metaplayer1.play
metaplayer2.play
Audio.bgm_stop
Audio.se_play("Audio/SE/Choose.wav")
Kernel.pbDisplayMessageFancy(@sprites["msgwindow"],
_INTL("What?\r\n{1} is evolving!",@pokemon.name),-1,100)
Audio.se_play("Audio/SE/Choose.wav")
oldstate=pbSaveSpriteState(@sprites["rsprite1"])
oldstate2=pbSaveSpriteState(@sprites["rsprite2"])
Audio.bgm_play("Audio/BGM/evolv.mid")
canceled=false
begin
metaplayer1.update
metaplayer2.update
Graphics.update
Input.update
if Input.trigger?(Input::B) && cancancel
canceled=true
pbRestoreSpriteState(@sprites["rsprite1"],oldstate)
pbRestoreSpriteState(@sprites["rsprite2"],oldstate2)
Graphics.update
break
end
end while metaplayer1.playing? && metaplayer2.playing?
if canceled
Audio.bgm_stop
Audio.se_play("Audio/SE/Choose.wav")
Kernel.pbDisplayMessageFancy(@sprites["msgwindow"],
_INTL("Huh?\r\n{1} stopped evolving!",@pokemon.name))
else
Audio.me_play("Audio/ME/004-Victory04")
newspeciesname=PBSpecies.getName(@newspecies)
oldspeciesname=PBSpecies.getName(@pokemon.species)
Kernel.pbDisplayMessageFancy(@sprites["msgwindow"],
_INTL("Congratulations! Your {1} evolved into {2}!",@pokemon.name,newspeciesname),-1,160)
@sprites["msgwindow"].text=""
createSpecies=pbCheckEvolutionEx(@pokemon){|pokemon,evonib,level,poke|
if evonib==14
next poke
else
next -1
end
}
@pokemon.species=@newspecies
$Trainer.seen[@newspecies]=true
$Trainer.owned[@newspecies]=true
@pokemon.name=newspeciesname if @pokemon.name==oldspeciesname
@pokemon.calcStats
# Check moves for new species
atkdata=File.open("PBS/attacksRS.dat","rb")
offset=atkdata.getOffset(@pokemon.species-1)
length=atkdata.getLength(@pokemon.species-1)>>1
atkdata.pos=offset
for k in 0..length-1
level=atkdata.fgetw
move=atkdata.fgetw
if level==@pokemon.level
# Learned a new move
pbLearnMove(@pokemon,move,true)
end
end
if createSpecies>0 && $Trainer.party.length<6
newpokemon=@pokemon.clone
newpokemon.species=createSpecies
newpokemon.name=PBSpecies.getName(createSpecies)
newpokemon.calcStats
$Trainer.party.push(newpokemon)
$Trainer.seen[createSpecies]=true
$Trainer.owned[createSpecies]=true
end
atkdata.close
end
end
end
def pbMiniCheckEvolution(pokemon,evonib,level,poke)
case evonib
when 1 # Evolves if loyal enough
return poke if pokemon.happiness>=200
when 2 # Evolves during the day if loyal enough
time=Time.now
return poke if pokemon.happiness>=200 && (time.hour<20 && time.hour>=6)
when 3 # Evolves at night if loyal enough
time=Time.now
return poke if pokemon.happiness>=200 && (time.hour>=20 && time.hour<6)
when 4
return poke if pokemon.level>=level
when 5, 6 # Evolves if traded
when 7 # Evolves with item
when 8
return poke if pokemon.level>=level && pokemon.attack>pokemon.defense
when 9
return poke if pokemon.level>=level && pokemon.attack==pokemon.defense
when 10
return poke if pokemon.level>=level && pokemon.attack<pokemon.defense
when 11 # Silcoon
return poke if pokemon.level>=level && (pokemon.personalID%10)<5
when 12 # Cascoon
return poke if pokemon.level>=level && (pokemon.personalID%10)>=5
when 13 # Ninjask
return poke if pokemon.level>=level
when 14 # Shedinja
when 15 # Feebas, TODO
end
return -1
end
def pbMiniCheckEvolutionItem(pokemon,evonib,level,poke,item)
case evonib
when 7 # Evolves with item
return poke if level==item
end
return -1
end
EVOTYPEMASK=0x0F
EVODATAMASK=0x30
EVONEXTFORM=0x00
EVOPREVFORM=0x10
def pbCheckEvolutionEx(pokemon)
return -1 if pokemon.item==PBItems::EVERSTONE
return -1 if pokemon.species<=0 || pokemon.eggsteps>0
ret=-1
File.open("PBS/evolutions.dat","rb"){|f|
f.pos=(pokemon.species-1)*8
offset=f.fgetdw
length=f.fgetdw
if length>0
f.pos=offset
i=0; loop do break unless i<length
evo=f.fgetb
evonib=evo&EVOTYPEMASK
level=f.fgetw
poke=f.fgetw
if poke<=PBSpecies.getCount && (evo&EVODATAMASK)==EVONEXTFORM
ret=yield pokemon,evonib,level,poke
break if ret>0
end
i+=5
end
end
}
return ret
end
def pbCheckEvolution(pokemon,item=0)
if item==0
return pbCheckEvolutionEx(pokemon){|pokemon,evonib,level,poke|
next pbMiniCheckEvolution(pokemon,evonib,level,poke)
}
else
return pbCheckEvolutionEx(pokemon){|pokemon,evonib,level,poke|
next pbMiniCheckEvolutionItem(pokemon,evonib,level,poke,item)
}
end
end
rescue Exception
if $!.is_a?(SystemExit) || "#{$!.class}"=="Reset"
raise $!
else
end
end