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

Project1

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

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

[复制链接]

Lv5.捕梦者

梦石
0
星屑
24252
在线时间
5037 小时
注册时间
2016-3-8
帖子
1618
跳转到指定楼层
1
发表于 2020-11-14 20:55:47 | 只看该作者 回帖奖励 |倒序浏览 |阅读模式

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

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

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

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

因为def params冲突了, 能整合一下么?
RUBY 代码复制
  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.  
  23.  This script allows you to use formulas to define parameters for weapons and
  24.  armors.
  25.  
  26.  For example, if you were using a script that provided equip levels, you can
  27.  define a formula that uses the level to determine the weapon's parameters.
  28.  
  29.  All attributes that the equip holds can be referenced.
  30.  Formula variables are also available to use.
  31.  
  32. --------------------------------------------------------------------------------
  33.  ** Installation
  34.  
  35.  Place this script below Materials and above Main
  36.  
  37. --------------------------------------------------------------------------------
  38.  ** Usage
  39.  
  40.  To specify a parameter formula, note-tag a weapon or armor with
  41.  
  42.    <param formula: TYPE>
  43.      FORMULA
  44.    </param formula>
  45.    
  46.  Where the TYPE is one of
  47.  
  48.    mhp - Max HP
  49.    mmp - Max MP
  50.    atk - Attack Power
  51.    def - Defense Power
  52.    mat - Magic Attack Power
  53.    mdf - Magic Defense Power
  54.    agi - Agility
  55.    luk - Luck
  56.  
  57.  The formula can be any valid formula that returns a number
  58.  The following formula variables are available
  59.  
  60.    p - game party
  61.    t - game troop
  62.    s - game switches
  63.    v - game variables
  64.  
  65. #===============================================================================
  66. =end
  67. $imported = {} if $imported.nil?
  68. $imported[:TH_EquipParamFormulas] = true
  69. #===============================================================================
  70. # ** Configuration
  71. #===============================================================================
  72. module TH
  73.   module Equip_Param_Formulas
  74.     Ext_Regex = /<param[-_ ]formula:\s*(\w+)\s*>(.*?)<\/param[-_ ]formula>/im
  75.  
  76.     Param_Table = {
  77.       :mhp => 0,
  78.       :mmp => 1,
  79.       :atk => 2,
  80.       :def => 3,
  81.       :mat => 4,
  82.       :mdf => 5,
  83.       :agi => 6,
  84.       :luk => 7
  85.     }
  86.   end
  87. end
  88. #===============================================================================
  89. # ** Rest of Script
  90. #===============================================================================
  91. module RPG
  92.   class EquipItem
  93.  
  94.     #---------------------------------------------------------------------------
  95.     # Not the most efficient way to do it but it preserves the interface
  96.     #---------------------------------------------------------------------------
  97.     def params
  98.       load_notetag_param_formulas unless @param_formulas_checked
  99.       return @param_formulas.collect {|f| eval_param_formula(f)}
  100.     end
  101.  
  102.     def eval_param_formula(formula, p=$game_party, s=$game_switches, t=$game_troop, v=$game_variables)
  103.       eval(formula)
  104.     end
  105.  
  106.     def load_notetag_param_formulas
  107.       @param_formulas_checked = true
  108.       @param_formulas = @params.map {|val| val.to_s }
  109.       results = self.note.scan(TH::Equip_Param_Formulas::Ext_Regex)
  110.       results.each do |res|
  111.         type = res[0].strip.downcase.to_sym
  112.         id = TH::Equip_Param_Formulas::Param_Table[type]
  113.         formula = res[1]
  114.         @param_formulas[id] = formula
  115.       end
  116.     end
  117.   end
  118. end

RUBY 代码复制
  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

Lv5.捕梦者

梦石
0
星屑
24252
在线时间
5037 小时
注册时间
2016-3-8
帖子
1618
2
 楼主| 发表于 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
复制代码
回复 支持 反对

使用道具 举报

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

本版积分规则

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

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

GMT+8, 2024-4-20 16:39

Powered by Discuz! X3.1

© 2001-2013 Comsenz Inc.

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