Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Binary file not shown.
19 changes: 15 additions & 4 deletions Data/Scripts/004_Game classes/002_Game_System.rb
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ class Game_System
attr_accessor :autoscroll_x_speed
attr_accessor :autoscroll_y_speed
attr_accessor :bgm_position
attr_accessor :bgs_position
attr_accessor :paused_bgm

def initialize
@map_interpreter = Interpreter.new(0, true)
Expand All @@ -37,6 +39,7 @@ def initialize
@autoscroll_y_speed = 0
@bgm_position = 0
@bgs_position = 0
@paused_bgm = nil
end

################################################################################
Expand All @@ -59,16 +62,16 @@ def bgm_play_internal2(name,volume,pitch,position) # :nodoc:
end
end

def bgm_play_internal(bgm,position) # :nodoc:
@bgm_position = position if !@bgm_paused
def bgm_play_internal(bgm,position,unpausing=false) # :nodoc:
@bgm_position = position if !@bgm_paused || unpausing
@playing_bgm = (bgm==nil) ? nil : bgm.clone
if bgm!=nil && bgm.name!=""
if FileTest.audio_exist?("Audio/BGM/"+bgm.name)
bgm_play_internal2("Audio/BGM/"+bgm.name,
bgm.volume,bgm.pitch,@bgm_position) if !@defaultBGM
end
else
@bgm_position = position if !@bgm_paused
@bgm_position = position if !@bgm_paused || unpausing
@playing_bgm = nil
Audio.bgm_stop if !@defaultBGM
end
Expand All @@ -93,7 +96,7 @@ def bgm_unpause # :nodoc:

def bgm_resume(bgm) # :nodoc:
if @bgm_paused
self.bgm_play_internal(bgm,@bgm_position)
self.bgm_play_internal(bgm,@bgm_position,true)
@bgm_position = 0
@bgm_paused = false
end
Expand Down Expand Up @@ -129,6 +132,14 @@ def bgm_restore
def getPlayingBGM
return (@playing_bgm) ? @playing_bgm.clone : nil
end

def getPausedBGM
return (@paused_bgm) ? @paused_bgm.clone : nil
end

def setPausedBGM
@paused_bgm = (@paused_bgm) ? nil : @playing_bgm
end

def setDefaultBGM(bgm,volume=80,pitch=100)
bgm = RPG::AudioFile.new(bgm,volume,pitch) if bgm.is_a?(String)
Expand Down
17 changes: 10 additions & 7 deletions Data/Scripts/008_Audio/002_Audio_Play.rb
Original file line number Diff line number Diff line change
@@ -1,12 +1,15 @@
def pbStringToAudioFile(str)
if str[/^(.*)\:\s*(\d+)\s*\:\s*(\d+)\s*$/] # Of the format "XXX: ###: ###"
file = $1
volume = $2.to_i
pitch = $3.to_i
formatted = str.split(":")
if formatted.length == 3
# Of the format "XXX: ###: ###"
file = formatted[0]
volume = formatted[1].to_i
pitch = formatted[2].to_i
return RPG::AudioFile.new(file,volume,pitch)
elsif str[/^(.*)\:\s*(\d+)\s*$/] # Of the format "XXX: ###"
file = $1
volume = $2.to_i
elsif formatted.length == 2
# Of the format "XXX: ###"
file = formatted[0]
volume = formatted[1].to_i
return RPG::AudioFile.new(file,volume,100)
else
return RPG::AudioFile.new(str,100,100)
Expand Down
5 changes: 5 additions & 0 deletions Data/Scripts/011_Battle/001_Battler/001_PokeBattle_Battler.rb
Original file line number Diff line number Diff line change
Expand Up @@ -706,6 +706,11 @@ def pbOwnedByPlayer?
return @battle.pbOwnedByPlayer?(@index)
end

# Returns true if self has 25% or less hp
def isLowHp
return @hp > 0 && @hp <= (@totalhp / 4)
end

