设为首页收藏本站|繁體中文

Project1

 找回密码
 注册会员
搜索
查看: 3431|回复: 5
打印 上一主题 下一主题

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

[复制链接]

Lv5.捕梦者 (版主)

遠航の猫咪

梦石
3
星屑
22437
在线时间
2335 小时
注册时间
2005-10-15
帖子
1160

开拓者

跳转到指定楼层
1
发表于 2017-11-25 23:21:12 | 只看该作者 回帖奖励 |倒序浏览 |阅读模式

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

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

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

SailCat (小猫子·要开心一点) 共上站 24 次,发表过 11 篇文章 上 次 在: [2006年01月28日11:41:18 星期六] 从 [162.105.120.91] 到本站一游。

Lv5.捕梦者

梦石
0
星屑
34870
在线时间
4148 小时
注册时间
2007-12-15
帖子
9981
2
发表于 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
回复 支持 反对

使用道具 举报

Lv1.梦旅人

梦石
0
星屑
247
在线时间
23 小时
注册时间
2012-8-15
帖子
34
3
发表于 2017-11-27 12:16:47 | 只看该作者
虽然看不懂,但是还是顶一下你!
回复 支持 0 反对 1

使用道具 举报

Lv2.观梦者

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

使用道具 举报

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

本版积分规则

拿上你的纸笔,建造一个属于你的梦想世界,加入吧。
 注册会员
找回密码

站长信箱:[email protected]|手机版|小黑屋|无图版|Project1游戏制作

GMT+8, 2024-4-25 15:29

Powered by Discuz! X3.1

© 2001-2013 Comsenz Inc.

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