| 赞 | 274  | 
 
| VIP | 0 | 
 
| 好人卡 | 0 | 
 
| 积分 | 153 | 
 
| 经验 | 515 | 
 
| 最后登录 | 2025-11-3 | 
 
| 在线时间 | 2108 小时 | 
 
 
 
 
 
Lv4.逐梦者 
	- 梦石
 - 1 
 
        - 星屑
 - 14298 
 
        - 在线时间
 - 2108 小时
 
        - 注册时间
 - 2017-9-28
 
        - 帖子
 - 663
 
 
 
 | 
	
- =begin
 
 - #===============================================================================
 
 -  Title: 自定义使用条件
 
 -  Author: Hime
 
 -  Date: Jan 4, 2014
 
 -  URL: http://himeworks.com/2013/11/26/custom-use-conditions/
 
 - --------------------------------------------------------------------------------
 
 -  ** Change log
 
 -  Jan 4, 2014
 
 -    - allows for "recursive" calls. Recursive calls do not check custom use
 
 -      conditions
 
 -    - added "Actor" condition
 
 -  Nov 29, 2013
 
 -    - fixed bug where no use conditions caused it to always fail
 
 -  Nov 26, 2013
 
 -    - Initial release
 
 - --------------------------------------------------------------------------------   
 
 -  ** Terms of Use
 
 -  * Free to use in non-commercial projects
 
 -  * Contact me for commercial use
 
 -  * No real support. The script is provided as-is
 
 -  * Will do bug fixes, but no compatibility patches
 
 -  * Features may be requested but no guarantees, especially if it is non-trivial
 
 -  * Credits to Hime Works in your project
 
 -  * Preserve this header
 
 - --------------------------------------------------------------------------------
 
 -  ** 说明
 
 -  
 
 -  本脚本可以为技能/物品设定自定义使用条件
 
 -  默认下只有两个武器类型限制条件,使用此脚本后,使用条件还可以是: 
 
 -  
 
 -    - 角色的职业
 
 -    - 已装备的武器
 
 -    - 已装备的护甲
 
 -    - 已装备的武器类型
 
 -    - 已装备的护甲类型
 
 -    - 已学会的技能
 
 -    - 自身是否附加某个状态
 
 -    - 公式, 适用于任何情况 
 
 -    
 
 -  你可以设定多个条件,必须全部满足才能使用技能;也可以:仅满足多个条件中的任意
 
 -  一个,就可以使用技能 
 
 -  
 
 - --------------------------------------------------------------------------------
 
 -  ** Installation
 
 -  
 
 -  In the script editor, place this script below Materials and above Main
 
  
- --------------------------------------------------------------------------------
 
 -  ** 使用方法
 
 -  
 
 -  -- 设定使用条件 --
 
 -  
 
 -  使用技能/物品备注
 
 -  
 
 -    <use conditions>
 
 -     类型1: 数值1
 
 -     类型2: 数值2
 
 -    </use conditions>
 
 -    
 
 -  详情请参考下面的“参考部分” 
 
 -  
 
 -  还有一个特殊的“公式”类型,可以让你使用任何可用的公式代码
 
 -  以下是可用的变量
 
 -  
 
 -    a - 当前角色
 
 -    p - 队伍
 
 -    t - 敌群
 
 -    s - 开关
 
 -    v - 变量
 
 -    
 
 -  -- 使用条件组 --
 
 -  
 
 -  一个“使用条件组”中包含多种使用条件
 
 -  你只需要使用多种上面的备注,它们就都会视为该技能的使用条件
 
 -  
 
 -  一个技能可以使用的条件是:至少满足一个使用条件组
 
 -  而满足一个使用条件组的条件是:满足组里面所有技能的使用条件
 
 -  因此,当技能有多个使用条件组时,只需满足任意一个就可以使用
 
 -  如果你被绕晕了,可以看看下面的例子 
 
  
