查看: 4424|回复: 5

[原创发布] 战斗动画增强插件

[复制链接]

遠航の猫咪

梦石
3
星屑
27057
在线时间
2428 小时
注册时间
2005-10-15
回帖
989

开拓者

发表于 2017-11-25 23:21:12 | 显示全部楼层 |阅读模式

加入我们,或者,欢迎回来。

您需要 登录 才可以下载或查看,没有账号?注册会员

×
即插即用型,可以允许在战斗中一个主回合放N个动画,自建RTAB引擎、技能连击特效适用

  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 > 0 and @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.     return unless animation_pending?
  98.     # 动画没播放完的情况下返回
  99.     return if @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. #==============================================================================
  109. # ■ Sprite_Battler
  110. #==============================================================================
  111. class Sprite_Battler < RPG::Sprite
  112.   include SailCat::BattleAnimation_Config
  113.   #--------------------------------------------------------------------------
  114.   # ● 效果中判定
  115.   #--------------------------------------------------------------------------
  116.   def effect?
  117.     @_whiten_duration > 0 or
  118.     @_appear_duration > 0 or
  119.     @_escape_duration > 0 or
  120.     @_animation_duration > 0 or
  121.     @_collapse_duration > 0 or
  122.     @_damage_duration > ($scene.phase4_step == 6 ? 0 : 40 - AWAIT_HIT_INTERVAL)
  123.   end
  124.   #--------------------------------------------------------------------------
  125.   # ● 刷新画面
  126.   #--------------------------------------------------------------------------
  127.   def update
  128.     super
  129.     # 战斗者为 nil 的情况下
  130.     if @battler == nil
  131.       self.bitmap = nil
  132.       loop_animation(nil)
  133.       return
  134.     end
  135.     # 总是更新
  136.     update_battler_change
  137.     update_battler_loop_animation
  138.     update_battler_main_phase
  139.     update_battler_blink
  140.     update_battler_appear
  141.     # 可见时更新
  142.     if @battler_visible
  143.       update_battler_escape
  144.       update_battler_whiten
  145.       update_battler_animation
  146.       update_battler_damage
  147.       update_battler_collapse
  148.     end
  149.     # 设置活动块的坐标
  150.     self.x = @battler.screen_x
  151.     self.y = @battler.screen_y
  152.     self.z = @battler.screen_z
  153.   end
  154.   #--------------------------------------------------------------------------
  155.   # ● 更新画面差异
  156.   #--------------------------------------------------------------------------
  157.   def update_battler_change
  158.     # 文件名和色相与当前情况有差异的情况下
  159.     if @battler.battler_name != @battler_name or
  160.        @battler.battler_hue != @battler_hue
  161.       # 获取、设置位图
  162.       @battler_name = @battler.battler_name
  163.       @battler_hue = @battler.battler_hue
  164.       self.bitmap = RPG::Cache.battler(@battler_name, @battler_hue)
  165.       @width = bitmap.width
  166.       @height = bitmap.height
  167.       self.ox = @width / 2
  168.       self.oy = @height
  169.       # 如果是战斗不能或者是隐藏状态就把透明度设置成 0
  170.       if @battler.dead? or @battler.hidden
  171.         self.opacity = 0
  172.       end
  173.     end
  174.   end
  175.   #--------------------------------------------------------------------------
  176.   # ● 更新状态动画
  177.   #--------------------------------------------------------------------------
  178.   def update_battler_loop_animation
  179.     # 动画 ID 与当前的情况有差异的情况下
  180.     if @battler.damage == nil and
  181.        @battler.state_animation_id != @state_animation_id
  182.       @state_animation_id = @battler.state_animation_id
  183.       loop_animation($data_animations[@state_animation_id])
  184.     end
  185.   end
  186.   #--------------------------------------------------------------------------
  187.   # ● 更新显示效果
  188.   #--------------------------------------------------------------------------
  189.   def update_battler_main_phase
  190.     # 应该被显示的角色的情况下
  191.     if @battler.is_a?(Game_Actor) and @battler_visible
  192.       # 不是主状态的时候稍稍降低点透明度
  193.       if $game_temp.battle_main_phase
  194.         self.opacity += 3 if self.opacity < 255
  195.       else
  196.         self.opacity -= 3 if self.opacity > 207
  197.       end
  198.     end
  199.   end
  200.   #--------------------------------------------------------------------------
  201.   # ● 更新明灭
  202.   #--------------------------------------------------------------------------
  203.   def update_battler_blink
  204.     if @battler.blink
  205.       blink_on
  206.     else
  207.       blink_off
  208.     end
  209.   end
  210.   #--------------------------------------------------------------------------
  211.   # ● 更新出现
  212.   #--------------------------------------------------------------------------
  213.   def update_battler_appear
  214.     # 不可见的情况下
  215.     unless @battler_visible
  216.       # 出现
  217.       if not @battler.hidden and not @battler.dead? and
  218.          (@battler.damage == nil or @battler.damage_pop)
  219.         appear
  220.         @battler_visible = true
  221.       end
  222.     end
  223.   end
  224.   #--------------------------------------------------------------------------
  225.   # ● 更新逃跑
  226.   #--------------------------------------------------------------------------
  227.   def update_battler_escape
  228.     if @battler.hidden
  229.       $game_system.se_play($data_system.escape_se)
  230.       escape
  231.       @battler_visible = false
  232.     end
  233.   end
  234.   #--------------------------------------------------------------------------
  235.   # ● 更新白色闪烁
  236.   #--------------------------------------------------------------------------
  237.   def update_battler_whiten
  238.     if @battler.white_flash
  239.       whiten
  240.       @battler.white_flash = false
  241.     end
  242.   end
  243.   #--------------------------------------------------------------------------
  244.   # ● 更新动画
  245.   #--------------------------------------------------------------------------
  246.   def update_battler_animation
  247.     if @battler.animation_id != 0
  248.       animation = $data_animations[@battler.animation_id]
  249.       animation(animation, @battler.animation_hit)
  250.       @battler.animation_id = 0
  251.     end
  252.   end
  253.   #--------------------------------------------------------------------------
  254.   # ● 更新伤害
  255.   #--------------------------------------------------------------------------
  256.   def update_battler_damage
  257.     if @battler.damage_pop
  258.       damage(@battler.damage, @battler.critical)
  259.       @battler.damage = nil
  260.       @battler.critical = false
  261.       @battler.damage_pop = false
  262.     end
  263.   end
  264.   #--------------------------------------------------------------------------
  265.   # ● 更新死亡
  266.   #--------------------------------------------------------------------------
  267.   def update_battler_collapse
  268.     # 如果动画没有播放完,不执行死亡效果
  269.     return if @battler.animation_pending?
  270.     if @battler.damage == nil and @battler.dead?
  271.       if @battler.is_a?(Game_Enemy)
  272.         $game_system.se_play($data_system.enemy_collapse_se)
  273.       else
  274.         $game_system.se_play($data_system.actor_collapse_se)
  275.       end
  276.       collapse
  277.       @battler_visible = false
  278.     end
  279.   end
  280. end

  281. #==============================================================================
  282. # ■ Scene_Battle
  283. #==============================================================================
  284. class Scene_Battle
  285.   include SailCat::BattleAnimation_Config
  286.   #--------------------------------------------------------------------------
  287.   # ● 定义实例变量
  288.   #--------------------------------------------------------------------------
  289.   attr_accessor :animation1_id
  290.   attr_accessor :animation2_id
  291.   attr_reader :phase4_step
  292.   #--------------------------------------------------------------------------
  293.   # ● 刷新画面 (主回合步骤 3 : 行动方动画)
  294.   #--------------------------------------------------------------------------
  295.   def update_phase4_step3
  296.     # 行动方动画 (ID 为 0 的情况下是白色闪烁)
  297.     @pending = false
  298.     if @animation1_id == 0
  299.       @active_battler.white_flash = true
  300.     else
  301.       # 如果行动者没有设置缓存动画,则设置默认的动画
  302.       unless @active_battler.animation_pending?
  303.         @active_battler.animation_id = @animation1_id
  304.         @active_battler.animation_hit = true
  305.       # 如果已经设置了缓存动画,则播放下一个缓存动画
  306.       else
  307.         @active_battler.next_animation
  308.         @pending |= @active_battler.animation_pending?
  309.       end
  310.     end
  311.     # 行动方动画没有播完的情况下,返回
  312.     return if @pending
  313.     # 为对像方准备默认动画的缓存(如果没有设置)
  314.     for target in @target_battlers
  315.       target.pend_animation(@animation2_id) unless target.animation_pending?
  316.     end
  317.     # 移至步骤 4
  318.     @phase4_step = 4
  319.   end
  320.   #--------------------------------------------------------------------------
  321.   # ● 刷新画面 (主回合步骤 4 : 对像方动画)
  322.   #--------------------------------------------------------------------------
  323.   def update_phase4_step4
  324.     # 对像方动画
  325.     @pending = false
  326.     for target in @target_battlers
  327.       # 战斗者显示下一动画
  328.       target.next_animation if target.animation_pending?
  329.       # 仍有动画没显示完的情况下,设置标志
  330.       @pending |= target.animation_pending?
  331.     end
  332.     # 弹出伤害的等待时间
  333.     @wait_count = @pending ? AWAIT_DAMAGE_INTERVAL : AWAIT_DAMAGE_FINAL
  334.     # 移至步骤 5
  335.     @phase4_step = 5
  336.   end
  337.   #--------------------------------------------------------------------------
  338.   # ● 刷新画面 (主回合步骤 5 : 显示伤害)
  339.   #--------------------------------------------------------------------------
  340.   def update_phase4_step5
  341.     # 隐藏帮助窗口
  342.     @help_window.visible = false
  343.     # 刷新状态窗口
  344.     @status_window.refresh
  345.     # 显示伤害
  346.     @target_battlers.each {|t| t.damage_pop = true if t.damage}
  347.     # 仍然有待播放缓存动画的情况下,移至步骤4,否则移到步骤6
  348.     @phase4_step = @pending ? 4 : 6
  349.   end
  350. end
