查看: 792|回复: 1

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

[复制链接]
梦石
0
星屑
3037
在线时间
388 小时
注册时间
2015-1-29
回帖
12
发表于 2026-3-22 18:53:56 | 显示全部楼层 |阅读模式

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

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

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

[pre lang="ruby"]#==============================================================================
# $SDrop$
# 伪·光环效果 By猫易箱
#------------------------------------------------------------------------------
# 在 角色、职业、技能、武器、护甲、敌人、状态 备注添加使用:
#   
# <获得光环:状态ID>条件</获得光环>   # 给全体队友附加状态
# <附加光环:状态ID>条件</附加光环>   # 给全体敌人附加状态
#   
#   条件表达式中的 属性和方法 默认代表 持有者
#   如:hp_rate, mp_rate, states.include?(id) 等…
#   条件为 true 或 空 时默认触发
#   
# 示例:
#   <获得光环:13>hp_rate < 0.3</获得光环>
#   <附加光环:10>rand(100) < 50</附加光环>
#   <附加光环:15>mp_rate > 0.5 && states.include?(3)</附加光环>
#==============================================================================

$imported = {} if $imported.nil?
$imported["SDrop_AuraStates"] = true

#==============================================================================
# ■ Game_BattlerBase
#------------------------------------------------------------------------------
#  添加光环解析和缓存的基础方法
#==============================================================================
class Game_BattlerBase
  #--------------------------------------------------------------------------
  # ● 别名初始化
  #--------------------------------------------------------------------------
  alias_method :aura_initialize, :initialize
  def initialize
    aura_initialize
    @aura_buffs = []    # 给队友的光环
    @aura_debuffs = []  # 给敌人的光环
  end
  #--------------------------------------------------------------------------
  # ● 解析备注中的光环
  #--------------------------------------------------------------------------
  def setup_auras(note)
    # 解析 <获得光环:ID>条件</获得光环>
    note.scan(/<获得光环:(\d+)>(.*?)<\/获得光环>/m) do |state_id, condition|
      @aura_buffs << {
        type: :Aura,
        state_id: state_id.to_i,
        condition: condition.strip
      }
    end
   
    # 解析 <附加光环:ID>条件</附加光环>
    note.scan(/<附加光环:(\d+)>(.*?)<\/附加光环>/m) do |state_id, condition|
      @aura_debuffs << {
        type: :deAura,
        state_id: state_id.to_i,
        condition: condition.strip
      }
    end
  end
  #--------------------------------------------------------------------------
  # ● 获取所有光环
  #--------------------------------------------------------------------------
  def auras
    @aura_buffs + @aura_debuffs
  end
  #--------------------------------------------------------------------------
  # ● 获取给队友的光环
  #--------------------------------------------------------------------------
  def aura_buffs
    @aura_buffs
  end
  #--------------------------------------------------------------------------
  # ● 获取给敌人的光环
  #--------------------------------------------------------------------------
  def aura_debuffs
    @aura_debuffs
  end
