Merge branch 'master' into refactor

This commit is contained in:
Maruno17
2020-10-18 21:40:04 +01:00
49 changed files with 2885 additions and 2861 deletions

View File

@@ -54,6 +54,7 @@ module Events
@@OnWildBattleOverride = Event.new
@@OnWildBattleEnd = Event.new
@@OnTrainerPartyLoad = Event.new
@@OnChangeDirection = Event.new
# Fires whenever a map is created. Event handler receives two parameters: the
# map (RPG::Map) and the tileset (RPG::Tileset)
@@ -159,6 +160,10 @@ module Events
# e[2] - Party
def self.onTrainerPartyLoad; @@OnTrainerPartyLoad; end
def self.onTrainerPartyLoad=(v); @@OnTrainerPartyLoad = v; end
# Fires whenever the player changes direction.
def self.onChangeDirection; @@OnChangeDirection; end
def self.onChangeDirection=(v); @@OnChangeDirection = v; end
end
@@ -254,7 +259,7 @@ Events.onMapUpdate += proc { |_sender,_e|
# Checks per step
#===============================================================================
# Party Pokémon gain happiness from walking
Events.onStepTaken += proc{
Events.onStepTaken += proc {
$PokemonGlobal.happinessSteps = 0 if !$PokemonGlobal.happinessSteps
$PokemonGlobal.happinessSteps += 1
if $PokemonGlobal.happinessSteps>=128
@@ -365,6 +370,12 @@ def pbOnStepTaken(eventTriggered)
pbBattleOnStepTaken(repel) if !eventTriggered && !$game_temp.in_menu
end
# Start wild encounters while turning on the spot
Events.onChangeDirection += proc {
repel = ($PokemonGlobal.repel>0)
pbBattleOnStepTaken(repel) if !$game_temp.in_menu
}
def pbBattleOnStepTaken(repel=false)
return if $Trainer.ablePokemonCount==0
encounterType = $PokemonEncounters.pbEncounterType
@@ -489,411 +500,6 @@ Events.onMapSceneChange += proc { |_sender,e|
#===============================================================================
# Event movement
#===============================================================================
module PBMoveRoute
Down = 1
Left = 2
Right = 3
Up = 4
LowerLeft = 5
LowerRight = 6
UpperLeft = 7
UpperRight = 8
Random = 9
TowardPlayer = 10
AwayFromPlayer = 11
Forward = 12
Backward = 13
Jump = 14 # xoffset, yoffset
Wait = 15 # frames
TurnDown = 16
TurnLeft = 17
TurnRight = 18
TurnUp = 19
TurnRight90 = 20
TurnLeft90 = 21
Turn180 = 22
TurnRightOrLeft90 = 23
TurnRandom = 24
TurnTowardPlayer = 25
TurnAwayFromPlayer = 26
SwitchOn = 27 # 1 param
SwitchOff = 28 # 1 param
ChangeSpeed = 29 # 1 param
ChangeFreq = 30 # 1 param
WalkAnimeOn = 31
WalkAnimeOff = 32
StepAnimeOn = 33
StepAnimeOff = 34
DirectionFixOn = 35
DirectionFixOff = 36
ThroughOn = 37
ThroughOff = 38
AlwaysOnTopOn = 39
AlwaysOnTopOff = 40
Graphic = 41 # Name, hue, direction, pattern
Opacity = 42 # 1 param
Blending = 43 # 1 param
PlaySE = 44 # 1 param
Script = 45 # 1 param
ScriptAsync = 101 # 1 param
end
def pbMoveRoute(event,commands,waitComplete=false)
route = RPG::MoveRoute.new
route.repeat = false
route.skippable = true
route.list.clear
route.list.push(RPG::MoveCommand.new(PBMoveRoute::ThroughOn))
i=0
while i<commands.length
case commands[i]
when PBMoveRoute::Wait, PBMoveRoute::SwitchOn, PBMoveRoute::SwitchOff,
PBMoveRoute::ChangeSpeed, PBMoveRoute::ChangeFreq, PBMoveRoute::Opacity,
PBMoveRoute::Blending, PBMoveRoute::PlaySE, PBMoveRoute::Script
route.list.push(RPG::MoveCommand.new(commands[i],[commands[i+1]]))
i += 1
when PBMoveRoute::ScriptAsync
route.list.push(RPG::MoveCommand.new(PBMoveRoute::Script,[commands[i+1]]))
route.list.push(RPG::MoveCommand.new(PBMoveRoute::Wait,[0]))
i += 1
when PBMoveRoute::Jump
route.list.push(RPG::MoveCommand.new(commands[i],[commands[i+1],commands[i+2]]))
i += 2
when PBMoveRoute::Graphic
route.list.push(RPG::MoveCommand.new(commands[i],
[commands[i+1],commands[i+2],commands[i+3],commands[i+4]]))
i += 4
else
route.list.push(RPG::MoveCommand.new(commands[i]))
end
i += 1
end
route.list.push(RPG::MoveCommand.new(PBMoveRoute::ThroughOff))
route.list.push(RPG::MoveCommand.new(0))
if event
event.force_move_route(route)
end
return route
end
def pbWait(numFrames)
numFrames.times do
Graphics.update
Input.update
pbUpdateSceneMap
end
end
#===============================================================================
# Player/event movement in the field
#===============================================================================
def pbLedge(_xOffset,_yOffset)
if PBTerrain.isLedge?(pbFacingTerrainTag)
if pbJumpToward(2,true)
$scene.spriteset.addUserAnimation(DUST_ANIMATION_ID,$game_player.x,$game_player.y,true,1)
$game_player.increase_steps
$game_player.check_event_trigger_here([1,2])
end
return true
end
return false
end
def pbSlideOnIce(event=nil)
event = $game_player if !event
return if !event
return if !PBTerrain.isIce?(pbGetTerrainTag(event))
$PokemonGlobal.sliding = true
direction = event.direction
oldwalkanime = event.walk_anime
event.straighten
event.walk_anime = false
loop do
break if !event.passable?(event.x,event.y,direction)
break if !PBTerrain.isIce?(pbGetTerrainTag(event))
event.move_forward
while event.moving?
Graphics.update
Input.update
pbUpdateSceneMap
end
end
event.center(event.x,event.y)
event.straighten
event.walk_anime = oldwalkanime
$PokemonGlobal.sliding = false
end
def pbTurnTowardEvent(event,otherEvent)
sx = 0; sy = 0
if $MapFactory
relativePos = $MapFactory.getThisAndOtherEventRelativePos(otherEvent,event)
sx = relativePos[0]
sy = relativePos[1]
else
sx = event.x - otherEvent.x
sy = event.y - otherEvent.y
end
return if sx == 0 and sy == 0
if sx.abs > sy.abs
(sx > 0) ? event.turn_left : event.turn_right
else
(sy > 0) ? event.turn_up : event.turn_down
end
end
def pbMoveTowardPlayer(event)
maxsize = [$game_map.width,$game_map.height].max
return if !pbEventCanReachPlayer?(event,$game_player,maxsize)
loop do
x = event.x
y = event.y
event.move_toward_player
break if event.x==x && event.y==y
while event.moving?
Graphics.update
Input.update
pbUpdateSceneMap
end
end
$PokemonMap.addMovedEvent(event.id) if $PokemonMap
end
def pbJumpToward(dist=1,playSound=false,cancelSurf=false)
x = $game_player.x
y = $game_player.y
case $game_player.direction
when 2; $game_player.jump(0,dist) # down
when 4; $game_player.jump(-dist,0) # left
when 6; $game_player.jump(dist,0) # right
when 8; $game_player.jump(0,-dist) # up
end
if $game_player.x!=x || $game_player.y!=y
pbSEPlay("Player jump") if playSound
$PokemonEncounters.clearStepCount if cancelSurf
$PokemonTemp.endSurf = true if cancelSurf
while $game_player.jumping?
Graphics.update
Input.update
pbUpdateSceneMap
end
return true
end
return false
end
#===============================================================================
# Fishing
#===============================================================================
def pbFishingBegin
$PokemonGlobal.fishing = true
if !pbCommonEvent(FISHING_BEGIN_COMMON_EVENT)
patternb = 2*$game_player.direction - 1
meta = pbGetMetadata(0,Metadata::PLAYER_A+$PokemonGlobal.playerID)
num = ($PokemonGlobal.surfing) ? 7 : 6
if meta && meta[num] && meta[num]!=""
charset = pbGetPlayerCharset(meta,num)
4.times do |pattern|
$game_player.setDefaultCharName(charset,patternb-pattern,true)
(Graphics.frame_rate/20).times do
Graphics.update
Input.update
pbUpdateSceneMap
end
end
end
end
end
def pbFishingEnd
if !pbCommonEvent(FISHING_END_COMMON_EVENT)
patternb = 2*($game_player.direction - 2)
meta = pbGetMetadata(0,Metadata::PLAYER_A+$PokemonGlobal.playerID)
num = ($PokemonGlobal.surfing) ? 7 : 6
if meta && meta[num] && meta[num]!=""
charset = pbGetPlayerCharset(meta,num)
4.times do |pattern|
$game_player.setDefaultCharName(charset,patternb+pattern,true)
(Graphics.frame_rate/20).times do
Graphics.update
Input.update
pbUpdateSceneMap
end
end
end
end
$PokemonGlobal.fishing = false
end
def pbFishing(hasEncounter,rodType=1)
speedup = ($Trainer.firstPokemon &&
(isConst?($Trainer.firstPokemon.ability,PBAbilities,:STICKYHOLD) ||
isConst?($Trainer.firstPokemon.ability,PBAbilities,:SUCTIONCUPS)))
biteChance = 20+(25*rodType) # 45, 70, 95
biteChance *= 1.5 if speedup # 67.5, 100, 100
hookChance = 100
oldpattern = $game_player.fullPattern
pbFishingBegin
msgWindow = pbCreateMessageWindow
ret = false
loop do
time = 5+rand(6)
time = [time,5+rand(6)].min if speedup
message = ""
time.times { message += ". " }
if pbWaitMessage(msgWindow,time)
pbFishingEnd
$game_player.setDefaultCharName(nil,oldpattern)
pbMessageDisplay(msgWindow,_INTL("Not even a nibble..."))
break
end
if hasEncounter && rand(100)<biteChance
$scene.spriteset.addUserAnimation(EXCLAMATION_ANIMATION_ID,$game_player.x,$game_player.y,true,3)
frames = Graphics.frame_rate - rand(Graphics.frame_rate/2) # 0.5-1 second
if !pbWaitForInput(msgWindow,message+_INTL("\r\nOh! A bite!"),frames)
pbFishingEnd
$game_player.setDefaultCharName(nil,oldpattern)
pbMessageDisplay(msgWindow,_INTL("The Pokémon got away..."))
break
end
if FISHING_AUTO_HOOK || rand(100)<hookChance
pbFishingEnd
pbMessageDisplay(msgWindow,_INTL("Landed a Pokémon!")) if !FISHING_AUTO_HOOK
$game_player.setDefaultCharName(nil,oldpattern)
ret = true
break
end
# biteChance += 15
# hookChance += 15
else
pbFishingEnd
$game_player.setDefaultCharName(nil,oldpattern)
pbMessageDisplay(msgWindow,_INTL("Not even a nibble..."))
break
end
end
pbDisposeMessageWindow(msgWindow)
return ret
end
# Show waiting dots before a Pokémon bites
def pbWaitMessage(msgWindow,time)
message = ""
periodTime = Graphics.frame_rate*4/10 # 0.4 seconds, 16 frames per dot
(time+1).times do |i|
message += ". " if i>0
pbMessageDisplay(msgWindow,message,false)
periodTime.times do
Graphics.update
Input.update
pbUpdateSceneMap
if Input.trigger?(Input::C) || Input.trigger?(Input::B)
return true
end
end
end
return false
end
# A Pokémon is biting, reflex test to reel it in
def pbWaitForInput(msgWindow,message,frames)
pbMessageDisplay(msgWindow,message,false)
numFrame = 0
twitchFrame = 0
twitchFrameTime = Graphics.frame_rate/10 # 0.1 seconds, 4 frames
loop do
Graphics.update
Input.update
pbUpdateSceneMap
# Twitch cycle: 1,0,1,0,0,0,0,0
twitchFrame = (twitchFrame+1)%(twitchFrameTime*8)
case twitchFrame%twitchFrameTime
when 0, 2
$game_player.pattern = 1
else
$game_player.pattern = 0
end
if Input.trigger?(Input::C) || Input.trigger?(Input::B)
$game_player.pattern = 0
return true
end
break if !FISHING_AUTO_HOOK && numFrame>frames
numFrame += 1
end
return false
end
#===============================================================================
# Bridges, cave escape points, and setting the heal point
#===============================================================================
def pbBridgeOn(height=2)
$PokemonGlobal.bridge = height
end
def pbBridgeOff
$PokemonGlobal.bridge = 0
end
def pbSetEscapePoint
$PokemonGlobal.escapePoint = [] if !$PokemonGlobal.escapePoint
xco = $game_player.x
yco = $game_player.y
case $game_player.direction
when 2; yco -= 1; dir = 8 # Down
when 4; xco += 1; dir = 6 # Left
when 6; xco -= 1; dir = 4 # Right
when 8; yco += 1; dir = 2 # Up
end
$PokemonGlobal.escapePoint = [$game_map.map_id,xco,yco,dir]
end
def pbEraseEscapePoint
$PokemonGlobal.escapePoint = []
end
def pbSetPokemonCenter
$PokemonGlobal.pokecenterMapId = $game_map.map_id
$PokemonGlobal.pokecenterX = $game_player.x
$PokemonGlobal.pokecenterY = $game_player.y
$PokemonGlobal.pokecenterDirection = $game_player.direction
end
#===============================================================================
# Partner trainer
#===============================================================================
def pbRegisterPartner(trainerid,trainername,partyid=0)
trainerid = getID(PBTrainers,trainerid)
pbCancelVehicles
trainer = pbLoadTrainer(trainerid,trainername,partyid)
Events.onTrainerPartyLoad.trigger(nil,trainer)
trainerobject = PokeBattle_Trainer.new(_INTL(trainer[0].name),trainerid)
trainerobject.setForeignID($Trainer)
for i in trainer[2]
i.owner = Pokemon::Owner.new_from_trainer(trainerobject)
i.calcStats
end
$PokemonGlobal.partner = [trainerid,trainerobject.name,trainerobject.id,trainer[2]]
end
def pbDeregisterPartner
$PokemonGlobal.partner = nil
end
#===============================================================================
# Event locations, terrain tags
#===============================================================================
@@ -1222,7 +828,7 @@ def pbCueBGM(bgm,seconds,volume=nil,pitch=nil)
end
def pbAutoplayOnTransition
surfbgm = pbGetMetadata(0,Metadata::SURF_BGM)
surfbgm = pbGetMetadata(0,MetadataSurfBGM)
if $PokemonGlobal.surfing && surfbgm
pbBGMPlay(surfbgm)
else
@@ -1231,7 +837,7 @@ def pbAutoplayOnTransition
end
def pbAutoplayOnSave
surfbgm = pbGetMetadata(0,Metadata::SURF_BGM)
surfbgm = pbGetMetadata(0,MetadataSurfBGM)
if $PokemonGlobal.surfing && surfbgm
pbBGMPlay(surfbgm)
else
@@ -1309,6 +915,412 @@ end
#===============================================================================
# Event movement
#===============================================================================
module PBMoveRoute
Down = 1
Left = 2
Right = 3
Up = 4
LowerLeft = 5
LowerRight = 6
UpperLeft = 7
UpperRight = 8
Random = 9
TowardPlayer = 10
AwayFromPlayer = 11
Forward = 12
Backward = 13
Jump = 14 # xoffset, yoffset
Wait = 15 # frames
TurnDown = 16
TurnLeft = 17
TurnRight = 18
TurnUp = 19
TurnRight90 = 20
TurnLeft90 = 21
Turn180 = 22
TurnRightOrLeft90 = 23
TurnRandom = 24
TurnTowardPlayer = 25
TurnAwayFromPlayer = 26
SwitchOn = 27 # 1 param
SwitchOff = 28 # 1 param
ChangeSpeed = 29 # 1 param
ChangeFreq = 30 # 1 param
WalkAnimeOn = 31
WalkAnimeOff = 32
StepAnimeOn = 33
StepAnimeOff = 34
DirectionFixOn = 35
DirectionFixOff = 36
ThroughOn = 37
ThroughOff = 38
AlwaysOnTopOn = 39
AlwaysOnTopOff = 40
Graphic = 41 # Name, hue, direction, pattern
Opacity = 42 # 1 param
Blending = 43 # 1 param
PlaySE = 44 # 1 param
Script = 45 # 1 param
ScriptAsync = 101 # 1 param
end
def pbMoveRoute(event,commands,waitComplete=false)
route = RPG::MoveRoute.new
route.repeat = false
route.skippable = true
route.list.clear
route.list.push(RPG::MoveCommand.new(PBMoveRoute::ThroughOn))
i=0
while i<commands.length
case commands[i]
when PBMoveRoute::Wait, PBMoveRoute::SwitchOn, PBMoveRoute::SwitchOff,
PBMoveRoute::ChangeSpeed, PBMoveRoute::ChangeFreq, PBMoveRoute::Opacity,
PBMoveRoute::Blending, PBMoveRoute::PlaySE, PBMoveRoute::Script
route.list.push(RPG::MoveCommand.new(commands[i],[commands[i+1]]))
i += 1
when PBMoveRoute::ScriptAsync
route.list.push(RPG::MoveCommand.new(PBMoveRoute::Script,[commands[i+1]]))
route.list.push(RPG::MoveCommand.new(PBMoveRoute::Wait,[0]))
i += 1
when PBMoveRoute::Jump
route.list.push(RPG::MoveCommand.new(commands[i],[commands[i+1],commands[i+2]]))
i += 2
when PBMoveRoute::Graphic
route.list.push(RPG::MoveCommand.new(commands[i],
[commands[i+1],commands[i+2],commands[i+3],commands[i+4]]))
i += 4
else
route.list.push(RPG::MoveCommand.new(commands[i]))
end
i += 1
end
route.list.push(RPG::MoveCommand.new(PBMoveRoute::ThroughOff))
route.list.push(RPG::MoveCommand.new(0))
if event
event.force_move_route(route)
end
return route
end
def pbWait(numFrames)
numFrames.times do
Graphics.update
Input.update
pbUpdateSceneMap
end
end
#===============================================================================
# Player/event movement in the field
#===============================================================================
def pbLedge(_xOffset,_yOffset)
if PBTerrain.isLedge?(pbFacingTerrainTag)
if pbJumpToward(2,true)
$scene.spriteset.addUserAnimation(DUST_ANIMATION_ID,$game_player.x,$game_player.y,true,1)
$game_player.increase_steps
$game_player.check_event_trigger_here([1,2])
end
return true
end
return false
end
def pbSlideOnIce(event=nil)
event = $game_player if !event
return if !event
return if !PBTerrain.isIce?(pbGetTerrainTag(event))
$PokemonGlobal.sliding = true
direction = event.direction
oldwalkanime = event.walk_anime
event.straighten
event.walk_anime = false
loop do
break if !event.passable?(event.x,event.y,direction)
break if !PBTerrain.isIce?(pbGetTerrainTag(event))
event.move_forward
while event.moving?
Graphics.update
Input.update
pbUpdateSceneMap
end
end
event.center(event.x,event.y)
event.straighten
event.walk_anime = oldwalkanime
$PokemonGlobal.sliding = false
end
def pbTurnTowardEvent(event,otherEvent)
sx = 0; sy = 0
if $MapFactory
relativePos = $MapFactory.getThisAndOtherEventRelativePos(otherEvent,event)
sx = relativePos[0]
sy = relativePos[1]
else
sx = event.x - otherEvent.x
sy = event.y - otherEvent.y
end
return if sx == 0 and sy == 0
if sx.abs > sy.abs
(sx > 0) ? event.turn_left : event.turn_right
else
(sy > 0) ? event.turn_up : event.turn_down
end
end
def pbMoveTowardPlayer(event)
maxsize = [$game_map.width,$game_map.height].max
return if !pbEventCanReachPlayer?(event,$game_player,maxsize)
loop do
x = event.x
y = event.y
event.move_toward_player
break if event.x==x && event.y==y
while event.moving?
Graphics.update
Input.update
pbUpdateSceneMap
end
end
$PokemonMap.addMovedEvent(event.id) if $PokemonMap
end
def pbJumpToward(dist=1,playSound=false,cancelSurf=false)
x = $game_player.x
y = $game_player.y
case $game_player.direction
when 2; $game_player.jump(0,dist) # down
when 4; $game_player.jump(-dist,0) # left
when 6; $game_player.jump(dist,0) # right
when 8; $game_player.jump(0,-dist) # up
end
if $game_player.x!=x || $game_player.y!=y
pbSEPlay("Player jump") if playSound
$PokemonEncounters.clearStepCount if cancelSurf
$PokemonTemp.endSurf = true if cancelSurf
while $game_player.jumping?
Graphics.update
Input.update
pbUpdateSceneMap
end
return true
end
return false
end
#===============================================================================
# Fishing
#===============================================================================
def pbFishingBegin
$PokemonGlobal.fishing = true
if !pbCommonEvent(FISHING_BEGIN_COMMON_EVENT)
patternb = 2*$game_player.direction - 1
meta = pbGetMetadata(0,MetadataPlayerA+$PokemonGlobal.playerID)
num = ($PokemonGlobal.surfing) ? 7 : 6
if meta && meta[num] && meta[num]!=""
charset = pbGetPlayerCharset(meta,num)
4.times do |pattern|
$game_player.setDefaultCharName(charset,patternb-pattern,true)
(Graphics.frame_rate/20).times do
Graphics.update
Input.update
pbUpdateSceneMap
end
end
end
end
end
def pbFishingEnd
if !pbCommonEvent(FISHING_END_COMMON_EVENT)
patternb = 2*($game_player.direction - 2)
meta = pbGetMetadata(0,MetadataPlayerA+$PokemonGlobal.playerID)
num = ($PokemonGlobal.surfing) ? 7 : 6
if meta && meta[num] && meta[num]!=""
charset = pbGetPlayerCharset(meta,num)
4.times do |pattern|
$game_player.setDefaultCharName(charset,patternb+pattern,true)
(Graphics.frame_rate/20).times do
Graphics.update
Input.update
pbUpdateSceneMap
end
end
end
end
$PokemonGlobal.fishing = false
end
def pbFishing(hasEncounter,rodType=1)
speedup = ($Trainer.firstPokemon &&
(isConst?($Trainer.firstPokemon.ability,PBAbilities,:STICKYHOLD) ||
isConst?($Trainer.firstPokemon.ability,PBAbilities,:SUCTIONCUPS)))
biteChance = 20+(25*rodType) # 45, 70, 95
biteChance *= 1.5 if speedup # 67.5, 100, 100
hookChance = 100
oldpattern = $game_player.fullPattern
pbFishingBegin
msgWindow = pbCreateMessageWindow
ret = false
loop do
time = 5+rand(6)
time = [time,5+rand(6)].min if speedup
message = ""
time.times { message += ". " }
if pbWaitMessage(msgWindow,time)
pbFishingEnd
$game_player.setDefaultCharName(nil,oldpattern)
pbMessageDisplay(msgWindow,_INTL("Not even a nibble..."))
break
end
if hasEncounter && rand(100)<biteChance
$scene.spriteset.addUserAnimation(EXCLAMATION_ANIMATION_ID,$game_player.x,$game_player.y,true,3)
frames = Graphics.frame_rate - rand(Graphics.frame_rate/2) # 0.5-1 second
if !pbWaitForInput(msgWindow,message+_INTL("\r\nOh! A bite!"),frames)
pbFishingEnd
$game_player.setDefaultCharName(nil,oldpattern)
pbMessageDisplay(msgWindow,_INTL("The Pokémon got away..."))
break
end
if FISHING_AUTO_HOOK || rand(100)<hookChance
pbFishingEnd
pbMessageDisplay(msgWindow,_INTL("Landed a Pokémon!")) if !FISHING_AUTO_HOOK
$game_player.setDefaultCharName(nil,oldpattern)
ret = true
break
end
# biteChance += 15
# hookChance += 15
else
pbFishingEnd
$game_player.setDefaultCharName(nil,oldpattern)
pbMessageDisplay(msgWindow,_INTL("Not even a nibble..."))
break
end
end
pbDisposeMessageWindow(msgWindow)
return ret
end
# Show waiting dots before a Pokémon bites
def pbWaitMessage(msgWindow,time)
message = ""
periodTime = Graphics.frame_rate*4/10 # 0.4 seconds, 16 frames per dot
(time+1).times do |i|
message += ". " if i>0
pbMessageDisplay(msgWindow,message,false)
periodTime.times do
Graphics.update
Input.update
pbUpdateSceneMap
if Input.trigger?(Input::C) || Input.trigger?(Input::B)
return true
end
end
end
return false
end
# A Pokémon is biting, reflex test to reel it in
def pbWaitForInput(msgWindow,message,frames)
pbMessageDisplay(msgWindow,message,false)
numFrame = 0
twitchFrame = 0
twitchFrameTime = Graphics.frame_rate/10 # 0.1 seconds, 4 frames
loop do
Graphics.update
Input.update
pbUpdateSceneMap
# Twitch cycle: 1,0,1,0,0,0,0,0
twitchFrame = (twitchFrame+1)%(twitchFrameTime*8)
case twitchFrame%twitchFrameTime
when 0, 2
$game_player.pattern = 1
else
$game_player.pattern = 0
end
if Input.trigger?(Input::C) || Input.trigger?(Input::B)
$game_player.pattern = 0
return true
end
break if !FISHING_AUTO_HOOK && numFrame>frames
numFrame += 1
end
return false
end
#===============================================================================
# Bridges, cave escape points, and setting the heal point
#===============================================================================
def pbBridgeOn(height=2)
$PokemonGlobal.bridge = height
end
def pbBridgeOff
$PokemonGlobal.bridge = 0
end
def pbSetEscapePoint
$PokemonGlobal.escapePoint = [] if !$PokemonGlobal.escapePoint
xco = $game_player.x
yco = $game_player.y
case $game_player.direction
when 2; yco -= 1; dir = 8 # Down
when 4; xco += 1; dir = 6 # Left
when 6; xco -= 1; dir = 4 # Right
when 8; yco += 1; dir = 2 # Up
end
$PokemonGlobal.escapePoint = [$game_map.map_id,xco,yco,dir]
end
def pbEraseEscapePoint
$PokemonGlobal.escapePoint = []
end
def pbSetPokemonCenter
$PokemonGlobal.pokecenterMapId = $game_map.map_id
$PokemonGlobal.pokecenterX = $game_player.x
$PokemonGlobal.pokecenterY = $game_player.y
$PokemonGlobal.pokecenterDirection = $game_player.direction
end
#===============================================================================
# Partner trainer
#===============================================================================
def pbRegisterPartner(trainerid,trainername,partyid=0)
trainerid = getID(PBTrainers,trainerid)
pbCancelVehicles
trainer = pbLoadTrainer(trainerid,trainername,partyid)
Events.onTrainerPartyLoad.trigger(nil,trainer)
trainerobject = PokeBattle_Trainer.new(_INTL(trainer[0].name),trainerid)
trainerobject.setForeignID($Trainer)
for i in trainer[2]
i.trainerID = trainerobject.id
i.ot = trainerobject.name
i.calcStats
end
$PokemonGlobal.partner = [trainerid,trainerobject.name,trainerobject.id,trainer[2]]
end
def pbDeregisterPartner
$PokemonGlobal.partner = nil
end
#===============================================================================
# Picking up an item found on the ground
#===============================================================================

View File

@@ -1,227 +1,3 @@
#===============================================================================
# Location signpost
#===============================================================================
class LocationWindow
def initialize(name)
@window = Window_AdvancedTextPokemon.new(name)
@window.resizeToFit(name,Graphics.width)
@window.x = 0
@window.y = -@window.height
@window.viewport = Viewport.new(0,0,Graphics.width,Graphics.height)
@window.viewport.z = 99999
@currentmap = $game_map.map_id
@frames = 0
end
def disposed?
@window.disposed?
end
def dispose
@window.dispose
end
def update
return if @window.disposed?
@window.update
if $game_temp.message_window_showing || @currentmap!=$game_map.map_id
@window.dispose
return
end
if @frames>80
@window.y -= 4
@window.dispose if @window.y+@window.height<0
else
@window.y += 4 if @window.y<0
@frames += 1
end
end
end
#===============================================================================
# Visibility circle in dark maps
#===============================================================================
class DarknessSprite < SpriteWrapper
attr_reader :radius
def initialize(viewport=nil)
super(viewport)
@darkness = BitmapWrapper.new(Graphics.width,Graphics.height)
@radius = radiusMin
self.bitmap = @darkness
self.z = 99998
refresh
end
def dispose
@darkness.dispose
super
end
def radiusMin; return 64; end # Before using Flash
def radiusMax; return 176; end # After using Flash
def radius=(value)
@radius = value
refresh
end
def refresh
@darkness.fill_rect(0,0,Graphics.width,Graphics.height,Color.new(0,0,0,255))
cx = Graphics.width/2
cy = Graphics.height/2
cradius = @radius
numfades = 5
for i in 1..numfades
for j in cx-cradius..cx+cradius
diff2 = (cradius * cradius) - ((j - cx) * (j - cx))
diff = Math.sqrt(diff2)
@darkness.fill_rect(j,cy-diff,1,diff*2,Color.new(0,0,0,255.0*(numfades-i)/numfades))
end
cradius = (cradius*0.9).floor
end
end
end
#===============================================================================
# Lights
#===============================================================================
class LightEffect
def initialize(event,viewport=nil,map=nil,filename=nil)
@light = IconSprite.new(0,0,viewport)
if filename!=nil && filename!="" && pbResolveBitmap("Graphics/Pictures/"+filename)
@light.setBitmap("Graphics/Pictures/"+filename)
else
@light.setBitmap("Graphics/Pictures/LE")
end
@light.z = 1000
@event = event
@map = (map) ? map : $game_map
@disposed = false
end
def disposed?
return @disposed
end
def dispose
@light.dispose
@map = nil
@event = nil
@disposed = true
end
def update
@light.update
end
end
class LightEffect_Lamp < LightEffect
def initialize(event,viewport=nil,map=nil)
lamp = AnimatedBitmap.new("Graphics/Pictures/LE")
@light = Sprite.new(viewport)
@light.bitmap = Bitmap.new(128,64)
src_rect = Rect.new(0, 0, 64, 64)
@light.bitmap.blt(0, 0, lamp.bitmap, src_rect)
@light.bitmap.blt(20, 0, lamp.bitmap, src_rect)
@light.visible = true
@light.z = 1000
lamp.dispose
@map = (map) ? map : $game_map
@event = event
end
end
class LightEffect_Basic < LightEffect
def update
return if !@light || !@event
super
@light.opacity = 100
@light.ox = 32
@light.oy = 48
if (Object.const_defined?(:ScreenPosHelper) rescue false)
@light.x = ScreenPosHelper.pbScreenX(@event)
@light.y = ScreenPosHelper.pbScreenY(@event)
@light.zoom_x = ScreenPosHelper.pbScreenZoomX(@event)
else
@light.x = @event.screen_x
@light.y = @event.screen_y
@light.zoom_x = 1.0
end
@light.zoom_y = @light.zoom_x
@light.tone = $game_screen.tone
end
end
class LightEffect_DayNight < LightEffect
def update
return if !@light || !@event
super
shade = PBDayNight.getShade
if shade>=144 # If light enough, call it fully day
shade = 255
elsif shade<=64 # If dark enough, call it fully night
shade = 0
else
shade = 255-(255*(144-shade)/(144-64))
end
@light.opacity = 255-shade
if @light.opacity>0
@light.ox = 32
@light.oy = 48
if (Object.const_defined?(:ScreenPosHelper) rescue false)
@light.x = ScreenPosHelper.pbScreenX(@event)
@light.y = ScreenPosHelper.pbScreenY(@event)
@light.zoom_x = ScreenPosHelper.pbScreenZoomX(@event)
@light.zoom_y = ScreenPosHelper.pbScreenZoomY(@event)
else
@light.x = @event.screen_x
@light.y = @event.screen_y
@light.zoom_x = 1.0
@light.zoom_y = 1.0
end
@light.tone.set($game_screen.tone.red,
$game_screen.tone.green,
$game_screen.tone.blue,
$game_screen.tone.gray)
end
end
end
Events.onSpritesetCreate += proc { |_sender,e|
spriteset = e[0] # Spriteset being created
viewport = e[1] # Viewport used for tilemap and characters
map = spriteset.map # Map associated with the spriteset (not necessarily the current map)
for i in map.events.keys
if map.events[i].name[/^outdoorlight\((\w+)\)$/i]
filename = $~[1].to_s
spriteset.addUserSprite(LightEffect_DayNight.new(map.events[i],viewport,map,filename))
elsif map.events[i].name.downcase=="outdoorlight"
spriteset.addUserSprite(LightEffect_DayNight.new(map.events[i],viewport,map))
elsif map.events[i].name[/^light\((\w+)\)$/i]
filename = $~[1].to_s
spriteset.addUserSprite(LightEffect_Basic.new(map.events[i],viewport,map,filename))
elsif map.events[i].name.downcase=="light"
spriteset.addUserSprite(LightEffect_Basic.new(map.events[i],viewport,map))
end
end
spriteset.addUserSprite(Particle_Engine.new(viewport,map))
}
#===============================================================================
# Battle start animation
#===============================================================================
@@ -540,6 +316,231 @@ def pbBattleAnimationOverride(viewport,battletype=0,foe=nil)
end
#===============================================================================
# Location signpost
#===============================================================================
class LocationWindow
def initialize(name)
@window = Window_AdvancedTextPokemon.new(name)
@window.resizeToFit(name,Graphics.width)
@window.x = 0
@window.y = -@window.height
@window.viewport = Viewport.new(0,0,Graphics.width,Graphics.height)
@window.viewport.z = 99999
@currentmap = $game_map.map_id
@frames = 0
end
def disposed?
@window.disposed?
end
def dispose
@window.dispose
end
def update
return if @window.disposed?
@window.update
if $game_temp.message_window_showing || @currentmap!=$game_map.map_id
@window.dispose
return
end
if @frames>80
@window.y -= 4
@window.dispose if @window.y+@window.height<0
else
@window.y += 4 if @window.y<0
@frames += 1
end
end
end
#===============================================================================
# Visibility circle in dark maps
#===============================================================================
class DarknessSprite < SpriteWrapper
attr_reader :radius
def initialize(viewport=nil)
super(viewport)
@darkness = BitmapWrapper.new(Graphics.width,Graphics.height)
@radius = radiusMin
self.bitmap = @darkness
self.z = 99998
refresh
end
def dispose
@darkness.dispose
super
end
def radiusMin; return 64; end # Before using Flash
def radiusMax; return 176; end # After using Flash
def radius=(value)
@radius = value
refresh
end
def refresh
@darkness.fill_rect(0,0,Graphics.width,Graphics.height,Color.new(0,0,0,255))
cx = Graphics.width/2
cy = Graphics.height/2
cradius = @radius
numfades = 5
for i in 1..numfades
for j in cx-cradius..cx+cradius
diff2 = (cradius * cradius) - ((j - cx) * (j - cx))
diff = Math.sqrt(diff2)
@darkness.fill_rect(j,cy-diff,1,diff*2,Color.new(0,0,0,255.0*(numfades-i)/numfades))
end
cradius = (cradius*0.9).floor
end
end
end
#===============================================================================
# Lights
#===============================================================================
class LightEffect
def initialize(event,viewport=nil,map=nil,filename=nil)
@light = IconSprite.new(0,0,viewport)
if filename!=nil && filename!="" && pbResolveBitmap("Graphics/Pictures/"+filename)
@light.setBitmap("Graphics/Pictures/"+filename)
else
@light.setBitmap("Graphics/Pictures/LE")
end
@light.z = 1000
@event = event
@map = (map) ? map : $game_map
@disposed = false
end
def disposed?
return @disposed
end
def dispose
@light.dispose
@map = nil
@event = nil
@disposed = true
end
def update
@light.update
end
end
class LightEffect_Lamp < LightEffect
def initialize(event,viewport=nil,map=nil)
lamp = AnimatedBitmap.new("Graphics/Pictures/LE")
@light = Sprite.new(viewport)
@light.bitmap = Bitmap.new(128,64)
src_rect = Rect.new(0, 0, 64, 64)
@light.bitmap.blt(0, 0, lamp.bitmap, src_rect)
@light.bitmap.blt(20, 0, lamp.bitmap, src_rect)
@light.visible = true
@light.z = 1000
lamp.dispose
@map = (map) ? map : $game_map
@event = event
end
end
class LightEffect_Basic < LightEffect
def update
return if !@light || !@event
super
@light.opacity = 100
@light.ox = 32
@light.oy = 48
if (Object.const_defined?(:ScreenPosHelper) rescue false)
@light.x = ScreenPosHelper.pbScreenX(@event)
@light.y = ScreenPosHelper.pbScreenY(@event)
@light.zoom_x = ScreenPosHelper.pbScreenZoomX(@event)
else
@light.x = @event.screen_x
@light.y = @event.screen_y
@light.zoom_x = 1.0
end
@light.zoom_y = @light.zoom_x
@light.tone = $game_screen.tone
end
end
class LightEffect_DayNight < LightEffect
def update
return if !@light || !@event
super
shade = PBDayNight.getShade
if shade>=144 # If light enough, call it fully day
shade = 255
elsif shade<=64 # If dark enough, call it fully night
shade = 0
else
shade = 255-(255*(144-shade)/(144-64))
end
@light.opacity = 255-shade
if @light.opacity>0
@light.ox = 32
@light.oy = 48
if (Object.const_defined?(:ScreenPosHelper) rescue false)
@light.x = ScreenPosHelper.pbScreenX(@event)
@light.y = ScreenPosHelper.pbScreenY(@event)
@light.zoom_x = ScreenPosHelper.pbScreenZoomX(@event)
@light.zoom_y = ScreenPosHelper.pbScreenZoomY(@event)
else
@light.x = @event.screen_x
@light.y = @event.screen_y
@light.zoom_x = 1.0
@light.zoom_y = 1.0
end
@light.tone.set($game_screen.tone.red,
$game_screen.tone.green,
$game_screen.tone.blue,
$game_screen.tone.gray)
end
end
end
Events.onSpritesetCreate += proc { |_sender,e|
spriteset = e[0] # Spriteset being created
viewport = e[1] # Viewport used for tilemap and characters
map = spriteset.map # Map associated with the spriteset (not necessarily the current map)
for i in map.events.keys
if map.events[i].name[/^outdoorlight\((\w+)\)$/i]
filename = $~[1].to_s
spriteset.addUserSprite(LightEffect_DayNight.new(map.events[i],viewport,map,filename))
elsif map.events[i].name.downcase=="outdoorlight"
spriteset.addUserSprite(LightEffect_DayNight.new(map.events[i],viewport,map))
elsif map.events[i].name[/^light\((\w+)\)$/i]
filename = $~[1].to_s
spriteset.addUserSprite(LightEffect_Basic.new(map.events[i],viewport,map,filename))
elsif map.events[i].name.downcase=="light"
spriteset.addUserSprite(LightEffect_Basic.new(map.events[i],viewport,map))
end
end
spriteset.addUserSprite(Particle_Engine.new(viewport,map))
}
#===============================================================================
# Entering/exiting cave animations
#===============================================================================

View File

@@ -34,8 +34,8 @@ class PokemonTemp
when "canrun"; rules["canRun"] = true
when "cannotrun"; rules["canRun"] = false
when "roamerflees"; rules["roamerFlees"] = true
when "noExp"; rules["expGain"] = false
when "noMoney"; rules["moneyGain"] = false
when "noexp"; rules["expGain"] = false
when "nomoney"; rules["moneyGain"] = false
when "switchstyle"; rules["switchStyle"] = true
when "setstyle"; rules["switchStyle"] = false
when "anims"; rules["battleAnims"] = true
@@ -45,7 +45,7 @@ class PokemonTemp
when "environment", "environ"; rules["environment"] = getID(PBEnvironment,var)
when "backdrop", "battleback"; rules["backdrop"] = var
when "base"; rules["base"] = var
when "outcomevar", "outcome"; rules["outcomeVar"] = var
when "outcome", "outcomevar"; rules["outcomeVar"] = var
when "nopartner"; rules["noPartner"] = true
else
raise _INTL("Battle rule \"{1}\" does not exist.",rule)
@@ -64,7 +64,7 @@ def setBattleRule(*args)
else
case arg.downcase
when "terrain", "weather", "environment", "environ", "backdrop",
"battleback", "base", "outcomevar", "outcome"
"battleback", "base", "outcome", "outcomevar"
r = arg
next
end

View File

@@ -241,6 +241,6 @@ def pbRoamingPokemonBattle(species, level)
return (decision!=2 && decision!=5)
end
EncounterModifier.registerEncounterEnd(proc{
EncounterModifier.registerEncounterEnd(proc {
$PokemonTemp.roamerIndex = nil
})