查看: 5372|回复: 1

[已经解决] 这两个与装备属性有关的脚本, 如何将其效果整合?

[复制链接]
梦石
0
星屑
30103
在线时间
5741 小时
注册时间
2016-3-8
回帖
1662
发表于 2020-11-14 20:55:47 | 显示全部楼层 |阅读模式

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

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

×
本帖最后由 alexncf125 于 2020-11-14 21:08 编辑

第一个能自动调整装备属性
第二个能手动调整装备属性

因为def params冲突了, 能整合一下么?
  1. =begin
  2. #===============================================================================
  3. Title: Equip Param Formulas
  4. Author: Hime
  5. Date: Mar 15, 2014
  6. URL: [url]http://www.himeworks.com/2014/03/15/equip-param-formulas/[/url]
  7. --------------------------------------------------------------------------------
  8. ** Change log
  9. Mar 15, 2014
  10.    - Initial release
  11. --------------------------------------------------------------------------------   
  12. ** Terms of Use
  13. * Free to use in non-commercial projects
  14. * Contact me for commercial use
  15. * No real support. The script is provided as-is
  16. * Will do bug fixes, but no compatibility patches
  17. * Features may be requested but no guarantees, especially if it is non-trivial
  18. * Credits to Hime Works in your project
  19. * Preserve this header
  20. --------------------------------------------------------------------------------
  21. ** Description

  22. This script allows you to use formulas to define parameters for weapons and
  23. armors.

  24. For example, if you were using a script that provided equip levels, you can
  25. define a formula that uses the level to determine the weapon's parameters.

  26. All attributes that the equip holds can be referenced.
  27. Formula variables are also available to use.

  28. --------------------------------------------------------------------------------
  29. ** Installation

  30. Place this script below Materials and above Main

  31. --------------------------------------------------------------------------------
  32. ** Usage

  33. To specify a parameter formula, note-tag a weapon or armor with

  34.    <param formula: TYPE>
  35.      FORMULA
  36.    </param formula>
  37.    
  38. Where the TYPE is one of

  39.    mhp - Max HP
  40.    mmp - Max MP
  41.    atk - Attack Power
  42.    def - Defense Power
  43.    mat - Magic Attack Power
  44.    mdf - Magic Defense Power
  45.    agi - Agility
  46.    luk - Luck

  47. The formula can be any valid formula that returns a number
  48. The following formula variables are available

  49.    p - game party
  50.    t - game troop
  51.    s - game switches
  52.    v - game variables

  53. #===============================================================================
  54. =end
  55. $imported = {} if $imported.nil?
  56. $imported[:TH_EquipParamFormulas] = true
  57. #===============================================================================
  58. # ** Configuration
  59. #===============================================================================
  60. module TH
  61.   module Equip_Param_Formulas
  62.     Ext_Regex = /<param[-_ ]formula:\s*(\w+)\s*>(.*?)<\/param[-_ ]formula>/im
  63.    
  64.     Param_Table = {
  65.       :mhp => 0,
  66.       :mmp => 1,
  67.       :atk => 2,
  68.       :def => 3,
  69.       :mat => 4,
  70.       :mdf => 5,
  71.       :agi => 6,
  72.       :luk => 7
  73.     }
  74.   end
  75. end
  76. #===============================================================================
  77. # ** Rest of Script
  78. #===============================================================================
  79. module RPG
  80.   class EquipItem
  81.    
  82.     #---------------------------------------------------------------------------
  83.     # Not the most efficient way to do it but it preserves the interface
  84.     #---------------------------------------------------------------------------
  85.     def params
  86.       load_notetag_param_formulas unless @param_formulas_checked
  87.       return @param_formulas.collect {|f| eval_param_formula(f)}
  88.     end
  89.    
  90.     def eval_param_formula(formula, p=$game_party, s=$game_switches, t=$game_troop, v=$game_variables)
  91.       eval(formula)
  92.     end
  93.    
  94.     def load_notetag_param_formulas
  95.       @param_formulas_checked = true
  96.       @param_formulas = @params.map {|val| val.to_s }
  97.       results = self.note.scan(TH::Equip_Param_Formulas::Ext_Regex)
  98.       results.each do |res|
  99.         type = res[0].strip.downcase.to_sym
  100.         id = TH::Equip_Param_Formulas::Param_Table[type]
  101.         formula = res[1]
  102.         @param_formulas[id] = formula
  103.       end
  104.     end
  105.   end
  106. end
