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

Project1

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

[已经解决] 如何为物品设置使用限制

[复制链接]

Lv3.寻梦者

梦石
0
星屑
1529
在线时间
177 小时
注册时间
2017-10-22
帖子
8
跳转到指定楼层
1
发表于 2018-12-16 21:30:22 | 只看该作者 回帖奖励 |倒序浏览 |阅读模式

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

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

x
如何将物品设置为只有装备特定道具的角色才能使用?
有相关的脚本能够做到吗?

Lv4.逐梦者

梦石
1
星屑
14504
在线时间
2086 小时
注册时间
2017-9-28
帖子
662
2
发表于 2018-12-17 14:43:20 | 只看该作者
  1. =begin
  2. #===============================================================================
  3. Title: 自定义使用条件
  4. Author: Hime
  5. Date: Jan 4, 2014
  6. URL: http://himeworks.com/2013/11/26/custom-use-conditions/
  7. --------------------------------------------------------------------------------
  8. ** Change log
  9. Jan 4, 2014
  10.    - allows for "recursive" calls. Recursive calls do not check custom use
  11.      conditions
  12.    - added "Actor" condition
  13. Nov 29, 2013
  14.    - fixed bug where no use conditions caused it to always fail
  15. Nov 26, 2013
  16.    - Initial release
  17. --------------------------------------------------------------------------------   
  18. ** Terms of Use
  19. * Free to use in non-commercial projects
  20. * Contact me for commercial use
  21. * No real support. The script is provided as-is
  22. * Will do bug fixes, but no compatibility patches
  23. * Features may be requested but no guarantees, especially if it is non-trivial
  24. * Credits to Hime Works in your project
  25. * Preserve this header
  26. --------------------------------------------------------------------------------
  27. ** 说明

  28. 本脚本可以为技能/物品设定自定义使用条件
  29. 默认下只有两个武器类型限制条件,使用此脚本后,使用条件还可以是:

  30.    - 角色的职业
  31.    - 已装备的武器
  32.    - 已装备的护甲
  33.    - 已装备的武器类型
  34.    - 已装备的护甲类型
  35.    - 已学会的技能
  36.    - 自身是否附加某个状态
  37.    - 公式, 适用于任何情况
  38.    
  39. 你可以设定多个条件,必须全部满足才能使用技能;也可以:仅满足多个条件中的任意
  40. 一个,就可以使用技能

  41. --------------------------------------------------------------------------------
  42. ** Installation

  43. In the script editor, place this script below Materials and above Main

  44. --------------------------------------------------------------------------------
  45. ** 使用方法

  46. -- 设定使用条件 --

  47. 使用技能/物品备注

  48.    <use conditions>
  49.     类型1: 数值1
  50.     类型2: 数值2
  51.    </use conditions>
  52.    
  53. 详情请参考下面的“参考部分”

  54. 还有一个特殊的“公式”类型,可以让你使用任何可用的公式代码
  55. 以下是可用的变量

  56.    a - 当前角色
  57.    p - 队伍
  58.    t - 敌群
  59.    s - 开关
  60.    v - 变量
  61.    
  62. -- 使用条件组 --

  63. 一个“使用条件组”中包含多种使用条件
  64. 你只需要使用多种上面的备注,它们就都会视为该技能的使用条件

  65. 一个技能可以使用的条件是:至少满足一个使用条件组
  66. 而满足一个使用条件组的条件是:满足组里面所有技能的使用条件
  67. 因此,当技能有多个使用条件组时,只需满足任意一个就可以使用
  68. 如果你被绕晕了,可以看看下面的例子

  69. --------------------------------------------------------------------------------
  70. ** 例子

  71. 假如你有一个技能,有两个使用条件组:

  72. 1. 自身必须附加7号状态,并且装备有2号武器类型的武器
  73. 2. 必须装备有21号武器

  74. 因此,该技能的备注栏里就应该填入:

  75. <use conditions>
  76.    state: 7
  77.    wtype: 2
  78. </use conditions>

  79. <use conditions>
  80.    weapon: 21
  81. </use conditions>

  82. 只要满足任意一个使用条件组,该技能就可以被使用

  83. --------------------------------------------------------------------------------
  84. ** 参考部分

  85. 以下为所有可用的使用条件类型

  86. 类型: weapon
  87. 数值: ID
  88. 说明: 必须装备某id的武器

  89. 类型: armor
  90. 数值: ID
  91. 说明: 必需装备某id的护甲

  92. 类型: wtype
  93. 数值: ID
  94. 说明: 必须装备某id武器类型的武器

  95. 类型: atype
  96. 数值: ID
  97. 说明: 必须装备某id护甲类型的护甲

  98. 类型: actor
  99. 数值: ID
  100. 说明: 使用者必须是某id的角色

  101. 类型: class
  102. 数值: ID
  103. 说明: 使用者必须是某id的职业

  104. 类型: state
  105. 数值: ID
  106. 说明: 使用者身上必须附加有某id的状态

  107. 类型: learned
  108. 数值: ID
  109. 说明: 使用者必须已学会某id的技能

  110. 类型: formula
  111. 数值: ruby 公式代码
  112. 说明: 需要代码返回true


  113. #===============================================================================
  114. =end
  115. $imported = {} if $imported.nil?
  116. $imported["TH_CustomUseConditions"] = true
  117. #===============================================================================
  118. # ** Configuration
  119. #===============================================================================
  120. module TH
  121.   module Custom_Use_Conditions
  122.    
  123.     Regex = /<use[-_ ]conditions>(.*?)<\/use[-_ ]conditions>/im
  124.   end
  125. end
  126. #===============================================================================
  127. # ** Rest of Script
  128. #===============================================================================
  129. module RPG
  130.   class UsableItem < BaseItem
  131.    
  132.     def use_conditions
  133.       load_notetag_use_conditions unless @use_conditions
  134.       return @use_conditions
  135.     end
  136.    
  137.     def load_notetag_use_conditions
  138.       @use_conditions = []
  139.       
  140.       res = self.note.scan(TH::Custom_Use_Conditions::Regex)
  141.       res.each do |result|
  142.         group = Data_UseConditionGroup.new
  143.         result[0].strip.split("\r\n").each do |option|
  144.           case option.strip
  145.           when /weapon:\s*(\d+)\s*/i
  146.             cond = make_custom_use_condition(:weapon, $1.to_i)
  147.           when /armor:\s*(\d+)\s*/i
  148.             cond = make_custom_use_condition(:armor, $1.to_i)
  149.           when /learned:\s*(\d+)\s*/i
  150.             cond = make_custom_use_condition(:learned, $1.to_i)
  151.           when /wtype:\s*(\d+)\s*/i
  152.             cond = make_custom_use_condition(:wtype, $1.to_i)
  153.           when /atype:\s*(\d+)\s*/i
  154.             cond = make_custom_use_condition(:atype, $1.to_i)
  155.           when /actor:\s*(\d+)\s*/i
  156.             cond = make_custom_use_condition(:actor, $1.to_i)
  157.           when /class:\s*(\d+)\s*/i
  158.             cond = make_custom_use_condition(:class, $1.to_i)
  159.           when /state:\s*(\d+)\s*/i
  160.             cond = make_custom_use_condition(:state, $1.to_i)
  161.           when /formula:\s*(.*)\s*/i
  162.             cond = make_custom_use_condition(:formula, $1)
  163.           end
  164.           group.conditions << cond
  165.         end
  166.         @use_conditions << group
  167.       end
  168.     end
  169.    
  170.     def make_custom_use_condition(type, value)
  171.       return Data_UseCondition.new(type, value)
  172.     end
  173.   end
  174. end

  175. class Data_UseConditionGroup
  176.   
  177.   attr_reader :conditions
  178.   
  179.   def initialize
  180.     @conditions = []
  181.   end
  182. end

  183. class Data_UseCondition
  184.   
  185.   attr_reader :type
  186.   attr_reader :value
  187.   
  188.   def initialize(type, value)
  189.     @type = type
  190.     @value = value
  191.   end
  192.   
  193.   def eval_use_condition(a, p=$game_party, t=$game_troop, s=$game_switches, v=$game_variables)
  194.     eval(@value)
  195.   end
  196. end

  197. class Game_BattlerBase
  198.   
  199.   def custom_use_conditions_met?(item)
  200.     true
  201.   end
  202. end

  203. class Game_Actor < Game_Battler
  204.   
  205.   alias :th_use_conditions_usable? :usable?
  206.   def usable?(item)
  207.     bool = th_use_conditions_usable?(item)
  208.     return false unless bool
  209.     unless @check_use_custom_conditions
  210.       @check_use_custom_conditions = true
  211.       bool = custom_use_conditions_met?(item)
  212.       @check_use_custom_conditions = false
  213.     end
  214.     return bool
  215.   end
  216.   
  217.   #-----------------------------------------------------------------------------
  218.   #
  219.   #-----------------------------------------------------------------------------
  220.   alias :th_use_conditions_custom_use_conditions_met? :custom_use_conditions_met?
  221.   def custom_use_conditions_met?(item)
  222.     return false unless th_use_conditions_custom_use_conditions_met?(item)
  223.     return true if item.nil? || item.use_conditions.empty?
  224.     weapons = self.weapons
  225.     armors = self.armors
  226.    
  227.     weapon_ids = weapons.collect {|obj| obj.id}
  228.     wtype_ids = weapons.collect {|obj| obj.wtype_id}
  229.     armor_ids = armors.collect {|obj| obj.id}
  230.     atype_ids = armors.collect {|obj| obj.atype_id}
  231.     state_ids = self.states.collect {|obj| obj.id }

  232.     # for each group
  233.     item.use_conditions.each do |group|      
  234.       # skip if any are not satisfied
  235.       next if group.conditions.any? do |cond|
  236.         value = cond.value
  237.         case cond.type
  238.         when :weapon
  239.           !weapon_ids.include?(value)
  240.         when :armor
  241.           !armor_ids.include?(value)
  242.         when :state
  243.           !state_ids.include?(value)
  244.         when :class
  245.           !(@class_id == value)
  246.         when :actor
  247.           !(@actor_id == value)
  248.         when :wtype
  249.           !wtype_ids.include?(value)
  250.         when :atype
  251.           !atype_ids.include?(value)
  252.         when :learned
  253.           [email protected]?(value)
  254.         when :formula
  255.           !cond.eval_use_condition(self)
  256.         end
  257.       end
  258.       
  259.       # all are satisfied, so this group is satisfied
  260.       return true
  261.     end
  262.     return false
  263.   end
  264. end

  265. class Window_BattleItem < Window_ItemList
  266.   
  267.   #--------------------------------------------------------------------------
  268.   # Overwrite. Item usability is based on actor, not party
  269.   #--------------------------------------------------------------------------
  270.   def include?(item)
  271.     BattleManager.actor.usable?(item)
  272.   end
  273. end
复制代码

评分

参与人数 2星屑 +30 +1 收起 理由
VIPArcher + 30 认可答案
whitedewxiao + 1 精品文章

查看全部评分

VA外站脚本汉化群:226308173   |    部分远古文件备份:https://wwzv.lanzoue.com/b02rac5pc  密码:acgm
回复 支持 2 反对 0

使用道具 举报

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

本版积分规则

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

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

GMT+8, 2024-4-25 10:30

Powered by Discuz! X3.1

© 2001-2013 Comsenz Inc.

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