=begin
==============================================================================
** FP Item and Skill Restrictions
Author: Hime
Version: 1.1
Date: May 13, 2012
------------------------------------------------------------------------------
** Change log
1.1 May 13
-added support for name requirements
-removed redundant method definitions
1.0 May 12
-Initial release
------------------------------------------------------------------------------
This script adds restrictions to skill and item usage.
The following restrictions are available
-state (state IDs)
-armor (armor IDs)
-weapon (weapon IDs)
-atype (armor types)
-wtype (weapon types)
-ctype (class types)
-ename (equip name)
-wname (weapon name)
-aname (armor name)
-cname (class name)
Equip means that you must have a specific
equip on you. Can be armor or weapon
You can specify generic equip types,
for armors or weapons
You can specify what state must be active
You can specify that one of your equips
must have a certain name
You can specify that only certain classes
can use it, or if the class name contains
a specific word
The same applies to items.
==============================================================================
=end
module Feature_Plus
module Skill_Restrict
# Feature code, do not change
FEATURE_SKILL_RESTRICT = 101
# Data_id's - for reference only
ARMOR_EQUIP = 0
WEAPON_EQUIP = 1
ATYPE_EQUIP = 2
WTYPE_EQUIP = 3
STATE_ACTIVE = 4
EQUIP_ENAME = 5
EQUIP_ANAME = 6
EQUIP_WNAME = 7
CLASS_TYPE = 8
CLASS_NAME = 9
SR_ARMOR = //i
SR_ATYPE = //i
SR_WEAPON = //i
SR_WTYPE = //i
SR_STATE = //i
SR_CTYPE = //i
SR_ENAME = //i
SR_ANAME = //i
SR_WNAME = //i
SR_CNAME = //i
end
end
#==============================================================================
# ** RPG classes
#------------------------------------------------------------------------------
# Load notetags
#==============================================================================
module RPG
class UsableItem < BaseItem
include Feature_Plus::Skill_Restrict
alias :fp_sr_initialize_rpg_usables :initialize
def initialize
fp_sr_initialize_rpg_usables
fp_sr_load_notetags
end
def add_sr_name_feature(name, data_id)
add_feature(FEATURE_SKILL_RESTRICT, data_id, name.downcase)
end
def add_sr_feature(values, data_id)
values.collect {|equip_id|
add_feature(FEATURE_SKILL_RESTRICT, data_id, equip_id)
}
end
def add_feature(code, data_id, value=0)
RPG::BaseItem::Feature.new(code, data_id, value)
end
def fp_sr_load_notetags
self.note.split(/[\r\n]+/).each do |line|
case line
when SR_ARMOR
values = line.scan(/\d+/).map(&:to_i)
@features.concat(add_sr_feature(values, ARMOR_EQUIP))
when SR_ATYPE
values = line.scan(/\d+/).map(&:to_i)
@features.concat(add_sr_feature(values, ATYPE_EQUIP))
when SR_WEAPON
values = line.scan(/\d+/).map(&:to_i)
@features.concat(add_sr_feature(values, WEAPON_EQUIP))
when SR_WTYPE
values = line.scan(/\d+/).map(&:to_i)
@features.concat(add_sr_feature(values, WTYPE_EQUIP))
when SR_STATE
values = line.scan(/\d+/).map(&:to_i)
@features.concat(add_sr_feature(values, STATE_ACTIVE))
when SR_CTYPE
values = line.scan(/\d+/).map(&:to_i)
@features.concat(add_sr_feature(values, CLASS_TYPE))
when SR_ENAME
@features << add_sr_name_feature($1, EQUIP_ENAME)
when SR_ANAME
@features << add_sr_name_feature($1, EQUIP_ANAME)
when SR_WNAME
@features << add_sr_name_feature($1, EQUIP_WNAME)
when SR_CNAME
@features << add_sr_name_feature($1, CLASS_NAME)
end
end
end
end
end
#==============================================================================
# ** DataManager
#------------------------------------------------------------------------------
# Initialize custom notetags
#==============================================================================
module DataManager
class << self
alias tsuki_fp_sr_init init
end
def self.init
tsuki_fp_sr_init
load_notetags_fp_skill_restrict
end
def self.load_notetags_fp_skill_restrict
groups = [$data_skills, $data_items]
for group in groups
for obj in group
next if obj.nil?
obj.fp_sr_load_notetags
end
end
end
end
class Game_BattlerBase
include Feature_Plus::Skill_Restrict
def fpsr_skill_features(skill, code, data_id)
skill.features.select {|ft| ft.code == code && ft.data_id == data_id}
end
def fpsr_condition_required(skill, data_id)
fpsr_skill_features(skill, FEATURE_SKILL_RESTRICT, data_id).collect {|skill| skill.value}
end
#--------------------------------------------------------------------------
# * Logical OR condition: as long as any one of the requirements are met
#--------------------------------------------------------------------------
def sr_require_ok?(ids, skill, data_id)
values = fpsr_condition_required(skill, data_id)
return true if values.empty?
return values.any?{|req| ids.include?(req)}
end
def sr_names_ok?(names, skill, data_id)
reqs = fpsr_condition_required(skill, data_id)
return true if reqs.empty?
req_str = reqs[0]
return names.any?{|str| str.include?(req_str)}
end
end
class Game_Actor < Game_Battler
#--------------------------------------------------------------------------
# * Add more conditions to actor skill and item usage
#--------------------------------------------------------------------------
def skill_conditions_met?(skill)
fpsr_conditions_met?(skill) && super
end
def item_conditions_met?(item)
fpsr_conditions_met?(item) && super
end
#--------------------------------------------------------------------------
# * FP:SR main condition check
#--------------------------------------------------------------------------
def fpsr_conditions_met?(skill)
return false unless sr_require_ok?(armor_ids, skill, ARMOR_EQUIP)
return false unless sr_require_ok?(atype_ids, skill, ATYPE_EQUIP)
return false unless sr_require_ok?(weapon_ids, skill, WEAPON_EQUIP)
return false unless sr_require_ok?(wtype_ids, skill, WTYPE_EQUIP)
return false unless sr_require_ok?(state_ids, skill, STATE_ACTIVE)
return false unless sr_require_ok?([self.class], skill, CLASS_TYPE)
return false unless sr_names_ok?(equip_names, skill, EQUIP_ENAME)
return false unless sr_names_ok?(weapon_names, skill, EQUIP_ANAME)
return false unless sr_names_ok?(armor_names, skill, EQUIP_WNAME)
return false unless sr_names_ok?([self.class.name.downcase], skill, CLASS_NAME)
return true
end
#--------------------------------------------------------------------------
# * Convenience methods
#--------------------------------------------------------------------------
def armor_ids
@equips.select {|item| item.is_armor? }.collect {|item| item.item_id }
end
def atype_ids
armors.collect {|armor| armor.atype_id}
end
def weapon_ids
@equips.select {|item| item.is_weapon? }.collect {|item| item.item_id}
end
def armor_names
armor_ids.collect {|id| $data_armors[id].name.downcase}
end
def weapon_names
weapon_ids.collect {|id| $data_weapons[id].name.downcase}
end
def wtype_ids
weapons.collect {|weapon| weapon.wtype_id}
end
def state_ids
states.collect {|state| state.id}
end
def equip_names
armor_names + weapon_names
end
end
#==============================================================================
# I need the item_id ...
#==============================================================================
class Game_BaseItem
attr_reader :item_id
end