查看: 668|回复: 1

[原创发布] 【脚本】“固定增伤”和“固定减伤”效果

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

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

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

×
本帖最后由 SmallDrop 于 2026-3-13 16:28 编辑

[pre lang="ruby"]#==============================================================================
# $SDrop$
# 固定增减伤效果 By猫易箱
#------------------------------------------------------------------------------
# 在 角色、职业、武器、护甲、敌人、状态 备注添加使用:
#
# <固定增伤>公式</固定增伤>
#
# 例如:
# <固定增伤>50</固定增伤> 受到伤害时,固定增加50点伤害
#
# <固定减伤>公式</固定减伤>
#
# 例如:
# <固定减伤>a.def * 1</固定减伤> 按自身100%的防御力,减少受到伤害
#==============================================================================

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

#==============================================================================
# ■ RPG::BaseItem
#------------------------------------------------------------------------------
#  为所有基础物品类添加备注解析方法
#==============================================================================

class RPG::BaseItem
  #--------------------------------------------------------------------------
  # ● 获取固定减伤公式
  #--------------------------------------------------------------------------
  def fixed_damage_reduce
    @fixed_damage_reduce ||= load_fixed_damage_reduce
  end
  
  def load_fixed_damage_reduce
    self.note =~ /<固定减伤>(.+?)<\/固定减伤>/m ? $1.strip : nil
  end
  
  #--------------------------------------------------------------------------
  # ● 获取固定增伤公式
  #--------------------------------------------------------------------------
  def fixed_damage_increase
    @fixed_damage_increase ||= load_fixed_damage_increase
  end
  
  def load_fixed_damage_increase
    self.note =~ /<固定增伤>(.+?)<\/固定增伤>/m ? $1.strip : nil
  end
end

#==============================================================================
# ■ Game_BattlerBase
#------------------------------------------------------------------------------
#  收集固定增减伤公式
#==============================================================================

class Game_BattlerBase
  #--------------------------------------------------------------------------
  # ● 获取所有固定减伤公式
  #--------------------------------------------------------------------------
  def fixed_reduce_formulas
    result = []
    feature_objects.each do |obj|
      if obj.respond_to?(:fixed_damage_reduce) && obj.fixed_damage_reduce
        result << obj.fixed_damage_reduce
      end
    end
    if self.is_a?(Game_Actor)
      self.equips.compact.each do |equip|
        if equip.respond_to?(:fixed_damage_reduce) && equip.fixed_damage_reduce
          result << equip.fixed_damage_reduce
        end
      end
    end
    result
  end
  
  #--------------------------------------------------------------------------
  # ● 获取所有固定增伤公式
  #--------------------------------------------------------------------------
  def fixed_increase_formulas
    result = []
    feature_objects.each do |obj|
      if obj.respond_to?(:fixed_damage_increase) && obj.fixed_damage_increase
        result << obj.fixed_damage_increase
      end
    end
    if self.is_a?(Game_Actor)
      self.equips.compact.each do |equip|
        if equip.respond_to?(:fixed_damage_increase) && equip.fixed_damage_increase
          result << equip.fixed_damage_increase
        end
      end
    end
    result
  end
end

#==============================================================================
# ■ Game_Battler
#------------------------------------------------------------------------------
#  计算固定增减伤
#==============================================================================

class Game_Battler < Game_BattlerBase
  #--------------------------------------------------------------------------
  # ● 计算公式
  #--------------------------------------------------------------------------
  def eval_fixed_formula(formula, a, b)
    begin
      a = a
      b = b
      v = $game_variables
      result = eval(formula, binding)
      
      # 将结果转换为整数(四舍五入)
      if result.is_a?(Float)
        result = result.round
      elsif !result.is_a?(Numeric)
        result = 0
      end
      
      result.to_i
    rescue => e
      p "公式错误: #{formula}, 错误: #{e.message}"
      0
    end
  end
  
  #--------------------------------------------------------------------------
  # ● 计算固定减伤总值
  #--------------------------------------------------------------------------
  def calc_fixed_reduce(user, item)
    total = 0
    fixed_reduce_formulas.each do |formula|
      value = eval_fixed_formula(formula, user, self)
      total += value if value > 0
    end
    total
  end
  
  #--------------------------------------------------------------------------
  # ● 计算固定增伤总值
  #--------------------------------------------------------------------------
  def calc_fixed_increase(user, item)
    total = 0
    fixed_increase_formulas.each do |formula|
      value = eval_fixed_formula(formula, user, self)
      total += value if value > 0
    end
    total
  end
  
  #--------------------------------------------------------------------------
  # ● 计算伤害(插入固定增减伤)
  #--------------------------------------------------------------------------
  alias fixed_damage_make_damage_value make_damage_value
  def make_damage_value(user, item)
    fixed_damage_make_damage_value(user, item)
   
    if @result.hp_damage > 0 && @result.hp_drain == 0
      reduce_total = calc_fixed_reduce(user, item)
      increase_total = calc_fixed_increase(user, item)
      net_mod = increase_total - reduce_total
      
      if net_mod != 0
        old_damage = @result.hp_damage
        new_damage = old_damage + net_mod
        new_damage = 1 if new_damage < 1
        @result.hp_damage = new_damage
      end
    end
  end
end[/pre]
在 角色、职业、武器、护甲、敌人、状态 备注添加使用:

<固定增伤>公式</固定增伤>                                 #固定增加,受到的伤害

<固定减伤>公式</固定减伤>                                 #固定减少,受到的伤害

示例:

<固定减伤>100</固定减伤>                                  #固定减少100点伤害

<固定增伤>rand(50) + 50</固定增伤>                   #在50-99之间随机增加伤害

<固定减伤>rand(100) < 50 ? 30 : 10</固定减伤>    #50%几率减伤30,否则10

<固定增伤>a.atk * 2</固定增伤>                           #根据 持有者 攻击力200%,增加伤害

<固定减伤>$game_actors[5].def</固定减伤>          #根据 5号角色 防御力100%,减少伤害

<固定增伤>[v[1], v[5], v[8]].sample</固定增伤>     #在 变量1 变量5 变量8 之间随机

固定增伤减效果公式:

固定增伤:基础伤害 × 暴击伤害 + 固定增伤值

固定减伤:基础伤害 × 暴击伤害 - 固定减伤值

“固定增伤”与“固定减伤”可组合使用

固定增伤 大于 固定减伤:固定增伤值 - 固定减伤值 = 固定增伤值 + 固定增伤效果

固定减伤 大于 固定增伤:固定减伤值 - 固定增伤值 = 固定减伤值 + 固定减伤效果

固定增伤 等于 固定减伤:无事发生

评分

参与人数 1赞 +1 收起 理由
RMVXA + 1 想到了固定减伤的防具

查看全部评分

梦石
0
星屑
5217
在线时间
494 小时
注册时间
2018-6-18
回帖
598

超评测参与

发表于 2026-3-13 20:32:58 | 显示全部楼层
很多肉鸽游戏里的效果,真不错!
回复

使用道具 举报

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

本版积分规则

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

在本版发帖返回顶部