end
#==============================================================================
# ■ Game_Actor
#------------------------------------------------------------------------------
#  处理角色的类,添加光环解析
#==============================================================================
class Game_Actor < Game_Battler
  #--------------------------------------------------------------------------
  # ● 别名初始化
  #--------------------------------------------------------------------------
  alias_method :actor_aura_initialize, :initialize
  def initialize(actor_id)
    actor_aura_initialize(actor_id)
    setup_actor_auras
  end
  #--------------------------------------------------------------------------
  # ● 设置角色的所有光环(包括职业)
  #--------------------------------------------------------------------------
  def setup_actor_auras
    # 角色本身
    setup_auras(actor.note)
    # 职业
    setup_auras($data_classes[@class_id].note) if @class_id
  end
  #--------------------------------------------------------------------------
  # ● 重写获取光环,动态包含装备、状态、技能
  #--------------------------------------------------------------------------
  def auras
    result = super
   
    # 装备的光环
    equips.compact.each do |item|
      item.note.scan(/<获得光环:(\d+)>(.*?)<\/获得光环>/m) do |state_id, condition|
        result << {
          type: :Aura,
          state_id: state_id.to_i,
          condition: condition.strip,
          source: item
        }
      end
      item.note.scan(/<附加光环:(\d+)>(.*?)<\/获得光环>/m) do |state_id, condition|
        result << {
          type: :deAura,
          state_id: state_id.to_i,
          condition: condition.strip,
          source: item
        }
      end
    end
   
    # 状态的光环
    states.each do |state|
      state.note.scan(/<获得光环:(\d+)>(.*?)<\/获得光环>/m) do |state_id, condition|
        result << {
          type: :Aura,
          state_id: state_id.to_i,
          condition: condition.strip,
          source: state
        }
      end
      state.note.scan(/<附加光环:(\d+)>(.*?)<\/获得光环>/m) do |state_id, condition|
        result << {
          type: :deAura,
          state_id: state_id.to_i,
          condition: condition.strip,
          source: state
        }
      end
    end
   
    # 技能的光环(通过职业或角色自身学会的技能)
    skills.each do |skill|
      skill.note.scan(/<获得光环:(\d+)>(.*?)<\/获得光环>/m) do |state_id, condition|
        result << {
          type: :Aura,
          state_id: state_id.to_i,
          condition: condition.strip,
          source: skill
        }
      end
      skill.note.scan(/<附加光环:(\d+)>(.*?)<\/获得光环>/m) do |state_id, condition|
        result << {
          type: :deAura,
          state_id: state_id.to_i,
          condition: condition.strip,
          source: skill
        }
      end
    end
   
    result.uniq
  end
  #--------------------------------------------------------------------------
  # ● 重写获取给队友的光环
  #--------------------------------------------------------------------------
  def aura_buffs
    auras.select {|aura| aura[:type] == :Aura }
  end
  #--------------------------------------------------------------------------
  # ● 重写获取给敌人的光环
  #--------------------------------------------------------------------------
  def aura_debuffs
    auras.select {|aura| aura[:type] == :deAura }
  end
end
#==============================================================================
# ■ Game_Enemy
#------------------------------------------------------------------------------
#  处理敌人的类,添加光环解析
#==============================================================================
class Game_Enemy < Game_Battler
  #--------------------------------------------------------------------------
  # ● 别名初始化
  #--------------------------------------------------------------------------
  alias_method :enemy_aura_initialize, :initialize
  def initialize(index, enemy_id)
    enemy_aura_initialize(index, enemy_id)
    setup_auras(enemy.note)
  end
  #--------------------------------------------------------------------------
  # ● 重写获取光环,动态包含技能
  #--------------------------------------------------------------------------
  def auras
    result = super
   
    # 技能的光环(敌人拥有的技能)
    enemy.actions.each do |action|
      skill = $data_skills[action.skill_id]
      next unless skill
      
      skill.note.scan(/<获得光环:(\d+)>(.*?)<\/获得光环>/m) do |state_id, condition|
        result << {
          type: :Aura,
          state_id: state_id.to_i,
          condition: condition.strip,
          source: skill
        }
      end
      skill.note.scan(/<附加光环:(\d+)>(.*?)<\/获得光环>/m) do |state_id, condition|
        result << {
          type: :deAura,
          state_id: state_id.to_i,
          condition: condition.strip,
          source: skill
        }
      end
    end
   
    result.uniq
  end
