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

Project1

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

[原创发布] 【脚本】伪·光环效果(给“全体队友/全体敌人”附加状态)

[复制链接]

Lv3.寻梦者

梦石
0
星屑
3037
在线时间
388 小时
注册时间
2015-1-29
帖子
17
跳转到指定楼层
1
发表于 2026-3-22 18:53:56 | 只看该作者 回帖奖励 |倒序浏览 |阅读模式

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

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

x
本帖最后由 SmallDrop 于 2026-4-1 16:59 编辑

RUBY 代码复制
  1. #==============================================================================
  2. # $SDrop$
  3. # 伪·光环效果 By猫易箱
  4. #------------------------------------------------------------------------------
  5. # 在 角色、职业、技能、武器、护甲、敌人、状态 备注添加使用:
  6. #   
  7. # <获得光环:状态ID>条件</获得光环>   # 给全体队友附加状态
  8. # <附加光环:状态ID>条件</附加光环>   # 给全体敌人附加状态
  9. #   
  10. #   条件表达式中的 属性和方法 默认代表 持有者
  11. #   如:hp_rate, mp_rate, states.include?(id) 等…
  12. #   条件为 true 或 空 时默认触发
  13. #   
  14. # 示例:
  15. #   <获得光环:13>hp_rate < 0.3</获得光环>
  16. #   <附加光环:10>rand(100) < 50</附加光环>
  17. #   <附加光环:15>mp_rate > 0.5 && states.include?(3)</附加光环>
  18. #==============================================================================
  19.  
  20. $imported = {} if $imported.nil?
  21. $imported["SDrop_AuraStates"] = true
  22.  
  23. #==============================================================================
  24. # ■ Game_BattlerBase
  25. #------------------------------------------------------------------------------
  26. #  添加光环解析和缓存的基础方法
  27. #==============================================================================
  28. class Game_BattlerBase
  29.   #--------------------------------------------------------------------------
  30.   # ● 别名初始化
  31.   #--------------------------------------------------------------------------
  32.   alias_method :aura_initialize, :initialize
  33.   def initialize
  34.     aura_initialize
  35.     @aura_buffs = []    # 给队友的光环
  36.     @aura_debuffs = []  # 给敌人的光环
  37.   end
  38.   #--------------------------------------------------------------------------
  39.   # ● 解析备注中的光环
  40.   #--------------------------------------------------------------------------
  41.   def setup_auras(note)
  42.     # 解析 <获得光环:ID>条件</获得光环>
  43.     note.scan(/<获得光环:(\d+)>(.*?)<\/获得光环>/m) do |state_id, condition|
  44.       @aura_buffs << {
  45.         type: :Aura,
  46.         state_id: state_id.to_i,
  47.         condition: condition.strip
  48.       }
  49.     end
  50.  
  51.     # 解析 <附加光环:ID>条件</附加光环>
  52.     note.scan(/<附加光环:(\d+)>(.*?)<\/附加光环>/m) do |state_id, condition|
  53.       @aura_debuffs << {
  54.         type: :deAura,
  55.         state_id: state_id.to_i,
  56.         condition: condition.strip
  57.       }
  58.     end
  59.   end
  60.   #--------------------------------------------------------------------------
  61.   # ● 获取所有光环
  62.   #--------------------------------------------------------------------------
  63.   def auras
  64.     @aura_buffs + @aura_debuffs
  65.   end
  66.   #--------------------------------------------------------------------------
  67.   # ● 获取给队友的光环
  68.   #--------------------------------------------------------------------------
  69.   def aura_buffs
  70.     @aura_buffs
  71.   end
  72.   #--------------------------------------------------------------------------
  73.   # ● 获取给敌人的光环
  74.   #--------------------------------------------------------------------------
  75.   def aura_debuffs
  76.     @aura_debuffs
  77.   end
  78. end
  79. #==============================================================================
  80. # ■ Game_Actor
  81. #------------------------------------------------------------------------------
  82. #  处理角色的类,添加光环解析
  83. #==============================================================================
  84. class Game_Actor < Game_Battler
  85.   #--------------------------------------------------------------------------
  86.   # ● 别名初始化
  87.   #--------------------------------------------------------------------------
  88.   alias_method :actor_aura_initialize, :initialize
  89.   def initialize(actor_id)
  90.     actor_aura_initialize(actor_id)
  91.     setup_actor_auras
  92.   end
  93.   #--------------------------------------------------------------------------
  94.   # ● 设置角色的所有光环(包括职业)
  95.   #--------------------------------------------------------------------------
  96.   def setup_actor_auras
  97.     # 角色本身
  98.     setup_auras(actor.note)
  99.     # 职业
  100.     setup_auras($data_classes[@class_id].note) if @class_id
  101.   end
  102.   #--------------------------------------------------------------------------
  103.   # ● 重写获取光环,动态包含装备、状态、技能
  104.   #--------------------------------------------------------------------------
  105.   def auras
  106.     result = super
  107.  
  108.     # 装备的光环
  109.     equips.compact.each do |item|
  110.       item.note.scan(/<获得光环:(\d+)>(.*?)<\/获得光环>/m) do |state_id, condition|
  111.         result << {
  112.           type: :Aura,
  113.           state_id: state_id.to_i,
  114.           condition: condition.strip,
  115.           source: item
  116.         }
  117.       end
  118.       item.note.scan(/<附加光环:(\d+)>(.*?)<\/获得光环>/m) do |state_id, condition|
  119.         result << {
  120.           type: :deAura,
  121.           state_id: state_id.to_i,
  122.           condition: condition.strip,
  123.           source: item
  124.         }
  125.       end
  126.     end
  127.  
  128.     # 状态的光环
  129.     states.each do |state|
  130.       state.note.scan(/<获得光环:(\d+)>(.*?)<\/获得光环>/m) do |state_id, condition|
  131.         result << {
  132.           type: :Aura,
  133.           state_id: state_id.to_i,
  134.           condition: condition.strip,
  135.           source: state
  136.         }
  137.       end
  138.       state.note.scan(/<附加光环:(\d+)>(.*?)<\/获得光环>/m) do |state_id, condition|
  139.         result << {
  140.           type: :deAura,
  141.           state_id: state_id.to_i,
  142.           condition: condition.strip,
  143.           source: state
  144.         }
  145.       end
  146.     end
  147.  
  148.     # 技能的光环(通过职业或角色自身学会的技能)
  149.     skills.each do |skill|
  150.       skill.note.scan(/<获得光环:(\d+)>(.*?)<\/获得光环>/m) do |state_id, condition|
  151.         result << {
  152.           type: :Aura,
  153.           state_id: state_id.to_i,
  154.           condition: condition.strip,
  155.           source: skill
  156.         }
  157.       end
  158.       skill.note.scan(/<附加光环:(\d+)>(.*?)<\/获得光环>/m) do |state_id, condition|
  159.         result << {
  160.           type: :deAura,
  161.           state_id: state_id.to_i,
  162.           condition: condition.strip,
  163.           source: skill
  164.         }
  165.       end
  166.     end
  167.  
  168.     result.uniq
  169.   end
  170.   #--------------------------------------------------------------------------
  171.   # ● 重写获取给队友的光环
  172.   #--------------------------------------------------------------------------
  173.   def aura_buffs
  174.     auras.select {|aura| aura[:type] == :Aura }
  175.   end
  176.   #--------------------------------------------------------------------------
  177.   # ● 重写获取给敌人的光环
  178.   #--------------------------------------------------------------------------
  179.   def aura_debuffs
  180.     auras.select {|aura| aura[:type] == :deAura }
  181.   end
  182. end
  183. #==============================================================================
  184. # ■ Game_Enemy
  185. #------------------------------------------------------------------------------
  186. #  处理敌人的类,添加光环解析
  187. #==============================================================================
  188. class Game_Enemy < Game_Battler
  189.   #--------------------------------------------------------------------------
  190.   # ● 别名初始化
  191.   #--------------------------------------------------------------------------
  192.   alias_method :enemy_aura_initialize, :initialize
  193.   def initialize(index, enemy_id)
  194.     enemy_aura_initialize(index, enemy_id)
  195.     setup_auras(enemy.note)
  196.   end
  197.   #--------------------------------------------------------------------------
  198.   # ● 重写获取光环,动态包含技能
  199.   #--------------------------------------------------------------------------
  200.   def auras
  201.     result = super
  202.  
  203.     # 技能的光环(敌人拥有的技能)
  204.     enemy.actions.each do |action|
  205.       skill = $data_skills[action.skill_id]
  206.       next unless skill
  207.  
  208.       skill.note.scan(/<获得光环:(\d+)>(.*?)<\/获得光环>/m) do |state_id, condition|
  209.         result << {
  210.           type: :Aura,
  211.           state_id: state_id.to_i,
  212.           condition: condition.strip,
  213.           source: skill
  214.         }
  215.       end
  216.       skill.note.scan(/<附加光环:(\d+)>(.*?)<\/获得光环>/m) do |state_id, condition|
  217.         result << {
  218.           type: :deAura,
  219.           state_id: state_id.to_i,
  220.           condition: condition.strip,
  221.           source: skill
  222.         }
  223.       end
  224.     end
  225.  
  226.     result.uniq
  227.   end
  228. end
  229. #==============================================================================
  230. # ■ AuraManager
  231. #------------------------------------------------------------------------------
  232. #  光环管理器 - 处理光环的触发和附加
  233. #==============================================================================
  234. module AuraManager
  235.   #--------------------------------------------------------------------------
  236.   # ● 模块的实例变量
  237.   #--------------------------------------------------------------------------
  238.   @processed_auras = {}   # 本回合已处理的光环记录
  239.   #--------------------------------------------------------------------------
  240.   # ● 清除本回合记录
  241.   #--------------------------------------------------------------------------
  242.   def self.clear_processed
  243.     @processed_auras = {}
  244.   end
  245.   #--------------------------------------------------------------------------
  246.   # ● 记录已处理的光环
  247.   #--------------------------------------------------------------------------
  248.   def self.mark_processed(battler, aura)
  249.     # 使用 battler 的唯一标识
  250.     if battler.is_a?(Game_Actor)
  251.       key = ["actor", battler.id, aura[:type], aura[:state_id]]
  252.     elsif battler.is_a?(Game_Enemy)
  253.       key = ["enemy", battler.enemy_id, battler.index, aura[:type], aura[:state_id]]
  254.     else
  255.       key = [battler.object_id, aura[:type], aura[:state_id]]
  256.     end
  257.     @processed_auras[key] = true
  258.   end
  259.   #--------------------------------------------------------------------------
  260.   # ● 检查光环是否已处理
  261.   #--------------------------------------------------------------------------
  262.   def self.processed?(battler, aura)
  263.     if battler.is_a?(Game_Actor)
  264.       key = ["actor", battler.id, aura[:type], aura[:state_id]]
  265.     elsif battler.is_a?(Game_Enemy)
  266.       key = ["enemy", battler.enemy_id, battler.index, aura[:type], aura[:state_id]]
  267.     else
  268.       key = [battler.object_id, aura[:type], aura[:state_id]]
  269.     end
  270.     @processed_auras.key?(key)
  271.   end
  272.   #--------------------------------------------------------------------------
  273.   # ● 评估条件表达式
  274.   #--------------------------------------------------------------------------
  275.   def self.evaluate_condition(condition, battler)
  276.     return true if condition.nil? || condition.empty?
  277.  
  278.     begin
  279.     # 使用 instance_eval 直接在 battler 的上下文中执行条件
  280.     result = battler.instance_eval(condition)
  281.     !!result
  282.     rescue => e
  283.       # 条件表达式出错时输出提示(调试用)
  284.       puts "光环条件错误: #{condition}, 错误: #{e.message}"
  285.       false
  286.     end
  287.   end
  288.   #--------------------------------------------------------------------------
  289.   # ● 触发所有光环
  290.   #--------------------------------------------------------------------------
  291.   def self.trigger_auras(battlers, target_type, target_unit)
  292.     battlers.each do |battler|
  293.       next unless battler.alive?  # 死亡不触发
  294.       auras = target_type == :Aura ? battler.aura_buffs : battler.aura_debuffs
  295.       auras.each do |aura|
  296.         # 跳过本回合已处理过的光环
  297.         next if processed?(battler, aura)
  298.         # 检查条件
  299.         if evaluate_condition(aura[:condition], battler)
  300.           # 给目标全体附加状态
  301.           target_unit.alive_members.each do |target|
  302.             target.add_state(aura[:state_id])
  303.           end
  304.         end
  305.         # 标记为已处理
  306.         mark_processed(battler, aura)
  307.       end
  308.     end
  309.   end
  310.   #--------------------------------------------------------------------------
  311.   # ● 战斗开始触发
  312.   #--------------------------------------------------------------------------
  313.   def self.on_battle_start
  314.     clear_processed
  315.     # 处理所有队友的光环
  316.     trigger_auras($game_party.alive_members, :deAura, $game_troop)  # 给敌人
  317.     trigger_auras($game_party.alive_members, :Aura, $game_party)    # 给队友
  318.     # 处理所有敌人的光环
  319.     trigger_auras($game_troop.alive_members, :deAura, $game_party)  # 给敌人(玩家)
  320.     trigger_auras($game_troop.alive_members, :Aura, $game_troop)    # 给队友(敌人)
  321.   end
  322.   #--------------------------------------------------------------------------
  323.   # ● 回合结束时触发
  324.   #--------------------------------------------------------------------------
  325.   def self.on_turn_end
  326.     clear_processed
  327.     # 处理所有队友的光环
  328.     trigger_auras($game_party.alive_members, :deAura, $game_troop)  # 给敌人
  329.     trigger_auras($game_party.alive_members, :Aura, $game_party)    # 给队友
  330.     # 处理所有敌人的光环
  331.     trigger_auras($game_troop.alive_members, :deAura, $game_party)  # 给敌人(玩家)
  332.     trigger_auras($game_troop.alive_members, :Aura, $game_troop)    # 给队友(敌人)
  333.   end
  334. end
  335. #==============================================================================
  336. # ■ BattleManager
  337. #------------------------------------------------------------------------------
  338. #  注入光环触发到战斗管理器中
  339. #==============================================================================
  340. module BattleManager
  341.   #--------------------------------------------------------------------------
  342.   # ● 别名回合结束
  343.   #--------------------------------------------------------------------------
  344.   class << self
  345.     alias_method :aura_turn_end, :turn_end
  346.   end
  347.  
  348.   def self.turn_end
  349.     AuraManager.on_turn_end
  350.     aura_turn_end
  351.   end
  352. end
  353. #==============================================================================
  354. # ■ Scene_Battle
  355. #------------------------------------------------------------------------------
  356. #  注入战斗开始触发
  357. #==============================================================================
  358. class Scene_Battle
  359.   #--------------------------------------------------------------------------
  360.   # ● 别名开始
  361.   #--------------------------------------------------------------------------
  362.   alias_method :aura_start_processing, :start
  363.   def start
  364.     aura_start_processing
  365.     AuraManager.on_battle_start
  366.   end
  367. end