复制代码

SailCat (小猫子·要开心一点) 共上站 24 次,发表过 11 篇文章 上 次 在: [2006年01月28日11:41:18 星期六] 从 [162.105.120.91] 到本站一游。
梦石
0
星屑
35258
在线时间
4171 小时
注册时间
2007-12-15
回帖
9490
发表于 2017-11-27 06:38:33 | 显示全部楼层
这个我看了半天发现不知道怎么用,
应该可以实现,类似格斗游戏的连续技了,

动画1,播放完毕的瞬间,X帧以内输入特殊组合键,比如→↓↘+A播放动画2

但是不知道怎么调用脚本,超长注释?写到公用事件中?

#     battler.pend_animation(动画ID, 伤害, 会心一击标志)   # 追加到动画的队尾
#     battler.insert_animation(动画ID, 伤害, 会心一击标志) # 在当前动画后切入

特殊时间段按键怎么实现呢?这样直接写的话,第二段的动画追加会自动播放了。
然后,这个脚本我发现有抗延迟,是不是能实现地图上动画的无缝循环播放了,xp地图播放循环动画一直在衔接的时候卡一下。

点评

loop_animation?请问有xp版本可用的吗,我上次的帖子有人回了一个其他版本的  发表于 2017-11-27 14:05
放循环动画得用loop_animation,如果用animation肯定会卡一下  发表于 2017-11-27 12:07
回复

使用道具 举报

梦石
0
星屑
247
在线时间
23 小时
注册时间
2012-8-15
回帖
33
发表于 2017-11-27 12:16:47 | 显示全部楼层
虽然看不懂,但是还是顶一下你!
回复 0 1

使用道具 举报

梦石
0
星屑
504
在线时间
43 小时
注册时间
2018-2-19
回帖
60
发表于 2018-3-10 03:12:56 | 显示全部楼层
感谢楼主分享。
梦想是谁创造的,梦想是自己创造的。站起来吧。
                      梦想由我们自己来创造。
  无论未来有多么困难,在下都会尽全力走下去。
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 注册会员

本版积分规则

Powered by Discuz! X5.0 © 2001-2026 Discuz! Team.

在本版发帖返回顶部