- -------------------------------------------------------------------------------- 
 
 -  ** 例子
 
 -  
 
 -  假如你有一个技能,有两个使用条件组:
 
 -  
 
 -  1. 自身必须附加7号状态,并且装备有2号武器类型的武器 
 
 -  2. 必须装备有21号武器 
 
 -  
 
 -  因此,该技能的备注栏里就应该填入:
 
 -  
 
 -  <use conditions>
 
 -    state: 7
 
 -    wtype: 2
 
 -  </use conditions>
 
 -  
 
 -  <use conditions>
 
 -    weapon: 21
 
 -  </use conditions>
 
 -  
 
 -  只要满足任意一个使用条件组,该技能就可以被使用
 
 -  
 
 - -------------------------------------------------------------------------------- 
 
 -  ** 参考部分
 
 -  
 
 -  以下为所有可用的使用条件类型 
 
 -  
 
 -  类型: weapon
 
 -  数值: ID
 
 -  说明: 必须装备某id的武器 
 
 -  
 
 -  类型: armor
 
 -  数值: ID
 
 -  说明: 必需装备某id的护甲 
 
 -  
 
 -  类型: wtype
 
 -  数值: ID
 
 -  说明: 必须装备某id武器类型的武器 
 
 -  
 
 -  类型: atype
 
 -  数值: ID
 
 -  说明: 必须装备某id护甲类型的护甲
 
 -  
 
 -  类型: actor
 
 -  数值: ID
 
 -  说明: 使用者必须是某id的角色
 
 -  
 
 -  类型: class
 
 -  数值: ID
 
 -  说明: 使用者必须是某id的职业
 
 -  
 
 -  类型: state
 
 -  数值: ID
 
 -  说明: 使用者身上必须附加有某id的状态
 
 -  
 
 -  类型: learned
 
 -  数值: ID
 
 -  说明: 使用者必须已学会某id的技能
 
 -  
 
 -  类型: formula
 
 -  数值: ruby 公式代码
 
 -  说明: 需要代码返回true
 
 -  
 
  
- #===============================================================================
 
 - =end
 
 - $imported = {} if $imported.nil?
 
 - $imported["TH_CustomUseConditions"] = true
 
 - #===============================================================================
 
 - # ** Configuration
 
 - #===============================================================================
 
 - module TH
 
 -   module Custom_Use_Conditions
 
 -     
 
 -     Regex = /<use[-_ ]conditions>(.*?)<\/use[-_ ]conditions>/im
 
 -   end
 
 - end
 
 - #===============================================================================
 
 - # ** Rest of Script
 
 - #===============================================================================
 
 - module RPG
 
 -   class UsableItem < BaseItem
 
 -     
 
 -     def use_conditions
 
 -       load_notetag_use_conditions unless @use_conditions
 
 -       return @use_conditions
 
 -     end
 
 -     
 
 -     def load_notetag_use_conditions
 
 -       @use_conditions = []
 
 -       
 
 -       res = self.note.scan(TH::Custom_Use_Conditions::Regex)
 
 -       res.each do |result|
 
 -         group = Data_UseConditionGroup.new
 
 -         result[0].strip.split("\r\n").each do |option|
 
 -           case option.strip
 
 -           when /weapon:\s*(\d+)\s*/i
 
 -             cond = make_custom_use_condition(:weapon, $1.to_i)
 
 -           when /armor:\s*(\d+)\s*/i
 
 -             cond = make_custom_use_condition(:armor, $1.to_i)
 
 -           when /learned:\s*(\d+)\s*/i
 
 -             cond = make_custom_use_condition(:learned, $1.to_i)
 
 -           when /wtype:\s*(\d+)\s*/i
 
 -             cond = make_custom_use_condition(:wtype, $1.to_i)
 
 -           when /atype:\s*(\d+)\s*/i
 
 -             cond = make_custom_use_condition(:atype, $1.to_i)
 
 -           when /actor:\s*(\d+)\s*/i
 
 -             cond = make_custom_use_condition(:actor, $1.to_i)
 
 -           when /class:\s*(\d+)\s*/i
 
 -             cond = make_custom_use_condition(:class, $1.to_i)
 
 -           when /state:\s*(\d+)\s*/i
 
 -             cond = make_custom_use_condition(:state, $1.to_i)
 
 -           when /formula:\s*(.*)\s*/i
 
 -             cond = make_custom_use_condition(:formula, $1)
 
 -           end
 
 -           group.conditions << cond
 
 -         end
 
 -         @use_conditions << group
 
 -       end
 
 -     end
 
 -     
 
 -     def make_custom_use_condition(type, value)
 
 -       return Data_UseCondition.new(type, value)
 
 -     end
 
 -   end
 
 - end
 
  