# Returns 0 if self is on the player's side, or 1 if self is on the opposing
# side.
def idxOwnSide
Expand Down
12 changes: 12 additions & 0 deletions Data/Scripts/011_Battle/001_Battler/007_Battler_UseMove.rb
Original file line number Diff line number Diff line change
Expand Up @@ -195,6 +195,8 @@ def pbUseMove(choice, specialUsage = false)
@lastRegularMoveUsed = nil
@lastRegularMoveTarget = -1
end
# Check if bgm needs to be switched
@battle.updateMusic()
@battle.pbGainExp # In case self is KO'd due to confusion
pbCancelMoves
pbEndTurn(choice)
Expand All @@ -212,6 +214,8 @@ def pbUseMove(choice, specialUsage = false)
@lastRegularMoveUsed = nil
@lastRegularMoveTarget = -1
@lastMoveFailed = true
# Check if bgm needs to be switched
@battle.updateMusic()
pbCancelMoves
pbEndTurn(choice)
return
Expand Down Expand Up @@ -289,6 +293,8 @@ def pbUseMove(choice, specialUsage = false)
@battle.pbDisplay(_INTL("{1} cannot use {2}!", user.pbThis, move.name))
@battle.pbHideAbilitySplash(b)
user.lastMoveFailed = true
# Check if bgm needs to be switched
@battle.updateMusic()
pbCancelMoves
pbEndTurn(choice)
return
Expand All @@ -309,6 +315,8 @@ def pbUseMove(choice, specialUsage = false)
if move.pbMoveFailed?(user, targets)
PBDebug.log(sprintf("[Move failed] In function code %s's def pbMoveFailed?", move.function))
user.lastMoveFailed = true
# Check if bgm needs to be switched
@battle.updateMusic()
pbCancelMoves
pbEndTurn(choice)
return
Expand Down Expand Up @@ -336,6 +344,8 @@ def pbUseMove(choice, specialUsage = false)
user.pbEffectsOnSwitchIn(true)
end
end
# Check if bgm needs to be switched
@battle.updateMusic()
pbCancelMoves
pbEndTurn(choice)
return
Expand Down Expand Up @@ -506,6 +516,8 @@ def pbUseMove(choice, specialUsage = false)
# External/general effects after all hits. Eject Button, Shell Bell, etc.
pbEffectsAfterMove(user, targets, move, realNumHits)
end
# Check if bgm needs to be switched
@battle.updateMusic()
# End effect of Mold Breaker
@battle.moldBreaker = false
# Gain Exp
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -234,6 +234,8 @@ def pbGainExpOne(idxParty, defeatedBattler, numPartic, expShare, expAll, showMes
pkmn.calc_stats
battler.pbUpdate(false) if battler
@scene.pbRefreshOne(battler.index) if battler
# Check if bgm needs to be switched
updateMusic()
pbDisplayPaused(_INTL("{1} grew to Lv. {2}!", pkmn.name, curLevel))
if !$game_switches[SWITCH_NO_LEVELS_MODE]
@scene.pbLevelUp(pkmn, battler, oldTotalHP, oldAttack, oldDefense,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -289,6 +289,8 @@ def pbReplace(idxBattler, idxParty, batonPass = false)
# Reorder the party for this battle
partyOrder = pbPartyOrder(idxBattler)
partyOrder[idxParty], partyOrder[idxPartyOld] = partyOrder[idxPartyOld], partyOrder[idxParty]
# Check if bgm needs to be switched
updateMusic()
# Send out the new Pokémon
pbSendOut([[idxBattler, party[idxParty]]])
pbCalculatePriority(false, [idxBattler]) if Settings::RECALCULATE_TURN_ORDER_AFTER_SPEED_CHANGES
Expand Down
33 changes: 33 additions & 0 deletions Data/Scripts/011_Battle/003_Battle/011_Battle_Phase_Attack.rb
Original file line number Diff line number Diff line change
Expand Up @@ -158,6 +158,39 @@ def pbAttackPhaseMoves
end
end

# Check the healthof every pokemon of the player in battle
# Switch to low health bgm if at least one of them has 25% or less hp
# Switch back to original battle bgm if all of them are above 25%
def updateMusic
pausedBGM = $game_system.getPausedBGM
hasLowHealthAlly = false

# Check for low health pokemon of the player
@battlers.each_with_index do |b,i|
if b.pbOwnedByPlayer? && b.isLowHp
hasLowHealthAlly = true
end
end

# Check if bgm should be switched to low health version
if pausedBGM == nil && hasLowHealthAlly
$game_system.setPausedBGM
$game_system.bgm_pause

pbBGMPlay("A Tight Spot During Battle (Low Health)")
end

# Check if bgm should be switched to original version
if pausedBGM && !hasLowHealthAlly
pbBGMFade()

$game_system.bgm_resume(pausedBGM)

# Reset paused bgm at the end
$game_system.setPausedBGM
end
end

#=============================================================================
# Attack phase
#=============================================================================
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -223,6 +223,8 @@ def pbHPChanged(battler,oldHP,showAnim=false)
while @sprites["dataBox_#{battler.index}"].animatingHP
pbUpdate
end
# Check if bgm needs to be switched
@battle.updateMusic()
end

def pbDamageAnimation(battler,effectiveness=0)
Expand Down