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

Project1

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

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

[复制链接]

Lv3.寻梦者

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

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

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

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

RUBY 代码复制
  1. #==============================================================================
  2. # $SDrop$
  3. # 固定增减伤效果 By猫易箱
  4. #------------------------------------------------------------------------------
  5. # 在 角色、职业、武器、护甲、敌人、状态 备注添加使用:
  6. #
  7. # <固定增伤>公式</固定增伤>
  8. #
  9. # 例如:
  10. # <固定增伤>50</固定增伤> 受到伤害时,固定增加50点伤害
  11. #
  12. # <固定减伤>公式</固定减伤>
  13. #
  14. # 例如:
  15. # <固定减伤>a.def * 1</固定减伤> 按自身100%的防御力,减少受到伤害
  16. #==============================================================================
  17.  
  18. $imported = {} if $imported.nil?
  19. $imported["SDrop_FixedDamage"] = true
  20.  
  21. #==============================================================================
  22. # ■ RPG::BaseItem
  23. #------------------------------------------------------------------------------
  24. #  为所有基础物品类添加备注解析方法
  25. #==============================================================================
  26.  
  27. class RPG::BaseItem
  28.   #--------------------------------------------------------------------------
  29.   # ● 获取固定减伤公式
  30.   #--------------------------------------------------------------------------
  31.   def fixed_damage_reduce
  32.     @fixed_damage_reduce ||= load_fixed_damage_reduce
  33.   end
  34.  
  35.   def load_fixed_damage_reduce
  36.     self.note =~ /<固定减伤>(.+?)<\/固定减伤>/m ? $1.strip : nil
  37.   end
  38.  
  39.   #--------------------------------------------------------------------------
  40.   # ● 获取固定增伤公式
  41.   #--------------------------------------------------------------------------
  42.   def fixed_damage_increase
  43.     @fixed_damage_increase ||= load_fixed_damage_increase
  44.   end
  45.  
  46.   def load_fixed_damage_increase
  47.     self.note =~ /<固定增伤>(.+?)<\/固定增伤>/m ? $1.strip : nil
  48.   end
  49. end
  50.  
  51. #==============================================================================
  52. # ■ Game_BattlerBase
  53. #------------------------------------------------------------------------------
  54. #  收集固定增减伤公式
  55. #==============================================================================
  56.  
  57. class Game_BattlerBase
  58.   #--------------------------------------------------------------------------
  59.   # ● 获取所有固定减伤公式
  60.   #--------------------------------------------------------------------------
  61.   def fixed_reduce_formulas
  62.     result = []
  63.     feature_objects.each do |obj|
  64.       if obj.respond_to?(:fixed_damage_reduce) && obj.fixed_damage_reduce
  65.         result << obj.fixed_damage_reduce
  66.       end
  67.     end
  68.     if self.is_a?(Game_Actor)
  69.       self.equips.compact.each do |equip|
  70.         if equip.respond_to?(:fixed_damage_reduce) && equip.fixed_damage_reduce
  71.           result << equip.fixed_damage_reduce
  72.         end
  73.       end
  74.     end
  75.     result
  76.   end
  77.  
  78.   #--------------------------------------------------------------------------
  79.   # ● 获取所有固定增伤公式
  80.   #--------------------------------------------------------------------------
  81.   def fixed_increase_formulas
  82.     result = []
  83.     feature_objects.each do |obj|
  84.       if obj.respond_to?(:fixed_damage_increase) && obj.fixed_damage_increase
  85.         result << obj.fixed_damage_increase
  86.       end
  87.     end
  88.     if self.is_a?(Game_Actor)
  89.       self.equips.compact.each do |equip|
  90.         if equip.respond_to?(:fixed_damage_increase) && equip.fixed_damage_increase
  91.           result << equip.fixed_damage_increase
  92.         end
  93.       end
  94.     end
  95.     result
  96.   end
  97. end
  98.  
  99. #==============================================================================
  100. # ■ Game_Battler
  101. #------------------------------------------------------------------------------
  102. #  计算固定增减伤
  103. #==============================================================================
  104.  
  105. class Game_Battler < Game_BattlerBase
  106.   #--------------------------------------------------------------------------
  107.   # ● 计算公式
  108.   #--------------------------------------------------------------------------
  109.   def eval_fixed_formula(formula, a, b)
  110.     begin
  111.       a = a
  112.       b = b
  113.       v = $game_variables
  114.       result = eval(formula, binding)
  115.  
  116.       # 将结果转换为整数(四舍五入)
  117.       if result.is_a?(Float)
  118.         result = result.round
  119.       elsif !result.is_a?(Numeric)
  120.         result = 0
  121.       end
  122.  
  123.       result.to_i
  124.     rescue => e
  125.       p "公式错误: #{formula}, 错误: #{e.message}"
  126.       0
  127.     end
  128.   end
  129.  
  130.   #--------------------------------------------------------------------------
  131.   # ● 计算固定减伤总值
  132.   #--------------------------------------------------------------------------
  133.   def calc_fixed_reduce(user, item)
  134.     total = 0
  135.     fixed_reduce_formulas.each do |formula|
  136.       value = eval_fixed_formula(formula, user, self)
  137.       total += value if value > 0
  138.     end
  139.     total
  140.   end
  141.  
  142.   #--------------------------------------------------------------------------
  143.   # ● 计算固定增伤总值
  144.   #--------------------------------------------------------------------------
  145.   def calc_fixed_increase(user, item)
  146.     total = 0
  147.     fixed_increase_formulas.each do |formula|
  148.       value = eval_fixed_formula(formula, user, self)
  149.       total += value if value > 0
  150.     end
  151.     total
  152.   end
  153.  
  154.   #--------------------------------------------------------------------------
  155.   # ● 计算伤害(插入固定增减伤)
  156.   #--------------------------------------------------------------------------
  157.   alias fixed_damage_make_damage_value make_damage_value
  158.   def make_damage_value(user, item)
  159.     fixed_damage_make_damage_value(user, item)
  160.  
  161.     if @result.hp_damage > 0 && @result.hp_drain == 0
  162.       reduce_total = calc_fixed_reduce(user, item)
  163.       increase_total = calc_fixed_increase(user, item)
  164.       net_mod = increase_total - reduce_total
  165.  
  166.       if net_mod != 0
  167.         old_damage = @result.hp_damage
  168.         new_damage = old_damage + net_mod
  169.         new_damage = 1 if new_damage < 1
  170.         @result.hp_damage = new_damage
  171.       end
  172.     end
  173.   end
  174. end

在 角色、职业、武器、护甲、敌人、状态 备注添加使用:

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

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

示例:

<固定减伤>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 想到了固定减伤的防具

查看全部评分

Lv4.逐梦者

梦石
0
星屑
4991
在线时间
493 小时
注册时间
2018-6-18
帖子
631
2
发表于 2026-3-13 20:32:58 | 只看该作者
很多肉鸽游戏里的效果,真不错!
回复 支持 反对

使用道具 举报

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

本版积分规则

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

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

GMT+8, 2026-6-4 13:29

Powered by Discuz! X3.1

© 2001-2013 Comsenz Inc.

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