Enabled BallBurst common animations to be played during other battle animations

This commit is contained in:
Maruno17
2022-02-22 19:26:50 +00:00
parent 2057084f69
commit e5be233224
5 changed files with 73 additions and 12 deletions

View File

@@ -125,7 +125,7 @@ class PictureEx
when Proc
cb.call(self)
when Array
cb[0].method(cb[1]).call(self)
cb[0].method(cb[1]).call(self, *cb[2])
when Method
cb.call(self)
end

View File

@@ -163,7 +163,7 @@ class Battle::Scene
def pbRecall(idxBattler)
@briefMessage = false
# Recall animation
recallAnim = Animation::BattlerRecall.new(@sprites, @viewport, idxBattler)
recallAnim = Animation::BattlerRecall.new(@sprites, @viewport, @battle.battlers[idxBattler])
loop do
recallAnim&.update
pbUpdate
@@ -564,4 +564,18 @@ class Battle::Scene
targetSprite.pbSetOrigin
end
end
# Ball burst common animations should have a focus of "Target" and a priority
# of "Front".
def pbBallBurstCommonAnimation(_picture_ex, anim_name, battler, target_x, target_y)
return if nil_or_empty?(anim_name)
animations = pbLoadBattleAnimations
anim = animations&.get_from_name("Common:" + anim_name)
return if !anim
animPlayer = PBAnimationPlayerX.new(anim, battler, nil, self)
animPlayer.discard_user_and_target_sprites # Don't involve user/target in animation
animPlayer.set_target_origin(target_x, target_y)
animPlayer.start
@animations.push(animPlayer)
end
end

View File

@@ -85,6 +85,30 @@ module Battle::Scene::Animation::BallAnimationMixin
return Color.new(255, 181, 247) # Poké Ball, Sport Ball, Apricorn Balls, others
end
# There are three kinds of animations shown when a Poké Ball opens up: one for
# when attempting to capture a Pokémon, one when recalling a Pokémon, and one
# for all other cases (e.g. sending out). This is anim_type (one of :capture,
# :recall and :main). The recall animation is the same for all Poké Balls, and
# the other two animations are different for each Poké Ball.
def getBallBurstAnimationName(poke_ball, anim_type = :main)
animations = pbLoadBattleAnimations
if anim_type == :recall
anim_name = "BallBurstRecall"
return anim_name if animations&.get_from_name("Common:" + anim_name)
else
name = poke_ball.to_s
if anim_type == :capture
anim = animations&.get_from_name("Common:BallBurstCapture" + name)
return "BallBurstCapture" + name if anim
anim = animations&.get_from_name("Common:BallBurstCapture")
return "BallBurstCapture" if anim
end
anim = animations&.get_from_name("Common:BallBurst" + name)
return "BallBurst" + name if anim
end
return "BallBurst"
end
def addBallSprite(ballX, ballY, poke_ball)
file_path = sprintf("Graphics/Battle animations/ball_%s", poke_ball)
ball = addNewSprite(ballX, ballY, file_path, PictureOrigin::CENTER)
@@ -249,12 +273,16 @@ module Battle::Scene::Animation::BallAnimationMixin
end
# The regular Poké Ball burst animation.
def ballBurst(delay, ballX, ballY, poke_ball)
def ballBurst(delay, ball, ballX, ballY, poke_ball)
ball.setDelta(delay, 0, 0, [@battler.battle.scene, :pbBallBurstCommonAnimation,
[getBallBurstAnimationName(poke_ball), @battler, ballX, ballY]])
end
# The Poké Ball burst animation used when absorbing a wild Pokémon during a
# capture attempt.
def ballBurstCapture(delay, ballX, ballY, poke_ball)
def ballBurstCapture(delay, ball, ballX, ballY, poke_ball)
ball.setDelta(delay, 0, 0, [@battler.battle.scene, :pbBallBurstCommonAnimation,
[getBallBurstAnimationName(poke_ball, :capture), @battler, ballX, ballY]])
end
def ballCaptureSuccess(ball, delay, ballX, ballY)
@@ -263,6 +291,8 @@ module Battle::Scene::Animation::BallAnimationMixin
end
# The Poké Ball burst animation used when recalling a Pokémon.
def ballBurstRecall(delay, ballX, ballY, poke_ball)
def ballBurstRecall(delay, ball, ballX, ballY, poke_ball)
ball.setDelta(delay, 0, 0, [@battler.battle.scene, :pbBallBurstCommonAnimation,
[getBallBurstAnimationName(poke_ball, :recall), @battler, ballX, ballY]])
end
end