end
#==============================================================================
# ■ AuraManager
#------------------------------------------------------------------------------
#  光环管理器 - 处理光环的触发和附加
#==============================================================================
module AuraManager
  #--------------------------------------------------------------------------
  # ● 模块的实例变量
  #--------------------------------------------------------------------------
  @processed_auras = {}   # 本回合已处理的光环记录
  #--------------------------------------------------------------------------
  # ● 清除本回合记录
  #--------------------------------------------------------------------------
  def self.clear_processed
    @processed_auras = {}
  end
  #--------------------------------------------------------------------------
  # ● 记录已处理的光环
  #--------------------------------------------------------------------------
  def self.mark_processed(battler, aura)
    # 使用 battler 的唯一标识
    if battler.is_a?(Game_Actor)
      key = ["actor", battler.id, aura[:type], aura[:state_id]]
    elsif battler.is_a?(Game_Enemy)
      key = ["enemy", battler.enemy_id, battler.index, aura[:type], aura[:state_id]]
    else
      key = [battler.object_id, aura[:type], aura[:state_id]]
    end
    @processed_auras[key] = true
  end
  #--------------------------------------------------------------------------
  # ● 检查光环是否已处理
  #--------------------------------------------------------------------------
  def self.processed?(battler, aura)
    if battler.is_a?(Game_Actor)
      key = ["actor", battler.id, aura[:type], aura[:state_id]]
    elsif battler.is_a?(Game_Enemy)
      key = ["enemy", battler.enemy_id, battler.index, aura[:type], aura[:state_id]]
    else
      key = [battler.object_id, aura[:type], aura[:state_id]]
    end
    @processed_auras.key?(key)
  end
  #--------------------------------------------------------------------------
  # ● 评估条件表达式
  #--------------------------------------------------------------------------
  def self.evaluate_condition(condition, battler)
    return true if condition.nil? || condition.empty?
   
    begin
    # 使用 instance_eval 直接在 battler 的上下文中执行条件
    result = battler.instance_eval(condition)
    !!result
    rescue => e
      # 条件表达式出错时输出提示(调试用)
      puts "光环条件错误: #{condition}, 错误: #{e.message}"
      false
    end
  end
  #--------------------------------------------------------------------------
  # ● 触发所有光环
  #--------------------------------------------------------------------------
  def self.trigger_auras(battlers, target_type, target_unit)
    battlers.each do |battler|
      next unless battler.alive?  # 死亡不触发
      auras = target_type == :Aura ? battler.aura_buffs : battler.aura_debuffs
      auras.each do |aura|
        # 跳过本回合已处理过的光环
        next if processed?(battler, aura)
        # 检查条件
        if evaluate_condition(aura[:condition], battler)
          # 给目标全体附加状态
          target_unit.alive_members.each do |target|
            target.add_state(aura[:state_id])
          end
        end
        # 标记为已处理
        mark_processed(battler, aura)
      end
    end
  end
  #--------------------------------------------------------------------------
  # ● 战斗开始触发
  #--------------------------------------------------------------------------
  def self.on_battle_start
    clear_processed
    # 处理所有队友的光环
    trigger_auras($game_party.alive_members, :deAura, $game_troop)  # 给敌人
    trigger_auras($game_party.alive_members, :Aura, $game_party)    # 给队友
    # 处理所有敌人的光环
    trigger_auras($game_troop.alive_members, :deAura, $game_party)  # 给敌人(玩家)
    trigger_auras($game_troop.alive_members, :Aura, $game_troop)    # 给队友(敌人)
  end
  #--------------------------------------------------------------------------
  # ● 回合结束时触发
  #--------------------------------------------------------------------------
  def self.on_turn_end
    clear_processed
    # 处理所有队友的光环
    trigger_auras($game_party.alive_members, :deAura, $game_troop)  # 给敌人
    trigger_auras($game_party.alive_members, :Aura, $game_party)    # 给队友
    # 处理所有敌人的光环
    trigger_auras($game_troop.alive_members, :deAura, $game_party)  # 给敌人(玩家)
    trigger_auras($game_troop.alive_members, :Aura, $game_troop)    # 给队友(敌人)
  end
end
#==============================================================================
# ■ BattleManager
#------------------------------------------------------------------------------
#  注入光环触发到战斗管理器中
#==============================================================================
module BattleManager
  #--------------------------------------------------------------------------
  # ● 别名回合结束
  #--------------------------------------------------------------------------
  class << self
    alias_method :aura_turn_end, :turn_end
  end
  
  def self.turn_end
    AuraManager.on_turn_end
    aura_turn_end
  end
end
#==============================================================================
# ■ Scene_Battle
#------------------------------------------------------------------------------
#  注入战斗开始触发
#==============================================================================
class Scene_Battle
  #--------------------------------------------------------------------------
  # ● 别名开始
  #--------------------------------------------------------------------------
  alias_method :aura_start_processing, :start
  def start
    aura_start_processing
    AuraManager.on_battle_start
  end
end[/pre]

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

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

所以你需要做一些小小的修改:
[fold=需修改内容]脚本编辑器
↓
查找:def state_addable?(state_id)
↓
#--------------------------------------------------------------------------
# ● 判定状态是否可以附加
#--------------------------------------------------------------------------
  def state_addable?(state_id)
    alive? && $data_states[state_id] && !state_resist?(state_id) &&
      !state_removed?(state_id) && !state_restrict?(state_id)
把这里的↑【!state_removed?(state_id) &&】去掉
  end[/fold]
如果你只用 行动结束 或 回合结束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号状态
梦石
0
星屑
68
在线时间
9 小时
注册时间
2025-10-20
回帖
1
发表于 2026-4-4 13:34:19 | 显示全部楼层
不能给单个队友光环吗?比如那个队友血低自动给光环,满血的不给
回复

使用道具 举报

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

本版积分规则

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

在本版发帖返回顶部