查看: 100|回复: 0

[转载发布] 战斗动画增强插件

[复制链接]
  • TA的每日心情
    开心
    5 天前
  • 签到天数: 33 天

    连续签到: 1 天

    [LV.5]常住居民I

    2022

    主题

    32

    回帖

    7144

    积分

    管理员

    Rank: 9Rank: 9Rank: 9

    VIP
    0
    卡币
    5074
    OK点
    16
    积分
    7144
    发表于 同元一千年八月七日(秋) | 显示全部楼层 |阅读模式
    即插即用型,可以允许在战斗中一个主回合放N个动画,自建RTAB引擎、技能连击特效适用

    RUBY 代码
    1. #==============================================================================
    2. # ■ 战斗动画增强 v1.0 by SailCat
    3. #------------------------------------------------------------------------------
    4. #   方法:本脚本插入到Main之前使用
    5. #   版本:v1.0 (Build 171125)
    6. #   效果:
    7. #     1. 允许战斗者在一个主回合中连续播放多个动画并显示多个伤害值
    8. #     2. 在所有动画和伤害值显示完毕以前,战斗者不会倒下
    9. #   配置:关于时间间隔的若干配置项
    10. #   冲突:其他动画增强脚本
    11. #   说明:
    12. #     每当需要让战斗者连续显示动画时,使用
    13. #     battler.pend_animation(动画ID, 伤害, 会心一击标志)   # 追加到动画的队尾
    14. #     battler.insert_animation(动画ID, 伤害, 会心一击标志) # 在当前动画后切入
    15. #     后两个参数可以省略,取自己的当前值,此外,还可使用
    16. #     battler.animation_id = 动画ID                        # 立即切入,队列顺延
    17. #==============================================================================
    18. #==============================================================================
    19. # ■ SailCat's 插件公用
    20. #==============================================================================
    21. module SailCat
    22.   $sailcat_import ||= {}
    23.   #--------------------------------------------------------------------------
    24.   # ● 植入
    25.   #--------------------------------------------------------------------------
    26.   $sailcat_import[:BattleAnimation] = 1.0
    27.   #--------------------------------------------------------------------------
    28.   # ● 脚本配置区
    29.   #--------------------------------------------------------------------------
    30.   module BattleAnimation_Config
    31.     AWAIT_HIT_INTERVAL = 0                # 每两次动画之间的间隔帧数
    32.     AWAIT_DAMAGE_INTERVAL = 8             # 每一击显示伤害的等待时间帧数
    33.     AWAIT_DAMAGE_FINAL = 8                # 播放完所有动画后的等待时间帧数
    34.   end
    35. end
    36. #==============================================================================
    37. # ■ Game_Battler
    38. #==============================================================================
    39. class Game_Battler
    40.   #--------------------------------------------------------------------------
    41.   # ● 定义实例变量
    42.   #--------------------------------------------------------------------------
    43.   attr_reader   :pending_animations       # 缓存的动画
    44.   #--------------------------------------------------------------------------
    45.   # ● 方法重定义
    46.   #--------------------------------------------------------------------------
    47.   unless method_defined? :sailcat_battleani_initialize
    48.     alias sailcat_battleani_initialize initialize
    49.   end
    50.   #--------------------------------------------------------------------------
    51.   # ● 初期化
    52.   #--------------------------------------------------------------------------
    53.   def initialize
    54.     sailcat_battleani_initialize
    55.     @pending_animations = []
    56.   end
    57.   #--------------------------------------------------------------------------
    58.   # ● 立即切入动画
    59.   #     value : 新的动画ID
    60.   #--------------------------------------------------------------------------
    61.   def animation_id=(value)
    62.     # 当前动画未处理,又要播放新动画时
    63.     insert_animation(@animation_id)if value > 0and@animation_id > 0
    64.     @animation_id = value
    65.   end
    66.   #--------------------------------------------------------------------------
    67.   # ● 缓存动画(在前)
    68.   #     ani_id  : 动画ID
    69.   #     damage  : 伤害
    70.   #     critical: 会心一击标志
    71.   #--------------------------------------------------------------------------
    72.   def insert_animation(ani_id, damage = self.damage, critical = self.critical)
    73.     # 追加到动画序列的开头
    74.     @pending_animations.shift([ani_id, damage, critical])
    75.   end
    76.   #--------------------------------------------------------------------------
    77.   # ● 缓存动画(在后)
    78.   #     ani_id  : 动画ID
    79.   #     damage  : 伤害
    80.   #     critical: 会心一击标志
    81.   #--------------------------------------------------------------------------
    82.   def pend_animation(ani_id, damage = self.damage, critical = self.critical)
    83.     # 追加到动画序列的末尾
    84.     @pending_animations.push([ani_id, damage, critical])
    85.   end
    86.   #--------------------------------------------------------------------------
    87.   # ● 动画等待判定
    88.   #--------------------------------------------------------------------------
    89.   def animation_pending?
    90.     not@pending_animations.empty?
    91.   end
    92.   #--------------------------------------------------------------------------
    93.   # ● 执行下一动画
    94.   #--------------------------------------------------------------------------
    95.   def next_animation
    96.     # 没有动画的情况下返回
    97.     returnunless animation_pending?
    98.     # 动画没播放完的情况下返回
    99.     returnif@animation_id > 0
    100.     animation = @pending_animations.shift
    101.     @animation_id = animation[0]
    102.     @damage = animation[1]
    103.     @critical = animation[2]
    104.     @animation_hit = @damage != "Miss"
    105.   end
    106. end
    107. #==============================================================================
    108. # ■ Sprite_Battler
    109. #==============================================================================
    110. class Sprite_Battler < RPG::Sprite
    111.   includeSailCat::BattleAnimation_Config
    112.   #--------------------------------------------------------------------------
    113.   # ● 效果中判定
    114.   #--------------------------------------------------------------------------
    115.   def effect?
    116.     @_whiten_duration > 0or
    117.     @_appear_duration > 0or
    118.     @_escape_duration > 0or
    119.     @_animation_duration > 0or
    120.     @_collapse_duration > 0or
    121.     @_damage_duration > ($scene.phase4_step == 6 ? 0 : 40 - AWAIT_HIT_INTERVAL)
    122.   end
    123.   #--------------------------------------------------------------------------
    124.   # ● 刷新画面
    125.   #--------------------------------------------------------------------------
    126.   def update
    127.     super
    128.     # 战斗者为 nil 的情况下
    129.     if@battler == nil
    130.       self.bitmap = nil
    131.       loop_animation(nil)
    132.       return
    133.     end
    134.     # 总是更新
    135.     update_battler_change
    136.     update_battler_loop_animation
    137.     update_battler_main_phase
    138.     update_battler_blink
    139.     update_battler_appear
    140.     # 可见时更新
    141.     if@battler_visible
    142.       update_battler_escape
    143.       update_battler_whiten
    144.       update_battler_animation
    145.       update_battler_damage
    146.       update_battler_collapse
    147.     end
    148.     # 设置活动块的坐标
    149.     self.x = @battler.screen_x
    150.     self.y = @battler.screen_y
    151.     self.z = @battler.screen_z
    152.   end
    153.   #--------------------------------------------------------------------------
    154.   # ● 更新画面差异
    155.   #--------------------------------------------------------------------------
    156.   def update_battler_change
    157.     # 文件名和色相与当前情况有差异的情况下
    158.     if@battler.battler_name != @battler_nameor
    159.        @battler.battler_hue != @battler_hue
    160.       # 获取、设置位图
    161.       @battler_name = @battler.battler_name
    162.       @battler_hue = @battler.battler_hue
    163.       self.bitmap = RPG::Cache.battler(@battler_name, @battler_hue)
    164.       @width = bitmap.width
    165.       @height = bitmap.height
    166.       self.ox = @width / 2
    167.       self.oy = @height
    168.       # 如果是战斗不能或者是隐藏状态就把透明度设置成 0
    169.       if@battler.dead? or@battler.hidden
    170.         self.opacity = 0
    171.       end
    172.     end
    173.   end
    174.   #--------------------------------------------------------------------------
    175.   # ● 更新状态动画
    176.   #--------------------------------------------------------------------------
    177.   def update_battler_loop_animation
    178.     # 动画 ID 与当前的情况有差异的情况下
    179.     if@battler.damage == niland
    180.        @battler.state_animation_id != @state_animation_id
    181.       @state_animation_id = @battler.state_animation_id
    182.       loop_animation($data_animations[@state_animation_id])
    183.     end
    184.   end
    185.   #--------------------------------------------------------------------------
    186.   # ● 更新显示效果
    187.   #--------------------------------------------------------------------------
    188.   def update_battler_main_phase
    189.     # 应该被显示的角色的情况下
    190.     if@battler.is_a?(Game_Actor)and@battler_visible
    191.       # 不是主状态的时候稍稍降低点透明度
    192.       if$game_temp.battle_main_phase
    193.         self.opacity += 3ifself.opacity < 255
    194.       else
    195.         self.opacity -= 3ifself.opacity > 207
    196.       end
    197.     end
    198.   end
    199.   #--------------------------------------------------------------------------
    200.   # ● 更新明灭
    201.   #--------------------------------------------------------------------------
    202.   def update_battler_blink
    203.     if@battler.blink
    204.       blink_on
    205.     else
    206.       blink_off
    207.     end
    208.   end
    209.   #--------------------------------------------------------------------------
    210.   # ● 更新出现
    211.   #--------------------------------------------------------------------------
    212.   def update_battler_appear
    213.     # 不可见的情况下
    214.     unless@battler_visible
    215.       # 出现
    216.       ifnot@battler.hiddenandnot@battler.dead? and
    217.          (@battler.damage == nilor@battler.damage_pop)
    218.         appear
    219.         @battler_visible = true
    220.       end
    221.     end
    222.   end
    223.   #--------------------------------------------------------------------------
    224.   # ● 更新逃跑
    225.   #--------------------------------------------------------------------------
    226.   def update_battler_escape
    227.     if@battler.hidden
    228.       $game_system.se_play($data_system.escape_se)
    229.       escape
    230.       @battler_visible = false
    231.     end
    232.   end
    233.   #--------------------------------------------------------------------------
    234.   # ● 更新白色闪烁
    235.   #--------------------------------------------------------------------------
    236.   def update_battler_whiten
    237.     if@battler.white_flash
    238.       whiten
    239.       @battler.white_flash = false
    240.     end
    241.   end
    242.   #--------------------------------------------------------------------------
    243.   # ● 更新动画
    244.   #--------------------------------------------------------------------------
    245.   def update_battler_animation
    246.     if@battler.animation_id != 0
    247.       animation = $data_animations[@battler.animation_id]
    248.       animation(animation, @battler.animation_hit)
    249.       @battler.animation_id = 0
    250.     end
    251.   end
    252.   #--------------------------------------------------------------------------
    253.   # ● 更新伤害
    254.   #--------------------------------------------------------------------------
    255.   def update_battler_damage
    256.     if@battler.damage_pop
    257.       damage(@battler.damage, @battler.critical)
    258.       @battler.damage = nil
    259.       @battler.critical = false
    260.       @battler.damage_pop = false
    261.     end
    262.   end
    263.   #--------------------------------------------------------------------------
    264.   # ● 更新死亡
    265.   #--------------------------------------------------------------------------
    266.   def update_battler_collapse
    267.     # 如果动画没有播放完,不执行死亡效果
    268.     returnif@battler.animation_pending?
    269.     if@battler.damage == niland@battler.dead?
    270.       if@battler.is_a?(Game_Enemy)
    271.         $game_system.se_play($data_system.enemy_collapse_se)
    272.       else
    273.         $game_system.se_play($data_system.actor_collapse_se)
    274.       end
    275.       collapse
    276.       @battler_visible = false
    277.     end
    278.   end
    279. end
    280. #==============================================================================
    281. # ■ Scene_Battle
    282. #==============================================================================
    283. class Scene_Battle
    284.   includeSailCat::BattleAnimation_Config
    285.   #--------------------------------------------------------------------------
    286.   # ● 定义实例变量
    287.   #--------------------------------------------------------------------------
    288.   attr_accessor :animation1_id
    289.   attr_accessor :animation2_id
    290.   attr_reader :phase4_step
    291.   #--------------------------------------------------------------------------
    292.   # ● 刷新画面 (主回合步骤 3 : 行动方动画)
    293.   #--------------------------------------------------------------------------
    294.   def update_phase4_step3
    295.     # 行动方动画 (ID 为 0 的情况下是白色闪烁)
    296.     @pending = false
    297.     if@animation1_id == 0
    298.       @active_battler.white_flash = true
    299.     else
    300.       # 如果行动者没有设置缓存动画,则设置默认的动画
    301.       unless@active_battler.animation_pending?
    302.         @active_battler.animation_id = @animation1_id
    303.         @active_battler.animation_hit = true
    304.       # 如果已经设置了缓存动画,则播放下一个缓存动画
    305.       else
    306.         @active_battler.next_animation
    307.         @pending |= @active_battler.animation_pending?
    308.       end
    309.     end
    310.     # 行动方动画没有播完的情况下,返回
    311.     returnif@pending
    312.     # 为对像方准备默认动画的缓存(如果没有设置)
    313.     for target in@target_battlers
    314.       target.pend_animation(@animation2_id)unless target.animation_pending?
    315.     end
    316.     # 移至步骤 4
    317.     @phase4_step = 4
    318.   end
    319.   #--------------------------------------------------------------------------
    320.   # ● 刷新画面 (主回合步骤 4 : 对像方动画)
    321.   #--------------------------------------------------------------------------
    322.   def update_phase4_step4
    323.     # 对像方动画
    324.     @pending = false
    325.     for target in@target_battlers
    326.       # 战斗者显示下一动画
    327.       target.next_animationif target.animation_pending?
    328.       # 仍有动画没显示完的情况下,设置标志
    329.       @pending |= target.animation_pending?
    330.     end
    331.     # 弹出伤害的等待时间
    332.     @wait_count = @pending ? AWAIT_DAMAGE_INTERVAL : AWAIT_DAMAGE_FINAL
    333.     # 移至步骤 5
    334.     @phase4_step = 5
    335.   end
    336.   #--------------------------------------------------------------------------
    337.   # ● 刷新画面 (主回合步骤 5 : 显示伤害)
    338.   #--------------------------------------------------------------------------
    339.   def update_phase4_step5
    340.     # 隐藏帮助窗口
    341.     @help_window.visible = false
    342.     # 刷新状态窗口
    343.     @status_window.refresh
    344.     # 显示伤害
    345.     @target_battlers.each{|t| t.damage_pop = trueif t.damage}
    346.     # 仍然有待播放缓存动画的情况下,移至步骤4,否则移到步骤6
    347.     @phase4_step = @pending ? 4 : 6
    348.   end
    349. end
    复制代码


                本帖来自P1论坛作者89444640,因Project1站服务器在国外有时候访问缓慢不方便作者交流学习,经联系P1站长fux2同意署名转载一起分享游戏制作经验,共同为国内独立游戏作者共同创造良好交流环境,原文地址:https://rpg.blue/forum.php?mod=viewthread&tid=404149  若有侵权,发帖作者可联系底部站长QQ在线咨询功能删除,谢谢。
    天天去同能,天天有童年!
    回复 论坛版权

    使用道具 举报

    ahome_bigavatar:guest
    ahome_bigavatar:welcomelogin
    您需要登录后才可以回帖 登录 | 立即注册

    本版积分规则

    QQ|Archiver|手机版|小黑屋|同能RPG制作大师 ( 沪ICP备12027754号-3 )

    GMT+8, 2024-5-3 03:19 , Processed in 0.066435 second(s), 46 queries .

    Powered by Discuz! X3.4

    Copyright © 2001-2020, Tencent Cloud.

    快速回复 返回顶部 返回列表