View File

@@ -453,7 +453,7 @@ class Battle::Scene::Animation::PokeballPlayerSendOut < Battle::Scene::Animation
delay = ball.totalDuration + 4
delay += 10 * @idxOrder # Stagger appearances if multiple Pokémon are sent out at once
ballOpenUp(ball, delay - 2, poke_ball)
ballBurst(delay, battlerStartX, battlerStartY - 18, poke_ball)
ballBurst(delay, ball, battlerStartX, battlerStartY - 18, poke_ball)
ball.moveOpacity(delay + 2, 2, 0)
# Set up battler sprite
battler = addSprite(batSprite, PictureOrigin::BOTTOM)
@@ -517,7 +517,7 @@ class Battle::Scene::Animation::PokeballTrainerSendOut < Battle::Scene::Animatio
delay += 10 if @showingTrainer # Give time for trainer to slide off screen
delay += 10 * @idxOrder # Stagger appearances if multiple Pokémon are sent out at once
ballOpenUp(ball, delay - 2, poke_ball)
ballBurst(delay, battlerStartX, battlerStartY - 18, poke_ball)
ballBurst(delay, ball, battlerStartX, battlerStartY - 18, poke_ball)
ball.moveOpacity(delay + 2, 2, 0)
# Set up battler sprite
battler = addSprite(batSprite, PictureOrigin::BOTTOM)
@@ -552,8 +552,9 @@ end
class Battle::Scene::Animation::BattlerRecall < Battle::Scene::Animation
include Battle::Scene::Animation::BallAnimationMixin
def initialize(sprites, viewport, idxBattler)
@idxBattler = idxBattler
def initialize(sprites, viewport, battler)
@battler = battler
@idxBattler = battler.index
super(sprites, viewport)
end
@@ -579,7 +580,7 @@ class Battle::Scene::Animation::BattlerRecall < Battle::Scene::Animation
# Poké Ball animation
ballOpenUp(ball, 0, poke_ball)
delay = ball.totalDuration
ballBurstRecall(delay, battlerEndX, battlerEndY, poke_ball)
ballBurstRecall(delay, ball, battlerEndX, battlerEndY, poke_ball)
ball.moveOpacity(10, 2, 0)
# Battler animation
battlerAbsorb(battler, delay, battlerEndX, battlerEndY, col)
@@ -741,7 +742,7 @@ class Battle::Scene::Animation::PokeballThrowCapture < Battle::Scene::Animation
battler = addSprite(batSprite, PictureOrigin::BOTTOM)
# Poké Ball absorbs battler
delay = ball.totalDuration
ballBurstCapture(delay, ballEndX, ballEndY, @poke_ball)
ballBurstCapture(delay, ball, ballEndX, ballEndY, @poke_ball)
delay = ball.totalDuration + 4
# NOTE: The Pokémon does not change color while being absorbed into a Poké
# Ball during a capture attempt. This may be an oversight in HGSS.
@@ -808,7 +809,7 @@ class Battle::Scene::Animation::PokeballThrowCapture < Battle::Scene::Animation
# Poké Ball opens
ball.setZ(delay, batSprite.z - 1)
ballOpenUp(ball, delay, @poke_ball, false)
ballBurst(delay, ballEndX, ballGroundY, @poke_ball)
ballBurst(delay, ball, ballEndX, ballGroundY, @poke_ball)
ball.moveOpacity(delay + 2, 2, 0)
# Battler emerges
col = getBattlerColorFromPokeBall(@poke_ball)

View File

@@ -368,6 +368,11 @@ class PBAnimations < Array
@array[i] = value
end
def get_from_name(name)
@array.each { |i| return i if i&.name == name }
return nil
end
def compact
@array.compact!
end
@@ -751,6 +756,17 @@ class PBAnimationPlayerX
@foColor.dispose
end
# Makes the original user and target sprites be uninvolved with the animation.
# The animation shows just its particles.
def discard_user_and_target_sprites
@animsprites[0] = nil
@animsprites[1] = nil
end
def set_target_origin(x, y)
@targetOrig = [x, y]
end
def start
@frame = 0
end