- class Data_UseConditionGroup
 
 -   
 
 -   attr_reader :conditions
 
 -   
 
 -   def initialize
 
 -     @conditions = []
 
 -   end
 
 - end
 
  
- class Data_UseCondition
 
 -   
 
 -   attr_reader :type
 
 -   attr_reader :value
 
 -   
 
 -   def initialize(type, value)
 
 -     @type = type
 
 -     @value = value
 
 -   end
 
 -   
 
 -   def eval_use_condition(a, p=$game_party, t=$game_troop, s=$game_switches, v=$game_variables)
 
 -     eval(@value)
 
 -   end
 
 - end
 
  
- class Game_BattlerBase
 
 -   
 
 -   def custom_use_conditions_met?(item)
 
 -     true
 
 -   end
 
 - end
 
  
- class Game_Actor < Game_Battler
 
 -   
 
 -   alias :th_use_conditions_usable? :usable?
 
 -   def usable?(item)
 
 -     bool = th_use_conditions_usable?(item)
 
 -     return false unless bool
 
 -     unless @check_use_custom_conditions
 
 -       @check_use_custom_conditions = true
 
 -       bool = custom_use_conditions_met?(item)
 
 -       @check_use_custom_conditions = false
 
 -     end
 
 -     return bool
 
 -   end
 
 -   
 
 -   #-----------------------------------------------------------------------------
 
 -   #
 
 -   #-----------------------------------------------------------------------------
 
 -   alias :th_use_conditions_custom_use_conditions_met? :custom_use_conditions_met?
 
 -   def custom_use_conditions_met?(item)
 
 -     return false unless th_use_conditions_custom_use_conditions_met?(item)
 
 -     return true if item.nil? || item.use_conditions.empty?
 
 -     weapons = self.weapons
 
 -     armors = self.armors
 
 -     
 
 -     weapon_ids = weapons.collect {|obj| obj.id}
 
 -     wtype_ids = weapons.collect {|obj| obj.wtype_id}
 
 -     armor_ids = armors.collect {|obj| obj.id}
 
 -     atype_ids = armors.collect {|obj| obj.atype_id}
 
 -     state_ids = self.states.collect {|obj| obj.id }
 
  
-     # for each group
 
 -     item.use_conditions.each do |group|      
 
 -       # skip if any are not satisfied
 
 -       next if group.conditions.any? do |cond|
 
 -         value = cond.value
 
 -         case cond.type
 
 -         when :weapon
 
 -           !weapon_ids.include?(value)
 
 -         when :armor
 
 -           !armor_ids.include?(value)
 
 -         when :state
 
 -           !state_ids.include?(value)
 
 -         when :class
 
 -           !(@class_id == value)
 
 -         when :actor
 
 -           !(@actor_id == value)
 
 -         when :wtype
 
 -           !wtype_ids.include?(value)
 
 -         when :atype
 
 -           !atype_ids.include?(value)
 
 -         when :learned
 
 -           [email protected]?(value)
 
 -         when :formula
 
 -           !cond.eval_use_condition(self)
 
 -         end
 
 -       end
 
 -       
 
 -       # all are satisfied, so this group is satisfied
 
 -       return true
 
 -     end
 
 -     return false
 
 -   end
 
 - end
 
  
- class Window_BattleItem < Window_ItemList
 
 -   
 
 -   #--------------------------------------------------------------------------
 
 -   # Overwrite. Item usability is based on actor, not party
 
 -   #--------------------------------------------------------------------------
 
 -   def include?(item)
 
 -     BattleManager.actor.usable?(item)
 
 -   end
 
 - end
 
  复制代码 |   
 
评分
- 
查看全部评分
 
 
 
 
 
 |