此脚本简单来说,就是自动给 全体队友/全体敌人 附加状态

可以设置成 回合结束1回合 来冒充光环的效果
但原版va重复附加1回合状态有bug,会导致→1回合成功→1回合失败→1回合成功→1回合失败 这样。

所以你需要做一些小小的修改:
需修改内容

如果你只用 行动结束 或 回合结束2回合 不修改也行

在 角色、职业、技能、武器、护甲、敌人、状态 备注添加使用:
  
<获得光环:状态ID>条件</获得光环>   # 给全体队友附加状态
<附加光环:状态ID>条件</附加光环>   # 给全体敌人附加状态

示例:

<获得光环:7>true</获得光环>
无条件,每回合给全体队友附加7号状态

<获得光环:8>hp_rate < 0.3</获得光环>
当 持有者 生命值低于30%时,给全体队友附加8号状态

<获得光环:9>(atk + def) > 500</获得光环>
当 持有者 攻击力+防御力 大于500时,给全体队友附加9号状态

<附加光环:10>rand(100) < 50</附加光环>
每回合50%几率给全体敌人附加10号状态

<附加光环:11>$game_troop.members.size > 3</附加光环>
敌人数量大于3时,给全体敌人附加11号状态

<附加光环:12>$game_troop.turn_count % 2 == 1</附加光环>
奇数回合(第1、3、5、7...回合)给全体敌人附加12号状态

Lv1.梦旅人

梦石
0
星屑
53
在线时间
8 小时
注册时间
2025-10-20
帖子
2
2
发表于 2026-4-4 13:34:19 | 只看该作者
不能给单个队友光环吗?比如那个队友血低自动给光环,满血的不给
回复 支持 反对

使用道具 举报

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

本版积分规则

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

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

GMT+8, 2026-6-4 11:17

Powered by Discuz! X3.1

© 2001-2013 Comsenz Inc.

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