复制代码
  1.     #随意增减装备属性的小插件
  2.     #
  3.     # 脚本说明
  4.     #
  5.     #  属性ID介绍
  6.     #0: 体力上限
  7.     #1: 魔力上限
  8.     #2: 物理攻击
  9.     #3: 物理防御
  10.     #4: 魔法攻击
  11.     #5: 魔法防御
  12.     #6: 敏捷值
  13.     #7: 幸运值
  14.     #
  15.     #装备类型: 武器【:weapon】    护甲【:armor】
  16.     #
  17.     #$game_system.params(武器类型,道具ID,属性ID,属性增减数值)
  18.     #脚本范例↓↓
  19.     #$game_system.params(:weapon,1,3,100)  #1号武器物理防御属性增加100点
  20.     #$game_system.params(:armor,1,3,-100)  #1号护甲物理防御属性降低100点
  21.     #
  22.     #顺便获取装备属性是可以直接调用系统默认方法 ↓
  23.     #$data_armors[道具ID].params[属性ID]  # 护甲
  24.     #$data_weapons[道具ID].params[属性ID]  # 武器
  25.     #属性ID与上方脚本说明相同
  26.     #==============================================================================
  27.     # ■ Game_System
  28.     #==============================================================================
  29.     class Game_System
  30.      alias new_initialize initialize
  31.      def initialize
  32.        new_initialize
  33.        @weapon = Array.new($data_weapons.size) {[0]*8}
  34.        @armor  = Array.new($data_armors.size) {[0]*8}
  35.      end
  36.      #--------------------------------------------------------------------------
  37.      # ● 额外属性获取方法
  38.      #--------------------------------------------------------------------------
  39.      def params(lei,id,params,par=0)
  40.       return @weapon[id][params] = @weapon[id][params] + par if lei==:weapon
  41.       return @armor[id][params] = @armor[id][params] + par  if lei==:armor
  42.      end  
  43.     end
  44.     #==============================================================================
  45.     # ■ RPG::EquipItem
  46.     #==============================================================================
  47.     class RPG::EquipItem < RPG::BaseItem
  48.      #--------------------------------------------------------------------------
  49.      # ● 获取武器与护甲的能力数组
  50.      #--------------------------------------------------------------------------
  51.      def params
  52.       data=[]
  53.       @params.size.times {|i| self.is_a?(RPG::Weapon) ?
  54.       data.push(@params[i]+$game_system.params(:weapon,@id,i)) :
  55.       data.push(@params[i]+$game_system.params(:armor,@id,i)) }
  56.       return data
  57.      end
  58.     end
复制代码
梦石
0
星屑
30103
在线时间
5741 小时
注册时间
2016-3-8
回帖
1662
 楼主| 发表于 2020-11-15 09:29:20 | 显示全部楼层
已自行解決, 贴一下解決方法~
  1. def params
  2.   load_notetag_param_formulas unless @param_formulas_checked
  3.   @param_formula = @param_formulas.collect {|f| eval_param_formula(f)}          #加了这句
  4.   return @param_formulas.collect {|f| eval_param_formula(f)}
  5. end
复制代码

  1. class RPG::EquipItem < RPG::BaseItem
  2.   #--------------------------------------------------------------------------
  3.   # ● 获取武器与护甲的能力数组
  4.   #--------------------------------------------------------------------------
  5.   alias new_params params          #加了这句
  6.   def params
  7.     new_params          #加了这句
  8.     data=[]
  9.     #以下三句把@params改成了@param_formula
  10.     @param_formula.size.times {|i| self.is_a?(RPG::Weapon) ?
  11.     data.push(@param_formula[i]+$game_system.params(:weapon,@id,i)) :
  12.     data.push(@param_formula[i]+$game_system.params(:armor,@id,i)) }
  13.     return data
  14.   end
  15. end
复制代码
回复

使用道具 举报

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

本版积分规则

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

在本版发帖返回顶部