Jump to content
PhoenixSoul

Lost Script Reuploads (for those of us who got on the train late)

Recommended Posts

Alright, so here's the skivvy on lost scripts.

 

It even says in most of them so link back to the original thread, don't repost, etcetera, but in times like these, when Dropbox decides to kill a download for their asinine reasons, or if a script writer decides to f*ck off their project, or whatever, there has to be a workaround. The Wayback Machine (https://archive.org) is awesome, but not foolproof (since it is user-driven and must be used by the people wanting to save these webpages for later perusing), so, is there an alternate method?

 

Yes, yes there is; you take these lost snippets of wonderful and useful information...

 

And group them all together, which I am doing here.

 

I will add to this list as I come across dead script links, and (hopefully) find ways around them.

 

I will also repoint to the original post, if possible. (Don't expect this though.)

 

Anyway, and without further ado...Scripts!

 

 

Mr.Bubblewand - Blood Magic (victim of Asinine Dropbox)

 

 

 

# â•”â•â•â•â•â•â•â•â•â•â•â•â•â•â•â•â•â•â•â•â•â•â•â•â•â•â•â•â•â•â•â•â•â•â•â•â•â•â•â•â•â•â•â•â•â•â•â•â•â•â•â•â•â•â•â•â•¤â•â•â•â•â•â•â•¤â•â•â•â•â•â•â•â•â•â•â•â•—
# ║ Blood Magic │ v1.1 │ (1/04/12) ║
# â•šâ•â•â•â•â•â•â•â•â•â•â•â•â•â•â•â•â•â•â•â•â•â•â•â•â•â•â•â•â•â•â•â•â•â•â•â•â•â•â•â•â•â•â•â•â•â•â•â•â•â•â•â•â•â•â•â•§â•â•â•â•â•â•â•§â•â•â•â•â•â•â•â•â•â•â•â•
# Script by:
# Mr. Bubble ( http://mrbubblewand.wordpress.com/ )
# Thanks to:
# Yanfly, whose scripts and designs I heavily referenced in order
# to learn RGSS3 and make this script
# VXA Help File
#--------------------------------------------------------------------------
# - What is Blood Magic? / What are Blood Mages?
#
# "Every mage can feel the dark lure of blood magic. Originally
# learned from demons, these dark rites tap into the power of blood,
# converting life into mana and giving the mage command over the minds
# of others. Such power comes with a price, though; a blood mage must
# sacrifice his/her own health, or the health of allies, to fuel these
# abilities." - Dragon Age: Origins, Blood Mage specialization description
#
# Blood magic is a form of magic that uses the power inherent in blood to
# fuel spellcasting. To put it simply, Blood Magic is the ability to use HP
# to cast skills instead of MP. This essentially increases the battler's
# effective MP.
#
# - What makes Blood Magic different from giving skills a simple HP cost?
#
# The main reason why Blood Magic is incredibly effective in the Dragon Age
# series is the option to have the MP to HP conversion ratio become
# even more efficient through passive skills or equipment bonuses. However,
# these pieces of gear were generally hard to come by.
#
# Blood Magic MP to HP conversions are done from a 1:x MP to HP ratio
# where x is the total blood magic bonus value of the caster. This means that
# the higher the bonus, the more "effective MP" the battler potentially has.
#
# For example, if the caster's Blood Magic MP to HP ratio is 3:1 and the
# caster has 30 health, the battler's "effective MP" pool becomes 90.
#
# - Does this mean battlers can just heal themselves for infinite HP?
#
# Not necessarily. In the Dragon Age series, Blood Magic is a sustained
# state that can be freely activated and deactivated by the user. When
# activated, the user gains a significant penalty to conventional healing.
# In Dragon Age: Origins, the penalty is 90% reduced healing. In
# Dragon Age II, the user cannot be healed at all except through
# very specific means. VX Ace already has built-in options to
# change recovery effect rates.
#
# Keep in mind that in the Dragon Age series, the maximum Health and Mana
# values for player characters were relatively small, never exceeding three
# digits each. Spell costs were also relatively high. Using the default Blood
# Magic settings in this script with the default VX Ace database
# values/settings is not recommended.
#
# Many of the Blood Magic mechanics provided in this script go beyond what
# was allowed in the Dragon Age series. It is up to developers to choose how
# close they wish to stick to the source material.
#
# How balanced Blood Magic can be in a game is left up to the developer.
#--------------------------------------------------------------------------
# ++ Changelog ++
#--------------------------------------------------------------------------
# v1.1 : Bugfix update. (1/04/2012)
# v1.0 : Initial release. (1/03/2012)
#--------------------------------------------------------------------------
# ++ Installation ++
#--------------------------------------------------------------------------
# Install this script in the Materials section in your project's
# script editor.
#=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
# ++ Notetags ++
#=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
# The following Notetags are for Actors, Classes, Weapons, Armors, Enemies,
# and States:
#
#
# Activates Blood Magic for the given Actor, Class, or Enemy. If the Blood
# Magic tag is applied to a piece of equipment, it will activate Blood Magic
# when it is equipped. If the Blood Magic tag is applied to a State, it
# will activate Blood Magic when the battler is inflicted by it.
#
# Be very cautious with what you add this tag to especially Actors and
# Classes since they will have no way to deactivate innate Blood Magic.
#
#
#
# Provides a bonus to the battler's Blood Magic Ratio for MP to HP
# conversions. n can be floating point values (ex. 1.3, 0.5, etc.).
#--------------------------------------------------------------------------
# The following Notetags are for Skills and Items only:
#
#
# Forces the skill or item to only be usable when the battler has
# Blood Magic activated.
#
#
# Allows the MP skill to ignore whenever Blood Magic is activated,
# allowing the skill to stick to its original MP cost. Tag has no
# effect on items.
#
#
# Allows the skill or item to ignore the Blood Magic healing penalty
# on the target. Use with discretion.
#--------------------------------------------------------------------------
# ++ Blood Magic Formula ++
#--------------------------------------------------------------------------
# This is a simplified internal formula used to calculate Blood Magic
# costs.
#
# hp_cost = (mp_cost * BASE_MP_MULTIPLIER) / blood_magic_bonuses
#
# Floating point value results are always rounded up.
#--------------------------------------------------------------------------
# ++ Compatibility ++
#--------------------------------------------------------------------------
# This script does not overwrite any default VXA methods. All default
# methods modified in this script are aliased.
#
# This script has built-in compatibility with the following scripts:
# - Yanfly Engine Ace - Skill Cost Manager
#
# Requests for compatibility with other scripts are welcome.
#--------------------------------------------------------------------------
# ++ Terms and Conditions ++
#--------------------------------------------------------------------------
# Please do not repost this script elsewhere without permission. Newest
# versions of this script can be found at http://mrbubblewand.wordpress.com/
#==============================================================================

$imported = {} if $imported.nil?
$imported["BubsBloodMagic"] = true

#==========================================================================
# ++ START OF USER CUSTOMIZATION MODULE ++
#==========================================================================
module Bubs
#==========================================================================
# ++ Blood Magic Settings
#==========================================================================
module BloodMagic

#--------------------------------------------------------------------------
# Global Base Blood Magic Ratio
#--------------------------------------------------------------------------
# This value sets the global base conversion ratio for MP to HP.
BASE_BMR = 1.0

#--------------------------------------------------------------------------
# Blood Magic Ratio Bonus
#--------------------------------------------------------------------------
# These values adds a set Blood Magic Ratio bonus to actors and enemies.
ACTOR_BMR_BONUS = 0.0 # BMR Bonus for all actors
ENEMY_BMR_BONUS = 0.0 # BMR Bonus for all enemies

#--------------------------------------------------------------------------
# Minimum Blood Magic Ratio
#--------------------------------------------------------------------------
# This value sets the minimum threshold for MP to HP conversions
MIN_BMR = 1.0

#--------------------------------------------------------------------------
# Use Maximum Blood Magic Ratio
#--------------------------------------------------------------------------
# true : Use MAX_BMR as the maximum MP to HP ratio
# false : Unlimited MP to HP ratio
USE_MAX_BMR = false
#--------------------------------------------------------------------------
# Maximum Blood Magic Ratio
#--------------------------------------------------------------------------
# This value sets a maximum ratio limit for MP to HP blood magic conversion
MAX_BMR = 10.0

#--------------------------------------------------------------------------
# Blood Magic Healing Penalty
#--------------------------------------------------------------------------
# Actors and Enemies with Blood Magic activated can receive a penalty to
# their Recovery Effect Rate where 100.0 is normal healing rate (100%)
# and 0.0 is no healing rate (0%).
#
# Keep in mind that VX Ace already has a feature which can reduce overall
# healing taken by the battler. This penalty stacks with those effects.
BM_HEAL_PENALTY = 0.0

#--------------------------------------------------------------------------
# Base MP Multiplier for Blood Magic
#--------------------------------------------------------------------------
# This value sets an arbitrary multiplier to base MP costs when calculating
# the HP cost through Blood Magic. This will not affect the actual base
# MP cost or the battler's MP cost rate (mcr). Results are rounded up.
#
# For example, if the multiplier is x2.0 and a skill costs 4 MP, then the
# HP cost through Blood Magic will be as though the spell originally
# costs 8 MP.
#
# Leave this value at 1.0 for unmodified base MP calculations.
MP_COST_MULTIPLIER = 1.0

#--------------------------------------------------------------------------
# Blood Magic General/SCM Settings
#--------------------------------------------------------------------------
# Some settings only apply when YEA - Skill Cost Manager is installed.
BM_HP_COST_COLOR = 10 # Color used from "Window" skin.
BM_HP_COST_SIZE = 20 # Font size used for Blood Magic HP costs.
BM_HP_COST_SUFFIX = "%sHP" # Suffix used for Blood Magic HP costs.
BM_HP_COST_ICON = 0 # Icon used for BM HP costs. Set 0 to disable.

end # module BloodMagic
end # module Bubs

#==========================================================================
# ++ END OF USER CUSTOMIZATION MODULE ++
#==========================================================================



#==========================================================================
# ++ Bubs::Regexp
#==========================================================================
module Bubs
module Regexp
module BaseItem
BLOOD_MAGIC_ACTIVE = /<(?:BLOOD_MAGIC|blood magic)>/i
BLOOD_MAGIC_BONUS =
/<(?:BLOOD_MAGIC_BONUS|blood magic bonus):\s*([-+]?\d+\.?\d*)>/i
end # module BaseItem

module UsableItem
BLOOD_MAGIC_REQUIRED = /<(?:BLOOD_MAGIC|blood magic):\s*require[d]?>/i
BLOOD_MAGIC_IGNORE_COST =
/<(?:BLOOD_MAGIC|blood magic):\s*ignore cost[s]?>/i
BLOOD_MAGIC_IGNORE_PENALTY =
/<(?:BLOOD_MAGIC|blood magic):\s*ignore penalty>/i
end # module UsableItem
end # module Regexp
end # module Bubs


#==========================================================================
# ++ DataManager
#==========================================================================
module DataManager

#--------------------------------------------------------------------------
# alias : load_database
#--------------------------------------------------------------------------
class << self; alias load_database_blood_magic load_database; end
def self.load_database
load_database_blood_magic # alias
load_notetags_blood_magic
end

#--------------------------------------------------------------------------
# new method : load_notetags_blood_magic
#--------------------------------------------------------------------------
def self.load_notetags_blood_magic
groups = [$data_actors, $data_classes, $data_skills, $data_items,
$data_weapons, $data_armors, $data_enemies, $data_states]
for group in groups
for obj in group
next if obj.nil?
obj.load_notetags_blood_magic
end
end
end

end # module DataManager


#==========================================================================
# ++ Icon
#==========================================================================
module Icon
#--------------------------------------------------------------------------
# new method : self.blood_magic_hp_cost
#--------------------------------------------------------------------------
def self.blood_magic_hp_cost; return Bubs::BloodMagic::BM_HP_COST_ICON; end
end # module Icon


#==========================================================================
# ++ Window_Base
#==========================================================================
class Window_Base < Window
#--------------------------------------------------------------------------
# new method : cost_colours
#--------------------------------------------------------------------------
def blood_magic_hp_cost_color; text_color(Bubs::BloodMagic::BM_HP_COST_COLOR); end;
end # class Window_Base


#==========================================================================
# ++ RPG::BaseItem
#==========================================================================
class RPG::BaseItem
#--------------------------------------------------------------------------
# public instance variables
#--------------------------------------------------------------------------
attr_accessor :blood_magic_active
attr_accessor :blood_magic_bonus

#--------------------------------------------------------------------------
# common cache : load_notetags_blood_magic
#--------------------------------------------------------------------------
def load_notetags_blood_magic
@blood_magic_active = false
@blood_magic_bonus = 0.0

self.note.split(/[\r\n]+/).each { |line|
case line

when Bubs::Regexp::BaseItem::BLOOD_MAGIC_ACTIVE
@blood_magic_active = true
when Bubs::Regexp::BaseItem::BLOOD_MAGIC_BONUS
@blood_magic_bonus = $1.to_f
end
} # self.note.split
end # def
end # RPG::BaseItem


#==========================================================================
# ++ RPG::UsableItem
#==========================================================================
class RPG::UsableItem < RPG::BaseItem
#--------------------------------------------------------------------------
# public instance variables
#--------------------------------------------------------------------------
attr_accessor :blood_magic_required
attr_accessor :blood_magic_ignore_cost
attr_accessor :blood_magic_ignore_penalty

#--------------------------------------------------------------------------
# common cache : load_notetags_blood_magic
#--------------------------------------------------------------------------
def load_notetags_blood_magic
@blood_magic_required = false
@blood_magic_ignore_cost = false
@blood_magic_ignore_penalty = false

self.note.split(/[\r\n]+/).each { |line|
case line

when Bubs::Regexp::UsableItem::BLOOD_MAGIC_REQUIRED
@blood_magic_required = true
when Bubs::Regexp::UsableItem::BLOOD_MAGIC_IGNORE_COST
@blood_magic_ignore_cost = true
when Bubs::Regexp::UsableItem::BLOOD_MAGIC_IGNORE_PENALTY
@blood_magic_ignore_penalty = true
end
} # self.note.split

end # def
end


#==========================================================================
# ++ Game_BattlerBase
#==========================================================================
class Game_BattlerBase
#--------------------------------------------------------------------------
# alias : skill_cost_payable?
#--------------------------------------------------------------------------
alias skill_cost_payable_blood_magic skill_cost_payable?
def skill_cost_payable?(skill)
if blood_magic_activated?
return false if self.hp <= skill_blood_magic_hp_cost(skill)
end
return skill_cost_payable_blood_magic(skill) # alias
end

#--------------------------------------------------------------------------
# alias : skill_conditions_met?
#--------------------------------------------------------------------------
alias skill_conditions_met_blood_magic skill_conditions_met?
def skill_conditions_met?(skill)
return false unless blood_magic_conditions_met?(skill)
return skill_conditions_met_blood_magic(skill) # alias
end

#--------------------------------------------------------------------------
# alias : item_conditions_met?
#--------------------------------------------------------------------------
alias item_conditions_met_blood_magic item_conditions_met?
def item_conditions_met?(item)
return false unless blood_magic_conditions_met?(item)
return item_conditions_met_blood_magic(item) # alias
end

#--------------------------------------------------------------------------
# new method : blood_magic_conditions_met?
#--------------------------------------------------------------------------
def blood_magic_conditions_met?(item)
return false if item.blood_magic_required && !blood_magic_activated?
return true
end

#--------------------------------------------------------------------------
# alias : pay_skill_cost
#--------------------------------------------------------------------------
alias pay_skill_cost_blood_magic pay_skill_cost
def pay_skill_cost(skill)
pay_skill_cost_blood_magic(skill) # alias
self.hp -= skill_blood_magic_hp_cost(skill)
end # def

#--------------------------------------------------------------------------
# alias : skill_mp_cost
#--------------------------------------------------------------------------
alias skill_mp_cost_blood_magic skill_mp_cost
def skill_mp_cost(skill)
if !skill.blood_magic_ignore_cost && blood_magic_activated?
return 0
else
skill_mp_cost_blood_magic(skill) # alias
end
end # def

#--------------------------------------------------------------------------
# new method : bmr # Blood Magic Ratio
#--------------------------------------------------------------------------
def bmr
n = Bubs::BloodMagic::BASE_BMR
if actor?
n += Bubs::BloodMagic::ACTOR_BMR_BONUS
n += self.actor.blood_magic_bonus
n += self.class.blood_magic_bonus
for equip in equips
next if equip.nil?
n += equip.blood_magic_bonus
end
else
n += Bubs::BloodMagic::ENEMY_BMR_BONUS
n += self.enemy.blood_magic_bonus
end
for state in states
next if state.nil?
n += state.blood_magic_bonus
end
# determine minimum blood ratio
n = [n, Bubs::BloodMagic::MIN_BMR].max
# determine maximum blood ratio cap
n = [n, Bubs::BloodMagic::MAX_BMR].min if Bubs::BloodMagic::USE_MAX_BMR
return n
end # def bmr

#--------------------------------------------------------------------------
# new method : blood_magic_activated?
#--------------------------------------------------------------------------
def blood_magic_activated?
if actor?
return true if self.actor.blood_magic_active
return true if self.class.blood_magic_active
for equip in equips
next if equip.nil?
return true if equip.blood_magic_active
end
else
return true if self.enemy.blood_magic_active
end
for state in states
next if state.nil?
return true if state.blood_magic_active
end
return false
end # def blood_magic_activated?

#--------------------------------------------------------------------------
# new method : skill_blood_magic_hp_cost
#--------------------------------------------------------------------------
# Determines the MP to HP cost conversion
def skill_blood_magic_hp_cost(skill)
return 0 if skill.blood_magic_ignore_cost

# default mp cost
n = (skill.mp_cost * mcr).to_i

if $imported["YEA-SkillCostManager"]
n += skill.mp_cost_percent * mmp * mcr
n = [n.to_i, skill.mp_cost_max].min unless skill.mp_cost_max.nil?
n = [n.to_i, skill.mp_cost_min].max unless skill.mp_cost_min.nil?
end

n = (n * Bubs::BloodMagic::MP_COST_MULTIPLIER).ceil
n = (n / bmr).ceil
n = [n, 0].max
return n
end # def skill_blood_magic_hp_cost(skill)

end # class Game_BattlerBase


#==========================================================================
# ++ Game_Battler
#==========================================================================
class Game_Battler < Game_BattlerBase
#--------------------------------------------------------------------------
# alias : make_damage
#--------------------------------------------------------------------------
alias make_damage_value_blood_magic make_damage_value
def make_damage_value(user, item)
make_damage_value_blood_magic(user, item) # alias

apply_blood_magic_penalty(item)
end

#--------------------------------------------------------------------------
# alias : apply_blood_magic_penalty
#--------------------------------------------------------------------------
def apply_blood_magic_penalty(item)
if item.damage.recover? && self.blood_magic_activated?
unless item.blood_magic_ignore_penalty
penalty = Bubs::BloodMagic::BM_HEAL_PENALTY * 0.01
value = @result.hp_damage * penalty
@result.make_damage(value.to_i, item)
end
end
end

end


#==========================================================================
# ++ Window_SkillList
#==========================================================================
class Window_SkillList < Window_Selectable
#--------------------------------------------------------------------------
# alias : draw_skill_cost
#--------------------------------------------------------------------------
alias draw_skill_cost_blood_magic draw_skill_cost
def draw_skill_cost(rect, skill)

if @actor.blood_magic_activated? &&
@actor.skill_blood_magic_hp_cost(skill) > 0

if $imported["YEA-SkillCostManager"]
draw_blood_magic_hp_skill_cost(rect, skill)
else
change_color(blood_magic_hp_cost_color, enable?(skill))
draw_text(rect, @actor.skill_blood_magic_hp_cost(skill), 2)
end # $imported

end # end if

draw_skill_cost_blood_magic(rect, skill) # alias
end # def draw_skill_cost

#--------------------------------------------------------------------------
# new method : draw_blood_magic_hp_skill_cost
#--------------------------------------------------------------------------
# Used only when YEA - Skill Cost Manager is installed
def draw_blood_magic_hp_skill_cost(rect, skill)
return unless @actor.skill_blood_magic_hp_cost(skill) > 0
change_color(blood_magic_hp_cost_color, enable?(skill))
#---
icon = Icon.blood_magic_hp_cost
if icon > 0
draw_icon(icon, rect.x + rect.width-24, rect.y, enable?(skill))
rect.width -= 24
end
#---
contents.font.size = Bubs::BloodMagic::BM_HP_COST_SIZE
cost = @actor.skill_blood_magic_hp_cost(skill)
text = sprintf(Bubs::BloodMagic::BM_HP_COST_SUFFIX, cost.group)
draw_text(rect, text, 2)
cx = text_size(text).width + 4
rect.width -= cx
reset_font_settings
end # def draw_blood_magic_hp_skill_cost

end # class Window_SkillList
Original topic: http://www.rpgmakercentral.com/topic/668-blood-magic/

 

 

 

And that is all for now; adding more as I become aware of more lost scripts

Share this post


Link to post
Share on other sites

Well if you went through mr. bubblewand's page you will see that virtually every script is gone. 

I have a few which I could post if needed.

 

Party guests

KMS Generic Gauge patches for

-yea battle engine

-yea victory aftermath

-yea system options

Absolutely, please do. In fact, spread the word to those who wish to assist; I gladly accept all hands who wish to help.

Share this post


Link to post
Share on other sites

Lost scripts Mr. Bubblewand

 

Party Guests

 

 

# â•”â•â•â•â•â•â•â•â•â•â•â•â•â•â•â•â•â•â•â•â•â•â•â•â•â•â•â•â•â•â•â•â•â•â•â•â•â•â•â•â•â•â•â•â•â•â•â•â•â•â•â•â•â•â•â•â•¤â•â•â•â•â•â•â•¤â•â•â•â•â•â•â•â•â•â•â•â•—
# ║ Party Guests │ v1.1 │ (7/13/12) ║
# â•šâ•â•â•â•â•â•â•â•â•â•â•â•â•â•â•â•â•â•â•â•â•â•â•â•â•â•â•â•â•â•â•â•â•â•â•â•â•â•â•â•â•â•â•â•â•â•â•â•â•â•â•â•â•â•â•â•§â•â•â•â•â•â•â•§â•â•â•â•â•â•â•â•â•â•â•â•
# Script by:
# Mr. Bubble
#--------------------------------------------------------------------------
# This script allows you to have actors as guests in the party
# similarly to various console RPGs. A custom window is added to the
# menu that displays current guests in the party.
#
# Party guests do not require special tags in their noteboxes. They are
# simply actors put into a "guests" group within the party which is
# seperate from any of your battle or reserve members. Because of
# this, guests are not eligible to be chosen for battle at all.
#
# Since guests are just glorified actors, names, face graphics,
# sprite graphics, etc. are defined in the Actors tab in the database
# like normal. Those settings are then used in various display windows
# related to guests.
#
# Guests provide no special effects to the party. However, other existing
# scripts can provide effects if desired.
#
# If an actor is already in the main party and is placed into the
# guest group, the actor will automatically be removed from the
# main party. The same is true vice versa.
#--------------------------------------------------------------------------
# ++ Changelog ++
#--------------------------------------------------------------------------
# v1.1 : Fixed guest_in_party? Script Call.
# : Changed instance variable name for Guest ID array. (7/13/2012)
# v1.0 : Initial release. (6/25/2012)
#--------------------------------------------------------------------------
# ++ Installation ++
#--------------------------------------------------------------------------
# Install this script in the Materials section in your project's
# script editor.
#=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
# ++ Script Calls ++
#=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
# The following script calls are meant to be used in "Script..."
# event commands found under Tab 3 when creating a new event.
#
# add_guest(actor_id)
# Adds an actor to the party guest group. If the actor is already in the
# main party, the actor will automatically be removed from the main
# party before being added to the guest group.
#
# remove_guest(actor_id)
# Removes the actor from the guest group.
#
# remove_all_guests
# Removes all actors from the guest group.
#
#=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
# ++ Conditional Branch Script Calls ++
#=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
# The following script calls are meant to be used in Conditional
# Branch event commands within the Tab 4 "Script" box.
# Each of these script calls will turn the given Game Switch ON
# or OFF, where ON is true and OFF is false.
#
# guest_in_party?(actor_id)
# Checks whether the given actor is a guest in the party.
#
#--------------------------------------------------------------------------
# ++ Compatibility ++
#--------------------------------------------------------------------------
# This script aliases the following default VXA methods:
#
# Game_Party#initialize
# Game_Party#add_actor
#
# There are no default method overwrites.
#
# Requests for compatibility with other scripts are welcome.
#--------------------------------------------------------------------------
# ++ Terms and Conditions ++
#--------------------------------------------------------------------------
# Please do not repost this script elsewhere without permission.
# Free for non-commercial use. For commercial use, contact me first.
#
# Newest versions of this script can be found at
# http://mrbubblewand.wordpress.com/
#==============================================================================

$imported = {} if $imported.nil?
$imported["BubsPartyGuests"] = true

#==========================================================================
# ++ START OF USER CUSTOMIZATION MODULE ++
#==========================================================================
module Bubs
#==========================================================================
# ++ Party Guests Settings
#==========================================================================
module PartyGuests

#--------------------------------------------------------------------------
# Guest Limit
#--------------------------------------------------------------------------
# The maximum number of guests that can accompany the party.
# !! Use caution when adding too many guests to the party since
# !! the Guests window in the menu is not currently suited to handle
# !! a large amount of guests to display.
MAX_GUESTS = 2

#--------------------------------------------------------------------------
# Guest Window Label Text
#--------------------------------------------------------------------------
GUEST_WINDOW_TEXT = "Guests"
#--------------------------------------------------------------------------
# Guest Window Display Style
#--------------------------------------------------------------------------
# Determines the style in which Guests are shown in the Guests window
# 0 : Show Guest face portraits
# 1 : Show Guest map sprites
GUEST_WINDOW_STYLE = 0
#--------------------------------------------------------------------------
# Hide Guest Window When No Guests
#--------------------------------------------------------------------------
# true : The Guest window will be hidden when there are no guests
# false : The Guest window will still be visible when there are no guests
HIDE_WINDOW_WHEN_NO_GUESTS = true

end # module PartyGuests
end # module Bubs

#==========================================================================
# ++ END OF USER CUSTOMIZATION MODULE ++
#==========================================================================



#==========================================================================
# ++ Game_Party
#==========================================================================
class Game_Party < Game_Unit
attr_accessor :guest_ids
#--------------------------------------------------------------------------
# alias : initialize
#--------------------------------------------------------------------------
alias initialize_bubs_party_guests initialize
def initialize
initialize_bubs_party_guests # alias

@guest_ids = []
end

#--------------------------------------------------------------------------
# new method : guests
#--------------------------------------------------------------------------
def guests
@guest_ids.collect {|id| $game_actors[id] }
end

#--------------------------------------------------------------------------
# new method : party_guests
#--------------------------------------------------------------------------
def party_guests
@guest_ids
end

#--------------------------------------------------------------------------
# new method : add_guest
#--------------------------------------------------------------------------
def add_guest(actor_id)
return if @guest_ids.size >= max_guests
return if @guest_ids.include?(actor_id)

remove_actor(actor_id)
@guest_ids.push(actor_id)
$game_player.refresh
$game_map.need_refresh = true
end

#--------------------------------------------------------------------------
# new method : remove_guest
#--------------------------------------------------------------------------
def remove_guest(actor_id)
@guest_ids.delete(actor_id)
$game_player.refresh
$game_map.need_refresh = true
end

#--------------------------------------------------------------------------
# alias : add_actor
#--------------------------------------------------------------------------
alias add_actor_bubs_party_guests add_actor
def add_actor(actor_id)
remove_guest(actor_id)
add_actor_bubs_party_guests(actor_id) # alias
end

#--------------------------------------------------------------------------
# new method : max_guests
#--------------------------------------------------------------------------
def max_guests
return Bubs::PartyGuests::MAX_GUESTS
end
end # class Game_Party


#==========================================================================
# ++ Window_PartyGuests
#==========================================================================
class Window_PartyGuests < Window_Base
#--------------------------------------------------------------------------
# * Object Initialization
#--------------------------------------------------------------------------
def initialize
super(0, 0, window_width, window_height)
refresh
end

#--------------------------------------------------------------------------
# window_width
#--------------------------------------------------------------------------
def window_width
return 160
end

#--------------------------------------------------------------------------
# height
#--------------------------------------------------------------------------
def window_height
fitting_height(guest_window_height)
end

#--------------------------------------------------------------------------
# new method : guest_window_height
#--------------------------------------------------------------------------
def guest_window_height
fh = 1
case Bubs::PartyGuests::GUEST_WINDOW_STYLE
when 0
fh = 1 + ($game_party.guest_ids.size * 2)
when 1
fh = $game_party.guest_ids.empty? ? 1 : 3
end
end

#--------------------------------------------------------------------------
# refresh
#--------------------------------------------------------------------------
def refresh
contents.clear
draw_party_guest_text
draw_party_guests
end

#--------------------------------------------------------------------------
# new method : draw_party_guests
#--------------------------------------------------------------------------
def draw_party_guests
case Bubs::PartyGuests::GUEST_WINDOW_STYLE
when 0
draw_party_guest_faces
when 1
draw_party_guest_graphics
end
end

#--------------------------------------------------------------------------
# new method : draw_party_guest_faces
#--------------------------------------------------------------------------
def draw_party_guest_faces
$game_party.guests.each_with_index { |actor, i|
draw_actor_half_face(actor, 20, 48 * i + line_height)
}
end

#--------------------------------------------------------------------------
# new method : draw_party_guest_graphic
#--------------------------------------------------------------------------
def draw_party_guest_graphics
$game_party.guests.each_with_index { |actor, i|
draw_actor_graphic(actor, 32 * i + 20, 24 * 3)
}
end

#--------------------------------------------------------------------------
# new method : draw_party_guest_text
#--------------------------------------------------------------------------
def draw_party_guest_text
change_color(system_color)
draw_text(0, 0, 160, line_height, Bubs::PartyGuests::GUEST_WINDOW_TEXT)
end

#--------------------------------------------------------------------------
# new method : draw_actor_half_face
#--------------------------------------------------------------------------
def draw_actor_half_face(actor, x, y, enabled = true)
draw_half_face(actor.face_name, actor.face_index, x, y, enabled)
end

#--------------------------------------------------------------------------
# new method : draw_half_face
#--------------------------------------------------------------------------
def draw_half_face(face_name, face_index, x, y, enabled = true)
bitmap = Cache.face(face_name)
rect = Rect.new(face_index % 4 * 96, face_index / 4 * 96 + 32, 96, 46)
contents.blt(x, y, bitmap, rect, enabled ? 255 : translucent_alpha)
bitmap.dispose
end

#--------------------------------------------------------------------------
# open
#--------------------------------------------------------------------------
def open
refresh
super
end
end # class Window_PartyGuests


#==========================================================================
# ++ Scene_Menu
#==========================================================================
class Scene_Menu < Scene_MenuBase
#--------------------------------------------------------------------------
# alias : start
#--------------------------------------------------------------------------
alias start_bubs_party_guests start
def start
start_bubs_party_guests # alias

create_guest_window
end

#--------------------------------------------------------------------------
# new method : create_guest_window
#--------------------------------------------------------------------------
def create_guest_window
return if $game_party.guests.empty? && Bubs::PartyGuests::HIDE_WINDOW_WHEN_NO_GUESTS

@guest_window = Window_PartyGuests.new
@guest_window.x = 0
@guest_window.y = Graphics.height - @gold_window.height - @guest_window.height
end
end # class Scene_Menu

#==========================================================================
# ++ Game_Actor
#==========================================================================
class Game_Actor < Game_Battler
#--------------------------------------------------------------------------
# new method : guest?
#--------------------------------------------------------------------------
def guest?
$game_party.guest_ids.include?(@actor_id)
end
end # class Game_Actor

#==========================================================================
# ++ Game_BattlerBase
#==========================================================================
class Game_BattlerBase
#--------------------------------------------------------------------------
# new method : guest?
#--------------------------------------------------------------------------
def guest?
return false
end
end # class Game_BattlerBase


#==========================================================================
# ++ Game_Interpreter
#==========================================================================
class Game_Interpreter
#--------------------------------------------------------------------------
# new method : remove_all_guests
#--------------------------------------------------------------------------
def remove_all_guests
$game_party.guest_ids.clear
end
alias remove_all_guest remove_all_guests

#--------------------------------------------------------------------------
# new method : add_guest
#--------------------------------------------------------------------------
def add_guest(actor_id)
$game_party.add_guest(actor_id)
end

#--------------------------------------------------------------------------
# new method : remove_guest
#--------------------------------------------------------------------------
def remove_guest(actor_id)
$game_party.remove_guest(actor_id)
end

#--------------------------------------------------------------------------
# new method : guest_in_party?
#--------------------------------------------------------------------------
def guest_in_party?(actor_id)
$game_party.guest_ids.include?(actor_id)
end
alias has_guest? guest_in_party?
alias have_guest? guest_in_party?
end # class Game_Interpreter

 

 

YEA Battle Engine Compatibility Patch 

 

#==============================================================================

# Compatibility Patch : v1.1 (1/15/12)
# YEA Battle Engine + KMS Generic Gauge
#==============================================================================
# Script by:
# Mr. Bubble
#--------------------------------------------------------------------------
# Place this script below both YEA Battle Engine and Generic Gauge in
# the script edtior.
#==============================================================================

$imported = {} if $imported.nil?
$kms_imported = {} if $kms_imported.nil?

class Window_BattleStatus < Window_Selectable
if $imported["YEA-BattleEngine"] && $kms_imported["GenericGauge"]
#--------------------------------------------------------------------------
# overwrite method: draw_actor_hp
#--------------------------------------------------------------------------
def draw_actor_hp(actor, dx, dy, width = 124)
super(actor, dx, dy, width - 4)
end

#--------------------------------------------------------------------------
# overwrite method: draw_actor_mp
#--------------------------------------------------------------------------
def draw_actor_mp(actor, dx, dy, width = 124)
super(actor, dx, dy, width - 4)
end

#--------------------------------------------------------------------------
# overwrite method: draw_actor_tp
#--------------------------------------------------------------------------
def draw_actor_tp(actor, dx, dy, width = 124)
super(actor, dx, dy, width - 4)
end

end # if $imported
end

 

 

YEA Victory Aftermath Compatibility Patch 

 

#==============================================================================

# Compatibility Patch : v1.1 (8/07/12)
# YEA Victory Aftermath + KMS Generic Gauge
#==============================================================================
# Script by:
# Mr. Bubble
#--------------------------------------------------------------------------
# Place this script below both YEA Victory Aftermath and KMS Generic Gauge
# in your script edtior.
#--------------------------------------------------------------------------
# ++ Changelog ++
#--------------------------------------------------------------------------
# v1.1 : Updated for Generic Gauge version 2012/08/05. (8/07/2012)
# v1.0 : Initial release. (1/24/2012)
#==============================================================================

module Bubs
module GenericGauge
#--------------------------------------------------------------------------
# Gauge Filenames
#--------------------------------------------------------------------------
# Images must be placed in the "Graphics/System" folder of your project
VA_EXP_IMAGE = "GaugeEXP" # Normal EXP Gauge Image
VA_MAX_LEVEL_IMAGE = "GaugeEXP" # MAX Level EXP Gauge Image,
# MAX Level filename is for when the actor
# is at MAX level
#--------------------------------------------------------------------------
# Gauge Position Offset
#--------------------------------------------------------------------------
VA_EXP_OFFSET = [-23, -2] # [x, y]
#--------------------------------------------------------------------------
# Gauge Length Adjustment
#--------------------------------------------------------------------------
VA_EXP_LENGTH = -4 # Victory Aftermath EXP
#--------------------------------------------------------------------------
# Gauge Slope
#--------------------------------------------------------------------------
# Must be between -89 ~ 89 degrees
VA_EXP_SLOPE = 30 # Victory Aftermath EXP

end # module GenericGauge
end # module Bubs


$imported ||= {}
$kms_imported ||= {}


if $imported["YEA-VictoryAftermath"] && $kms_imported["GenericGauge"]
#==============================================================================
# ++ Window_VictoryEXP_Front
#==============================================================================
class Window_VictoryEXP_Front < Window_VictoryEXP_Back
#--------------------------------------------------------------------------
# overwrite : draw_gauge
#--------------------------------------------------------------------------
def draw_gauge(x, y, width, rate, color1, color2)
normal_image = Bubs::GenericGauge::VA_EXP_IMAGE
max_image = Bubs::GenericGauge::VA_MAX_LEVEL_IMAGE
image = rate >= 1.0 ? max_image : normal_image
offset = Bubs::GenericGauge::VA_EXP_OFFSET
len_offset = Bubs::GenericGauge::VA_EXP_LENGTH
slope = Bubs::GenericGauge::VA_EXP_SLOPE
draw_generic_gauge(image, x, y, width, rate, offset, len_offset, slope)
end

end # class Window_VictoryEXP_Front
 

end # end $imported

 

 

YEA System Options Compatibility Patch 

 

#==============================================================================

# Compatibility Patch : v1.1 (8/07/12)
# YEA System Options + KMS Generic Gauge
#==============================================================================
# Script by:
# Mr. Bubble
#--------------------------------------------------------------------------
# Place this script below both YEA System Options and KMS Generic Gauge
# in your script edtior.
#
# Due to the nature of both scripts, several methods in YEA System Options
# were overwritten.
#
# All Generic Gauge images must be placed in the "Graphics/System"
# folder of your project.
#--------------------------------------------------------------------------
# ++ Changelog ++
#--------------------------------------------------------------------------
# v1.1 : Updated for Generic Gauge version 2012/08/05. (8/07/2012)
# v1.0 : Initial release. (1/31/2012)
#==============================================================================

module Bubs
module GenericGauge
#--------------------------------------------------------------------------
# Window Tone Gauge Settings
#--------------------------------------------------------------------------
WINDOW_TONE_GAUGE = {
:window_red => "GaugeRed", # Red Tone Gauge
:window_grn => "GaugeGreen", # Green Tone Gauge
:window_blu => "GaugeBlue", # Blue Tone Gauge

# The following settings affect all Window Tone generic gauges
:offset => [-23, -2], # Gauge Position Offset [x, y]
:length => -4, # Gauge Length Adjustment
:slope => 30, # Gauge Slope; Must be between -89 ~ 89 degrees

} # <-- Do not delete!

#--------------------------------------------------------------------------
# Volume Gauge Settings
#--------------------------------------------------------------------------
VOLUME_GAUGE = {
:volume_bgm => "GaugeBGM", # BGM Gauge
:volume_bgs => "GaugeBGS", # BGS Gauge
:volume_sfx => "GaugeSFX", # SFX Gauge

# The following settings affect all Volume generic gauges
:offset => [-23, -2], # Gauge Position Offset [x, y]
:length => -4, # Gauge Length Adjustment
:slope => 30, # Gauge Slope; Must be between -89 ~ 89 degrees

} # <-- Do not delete!

#--------------------------------------------------------------------------
# Custom Variable Gauge Settings
#--------------------------------------------------------------------------
CUSTOM_VARIABLE_GAUGE = {
# Default gauge used if custom variable gauge is not defined
:default_gauge => "GaugeWIN",
:windowskin => "GaugeWIN",
#------------------------------------------------------------------------
# Variable index must match the same index that you defined in
# CUSTOM_VARIABLES in YEA System Options. Otherwise, :default_gauge
# will be used.
#------------------------------------------------------------------------
1 => "GaugeMP", # Variable 1 Gauge
2 => "GaugeTP", # Variable 2 Gauge


# The following settings affect all Custom Variable generic gauges
:offset => [-23, -2], # Gauge Position Offset [x, y]
:length => -4, # Gauge Length Adjustment
:slope => 30, # Gauge Slope; Must be between -89 ~ 89 degrees

} # <-- Do not delete!

end # module GenericGauge
end # module Bubs


$imported = {} if $imported.nil?
$kms_imported = {} if $kms_imported.nil?

if $imported["YEA-SystemOptions"] && $kms_imported["GenericGauge"]
#==============================================================================
# ++ Window_SystemOptions
#==============================================================================
class Window_SystemOptions < Window_Command
#--------------------------------------------------------------------------
# overwrite : draw_window_tone
#--------------------------------------------------------------------------
def draw_window_tone(rect, index, symbol)
name = @list[index][:name]
draw_text(0, rect.y, contents.width/2, line_height, name, 1)
#---
dx = contents.width / 2
tone = $game_system.window_tone
case symbol
when :window_red
rate = (tone.red + 255.0) / 510.0
colour1 = Color.new(128, 0, 0)
colour2 = Color.new(255, 0, 0)
value = tone.red.to_i
when :window_grn
rate = (tone.green + 255.0) / 510.0
colour1 = Color.new(0, 128, 0)
colour2 = Color.new(0, 255, 0)
value = tone.green.to_i
when :window_blu
rate = (tone.blue + 255.0) / 510.0
colour1 = Color.new(0, 0, 128)
colour2 = Color.new(0, 0, 255)
value = tone.blue.to_i
end
#---

image = Bubs::GenericGauge::WINDOW_TONE_GAUGE[symbol]
width = contents.width - dx - 48
offset = Bubs::GenericGauge::WINDOW_TONE_GAUGE[:offset]
len_offset = Bubs::GenericGauge::WINDOW_TONE_GAUGE[:length]
slope = Bubs::GenericGauge::WINDOW_TONE_GAUGE[:slope]

draw_generic_gauge(image, dx, rect.y, width, rate, offset, len_offset, slope)
#---
draw_text(dx, rect.y, contents.width - dx - 48, line_height, value, 2)
end

#--------------------------------------------------------------------------
# overwrite : draw_volume
#--------------------------------------------------------------------------
def draw_volume(rect, index, symbol)
name = @list[index][:name]
draw_text(0, rect.y, contents.width/2, line_height, name, 1)
#---
dx = contents.width / 2
case symbol
when :volume_bgm
rate = $game_system.volume(:bgm)
when :volume_bgs
rate = $game_system.volume(:bgs)
when :volume_sfx
rate = $game_system.volume(:sfx)
end
colour1 = text_color(YEA::SYSTEM::COMMAND_VOCAB[symbol][1])
colour2 = text_color(YEA::SYSTEM::COMMAND_VOCAB[symbol][2])
value = sprintf("%d%%", rate)
rate *= 0.01
#---

image = Bubs::GenericGauge::VOLUME_GAUGE[symbol]
width = contents.width - dx - 48
offset = Bubs::GenericGauge::VOLUME_GAUGE[:offset]
len_offset = Bubs::GenericGauge::VOLUME_GAUGE[:length]
slope = Bubs::GenericGauge::VOLUME_GAUGE[:slope]

draw_generic_gauge(image, dx, rect.y, width, rate, offset, len_offset, slope)
#---
draw_text(dx, rect.y, contents.width - dx - 48, line_height, value, 2)
end

#--------------------------------------------------------------------------
# overwrite : draw_custom_variable
#--------------------------------------------------------------------------
def draw_custom_variable(rect, index, ext)
name = @list[index][:name]
draw_text(0, rect.y, contents.width/2, line_height, name, 1)
#---
dx = contents.width / 2
value = $game_variables[YEA::SYSTEM::CUSTOM_VARIABLES[ext][0]]
colour1 = text_color(YEA::SYSTEM::CUSTOM_VARIABLES[ext][2])
colour2 = text_color(YEA::SYSTEM::CUSTOM_VARIABLES[ext][3])
minimum = YEA::SYSTEM::CUSTOM_VARIABLES[ext][4]
maximum = YEA::SYSTEM::CUSTOM_VARIABLES[ext][5]
rate = (value - minimum).to_f / [(maximum - minimum).to_f, 0.01].max
dx = contents.width/2
#---
var_index = YEA::SYSTEM::CUSTOM_VARIABLES[ext][0]

if Bubs::GenericGauge::CUSTOM_VARIABLE_GAUGE.include?(var_index)
image = Bubs::GenericGauge::CUSTOM_VARIABLE_GAUGE[var_index]
else
image = Bubs::GenericGauge::CUSTOM_VARIABLE_GAUGE[:default_gauge]
end

offset = Bubs::GenericGauge::CUSTOM_VARIABLE_GAUGE[:offset]
len_offset = Bubs::GenericGauge::CUSTOM_VARIABLE_GAUGE[:length]
slope = Bubs::GenericGauge::CUSTOM_VARIABLE_GAUGE[:slope]
width = contents.width - dx - 48
draw_generic_gauge(image, dx, rect.y, width, rate, offset, len_offset, slope)

#---
draw_text(dx, rect.y, contents.width - dx - 48, line_height, value, 2)
end

end # class Window_SystemOptions
 

end # $imported

 

Tactics Ogre Crafting System

Spoiler

# ╔══════════════════════════════════════════════════════╤═══════╤═══════════╗
# ║ Tactics Ogre PSP Crafting System                     │ v2.04 │ (5/18/13) ║
# ╚══════════════════════════════════════════════════════╧═══════╧═══════════╝
# Script by:
#     Mr. Bubble ( http://mrbubblewand.wordpress.com/ )
# Thanks:
#     Mithran, regexp references
#     estriole, assistance with scene interpreter
#--------------------------------------------------------------------------
# This item crafting script is modeled after the crafting system implemented
# in the PSP remake of Tactics Ogre: Let Us Cling Together. It's a very
# simple crafting system with a very simple GUI which I also used as
# a model.
#
# Players must have recipe books in their inventory when entering the
# crafting scene. Any recipe books owned by the player will be displayed 
# in a list. When a recipe book is selected, all possible items, armors,
# and weapons in the recipe book will be listed and you will be able to
# craft them provided that the player has the necessary ingredients.
#
# The script "Info Pages Window" is required.
#
# Feel free to reguest custom information to be added to item info pages
# in the crafting scene.
#--------------------------------------------------------------------------
#      Changelog   
#--------------------------------------------------------------------------
# v2.04 : Italian language support added.
#       : Shifted some code. (5/18/2013)
# v2.03 : Compatibility Update: "TH_SceneInterpreter"
#       : Bugfix: Fixed bug where selecting the number to craft
#       : ignores the amount of ingredients available. (5/11/2013)
# v2.02 : Bugfix: Fixed categories nil error.
# v2.01 : Bugfix: Fixed ingredient numbers in info window.
#       : New tag: <craft result>. See comments for more info.
#       : You can now run a common event after crafting an item.
#       : You can now change how many of an item you gain per 
#       : set of ingredients. (5/02/2013)
# v2.00 : Now requires script: "Info Pages Window".
#       : This script will now check if any required scripts are
#       : missing. If any are missing, the game will be exited.
#       : Many crafting customization options related to the info
#       : pages window have been removed.
#       : Changed version number format.
#       : $imported variable now uses version number.
#       : Changed some methods, add-ons/patches may not work anymore.
#       : Removed about 700+ lines of code. (5/02/2013)
# v1.14 : Calling the crafting scene directly with SceneManager will 
#       : no longer crash the game. (4/28/2013)
# v1.13 : Bugfix: Custom craft result sound effects should no longer 
#       : crash the game.
#       : Equippable members info page added. 
#       : Cleaned up some code. (3/26/13)
# v1.12 : Quick compatibility update with Tsukihime's TO Crafting Shop
#       : script. (3/13/13)
# v1.11 : You can now require specific actors in the party as a crafting 
#       : requirement.
#       : New ingredient notetag added.
#       : New options in the customization module added.
#       : Slight code efficiency update. (2/06/2013)
# v1.10 : TP Recovery now displays the correct value.
#       : Recipebook images are now centered by default. (9/04/2012)
# v1.09 : State resistance item info is now viewable.
#       : Footer text is now properly aligned. (8/28/2012)
# v1.08 : Compatibility: "YEA-AceMenuEngine" support added.
#       : You can now view item details in the crafting scene if the
#       : script "Reader Functions for Features/Effects" is installed.
#       : Info window style has changed.
#       : Any amount of ingredients can now be displayed, not just 6.
#       : Configuration module has many new settings.
#       : Some method names have changed.
#       : Removed a chunk of redundant code.
#       : Efficiency update. (8/25/2012)
# v1.07 : Fixed issue where you can still craft from a recipebook even if
#       : you have zero left as a result of using it in a crafting recipe.
#       : Script call for the crafting scene has changed. The old one can
#       : still be used though.
#       : New Notetag for recipebooks added.
#       : You can now choose which recipebooks can be included in the
#       : crafting scene by category. 
#       : Efficiency update. (8/18/2012)
# v1.06 : Compatibility: "XAS VX Ace" support added. (8/08/2012)
# v1.05 : You can now change the recipebook pictures directory.
#       : You can now assign sound effects for crafted items.
#       : Slight code efficiency update. (7/29/2012)
# v1.04 : Added the option to use images as recipebook covers.
#       : New Notetag for recipebooks added. 
#       : New option in customization module for book images. (7/27/2012)
# v1.03 : Colon between type and ID no longer needed.
#       : Updated comments to reflect changes.
#       : Tool regexp updated. (7/27/2012)
# v1.02 : You can now change the Gold icon in the customization module.
#       : You can now change the name of Gold in windows. (7/27/2012)
# v1.01 : Fixed issue with long item names getting cut off in windows.
#       : Confirm window removed. 
#       : Quantity selection window implemented.
#       : Crafting Gold fee implemented.
#       : Crafting tool requirement implemented.
#       : New options added in customization module. (7/26/2012)
# v1.00 : Initial release. (7/25/2012)
#--------------------------------------------------------------------------
#      Installation & Requirements
#--------------------------------------------------------------------------
# Install this script in the Materials section in your project's
# script editor BELOW the script "Info Pages Window".
#=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
#      Notetags   
#=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
# Note: Some tags are given shorter tags for typing convenience. You only
#       need to use one <tag> from a given group for a notebox. 
#       Use common sense.
#
# The following Notetags are for Items, Weapons, and Armors only:
#
# <recipebook>
# setting
# setting
# </recipebook>
#   This tag allows you define a recipe book. You can add as many 
#   settings between the <recipebook> tags as you like. Only items with 
#   this tag will appear in the recipes window in the crafting scene. 
#   The following settings are available:
#
#     item: id
#     item: id, id, id ...
#     i: id
#     i: id, id, id ...
#       This setting defines the items that can be crafted from the 
#       recipe book where id is the Item ID number found in your database. 
#       You can list multiple id numbers on the same line separated by commas. 
#       This setting can be used multiple times within the <recipebook> tags.
#
#     weapon: id
#     weapon: id, id, id ...
#     w: id
#     w: id, id, id ...
#       This setting defines the weapons that can be crafted from the 
#       recipe book where id is the Weapon ID number found in your database. 
#       You can list multiple id numbers on the same line separated by commas. 
#       This setting can be used multiple times within the <recipebook> tags.
#       
#     armor: id
#     armor: id, id, id ...
#     armour: id
#     armour: id, id, id ...
#     a: id
#     a: id, id, id ...
#       This setting defines the armors that can be crafted from the 
#       recipe book where id is the Armor ID number found in your database. 
#       You can list multiple id numbers on the same line separated by commas. 
#       This setting can be used multiple times within the <recipebook> tags.
#
#     picture: filename
#     pic: filename
#     cover: filename
#       This setting defines the image used to represent the recipe book
#       in the crafting scene where filename is the name of a picture
#       located in the Graphics/Pictures/ folder of your project. Do
#       not include the filename's extension. Recommended picture 
#       resolutions are [width: 248, height: 320] for default resolutions 
#       and [width: 296, height: 384] for 480x640 resolutions.
#
#     category: name
#       This setting defines the recipebook's category label. Category
#       labels are used by developers to determine which recipebooks
#       they want included in the crafting scene. If a category label is
#       not defined, the default category is "none". This is a completely
#       optional setting.
#   
# <ingredients>
# setting
# setting
# </ingredients>
#   This tag allows you define the ingredients required to craft an item. 
#   You can add as many settings between the <ingredients> tags as you like.
#   If an item, weapon, or armor has no ingredients, you can still craft it.
#   The following settings are available:
#
#     item: id
#     item: id xN
#     i: id
#     i: id xN
#       This setting defines the item ingredients required to craft the
#       item, weapon, or armor where id is the Item ID number found in 
#       your database. xN is total number of that ingredient required if
#       it is included after the id number where N is a whole number 
#       (ex. x2, x3, x4, etc.). If xN is not included, the script will
#       automatically assume x1. You can list multiple id numbers on the 
#       same line separated by commas. This setting can be used multiple 
#       times within the <ingredients> tags.
#
#     weapon: id
#     weapon: id xN
#     w: id
#     w: id xN
#       This setting defines the weapon ingredients required to craft the
#       item, weapon, or armor where id is the Weapon ID number found in 
#       your database. xN is total number of that ingredient required if
#       it is included after the id number where N is a whole number 
#       (ex. x2, x3, x4, etc.). If xN is not included, the script will
#       automatically assume x1. You can list multiple id numbers on the 
#       same line separated by commas. This setting can be used multiple 
#       times within the <ingredients> tags.
#
#     armor: id
#     armor: id xN
#     armour: id
#     armour: id xN
#     a: id
#     a: id xN
#       This setting defines the armor ingredients required to craft the
#       item, weapon, or armor where id is the Weapon ID number found in 
#       your database. xN is total number of that ingredient required if
#       it is included after the id number where N is a whole number 
#       (ex. x2, x3, x4, etc.). If xN is not included, the script will
#       automatically assume x1. You can list multiple id numbers on the 
#       same line separated by commas. This setting can be used multiple 
#       times within the <ingredients> tags.
#
#     gold: amount
#       This setting defines the amount of Gold required to craft
#       the item, armor, or weapon where amount is any amount of gold. 
#       If this setting is omitted, it will use the default fee defined 
#       in the customization module.
#
#     tool: item id
#     tool: i id
#     tool: weapon id
#     tool: w id
#     tool: armor id
#     tool: armour id
#     tool: a id
#       This setting defines the tools required to craft the item, weapon, 
#       or armor where id is the item, weapon, or armor ID number found in 
#       your database. Tools are not consumed in the crafting process. 
#       This setting can be used multiple times within the <ingredients> 
#       tags.
#
#     actor: actor_id
#       This setting defines the actor required to craft the item, weapon,
#       or armor where actor_id is the actor ID number from your database.
#       Currently, nothing happens to the actor after crafting an item
#       that requires one. This setting can be used multiple times within
#       the <ingredients> tags.
#
# <craft result>
# setting
# setting
# </craft result>
#   This tag allows you to define what happens after an item is 
#   crafted. You can add as many settings between the <craft result> 
#   tags as you like.
#   The following settings are available:
#
#     se: filename, volume, pitch
#       This setting defines the custom sound effect played when the
#       item is crafted. filename is a sound effect filename found in
#       the Audio/SE/ folder. volume is a value between 0~100. pitch is 
#       a value between 50~150. If this setting is omitted, the default
#       crafting sound effect defined in the customization module will
#       play instead.
#
#     amount: n
#       This setting defines the amount that is produced from one
#       set of ingredients, where n is a number. By default, the
#       amount produced from one set of ingredients is 1.
#
#     common_event: id
#     cev: id
#       This setting defines a common event that runs right after an
#       item is crafted where id is a common event ID number
#       from your database.
#
# Here are some examples of proper <recipebook> tags and <ingredients> tags:
#
#     <recipebook>
#     weapon: 1, 2, 7, 8, 13, 14, 19, 20
#     weapon: 25, 37, 38
#     armor: 1, 2, 3, 4, 5
#     item: 40
#     </recipebook>
#
# It is important to know that Note boxes have iffy word wrap distinction. 
# If a line is too long and overflows into the next line, that next line 
# might be treated as a new line in the Note box. To stay on the safe side, 
# if you have a long list of ids for a single item type setting, you 
# should start the next line with the similar type setting. See the 
# "weapon:" settings in this example tag.
#
#     <ingredients>
#     item: 29 x3
#     item: 30 x2
#     item: 31
#     </ingredients>
#
# Each ingredient id must be on its own line, unlike the recipebook tag. 
# More than 6 ingredients are possible, but the Required Ingredients
# window will not display more than 6. The last setting tag "item: 31" does
# not have an "xN" multiplier which means the script will automatically
# assume "x1".
#
#     <ingredients>
#     fee: 30
#     se: Bell3, 80, 100
#     tool: item 40
#     item: 21
#     item: 22 x2
#     </ingredients>
#
# This tag is an example of how to use the "fee" and "tool" setting tags.
# Item ID 40 is required to craft the item, but it will not be consumed.
# Each item crafted costs 30 gold. The sound effect Bell3 will play
# when the item is crafted.
#
#=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
#      Script Calls   
#=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
# The following Script Calls are meant to be used in "Script..." event 
# commands found under Tab 3 when creating a new event.
#
# call_tocrafting_scene
#   This script call opens up a Tactics Ogre Crafting scene with all 
#   recipebooks the player has in their inventory.
#
# call_tocrafting_scene( :category, :category, ...)
#   This script call opens up the Tactics Ogre Crafting scene with 
#   only recipebooks that have the category included in one of the
#   script call's arguments. You can list as many categories in the 
#   script call's arguments separated by commas as you like. Category
#   names must always be preceeded by a colon (:).
#
# Here is an example of a script call using call_tocrafting_scene with
# category arguments:
#
#   call_tocrafting_scene( :smithing )
#   
# This script call will open up the crafting scene with only recipebooks
# that have the category of "smithing".
#
#--------------------------------------------------------------------------
#      FAQ   
#--------------------------------------------------------------------------
# --Why am I allowed to craft items that have no required ingredients?
#
#     This was done on purpose to ease game development. I assumed that
#     when people finalize a game, they will have an appropriate list of
#     ingredients for each craftable item defined by then.
#
# --Can an item/armor/weapon have a <recipebook> tag AND an <ingredients> 
#   tag?
#   
#     Yes.
#
# --Why isn't "Success Rate" also implemented in this script from 
#   Tactics Ogre PSP?
#
#     Because I think Success Rate on crafting in single-player games
#     is annoying and pointless due to save and load. But if there is
#     demand for it, I can implement it.
#--------------------------------------------------------------------------
#      Compatibility   
#--------------------------------------------------------------------------
# This script aliases the following default VXA methods:
#
#     DataManager#load_database
#    
# There are no default method overwrites.
#
# This script has built-in compatibility with the following scripts:
#
#     -Xiderwong Action System (XAS) VX Ace
#     -Yanfly Engine Ace - Ace Menu Engine by YF
#     -Scene Interpreter by Tsukihime
#
# Requests for compatibility with other scripts are welcome.
#--------------------------------------------------------------------------
#      Terms and Conditions   
#--------------------------------------------------------------------------
# Please do not repost this script elsewhere without permission. 
# Free for non-commercial use. For commercial use, contact me first.
#
# Newest versions of this script can be found at 
#                                           http://mrbubblewand.wordpress.com/
#=============================================================================

$imported ||= {}
$imported["BubsTOCrafting"] = 2.04

#==========================================================================
# ++ START OF USER CUSTOMIZATION MODULE ++
#==========================================================================
module Bubs
  #==========================================================================
  # ++ TO Crafting Settings
  #==========================================================================
  module TOCrafting
  #--------------------------------------------------------------------------
  #   Ingredients List Display Settings
  #--------------------------------------------------------------------------
  INGREDIENTS_HEADER_TEXT = "Components" # Header text
  INGREDIENTS_PAGE_SIZE = 5 # 6 is recommended for 640x480 resolutions
  NOT_ENOUGH_INGREDIENTS_COLOR = 10 # Windowskin color index, default 10 (red)

  #--------------------------------------------------------------------------
  #   Ingredients Info Page Footer Text
  #--------------------------------------------------------------------------
  # Recommended length: 22 characters "                      "
  #INGREDIENTS_VIEW_MORE_FOOTER_TEXT = "←A  Shift: More...  S→"
  INGREDIENTS_VIEW_MORE_FOOTER_TEXT = "←A                  S→"

  #--------------------------------------------------------------------------
  #   Tools Display Settings
  #--------------------------------------------------------------------------
  TOOL_AVAILABLE_TEXT = "Available"
  TOOL_AVAILABLE_TEXT_COLOR = 3 # Windowskin color index, default 3 (green)
  TOOL_UNAVAILABLE_TEXT = "Unavailable"
  TOOL_UNAVAILABLE_TEXT_COLOR = 10 # Windowskin color index, default 10 (red)
  
  #--------------------------------------------------------------------------
  #   Faded Requirement Not Met Display Settings
  #--------------------------------------------------------------------------
  # true  : Ingredient quantity and Tool requirement text will be faded
  #         out like the item name if the requirement isn't met
  # false : Ingredient quantity and Tool requirement text will not be faded
  FADED_REQUIREMENT_QUANTITY = false
    
  #--------------------------------------------------------------------------
  #   Crafting Gold Fee Default Markdown/Markup Rate
  #--------------------------------------------------------------------------
  # If a "gold: amount" setting is not included in an <ingredients> tag,
  # it will use the item's Price in the database by default. This setting
  # allows you to automatically increase or decrease that item, armor
  # or weapon price by a specified rate where 100.0 is normal price and
  # 0.0 is free.
  CRAFTING_FEE_PRICE_RATE = 0.0
  #--------------------------------------------------------------------------
  #   Gold Window Settings
  #--------------------------------------------------------------------------
  # true  : Gold window appears in crafting scene
  # false : Gold crafting fees appear in ingredients list, no gold window
  USE_GOLD_WINDOW = false
  GOLD_WINDOW_ICON_INDEX = 361 # Icon Index number
  GOLD_WINDOW_TEXT = "Gold"
  
  #--------------------------------------------------------------------------
  #   Crafting Result Header Text
  #--------------------------------------------------------------------------
  RESULT_WINDOW_HEADER_TEXT = "You crafted"
  
  #--------------------------------------------------------------------------
  #   Stretch Recipebook Pictures Setting
  #--------------------------------------------------------------------------
  # Recommended width and height for book covers images:
  #
  #     width: 248, height: 320 (default resolutions)
  #     width: 296, height: 384 (480x640 resolutions)
  #
  # true  : Book cover pics are stretched to fit the contents of the window.
  # false : Book cover pics are drawn normally.
  STRETCH_RECIPEBOOK_PICTURES = false
  #--------------------------------------------------------------------------
  #   Recipebook Images Folder Directory
  #--------------------------------------------------------------------------
  # Project folder where recipebook pictures are located.
  #
  # Default: "Graphics/Pictures/"
  RECIPEBOOK_PICTURES_DIRECTORY = "Graphics/Pictures/"
  
  #--------------------------------------------------------------------------
  #   Default Crafting Result Sound Effect
  #--------------------------------------------------------------------------
  # Filename : SE filename in Audio/SE/ folder
  # Volume   : Between 0~100
  # Pitch    : Between 50~150
  #
  #                       Filename, Volume, Pitch
  CRAFTING_RESULT_SE = [   "Bell2",     80,   100]
    
  #--------------------------------------------------------------------------
  #   Actor Requirement Display Settings
  #--------------------------------------------------------------------------
  ACTOR_AVAILABLE_TEXT = "Available"
  ACTOR_AVAILABLE_TEXT_COLOR = 3 # Windowskin color index, default 3 (green)
  ACTOR_UNAVAILABLE_TEXT = "Unavailable"
  ACTOR_UNAVAILABLE_TEXT_COLOR = 10 # Windowskin color index, default 10 (red)
  
  #--------------------------------------------------------------------------
  #   Change Ingredident Page Button
  #--------------------------------------------------------------------------
  # This setting determine which gamepad button changes the ingredient
  # window page. Possible buttons include :LEFT, :RIGHT, :UP, :DOWN,
  # :A, :B, :C, :X, :Y, :Z, :L, :R
  NEXT_INGREDIENT_PAGE_BUTTON = :A
    
  #--------------------------------------------------------------------------
  #   YEA Ace Menu Engine - Custom Menu Command Setting
  #--------------------------------------------------------------------------
  # This setting only takes effect when YEA - Ace Menu Engine is installed
  # in the same project.
  #
  # To add the TOCrafting scene to Ace Menu Engine, look for a 
  # configuration setting called "- Main Menu Settings -". There is a
  # variable called COMMANDS that has an array of orange symbols. Add
  # the symbol :tocrafting to the COMMANDS array to add the crafting
  # command to your menu.
  #
  # The setting here working exactly the same as the CUSTOM_COMMAND
  # setting in Ace Menu Engine. For more information, please refer to
  # the Ace Menu Engine script.
  TOCRAFTING_CUSTOM_COMMAND = {
  #             ["Display Name", EnableSwitch, ShowSwitch,      Handler Method],
    :tocrafting => [  "Crafting",           0,          0, :command_tocrafting],
  } # <- Do not delete.

  end # module TOCrafting
end # module Bubs

#==========================================================================
# ++ END OF USER CUSTOMIZATION MODULE ++
#==========================================================================


#==============================================================================
# ++ Sound
#==============================================================================
module Sound
  #--------------------------------------------------------------------------
  # new method : play_tocrafting_result
  #--------------------------------------------------------------------------
  def self.play_tocrafting_result
    filename = Bubs::TOCrafting::CRAFTING_RESULT_SE[0]
    volume   = Bubs::TOCrafting::CRAFTING_RESULT_SE[1]
    volume = volume * 0.01 * $game_system.get_sfx_volume #Dyluck
    pitch    = Bubs::TOCrafting::CRAFTING_RESULT_SE[2]
    Audio.se_play("Audio/SE/" + filename, volume, pitch) 
  end
  
  #--------------------------------------------------------------------------
  # new method : play_custom_tocrafting_result
  #--------------------------------------------------------------------------
  def self.play_custom_tocrafting_result(filename, volume, pitch)
    Audio.se_play("Audio/SE/" + filename, volume, pitch) 
  end
  
  #--------------------------------------------------------------------------
  # new method : play_page_change
  #--------------------------------------------------------------------------
  def self.play_page_change
    filename = Bubs::TOCrafting::PAGE_CHANGE_SE[0]
    volume   = Bubs::TOCrafting::PAGE_CHANGE_SE[1]
    volume = volume * 0.01 * $game_system.get_sfx_volume #Dyluck
    pitch    = Bubs::TOCrafting::PAGE_CHANGE_SE[2]
    Audio.se_play("Audio/SE/" + filename, volume, pitch) 
  end
end # module Sound


#==============================================================================
# ++ Cache
#==============================================================================
module Cache
  #--------------------------------------------------------------------------
  # new method : recipebook_cover
  #--------------------------------------------------------------------------
  def self.recipebook_cover(filename)
    load_bitmap(Bubs::TOCrafting::RECIPEBOOK_PICTURES_DIRECTORY, filename)
  end
end # module Cache


#==========================================================================
# ++ Bubs::Regexp
#==========================================================================
module Bubs
  module Regexp
    RECIPEBOOK_START_TAG = /<(?:RECIPE[_\s]?BOOK|ricetta)>/i
    RECIPEBOOK_END_TAG = /<\/(?:RECIPE[_\s]?BOOK|ricetta)>/i
    RECIPEBOOK_OBJ_TAG = /(\w+):\s*(\d+(?:\s*,\s*\d+)*)/i
    RECIPEBOOK_COVER_TAG = /(?:PICTURE|PIC|COVER|immagine|IMG):\s*(\w+)/i
    RECIPEBOOK_CATEGORY_TAG = /category?:\s*(\w+)/i

    INGREDIENT_START_TAG = /<(?:INGREDIENTS?|ingredienti)>/i
    INGREDIENT_END_TAG = /<\/(?:INGREDIENTS?|ingredienti)>/i
    INGREDIENT_OBJ_TAG = /(\w+):\s*[×x]?(\d+)\s*[×x]?(\d+)?/i
    
    CRAFT_RESULT_START_TAG = /<(?:CRAFT[_\s]RESULT?|risultato)>/i
    CRAFT_RESULT_END_TAG = /<\/(?:CRAFT[_\s]RESULT?|risultato)>/i
    CRAFT_RESULT_OBJ_TAG = /(\w+):\s*[×x]?(\d+)\s*[×x]?(\d+)?/i
    
    REQUIRED_TOOLS_TAG = /(?:TOOLS?|strumento):\s*(\w+)\s*(\d+)/i
    
    CRAFTING_CUSTOM_SE_TAG = /SE:\s*(\w+)\s*,\s*(\d+)\s*,\s*(\d+)/i

  end # module Regexp
end # module Bubs


#==========================================================================
# ++ DataManager
#==========================================================================
module DataManager
  #--------------------------------------------------------------------------
  # alias : load_database
  #--------------------------------------------------------------------------
  class << self; alias load_database_bubs_tocrafting load_database; end
  def self.load_database
    load_database_bubs_tocrafting # alias
    load_notetags_bubs_tocrafting
  end
  
  #--------------------------------------------------------------------------
  # new method : load_notetags_bubs_tocrafting
  #--------------------------------------------------------------------------
  def self.load_notetags_bubs_tocrafting
    groups = [$data_items, $data_weapons, $data_armors]
    for group in groups
      for obj in group
        next if obj.nil?
        obj.load_notetags_bubs_tocrafting
      end # for obj
    end # for group
  end # def
  
end # module DataManager


#==========================================================================
# ++ RPG::BaseItem
#==========================================================================
class RPG::BaseItem
  #--------------------------------------------------------------------------
  # public instance variables
  #--------------------------------------------------------------------------
  attr_accessor :recipe_list
  attr_accessor :ingredient_list
  attr_accessor :tocrafting_tools
  attr_accessor :tocrafting_actors
  attr_accessor :tocrafting_skills
  attr_accessor :tocrafting_gold_fee
  attr_accessor :tocrafting_bookcover
  attr_accessor :tocrafting_se
  attr_accessor :tocrafting_category
  attr_accessor :tocrafting_amount
  attr_accessor :tocrafting_cev

  #--------------------------------------------------------------------------
  # common cache : load_notetags_bubs_tocrafting
  #--------------------------------------------------------------------------
  def load_notetags_bubs_tocrafting
    @recipe_list = []
    @ingredient_list = []
    @tocrafting_tools = []
    @tocrafting_actors = []
    @tocrafting_skills = []
    @tocrafting_gold_fee = self.price
    @tocrafting_bookcover = ""
    @tocrafting_se = []
    @tocrafting_category = :none
    @tocrafting_amount = 1
    @tocrafting_cev = 0

  
    load_notetags_default_fee_bubs_tocrafting
    
    recipe_tag = false
    ingredient_tag = false
    result_tag = false
    
    self.note.split(/[\r\n]+/).each { |line|
      case line
      when Bubs::Regexp::RECIPEBOOK_START_TAG
        recipe_tag = true
      when Bubs::Regexp::RECIPEBOOK_END_TAG
        recipe_tag = false
        
      when Bubs::Regexp::INGREDIENT_START_TAG
        ingredient_tag = true
      when Bubs::Regexp::INGREDIENT_END_TAG
        ingredient_tag = false
        
      when Bubs::Regexp::CRAFT_RESULT_START_TAG
        result_tag = true
      when Bubs::Regexp::CRAFT_RESULT_END_TAG
        result_tag = false
        
      when Bubs::Regexp::RECIPEBOOK_COVER_TAG
        next unless recipe_tag
        @tocrafting_bookcover = $1
        
      when Bubs::Regexp::RECIPEBOOK_CATEGORY_TAG
        next unless recipe_tag
        @tocrafting_category = $1.to_sym
        
      when Bubs::Regexp::REQUIRED_TOOLS_TAG # tools
        next unless ingredient_tag
        load_notetags_tools_bubs_tocrafting(line)
        
      when Bubs::Regexp::CRAFTING_CUSTOM_SE_TAG
        next unless ingredient_tag || result_tag
        @tocrafting_se = [$1, $2.to_i, $3.to_i]


      else
        load_notetags_recipelist_bubs_tocrafting(line) if recipe_tag
        load_notetags_ingredients_bubs_tocrafting(line) if ingredient_tag
        load_notetags_craft_result_bubs_tocrafting(line) if result_tag
      end # case
    } # self.note.split
    @recipe_list.compact!
    @ingredient_list.compact!
    @tocrafting_tools.compact!
    @tocrafting_actors.compact!
    @tocrafting_skills.compact!
  end # load_notetags_bubs_tocrafting
  
  #--------------------------------------------------------------------------
  # common cache : load_notetags_default_fee_bubs_tocrafting
  #--------------------------------------------------------------------------
  def load_notetags_default_fee_bubs_tocrafting
    rate = Bubs::TOCrafting::CRAFTING_FEE_PRICE_RATE
    @tocrafting_gold_fee = (@tocrafting_gold_fee * (rate * 0.01)).to_i
  end

  #--------------------------------------------------------------------------
  # common cache : load_notetags_recipelist_bubs_tocrafting
  #--------------------------------------------------------------------------
  def load_notetags_recipelist_bubs_tocrafting(line)
    return unless line =~ Bubs::Regexp::RECIPEBOOK_OBJ_TAG ? true : false
    match = $~.clone
    id_array = match[2].scan(/\d+/)
    
    case match[1].upcase
    when "I", "ITEM", "OGGETTO"
      for id in id_array
        @recipe_list.push( $data_items[id.to_i] )
      end
      
    when "W", "WEAPON", "WEP", "ARMA"
      for id in id_array
        @recipe_list.push( $data_weapons[id.to_i] )
      end
      
    when "A", "ARMOR", "ARMOUR", "ARM", "ARMATURA"
      for id in id_array
        @recipe_list.push( $data_armors[id.to_i] )
      end # for
      
    end # case
  end # def load_notetags_recipelist_bubs_tocrafting
    
  #--------------------------------------------------------------------------
  # common cache : load_notetags_ingredients_bubs_tocrafting
  #--------------------------------------------------------------------------
  def load_notetags_ingredients_bubs_tocrafting(line)
    return unless line =~ Bubs::Regexp::INGREDIENT_OBJ_TAG ? true : false
    amount = $3 ? $3.to_i : 1
    
    case $1.upcase
    when "I", "ITEM", "OGGETTO"
      amount.times do @ingredient_list.push( $data_items[$2.to_i] ) end
      
    when "W", "WEAPON", "WEP", "ARMA"
      amount.times do @ingredient_list.push( $data_weapons[$2.to_i] ) end
      
    when "A", "ARMOR", "ARMOUR", "ARM", "ARMATURA"
      amount.times do @ingredient_list.push( $data_armors[$2.to_i] ) end
    
    when "FEE", "GOLD", "PREZZO", "ORO"
      @tocrafting_gold_fee = $2.to_i
      
    when "SKILL"
      @tocrafting_skills.push( $2.to_i )
      
    when "ACTOR", "EROE"
      @tocrafting_actors.push( $2.to_i )
      
    end # case $1.upcase
  end # def load_notetags_ingredients_bubs_tocrafting
  
  #--------------------------------------------------------------------------
  # common cache : load_notetags_tools_bubs_tocrafting
  #--------------------------------------------------------------------------
  def load_notetags_tools_bubs_tocrafting(line)
    line =~ Bubs::Regexp::REQUIRED_TOOLS_TAG
      
    case $1.upcase
    when "I", "ITEM", "OGGETTO"
      @tocrafting_tools.push( $data_items[$2.to_i] )
      
    when "W", "WEAPON", "WEP", "ARMA"
      @tocrafting_tools.push( $data_weapons[$2.to_i] )
      
    when "A", "ARMOR", "ARMOUR", "ARM", "ARMATURA"
      @tocrafting_tools.push( $data_armors[$2.to_i] )
      
    end # case
  end # def load_notetags_tools_bubs_tocrafting
  
  #--------------------------------------------------------------------------
  # common cache : load_notetags_craft_result_bubs_tocrafting
  #--------------------------------------------------------------------------
  def load_notetags_craft_result_bubs_tocrafting(line)
    line =~ Bubs::Regexp::CRAFT_RESULT_OBJ_TAG
    
    case $1.upcase
    when "COMMON_EVENT", "CEV", "EVENTO_COMUNE", "EVC" # common event
      @tocrafting_cev = $2.to_i
    
    when "AMOUNT", "AMT", "QUANTITÀ" # amount
      @tocrafting_amount = $2.to_i

    end
  end
  #--------------------------------------------------------------------------
  # new method : recipebook?
  #--------------------------------------------------------------------------
  def recipebook?
    return false unless self.is_a?(RPG::UsableItem) || self.is_a?(RPG::EquipItem)
    return !@recipe_list.empty?
  end
end # class RPG::BaseItem


#==============================================================================
# ++ Window_TOCraftingRecipeList
#==============================================================================
class Window_TOCraftingRecipeList < Window_ItemList
  #--------------------------------------------------------------------------
  # public instance variables
  #--------------------------------------------------------------------------
  attr_reader :info_window
  attr_reader :header_window
  attr_reader :cover_window
  #--------------------------------------------------------------------------
  # initialize
  #--------------------------------------------------------------------------
  def initialize(x, y, height)
    super(x, y, window_width, height)
  end

  #--------------------------------------------------------------------------
  # categories=
  #--------------------------------------------------------------------------
  def categories=(categories)
    @categories = categories
  end
  
  #--------------------------------------------------------------------------
  # window_width
  #--------------------------------------------------------------------------
  def window_width
    Graphics.width / 2
  end
  
  #--------------------------------------------------------------------------
  # current_item_enabled?           # Get Activation State of Selection Item
  #--------------------------------------------------------------------------
  def current_item_enabled?
    enable?(@data[index])
  end
  
  #--------------------------------------------------------------------------
  # enable?                               # Display in Enabled State?
  #--------------------------------------------------------------------------
  def enable?(item)
    return false if item.nil?
    return true
  end
  
  #--------------------------------------------------------------------------
  # col_max
  #--------------------------------------------------------------------------
  def col_max
    return 1
  end

  #--------------------------------------------------------------------------
  # include?                              # Include in Item List?
  #--------------------------------------------------------------------------
  def include?(item)
    return false if item.nil?
    return include_recipebook?(item) if item.recipebook?
    return false
  end
  
  #--------------------------------------------------------------------------
  # include_recipebook?
  #--------------------------------------------------------------------------
  def include_recipebook?(item)
    @categories ||= []
    return true if @categories.empty?
    return true if @categories.include?(item.tocrafting_category)
    return false
  end
  
  #--------------------------------------------------------------------------
  # draw_item
  #--------------------------------------------------------------------------
  def draw_item(index)
    item = @data[index]
    if item
      rect = item_rect(index)
      rect.width -= 4
      draw_item_name(item, rect.x, rect.y, enable?(item), rect.width - 24)
    end
  end
  
  #--------------------------------------------------------------------------
  # info_window=
  #--------------------------------------------------------------------------
  def info_window=(info_window)
    @info_window = info_window
    call_update_help
  end
  
  #--------------------------------------------------------------------------
  # header_window=
  #--------------------------------------------------------------------------
  def header_window=(header_window)
    @header_window = header_window
  end
  
  #--------------------------------------------------------------------------
  # cover_window=
  #--------------------------------------------------------------------------
  def cover_window=(cover_window)
    @cover_window = cover_window
  end
  
  #--------------------------------------------------------------------------
  # update_help
  #--------------------------------------------------------------------------
  def update_help
    @help_window.set_item(item) if @help_window
    @info_window.item = item if @info_window
    @header_window.item = item if @header_window
    @cover_window.item = item if @cover_window
  end

end # Window_TOCraftingRecipeList


#==============================================================================
# ++ Window_TOCraftingItemListHeader
#==============================================================================
class Window_TOCraftingItemListHeader < Window_Base
  #--------------------------------------------------------------------------
  # initialize
  #--------------------------------------------------------------------------
  def initialize(x, y)
    super(x, y, window_width, window_height)
    @item = nil
  end
  
  #--------------------------------------------------------------------------
  # window_width
  #--------------------------------------------------------------------------
  def window_width
    Graphics.width / 2
  end
  
  #--------------------------------------------------------------------------
  # window_height
  #--------------------------------------------------------------------------
  def window_height
    fitting_height(1)
  end
  
  #--------------------------------------------------------------------------
  # item=                                   # Set window header item
  #--------------------------------------------------------------------------
  def item=(item)
    @item = item
  end
  
  #--------------------------------------------------------------------------
  # refresh
  #--------------------------------------------------------------------------
  def refresh
    contents.clear
    draw_itemlist_header_item(0, 0)
  end
  
  #--------------------------------------------------------------------------
  # draw_itemlist_header_item
  #--------------------------------------------------------------------------
  def draw_itemlist_header_item(x, y)
    return unless @item
    draw_item_name(@item, x, y, true, contents.width - 28)
  end
  
end # class Window_TOCraftingItemListHeader


#==============================================================================
# ++ Window_TOCraftingItemList
#==============================================================================

class Window_TOCraftingItemList < Window_ItemList
  #--------------------------------------------------------------------------
  # initialize
  #--------------------------------------------------------------------------
  def initialize(x, y, height)
    super(x, y, window_width, height)
    @item = nil
  end
  
  #--------------------------------------------------------------------------
  # update
  #--------------------------------------------------------------------------
  def update
    if $imported["TH_SceneInterpreter"]
      return if SceneManager.scene.interpreter.running?
    end
    super
  end
  
  
  #--------------------------------------------------------------------------
  # window_width
  #--------------------------------------------------------------------------
  def window_width
    Graphics.width / 2
  end
  
  #--------------------------------------------------------------------------
  # col_max
  #--------------------------------------------------------------------------
  def col_max
    return 1
  end
  
  #--------------------------------------------------------------------------
  # item=
  #--------------------------------------------------------------------------
  def item=(item)
    @item = item
    refresh
  end
  
  #--------------------------------------------------------------------------
  # info_window=
  #--------------------------------------------------------------------------
  def info_window=(info_window)
    @info_window = info_window
    call_update_help
  end
  
  #--------------------------------------------------------------------------
  # gold_window=
  #--------------------------------------------------------------------------
  def gold_window=(gold_window)
    @gold_window = gold_window
    call_update_help
  end
  
  #--------------------------------------------------------------------------
  # current_item_enabled?           # Get Activation State of Selection Item
  #--------------------------------------------------------------------------
  def current_item_enabled?
    enable?(@data[index])
  end
  
  #--------------------------------------------------------------------------
  # enable?                               # Display in Enabled State?
  #--------------------------------------------------------------------------
  def enable?(item)
    return false if item.nil?
    return false unless has_recipebook?
    return false if item.tocrafting_gold_fee > $game_party.gold
    return false if $game_party.item_max?(item)
    return false unless have_tools?(item)
    return false unless have_actors?(item)
    return true if item.ingredient_list.empty?
    return have_ingredients?(item)
  end

  #--------------------------------------------------------------------------
  # has_recipebook?                       
  #--------------------------------------------------------------------------
  def has_recipebook?
    return true if $imported["TH_TOCraftingShop"]
    return true if $game_party.item_number(@item) > 0
    return false
  end
  
  #--------------------------------------------------------------------------
  # have_ingredients?                            
  #--------------------------------------------------------------------------
  def have_ingredients?(item)
    item.ingredient_list.uniq.each do |ingredient|
      party_amount = $game_party.item_number(ingredient)
      required_amount = item.ingredient_list.count(ingredient)
      return false if party_amount < required_amount  
    end # do
    return true
  end
  
  #--------------------------------------------------------------------------
  # have_tools?                            
  #--------------------------------------------------------------------------
  def have_tools?(item)
    item.tocrafting_tools.each do |tool|
      return false if !$game_party.has_item?(tool)
    end
    return true
  end
  
  #--------------------------------------------------------------------------
  # have_actors?
  #--------------------------------------------------------------------------
  def have_actors?(item)
    item.tocrafting_actors.each do |id|
      return false unless $game_party.members.include?($game_actors[id])
    end
    return true
  end
  
  #--------------------------------------------------------------------------
  # include?                              # Include in Item List?
  #--------------------------------------------------------------------------
  def include?(item)
    return false if item.nil?
    return true
  end
  
  #--------------------------------------------------------------------------
  # make_item_list
  #--------------------------------------------------------------------------
#  def make_item_list
#    @data = @item.recipe_list.each { |item| include?(item) } if @item
#  end
  #--------------------------------------------------------------------------
  # make_item_list #Dyluck
  #--------------------------------------------------------------------------
  def make_item_list
    @item.recipe_list.each { |item| include?(item) } if @item
    @data = []
    @item.recipe_list.each { |ele| @data.push(ele) if has_skill_level?(ele)} if @item
    #@data = @item.recipe_list.each { |item| include?(item) } if @item
    #@data.delete_if { |element| !has_skill_level?(element) } if @item
  end

  #--------------------------------------------------------------------------
  # has_skill_level? #Dyluck
  #--------------------------------------------------------------------------
  
  def has_skill_level?(item)
    if item.note =~ /<req (.*)>/i
      my_req = $1.to_i
    else
      return true
    end
    if item.note =~ /<var (.*)>/i
      x = $1.to_i
      #my_var = $game_variables[x] if $game_variables
    else
      return true
    end
    if $game_variables[x] == my_req #changed >= to == so can't craft duplicate
      return true
    end
    return false
  end
     
  #--------------------------------------------------------------------------
  # update_help
  #--------------------------------------------------------------------------
  def update_help
    @help_window.set_item(item) if @help_window
    @info_window.item = item if @info_window
    @gold_window.item = item if @gold_window
  end
  
  #--------------------------------------------------------------------------
  # update_open
  #--------------------------------------------------------------------------
  def update_open
    self.openness += 24
    @opening = false if open?
  end

end # class Window_TOCraftingItemList


#==============================================================================
# ++ Window_TOCraftingInfo
#==============================================================================
# If you get an error on this line, place this crafting script BELOW
# the script "Info Pages Window" in your script editor list.
class Window_TOCraftingInfo < Window_InfoPages
  #--------------------------------------------------------------------------
  # Constants (Starting Number of Buff/Debuff Icons)
  #--------------------------------------------------------------------------
  ICON_BUFF_START       = 5584 #64              # buff (16 icons)
  ICON_DEBUFF_START     = 5600 #80              # debuff (16 icons)
  #--------------------------------------------------------------------------
  # public instance variables
  #--------------------------------------------------------------------------
  attr_accessor :number
  attr_accessor :page_change
  attr_accessor :vert_page_index
  attr_reader   :ingredients
  #--------------------------------------------------------------------------
  # initialize
  #--------------------------------------------------------------------------
  def initialize(x, y, width, height)
    super
    @number = 1
    @ingredients = []
    set_page_keys
  end
  
  #--------------------------------------------------------------------------
  # inh ov : set_page_keys
  #--------------------------------------------------------------------------
  def set_page_keys
    @page_index = @vert_page_index = 0
    @item_pages = Bubs::InfoPages::ITEM_INFO_PAGES.clone
    @equipitem_pages  = Bubs::InfoPages::EQUIP_INFO_PAGES.clone
    @item_pages.unshift(:ingredients)
    @equipitem_pages.unshift(:ingredients)
    refresh
  end
  
  #--------------------------------------------------------------------------
  # refresh
  #--------------------------------------------------------------------------
  def refresh
    contents.clear
    create_ingredients_array(@item) if @item
    standard_page_doodads(4, 0)
    return unless @item
    draw_page_contents(4, line_height * 2, @item)
  end
  
  #--------------------------------------------------------------------------
  # update
  #--------------------------------------------------------------------------
  def update
    if $imported["TH_SceneInterpreter"]
      return if SceneManager.scene.interpreter.running?
    end
    super
  end

  #--------------------------------------------------------------------------
  # item=                                        # Set Item
  #--------------------------------------------------------------------------
  def item=(item)
    @vert_page_index = 0
    super
  end


  #--------------------------------------------------------------------------
  # draw_page_contents
  #--------------------------------------------------------------------------
  def draw_page_contents(x, y, item)
    draw_ingredients(x, y) if current_page == :ingredients
    super
  end # def
    
  #--------------------------------------------------------------------------
  # update_page
  #--------------------------------------------------------------------------
  def update_page
    if visible
      if Input.trigger?(next_ingredient_page_button) && vert_page_max > 1
        next_ingredient_page if current_page == :ingredients
      end
    end
    super
  end
  
  #--------------------------------------------------------------------------
  # next_ingredient_page_button
  #--------------------------------------------------------------------------
  def next_ingredient_page_button
    Bubs::TOCrafting::NEXT_INGREDIENT_PAGE_BUTTON
  end

  #--------------------------------------------------------------------------
  # inh ov : draw_info_footer_text
  #--------------------------------------------------------------------------
  def draw_info_footer_text(x, y)
    if current_page == :ingredients
      draw_ingredients_footer_text(x, y)
    else
      super
    end
  end
  
  #--------------------------------------------------------------------------
  # ingredients_view_more_footer_text
  #--------------------------------------------------------------------------
  def ingredients_view_more_footer_text
    Bubs::TOCrafting::INGREDIENTS_VIEW_MORE_FOOTER_TEXT
  end
  
  #--------------------------------------------------------------------------
  # draw_ingredients_footer_text
  #--------------------------------------------------------------------------
  def draw_ingredients_footer_text(x, y)
    y = y + line_height * (contents.height / line_height - 1)
    rect = standard_rect(x, y)
    change_color(normal_color)
    if vert_page_max > 1
      draw_text(rect, ingredients_view_more_footer_text, 1)
    else
      draw_text(rect, normal_footer_text, 1)
    end
  end
  
  #--------------------------------------------------------------------------
  # next_ingredient_page
  #--------------------------------------------------------------------------
  def next_ingredient_page
    @vert_page_index = (@vert_page_index + 1) % vert_page_max
    refresh
  end
  
  #--------------------------------------------------------------------------
  # required_ingredients
  #--------------------------------------------------------------------------
  def required_ingredients
    @item.ingredient_list
  end
  
  #--------------------------------------------------------------------------
  # required_tools
  #--------------------------------------------------------------------------
  def required_tools
    @item.tocrafting_tools
  end
  
  #--------------------------------------------------------------------------
  # required_actors
  #--------------------------------------------------------------------------
  def required_actors
    @item.tocrafting_actors
  end
  
  #--------------------------------------------------------------------------
  # ingredients_header_text
  #--------------------------------------------------------------------------
  def ingredients_header_text
    Bubs::TOCrafting::INGREDIENTS_HEADER_TEXT
  end
  
  #--------------------------------------------------------------------------
  # inh ov : draw_info_header_text
  #--------------------------------------------------------------------------
  def draw_info_header_text(x, y)
    if current_page == :ingredients
      draw_ingredients_header_text(x, y)
    else
      super
    end
  end
  
  #--------------------------------------------------------------------------
  # draw_ingredients_header_text
  #--------------------------------------------------------------------------
  def draw_ingredients_header_text(x, y)
    rect = standard_rect(x, y)
    change_color(system_color)
    draw_text(rect, ingredients_header_text)
    draw_icon(@item.icon_index, rect.width - 24, y) if @item
  end
  
  #--------------------------------------------------------------------------
  # use_gold_window?
  #--------------------------------------------------------------------------
  def use_gold_window?
    Bubs::TOCrafting::USE_GOLD_WINDOW
  end
  
  #--------------------------------------------------------------------------
  # create_ingredient_array
  #--------------------------------------------------------------------------
  def create_ingredients_array(item)
    @ingredients = []
    container = Struct.new(:type, :obj)
    
    if !use_gold_window? && @item.tocrafting_gold_fee > 0
      ingredient = container.new(:gold, @item.tocrafting_gold_fee)
      @ingredients.push( ingredient )
    end
    
    required_actors.uniq.each do |id|
      ingredient = container.new(:actor, $game_actors[id])
      @ingredients.push( ingredient )
    end
    
    required_tools.uniq.each do |obj|
      ingredient = container.new(:tool, obj)
      @ingredients.push( ingredient )
    end
    
    required_ingredients.uniq.each do |obj|
      ingredient = container.new(:ingredient, obj)
      @ingredients.push( ingredient )
    end
  end
  
  #--------------------------------------------------------------------------
  # draw_ingredients
  #--------------------------------------------------------------------------
  def draw_ingredients(x, y)
    return unless @item
    i = 0
    @vert_page_index = 0 if viewable_ingredients.nil?
    for ingredient in viewable_ingredients
      
      case ingredient.type
      when :gold
        draw_gold_info(ingredient.obj, x, y)
        i += 1
      when :actor
        draw_actor_req_info(ingredient.obj, x, y + line_height * (i * 2))
        i += 1
      when :tool
        draw_tools_info(ingredient.obj, x, y + line_height * (i * 2))
        i += 1
      when :ingredient
        draw_ingredient_info(ingredient.obj, x, y + line_height * (i * 2))
        i += 1
      end
    end
  end

  #--------------------------------------------------------------------------
  # viewable_ingredients
  #--------------------------------------------------------------------------
  def viewable_ingredients
    @ingredients[@vert_page_index * vert_page_size, vert_page_size]
  end
  
  #--------------------------------------------------------------------------
  # vert_page_size                 # Number of Ingredients Displayable at Once
  #--------------------------------------------------------------------------
  def vert_page_size
    Bubs::TOCrafting::INGREDIENTS_PAGE_SIZE
  end

  #--------------------------------------------------------------------------
  # vert_page_max                            # Get Maximum Number of Pages
  #--------------------------------------------------------------------------
  def vert_page_max
    (@ingredients.size + vert_page_size) / vert_page_size
  end
  
  #--------------------------------------------------------------------------
  # required_amount
  #--------------------------------------------------------------------------
  def required_amount(item)
    required_ingredients.count(item) * @number
  end
  
  #--------------------------------------------------------------------------
  # party_amount
  #--------------------------------------------------------------------------
  def party_amount(item)
    $game_party.item_number(item)
  end
  
  #--------------------------------------------------------------------------
  # crafting_fee
  #--------------------------------------------------------------------------
  def crafting_fee
    @item.tocrafting_gold_fee
  end
  
  #--------------------------------------------------------------------------
  # party_gold
  #--------------------------------------------------------------------------
  def party_gold
    $game_party.gold
  end
  
  #--------------------------------------------------------------------------
  # currency_unit
  #--------------------------------------------------------------------------
  def currency_unit
    Vocab::currency_unit
  end
  
  #--------------------------------------------------------------------------
  # draw_tools_info
  #--------------------------------------------------------------------------
  def draw_tools_info(item, x, y)
    enabled = $game_party.has_item?(item)
    width = contents.width - 4 - x
    
    draw_item_name(item, x, y, enabled, width)
    draw_tool_availability_text(item, x, y, enabled)
  end
  
  #--------------------------------------------------------------------------
  # draw_actor_req_info
  #--------------------------------------------------------------------------
  def draw_actor_req_info(actor, x, y)
    enabled = $game_party.members.include?(actor)
    width = contents.width - 4 - x
    icon_index = actor_icon_id(actor.id)
    draw_icon(icon_index, x, y, enabled)
    draw_actor_availability_text(actor.id, x, y, enabled)
    change_color(normal_color, enabled)
    draw_text(x + 24, y, width, line_height, actor.name)
  end
  
  #--------------------------------------------------------------------------
  # draw_tool_availability_text
  #--------------------------------------------------------------------------
  def draw_tool_availability_text(item, x, y, enabled)
    rect = Rect.new(x, y + line_height, contents.width - 4 - x, line_height)
    if enabled
      change_color(text_color(Bubs::TOCrafting::TOOL_AVAILABLE_TEXT_COLOR))
      draw_text(rect, Bubs::TOCrafting::TOOL_AVAILABLE_TEXT, 2)
    else
      change_color(text_color(Bubs::TOCrafting::TOOL_UNAVAILABLE_TEXT_COLOR))
      draw_text(rect, Bubs::TOCrafting::TOOL_UNAVAILABLE_TEXT, 2)
    end
  end
  
  #--------------------------------------------------------------------------
  # draw_actor_availability_text
  #--------------------------------------------------------------------------
  def draw_actor_availability_text(item, x, y, enabled)
    rect = Rect.new(x, y + line_height, contents.width - 4 - x, line_height)
    if enabled
      change_color(text_color(Bubs::TOCrafting::ACTOR_AVAILABLE_TEXT_COLOR))
      draw_text(rect, Bubs::TOCrafting::ACTOR_AVAILABLE_TEXT, 2)
    else
      change_color(text_color(Bubs::TOCrafting::ACTOR_UNAVAILABLE_TEXT_COLOR))
      draw_text(rect, Bubs::TOCrafting::ACTOR_UNAVAILABLE_TEXT, 2)
    end
  end
  
  #--------------------------------------------------------------------------
  # draw_ingredient_info
  #--------------------------------------------------------------------------
  def draw_ingredient_info(item, x, y)
    enabled = party_amount(item) >= required_amount(item)
    width = contents.width - 4 - x
    
    draw_item_name(item, x, y, enabled, width)
    not_enough_ingredients_color unless enabled     
    rect = Rect.new(x, y + line_height, contents.width - 4 - x, line_height)
    draw_text(rect, sprintf("×%2d/%2d", required_amount(item), party_amount(item)), 2)
  end
  
  #--------------------------------------------------------------------------
  # draw_gold_info
  #--------------------------------------------------------------------------
  def draw_gold_info(item, x, y)
    return if item.nil?
    enabled = party_gold >= crafting_fee
    cx = text_size(currency_unit).width
    width = contents.width - 4 - x
    
    draw_gold_name(x, y, enabled)
    
    change_color(system_color)
    draw_text(x, y + line_height, width, line_height, currency_unit, 2)
    change_color(normal_color)
    
    not_enough_ingredients_color unless enabled
    text = sprintf("%8d/%8d", crafting_fee * @number, party_gold)
    draw_text(x, y + line_height, width - cx - 2, line_height, text, 2)
  end
  
  #--------------------------------------------------------------------------
  # draw_gold_name
  #--------------------------------------------------------------------------
  def draw_gold_name(x, y, enabled = true)
    draw_icon(Bubs::TOCrafting::GOLD_WINDOW_ICON_INDEX, x, y, enabled)
    change_color(normal_color, enabled)
    draw_text(x + 24, y, width, line_height, Bubs::TOCrafting::GOLD_WINDOW_TEXT)
  end
  
  #--------------------------------------------------------------------------
  # not_enough_ingredients_color
  #--------------------------------------------------------------------------
  def not_enough_ingredients_color
    enabled = !Bubs::TOCrafting::FADED_REQUIREMENT_QUANTITY
    color_index = Bubs::TOCrafting::NOT_ENOUGH_INGREDIENTS_COLOR
    change_color(text_color(color_index), enabled)
  end

end # class Window_TOCraftingInfo


#==============================================================================
# ++ Window_TOCraftingResult
#==============================================================================
class Window_TOCraftingResult < Window_Selectable
  #--------------------------------------------------------------------------
  # initialize
  #--------------------------------------------------------------------------
  def initialize(x, y)
    @item = nil
    @number = 0
    super(x, y, window_width,window_height)
  end
  
  #--------------------------------------------------------------------------
  # window_width
  #--------------------------------------------------------------------------
  def window_width
    Graphics.width / 2
  end
  
  #--------------------------------------------------------------------------
  # window_height
  #--------------------------------------------------------------------------
  def window_height
    fitting_height(2)
  end
  
  #--------------------------------------------------------------------------
  # set
  #--------------------------------------------------------------------------
  def set(item, number)
    @item = item
    @number = number
  end
  
  #--------------------------------------------------------------------------
  # * Frame Update
  #--------------------------------------------------------------------------
  def update
    super
    process_cursor_move
    process_handling
  end
    
  #--------------------------------------------------------------------------
  # refresh
  #--------------------------------------------------------------------------
  def refresh
    contents.clear
    draw_result_header_text(4, 0)
    draw_result_item(4, line_height)
  end
  
  #--------------------------------------------------------------------------
  # draw_result_header_text
  #--------------------------------------------------------------------------
  def draw_result_header_text(x, y)
    return unless @item
    rect = Rect.new(x, y, contents.width - 4 - x, line_height)
    change_color(system_color)
    draw_text(rect, Bubs::TOCrafting::RESULT_WINDOW_HEADER_TEXT, 1)
  end
  
  #--------------------------------------------------------------------------
  # draw_result_item
  #--------------------------------------------------------------------------
  def draw_result_item(x, y)
    return unless @item
    draw_item_name(@item, x, y, true)
    draw_item_amount(x, y, @number)
  end
  
  #--------------------------------------------------------------------------
  # draw_item_amount
  #--------------------------------------------------------------------------
  def draw_item_amount(x, y, number)
    rect = Rect.new(x, y, contents.width - 4 - x, line_height)
    draw_text(rect, sprintf("×%2d", number), 2)
  end

end # class Window_TOCraftingResult


#==============================================================================
# ++ Window_TOCraftingGold
#==============================================================================
class Window_TOCraftingGold < Window_Base
  #--------------------------------------------------------------------------
  # public instance variables
  #--------------------------------------------------------------------------
  attr_accessor :number
  #--------------------------------------------------------------------------
  # initialize
  #--------------------------------------------------------------------------
  def initialize
    super(0, 0, window_width, fitting_height(2))
    @item = nil
    @number = 1
    refresh
  end
  
  #--------------------------------------------------------------------------
  # window_width
  #--------------------------------------------------------------------------
  def window_width
    return Graphics.width / 2
  end
  
  #--------------------------------------------------------------------------
  # item=
  #--------------------------------------------------------------------------
  def item=(item)
    @item = item
    refresh
  end
  
  #--------------------------------------------------------------------------
  # refresh
  #--------------------------------------------------------------------------
  def refresh
    contents.clear
    draw_gold_info(4, 0)
  end

  #--------------------------------------------------------------------------
  # currency_unit
  #--------------------------------------------------------------------------
  def currency_unit
    Vocab::currency_unit
  end
  
  #--------------------------------------------------------------------------
  # open
  #--------------------------------------------------------------------------
  def open
    refresh
    super
  end
  
  #--------------------------------------------------------------------------
  # crafting_fee
  #--------------------------------------------------------------------------
  def crafting_fee
    @item.tocrafting_gold_fee
  end
  
  #--------------------------------------------------------------------------
  # party_gold
  #--------------------------------------------------------------------------
  def party_gold
    $game_party.gold
  end
  
  #--------------------------------------------------------------------------
  # draw_gold_info
  #--------------------------------------------------------------------------
  def draw_gold_info(x, y)
    return if @item.nil?
    enabled = party_gold >= crafting_fee
    cx = text_size(currency_unit).width
    width = contents.width - 4 - x
    
    draw_gold_name(x, y, enabled)
    
    change_color(system_color)
    draw_text(x, y + line_height, width, line_height, currency_unit, 2)
    change_color(normal_color)
    
    not_enough_ingredients_color unless enabled
    text = sprintf("%8d/%8d", crafting_fee * @number, party_gold)
    draw_text(x, y + line_height, width - cx - 2, line_height, text, 2)
  end
  
  #--------------------------------------------------------------------------
  # draw_gold_name
  #--------------------------------------------------------------------------
  def draw_gold_name(x, y, enabled = true)
    draw_icon(Bubs::TOCrafting::GOLD_WINDOW_ICON_INDEX, x, y, enabled)
    change_color(normal_color, enabled)
    draw_text(x + 24, y, width, line_height, Bubs::TOCrafting::GOLD_WINDOW_TEXT)
  end
  
  #--------------------------------------------------------------------------
  # not_enough_ingredients_color
  #--------------------------------------------------------------------------
  def not_enough_ingredients_color
    enabled = !Bubs::TOCrafting::FADED_REQUIREMENT_QUANTITY
    color_index = Bubs::TOCrafting::NOT_ENOUGH_INGREDIENTS_COLOR
    change_color(text_color(color_index), enabled) 
  end
end # class Window_TOCraftingGold


#==============================================================================
# ++ Window_TOCraftingNumber
#==============================================================================
class Window_TOCraftingNumber < Window_Selectable
  #--------------------------------------------------------------------------
  # public instance variables
  #--------------------------------------------------------------------------
  attr_accessor   :number                   # quantity entered
  attr_reader     :item
  #--------------------------------------------------------------------------
  # initialize
  #--------------------------------------------------------------------------
  def initialize(x, y, height)
    super(x, y, window_width, height)
    @item = nil
    @info_window = nil
    @max = 1
    @price = 0
    @number = 1
    @currency_unit = Vocab::currency_unit
    @hold_max = 1
    @actual_max = 1
  end
  
  #--------------------------------------------------------------------------
  # window_width
  #--------------------------------------------------------------------------
  def window_width
    return Graphics.width / 2
  end
  
  #--------------------------------------------------------------------------
  # info_window=
  #--------------------------------------------------------------------------
  def info_window=(info_window)
    @info_window = info_window
  end
  
  #--------------------------------------------------------------------------
  # gold_window=
  #--------------------------------------------------------------------------
  def gold_window=(gold_window)
    @gold_window = gold_window
  end
  
  #--------------------------------------------------------------------------
  # set
  #--------------------------------------------------------------------------
  def set(item, max, price, currency_unit = nil)
    @item = item
    @max = max
    @price = price
    @currency_unit = currency_unit if currency_unit
    @number = item.tocrafting_amount
    
    @hold_max = $game_party.max_item_number(item) - $game_party.item_number(item)
    temp = @hold_max % item.tocrafting_amount
    @actual_max = [[(@max * item.tocrafting_amount), @hold_max - temp].min, 0].max
    refresh
  end
  
  #--------------------------------------------------------------------------
  # currency_unit
  #--------------------------------------------------------------------------
  def currency_unit=(currency_unit)
    @currency_unit = currency_unit
    refresh
  end
  
  #--------------------------------------------------------------------------
  # refresh
  #--------------------------------------------------------------------------
  def refresh
    contents.clear
    draw_item_name(@item, 0, item_y)
    draw_number
    update_info_window
    update_gold_window
  end
  
  #--------------------------------------------------------------------------
  # draw_number
  #--------------------------------------------------------------------------
  def draw_number
    change_color(normal_color)
    draw_text(cursor_x - 28, item_y, 22, line_height, "×")
    draw_text(cursor_x, item_y, cursor_width - 4, line_height, @number, 2)
  end
  
  #--------------------------------------------------------------------------
  # draw_total_price
  #--------------------------------------------------------------------------
  def draw_total_price
    return if @item.nil?
    return if @item.tocrafting_gold_fee == 0
    width = contents_width - 8
    total_price = @price * (@number / @item.tocrafting_amount)
    draw_currency_value(total_price, @currency_unit, 4, price_y, width)
  end
  
  #--------------------------------------------------------------------------
  # item_y                        # Y Coordinate of Item Name Display Line
  #--------------------------------------------------------------------------
  def item_y
    contents_height / 2 - line_height * 3 / 2
  end
  
  #--------------------------------------------------------------------------
  # price_y                       # Y Coordinate of Price Display Line
  #--------------------------------------------------------------------------
  def price_y
    contents_height / 2 + line_height / 2
  end
  
  #--------------------------------------------------------------------------
  # cursor_width
  #--------------------------------------------------------------------------
  def cursor_width
    figures * 10 + 12
  end
  
  #--------------------------------------------------------------------------
  # cursor_x                      # Get X Coordinate of Cursor
  #--------------------------------------------------------------------------
  def cursor_x
    contents_width - cursor_width - 4
  end
  
  #--------------------------------------------------------------------------
  # figures              # Get Maximum Number of Digits for Quantity Display
  #--------------------------------------------------------------------------
  def figures
    return 2
  end
  
  #--------------------------------------------------------------------------
  # update                        # Frame Update
  #--------------------------------------------------------------------------
  def update
    super
    if active
      last_number = @number
      update_number
      if @number != last_number
        Sound.play_cursor
        refresh
      end
    end
  end
  
  #--------------------------------------------------------------------------
  # update_number                         # Update Quantity
  #--------------------------------------------------------------------------
  def update_number
    change_number(1) if Input.repeat?(:RIGHT)
    change_number(-1) if Input.repeat?(:LEFT)
    change_number(10) if Input.repeat?(:UP)
    change_number(-10) if Input.repeat?(:DOWN)
  end

  #--------------------------------------------------------------------------
  # change_number
  #--------------------------------------------------------------------------
  def change_number(amount)
    craft_amt = @item.tocrafting_amount
    temp = (@number + (amount * craft_amt)) 
    temp_mod = temp % craft_amt
    @number = [[temp - temp_mod, @actual_max].min, craft_amt].max
  end
  
  #--------------------------------------------------------------------------
  # update_cursor
  #--------------------------------------------------------------------------
  def update_cursor
    cursor_rect.set(cursor_x, item_y, cursor_width, line_height)
  end
  
  #--------------------------------------------------------------------------
  # update_info_window
  #--------------------------------------------------------------------------
  def update_info_window
    @info_window.number = (@number / @item.tocrafting_amount)
    @info_window.refresh
  end
  
  #--------------------------------------------------------------------------
  # update_gold_window
  #--------------------------------------------------------------------------
  def update_gold_window
    @gold_window.number = (@number / @item.tocrafting_amount)
    @gold_window.refresh
  end

end # class Window_TOCraftingNumber


#==============================================================================
# ++ Window_TOCraftingCover
#==============================================================================
class Window_TOCraftingCover < Window_Base
  #--------------------------------------------------------------------------
  # refresh
  #--------------------------------------------------------------------------
  def refresh
    contents.clear
    draw_bookcover(0, 0)
  end
  
  #--------------------------------------------------------------------------
  # item=
  #--------------------------------------------------------------------------
  def item=(item)
    @item = item
    refresh
  end
  
  #--------------------------------------------------------------------------
  # stretch_pictures?
  #--------------------------------------------------------------------------
  def stretch_pictures?
    Bubs::TOCrafting::STRETCH_RECIPEBOOK_PICTURES
  end
  
  #--------------------------------------------------------------------------
  # draw_bookcover
  #--------------------------------------------------------------------------
  def draw_bookcover(x, y)
    return unless @item
    bitmap = Cache.recipebook_cover(@item.tocrafting_bookcover)
    rect = Rect.new(0, 0, contents.width, contents.height)
    if stretch_pictures?
      contents.stretch_blt(rect, bitmap, bitmap.rect)
    else
      x = (contents.width - bitmap.width) / 2
      y = (contents.height - bitmap.height) / 2
      contents.blt(x, y, bitmap, rect)
    end
    bitmap.dispose
  end
  
end # class Window_TOCraftingCover


#==============================================================================
# ++ Game_Interpreter
#==============================================================================
class Game_Interpreter
  #--------------------------------------------------------------------------
  # new method : call_tocrafting_scene
  #--------------------------------------------------------------------------
  def call_tocrafting_scene(*args)
    SceneManager.call(Scene_TOCrafting)
    SceneManager.scene.prepare(args)
  end
  alias open_tocrafting_shop call_tocrafting_scene
end


#==============================================================================
# ++ Scene_TOCrafting
#==============================================================================
class Scene_TOCrafting < Scene_MenuBase
  #--------------------------------------------------------------------------
  # prepare
  #--------------------------------------------------------------------------
  def prepare(categories)
    @categories = categories
  end

  #--------------------------------------------------------------------------
  # start
  #--------------------------------------------------------------------------
  def start
    super
    check_required_scripts
    create_help_window
    create_gold_window
    create_cover_window
    create_info_window
    create_itemlist_header_window
    create_itemlist_window
    create_recipelist_window
    create_number_window
    create_result_window
  end
  
  #--------------------------------------------------------------------------
  # check_required_scripts
  #--------------------------------------------------------------------------
  def check_required_scripts
    return if $imported["BubsInfoPages"]
    msgbox("Tactics Ogre PSP Crafting System requires the script \"Info Pages Window\"\n" +
    "Find it at http://mrbubblewand.wordpress.com/")
    exit
  end

  
  #--------------------------------------------------------------------------
  # create_gold_window
  #--------------------------------------------------------------------------
  def create_gold_window
    @gold_window = Window_TOCraftingGold.new
    @gold_window.viewport = @viewport
    @gold_window.hide.close
    @gold_window.x = 0
    @gold_window.y = Graphics.height - @gold_window.height
  end
  
  #--------------------------------------------------------------------------
  # create_recipelist_window
  #--------------------------------------------------------------------------
  def create_recipelist_window
    wx = 0
    wy = @help_window.height
    wh = Graphics.height - wy
    @recipelist_window = Window_TOCraftingRecipeList.new(wx, wy, wh)
    @recipelist_window.viewport = @viewport
    @recipelist_window.help_window = @help_window
    @recipelist_window.info_window = @info_window
    @recipelist_window.header_window = @itemlist_header_window
    @recipelist_window.cover_window = @cover_window
    @recipelist_window.categories = @categories
    @recipelist_window.set_handler(:ok,     method(:on_recipelist_ok))
    @recipelist_window.set_handler(:cancel, method(:on_recipelist_cancel))
    @recipelist_window.refresh
    @recipelist_window.show.activate.select(0)
  end
  
  #--------------------------------------------------------------------------
  # on_recipelist_ok
  #--------------------------------------------------------------------------
  def on_recipelist_ok
    @recipelist_window.close
    @itemlist_window.item = @recipelist_window.item
    @gold_window.show.open if gold_window?
    @cover_window.hide
    @info_window.show
    @info_window.set_page_keys
    activate_itemlist_window
  end
  
  #--------------------------------------------------------------------------
  # on_recipelist_cancel
  #--------------------------------------------------------------------------
  def on_recipelist_cancel
    refresh
    return_scene
  end
  
  #--------------------------------------------------------------------------
  # activate_recipelist_window
  #--------------------------------------------------------------------------
  def activate_recipelist_window
    refresh
    @recipelist_window.show.open.activate
  end
  
  #--------------------------------------------------------------------------
  # create_itemlist_window
  #--------------------------------------------------------------------------
  def create_itemlist_window
    wx = 0
    wy = @help_window.height + @itemlist_header_window.height
    wh = Graphics.height - wy
    wh = wh - @gold_window.height if gold_window?
    @itemlist_window = Window_TOCraftingItemList.new(wx, wy, wh)
    @itemlist_window.viewport = @viewport
    @itemlist_window.help_window = @help_window
    @itemlist_window.info_window = @info_window
    @itemlist_window.gold_window = @gold_window
    @itemlist_window.hide
    @itemlist_window.close
    @itemlist_window.set_handler(:ok,     method(:on_itemlist_ok))
    @itemlist_window.set_handler(:cancel, method(:on_itemlist_cancel))
    @itemlist_window.refresh
  end
  
  #--------------------------------------------------------------------------
  # on_itemlist_ok
  #--------------------------------------------------------------------------
  def on_itemlist_ok
    @item = @itemlist_window.item
    @itemlist_window.close.hide
    @number_window.set(@item, max_craft, crafting_fee)
    @info_window.page_change = false
    @info_window.set_page_keys
    @number_window.show.open.activate
  end
  
  #--------------------------------------------------------------------------
  # on_itemlist_cancel
  #--------------------------------------------------------------------------
  def on_itemlist_cancel
    @itemlist_window.close
    @itemlist_header_window.close
    @gold_window.close.hide if gold_window?
    @info_window.hide
    @cover_window.show
    activate_recipelist_window
  end
  
  #--------------------------------------------------------------------------
  # activate_itemlist_window
  #--------------------------------------------------------------------------
  def activate_itemlist_window
    refresh
    @itemlist_header_window.show.open
    @itemlist_window.show.open.activate.select(0)
  end
  
  #--------------------------------------------------------------------------
  # create_number_window
  #--------------------------------------------------------------------------
  def create_number_window
    wx = 0
    wy = @itemlist_header_window.y + @itemlist_header_window.height
    wh = Graphics.height - wy
    wh = wh - @gold_window.height if gold_window?
    @number_window = Window_TOCraftingNumber.new(wx, wy, wh)
    @number_window.viewport = @viewport
    @number_window.info_window = @info_window
    @number_window.gold_window = @gold_window
    @number_window.hide.close
    @number_window.set_handler(:ok,     method(:on_number_ok))
    @number_window.set_handler(:cancel, method(:on_number_cancel))
  end
  
  #--------------------------------------------------------------------------
  # on_number_ok
  #--------------------------------------------------------------------------
  def on_number_ok
    @number_window.close.hide
    @number_window.number
    do_crafting(@item, @number_window.number)
    @result_window.set(@item, @number_window.number)
    @result_window.show.open.activate
    @itemlist_window.show.open
    @info_window.page_change = true
    
    @gold_window.number = @info_window.number = 1
    refresh
    @result_window.show.open.activate
  end
  
  #--------------------------------------------------------------------------
  # on_number_cancel
  #--------------------------------------------------------------------------
  def on_number_cancel
    @number_window.close.hide
    @gold_window.number = @info_window.number = 1
    @info_window.page_change = true
    @itemlist_window.show.open.activate
  end

  #--------------------------------------------------------------------------
  # create_result_window
  #--------------------------------------------------------------------------
  def create_result_window
    wx = Graphics.width / 4
    wy = 0
    @result_window = Window_TOCraftingResult.new(wx, wy)
    @result_window.y = (Graphics.height / 2) - (@result_window.height / 2)
    @result_window.viewport = @viewport
    @result_window.hide.close
    @result_window.set_handler(:ok,     method(:on_result_ok))
    
    @result_window.refresh
  end
  
  #--------------------------------------------------------------------------
  # on_result_ok
  #--------------------------------------------------------------------------
  def on_result_ok
    @result_window.close.hide
    @itemlist_window.activate
    check_common_event(@item)

  end
  
  #--------------------------------------------------------------------------
  # create_itemlist_header_window
  #--------------------------------------------------------------------------
  def create_itemlist_header_window
    wx = 0
    wy = @help_window.height
    @itemlist_header_window = Window_TOCraftingItemListHeader.new(wx, wy)
    @itemlist_header_window.viewport = @viewport
    @itemlist_header_window.hide
    @itemlist_header_window.close
    @itemlist_header_window.refresh
  end
  
  #--------------------------------------------------------------------------
  # create_cover_window
  #--------------------------------------------------------------------------
  def create_cover_window
    wx = Graphics.width / 2
    wy = @help_window.height
    wh = Graphics.height - @help_window.height
    ww = Graphics.width - wx
    @cover_window = Window_TOCraftingCover.new(wx, wy, ww, wh)
    @cover_window.viewport = @viewport
    @cover_window.refresh
    @cover_window.show
  end
  
  #--------------------------------------------------------------------------
  # create_info_window
  #--------------------------------------------------------------------------
  def create_info_window
    wx = Graphics.width / 2
    wy = @help_window.height
    ww = Graphics.width - wx
    wh = Graphics.height - @help_window.height
    @info_window = Window_TOCraftingInfo.new(wx, wy, ww, wh)
    @info_window.viewport = @viewport
    @info_window.hide
    @info_window.refresh
  end
  
  #--------------------------------------------------------------------------
  # refresh
  #--------------------------------------------------------------------------
  def refresh
    @info_window.refresh
    @help_window.refresh
    @itemlist_window.refresh
    @recipelist_window.refresh
    @result_window.refresh
    @itemlist_header_window.refresh
    @gold_window.refresh
  end
  
  #--------------------------------------------------------------------------
  # do_crafting
  #--------------------------------------------------------------------------
  def do_crafting(item, number)
    return unless item
    play_crafting_se(item)
    lose_ingredients(item, number)
    pay_crafting_fee(item, number)
    gain_crafted_item(item, number)
    skill_level_gain?(item) #Dyluck
  end
  
  #--------------------------------------------------------------------------
  # play_crafting_se
  #--------------------------------------------------------------------------
  def play_crafting_se(item)
    if item.tocrafting_se.empty?
      Sound.play_tocrafting_result
    else
      se = item.tocrafting_se
      se[1] = se[1] * 0.01 * $game_system.get_sfx_volume
      Sound.play_custom_tocrafting_result(se[0], se[1], se[2])
    end
  end
  
  #--------------------------------------------------------------------------
  # skill_level_gain? #Dyluck
  #--------------------------------------------------------------------------

  def skill_level_gain?(item)
    if item.note =~ /<req (.*)>/i
      my_req = $1.to_i
    else
      return
    end
    if item.note =~ /<var (.*)>/i
      x = $1.to_i
      #my_var = $game_variables[x] if $game_variables
    else
      return
    end
    #$game_variables[86] += 1 #test
    if $game_variables[x] == my_req
      $game_variables[x] += 1
    end
    #$game_variables[86] += 9 #test
  end
  
  #--------------------------------------------------------------------------
  # check_common_event
  #--------------------------------------------------------------------------
  def check_common_event(item)
    return unless item.tocrafting_cev > 0
    $game_temp.reserve_common_event(item.tocrafting_cev)
    if $imported["TH_SceneInterpreter"]
      a = $game_temp.common_event_reserved?
      b = $data_common_events[$game_temp.common_event_id].run_scene == :current
      return if !a || (a && B)
    end
    SceneManager.goto(Scene_Map) if $game_temp.common_event_reserved?
  end
  
  #--------------------------------------------------------------------------
  # lose_ingredients
  #--------------------------------------------------------------------------
  def lose_ingredients(item, number)
    item.ingredient_list.each do |ingredient|
      $game_party.lose_item(ingredient, number / @item.tocrafting_amount)
    end
  end
  
  #--------------------------------------------------------------------------
  # pay_crafting_fee
  #--------------------------------------------------------------------------
  def pay_crafting_fee(item, number)
    amt = @item.tocrafting_amount
    $game_party.lose_gold(item.tocrafting_gold_fee * (number / amt))
  end
  
  #--------------------------------------------------------------------------
  # gain_crafted_item
  #--------------------------------------------------------------------------
  def gain_crafted_item(item, number)
    $game_party.gain_item(item, number)
  end
  
  #--------------------------------------------------------------------------
  # crafting_fee
  #--------------------------------------------------------------------------
  def crafting_fee
    @item.tocrafting_gold_fee
  end
  
  #--------------------------------------------------------------------------
  # gold_window?
  #--------------------------------------------------------------------------
  def gold_window?
    Bubs::TOCrafting::USE_GOLD_WINDOW
  end

  #--------------------------------------------------------------------------
  # party_gold
  #--------------------------------------------------------------------------
  def party_gold
    $game_party.gold
  end
  
  #--------------------------------------------------------------------------
  # max_craft
  #--------------------------------------------------------------------------
  def max_craft
    max = $game_party.max_item_number(@item) - $game_party.item_number(@item)
    max = crafting_fee == 0 ? max : [max, party_gold / crafting_fee].min
    for ingredient in @item.ingredient_list.uniq.each
      break if max == 0
      count = @item.ingredient_list.count(ingredient)
      temp_max = 0
      for i in 1..max
        break if (i * count) > $game_party.item_number(ingredient)
        temp_max += 1
      end # for
      max = temp_max if max > temp_max
    end # for
    return max
  end
  
end # class Scene_TOCrafting


if $imported["TH_SceneInterpreter"]
#==============================================================================
# ++ Scene_Base
#==============================================================================
class Scene_Base
  #--------------------------------------------------------------------------
  # for compatibility : interpreter
  #--------------------------------------------------------------------------
  def interpreter
    @interpreter
  end
end

end # if $imported["TH_SceneInterpreter"]


if defined?(XAS_SYSTEM)
#==============================================================================
# ++ Window_ItemList
#==============================================================================
class Window_ItemList < Window_Selectable
  #--------------------------------------------------------------------------
  # compatibility alias : can_equip_item_action?
  #--------------------------------------------------------------------------
  alias can_equip_item_action_bubs_tocrafting can_equip_item_action?
  def can_equip_item_action?
    return false if SceneManager.scene_is?(Scene_TOCrafting)
    return can_equip_item_action_bubs_tocrafting # alias
  end
end # class Window_ItemList

end # if defined?(XAS_SYSTEM)


if $imported["YEA-AceMenuEngine"]
  
if !YEA::MENU::CUSTOM_COMMANDS.include?(:tocrafting)
  YEA::MENU::CUSTOM_COMMANDS.merge!(Bubs::TOCrafting::TOCRAFTING_CUSTOM_COMMAND)
end

#==============================================================================
# ++ Scene_Menu
#==============================================================================
class Scene_Menu < Scene_MenuBase
  #--------------------------------------------------------------------------
  # compatibility method : command_tocrafting
  #--------------------------------------------------------------------------
  def command_tocrafting(*args)
    SceneManager.call(Scene_TOCrafting)
    SceneManager.scene.prepare(args)
  end
end # class Scene_Menu

end # if $imported["YEA-AceMenuEngine"]

 

Reader Functions

Spoiler

# ╔═══════════════════════════════════════════════════════╤══════╤═══════════╗
# ║ Reader Functions for Features/Effects                 │ v1.4 │ (4/14/13) ║
# ╚═══════════════════════════════════════════════════════╧══════╧═══════════╝
# Script by:
#     Mr. Bubble ( http://mrbubblewand.wordpress.com/ )
#--------------------------------------------------------------------------
# This is a scripter's tool. This means programming knowledge and Ruby 
# knowledge are required to understand and utilize this script. This script 
# does nothing by itself.
#
# If you are a regular user using this script for another existing script,
# you don't need to do anything with this script. Just install it in your
# script editor and leave it alone.
#
# All RPG::BaseItem objects have an array of RPG::BaseItem::Feature objects 
# that contain all Feature properties defined by the developer in the 
# database. Unfortunately, the way Feature objects is coded makes it not 
# immediately understandable by humans. It requires checking the methods in 
# Game_BattlerBase and Game_Battler to decipher what the values in a Feature 
# mean. This makes trying to display a specific object's features difficult 
# to accomplish.
#
# This script is essentially a collection of wrapper functions based off the 
# methods defined in Game_BattlerBase and Game_Battler. This was mostly a 
# copy and paste job and most of the return values are similar to the ones 
# from those original classes.
#
# For example, if you have a $data_items object, you can do
#   
#   $data_items[id].hp_recovery
#
# to directly get that item's total HP recovery value. There are many 
# other usable methods.
#
# RPG::UsableItem objects do not have Features, but have a similar inner 
# class called RPG::UsableItem::Effect which have their own reader 
# functions.
#
# This script was made for my own use, but other scripters can use it
# if they want.
#--------------------------------------------------------------------------
#   ++ Changelog ++
#--------------------------------------------------------------------------
# v1.4 : Bugfix: Added the Game_Party constants. Oops. (4/14/2013)
# v1.3 : Bugfix: "add_debuffs" and "remove_debuffs" now return
#      : the correct value instead of an array. (4/06/2013)
# v1.2 : "tp_gain" has changed to "tp_recovery". (9/04/2012)
# v1.1 : Bugfix: Arrays no longer return an array of arrays. (8/23/2012)
# v1.0 : Initial release. (8/20/2012)
#--------------------------------------------------------------------------
#   ++ Installation ++
#--------------------------------------------------------------------------
# Install this script in the Materials section in your project's
# script editor.
#=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
#   ++ Methods ++
#=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
# The following methods are for any RPG::BaseItem object:
#
# param(param_id)
#   param_id is a value between 0~7. Not to be confused with the standard 
#   param methods, this method returns the rate modifier for the given 
#   parameter. Param rates start at 1.0 by default.
#
# xparam(xparam_id)
#   xparam_id is a value between 0~9. Ex-Parameters start at 0.0 by default.
#
# sparam(sparam_id)
#   sparam_id is a value between 0~9. Sp-Parameters start at 1.0 by default.
#
# mhp               # MHP  Maximum Hit Points
# mmp               # MMP  Maximum Magic Points
# atk               # ATK  ATtacK power
# def               # DEF  DEFense power
# mat               # MAT  Magic ATtack power
# mdf               # MDF  Magic DeFense power
# agi               # AGI  AGIlity
# luk               # LUK  LUcK
#   In general, anything that is not an RPG::EquipItem object will return 0.
#
# hit               # HIT  HIT rate
# eva               # EVA  EVAsion rate
# cri               # CRI  CRItical rate
# cev               # CEV  Critical EVasion rate
# mev               # MEV  Magic EVasion rate
# mrf               # MRF  Magic ReFlection rate
# cnt               # CNT  CouNTer attack rate
# hrg               # HRG  Hp ReGeneration rate
# mrg               # MRG  Mp ReGeneration rate
# trg               # TRG  Tp ReGeneration rate
#   Ex-Parameters start at 0.0 by default.
#
# tgr               # TGR  TarGet Rate
# grd               # GRD  GuaRD effect rate
# rec               # REC  RECovery effect rate
# pha               # PHA  PHArmacology
# mcr               # MCR  Mp Cost Rate
# tcr               # TCR  Tp Charge Rate
# pdr               # PDR  Physical Damage Rate
# mdr               # MDR  Magical Damage Rate
# fdr               # FDR  Floor Damage Rate
# exr               # EXR  EXperience Rate
#   Sp-Paramters start at 1.0 by default.
#
# mhp_rate          # MHP  Maximum Hit Points rate
# mmp_rate          # MMP  Maximum Magic Points rate
# atk_rate          # ATK  ATtacK power rate
# def_rate          # DEF  DEFense power rate
# mat_rate          # MAT  Magic ATtack power rate
# mdf_rate          # MDF  Magic DeFense power rate
# agi_rate          # AGI  AGIlity rate
# luk_rate          # LUK  LUcK rate
#   Not to be confused with the standard param methods, these methods 
#   return the rate modifier for the given parameter. Param rates start 
#   at 1.0 by default.
#
# dual_wield?
# auto_battle?
# guard?
# substitute?
# preserve_tp?
# encounter_half?
# encounter_none?
# cancel_surprise?
# raise_preemptive?
# gold_double?
# drop_item_double?
#   Returns true if that specified Feature flag is found. Otherwise, false.
#
# get_feature_flags
#   Returns an array of keys that each represent a Feature flag. If the 
#   key is included in the array, it means the flag is true. Possible keys
#   are:
#       :dual_wield
#       :auto_battle
#       :guard 
#       :substitute
#       :preserve_tp
#       :encounter_half
#       :encounter_none
#       :cancel_surprise
#       :raise_preemptive
#       :gold_double
#       :drop_item_double
#
# element_rate(element_id)
#   Returns the element modifier rate for a given element_id. A value 
#   of 1.0 means no change.
#
# debuff_rate(param_id)
#   Returns the debuff modifier rate for a given param_id. A value of 
#   1.0 means no change.
#
# state_rate(state_id)
#   Returns the state modifier rate for a given state_id. A value of 1.0
#   means no change.
#
# state_resist_set
#   Returns an array of resist state ID numbers.
#
# atk_elements
#   Returns an array of attack element ID numbers.
#
# atk_states
#   Returns an array of attack state ID numbers.
#
# atk_states_rate(state_id)
#   Returns the total attack state rate for a given state_id.
#
# atk_speed
#   Returns the attack speed value.
#
# atk_times_add
#   Returns the number of consecutive attacks granted.
#
# added_skill_types
#   Returns an array of added skill type ID numbers.
#
# sealed_skill_types
#   Returns an array of sealed skill type ID numbers.
#
# added_skills
#   Returns an array of added skill ID numbers.
#
# sealed_skills
#   Returns an array of sealed skill ID numbers.
#
# equip_wtypes
#   Returns an array of granted equip weapon types ID numbers
#
# equip_atypes
#   Returns an array of granted equip armor types ID numbers
#
# fixed_equips
#   Returns an array of fixed equipment index numbers. Each index 
#   corresponds to an existing equip slot. 
#   (0:Weapon, 1:Shield, 2:Helmet, 3:Armor, 4:Accessory)
#
# sealed_equips
#   Returns an array of sealed equipment index numbers. Each index 
#   corresponds to an existing equip slot. 
#   (0:Weapon, 1:Shield, 2:Helmet, 3:Armor, 4:Accessory)
#
# action_plus_set
#   Returns an array of Action Times+ chances.
#
#--------------------------------------------------------------------------
# The following methods are for any RPG::UsableItem object:
#
# hp_recovery
#   Returns a flat HP recovery value.
#
# hp_recovery_rate
#   Returns the rate of HP recovery.
#
# mp_recovery
#   Returns a flat MP recovery value.
#
# mp_recovery_rate
#   Returns the rate of MP recovery.
#
# tp_recovery
#   Returns a flat TP recovery value.
#
# add_states
#   Returns an array of state IDs that are added to the target.
#
# remove_states
#   Returns an array of state IDs that are removed from the target.
#
# add_states_with_rates
#   Returns a multi-dimensional array where [index][0] is a state_id 
#   number and [index][1] is the success rate.
#   [[state_id, rate],[state_id, rate],[state_id, rate], ...]
#   state_id 0 represents 'Normal Attack'.
#
# remove_states_with_rates
#   Returns a multi-dimensional array where [index][0] is a state_id 
#   number and [index][1] is the remove rate.
#   [[state_id, rate],[state_id, rate],[state_id, rate], ...]
#
# add_buffs
#   Returns an array buffs represented by param_id numbers.
#
# add_debuffs
#   Returns an array debuffs represented by param_id numbers.
#
# add_buffs_with_turns
#   Returns a multi-dimensional array where [index][0] is a param_id 
#   number and [index][1] is the buff turn duration.
#   [[param_id, turn],[param_id, turn],[param_id, turn], ...]
#
# add_debuffs_with_turns
#   Returns a multi-dimensional array where [index][0] is a param_id 
#   number and [index][1] is the debuff turn duration.
#   [[param_id, turn],[param_id, turn],[param_id, turn], ...]
#
# remove_buffs
#   Returns an array of removed buffs represented by param_id numbers.
#
# remove_debuffs
#   Returns an array of removed debuffs represented by param_id numbers.
#
# escape?
#   Returns true or false if the skill/item provides escape from battle.
#
# grow(param_id)
#   Returns the total amount of param growth for the given param_id.
#
# learn_skills
#   Returns an array of skill IDs that the skill/item teaches.
#
# common_event
#   Returns a common event ID number. Otherwise, it returns nil.
#
#--------------------------------------------------------------------------
#   ++ Compatibility ++
#--------------------------------------------------------------------------
# There are no default method overwrites.
#
# Requests for compatibility with other scripts are welcome.
#--------------------------------------------------------------------------
#   ++ Terms and Conditions ++
#--------------------------------------------------------------------------
# Please do not repost this script elsewhere without permission. 
# Free for non-commercial use. For commercial use, contact me first.
#
# Newest versions of this script can be found at 
#                                           http://mrbubblewand.wordpress.com/
#==============================================================================

$imported ||= {}
$imported["BubsFeaturesReader"] = true

#==========================================================================
# ++ This script contains no customization module ++
#==========================================================================


#==============================================================================
# ++ RPG::EquipItem
#==============================================================================
class RPG::BaseItem
  #--------------------------------------------------------------------------
  # * Constants (Features)
  #--------------------------------------------------------------------------
  FEATURE_ELEMENT_RATE  = 11              # Element Rate
  FEATURE_DEBUFF_RATE   = 12              # Debuff Rate
  FEATURE_STATE_RATE    = 13              # State Rate
  FEATURE_STATE_RESIST  = 14              # State Resist
  FEATURE_PARAM         = 21              # Parameter
  FEATURE_XPARAM        = 22              # Ex-Parameter
  FEATURE_SPARAM        = 23              # Sp-Parameter
  FEATURE_ATK_ELEMENT   = 31              # Atk Element
  FEATURE_ATK_STATE     = 32              # Atk State
  FEATURE_ATK_SPEED     = 33              # Atk Speed
  FEATURE_ATK_TIMES     = 34              # Atk Times+
  FEATURE_STYPE_ADD     = 41              # Add Skill Type
  FEATURE_STYPE_SEAL    = 42              # Disable Skill Type
  FEATURE_SKILL_ADD     = 43              # Add Skill
  FEATURE_SKILL_SEAL    = 44              # Disable Skill
  FEATURE_EQUIP_WTYPE   = 51              # Equip Weapon
  FEATURE_EQUIP_ATYPE   = 52              # Equip Armor
  FEATURE_EQUIP_FIX     = 53              # Lock Equip
  FEATURE_EQUIP_SEAL    = 54              # Seal Equip
  FEATURE_SLOT_TYPE     = 55              # Slot Type
  FEATURE_ACTION_PLUS   = 61              # Action Times+
  FEATURE_SPECIAL_FLAG  = 62              # Special Flag
  FEATURE_COLLAPSE_TYPE = 63              # Collapse Effect
  FEATURE_PARTY_ABILITY = 64              # Party Ability
  #--------------------------------------------------------------------------
  # * Constants (Feature Flags)
  #--------------------------------------------------------------------------
  FLAG_ID_AUTO_BATTLE   = 0               # auto battle
  FLAG_ID_GUARD         = 1               # guard
  FLAG_ID_SUBSTITUTE    = 2               # substitute
  FLAG_ID_PRESERVE_TP   = 3               # preserve TP
  #--------------------------------------------------------------------------
  # * Constants (Game_Party)
  #--------------------------------------------------------------------------
  ABILITY_ENCOUNTER_HALF    = 0           # halve encounters
  ABILITY_ENCOUNTER_NONE    = 1           # disable encounters
  ABILITY_CANCEL_SURPRISE   = 2           # disable surprise
  ABILITY_RAISE_PREEMPTIVE  = 3           # increase preemptive strike rate
  ABILITY_GOLD_DOUBLE       = 4           # double money earned
  ABILITY_DROP_ITEM_DOUBLE  = 5           # double item acquisition rate
  #--------------------------------------------------------------------------
  # * Access Method by Parameter Abbreviations
  #--------------------------------------------------------------------------
  def mhp;  param(0);   end               # MHP  Maximum Hit Points
  def mmp;  param(1);   end               # MMP  Maximum Magic Points
  def atk;  param(2);   end               # ATK  ATtacK power
  def def;  param(3);   end               # DEF  DEFense power
  def mat;  param(4);   end               # MAT  Magic ATtack power
  def mdf;  param(5);   end               # MDF  Magic DeFense power
  def agi;  param(6);   end               # AGI  AGIlity
  def luk;  param(7);   end               # LUK  LUcK
  def hit;  xparam(0);  end               # HIT  HIT rate
  def eva;  xparam(1);  end               # EVA  EVAsion rate
  def cri;  xparam(2);  end               # CRI  CRItical rate
  def cev;  xparam(3);  end               # CEV  Critical EVasion rate
  def mev;  xparam(4);  end               # MEV  Magic EVasion rate
  def mrf;  xparam(5);  end               # MRF  Magic ReFlection rate
  def cnt;  xparam(6);  end               # CNT  CouNTer attack rate
  def hrg;  xparam(7);  end               # HRG  Hp ReGeneration rate
  def mrg;  xparam(8);  end               # MRG  Mp ReGeneration rate
  def trg;  xparam(9);  end               # TRG  Tp ReGeneration rate
  def tgr;  sparam(0);  end               # TGR  TarGet Rate
  def grd;  sparam(1);  end               # GRD  GuaRD effect rate
  def rec;  sparam(2);  end               # REC  RECovery effect rate
  def pha;  sparam(3);  end               # PHA  PHArmacology
  def mcr;  sparam(4);  end               # MCR  Mp Cost Rate
  def tcr;  sparam(5);  end               # TCR  Tp Charge Rate
  def pdr;  sparam(6);  end               # PDR  Physical Damage Rate
  def mdr;  sparam(7);  end               # MDR  Magical Damage Rate
  def fdr;  sparam(8);  end               # FDR  Floor Damage Rate
  def exr;  sparam(9);  end               # EXR  EXperience Rate
  #--------------------------------------------------------------------------
  # * Access Method by Parameter Abbreviations (Rates)
  #--------------------------------------------------------------------------
  def mhp_rate;  param_rate(0);   end     # MHP  Maximum Hit Points rate
  def mmp_rate;  param_rate(1);   end     # MMP  Maximum Magic Points rate
  def atk_rate;  param_rate(2);   end     # ATK  ATtacK power rate
  def def_rate;  param_rate(3);   end     # DEF  DEFense power rate
  def mat_rate;  param_rate(4);   end     # MAT  Magic ATtack power rate
  def mdf_rate;  param_rate(5);   end     # MDF  Magic DeFense power rate
  def agi_rate;  param_rate(6);   end     # AGI  AGIlity rate
  def luk_rate;  param_rate(7);   end     # LUK  LUcK rate
  #--------------------------------------------------------------------------
  # * Get Feature Object Array (Feature Codes Limited)
  #--------------------------------------------------------------------------
  # features_with_id, features_sum_all, action_plus_set, special_flag, 
  # party_ability
  def get_features(code)
    features.select {|ft| ft.code == code }
  end
  #--------------------------------------------------------------------------
  # * Get Feature Object Array (Feature Codes and Data IDs Limited)
  #--------------------------------------------------------------------------
  # features_pi, features_sum, features_set
  def features_with_id(code, id)
    get_features(code).select {|ft| ft.code == code && ft.data_id == id }
  end
  #--------------------------------------------------------------------------
  # * Calculate Complement of Feature Values
  #--------------------------------------------------------------------------
  # sparam, element_rate, debuff_rate, state_rate
  def features_pi(code, id)
    features_with_id(code, id).inject(1.0) {|r, ft| r *= ft.value }
  end
  #--------------------------------------------------------------------------
  # * Calculate Sum of Feature Values (Specify Data ID)
  #--------------------------------------------------------------------------
  # xparam, atk_states_rate
  def features_sum(code, id)
    features_with_id(code, id).inject(0.0) {|r, ft| r += ft.value }
  end
  #--------------------------------------------------------------------------
  # * Calculate Sum of Feature Values (Data ID Unspecified)
  #--------------------------------------------------------------------------
  # atk_speed, atk_times_add
  def features_sum_all(code)
    get_features(code).inject(0.0) {|r, ft| r += ft.value }
  end
  #--------------------------------------------------------------------------
  # * Calculate Set Sum of Features
  #--------------------------------------------------------------------------
  # state_resists, atk_elements, atk_states, added_skill_types, 
  # skill_type_sealed?, sealed_skill_types, added_skills, skill_sealed?, 
  # sealed_skills, equip_wtype_ok?, equip_wtypes, equip_atype_ok?, 
  # equip_atypes, equip_type_fixed?, fixed_equips, equip_type_sealed?, 
  # sealed_equips, slot_type, collapse_type
  def features_set(code)
    get_features(code).inject([]) {|r, ft| r |= [ft.data_id]}
  end
  #--------------------------------------------------------------------------
  # * Get Rate of Parameter Change
  #--------------------------------------------------------------------------
  def param_rate(param_id)
    features_pi(FEATURE_PARAM, param_id)
  end
  #--------------------------------------------------------------------------
  # * Get Ex-Parameter
  #--------------------------------------------------------------------------
  def xparam(xparam_id)
    features_sum(FEATURE_XPARAM, xparam_id)
  end
  #--------------------------------------------------------------------------
  # * Get Sp-Parameter
  #--------------------------------------------------------------------------
  def sparam(sparam_id)
    features_pi(FEATURE_SPARAM, sparam_id)
  end
  #--------------------------------------------------------------------------
  # * Get Element Rate
  #--------------------------------------------------------------------------
  def element_rate(element_id)
    features_pi(FEATURE_ELEMENT_RATE, element_id)
  end
  #--------------------------------------------------------------------------
  # * Get Debuff Rate
  #--------------------------------------------------------------------------
  def debuff_rate(param_id)
    features_pi(FEATURE_DEBUFF_RATE, param_id)
  end
  #--------------------------------------------------------------------------
  # * Get State Rate
  #--------------------------------------------------------------------------
  def state_rate(state_id)
    features_pi(FEATURE_STATE_RATE, state_id)
  end
  #--------------------------------------------------------------------------
  # * Get Array of States to Resist
  #--------------------------------------------------------------------------
  def state_resist_set
    features_set(FEATURE_STATE_RESIST)
  end
  #--------------------------------------------------------------------------
  # * Determine if State Is Resisted
  #--------------------------------------------------------------------------
  def state_resist?(state_id)
    state_resist_set.include?(state_id)
  end
  #--------------------------------------------------------------------------
  # * Get Attack Element
  #--------------------------------------------------------------------------
  def atk_elements
    features_set(FEATURE_ATK_ELEMENT)
  end
  #--------------------------------------------------------------------------
  # * Get Attack State
  #--------------------------------------------------------------------------
  def atk_states
    features_set(FEATURE_ATK_STATE)
  end
  #--------------------------------------------------------------------------
  # * Get Attack State Invocation Rate
  #--------------------------------------------------------------------------
  def atk_states_rate(state_id)
    features_sum(FEATURE_ATK_STATE, state_id)
  end
  #--------------------------------------------------------------------------
  # * Get Attack Speed
  #--------------------------------------------------------------------------
  def atk_speed
    features_sum_all(FEATURE_ATK_SPEED)
  end
  #--------------------------------------------------------------------------
  # * Get Additional Attack Times
  #--------------------------------------------------------------------------
  def atk_times_add
    [features_sum_all(FEATURE_ATK_TIMES), 0].max
  end
  #--------------------------------------------------------------------------
  # * Get Added Skill Types
  #--------------------------------------------------------------------------
  def added_skill_types
    features_set(FEATURE_STYPE_ADD)
  end
  #--------------------------------------------------------------------------
  # * Determine if Skill Type Is Disabled
  #--------------------------------------------------------------------------
  def skill_type_sealed?(stype_id)
    features_set(FEATURE_STYPE_SEAL).include?(stype_id)
  end
  #--------------------------------------------------------------------------
  # * Get Disabled Skill Type ID Array
  #--------------------------------------------------------------------------
  def sealed_skill_types
    features_set(FEATURE_STYPE_SEAL)
  end
  #--------------------------------------------------------------------------
  # * Get Added Skills ID Array
  #--------------------------------------------------------------------------
  def added_skills
    features_set(FEATURE_SKILL_ADD)
  end
  #--------------------------------------------------------------------------
  # * Determine if Skill Is Disabled
  #--------------------------------------------------------------------------
  def skill_sealed?(skill_id)
    features_set(FEATURE_SKILL_SEAL).include?(skill_id)
  end
  #--------------------------------------------------------------------------
  # * Get Sealed Skills ID Array
  #--------------------------------------------------------------------------
  def sealed_skills
    features_set(FEATURE_SKILL_SEAL)
  end
  #--------------------------------------------------------------------------
  # * Determine if Weapon Can Be Equipped
  #--------------------------------------------------------------------------
  def equip_wtype_ok?(wtype_id)
    features_set(FEATURE_EQUIP_WTYPE).include?(wtype_id)
  end
  #--------------------------------------------------------------------------
  # * Get Equip Weapon Types ID Array
  #--------------------------------------------------------------------------
  def equip_wtypes
    features_set(FEATURE_EQUIP_WTYPE)
  end
  #--------------------------------------------------------------------------
  # * Determine if Armor Can Be Equipped
  #--------------------------------------------------------------------------
  def equip_atype_ok?(atype_id)
    features_set(FEATURE_EQUIP_ATYPE).include?(atype_id)
  end
  #--------------------------------------------------------------------------
  # * Get Equip Armor Types ID Array
  #--------------------------------------------------------------------------
  def equip_atypes
    features_set(FEATURE_EQUIP_ATYPE)
  end
  #--------------------------------------------------------------------------
  # * Determine if Equipment Is Locked
  #--------------------------------------------------------------------------
  def equip_type_fixed?(etype_id)
    features_set(FEATURE_EQUIP_FIX).include?(etype_id)
  end
  #--------------------------------------------------------------------------
  # * Get Fixed Equips Index Array
  #--------------------------------------------------------------------------
  def fixed_equips
    features_set(FEATURE_EQUIP_FIX)
  end
  #--------------------------------------------------------------------------
  # * Determine if Equipment Is Sealed
  #--------------------------------------------------------------------------
  def equip_type_sealed?(etype_id)
    features_set(FEATURE_EQUIP_SEAL).include?(etype_id)
  end
  #--------------------------------------------------------------------------
  # * Get Sealed Equips Index Array
  #--------------------------------------------------------------------------
  def sealed_equips
    features_set(FEATURE_EQUIP_SEAL)
  end
  #--------------------------------------------------------------------------
  # * Get Slot Type
  #--------------------------------------------------------------------------
  def slot_type
    features_set(FEATURE_SLOT_TYPE).max || 0
  end
  #--------------------------------------------------------------------------
  # * Determine if Dual Wield
  #--------------------------------------------------------------------------
  def dual_wield?
    slot_type == 1
  end
  #--------------------------------------------------------------------------
  # * Get Array of Additional Action Time Probabilities
  #--------------------------------------------------------------------------
  def action_plus_set
    get_features(FEATURE_ACTION_PLUS).collect {|ft| ft.value }
  end
  alias action_times_plus action_plus_set
  #--------------------------------------------------------------------------
  # * Determine if Special Flag
  #--------------------------------------------------------------------------
  def special_flag(flag_id)
    get_features(FEATURE_SPECIAL_FLAG).any? {|ft| ft.data_id == flag_id }
  end
  #--------------------------------------------------------------------------
  # * Get Collapse Effect
  #--------------------------------------------------------------------------
  def collapse_type
    features_set(FEATURE_COLLAPSE_TYPE).max || 0
  end
  #--------------------------------------------------------------------------
  # * Determine if Auto Battle
  #--------------------------------------------------------------------------
  def auto_battle?
    special_flag(FLAG_ID_AUTO_BATTLE)
  end
  #--------------------------------------------------------------------------
  # * Determine if Guard
  #--------------------------------------------------------------------------
  def guard?
    special_flag(FLAG_ID_GUARD)
  end
  #--------------------------------------------------------------------------
  # * Determine if Substitute
  #--------------------------------------------------------------------------
  def substitute?
    special_flag(FLAG_ID_SUBSTITUTE)
  end
  #--------------------------------------------------------------------------
  # * Determine if Preserve TP
  #--------------------------------------------------------------------------
  def preserve_tp?
    special_flag(FLAG_ID_PRESERVE_TP)
  end
  #--------------------------------------------------------------------------
  # * Determine Party Ability
  #--------------------------------------------------------------------------
  def party_ability(ability_id)
    get_features(FEATURE_PARTY_ABILITY).any? {|ft| ft.data_id == ability_id}
  end
  #--------------------------------------------------------------------------
  # * Halve Encounters?
  #--------------------------------------------------------------------------
  def encounter_half?
    party_ability(ABILITY_ENCOUNTER_HALF)
  end
  #--------------------------------------------------------------------------
  # * Disable Encounters?
  #--------------------------------------------------------------------------
  def encounter_none?
    party_ability(ABILITY_ENCOUNTER_NONE)
  end
  #--------------------------------------------------------------------------
  # * Disable Surprise?
  #--------------------------------------------------------------------------
  def cancel_surprise?
    party_ability(ABILITY_CANCEL_SURPRISE)
  end
  #--------------------------------------------------------------------------
  # * Increase Preemptive Strike Rate?
  #--------------------------------------------------------------------------
  def raise_preemptive?
    party_ability(ABILITY_RAISE_PREEMPTIVE)
  end
  #--------------------------------------------------------------------------
  # * Double Money Earned?
  #--------------------------------------------------------------------------
  def gold_double?
    party_ability(ABILITY_GOLD_DOUBLE)
  end
  #--------------------------------------------------------------------------
  # * Double Item Acquisition Rate?
  #--------------------------------------------------------------------------
  def drop_item_double?
    party_ability(ABILITY_DROP_ITEM_DOUBLE)
  end
  #--------------------------------------------------------------------------
  # * Get Feature Flag Keys
  #--------------------------------------------------------------------------
  def get_feature_flags
    array = []
    array.push(:dual_wield)       if dual_wield?
    array.push(:auto_battle)      if auto_battle?
    array.push(:guard)            if guard?
    array.push(:substitute)       if substitute?
    array.push(:preserve_tp)      if preserve_tp?
    array.push(:encounter_half)   if encounter_half?
    array.push(:encounter_none)   if encounter_none?
    array.push(:cancel_surprise)  if cancel_surprise?
    array.push(:raise_preemptive) if raise_preemptive?
    array.push(:gold_double)      if gold_double?
    array.push(:drop_item_double) if drop_item_double?
    return array
  end
  
  #--------------------------------------------------------------------------
  # * Get Feature By Key
  #--------------------------------------------------------------------------
  def feature_by_key(key)
    case key
    when :mhp
      mhp
    when :mmp
      mmp
    when :atk
      atk
    when :def
      self.def
    when :mat 
      mat
    when :mdf
      mdf
    when :agi
      agi
    when :luk
      luk

    when :mhp
      mhp
    when :mmp
      mmp
    when :atk
      atk
    when :def
      self.def
    when :mat 
      mat
    when :mdf 
      mdf
    when :agi 
      agi
    when :luk 
      luk

    when :mhp_rate 
      mhp_rate
    when :mmp_rate 
      mmp_rate
    when :atk_rate 
      atk_rate
    when :def_rate 
      def_rate
    when :mat_rate 
      mat_rate
    when :mdf_rate 
      mdf_rate
    when :agi_rate 
      agi_rate
    when :luk_rate 
      luk_rate

    when :hit 
      hit
    when :eva 
      eva
    when :cri 
      cri
    when :cev 
      cev
    when :mev 
      mev
    when :mrf 
      mrf
    when :cnt
      cnt
    when :hrg
      hrg
    when :mrg 
      mrg
    when :trg 
      trg

    when :tgr 
      tgr
    when :grd 
      grd
    when :rec 
      rec
    when :pha
      pha
    when :mcr 
      mcr
    when :tcr 
      tcr
    when :pdr 
      pdr
    when :mdr 
      mdr
    when :fdr 
      fdr
    when :exr 
      exr

    when :element_rate 
      element_rate
    when :debuff_rate 
      debuff_rate
    when :state_rate 
      state_rate
    when :state_resist_set
      state_resist_set

    when :atk_elements
      atk_elements
    when :atk_states 
      atk_states
    when :atk_speed 
      atk_speed
    when :atk_times_add 
      atk_times_add

    when :added_skill_types 
      added_skill_types
    when :added_skills 
      added_skills
    when :sealed_skill_types 
      sealed_skill_types
    when :sealed_skills 
      sealed_skills

    when :equip_wtypes 
      equip_wtypes
    when :equip_atypes 
      equip_atypes
    when :fixed_equips 
      fixed_equips
    when :sealed_equips 
      sealed_equips
    when :dual_wield 
      dual_wield?

    when :action_times_plus 
      action_times_plus
      
    when :auto_battle 
      auto_battle?
    when :guard 
      guard?
    when :substitute 
      substitute?
    when :preserve_tp 
      preserve_tp?

    when :collapse_effect 
      collapse_effect

    when :encounter_half 
      encounter_half?
    when :encounter_none 
      encounter_none?
    when :cancel_surprise 
      cancel_surprise?
    when :raise_preemptive 
      raise_preemptive?
    when :gold_double 
      gold_double?
    when :drop_item_double 
      drop_item_double?
    end
  end

end # class RPG::BaseItem


#==============================================================================
# ++ RPG::UsableItem
#==============================================================================
class RPG::UsableItem
  #--------------------------------------------------------------------------
  # * Constants (Effects)
  #--------------------------------------------------------------------------
  EFFECT_RECOVER_HP     = 11              # HP Recovery
  EFFECT_RECOVER_MP     = 12              # MP Recovery
  EFFECT_GAIN_TP        = 13              # TP Gain
  EFFECT_ADD_STATE      = 21              # Add State
  EFFECT_REMOVE_STATE   = 22              # Remove State
  EFFECT_ADD_BUFF       = 31              # Add Buff
  EFFECT_ADD_DEBUFF     = 32              # Add Debuff
  EFFECT_REMOVE_BUFF    = 33              # Remove Buff
  EFFECT_REMOVE_DEBUFF  = 34              # Remove Debuff
  EFFECT_SPECIAL        = 41              # Special Effect
  EFFECT_GROW           = 42              # Raise Parameter
  EFFECT_LEARN_SKILL    = 43              # Learn Skill
  EFFECT_COMMON_EVENT   = 44              # Common Events
  #--------------------------------------------------------------------------
  # * Constants (Special Effects)
  #--------------------------------------------------------------------------
  SPECIAL_EFFECT_ESCAPE = 0               # Escape
  #--------------------------------------------------------------------------
  # * Get Effect Object Array (Effect Codes Limited)
  #--------------------------------------------------------------------------
  def get_effects(code)
    effects.select {|ef| ef.code == code }
  end
  #--------------------------------------------------------------------------
  # * Get Effect Object Array (Effect Codes and Data IDs Limited)
  #--------------------------------------------------------------------------
  def effects_with_id(code, id)
    get_effects(code).select {|ef| ef.code == code && ef.data_id == id }
  end
  #--------------------------------------------------------------------------
  # * Calculate Complement of Effect Value1
  #--------------------------------------------------------------------------
  def effects_pi_value1(code, id)
    effects_with_id(code, id).inject(1.0) {|r, ef| r *= ef.value1 }
  end
  #--------------------------------------------------------------------------
  # * Calculate Sum of Effect Value 1 (Specify Data ID)
  #--------------------------------------------------------------------------
  def effects_sum_value1(code, id)
    effects_with_id(code, id).inject(0.0) {|r, ef| r += ef.value1 }
  end
  #--------------------------------------------------------------------------
  # * Calculate Sum of Effect Value 2 (Specify Data ID)
  #--------------------------------------------------------------------------
  def effects_sum_value2(code, id)
    effects_with_id(code, id).inject(0.0) {|r, ef| r += ef.value2 }
  end
  #--------------------------------------------------------------------------
  # * Calculate Sum of Effect Value 1 (Data ID Unspecified)
  #--------------------------------------------------------------------------
  def effects_sum_all_value1(code)
    get_effects(code).inject(0.0) {|r, ef| r += ef.value1 }
  end
  #--------------------------------------------------------------------------
  # * Calculate Sum of Effect Value 2 (Data ID Unspecified)
  #--------------------------------------------------------------------------
  def effects_sum_all_value2(code)
    get_effects(code).inject(0.0) {|r, ef| r += ef.value2 }
  end
  #--------------------------------------------------------------------------
  # * Calculate Set Sum of Effects
  #--------------------------------------------------------------------------
  def effects_set(code)
    get_effects(code).inject([]) {|r, ef| r.push(ef.data_id) }
  end
  #--------------------------------------------------------------------------
  # * Get Effect ID with Value1
  #--------------------------------------------------------------------------
  def effects_set_with_value1(code)
    get_effects(code).inject([]) {|r, ef| r.push([ef.data_id, ef.value1]) }
  end
  #--------------------------------------------------------------------------
  # * Get HP Recovery Value
  #--------------------------------------------------------------------------
  def hp_recovery
    effects_sum_all_value2(EFFECT_RECOVER_HP)
  end
  #--------------------------------------------------------------------------
  # * Get HP Recovery Rate
  #--------------------------------------------------------------------------
  def hp_recovery_rate
    effects_sum_all_value1(EFFECT_RECOVER_HP)
  end
  #--------------------------------------------------------------------------
  # * Get MP Recovery Value
  #--------------------------------------------------------------------------
  def mp_recovery
    effects_sum_all_value2(EFFECT_RECOVER_MP)
  end
  #--------------------------------------------------------------------------
  # * Get MP Recovery Rate
  #--------------------------------------------------------------------------
  def mp_recovery_rate
    effects_sum_all_value1(EFFECT_RECOVER_MP)
  end
  #--------------------------------------------------------------------------
  # * Get TP Recovery Value
  #--------------------------------------------------------------------------
  def tp_recovery
    effects_sum_all_value1(EFFECT_GAIN_TP)
  end
  #--------------------------------------------------------------------------
  # * Get Add States IDs Array
  #--------------------------------------------------------------------------
  # state_id 0 represents 'Normal Attack'.
  def add_states
    effects_set(EFFECT_ADD_STATE)
  end
  #--------------------------------------------------------------------------
  # * Get Remove States IDs Array
  #--------------------------------------------------------------------------
  def remove_states
    effects_set(EFFECT_REMOVE_STATE)
  end
  #--------------------------------------------------------------------------
  # * Get Add States IDs with Rates Array
  #--------------------------------------------------------------------------
  # returns a multi-dimensional array where [index][0] is a
  # state_id number and [index][1] is the success rate.
  # [[state_id, rate],[state_id, rate],[state_id, rate], ...]
  #
  # state_id 0 represents 'Normal Attack'.
  def add_states_with_rates
    effects_set_with_value1(EFFECT_ADD_STATE)
  end
  #--------------------------------------------------------------------------
  # * Get Remove States IDs with Rates Array
  #--------------------------------------------------------------------------
  # returns a multi-dimensional array where [index][0] is a
  # state_id number and [index][1] is the success rate.
  # [[state_id, rate],[state_id, rate],[state_id, rate], ...]
  def remove_states_with_rates
    effects_set_with_value1(EFFECT_REMOVE_STATE)
  end
  #--------------------------------------------------------------------------
  # * Get Add Buffs Param Index Array
  #--------------------------------------------------------------------------
  def add_buffs
    effects_set(EFFECT_ADD_BUFF)
  end
  #--------------------------------------------------------------------------
  # * Get Add Debuffs Param Index Array
  #--------------------------------------------------------------------------
  def add_debuffs
    effects_set(EFFECT_ADD_DEBUFF)
  end
  #--------------------------------------------------------------------------
  # * Get Add Buffs Param Index with Turns Array
  #--------------------------------------------------------------------------
  # returns a multi-dimensional array where [index][0] is a
  # param_id value and [index][1] is the turn duration.
  # [[param_index, turn],[param_index, turn],[param_index, turn], ...]
  def add_buffs_with_turns
    effects_set_with_value1(EFFECT_ADD_BUFF)
  end
  #--------------------------------------------------------------------------
  # * Get Add Debuffs Param Index with Turns Array
  #--------------------------------------------------------------------------
  # returns a multi-dimensional array where [index][0] is a
  # param_id value and [index][1] is the turn duration.
  # [[param_index, turn],[param_index, turn],[param_index, turn], ...]
  def add_debuffs_with_turns
    effects_set_with_value1(EFFECT_ADD_DEBUFF)
  end
  #--------------------------------------------------------------------------
  # * Get Remove Buffs Param Index
  #--------------------------------------------------------------------------
  def remove_buffs
    effects_set(EFFECT_REMOVE_BUFF)
  end
  #--------------------------------------------------------------------------
  # * Get Remove Debuffs Param Index
  #--------------------------------------------------------------------------
  def remove_debuffs
    effects_set(EFFECT_REMOVE_DEBUFF)
  end
  #--------------------------------------------------------------------------
  # * Determine Escape Item/Skill
  #--------------------------------------------------------------------------
  def escape?
    !effects_set(EFFECT_SPECIAL).empty?
  end
  #--------------------------------------------------------------------------
  # * Get Param Growth with Values
  #--------------------------------------------------------------------------
  def grow(param_id)
    effects_sum_value1(EFFECT_GROW, param_id)
  end
  #--------------------------------------------------------------------------
  # * Get Learn Skills IDs Array
  #--------------------------------------------------------------------------
  def learn_skills
    effects_set(EFFECT_LEARN_SKILL)
  end
  #--------------------------------------------------------------------------
  # * Get Common Event ID
  #--------------------------------------------------------------------------
  def common_event
    effects_set(EFFECT_COMMON_EVENT).last
  end
  #--------------------------------------------------------------------------
  # * Get Effect By Key
  #--------------------------------------------------------------------------
  def effect_by_key(key)
    case key
    when :hp_recovery
      hp_recovery
    when :hp_recovery_rate
      hp_recovery_rate
    when :mp_recovery
      mp_recovery
    when :mp_recovery_rate
      mp_recovery_rate
    when :tp_recovery
      tp_recovery
    when :add_states
      add_states
    when :remove_states
      remove_states
    when :add_states_with_rates
      add_states_with_rates
    when :remove_states_with_rates
      remove_states_with_rates
    when :add_buffs
      add_buffs
    when :add_debuffs
      add_debuffs
    when :add_buffs_with_turns
      add_buffs_with_turns
    when :add_debuffs_with_turns
      add_debuffs_with_turns
    when :remove_buffs
      remove_buffs
    when :remove_debuffs
      remove_debuffs
    when :escape
      escape?
    when :learn_skills
      learn_skills
    when :comment_event
      common_event
    end
  end

end # class RPG::UsableItem


#==============================================================================
# ++ RPG::EquipItem
#==============================================================================
class RPG::EquipItem
  #--------------------------------------------------------------------------
  # * Access Method by Parameter Abbreviations
  #--------------------------------------------------------------------------
  def mhp;  param(0);   end          # MHP  Maximum Hit Points
  def mmp;  param(1);   end          # MMP  Maximum Magic Points
  def atk;  param(2);   end          # ATK  ATtacK power
  def def;  param(3);   end          # DEF  DEFense power
  def mat;  param(4);   end          # MAT  Magic ATtack power
  def mdf;  param(5);   end          # MDF  Magic DeFense power
  def agi;  param(6);   end          # AGI  AGIlity
  def luk;  param(7);   end          # LUK  LUcK
  #--------------------------------------------------------------------------
  # * Get Parameter
  #--------------------------------------------------------------------------
  def param(param_id)
    params[param_id]
  end
  
end # class RPG::EquipItem

 

Info Pages

Spoiler

# ╔═══════════════════════════════════════════════════════╤═══════╤═══════════╗
# ║ Info Pages Window                                     │ v1.01 │ (5/03/13) ║
# ╚═══════════════════════════════════════════════════════╧═══════╧═══════════╝
# Script by:
#     Mr. Bubble ( http://mrbubblewand.wordpress.com/ )
#--------------------------------------------------------------------------
# This script is meant to be used with other scripts and has no effect
# by itself. However, if you are a regular user, please read the 
# user customization module since you can still change settings
# related to this script.
#
# This script was made as an API for my own purposes, but other scripters
# may utilize it as well. However, I do not expect any other scripters to 
# actually use this. This means documentation on how to implement this 
# script into your own custom scenes is not yet available. If you are 
# interested in how to implement this window into your own scenes, feel 
# free to ask.
#--------------------------------------------------------------------------
#      Changelog
#--------------------------------------------------------------------------
# v1.01 : Added more info pages for equipment. (5/03/2013)
# v1.00 : Initial release. (4/14/2013)
#--------------------------------------------------------------------------
#      Installation and Requirements
#--------------------------------------------------------------------------
# Install this script in the Materials section in your project's
# script editor.
#
# This script also requires "Reader Functions for Features/Effects" 
# installed in your project as well.
#--------------------------------------------------------------------------
#      Compatibility   
#--------------------------------------------------------------------------
# There are no default method overwrites.
#
# This script has built-in compatibility with the following scripts:
#
#     -Yami Engine Symphony - Equipment Learning
#     -Shield Blocking
#
# Requests for compatibility with other scripts are welcome.
#--------------------------------------------------------------------------
#      Terms and Conditions   
#--------------------------------------------------------------------------
# Please do not repost this script elsewhere without permission. 
# Free for non-commercial use. For commercial use, contact me first.
#
# Newest versions of this script can be found at 
#                                         http://mrbubblewand.wordpress.com/
#=============================================================================

$imported ||= {}
$imported["BubsInfoPages"] = 1.01

#==========================================================================
#    START OF USER CUSTOMIZATION MODULE   
#==========================================================================
module Bubs
  #==========================================================================
  # ++ Info Page Settings
  #==========================================================================
  module InfoPages
  #--------------------------------------------------------------------------
  #   Item Info Pages
  #--------------------------------------------------------------------------
  # This setting determines the order of info pages for usable items. 
  # Each kind of info page is represented by a symbol.
  #
  # The following symbols require the script "Reader Functions 
  # for Features/Effects":
  #
  #   :basic_page
  #       Display HP/MP/TP Recovery values and states added or removed.
  #   :use_page
  #       Display infomation related to the item's usability.
  #   :learn_skill_page
  #       Display a list of skills that the item teaches.
  #   :misc_page
  #       Display miscellaneous information for debugging/testing.
  #       Not recommended for completed games.
  ITEM_INFO_PAGES = [:basic_page,         # Page 1
                     #:use_page,           # Page 2
                     #:learn_skill_page,   # Page 3
                     #:misc_page,          # Page 4
                     # Add more symbols here
                     
                    ] # <- Do not delete.
                    
  #--------------------------------------------------------------------------
  #   Equip Info Page List
  #--------------------------------------------------------------------------
  # This setting determines the order of info pages for equippable items. 
  # Each kind of info page is represented by a symbol. Possible symbols
  # include:
  #
  #   :equippable_page
  #       Display a list of actors in the party that can equip the item.
  #
  # The following symbols require the script "Reader Functions 
  # for Features/Effects":
  #
  #   :param_page       
  #       Display basic parameter modification values and rates.
  #   :xparam_page
  #       Display X-parameter modification rates.
  #   :sparam_page
  #       Display Sp-parameter modification rates.
  #   :attack_page
  #       Display attack-related properties.
  #   :element_page
  #       Display element resistance modifiers.
  #   :state_page
  #       Display state resistance modifiers and state immunities.
  #   :added_skills_page
  #       Display a list of skills that the item grants while equipped.
  #   :sealed_skills_page
  #       Display a list of skills that the item disables while equipped.
  #   :equip_types_page
  #       Display the equip types the item allows the actor to equip.
  #   :equip_slots_page
  #       Display information related to equip slots.
  #   :added_skill_types_page
  #       Display a list of skill types the item allows the actor to cast.
  #   :special_flag_page
  #       Display a list special effects the item grants.
  #
  # The following symbols display unique information created by
  # other custom scripts:
  #
  #   :yes_equip_learn_page
  #       Display a list of skills learnable with AP points.
  #       Requires "Yami Engine Symphony - Equipment Learning"
  #   :bubs_blocking_page
  #       Display parameters related to blocking.
  #       Requires "Shield Blocking" by Mr. Bubble.
  EQUIP_INFO_PAGES = [:param_page,            # Page 1
#                      :xparam_page,           # Page 2
#                      :sparam_page,           # Page 3
#                      :attack_page,           # Page 4
#                      :element_page,          # etc...
#                      :state_page,      
#                      :equippable_page,
#                      :added_skills_page,
#                      :sealed_skills_page,
#                      :added_skill_types_page,
#                      :equip_slots_page,
#                      :equip_types_page,
#                      :special_flag_page,
                      # Add more symbols here
                      
                     ] # <- Do not delete.

  #--------------------------------------------------------------------------
  #   Change Page Buttons
  #--------------------------------------------------------------------------
  # This setting determine which gamepad buttons change aspects of the
  # item scene such as changing categories or changing the info window.
  # Default buttons that you can use include: 
  #
  # :LEFT, :RIGHT
  # :A, :B, :C, :X, :Y, :Z, :L, :R
  # :SHIFT, :CTRL, :ALT 
  PAGE_BUTTONS = {
    :next_info_page     => :Y,
    :prev_info_page     => :X,
  } # <- Do not delete.
  #--------------------------------------------------------------------------
  #   Page Button Icons
  #--------------------------------------------------------------------------
  # This setting defines the icons that represent buttons in the
  # info window.
  PAGE_BUTTON_ICONS = {
    :next_info_page     => 0, # Next Info Page Button Icon Index
    :prev_info_page     => 0, # Previous Info Page Button Icon Index
  } # <- Do not delete.
  
  #--------------------------------------------------------------------------
  #   Info Page Footer Text
  #--------------------------------------------------------------------------
  # This setting defines the footer text that is displayed at the bottom
  # of all info pages.
  #
  # Recommended length: 22 characters "                      "
  NORMAL_FOOTER_TEXT                = "←A     More Info    S→"

  #--------------------------------------------------------------------------
  #   Actor Icon Index Numbers
  #--------------------------------------------------------------------------
  # This setting lets you define the icon index number that represents
  # an actor in info windows.
  ACTOR_ICONS = {
  # actor_id => icon_index,
           1 => 16,
           
           
  } # <- Do not delete.
  ACTOR_ICONS.default = 16 # Default icon if an actor icon is not found
  
  #--------------------------------------------------------------------------
  #   Use Full Parameter Names
  #--------------------------------------------------------------------------
  #  true : Use full parameter names in certain info windows.
  # false : Use abbreviated parameter names in info windows.
  USE_FULL_PARAMETER_NAMES = true
  #--------------------------------------------------------------------------
  #   Parameter Full Names
  #--------------------------------------------------------------------------
  PARAM_VOCAB_FULL = ["Health Points",    # HP
                      "Magic Points",     # MP
                      "Attack",           # ATK
                      "Defense",          # DEF
                      "Magic Attack",     # MAT
                      "Magic Defense",    # MDF
                      "Agility",          # AGI
                      "Luck"]             # LUK
  #--------------------------------------------------------------------------
  #   X-Parameter Abbreviations
  #--------------------------------------------------------------------------
  XPARAM_VOCAB = [  "HIT",    # HIT rate
                    "EVA",    # EVAsion rate
                    "CRI",    # CRItical rate
                    "CEV",    # Critical EVasion rate
                    "MEV",    # Magic EVasion rate
                    "MRF",    # Magic ReFlection rate
                    "CNT",    # CouNTer attack rate
                    "HRG",    # Hp ReGeneration rate
                    "MRG",    # Mp ReGeneration rate
                    "TRG"]    # Tp ReGeneration rate
  #--------------------------------------------------------------------------
  #   X-Parameter Full Names
  #--------------------------------------------------------------------------
  XPARAM_VOCAB_FULL = [ "Hit",              # HIT rate
                        "Evasion",          # EVAsion rate
                        "Critical",         # CRItical rate
                        "Critical Evasion", # Critical EVasion rate
                        "Magic Evasion",    # Magic EVasion rate
                        "Magic Reflection", # Magic ReFlection rate
                        "Counter Attack",   # CouNTer attack rate
                        "HP Regeneration",  # Hp ReGeneration rate
                        "MP Regeneration",  # Mp ReGeneration rate
                        "TP Regeneration"]  # Tp ReGeneration rate
  #--------------------------------------------------------------------------
  #   Sp-Parameter Abbreviations
  #--------------------------------------------------------------------------
  SPARAM_VOCAB   = ["TGR",    # TarGet Rate
                    "GRD",    # GuaRD effect rate
                    "REC",    # RECovery effect rate
                    "PHA",    # PHArmacology
                    "MCR",    # Mp Cost Rate
                    "TCR",    # Tp Charge Rate
                    "PDR",    # Physical Damage Rate
                    "MDR",    # Magical Damage Rate
                    "FDR",    # Floor Damage Rate
                    "EXR"]    # EXperience Rate
  #--------------------------------------------------------------------------
  #   Sp-Parameter Full Names
  #--------------------------------------------------------------------------
  SPARAM_VOCAB_FULL= ["Target Rate",      # TarGet Rate
                      "Guard Effect",     # GuaRD effect rate
                      "Recovery Effect",  # RECovery effect rate
                      "Pharmacology",     # PHArmacology
                      "MP Cost Rate",     # Mp Cost Rate
                      "TP Charge Rate",   # Tp Charge Rate
                      "Physical Damage",  # Physical Damage Rate
                      "Magical Damage",   # Magical Damage Rate
                      "Floor Damage",     # Floor Damage Rate
                      "Experience Bonus"] # EXperience Rate
                     
  #--------------------------------------------------------------------------
  #   Info Page Label Text
  #--------------------------------------------------------------------------
  INFO_LABEL_TEXT = {
    # General
    :main_header      => "Information",
    
    # Weapons and Armor
    :atk_elements       => "Attack Elements",
    :atk_speed          => "Attack Speed",
    :atk_times_add      => "Number of Attacks",
    :atk_states         => "Attack States",
    :element_rate       => "Element Resistances",
    :state_rate         => "State Resistances",
    :state_resist_set   => "State Immunity",
    :equippable         => "Equippable Members",
    :special_flag       => "Special Effects",
    :added_skills       => "Added Skills",
    :sealed_skills      => "Sealed Skills",
    :added_skill_types  => "Added Skill Types",
    :sealed_skill_types => "Sealed Skill Types",
    :equip_wtypes       => "Added Weapon Types",
    :equip_atypes       => "Added Armor Types",
    :fixed_equips       => "Fixed Equipment",
    :sealed_equips      => "Sealed Equipment",
    
    # Slot Type
    :dual_wield       => "Dual Wield",
    
    # Items and Skills
    :hp_recovery      => "HP Recovery",
    :mp_recovery      => "MP Recovery",
    :tp_recovery      => "FP Recovery", #TP
    :add_states       => "Adds",
    :remove_states    => "Removes",
    :learn_skill      => "Teaches Skills",
    :common_event     => "Common Event ID",
    :scope            => "Target",
    :animation        => "Animation ID",
    
    # Hit Type
    :hit_type         => "Hit Type",
    :certain_hit      => "-",
    :physical_atk     => "Physical",
    :magical_atk      => "Magical",
    
    # Occasion
    :occasion         => "Usable",
    :always_use       => "Anywhere",
    :battle_use       => "Battle",
    :menu_use         => "Menu",
    :never_use        => "-",
    
    # Invocation
    :speed            => "Speed",
    :success_rate     => "Hit Rate",
    :repeats          => "Number of Hits",
    :tp_gain          => "FP Gain", #TP
        
    # Special Flags
    :auto_battle      => "Auto-Battle",
    :guard            => "Super Guard",
    :substitute       => "Substitute",
    :preserve_tp      => "Preserve TP",
    
    # Party Ability
    :encounter_half   => "Encounter Half",
    :encounter_none   => "Encounter None",
    :cancel_surprise  => "Cancel Surprise",
    :raise_preemptive => "Raise Pre-emptive",
    :gold_double      => "Double Gold Drop",
    :drop_item_double => "Double Item Drop",
    
    # Yami Engine Symphony - Equipment Learning
    :yes_equip_learn  => "Available Skills",
    
    # Bubs Shield Blocking
    :blocking        => "Blocking",
    :crit_blocking   => "Critical Blocking",
    :blocking_yes    => "Yes",
    :blocking_no     => "No",
    :unblockable     => "Unblockable",
    
    
  } # <- Do not delete.
  
  #--------------------------------------------------------------------------
  #   Scope Label Text
  #--------------------------------------------------------------------------
  SCOPE_TEXT = {
    0   => "None",
    1   => "One Enemy",
    2   => "All Enemies",
    3   => "One Random Enemy",
    4   => "Two Random Enemies",
    5   => "Three Random Enemies",
    6   => "Four Random Enemies",
    7   => "One Ally",
    8   => "All Allies",
    9   => "One Dead Ally",
    10  => "All Dead Allies",
    11  => "User",
  } # <- Do not delete.
  
  #--------------------------------------------------------------------------
  #   Special Flag Icon Index Numbers
  #--------------------------------------------------------------------------
  SPECIAL_FLAG_ICONS = {
    # Slot Type
    :dual_wield       =>  11,

    # Special Flags
    :auto_battle      =>  14,
    :guard            => 161,
    :substitute       =>  12,
    :preserve_tp      =>  13,
    
    # Party Ability
    :encounter_half   => 123,
    :encounter_none   => 122,
    :cancel_surprise  =>  10,
    :raise_preemptive => 143,
    :gold_double      => 360,
    :drop_item_double => 495,

  } # <- Do not delete.

  #--------------------------------------------------------------------------
  #   Element Icon Index Numbers
  #--------------------------------------------------------------------------
  # This setting lets you define the icon index number that represents
  # an element in info pages
  #
  # Requires "Reader Functions for Features/Effects" to see effects.
  ELEMENT_ICONS = {
    1 => 116, # Physical
    2 => 113, # Absorb
    3 =>  96, # Fire
    4 =>  97, # Ice
    5 =>  98, # Thunder
    6 =>  99, # Water
    7 => 100, # Earth
    8 => 101, # Wind
    9 => 102, # Light
   10 => 103, # Dark
   # Add more element definitions here.
   
  } # <- Do not delete.
    
  #--------------------------------------------------------------------------
  #   Element ID List for Info Page
  #--------------------------------------------------------------------------
  # This setting determines which elements are seen in an item's element
  # info page where each number in the array is an Element ID number from
  # your database.
  #
  # Requires "Reader Functions for Features/Effects" to see effects.
  DISPLAYED_ELEMENT_RESISTS = [1,2,3,4,5,6,7,8,9,10]
  
  #--------------------------------------------------------------------------
  #   State ID List for Info Page
  #--------------------------------------------------------------------------
  # This setting determines which states are seen in an item's state
  # info page where each number in the array is a State ID number from
  # your database.
  #
  # Requires "Reader Functions for Features/Effects" to see effects.
  DISPLAYED_STATE_RESISTS   = [1,2,3,4,5,6,7,8]

  #--------------------------------------------------------------------------
  #   Page Change Sound Effect
  #--------------------------------------------------------------------------
  # Filename : SE filename in Audio/SE/ folder
  # Volume   : Between 0~100
  # Pitch    : Between 50~150
  #
  #                  Filename, Volume, Pitch
  PAGE_CHANGE_SE = ["Cursor1",     80,   100]
    
  #--------------------------------------------------------------------------
  #   Maximum Icon Columns
  #--------------------------------------------------------------------------
  # Recommended value: 2
  MAX_COLUMNS = 2
  
  end # module InfoPages
end # module Bubs


#==========================================================================
#     END OF USER CUSTOMIZATION MODULE 
#==========================================================================


#==============================================================================
# ++ Sound
#==============================================================================
module Vocab
  #--------------------------------------------------------------------------
  # new method : xparam
  #--------------------------------------------------------------------------
  def self.xparam(param_id)
    Bubs::InfoPages::XPARAM_VOCAB[param_id]
  end
  
  #--------------------------------------------------------------------------
  # new method : sparam
  #--------------------------------------------------------------------------
  def self.sparam(param_id)
    Bubs::InfoPages::SPARAM_VOCAB[param_id]
  end
  
  #--------------------------------------------------------------------------
  # new method : param_f
  #--------------------------------------------------------------------------
  def self.param_f(param_id)
    Bubs::InfoPages::PARAM_VOCAB_FULL[param_id]
  end
  
  #--------------------------------------------------------------------------
  # new method : xparam_f
  #--------------------------------------------------------------------------
  def self.xparam_f(param_id)
    Bubs::InfoPages::XPARAM_VOCAB_FULL[param_id]
  end
  
  #--------------------------------------------------------------------------
  # new method : sparam_f
  #--------------------------------------------------------------------------
  def self.sparam_f(param_id)
    Bubs::InfoPages::SPARAM_VOCAB_FULL[param_id]
  end

end # module Vocab

#==============================================================================
# ++ Sound
#==============================================================================
module Sound
  #--------------------------------------------------------------------------
  # new method : play_info_page_change
  #--------------------------------------------------------------------------
  def self.play_info_page_change
    filename = Bubs::InfoPages::PAGE_CHANGE_SE[0]
    volume   = Bubs::InfoPages::PAGE_CHANGE_SE[1]
    volume = volume * 0.01 * $game_system.get_sfx_volume #Dyluck
    pitch    = Bubs::InfoPages::PAGE_CHANGE_SE[2]
    Audio.se_play("Audio/SE/" + filename, volume, pitch) 
  end
end # module Sound


#==============================================================================
# ++ Window_InfoPages
#==============================================================================
class Window_InfoPages < Window_Base
  #--------------------------------------------------------------------------
  # Constants (Starting Number of Buff/Debuff Icons)
  #--------------------------------------------------------------------------
  ICON_BUFF_START       = 5584 #64              # buff (16 icons)
  ICON_DEBUFF_START     = 5600 #80              # debuff (16 icons)
  #--------------------------------------------------------------------------
  # public instance variables
  #--------------------------------------------------------------------------
  attr_accessor :number
  attr_accessor :page_change
  attr_accessor :page_index
  attr_reader   :last_item
  #--------------------------------------------------------------------------
  # initialize
  #--------------------------------------------------------------------------
  def initialize(x, y, width, height)
    super(x, y, width, height)
    @item = nil
    @last_item = nil
    @pages = [:nothing]
    @page_change = true
    @page_index = 0
    setup_page_types
  end
  
  #--------------------------------------------------------------------------
  # setup_page_types
  #--------------------------------------------------------------------------
  def setup_page_types
    @item_pages = Bubs::InfoPages::ITEM_INFO_PAGES
    @skill_pages = [:nothing]
    @equipitem_pages  = Bubs::InfoPages::EQUIP_INFO_PAGES
  end
  
  #--------------------------------------------------------------------------
  # refresh
  #--------------------------------------------------------------------------
  def refresh
    contents.clear
    standard_page_doodads(4, 0)
    return unless @item
    draw_page_contents(4, line_height * 2, @item)
  end
  
  #--------------------------------------------------------------------------
  # item=                                        # Set Item
  #--------------------------------------------------------------------------
  def item=(item)
    @last_item = @item
    @item = item
    change_page_type
    refresh
  end
  
  #--------------------------------------------------------------------------
  # change_page_type
  #--------------------------------------------------------------------------
  def change_page_type
    if @item.is_a?(RPG::Item)
      @pages = @item_pages
      @page_index = 0 if @last_item && !@last_item.is_a?(RPG::Item)
    elsif @item.is_a?(RPG::Skill)
      @pages = @skill_pages
      @page_index = 0 if @last_item && !@last_item.is_a?(RPG::Skill)
    elsif @item.is_a?(RPG::EquipItem)
      @pages = @equipitem_pages
      @page_index = 0 if @last_item && !@last_item.is_a?(RPG::EquipItem)
    end
  end

  #--------------------------------------------------------------------------
  # update
  #--------------------------------------------------------------------------
  def update
    super
    update_page
  end
  
  #--------------------------------------------------------------------------
  # update_page               # Checks for button input for page changing
  #--------------------------------------------------------------------------
  def update_page
    if visible && @page_change
      next_info_page if Input.trigger?(next_page_button) 
      prev_info_page if Input.trigger?(prev_page_button)
    end
  end
  
  #--------------------------------------------------------------------------
  # current_page
  #--------------------------------------------------------------------------
  def current_page
    @pages[@page_index]
  end

  #--------------------------------------------------------------------------
  # draw_page_contents
  #--------------------------------------------------------------------------
  def draw_page_contents(x, y, item)
    case current_page
    when :basic_page
      return feature_reader_req(x, y) unless $imported["BubsFeaturesReader"]
      draw_usableitem_page(item, x, y)
      
    when :use_page
      draw_use_page(item, x, y)
      
    when :learn_skill_page
      return feature_reader_req(x, y) unless $imported["BubsFeaturesReader"]
      draw_learn_skill_page(item, x, y)
      
    when :misc_page
      return feature_reader_req(x, y) unless $imported["BubsFeaturesReader"]
      draw_misc_page(item, x, y)
      
    when :special_flag_page
      return feature_reader_req(x, y) unless $imported["BubsFeaturesReader"]
      draw_special_flag_page(item, x, y)

    when :param_page
      return feature_reader_req(x, y) unless $imported["BubsFeaturesReader"]
      draw_param_page(item, x, y)
      
    when :xparam_page
      return feature_reader_req(x, y) unless $imported["BubsFeaturesReader"]
      draw_xparam_page(item, x, y)
      
    when :sparam_page
      return feature_reader_req(x, y) unless $imported["BubsFeaturesReader"]
      draw_sparam_page(item, x, y)
      
    when :attack_page
      return feature_reader_req(x, y) unless $imported["BubsFeaturesReader"]
      draw_attack_info(item, x, y)
      
    when :element_page
      return feature_reader_req(x, y) unless $imported["BubsFeaturesReader"]
      draw_element_resists_page(item, x, y)
      
    when :state_page
      return feature_reader_req(x, y) unless $imported["BubsFeaturesReader"]
      draw_state_resists_page(item, x, y)
      
    when :added_skills_page
      return feature_reader_req(x, y) unless $imported["BubsFeaturesReader"]
      draw_added_skills_page(item, x, y)
      
    when :sealed_skills_page
      return feature_reader_req(x, y) unless $imported["BubsFeaturesReader"]
      draw_sealed_skills_page(item, x, y)
      
    when :added_skill_types_page
      return feature_reader_req(x, y) unless $imported["BubsFeaturesReader"]
      draw_added_skill_types_page(item, x, y)
      
    when :equip_types_page
      return feature_reader_req(x, y) unless $imported["BubsFeaturesReader"]
      draw_equip_types_page(item, x, y)
      
    when :equip_wtypes_page
      return feature_reader_req(x, y) unless $imported["BubsFeaturesReader"]
      draw_equip_wtypes_page(item, x, y)
      
    when :equip_atypes_page
      return feature_reader_req(x, y) unless $imported["BubsFeaturesReader"]
      draw_equip_atypes_page(item, x, y)
      
    when :equip_slots_page
      return feature_reader_req(x, y) unless $imported["BubsFeaturesReader"]
      draw_equip_slots_page(item, x, y)
      
    when :yes_equip_learn_page
      return yes_equip_learn_req(x, y) unless $imported["YES-EquipmentLearning"]
      draw_yes_equip_learn_page(item, x, y)
      
    when :bubs_blocking_page
      return unless $imported["BubsBlocking"]
      draw_bubs_blocking_page(item, x, y)
      
    when :equippable_page
      draw_equippable_page(item, x, y) 
      
    end # case
  end # def
    
  #--------------------------------------------------------------------------
  # standard_page_doodads
  #--------------------------------------------------------------------------
  def standard_page_doodads(x, y)
    draw_info_header_text(x, y)
    draw_info_footer_text(x, y)
    draw_horz_line(line_height)
    draw_info_button_icons(x, y)
  end
  
  #--------------------------------------------------------------------------
  # feature_reader_req
  #--------------------------------------------------------------------------
  def feature_reader_req(x, y)
    change_color(normal_color)
    lh = line_height
    rect = Rect.new(x, y, contents.width - 4 - x, lh)
    text = "This page requires"
    rect.y += lh
    draw_text(rect, text, 1)
    text = "the script"
    rect.y += lh
    draw_text(rect, text, 1)
    text = "\"Reader Functions for "
    rect.y += lh
    draw_text(rect, text, 1)
    text = "Features\/Effects\""
    rect.y += lh
    draw_text(rect, text, 1)
    text = "to be properly viewed."
    rect.y += lh
    draw_text(rect, text, 1)
  end
  
  #--------------------------------------------------------------------------
  # yes_equip_learn_req
  #--------------------------------------------------------------------------
  def yes_equip_learn_req(x, y)
    change_color(normal_color)
    lh = line_height
    rect = Rect.new(x, y, contents.width - 4 - x, lh)
    text = "This page requires"
    rect.y += lh
    draw_text(rect, text, 1)
    text = "the script"
    rect.y += lh
    draw_text(rect, text, 1)
    text = "\"Yami Engine Symphony -"
    rect.y += lh
    draw_text(rect, text, 1)
    text = "Equipment Learning\""
    rect.y += lh
    draw_text(rect, text, 1)
    text = "to be properly viewed."
    rect.y += lh
    draw_text(rect, text, 1)
  end
  
  #--------------------------------------------------------------------------
  # icon_width
  #--------------------------------------------------------------------------
  def icon_width
    return 24
  end
  
  #--------------------------------------------------------------------------
  # prev_page_button
  #--------------------------------------------------------------------------
  def prev_page_button
    Bubs::InfoPages::PAGE_BUTTONS[:prev_info_page]
  end
  
  #--------------------------------------------------------------------------
  # next_page_button
  #--------------------------------------------------------------------------
  def next_page_button
    Bubs::InfoPages::PAGE_BUTTONS[:next_info_page]
  end
  
  #--------------------------------------------------------------------------
  # normal_footer_text
  #--------------------------------------------------------------------------
  def normal_footer_text
    Bubs::InfoPages::NORMAL_FOOTER_TEXT
  end
  
  #--------------------------------------------------------------------------
  # use_full_param_names?
  #--------------------------------------------------------------------------
  def use_full_param_names?
    Bubs::InfoPages::USE_FULL_PARAMETER_NAMES
  end
  
  #--------------------------------------------------------------------------
  # vocab_param
  #--------------------------------------------------------------------------
  def vocab_param(param_id)
    return Vocab::param_f(param_id) if use_full_param_names?
    return Vocab::param(param_id)
  end
  
  #--------------------------------------------------------------------------
  # vocab_xparam
  #--------------------------------------------------------------------------
  def vocab_xparam(param_id)
    return Vocab::xparam_f(param_id) if use_full_param_names?
    return Vocab::xparam(param_id)
  end
  
  #--------------------------------------------------------------------------
  # vocab_sparam
  #--------------------------------------------------------------------------
  def vocab_sparam(param_id)
    return Vocab::sparam_f(param_id) if use_full_param_names?
    return Vocab::sparam(param_id)
  end
  
  #--------------------------------------------------------------------------
  # button_icon_id
  #--------------------------------------------------------------------------
  def button_icon_id(symbol)
    Bubs::InfoPages::PAGE_BUTTON_ICONS[symbol]
  end
  
  #--------------------------------------------------------------------------
  # actor_icons
  #--------------------------------------------------------------------------
  def actor_icon_id(actor_id)
    Bubs::InfoPages::ACTOR_ICONS[actor_id]
  end

  #--------------------------------------------------------------------------
  # element_icon_id
  #--------------------------------------------------------------------------
  def element_icon_id(element_id)
    Bubs::InfoPages::ELEMENT_ICONS[element_id]
  end
  
  #--------------------------------------------------------------------------
  # special_flag_icon_id
  #--------------------------------------------------------------------------
  def special_flag_icon_id(symbol)
    Bubs::InfoPages::SPECIAL_FLAG_ICONS[symbol]
  end
  
  #--------------------------------------------------------------------------
  # listed_elements
  #--------------------------------------------------------------------------
  def listed_elements
    Bubs::InfoPages::DISPLAYED_ELEMENT_RESISTS
  end
  
  #--------------------------------------------------------------------------
  # listed_states
  #--------------------------------------------------------------------------
  def listed_states
    Bubs::InfoPages::DISPLAYED_STATE_RESISTS
  end
  
  #--------------------------------------------------------------------------
  # label_text
  #--------------------------------------------------------------------------
  def label_text(symbol)
    Bubs::InfoPages::INFO_LABEL_TEXT[symbol]
  end
  
  #--------------------------------------------------------------------------
  # col_max
  #--------------------------------------------------------------------------
  def col_max
    Bubs::InfoPages::MAX_COLUMNS
  end
  
  #--------------------------------------------------------------------------
  # scope_text
  #--------------------------------------------------------------------------
  def scope_text(scope_id)
    Bubs::InfoPages::SCOPE_TEXT[scope_id]
  end
  
  #--------------------------------------------------------------------------
  # draw_label_text
  #--------------------------------------------------------------------------
  def draw_label_text(symbol, x, y, align = 0)
    change_color(system_color)
    rect = standard_rect(x, y) 
    text = label_text(symbol)
    draw_text(rect, text, align)
  end
  
  #--------------------------------------------------------------------------
  # item_width
  #--------------------------------------------------------------------------
  def item_width
    (width - standard_padding * 2 + 4) / col_max - 4
  end
  
  #--------------------------------------------------------------------------
  # next_info_page
  #--------------------------------------------------------------------------
  def next_info_page
    @page_index = (@page_index + 1) % @pages.size
    Sound.play_info_page_change
    refresh
  end
  
  #--------------------------------------------------------------------------
  # prev_info_page
  #--------------------------------------------------------------------------
  def prev_info_page
    @page_index = (@page_index - 1) % @pages.size
    Sound.play_info_page_change
    refresh
  end
  
  #--------------------------------------------------------------------------
  # line_color                              # Get Color of Horizontal Line
  #--------------------------------------------------------------------------
  def line_color
    color = normal_color
    color.alpha = 48
    color
  end
    
  #--------------------------------------------------------------------------
  # standard_rect
  #--------------------------------------------------------------------------
  def standard_rect(x, y)
    Rect.new(x, y, contents.width - 4 - x, line_height)
  end
  
  #--------------------------------------------------------------------------
  # draw_horz_line
  #--------------------------------------------------------------------------
  def draw_horz_line(y)
    line_y = y + line_height / 2 - 1
    contents.fill_rect(0, line_y, contents_width, 2, line_color)
  end
  
  #--------------------------------------------------------------------------
  # draw_info_footer_text
  #--------------------------------------------------------------------------
  def draw_info_footer_text(x, y)
    y = y + line_height * (contents.height / line_height - 1)
    rect = standard_rect(x, y)
    #rect.x += 0
    change_color(normal_color)
    draw_text(rect, normal_footer_text, 1)
  end
  
  #--------------------------------------------------------------------------
  # draw_info_button_icons
  #--------------------------------------------------------------------------
  def draw_info_button_icons(x, y)
    y = y + line_height * (contents.height / line_height - 1)
    draw_icon(button_icon_id(:prev_info_page), x, y)
    x = contents.width - icon_width - 4
    draw_icon(button_icon_id(:next_info_page), x, y)
  end
  
  #--------------------------------------------------------------------------
  # draw_equippable_page
  #--------------------------------------------------------------------------
  def draw_equippable_page(item, x, y)
    draw_label_text(:equippable, x, y)
    draw_equippable_members_info(item, x, y + line_height)
  end
  
  #--------------------------------------------------------------------------
  # draw_equippable_members_info
  #--------------------------------------------------------------------------
  def draw_equippable_members_info(item, x, y)
    change_color(normal_color)
    temp = $game_party.members.select { |member| member.equippable?(item) }
    temp.each_with_index do |member, index|
      y_plus = line_height * (index / col_max)
      x_plus = index % col_max * item_width
      icon_index = actor_icon_id(member.id) ? member.id : :default
      draw_icon(actor_icon_id(icon_index), x + x_plus, y + y_plus)
      rect = Rect.new(x, y, contents.width / col_max - 4 - x, line_height)
      rect.x += x_plus
      rect.y += y_plus
      text = sprintf("%s", member.name)
      draw_text(rect, text, 2)
    end
  end
    
  #--------------------------------------------------------------------------
  # draw_param_page
  #--------------------------------------------------------------------------
  def draw_param_page(item, x, y)
    8.times do |i|
      y_plus = line_height * i
      x_plus = 0 #i % col_max * item_width
      draw_param_name(x + x_plus, y + y_plus, i)
      draw_param_value(item, x + x_plus, y + y_plus, i)
    end
  end
  
  #--------------------------------------------------------------------------
  # draw_xparam_page
  #--------------------------------------------------------------------------
  def draw_xparam_page(item, x, y)
    10.times do |i|
      y_plus = line_height * i
      x_plus = 0 #i % col_max * item_width
      draw_xparam_name(x + x_plus, y + y_plus, i)
      draw_xparam_value(item, x + x_plus, y + y_plus, i)
    end
  end

  #--------------------------------------------------------------------------
  # draw_sparam_page
  #--------------------------------------------------------------------------
  def draw_sparam_page(item, x, y)
    10.times do |i|
      y_plus = line_height * i
      x_plus = 0 #i % col_max * item_width
      draw_sparam_name(x + x_plus, y + y_plus, i)
      draw_sparam_value(item, x + x_plus, y + y_plus, i)
    end
  end
  
  #--------------------------------------------------------------------------
  # draw_attack_info
  #--------------------------------------------------------------------------
  def draw_attack_info(item, x, y)
    draw_attack_elements(item, x, y + line_height * 0)
    draw_attack_speed(item, x, y + line_height * 1)
    draw_number_of_attacks(item, x, y + line_height * 2)
    draw_label_text(:atk_states, x, y + line_height * 4)
    draw_attack_states(item, x, y + line_height * 5)
  end
  
  #--------------------------------------------------------------------------
  # draw_attack_elements
  #--------------------------------------------------------------------------
  def draw_attack_elements(item, x, y)
    draw_label_text(:atk_elements, x, y)
    draw_attack_elements_icons(item, x, y)
  end
  
  #--------------------------------------------------------------------------
  # draw_info_header_text
  #--------------------------------------------------------------------------
  def draw_info_header_text(x, y)
    rect = standard_rect(x, y)
    draw_label_text(:main_header, x, y)
    draw_icon(@item.icon_index, rect.width - icon_width, y) if @item
  end
  
  #--------------------------------------------------------------------------
  # draw_attack_elements_icons
  #--------------------------------------------------------------------------
  def draw_attack_elements_icons(item, x, y)
    icons = item.atk_elements
    icons.reverse.each_with_index do |id, i|
      n = element_icon_id(id) ? element_icon_id(id) : 0
      draw_icon(n, contents.width - 4 - x - (icon_width * (i + 1)), y)
    end
  end
  
  #--------------------------------------------------------------------------
  # draw_attack_speed
  #--------------------------------------------------------------------------
  def draw_attack_speed(item, x, y)
    draw_label_text(:atk_speed, x, y)
    rect = standard_rect(x, y)
    value = item.atk_speed
    change_color(param_change_color(value))
    draw_text(rect, sprintf("%+d", value), 2)
  end
  
  #--------------------------------------------------------------------------
  # draw_number_of_attacks
  #--------------------------------------------------------------------------
  def draw_number_of_attacks(item, x, y)
    draw_label_text(:atk_times_add, x, y)
    rect = standard_rect(x, y)
    value = item.atk_times_add
    change_color(param_change_color(value))
    draw_text(rect, sprintf("%+d", value), 2)
  end
  
  #--------------------------------------------------------------------------
  # draw_attack_states
  #--------------------------------------------------------------------------
  def draw_attack_states(item, x, y)
    change_color(normal_color)
    item.atk_states.each_with_index do |state_id, index|
      y_plus = line_height * (index / col_max)
      x_plus = index % col_max * item_width
      icon_index = $data_states[state_id].icon_index
      draw_icon(icon_index, x + x_plus, y + y_plus)
      rect = Rect.new(x, y, contents.width / col_max - 4 - x, line_height)
      rect.x += x_plus
      rect.y += y_plus
      rate = item.atk_states_rate(state_id) * 100
      text = sprintf("%d%%", rate)
      draw_text(rect, text, 2)
    end
  end  
  
  #--------------------------------------------------------------------------
  # draw_element_resists_page
  #--------------------------------------------------------------------------
  def draw_element_resists_page(item, x, y)
    draw_label_text(:element_rate, x, y)
    draw_element_resists(item, x, y + line_height * 1)
  end
  
  #--------------------------------------------------------------------------
  # draw_state_resists_page
  #--------------------------------------------------------------------------
  def draw_state_resists_page(item, x, y)
    draw_label_text(:state_rate, x, y)
    draw_state_resists(item, x, y + line_height * 1)
    draw_label_text(:state_resist_set, x, y + line_height * 8)
    draw_state_immunity(item, x, y + + line_height * 9)
  end
  
  #--------------------------------------------------------------------------
  # draw_state_resists
  #--------------------------------------------------------------------------
  def draw_state_resists(item, x, y)
    listed_states.each_with_index do |state_id, index|
      y_plus = line_height * (index / col_max)
      x_plus = index % col_max * item_width
      icon_index = $data_states[state_id].icon_index
      draw_icon(icon_index, x + x_plus, y + y_plus)
      rect = Rect.new(x, y, contents.width / col_max - 4 - x, line_height)
      rect.x += x_plus
      rect.y += y_plus
      rate = item.state_rate(state_id) * 100 - 100
      change_color(param_change_color(-rate))
      text = sprintf("%+d%%", -rate)
      draw_text(rect, text, 2)    
    end
  end
  
  #--------------------------------------------------------------------------
  # draw_state_immunity
  #--------------------------------------------------------------------------
  def draw_state_immunity(item, x, y)
    item.state_resist_set.each_with_index do |state_id, index|
      icon_row_max = (contents.width - 4 - x) / icon_width
      y_plus = (index / icon_row_max) * line_height
      x_plus = (index % icon_row_max) * icon_width
      icon_index = $data_states[state_id].icon_index
      draw_icon(icon_index, x + x_plus, y + y_plus)
    end
  end
  
  #--------------------------------------------------------------------------
  # draw_element_resists
  #--------------------------------------------------------------------------
  def draw_element_resists(item, x, y)
    change_color(normal_color)
    listed_elements.each_with_index do |element_id, index|
      y_plus = line_height * (index / col_max)
      x_plus = index % col_max * item_width
      icon_index = element_icon_id(element_id) ? element_icon_id(element_id) : 0
      draw_icon(icon_index, x + x_plus, y + y_plus)
      rect = Rect.new(x + x_plus, y + y_plus, contents.width / col_max - 4 - x, line_height)
      rate = item.element_rate(element_id) * 100 - 100
      change_color(param_change_color(-rate))
      text = sprintf("%+d%%", -rate)
      draw_text(rect, text, 2)  
    end
  end
  
  #--------------------------------------------------------------------------
  # draw_usableitem_page
  #--------------------------------------------------------------------------
  def draw_usableitem_page(item, x, y)
    lh = line_height
    draw_hp_recovery(item, x, y + lh * 0)
    draw_mp_recovery(item, x, y + lh * 1)
    draw_tp_recovery(item, x, y + lh * 2)
    draw_label_text(:add_states, x, y  + lh * 4)
    draw_add_state_icons(item, x, y + lh * 5)
    draw_label_text(:remove_states, x, y + lh * 7)
    draw_remove_state_icons(item, x, y + lh * 8)
  end
  
  #--------------------------------------------------------------------------
  # draw_add_state_icons
  #--------------------------------------------------------------------------
  def draw_add_state_icons(item, x, y)
    icons = get_add_state_icons(item)
    draw_icon_columns(icons, x, y)
  end

  
  #--------------------------------------------------------------------------
  # draw_remove_state_icons
  #--------------------------------------------------------------------------
  def draw_remove_state_icons(item, x, y)
    icons = get_remove_state_icons(item)
    draw_icon_columns(icons, x, y)
  end

  #--------------------------------------------------------------------------
  # draw_learn_skill_page
  #--------------------------------------------------------------------------
  def draw_learn_skill_page(item, x, y)
    draw_label_text(:learn_skill, x, y)
    draw_learn_skills(item, x, y + line_height)
  end
  
  #--------------------------------------------------------------------------
  # draw_learn_skills
  #--------------------------------------------------------------------------
  def draw_learn_skills(item, x, y)
    w = contents_width - icon_width
    item.learn_skills.each_with_index do |skill_id, i|
      skill = $data_skills[skill_id]
      draw_item_name(skill, x, y + line_height * i, true, w)
    end
  end
  
  #--------------------------------------------------------------------------
  # draw_misc_page
  #--------------------------------------------------------------------------
  def draw_misc_page(item, x, y)
    lh = line_height
    draw_common_event_info(item, x, y)
    draw_common_event_name(item, x, y + lh)
    draw_animation_info(item, x, y + lh * 2)
  end
  
  #--------------------------------------------------------------------------
  # draw_common_event_info
  #--------------------------------------------------------------------------
  def draw_common_event_info(item, x, y)
    draw_label_text(:common_event, x, y)
    rect = standard_rect(x, y)
    change_color(normal_color)
    text = item.common_event ? sprintf("%d", item.common_event) : "-"
    draw_text(rect, text, 2)
  end
  
  #--------------------------------------------------------------------------
  # draw_common_event_name
  #--------------------------------------------------------------------------
  def draw_common_event_name(item, x, y)
    return unless item.common_event
    id = item.common_event
    rect = standard_rect(x, y)
    text = $data_common_events[id].name
    draw_text(rect, text)
  end
  
  #--------------------------------------------------------------------------
  # draw_animation_info
  #--------------------------------------------------------------------------
  def draw_animation_info(item, x, y)
    lh = line_height
    draw_label_text(:animation, x, y)
    draw_animation_id(item, x, y)
    draw_animation_name(item, x, y + lh)
  end
  
  #--------------------------------------------------------------------------
  # draw_animation_id
  #--------------------------------------------------------------------------
  def draw_animation_id(item, x, y)
    text = item.animation_id
    rect = standard_rect(x, y)
    change_color(normal_color)
    draw_text(rect, text, 2)
  end
  
  #--------------------------------------------------------------------------
  # draw_animation_name
  #--------------------------------------------------------------------------
  def draw_animation_name(item, x, y)
    id = item.animation_id
    text = $data_animations[id] ? $data_animations[id].name : "None"
    rect = standard_rect(x, y)
    change_color(normal_color)
    draw_text(rect, text)
  end
  
  
  #--------------------------------------------------------------------------
  # draw_special_flag_page
  #--------------------------------------------------------------------------
  def draw_special_flag_page(item, x, y)
    draw_label_text(:special_flag, x, y)
    draw_special_flag_list(item, x, y + line_height)
  end
  
  #--------------------------------------------------------------------------
  # draw_special_flag_text
  #--------------------------------------------------------------------------
  def draw_special_flag_list(item, x, y)
    lh = line_height
    change_color(normal_color)
    item.get_feature_flags.each_with_index do |symbol, i|
      text = label_text(symbol)
      rect = standard_rect(x + 24, y + lh * i)
      draw_text(rect, text)
      draw_icon(special_flag_icon_id(symbol), x, y + lh * i)
    end
  end
  
  #--------------------------------------------------------------------------
  # draw_yes_equip_learn_page
  #--------------------------------------------------------------------------
  def draw_yes_equip_learn_page(item, x, y)
    draw_label_text(:yes_equip_learn, x, y)
    draw_yes_item_skills(item, x, y + line_height)
  end
  
  #--------------------------------------------------------------------------
  # draw_yes_item_skills
  #--------------------------------------------------------------------------
  def draw_yes_item_skills(item, x, y)
    lh = line_height
    vocab_ap = YES::EQUIPMENT_LEARNING::VOCAB
    vocab_size = text_size(vocab_ap).width
    item.el_skills.each_with_index do |skill_id, i|
      skill = $data_skills[skill_id]
      rect = standard_rect(x, y + lh * i)
      draw_item_name(skill, x, y + lh * i)
      change_color(system_color)
      draw_text(rect, vocab_ap, 2)
      change_color(normal_color)
      rect.width -= vocab_size
      draw_text(rect, skill.el_require, 2)
    end
  end
    
  #--------------------------------------------------------------------------
  # draw_icon_columns
  #--------------------------------------------------------------------------
  def draw_icon_columns(icons, x, y)
    icons.each_with_index do |n, i|
      icon_row_max = (contents.width - 4 - x) / icon_width
      y_plus = (i / icon_row_max) * line_height
      x_plus = (i % icon_row_max) * icon_width
      draw_icon(n, x + x_plus, y + y_plus)
    end
  end
  
  #--------------------------------------------------------------------------
  # get_add_state_icons
  #--------------------------------------------------------------------------
  def get_add_state_icons(item)
    icons = item.add_states.collect   { |id| $data_states[id].icon_index }
    icons += item.add_buffs.collect   { |param| buff_icon_index( 1, param) }
    icons += item.add_debuffs.collect { |param| buff_icon_index(-1, param) }
    icons.delete(0)
    icons
  end  
  
  #--------------------------------------------------------------------------
  # get_remove_state_icons
  #--------------------------------------------------------------------------
  def get_remove_state_icons(item)
    icons =  item.remove_states.collect  { |id| $data_states[id].icon_index }
    icons += item.remove_buffs.collect   { |param| buff_icon_index( 1, param) }
    icons += item.remove_debuffs.collect { |param| buff_icon_index(-1, param) }
    icons.delete(0)
    icons
  end
  
  #--------------------------------------------------------------------------
  # buff_icon_index           # Get Icon Number Corresponding to Buff/Debuff
  #--------------------------------------------------------------------------
  def buff_icon_index(buff_level, param_id)
    if buff_level > 0
      return ICON_BUFF_START + (buff_level - 1) * 8 + param_id
    elsif buff_level < 0
      return ICON_DEBUFF_START + (-buff_level - 1) * 8 + param_id 
    else
      return 0
    end
  end
    
  #--------------------------------------------------------------------------
  # draw_hp_recovery
  #--------------------------------------------------------------------------
  def draw_hp_recovery(item, x, y)
    value = item.hp_recovery
    draw_recovery_text(:hp_recovery, x, y, value)
  end
  
  #--------------------------------------------------------------------------
  # draw_mp_recovery
  #--------------------------------------------------------------------------
  def draw_mp_recovery(item, x, y)
    value = item.mp_recovery
    draw_recovery_text(:mp_recovery, x, y, value)
  end
  
  #--------------------------------------------------------------------------
  # draw_tp_recovery
  #--------------------------------------------------------------------------
  def draw_tp_recovery(item, x, y)
    # If you get an error on this line, it means you are using an old
    # version of "Reader Functions for Features/Effects". Get v1.2 or above.
    value = item.tp_recovery
    symbol = :tp_recovery
    draw_recovery_text(symbol, x, y, value)
  end
  
  #--------------------------------------------------------------------------
  # draw_recovery_text
  #--------------------------------------------------------------------------
  def draw_recovery_text(symbol, x, y, value)
    rect = standard_rect(x, y)
    draw_label_text(symbol, x, y)
    text = get_recovery_text(value)
    draw_text(rect, text, 2)
  end
  
  #--------------------------------------------------------------------------
  # get_recovery_text
  #--------------------------------------------------------------------------
  def get_recovery_text(value, rate = 0)
    rate = rate * 100
    if value != 0 && rate != 0
      change_color(param_change_color(value))
      text = sprintf("%+d%%%+d", rate, value)
    elsif rate != 0
      change_color(param_change_color(rate))
      text = sprintf("%+d%%", rate)
    else
      change_color(param_change_color(value))
      text = sprintf("%+d", value)
    end
    return text
  end

  #--------------------------------------------------------------------------
  # draw_param_name
  #--------------------------------------------------------------------------
  def draw_param_name(x, y, param_id)
    change_color(system_color)
    text = vocab_param(param_id)
    draw_text(x, y, contents.width - 4 - x, line_height, text)
  end
  
  #--------------------------------------------------------------------------
  # draw_xparam_name
  #--------------------------------------------------------------------------
  def draw_xparam_name(x, y, param_id)
    change_color(system_color)
    text = vocab_xparam(param_id)
    draw_text(x, y, contents.width - 4 - x, line_height, text)
  end
  
  #--------------------------------------------------------------------------
  # draw_sparam_name
  #--------------------------------------------------------------------------
  def draw_sparam_name(x, y, param_id)
    change_color(system_color)
    text = vocab_sparam(param_id)
    draw_text(x, y, contents.width - 4 - x, line_height, text)
  end
  
  #--------------------------------------------------------------------------
  # draw_param_value
  #--------------------------------------------------------------------------
  def draw_param_value(item, x, y, param_id)
    value = item.param(param_id)
    rate = item.param_rate(param_id)
    text = get_param_text(value, rate)
    draw_parameter_value(text, x, y)
  end
  
  #--------------------------------------------------------------------------
  # draw_xparam_value
  #--------------------------------------------------------------------------
  def draw_xparam_value(item, x, y, param_id)
    value = item.xparam(param_id)
    text = get_xparam_text(value)
    draw_parameter_value(text, x, y)
  end
  
  #--------------------------------------------------------------------------
  # draw_sparam_value
  #--------------------------------------------------------------------------
  def draw_sparam_value(item, x, y, param_id)
    value = item.sparam(param_id)
    text = get_sparam_text(value)
    draw_parameter_value(text, x, y)
  end
  
  #--------------------------------------------------------------------------
  # draw_parameter_value
  #--------------------------------------------------------------------------
  def draw_parameter_value(text, x, y)
    rect = standard_rect(x, y)
    draw_text(rect, text, 2)
  end
  
  #--------------------------------------------------------------------------
  # get_param_text
  #--------------------------------------------------------------------------
  def get_param_text(value, rate = 0)
    rate = (rate * 100).to_i - 100
    if value != 0 && rate != 0
      change_color(param_change_color(value))
      text = sprintf("%+d%%%+d", rate, value)
    elsif rate != 0
      change_color(param_change_color(rate))
      text = sprintf("%+d%%", rate)
    else
      change_color(param_change_color(value))
      text = sprintf("%+d", value)
    end
    return text
  end
  
  #--------------------------------------------------------------------------
  # get_xparam_text
  #--------------------------------------------------------------------------
  def get_xparam_text(value)
    value = (value * 100)
    change_color(param_change_color(value))
    text = sprintf("%+d%%", value)
    return text
  end

  #--------------------------------------------------------------------------
  # get_sparam_text
  #--------------------------------------------------------------------------
  def get_sparam_text(value)
    value = (value * 100).to_i - 100
    change_color(param_change_color(value))
    text = sprintf("%+d%%", value)
    return text
  end
  
  #--------------------------------------------------------------------------
  # draw_use_page
  #--------------------------------------------------------------------------
  def draw_use_page(item, x, y)
    lh = line_height
    draw_scope_info(item, x, y)
    draw_occasion_info(item, x, y + lh)
    draw_hit_type_info(item, x, y + lh * 2)
    draw_invocation_info(item, x, y + lh * 4)
  end
  
  #--------------------------------------------------------------------------
  # draw_scope_info
  #--------------------------------------------------------------------------
  def draw_scope_info(item, x, y)
    draw_label_text(:scope, x, y)
    draw_scope_text(item, x, y)
  end
  
  #--------------------------------------------------------------------------
  # draw_scope_text
  #--------------------------------------------------------------------------
  def draw_scope_text(item, x, y)
    scope_id = item.scope
    text = scope_text(scope_id)
    rect = standard_rect(x, y)
    change_color(normal_color)
    draw_text(rect, text, 2)
  end
  
  #--------------------------------------------------------------------------
  # draw_occasion_info
  #--------------------------------------------------------------------------
  def draw_occasion_info(item, x, y)
    draw_label_text(:occasion, x, y)
    draw_occasion_text(item, x, y)
  end
  
  #--------------------------------------------------------------------------
  # draw_occasion_text
  #--------------------------------------------------------------------------
  def draw_occasion_text(item, x, y)
    case item.occasion
    when 0
      text = label_text(:always_use)
    when 1
      text = label_text(:battle_use)
    when 2
      text = label_text(:menu_use)
    when 3
      text = label_text(:never_use)
    end
    rect = standard_rect(x, y)
    change_color(normal_color)
    draw_text(rect, text, 2)
  end
  
  #--------------------------------------------------------------------------
  # draw_hit_type_info
  #--------------------------------------------------------------------------
  def draw_hit_type_info(item, x, y)
    draw_label_text(:hit_type, x, y)
    draw_hit_type_text(item, x, y)
  end
  
  #--------------------------------------------------------------------------
  # draw_hit_type_text
  #--------------------------------------------------------------------------
  def draw_hit_type_text(item, x, y)
    case item.hit_type
    when 0
      text = label_text(:certain_hit)
    when 1
      text = label_text(:physical_atk)
    when 2
      text = label_text(:magical_atk)
    end
    rect = standard_rect(x, y)
    change_color(normal_color)
    draw_text(rect, text, 2)
  end
  
  #--------------------------------------------------------------------------
  # draw_invocation_info
  #--------------------------------------------------------------------------
  def draw_invocation_info(item, x, y)
    lh = line_height
    draw_success_info(item, x, y)
    draw_speed_info(item,   x, y + lh)
    draw_repeats_info(item, x, y + lh * 2)
    draw_tp_gain_info(item, x, y + lh * 3)
  end
  
  #--------------------------------------------------------------------------
  # draw_speed_info
  #--------------------------------------------------------------------------
  def draw_speed_info(item, x, y)
    draw_label_text(:speed, x, y)
    text = item.speed
    rect = standard_rect(x, y)
    change_color(normal_color)
    draw_text(rect, text, 2)
  end
  
  #--------------------------------------------------------------------------
  # draw_success_info
  #--------------------------------------------------------------------------
  def draw_success_info(item, x, y)
    draw_label_text(:success_rate, x, y)
    text = sprintf("%d%%", item.success_rate) 
    rect = standard_rect(x, y)
    change_color(normal_color)
    draw_text(rect, text, 2)
  end
  
  #--------------------------------------------------------------------------
  # draw_repeats_info
  #--------------------------------------------------------------------------
  def draw_repeats_info(item, x, y)
    draw_label_text(:repeats, x, y)
    text = item.repeats
    rect = standard_rect(x, y)
    change_color(normal_color)
    draw_text(rect, text, 2)
  end
  
  #--------------------------------------------------------------------------
  # draw_tp_gain_info
  #--------------------------------------------------------------------------
  def draw_tp_gain_info(item, x, y)
    draw_label_text(:tp_gain, x, y)
    text = item.tp_gain
    rect = standard_rect(x, y)
    change_color(normal_color)
    draw_text(rect, text, 2)
  end
  
  #--------------------------------------------------------------------------
  # draw_added_skills_page
  #--------------------------------------------------------------------------
  def draw_added_skills_page(item, x, y)
    lh = line_height
    draw_label_text(:added_skills, x, y)
    draw_added_skills_info(item, x, y + lh)
  end
  
  #--------------------------------------------------------------------------
  # draw_added_skills_info
  #--------------------------------------------------------------------------
  def draw_added_skills_info(item, x, y)
    w = contents_width - icon_width
    item.added_skills.each_with_index do |skill_id, i|
      skill = $data_skills[skill_id]
      draw_item_name(skill, x, y + line_height * i, true, w)
    end
  end
  
  #--------------------------------------------------------------------------
  # draw_sealed_skills_page
  #--------------------------------------------------------------------------
  def draw_sealed_skills_page(item, x, y)
    lh = line_height
    draw_label_text(:sealed_skills, x, y)
    draw_sealed_skills_info(item, x, y + lh)
  end
  
  #--------------------------------------------------------------------------
  # draw_sealed_skills_info
  #--------------------------------------------------------------------------
  def draw_sealed_skills_info(item, x, y)
    w = contents_width - icon_width
    item.sealed_skills.each_with_index do |skill_id, i|
      skill = $data_skills[skill_id]
      draw_item_name(skill, x, y + line_height * i, true, w)
    end
  end
  
  #--------------------------------------------------------------------------
  # draw_added_skill_types_page
  #--------------------------------------------------------------------------
  def draw_added_skill_types_page(item, x, y)
    lh = line_height
    draw_label_text(:added_skill_types, x, y)
    draw_added_skill_types_info(item, x, y + lh)
  end
  
  #--------------------------------------------------------------------------
  # draw_added_skill_types_info
  #--------------------------------------------------------------------------
  def draw_added_skill_types_info(item, x, y)
    lh = line_height
    rect = standard_rect(x, y)
    change_color(normal_color)
    item.added_skill_types.each_with_index do |skill_type_id, i|
      text = $data_system.skill_types[skill_type_id]
      draw_text(rect, text)
      rect.y += lh
    end
  end
  
  #--------------------------------------------------------------------------
  # draw_equip_wtypes_page
  #--------------------------------------------------------------------------
  def draw_equip_wtypes_page(item, x, y)
    lh = line_height
    draw_label_text(:equip_wtypes, x, y)
    draw_wtypes_info(item, x, y + lh)
  end

  #--------------------------------------------------------------------------
  # draw_wtypes_info
  #--------------------------------------------------------------------------
  def draw_wtypes_info(item, x, y)
    lh = line_height
    change_color(normal_color)
    item.equip_wtypes.each_with_index do |wtype_id, i|
      y_plus = lh * (i / col_max)
      x_plus = i % col_max * item_width
      rect = Rect.new(x + x_plus, y + y_plus, width, lh)
      text = $data_system.weapon_types[wtype_id]
      draw_text(rect, text)  
    end
  end
  
  #--------------------------------------------------------------------------
  # draw_equip_atypes_page
  #--------------------------------------------------------------------------
  def draw_equip_atypes_page(item, x, y)
    lh = line_height
    draw_label_text(:equip_atypes, x, y)
    draw_atypes_info(item, x, y + lh)
  end
  
  #--------------------------------------------------------------------------
  # draw_atypes_info
  #--------------------------------------------------------------------------
  def draw_atypes_info(item, x, y)
    lh = line_height
    change_color(normal_color)
    width = contents.width / col_max - 4 - x
    item.equip_atypes.each_with_index do |atype_id, i|      
      y_plus = lh * (i / col_max)
      x_plus = i % col_max * item_width
      rect = Rect.new(x + x_plus, y + y_plus, width, lh)
      text = $data_system.armor_types[atype_id]
      draw_text(rect, text)  
    end
  end
  
  #--------------------------------------------------------------------------
  # draw_equip_types_page
  #--------------------------------------------------------------------------
  def draw_equip_types_page(item, x, y)
    lh = line_height
    draw_label_text(:equip_wtypes, x, y)
    draw_wtypes_info(item, x, y + lh)
    draw_label_text(:equip_atypes, x, y + lh * 5)
    draw_atypes_info(item, x, y + lh * 6)
  end
  

  
  #--------------------------------------------------------------------------
  # draw_sealed_equips_info
  #--------------------------------------------------------------------------
  def draw_sealed_equips_info(item, x, y)
    lh = line_height
    rect = standard_rect(x, y)
    change_color(normal_color)
    item.sealed_equips.each_with_index do |etype_id, i|
      text = Vocab::etype(etype_id) #$$data_system.armor_types[atype_id]
      draw_text(rect, text)
      rect.y += lh
    end
  end
  
  #--------------------------------------------------------------------------
  # draw_equip_slots_page
  #--------------------------------------------------------------------------
  def draw_equip_slots_page(item, x, y)
    lh = line_height
    draw_label_text(:fixed_equips, x, y)
    draw_sealed_equips_info(item, x, y + lh)
    draw_label_text(:sealed_equips, x, y + lh * 5)
    draw_sealed_equips_info(item, x, y + lh * 6)
  end
  
  #--------------------------------------------------------------------------
  # draw_sealed_equips_info
  #--------------------------------------------------------------------------
  def draw_sealed_equips_info(item, x, y)
    lh = line_height
    change_color(normal_color)
    width = contents.width / col_max - 4 - x
    item.fixed_equips.each_with_index do |etype_id, i|
      y_plus = lh * (i / col_max)
      x_plus = i % col_max * item_width
      rect = Rect.new(x + x_plus, y + y_plus, width, lh)
      text = Vocab::etype(etype_id)
      draw_text(rect, text)  
    end
  end
  
  #--------------------------------------------------------------------------
  # draw_bubs_blocking_page
  #--------------------------------------------------------------------------
  def draw_bubs_blocking_page(item, x, y)
    lh = line_height
    draw_label_text(:blocking, x, y)
    draw_bubs_can_block_info(item, x, y)
    draw_label_text(:crit_blocking, x, y + lh)
    draw_bubs_can_crit_block_info(item, x, y + lh)
    draw_bubs_block_param_info(item, x, y + lh * 3)
    draw_label_text(:unblockable, x, y + lh * 8)
    draw_bubs_unblockable_info(item, x, y + lh * 8)
  end
  
  #--------------------------------------------------------------------------
  # draw_bubs_can_block_info
  #--------------------------------------------------------------------------
  def draw_bubs_can_block_info(item, x, y)
    rect = standard_rect(x, y)
    change_color(normal_color)
    text = label_text(:blocking_no)
    text = label_text(:blocking_yes) if item.blocking
    draw_text(rect, text, 2)
  end
  
  #--------------------------------------------------------------------------
  # draw_bubs_can_crit_block_info
  #--------------------------------------------------------------------------
  def draw_bubs_can_crit_block_info(item, x, y)
    rect = standard_rect(x, y)
    change_color(normal_color)
    text = label_text(:blocking_no)
    text = label_text(:blocking_yes) if item.critical_blocking
    draw_text(rect, text, 2)
  end
  
  #--------------------------------------------------------------------------
  # draw_bubs_block_param_info
  #--------------------------------------------------------------------------
  def draw_bubs_block_param_info(item, x, y)
    lh = line_height
    draw_bubs_block_blc_info(item, x, y)
    draw_bubs_block_cbl_info(item, x, y + lh)
    draw_bubs_block_blr_info(item, x, y + lh * 2)
    draw_bubs_block_blv_info(item, x, y + lh * 3)
  end
  
  #--------------------------------------------------------------------------
  # draw_bubs_block_blc
  #--------------------------------------------------------------------------
  def draw_bubs_block_blc_info(item, x, y)
    rect = standard_rect(x, y)
    change_color(system_color)
    text = use_full_param_names? ? Vocab::blc : Vocab::blc_a
    draw_text(rect, text)
    change_color(normal_color)
    text = sprintf("%+.1f%%", item.block_chance)
    draw_text(rect, text, 2)
  end
  
  #--------------------------------------------------------------------------
  # draw_bubs_block_cbl
  #--------------------------------------------------------------------------
  def draw_bubs_block_cbl_info(item, x, y)
    rect = standard_rect(x, y)
    change_color(system_color)
    text = use_full_param_names? ? Vocab::cbl : Vocab::cbl_a
    draw_text(rect, text)
    change_color(normal_color)
    text = sprintf("%+.1f%%", item.critical_block_chance)
    draw_text(rect, text, 2)
  end
  
  #--------------------------------------------------------------------------
  # draw_bubs_block_blr
  #--------------------------------------------------------------------------
  def draw_bubs_block_blr_info(item, x, y)
    rect = standard_rect(x, y)
    change_color(system_color)
    text = use_full_param_names? ? Vocab::blr : Vocab::blr_a
    draw_text(rect, text)
    change_color(normal_color)
    text = sprintf("%+.1f%%", item.block_reduction_rate)
    draw_text(rect, text, 2)
  end
  
  #--------------------------------------------------------------------------
  # draw_bubs_block_blv_info
  #--------------------------------------------------------------------------
  def draw_bubs_block_blv_info(item, x, y)
    rect = standard_rect(x, y)
    change_color(system_color)
    text = use_full_param_names? ? Vocab::blv : Vocab::blv_a
    draw_text(rect, text)
    change_color(normal_color)
    text = sprintf("%d", item.block_value)
    draw_text(rect, text, 2)
  end
  
  #--------------------------------------------------------------------------
  # draw_bubs_unblockable_info
  #--------------------------------------------------------------------------
  def draw_bubs_unblockable_info(item, x, y)
    rect = standard_rect(x, y)
    change_color(normal_color)
    text = label_text(:blocking_no)
    text = label_text(:blocking_yes) if item.unblockable
    draw_text(rect, text, 2)
  end
  
end # class Window_InfoPages

 

Edited by roninator2
added code

Share this post


Link to post
Share on other sites

The Party Guest script looks interesting for a pokemon-like game or a pokemon fanmade : make the mons be your team and the trainer be your guest, coupled with a very basic changing in-battle view system (like Yanfly's Animated Battlers to see your team) and the box-script it could be really easier to do something like that. But with that idea, there is a question : does the guest in the party join the caterpillar ? If yes then it could be possible to set him as the played character in the caterpillar and let your creatures/mons/whatever you want just follow the actor.

Share this post


Link to post
Share on other sites

More Mr. Bubble scripts found.

 

Auto Life Effect

Spoiler

# ╔═══════════════════════════════════════════════════════╤══════╤═══════════╗
# ║ Auto-Life Effect                                      │ v1.9 │ (8/17/12) ║
# ╚═══════════════════════════════════════════════════════╧══════╧═══════════╝
# Script by:
#     Mr. Bubble ( http://mrbubblewand.wordpress.com/ )
# Thanks:
#     Yanfly, script and design references
#     Mithran, regexp examples
#--------------------------------------------------------------------------
# This script is my attempt to replicate the well-known status effect
# "Auto-Life" a.k.a. "Reraise", "Life 3", "Lifeline", etc. in VX Ace.
# Auto-life automatically revives battlers when they are Incapacitated
# in battle.
#
# Be aware that the customization module in this script allows you to
# assign a Game Switch that disables all auto-life effects in-game. This
# is useful for evented battles.
#
# If you experience bug or oddities related to auto-life, please report 
# them to me.
#--------------------------------------------------------------------------
#   ++ Changelog ++
#--------------------------------------------------------------------------
# v1.9 : Actors, Classes and Enemies can now have autolife tags. 
#      : Efficiency update. (8/17/2012)
# v1.8 : Removed debug remnant. (7/12/2012)
# v1.7 : Fixed F8 crash with YEA Battle Engine. (7/12/2012)
# v1.6 : Fixed a typo which caused an error. (7/12/2012)
# v1.5 : 'Attack Times+' issues should be fixed now. 
#      : New option added in customization module.
#      : Auto-life checks are now also done at the end of turn. (7/11/2012)
# v1.4 : Compatibility update for 'Guts Effects' (7/11/2012)
# v1.3 : Efficiency update. (7/11/2012)
# v1.2 : autolifeable flags are now reset before each battle. (7/10/2012)
# v1.1 : DISABLE_AUTOLIFE_SWITCH_ID should now work. (7/10/2012)
# v1.0 : Initial release. (7/10/2012)
#--------------------------------------------------------------------------
#   ++ Installation ++
#--------------------------------------------------------------------------
# Install this script in the Materials section in your project's
# script editor.
#
# Install this script below any scripts that modify the default 
# battle system in you script editor.
#=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
#   ++ Notetags ++
#=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
# Note: Some tags are given shorter tags for typing convenience. You only
#       need to use one <tag> from a given group for a notebox.
#       Use common sense.
#
# The following Notetags are for Actors, Classes, States, Weapons, Armors,
# and Enemies:
#
# <autolife>
#   This tag provides an in-battle auto-life effect to the state or equipment. 
#   This tag will use all default auto-life values as defined in the 
#   customization module in this script.
#     
# <custom autolife>
# setting
# setting
# </custom autolife>
#   This tag allows you create auto-life equipment and states with custom
#   values. You can add as many settings between the <custom> tags as you
#   like. Any settings you do not include will use the default values
#   defined in the customization module. The following settings are available:
#   
#     chance: n%
#       This setting defines the chance of auto-life triggering when
#       the battler dies where n is a percentage value between 0.1 ~ 100.0.
#       
#     hp recovery: n%
#     hp: n%
#       This setting defines the amount of HP the battler recovers when
#       auto-life is triggered where n is the percentage rate recovered
#       based on MAX HP. If set to 0%, the battler will regain at least
#       1 HP.
#       
#     mp recovery: n%
#     mp: n%
#       This setting defines the amount of MP the battler recovers when
#       auto-life is triggered where n is the percentage rate recovered
#       based on MAX MP.
#       
#     animation id: id
#     ani id: id
#       This setting defines the database animation used on the battler
#       when auto-life is triggered where id is the animation ID number
#       found in your database.
#       
#     break: n%
#       This setting defines the chance of the piece of equipment breaking
#       when auto-life is triggered where n is a percentage value between 
#       0.0 ~ 100.0. This setting is only for equipment.
#       
# Here is an example of a custom autolife tag:
#
#   <custom autolife>
#   chance: 50%
#   hp: 5%
#   ani id: 41
#   </custom autolife>
#
# The settings "mp recovery" and "break" would use their default values 
# since they are not included in this example tag.
#--------------------------------------------------------------------------
#   ++ Compatibility ++
#--------------------------------------------------------------------------
# This script has built-in compatibility with the following scripts:
#
#     -Guts Effect
#     -YEA Battle Engine
#
# This script aliases the following default VXA methods:
#
#     BattleManager#judge_win_loss
#     Game_BattlerBase#initialize
#     Game_Battler#on_battle_end
#     Game_Battler#on_battle_start
#     Game_Battler#die
#     Scene_Battle#process_action
#     Scene_Battle#process_action_end
#     Scene_Battle#turn_end
#    
# There are no default method overwrites.
#
# Requests for compatibility with other scripts are welcome.
#--------------------------------------------------------------------------
#      Compatibility Notes
#--------------------------------------------------------------------------
# If 'Auto-Life Effects' and 'Guts Effects' are installed in the same
# project, auto-life effects will always take precdence over guts
# effects.
#--------------------------------------------------------------------------
#   ++ Terms and Conditions ++
#--------------------------------------------------------------------------
# Please do not repost this script elsewhere without permission. 
# Free for non-commercial use. For commercial use, contact me first.
#
# Newest versions of this script can be found at 
#                                           http://mrbubblewand.wordpress.com/
#==============================================================================

$imported ||= {}
$imported["BubsAutoLife"] = true

#==========================================================================
# ++ START OF USER CUSTOMIZATION MODULE ++
#==========================================================================
module Bubs
  #==========================================================================
  # ++ Auto-Life Settings
  #==========================================================================
  module AutoLife
  #--------------------------------------------------------------------------
  #   Disable Auto-life Switch ID Setting     !! IMPORTANT SETTING !!
  #--------------------------------------------------------------------------
  # This setting defines the switch ID number used to determine if revival 
  # by auto-life is allowed in battle. This is useful for evented battles and
  # such. If the ID is set to 0, no game switches will be used.
  #
  # If the switch is ON, all auto-life effects are disabled.
  # If the switch is OFF, any auto-life effects are allowed.
  DISABLE_AUTOLIFE_SWITCH_ID = 0
  
  #--------------------------------------------------------------------------
  #   Default Auto-life Settings
  #--------------------------------------------------------------------------
  # These settings determine the default values for auto-life effects on
  # equipment and states.  
  AUTOLIFE_DEFAULTS = {
    :hp_rate  => 10.0,  # HP Recovery Rate (%)
    :mp_rate  => 10.0,  # MP Recovery Rate (%)
    :chance   => 100.0, # Auto-life chance (%)
    :break    => 100.0, # Item break chance, equipment only (%)
    :ani_id   => 42,    # Animation ID number
  } # <-- Do not delete.
  
  #--------------------------------------------------------------------------
  #   Check Auto-life Triggers After Each Action
  #--------------------------------------------------------------------------
  # true  : Auto-life checks can be done after each complete action.
  # false : Auto-life checks are done only at the end of turn.
  CHECK_AFTER_EACH_ACTION = true
  
  #--------------------------------------------------------------------------
  #   Auto-life Effect Text Setting
  #--------------------------------------------------------------------------
  # This setting defines the battle message that displays when auto-life 
  # successfuly triggers.
  #
  # %s is automatically replaced by the battler's name. 
  AUTOLIFE_EFFECT_TEXT = "%s's got a second wind!"
  
  #--------------------------------------------------------------------------
  #   Item Break Text Setting
  #--------------------------------------------------------------------------
  # This determines the message that displays when an item breaks after
  # triggering auto-life
  #
  # The first %s is automatically replaced by the battler's name. 
  # The second %s is automatically replaced by the item's name.
  ITEM_BREAK_TEXT = "%s's %s breaks!"
  
  #--------------------------------------------------------------------------
  #   Item Break Sound Effect Setting
  #--------------------------------------------------------------------------
  # This setting defines the sound effect used when the Item Break Text
  # is displayed in-battle.
  #
  #                "filename", Volume, Pitch
  ITEM_BREAK_SE = [ "Attack2",     80,   100]
  
  end # module AutoLife
end # module Bubs

#==========================================================================
# ++ END OF USER CUSTOMIZATION MODULE ++
#==========================================================================



#==============================================================================
# ++ Vocab
#==============================================================================
module Vocab
  AutoLifeItemBreak = Bubs::AutoLife::ITEM_BREAK_TEXT
  AutoLifeEffect = Bubs::AutoLife::AUTOLIFE_EFFECT_TEXT
end # module Vocab

#==============================================================================
# ++ Sound
#==============================================================================
module Sound
  def self.play_autolife_item_break
    file = Bubs::AutoLife::ITEM_BREAK_SE[0]
    volume = Bubs::AutoLife::ITEM_BREAK_SE[1]
    pitch = Bubs::AutoLife::ITEM_BREAK_SE[2]
    Audio.se_play("/Audio/SE/" + file, volume, pitch) 
  end
end # module Sound


#==========================================================================
# ++ DataManager
#==========================================================================
module DataManager
  #--------------------------------------------------------------------------
  # alias : load_database
  #--------------------------------------------------------------------------
  class << self; alias load_database_bubs_autolife load_database; end
  def self.load_database
    load_database_bubs_autolife # alias
    load_notetags_bubs_autolife
  end
  
  #--------------------------------------------------------------------------
  # new method : load_notetags_bubs_autolife
  #--------------------------------------------------------------------------
  def self.load_notetags_bubs_autolife
    groups = [$data_weapons, $data_armors, $data_states, $data_classes,
              $data_actors, $data_enemies]
    for group in groups
      for obj in group
        next if obj.nil?
        obj.load_notetags_bubs_autolife
      end # for obj
    end # for group
  end # def
  
end # module DataManager


#==========================================================================
# ++ BattleManager
#==========================================================================
module BattleManager
  class << self; alias judge_win_loss_bubs_autolife judge_win_loss; end
  #--------------------------------------------------------------------------
  # alias : judge_win_loss
  #--------------------------------------------------------------------------
  def self.judge_win_loss
    if @phase
      return process_abort   if aborting?
      return false           if autolifeable_members
    end
    judge_win_loss_bubs_autolife # alias
  end
  
  #--------------------------------------------------------------------------
  # new method : autolifeable_members
  #--------------------------------------------------------------------------
  def self.autolifeable_members
    $game_party.battle_members.each do |actor|
      return true if actor.autolifeable
    end
    
    $game_troop.members.each do |enemy|
      return true if enemy.autolifeable
    end
    
    return false
  end # self
  
end # module BattleManager


#==========================================================================
# ++ Bubs::Regexp
#==========================================================================
module Bubs
  module Regexp
    AUTOLIFE_TAG           = /<AUTO[\s-]?LIFE>/i
    AUTOLIFE_START_TAG     = /<CUSTOM[\s]?AUTO[\s-]?LIFE>/i
    AUTOLIFE_END_TAG       = /<\/CUSTOM[\s]?AUTO[\s-]?LIFE>/i
    AUTOLIFE_CHANCE_TAG    = /CHANCE:\s*([+]?\d+\.?\d*)[%%]?/i
    AUTOLIFE_BREAK_TAG     = /BREAK:\s*([+]?\d+\.?\d*)[%%]?/i
    AUTOLIFE_HP_TAG        = /HP\s*(?:RECOVERY)?:\s*([+]?\d+\.?\d*)[%%]?/i
    AUTOLIFE_MP_TAG        = /MP\s*(?:RECOVERY)?:\s*([+]?\d+\.?\d*)[%%]?/i
    AUTOLIFE_ANIMATION_TAG = /(?:ANIMATION|ANI)\s*(?:ID)?:\s*(\d+)/i
  end # module Regexp
end # module Bubs


#==========================================================================
# ++ RPG::BaseItem
#==========================================================================
# A superclass of actor, class, skill, item, weapon, armor, enemy, and state.
class RPG::BaseItem
  #--------------------------------------------------------------------------
  # public instance variables
  #--------------------------------------------------------------------------
  attr_accessor :autolife
  attr_accessor :autolife_chance
  attr_accessor :autolife_hp_recovery_rate
  attr_accessor :autolife_mp_recovery_rate
  attr_accessor :autolife_animation_id
  attr_accessor :autolife_break_chance
  #--------------------------------------------------------------------------
  # common cache : load_notetags_bubs_autolife
  #--------------------------------------------------------------------------
  def load_notetags_bubs_autolife
    @autolife = false
    @autolife_chance           = Bubs::AutoLife::AUTOLIFE_DEFAULTS[:chance]
    @autolife_break_chance     = Bubs::AutoLife::AUTOLIFE_DEFAULTS[:break]
    @autolife_hp_recovery_rate = Bubs::AutoLife::AUTOLIFE_DEFAULTS[:hp_rate]
    @autolife_mp_recovery_rate = Bubs::AutoLife::AUTOLIFE_DEFAULTS[:mp_rate]
    @autolife_animation_id     = Bubs::AutoLife::AUTOLIFE_DEFAULTS[:ani_id]
    
    autolife_tag = false

    self.note.split(/[\r\n]+/).each { |line|
      case line
      when Bubs::Regexp::AUTOLIFE_TAG
        @autolife = true
        
      when Bubs::Regexp::AUTOLIFE_START_TAG
        @autolife = true
        autolife_tag = true
        
      when Bubs::Regexp::AUTOLIFE_END_TAG
        autolife_tag = false
        
      else
        next unless autolife_tag
        case line.upcase
        
        when Bubs::Regexp::AUTOLIFE_CHANCE_TAG
          @autolife_chance = $1.to_f
          
        when Bubs::Regexp::AUTOLIFE_BREAK_TAG
          @autolife_break_chance = $1.to_f
          
        when Bubs::Regexp::AUTOLIFE_HP_TAG
          @autolife_hp_recovery_rate = $1.to_f
          
        when Bubs::Regexp::AUTOLIFE_MP_TAG
          @autolife_mp_recovery_rate = $1.to_f
          
        when Bubs::Regexp::AUTOLIFE_ANIMATION_TAG
          @autolife_animation_id = $1.to_i

        end # case
      end # else
      
    } # self.note.split
  end # def
  
end # RPG::BaseItem


#==============================================================================
# ++ Window_BattleLog
#==============================================================================
class Window_BattleLog < Window_Selectable  
  #--------------------------------------------------------------------------
  # new method : display_guts_text
  #--------------------------------------------------------------------------
  def display_autolife_text(target)
    add_text(sprintf(Vocab::AutoLifeEffect, target.name))
    wait
  end # def display_guts_text
  
  #--------------------------------------------------------------------------
  # new method : display_autolife_item_break_text
  #--------------------------------------------------------------------------
  def display_autolife_item_break_text(target, item)
    Sound.play_autolife_item_break
    add_text(sprintf(Vocab::AutoLifeItemBreak, target.name, item.name))
    wait
  end # def display_guts_text
end # class Window_BattleLog


#==========================================================================
# ++ Game_BattlerBase
#==========================================================================
class Game_BattlerBase
  #--------------------------------------------------------------------------
  # public instance variables
  #--------------------------------------------------------------------------
  attr_accessor :autolifeable         # autolife check flag
  attr_accessor :autolife_state_id    # save state id before actor dies
  #--------------------------------------------------------------------------
  # alias : initialize
  #--------------------------------------------------------------------------
  alias initialize_bubs_autolife initialize
  def initialize
    initialize_bubs_autolife # alias
    
    @autolifeable = false
    @autolife_state_id = 0
  end
end # class Game_BattlerBase


#==============================================================================
# ++ Game_Battler
#==============================================================================
class Game_Battler < Game_BattlerBase
  #--------------------------------------------------------------------------
  # alias : die
  #--------------------------------------------------------------------------
  alias die_bubs_autolife die
  def die
    @autolifeable = true
    @autolife_state_id = determine_autolife_state_id
    
    die_bubs_autolife # alias
  end # def die
  
  #--------------------------------------------------------------------------
  # alias : on_battle_end
  #--------------------------------------------------------------------------
  alias on_battle_end_bubs_autolife on_battle_end
  def on_battle_end
    @autolifeable = false
    
    on_battle_end_bubs_autolife # alias
  end # def on_battle_end
  
  #--------------------------------------------------------------------------
  # alias : on_battle_start
  #--------------------------------------------------------------------------
  alias on_battle_start_bubs_autolife on_battle_start
  def on_battle_start
    @autolifeable = false
    
    on_battle_start_bubs_autolife # alias
  end # def on_battle_start

  #--------------------------------------------------------------------------
  # new method : determine_autolife_obj
  #--------------------------------------------------------------------------
  def determine_autolife_obj
    # States
    if @autolife_state_id != 0
      id = @autolife_state_id
      @autolife_state_id = 0
      return $data_states[id]
    end
    
    if actor?
      return self.actor if activate_autolife?(self.actor)
      return self.class if activate_autolife?(self.class)
      # Actor equips
      for equip in equips
        next if equip.nil?
        return equip if activate_autolife?(equip)
      end # for

    else
      return self.enemy if activate_autolife?(self.enemy)
    end
    
    return nil
  end # def determine_autolife_obj
  
  #--------------------------------------------------------------------------
  # new method : determine_autolife_state_id
  #--------------------------------------------------------------------------
  # All states are wiped out upon dying so this method returns
  # the id number of the state that successfully triggers autolife.
  def determine_autolife_state_id
    for state in states
      next if state.nil?
      return state.id if activate_autolife?(state)
    end # for
    return 0
  end
  
  #--------------------------------------------------------------------------
  # new method : apply_autolife_effects
  #--------------------------------------------------------------------------
  def apply_autolife_effects(item)
    revive
    autolife_recovery(item)
    remove_autolife_state(item)
  end
  
  #--------------------------------------------------------------------------
  # new method : remove_autolife_item
  #--------------------------------------------------------------------------
  def remove_autolife_item(item)
    return unless actor?
    discard_equip(item) if item.is_a?(RPG::EquipItem)
  end
  
  #--------------------------------------------------------------------------
  # new method : remove_autolife_state
  #--------------------------------------------------------------------------
  def remove_autolife_state(item)
    remove_state(item.id) if item.is_a?(RPG::State)
  end
  
  #--------------------------------------------------------------------------
  # new method : autolife_recovery
  #--------------------------------------------------------------------------
  def autolife_recovery(item)
    self.hp += (mhp * (item.autolife_hp_recovery_rate * 0.01)).to_i
    self.mp += (mmp * (item.autolife_mp_recovery_rate * 0.01)).to_i
  end

  #--------------------------------------------------------------------------
  # new method : autolife_disabled?
  #--------------------------------------------------------------------------
  def autolife_disabled?
    return false
  end
  
  #--------------------------------------------------------------------------
  # new method : activate_autolife?
  #--------------------------------------------------------------------------
  def activate_autolife?(item)
    return false unless item.autolife
    rand < (item.autolife_chance * 0.01)
  end

end # class Game_Battler


#==============================================================================
# ++ Scene_Battle
#==============================================================================
class Scene_Battle < Scene_Base
  #--------------------------------------------------------------------------
  # alias : process_action
  #--------------------------------------------------------------------------
  alias process_action_bubs_autolife process_action
  def process_action
    process_action_bubs_autolife # alias
    
    # process_action_end never gets called if the last party member is
    # killed by an enemy with more Action Time+ actions in queue.
    # This clears all actions of all battlers 
    if !@subject.nil? 
      if @subject.current_action && $game_party.all_dead?
        all_battle_members.each do |battler|
          battler.clear_actions
        end
      end
    end
  end # def process_action

  #--------------------------------------------------------------------------
  # alias : process_action_end
  #--------------------------------------------------------------------------
  alias process_action_end_bubs_autolife process_action_end
  def process_action_end
    if Bubs::AutoLife::CHECK_AFTER_EACH_ACTION
      process_autolife_check
    end
    
    process_action_end_bubs_autolife # alias
  end # def process_action_end
  
  #--------------------------------------------------------------------------
  # alias : turn_end
  #--------------------------------------------------------------------------
  alias turn_end_bubs_autolife turn_end
  def turn_end
    process_autolife_check
    
    turn_end_bubs_autolife # alias
  end # def turn_end
   
  #--------------------------------------------------------------------------
  # new method : process_autolife_check
  #--------------------------------------------------------------------------
  def process_autolife_check
    all_battle_members.each do |battler|
      determine_autolife(battler)
      determine_guts(battler) if $imported["BubsGuts"]
    end
  end # def process_autolife_check
  
  #--------------------------------------------------------------------------
  # new method : determine_autolife
  #--------------------------------------------------------------------------
  def determine_autolife(battler)
    return unless battler.autolifeable
    battler.autolifeable = false
    return if $game_switches[Bubs::AutoLife::DISABLE_AUTOLIFE_SWITCH_ID]
    return unless battler.dead?
    return if battler.autolife_disabled?
    obj = battler.determine_autolife_obj
    return if obj.nil?
    
    @log_window.clear
    # Display general autolife text
    @log_window.display_autolife_text(battler)
    # Heal battler
    battler.apply_autolife_effects(obj)
    @status_window.refresh
    # Play animation on battler
    show_animation([battler], obj.autolife_animation_id)
    determine_autolife_item_break(battler, obj)
    
    wait(35)
    @log_window.clear
  end # def apply_guts_effects
  
  #--------------------------------------------------------------------------
  # new method : determine_autolife_item_break
  #--------------------------------------------------------------------------
  def determine_autolife_item_break(battler, item)
    return unless item.is_a?(RPG::EquipItem) 
    return unless (rand < (item.autolife_break_chance * 0.01))
    @log_window.display_autolife_item_break_text(battler, item)
    battler.discard_equip(item)
  end
  
  #--------------------------------------------------------------------------
  # new method : clear_all_autolifeable_flags
  #--------------------------------------------------------------------------
  def clear_all_autolifeable_flags
    all_battle_members.each do |member|
      member.autolifeable = false
    end
  end

  if $imported["YEA-BattleEngine"]
  #--------------------------------------------------------------------------
  # alias : debug_kill_all
  #--------------------------------------------------------------------------
  alias debug_kill_all_bubs_autolife debug_kill_all
  def debug_kill_all
    debug_kill_all_bubs_autolife # alias
    
    clear_all_autolifeable_flags
  end
  end # if $imported["YEA-BattleEngine"]
  
end # class Scene_Battle

 

 

Bow attack action sequence RPG Tankentai sideview battle system

Spoiler

#============================================================================== 
# + Bow Attack Action Sequence for RPG Tankentai Sideview Battle System 
#   v2.0 (Kaduki) 
#------------------------------------------------------------------------------ 
#  Script by Mr. Bubble 
#------------------------------------------------------------------------------ 
# ++ How to Install 
# * Install below the Tankentai Sideview scripts 
# * Requires Animation 83 from the demo placed in the same ID in your project. 
#   Animation ID can be changed. 
#============================================================================== 
# ++ Assigning a Bow Action to Skills and Weapons 
# 
#   [With Notetag] 
# * In the Notes field of a skill or weapon, type in 
# 
#               <action: BOW_ATTACK> 
# 
#   You do not need quotes around BOW_ATTACK. Remember that it requires  
#   Bubs' Notetags for TSBS. 
# 
#   [Battler Configuration] 
# * Assign "BOW_ATTACK" to a weapon or skill under  
#   Weapon Action Sequence Settings and Skill Action Sequence Settings in 
#   the SBS Configurations script. 
#============================================================================== 

module N01 
  # Animation ID for when bow is shown and drawn 
  BOW_ANIMATION = 94 
#------------------------------------------------------------------------------ 
  BOW_ANIME = { 
   
   
  # "DRAW_POSE" is a Battler Frame Animation key. 
  # It will play a specific animation from the battler's character sheet. 
  # For Kaduki Battlers, it will play its own special row. 
  # If an enemy tries to use this key, it will not do anything. 
  "DRAW_POSE"      => [ 3,  1,  3,   2,   0,  -1,   0, true,"" ], 
     
  # "DRAW_BOW" is a Battle Animation key. 
  # It plays the bow animation from the Database on top of the battler 
  # using this key. 
  "DRAW_BOW"  => ["anime",  BOW_ANIMATION,  0, false, false, false], 
     
  # "ARROW_ANGLE" is a Flying Graphic Angle key. 
  # It modifies the angle of the arrow when it travels from the user to 
  # the target. "ARROW_ANGLE" is not directly used within an action sequence. 
  # Instead, it is used in the "SHOOT_ARROW" hash. 
  "ARROW_ANGLE"     => [ 30, 60,  11], 
     
  # "SHOOT_ARROW" is a Moving Animation key 
  # It defines the trajectory of the arrow that is shot at the target. 
  # Notice how "ARROW_ANGLE" is used within the hash. "ARROW_ANGLE" 
  # is a set predefined values that determine the angle of the arrow 
  # while in flight. 
  # The Yp (Y-pitch) needed to be moved up 16 pixels so it wouldn't look 
  # like an actor shot an arrow from their legs. 
  # ANIME Key               Type   ID Object Pass Time Arc  Xp Yp Start Z Weapon 
  "SHOOT_ARROW"  => ["m_a", 0,  0,   0, 15,  -10,  0, -16, 0,false,"ARROW_ANGLE"],
     
  } # <-- Do not delete this! 
  ANIME.merge!(BOW_ANIME) 
   
  # Action Sequence 
  BOW_ATTACK_ACTION = { 
  # To help explain what the "BOW_ATTACK" sequence does, I've formatted it as 
  # a vertical list. It does not matter how much whitespace there is between 
  # each key as long as there are commas separating each key from each other. 
  #  
  # Beside each key is a comment briefly explaining what each key does. 
  # Keep in mind that action sequences are processed from left to right,  
  # top to bottom, in order. 
   
  # Action Key 
  "BOW_ATTACK" => [ # Anime Keys 
                  "STEP_FORWARD", # Battler steps forward a bit 
                  "DRAW_BOW",     # Battler plays bow animation on self 
                  "DRAW_POSE",    # Play Kaduki pose 
                  "16",           # Delays the sequence for 16 frames 
                  "SHOOT_ARROW",  # Executes arrow projectile to target 
                  "12",           # Delays the sequence for 12 frames 
                  "DAMAGE_ANIM",  # Damage the target and play the weapon 
                                  # skill's animation (if it hits) 
                  "16",           # Delays the sequence for 12 frames 
                  "Can Collapse", # Determines if battler is at 0 HP 
                                  # and turns off their immortal flag so 
                                  # that they can die/collapse. 
                  "FLEE_RESET"    # Reset battler to start coordinates 
                  ], # Closing square bracket. Don't forgot the comma! 
   "DOUBLE_STRAFE" => [ # Anime Keys 
                  "Afterimage ON", 
                  "STEP_FORWARD", # Battler steps forward a bit 
                  "CAST_PHYS_AN", # Cast Physical Animation 
                  "40", 
                  "BB_TINT_SKILL", 
                  "20", 
                  "DRAW_BOW",     # Battler plays bow animation on self 
                  "DRAW_POSE",    # Play Kaduki pose 
                  "10",           # Delays the sequence for 16 frames 
                  "SHOOT_ARROW",  # Executes arrow projectile to target 
                  "6",           # Delays the sequence for 12 frames 
                  "DRAW_BOW",     # Battler plays bow animation on self 
                  "DRAW_POSE",    # Play Kaduki pose 
                  "SHAKE_SCREEN_MILD", 
                  "DAMAGE_ANIM",  # Damage the target and play the weapon 
                                  # skill's animation (if it hits) 
                   "5",           # Delays the sequence for 12 frames 
                  "SHOOT_ARROW",  # Executes arrow projectile to target 
                  "12",           # Delays the sequence for 12 frames 
                  "SHAKE_SCREEN_MILD", 
                  "DAMAGE_ANIM",  # Damage the target and play the weapon 
                                  # skill's animation (if it hits) 
                  "16",           # Delays the sequence for 12 frames 
                  "Can Collapse", # Determines if battler is at 0 HP 
                                  # and turns off their immortal flag so 
                                  # that they can die/collapse. 
                  "BB_TINT_NORMAL", 
                  "Afterimage OFF", 
                  "FLEE_RESET"    # Reset battler to start coordinates 
                  ], # Closing square bracket. Don't forgot the comma! 
  } # <-- Do not delete this! 
  ACTION.merge!(BOW_ATTACK_ACTION) 
end 

 

 

Gender Functions

Spoiler

# ╔═══════════════════════════════════════════════════════╤══════╤═══════════╗
# ║ Gender Functions                                      │ v1.2 │ (1/06/12) ║
# ╚═══════════════════════════════════════════════════════╧══════╧═══════════╝
# Script by:
#     Mr. Bubble ( http://mrbubblewand.wordpress.com/ )
# Thanks:
#     Yanfly, script and design references
#--------------------------------------------------------------------------
# This is a simple script that provides developers the option to define the
# gender of Actors and Enemies in their game. With the use of script calls
# and new methods, this opens up a variety of options for eventers and 
# scripters alike.
#--------------------------------------------------------------------------
# ++ Changelog ++
#--------------------------------------------------------------------------
# v1.2 : Efficency update. (1/06/12)
# v1.1 : Enemies should now use the proper default gender value. (1/04/12)
# v1.0 : Initial release. (1/04/12)
#--------------------------------------------------------------------------
# ++ Installation ++
#--------------------------------------------------------------------------
# Install this script in the Materials section in your project's
# script editor.
#=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
# ++ Notetags ++
#=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
# The following notetags are for Actors and Enemies only:
# 
# <gender: none>
# <gender: genderless>
#   Defines the Actor or Enemy as genderless. The internal value that 
#   represents genderless is 0.
#   
# <gender: m>
# <gender: male>
#   Defines the Actor or Enemy as male. The internal value that
#   represents male is 1.
#   
# <gender: f>
# <gender: female>
#   Defines the Actor or Enemy as female. The internal value that
#   represents female is 2.
#
#=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
# ++ Conditional Branch Script Calls ++
#=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
# The following script calls are meant to be used in Conditional
# Branch event commands within the Tab 4 "Script" box.
# Each of these script calls will turn the given Game Switch ON
# or OFF, where ON is true and OFF is false.
#
# leader_genderless?
# leader_male?
# leader_female?
#   These script calls check the gender of the party leader.
#
# party_member_genderless?(index)
# party_member_male?(index)
# party_member_female?(index)
#   These script calls check the gender of the given party member
#   where index is the party position index. 0 is the party leader,
#   1 is the 2nd member, 2 is the 3rd member, etc.
#
# actor_genderless?(id)
# actor_male?(id)
# actor_female?(id)
#   These script calls check an actor's gender where id is an
#   actor id from the Database. These can check the gender of actors
#   not in the current party.
#
# battle_party_all_genderless?
# battle_party_all_male?
# battle_party_all_female?
#   These script calls check if all members in the battle party
#   have matching genders.
#
# troop_enemy_genderless?(index)
# troop_enemy_male?(index)
# troop_enemy_female?(index)
#   These script calls check the gender of the given enemy in the 
#   current troop where index is the enemy's troop position index. 
#   0 is the first enemy, 1 is the 2nd enemy, 2 is the 3rd enemy, 
#   etc. This script call only works in-battle.
#   
# enemy_genderless?(id)
# enemy_male?(id)
# enemy_female?(id)
#   These script calls check an enemy's gender where id is an
#   enemy id from the Database. These can check the gender of enemies
#   even when not in battle.
#=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
# ++ Variable Operation Script Calls ++
#=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
# The following script calls are meant to be used in Variable 
# Operation event commands within the "Script" box.
# Each of these script calls return a number which is then
# stored into the given Game Variable.
#
# all_party_genderless_count
# all_party_male_count
# all_party_female_count
#   These script calls count the number of party members that has
#   a specified gender and stores the number into the given
#   Game Variable. This includes both battle and reserve members
#   in the party.
#
# battle_party_genderless_count
# battle_party_male_count
# battle_party_female_count
#   These script calls count the number of battle members in the 
#   party that has a specified gender and stores the number 
#   into the given Game Variable. This does not include reserve members.
# 
# reserve_party_genderless_count
# reserve_party_male_count
# reserve_party_female_count
#   These script calls count the number of reserve members in the 
#   party that has a specified gender and stores the number 
#   into the given Game Variable. This does not include battle members.
#--------------------------------------------------------------------------
# ++ Compatibility ++
#--------------------------------------------------------------------------
# This script does not overwrite any default VXA methods. All default
# methods modified in this script are aliased.
#
# Requests for compatibility with other scripts are welcome.
#--------------------------------------------------------------------------
# ++ Terms and Conditions ++
#--------------------------------------------------------------------------
# Please do not repost this script elsewhere without permission. Newest 
# versions of this script can be found at http://mrbubblewand.wordpress.com/
#==========================================================================

$imported = {} if $imported.nil?
$imported["BubsGenderFunctions"] = true
  
#==========================================================================
# ++ START OF USER CUSTOMIZATION MODULE ++
#==========================================================================

module Bubs
  module GenderFunctions
  #--------------------------------------------------------------------------
  # Default Gender Settings
  #--------------------------------------------------------------------------
  # The values below will determine the default gender for actors and
  # enemies if a notetag is not found.
  #     0 : Genderless
  #     1 : Male
  #     2 : Female
  DEFAULT_ACTOR_GENDER = 0    # Actors
  DEFAULT_ENEMY_GENDER = 0    # Enemies
  
  end # module GenderFunctions
end # module Bubs
  
#==========================================================================
# ++ END OF USER CUSTOMIZATION MODULE ++
#==========================================================================


#==========================================================================
# ++ Bubs::Regexp
#==========================================================================
module Bubs
  module Regexp
    GENDER_NONE = /<(?:GENDER|sex):\s*(?:NONE|genderless)>/i
    GENDER_MALE = /<(?:GENDER|sex):\s*(?:M|male)>/i
    GENDER_FEMALE = /<(?:GENDER|sex):\s*(?:F|female)>/i
  end
end # module Bubs


#==========================================================================
# ++ DataManager
#==========================================================================
module DataManager
  #--------------------------------------------------------------------------
  # alias : load_database
  #--------------------------------------------------------------------------
  class << self; alias load_database_bubs_gender_func load_database; end
  def self.load_database
    load_database_bubs_gender_func # alias
    load_notetags_bubs_gender_func
  end
  
  #--------------------------------------------------------------------------
  # new method : load_notetags_bubs_gender_func
  #--------------------------------------------------------------------------
  def self.load_notetags_bubs_gender_func
    groups = [$data_actors, $data_enemies]
    for group in groups
      for obj in group
        next if obj.nil?
        obj.load_notetags_bubs_gender_func
      end # for
    end # for
  end # def
  
end # module DataManager


#==========================================================================
# ++ RPG::BaseItem
#==========================================================================
class RPG::BaseItem
  #--------------------------------------------------------------------------
  # public instance variables
  #--------------------------------------------------------------------------
  attr_accessor :gender
  
  #--------------------------------------------------------------------------
  # common cache : load_notetags_bubs_gender_func
  #--------------------------------------------------------------------------
  def load_notetags_bubs_gender_func
    if self.is_a?(RPG::Actor)
      @gender = Bubs::GenderFunctions::DEFAULT_ACTOR_GENDER
    else
      @gender = Bubs::GenderFunctions::DEFAULT_ENEMY_GENDER
    end
    
    self.note.split(/[\r\n]+/).each { |line|
      case line
      when Bubs::Regexp::GENDER_NONE
        @gender = 0
      when Bubs::Regexp::GENDER_MALE
        @gender = 1
      when Bubs::Regexp::GENDER_FEMALE
        @gender = 2
      end
    } # self.note.split
    
  end # def
end # class RPG::BaseItem


#==========================================================================
# ++ Game_BattlerBase
#==========================================================================
class Game_BattlerBase
  #--------------------------------------------------------------------------
  # new method : genderless?
  #--------------------------------------------------------------------------
  def genderless?
    if actor?
      return true if self.actor.gender == 0
    else
      return true if self.enemy.gender == 0
    end
    return false
  end
  #--------------------------------------------------------------------------
  # new method : male?
  #--------------------------------------------------------------------------
  def male?
    if actor?
      return true if self.actor.gender == 1
    else
      return true if self.enemy.gender == 1
    end
    return false
  end
  #--------------------------------------------------------------------------
  # new method : male?
  #--------------------------------------------------------------------------
  def female?
    if actor?
      return true if self.actor.gender == 2
    else
      return true if self.enemy.gender == 2
    end
    return false  
  end
end # class Game_BattlerBase


module Bubs
  module GenderFunctions
  module ScriptCalls
  #--------------------------------------------------------------------------
  # new method : leader_genderless?
  #--------------------------------------------------------------------------
  def leader_genderless?
    leader = $game_party.leader
    return leader.genderless? unless leader.nil?
    return false
  end
  #--------------------------------------------------------------------------
  # new method : leader_male?
  #--------------------------------------------------------------------------
  def leader_male?
    leader = $game_party.leader
    return leader.male? unless leader.nil?
    return false
  end
  #--------------------------------------------------------------------------
  # new method : leader_female?
  #--------------------------------------------------------------------------
  def leader_female?
    leader = $game_party.leader
    return leader.female? unless leader.nil?
    return false  
  end
  #--------------------------------------------------------------------------
  # new method : party_member_genderless?
  #--------------------------------------------------------------------------
  def party_member_genderless?(index)
    member = $game_party.members[index]
    return member.genderless? unless member.nil?
    return false
  end
  #--------------------------------------------------------------------------
  # new method : party_member_male?
  #--------------------------------------------------------------------------
  def party_member_male?(index)
    member = $game_party.members[index]
    return member.male? unless member.nil?
    return false
  end
  #--------------------------------------------------------------------------
  # new method : party_member_female?
  #--------------------------------------------------------------------------
  def party_member_female?(index)
    member = $game_party.members[index]
    return member.female? unless member.nil?
    return false
  end
  #--------------------------------------------------------------------------
  # new method : actor_genderless?
  #--------------------------------------------------------------------------
  def actor_genderless?(id)
    actor = $game_actors[id]
    return actor.genderless? unless actor.nil?
    return false
  end
  #--------------------------------------------------------------------------
  # new method : actor_male?
  #--------------------------------------------------------------------------
  def actor_male?(id)
    actor = $game_actors[id]
    return actor.male? unless actor.nil?
    return false  
  end
  #--------------------------------------------------------------------------
  # new method : actor_female?
  #--------------------------------------------------------------------------
  def actor_female?(id)
    actor = $game_actors[id]
    return actor.female? unless actor.nil?
    return false  
  end
  #--------------------------------------------------------------------------
  # new method : battle_party_all_genderless?
  #--------------------------------------------------------------------------
  def battle_party_all_genderless?
    count = 0
    for member in $game_party.battle_members
      next if member.nil?
      count += 1 if member.genderless?
    end
    return true if count == $game_party.max_battle_members
    return false
  end
  #--------------------------------------------------------------------------
  # new method : battle_party_all_male?
  #--------------------------------------------------------------------------
  def battle_party_all_male?
    count = 0
    for member in $game_party.battle_members
      next if member.nil?
      count += 1 if member.male?
    end
    return true if count == $game_party.max_battle_members
    return false
  end
  #--------------------------------------------------------------------------
  # new method : battle_party_all_female?
  #--------------------------------------------------------------------------
  def battle_party_all_female?
    count = 0
    for member in $game_party.battle_members
      next if member.nil?
      count += 1 if member.female?
    end
    return true if count == $game_party.max_battle_members
    return false
  end
  #--------------------------------------------------------------------------
  # new method : battle_party_genderless_count
  #--------------------------------------------------------------------------
  def battle_party_genderless_count
    count = 0
    for member in $game_party.battle_members
      next if member.nil?
      count += 1 if member.genderless?
    end
    return count  
  end
  #--------------------------------------------------------------------------
  # new method : battle_party_male_count
  #--------------------------------------------------------------------------
  def battle_party_male_count
    count = 0
    for member in $game_party.battle_members
      next if member.nil?
      count += 1 if member.male?
    end
    return count  
  end
  #--------------------------------------------------------------------------
  # new method : battle_party_female_count
  #--------------------------------------------------------------------------
  def battle_party_female_count
    count = 0
    for member in $game_party.battle_members
      next if member.nil?
      count += 1 if member.female?
    end
    return count  
  end
  #--------------------------------------------------------------------------
  # new method : reserve_party_genderless_count
  #--------------------------------------------------------------------------
  def reserve_party_genderless_count
    count = 0
    count += all_party_genderless_count
    count -= battle_party_genderless_count
    return count
  end
  #--------------------------------------------------------------------------
  # new method : reserve_party_male_count
  #--------------------------------------------------------------------------
  def reserve_party_male_count
    count = 0
    count += all_party_male_count
    count -= battle_party_male_count
    return count
  end
  #--------------------------------------------------------------------------
  # new method : reserve_party_female_count
  #--------------------------------------------------------------------------
  def reserve_party_female_count
    count = 0
    count += all_party_female_count
    count -= battle_party_female_count
    return count
  end
  #--------------------------------------------------------------------------
  # new method : all_party_genderless_count
  #--------------------------------------------------------------------------
  def all_party_genderless_count
    count = 0
    for member in $game_party.all_members
      next if member.nil?
      count += 1 if member.genderless?
    end
    return count  
  end
  #--------------------------------------------------------------------------
  # new method : all_party_male_count
  #--------------------------------------------------------------------------
  def all_party_male_count
    count = 0
    for member in $game_party.all_members
      next if member.nil?
      count += 1 if member.male?
    end
    return count  
  end
  #--------------------------------------------------------------------------
  # new method : all_party_female_count
  #--------------------------------------------------------------------------
  def all_party_female_count
    count = 0
    for member in $game_party.all_members
      next if member.nil?
      count += 1 if member.female?
    end
    return count  
  end
  #--------------------------------------------------------------------------
  # new method : troop_enemy_genderless?
  #--------------------------------------------------------------------------
  def troop_enemy_genderless?(index)
    if $game_party.in_battle
      enemy = $game_troop.members[index]
      return enemy.genderless? unless enemy.nil?
    end
    return false
  end
  #--------------------------------------------------------------------------
  # new method : troop_enemy_male?
  #--------------------------------------------------------------------------
  def troop_enemy_male?(index)
    if $game_party.in_battle
      enemy = $game_troop.members[index]
      return enemy.male? unless enemy.nil?
    end
    return false
  end
  #--------------------------------------------------------------------------
  # new method : troop_enemy_female?
  #--------------------------------------------------------------------------
  def troop_enemy_female?(index)
    if $game_party.in_battle
      enemy = $game_troop.members[index]
      return enemy.female? unless enemy.nil?
    end
    return false
  end
  #--------------------------------------------------------------------------
  # new method : enemy_genderless?
  #--------------------------------------------------------------------------
  def enemy_genderless?(id)
    enemy = $data_enemies[id]
    return true if !enemy.nil? && enemy.gender == 0
    return false
  end
  #--------------------------------------------------------------------------
  # new method : enemy_male?
  #--------------------------------------------------------------------------
  def enemy_male?(id)
    enemy = $data_enemies[id]
    return true if !enemy.nil? && enemy.gender == 1
    return false
  end
  #--------------------------------------------------------------------------
  # new method : enemy_female?
  #--------------------------------------------------------------------------
  def enemy_female?(id)
    enemy = $data_enemies[id]
    return true if !enemy.nil? && enemy.gender == 2
    return false
  end
end # module ScriptCalls
end # module GenderFunctions
end # module Bubs

#==========================================================================
# ++ Game_Interpreter
#==========================================================================
class Game_Interpreter; include Bubs::GenderFunctions::ScriptCalls; end

 

 

Gender requirements

Spoiler

# ╔═══════════════════════════════════════════════════════╤══════╤═══════════╗
# ║ Gender Requirements                                   │ v1.0 │ (1/07/12) ║
# ╚═══════════════════════════════════════════════════════╧══════╧═══════════╝
# Script by:
#     Mr. Bubble ( http://mrbubblewand.wordpress.com/ )
# Thanks:
#     Yanfly, script and design references, suggesting to make this script
#--------------------------------------------------------------------------
# This is an add-on script for Gender Functions which allows developers to
# define gender requirements for equipment, skills, and items.
#
# Built-in support for Yanfly Engine Ace - Class System is included.
#--------------------------------------------------------------------------
# ++ Changelog ++
#--------------------------------------------------------------------------
# v1.0 : Initial release. (1/06/2012)
#--------------------------------------------------------------------------
# ++ Installation ++
#--------------------------------------------------------------------------
# Install this script in the Materials section in your project's
# script editor. This script requires that Gender Functions is also 
# installed in your project.
#
# Place this script below YEA - Class System in your script editor list
# if you have that script installed as well.
#=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
# ++ Notetags ++
#=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
# The following notetags are for Classes, Skills, Items, Weapons, 
# and Armors:
#
# <gender req: genderless>
# <gender requirement: genderless>
#   Requires that the actor be genderless in order to use/equip the skill, 
#   item, weapon, or armor. Each tag listed above has the same effect. 
#   Simply choose whichever one you prefer to type.
#  
# <gender req: m>
# <gender req: male>
# <gender requirement: male>
#   Requires that the actor be male in order to use/equip the skill, 
#   item, weapon, or armor. Each tag listed above has the same effect. 
#   Simply choose whichever one you prefer to type.
#  
# <gender req: f>
# <gender req: female>
# <gender requirement: female>
#   Requires that the actor be female in order to use/equip the skill, 
#   item, weapon, or armor. Each tag listed above has the same effect. 
#   Simply choose whichever one you prefer to type.
# 
# Multiple gender requirement tags may be added to the same notebox.
#
# Class gender requirements are currently only for YEA - Class System.
# Gender requirements for classes do not affect the "Change Class..." 
# event command.
#--------------------------------------------------------------------------
# The following notetags are for Actors, Classes, and Enemies:
#
# <gender req: ignore>
# <gender requirement: ignore>
#   Allows the actor, class, or enemy to ignore any imposed gender 
#   requirements for classes, skills, items, weapons, and armors. Each 
#   tag listed above has the same effect. Simply choose whichever one 
#   you prefer to type.
#
# If you need very specifc exceptions made regarding gender requirements,
# it is recommended that you create your own Armor Type(s) in your
# Database and define equip permissions through that.
#--------------------------------------------------------------------------
# ++ Compatibility ++
#--------------------------------------------------------------------------
# This script does not overwrite any default VXA methods. All default
# methods modified in this script are aliased.
#
# This script has built-in compatibility with the following scripts:
#     - Yanfly Engine Ace - Class System
#
# Requests for compatibility with other scripts are welcome.
#--------------------------------------------------------------------------
# ++ Terms and Conditions ++
#--------------------------------------------------------------------------
# Please do not repost this script elsewhere without permission. Newest 
# versions of this script can be found at http://mrbubblewand.wordpress.com/
#==========================================================================

$imported = {} if $imported.nil?
$imported["BubsGenderRequirements"] = true

#==========================================================================
# ++ THIS SCRIPT CONTAINS NO USER CUSTOMIZATION MODULE ++
#==========================================================================

if $imported["BubsGenderFunctions"]
#==========================================================================
# ++ Bubs::Regexp
#==========================================================================
module Bubs
  module Regexp 
    module BaseItem
      GENDER_REQUIREMENTS = 
        /<GENDER[_\s](?:REQUIREMENT[S]?|req):\s*(\w*)>/i
    end # module BaseItem
  end # module Regexp 
end # module Bubs


#==========================================================================
# ++ DataManager
#==========================================================================
module DataManager
  
  #--------------------------------------------------------------------------
  # alias : load_database
  #--------------------------------------------------------------------------
  class << self; alias load_database_bubs_gender_requirements load_database; end
  def self.load_database
    load_database_bubs_gender_requirements # alias
    load_notetags_bubs_gender_requirements
  end
  
  #--------------------------------------------------------------------------
  # new method : load_notetags_bubs_gender_requirements
  #--------------------------------------------------------------------------
  def self.load_notetags_bubs_gender_requirements
    groups = [$data_actors, $data_classes, $data_skills, $data_items, 
      $data_weapons, $data_armors, $data_enemies]
    for group in groups
      for obj in group
        next if obj.nil?
        obj.load_notetags_bubs_gender_requirements
      end
    end
  end
  
end # module DataManager


#==========================================================================
# ++ RPG::BaseItem
#==========================================================================
class RPG::BaseItem
  #--------------------------------------------------------------------------
  # public instance variables
  #--------------------------------------------------------------------------
  attr_accessor :gender_requirements
  attr_accessor :ignore_gender_requirements
  
  #--------------------------------------------------------------------------
  # common cache : load_notetags_bubs_gender_requirements
  #--------------------------------------------------------------------------
  def load_notetags_bubs_gender_requirements
    @gender_requirements = []
    @ignore_gender_requirements = false
    
    self.note.split(/[\r\n]+/).each { |line|
      case line
      when Bubs::Regexp::BaseItem::GENDER_REQUIREMENTS
        case $1.upcase
        when "IGNORE"
          next unless self.is_a?(RPG::Actor) || 
            self.is_a?(RPG::Class) || 
            self.is_a?(RPG::Enemy)
          @ignore_gender_requirements = true
          
        when "GENDERLESS", "NONE"
          next if self.is_a?(RPG::Actor) || self.is_a?(RPG::Enemy)
          @gender_requirements.push(0) unless @gender_requirements.include?(0)
        
        when "MALE", "M"
          next if self.is_a?(RPG::Actor) || self.is_a?(RPG::Enemy)
          @gender_requirements.push(1) unless @gender_requirements.include?(1)
          
        when "FEMALE", "F"
          next if self.is_a?(RPG::Actor) || self.is_a?(RPG::Enemy)
          @gender_requirements.push(2) unless @gender_requirements.include?(2)

        end # case 
      end # case
    } # self.note.split
    
  end # def
end # class RPG::BaseItem


#==============================================================================
# ++ Game_BattlerBase
#==============================================================================
class Game_BattlerBase
  #--------------------------------------------------------------------------
  # new method : gender_conditions_met?
  #--------------------------------------------------------------------------
  def gender_conditions_met?(item)
    return true if item.gender_requirements.empty?
    if actor?
      return true if self.actor.ignore_gender_requirements
      # ensures being a class does not allow ignoring class gender reqs
      unless item.is_a?(RPG::Class)
        return true if self.class.ignore_gender_requirements
      end
      return true if item.gender_requirements.include?(self.actor.gender)
    else
      return true if self.enemy.ignore_gender_requirements
      return true if item.gender_requirements.include?(self.enemy.gender)
    end 
    return false
  end
  
  #--------------------------------------------------------------------------
  # alias : equippable?
  #--------------------------------------------------------------------------
  alias equippable_bubs_gender_requirements equippable?
  def equippable?(item) 
    return false unless equippable_bubs_gender_requirements(item) # alias
    return false unless gender_conditions_met?(item)
    return true
  end
  
  #--------------------------------------------------------------------------
  # alias : skill_conditions_met?
  #--------------------------------------------------------------------------
  alias skill_conditions_met_bubs_gender_requirements skill_conditions_met?
  def skill_conditions_met?(skill)
    return false unless gender_conditions_met?(skill)
    return skill_conditions_met_bubs_gender_requirements(skill) # alias
  end
  
  #--------------------------------------------------------------------------
  # alias : item_conditions_met?
  #--------------------------------------------------------------------------
  alias item_conditions_met_bubs_gender_requirements item_conditions_met?
  def item_conditions_met?(item)
    return false unless gender_conditions_met?(item)
    return item_conditions_met_bubs_gender_requirements(item) # alias
  end

end # class Game_BattlerBase


#==============================================================================
# ++ Window_ClassList
#==============================================================================
if $imported["YEA-ClassSystem"]

class Window_ClassList < Window_Selectable
  #--------------------------------------------------------------------------
  # alias : include?
  #--------------------------------------------------------------------------
  alias include_bubs_gender_requirements include?
  def include?(item)
    return false unless @actor.gender_conditions_met?(item)
    return include_bubs_gender_requirements(item) # alias
  end
  
end # class Window_ClassList

end # if $imported["YEA-ClassSystem"]

end # if $imported["BubsGenderFunctions"]

 

 

Limit sell items to buy items

Spoiler

#==============================================================================
# ++ Limit Sell Items to Buy Item Selections - v1.1 (1/01/12)
#==============================================================================
# Original RMVX/RGSS2 script by: 
#             Mithran
# Ported to RMVXA/RGSS3 by:
#             Mr. Bubble
#--------------------------------------------------------------------------
# This script restricts the types of items the player can sell to a shop
# to only what the player can buy from the shop. Sellable item restrictions
# can optionally be turned off or on with a game switch.
#
# Original script port request by Seiryuki.
#--------------------------------------------------------------------------
# ++ This script aliases the following methods:
#       Scene_Shop#create_sell_window
#==============================================================================

#--------------------------------------------------------------------------
# ++ Customization Module - START
#--------------------------------------------------------------------------

module Bubs
  module MithranLimitSellItems
  # ++ Limit Shop Default
  #    Determines whether all shops only buyback items they can 
  #    sell by default
  LIMIT_SHOP_SELL_DEFAULT = true
  
  # ++ Limit Shop Game Switch
  #    Set whether you want a game switch ID to determine when Limit Shop
  #    is active. Otherwise, you can leave it as nil.
  LIMIT_SHOP_SELL_SWITCH = nil
  
  end
end

#--------------------------------------------------------------------------
# ++ Customization Module - END
#--------------------------------------------------------------------------

$imported = {} if $imported.nil?
$imported["MithranLimitSellItems"] = true

#==============================================================================
# ++ Window_LimitShopSell : new class
#==============================================================================
# $game_temp.shop_goods no longer exists in RGSS3. Because of this, a new
# class was created.

class Window_LimitShopSell < Window_ShopSell
  #--------------------------------------------------------------------------
  # ++ Object Initialization
  #     x      : window x-coordinate
  #     y      : window y-coordinate
  #     width  : window width
  #     height : window height
  #     shop_goods : array of shop goods
  #--------------------------------------------------------------------------
  def initialize(x, y, width, height, shop_goods)
    super(x, y, width, height)
    @shop_goods = shop_goods
  end
  #--------------------------------------------------------------------------
  # ++ Whether or not to include in item list
  #     item : item
  #--------------------------------------------------------------------------
  def include?(item)
    return false if @shop_goods.nil?
    return false if item.nil?
    for pair in @shop_goods
      case @category
      when :item
        if item.is_a?(RPG::Item) && !item.key_item?
          return true if pair[0] == 0 && pair[1] == item.id
        end
      when :weapon
        if item.is_a?(RPG::Weapon)
          return true if pair[0] == 1 && pair[1] == item.id
        end
      when :armor
        if item.is_a?(RPG::Armor)
          return true if pair[0] == 2 && pair[1] == item.id
        end
      when :key_item
        if item.is_a?(RPG::Item) && item.key_item?
          return true if pair[0] == 0 && pair[1] == item.id
        end
      else
        return false
      end # case
    end # for
    return false
  end # def include?(item)
end # class

#==============================================================================
# ++ Scene_Shop
#==============================================================================
class Scene_Shop < Scene_MenuBase
  #--------------------------------------------------------------------------
  # ++ create_sell_window : alias
  #--------------------------------------------------------------------------
  alias create_sell_window_limit_shop_sell create_sell_window
  def create_sell_window
    if Bubs::MithranLimitSellItems::LIMIT_SHOP_SELL_DEFAULT || 
                $game_switches[Bubs::MithranLimitSellItems::LIMIT_SHOP_SELL_SWITCH]
                
      wy = @category_window.y + @category_window.height
      wh = Graphics.height - wy
      # changed to Window_LimitShopSell.new
      @sell_window = Window_LimitShopSell.new(0, wy, Graphics.width, wh, @goods)
      @sell_window.viewport = @viewport
      @sell_window.help_window = @help_window
      @sell_window.hide
      @sell_window.set_handler(:ok,     method(:on_sell_ok))
      @sell_window.set_handler(:cancel, method(:on_sell_cancel))
      @category_window.item_window = @sell_window
    else
      create_sell_window_limit_shop_sell # alias
    end # if
  end # def create_sell_window
end # class

 

 

Shield Blocking

Spoiler

# ╔═══════════════════════════════════════════════════════╤══════╤═══════════╗
# ║ Shield Blocking                                       │ v1.2 │ (4/28/13) ║
# ╚═══════════════════════════════════════════════════════╧══════╧═══════════╝
# Script by:
#     Mr. Bubble ( http://mrbubblewand.wordpress.com/ )
#--------------------------------------------------------------------------
# The motivation for making this script came from the awkward infatuation 
# with newbie RM users and dual-weapon wielding. Maybe there needs to be a 
# better incentive for using a shield.
#
# With that, I chose to make a script that supports blocking in battle. 
# Shield block design mechanics are borrowed from World of Warcraft. This 
# includes the now obsolete 'block value' statistic and more recent
# 'critical block' mechanic. Users have a choice of using block value to 
# reduce damage, a simple percentage reduction of damage, or a mix of both.
#
# This script introduces four new battler parameters for both actors and
# enemies:
#
#   blv : BLock Value - reduces blocked damage by a flat amount
#   blr : BLock reduction Rate - reduces damage by a percentage
#   blc : BLock Chance - percentage chance to block normally
#   cbl : Critical BLock chance - percentage chance to block critically
#   
# Additional options include negating critical hits when they are blocked.
#--------------------------------------------------------------------------
#      Changelog   
#--------------------------------------------------------------------------
# v1.2 : Bugfix: Block chance is no longer always maxed.
#      : Bugfix: Having high amounts of block value will no longer 
#      : output large, inaccurate numbers in the battle log.
#      : Compatibility Update: YEA - Ace Battle Engine.
#      : Customization options added for YEA - Ace Battle Engine. 
#      : Blocking now prevents states and other hit effects
#      : if damage is reduced to 0. (4/28/2013)
#      : Custom sound files should no longer crash the game. (4/17/2013)
# v1.1 : Bugfix: Fixed typo with $imported variable. (7/09/2012)
# v1.0 : Initial release. (7/03/2012)
#--------------------------------------------------------------------------
#      Installation   
#--------------------------------------------------------------------------
# Install this script in the Materials section in your project's
# script editor.
#
# Install below YEA - Ace Status Menu if you also have that installed.
#=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
#      Notetags   
#=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
# The following Notetags are for Actors, Classes, Weapons, Armors, Enemies, 
# and States:
#
# Note: Some tags are given shorter tags for typing convenience. You only
#       need to use one <tag> from a given group for a notebox.
#
# <blocking>
# <block>
#   This tag allows the ability to block. Blocking an attack reduces damage
#   taken depending on the battler's block value (BLV) and block reduction 
#   rate (BLR). This tag is not limited to shields. Any actor, class, or 
#   piece of equipment can provide the ability to block. Enemies can
#   block too.
#
# <critical blocking>
# <critical block>
# <crit block>
#   This tag allows the critical blocking ability. Critical blocks provide a 
#   bonus to block value and block reduction rate when critical blocks occur.
#   Critical blocks take precedence over normal blocks if both occur at the
#   same time. This tag is not limited to shields. Any actor, class, or 
#   piece of equipment can provide the ability to critical block. Enemies
#   can critical block too.
#
# <block value: +n>
# <block value: -n>
#   This tag modifies block value (BLV). Block value directly subtracts 
#   damage from an attack when a block occurs. For example, if an attacker
#   does 200 damage, and a defender has 50 block value, the defender can
#   potentially reduce the damage to 150 damage if the attack is blocked.
#   Block value stacks with block reduction rate (BLR).
#
# <block reduction rate: +n%>
# <block reduction rate: -n%>
# <block rate: +n%>
# <block rate: -n%>
#   This tag modifies block reduction rate (BLR) which reduces damage by a 
#   percentage rate. For example, if BLR is 30, damage will be reduced by
#   30% when blocked. This effect stacks with block value (BLV).
#   Do not mistake "block rate" with "block chance". They are different 
#   within this script.
#   
# <block chance: +n%>
# <block chance: -n%>
#   This tag modifies normal block chance (BLC). Normal block chance
#   affects how often normal blocks occur.
#
# <critical block chance: +n%>
# <critical block chance: -n%>
# <crit block chance: +n%>
# <crit block chance: -n%>
#   This tag modifies critical block chance (CBL). Critical block chance
#   affects how often critical blocks occur.
#--------------------------------------------------------------------------
# The following Notetags are for Skills and Items only:
#
# <unblockable>
#   Items and skills with this tag are rendered unblockable. This tag will
#   only affect blocking. It has no effect on evasion, etc.
#--------------------------------------------------------------------------
#      Blocking Formula   
#--------------------------------------------------------------------------
# This is a simplified internal formula used to calculate total block 
# damage reduction:
#
#   damage = (damage - block_value) * (1 - (block_reduction_rate))
#
# Rates in VXAce are generally kept as values between 0.0 and 1.0
#
# A bonus multiplier is applied to block_value and block_reduction_rate
# when a critical block occurs.
#--------------------------------------------------------------------------
#      Compatibility   
#--------------------------------------------------------------------------
# This script has built-in compatibility with the following scripts:
#     - Yanfly Engine Ace - Ace Status Menu
#     - Yanfly Engine Ace - Ace Battle Engine
#
# This script aliases the following default VXA methods:
#
#     Game_Battler#execute_damage
#     Game_Battler#make_damage_value
#     Game_Battler#apply_guard
#     Game_Battler#item_effect_apply
#
#     Game_ActionResult#clear_hit_flags
#     Game_ActionResult#clear_damage_values
#
#     Window_BattleLog#display_hp_damage
#    
# There are no default method overwrites.
#
# Requests for compatibility with other scripts are welcome.
#--------------------------------------------------------------------------
#     Compatibility Notes
#--------------------------------------------------------------------------
# To add the various blocking parameters to the Ace Status Menu 
# "Properties" window, add the lines:
#
#             [:blv, "Block Value"],
#             [:blr, "Block Reduction Rate"],
#             [:blc, "Block Chance"],
#             [:cbl, "Critical Block Chance"],
# 
# Under any one of the three PROPERTIES_COLUMN under Properties Window 
# Settings.
#--------------------------------------------------------------------------
#      Terms and Conditions   
#--------------------------------------------------------------------------
# Please do not repost this script elsewhere without permission. 
# Free for non-commercial use. For commercial use, contact me first.
#
# Newest versions of this script can be found at 
#                                           http://mrbubblewand.wordpress.com/
#==============================================================================

$imported = {} if $imported.nil?
$imported["BubsBlocking"] = true

#==========================================================================
#    START OF USER CUSTOMIZATION MODULE   
#==========================================================================
module Bubs
  #==========================================================================
  #    Blocking Settings
  #==========================================================================
  module Blocking
  #--------------------------------------------------------------------------
  #   Block Parameters Vocab
  #--------------------------------------------------------------------------
  BLV_VOCAB = "BLK Value"             # Block Value
  BLR_VOCAB = "BLK Reduction Rate"    # Block Reduction Rate
  BLC_VOCAB = "BLK Chance"            # Block Chance
  CBL_VOCAB = "Crit BLK Chance"   # Critical Block Chance
  
  #--------------------------------------------------------------------------
  #   Block Parameters Vocab Abbreviations
  #--------------------------------------------------------------------------
  BLV_VOCAB_A = "BLV"    # Block Value Abbr.
  BLR_VOCAB_A = "BLR"    # Block Reduction Rate Abbr.
  BLC_VOCAB_A = "BLC"    # Block Chance Abbr.
  CBL_VOCAB_A = "CBL"    # Critical Block Chance Abbr.
  
  #--------------------------------------------------------------------------
  #   Default Blocking Armor Types
  #--------------------------------------------------------------------------
  # This setting allows you to automatically set certain Armor Type IDs
  # with the Blocking trait. Armor Type IDs can be found under the "Terms"
  # tab in the database of your project. For example, this can be useful 
  # if you have shields as an Armor Type.
  BLOCKING_ARMOR_TYPES = [5,6]
  
  #--------------------------------------------------------------------------
  #   Default Critical Blocking Armor Types
  #--------------------------------------------------------------------------
  # This setting allows you to automatically set certain Armor Type IDs
  # with the Critical Blocking trait. Armor Type IDs can be found under the 
  # "Terms" tab in the database of your project.
  #
  # Critical blocking provides a higher damage reduction effect than normal
  # blocking.
  CRITICAL_BLOCKING_ARMOR_TYPES = [6]
  
  #--------------------------------------------------------------------------
  #   Unblockable Elements Setting
  #--------------------------------------------------------------------------
  # This setting allows you to have unblockable elements for any item
  # or skill that has an Element ID listed in the array. Element ID numbers
  # can be found under the "Terms" tab in the database of your project.
  UNBLOCKABLE_ELEMENTS = []
  #--------------------------------------------------------------------------
  #   Unblockable Skill Types Setting
  #--------------------------------------------------------------------------
  # This setting allows you to have unblockable Skill Type in the event
  # you choose to make such a skill category. Skill Type ID numbers
  # can be found under the "Terms" tab in the database of your project.
  UNBLOCKABLE_SKILL_TYPES = []
  
  #--------------------------------------------------------------------------
  #   Blockable Hit Types Setting
  #--------------------------------------------------------------------------
  # This setting allows you to decide what kind of hit types are blockable 
  # Add the hit type number into the array to allow that type to be blockable.
  # 
  # 0 : Certain hits
  # 1 : Physical attacks
  # 2 : Magical attacks
  BLOCKABLE_HIT_TYPES = [1]

  #--------------------------------------------------------------------------
  #   Block Value Variance
  #--------------------------------------------------------------------------
  # This value determines the variance range for Block Value when attacks
  # are blocked. This works similarly to the variance value for items and 
  # skills. This has no effect on Block Reduction Rate.
  BLV_VARIANCE = 10
  
  #--------------------------------------------------------------------------
  #   Block Sound Effects
  #--------------------------------------------------------------------------
  # These settings allow you to choose a sound effect for normal and critical
  # blocks.
  #                    "Filename", Volume, Pitch
  NORMAL_BLOCK_SE   = ["Parry",     90,   110]   # Normal Block SE
  CRITICAL_BLOCK_SE = ["Evasion2",     90,   110]   # Critical Block SE
    
  #--------------------------------------------------------------------------
  #   Actor Default Block Parameter Formulas
  #--------------------------------------------------------------------------
  # The following settings are formulas used for producing the base values 
  # for blocking parameters. The values produced by these formulas stack 
  # with any bonuses gained from equipped items, class, states, etc.
  #
  # Formulas are made within the scope of class Game_Battler. This means
  # parameters such as (but not limited to) atk, def, level, luk, etc. can
  # be used within formulas. If you wish to use the defense parameter
  # "def", you must use the term "self.def" instead.
  #
  # Blocking-specific battler parameters may also be used:
  #   blv : BLock Value               (value range: 0~max_blv)
  #   blr : BLock reduction Rate      (value range: 0.0~1.0)
  #   blc : BLock Chance              (value range: 0.0~1.0)
  #   cbl : Critical BLock chance     (value range: 0.0~1.0)
  #
  # A value of 1.0 means 100%.
  #
  # For these formulas, :base_blr, :base_blc, and :base_cbl should 
  # produce rate values between 0~100.
  ACTOR_BLOCK_SETTINGS = {
    :base_blv => "(self.def / 5)",     # Base Block Value Formula
    :base_blr => "0",                  # Base Block Reduction Rate Formula
    :base_blc => "5",                  # Base Block Chance Formula
    :base_cbl => "(blc * 100) / 3",    # Base Critical Block Chance Formula
  
  #--------------------------------------------------------------------------
  #   Actor Maximum Block Parameter Settings
  #--------------------------------------------------------------------------
  # The following settings allow you to set maximum values for any block
  # parameters for actors.
    :max_blv => 9999,    # Maximum Block Value
    :max_blr => 100,      # Maximum Block Reduction Rate (%)
    :max_blc => 75,       # Maximum Block Chance (%)
    :max_cbl => 50,       # Maximum Critical Block Chance (%)
    
  #--------------------------------------------------------------------------
  #   Actor Critical Block Multiplier Settings
  #--------------------------------------------------------------------------
  # You can set Block Value and Block Reduction Rate multiplier for
  # actor Critical Blocks here.
    :critical_blv_multiplier => 2.0, # Block Value Crit Multiplier
    :critical_blr_multiplier => 2.0, # Block Reduction Rate Crit Multiplier
    
  #--------------------------------------------------------------------------
  #   Actor TP Gain On Block Formula
  #--------------------------------------------------------------------------
  # You may specify the formula used for TP gain whenever a block is made
  # by an actor. This setting is for advanced users.
  #
  # Data included within the scope of Game_Battler is available which 
  # includes, but is not limited to, atk, mhp, mmp, tp, tcr, etc.
  #
  # "blocked_damage" is available as a variable which holds the total
  # amount of damage that was blocked by the actor.
    :tp_gain => "40 * (blocked_damage / mhp.to_f) * tcr",
    
  #--------------------------------------------------------------------------
  #   Actor Block - Cancel Critical Hits
  #--------------------------------------------------------------------------
  # true  : Prevent critical hits when an attack is blocked.
  # false : Critical hits are not prevented.
    :cancel_critical_hits => true,
    
  #--------------------------------------------------------------------------
  #   Actor Block - In-battle Text
  #--------------------------------------------------------------------------
  # These settings allow you to change the in-battle text when a normal 
  # or critical block occurs. The first %s is the actor's name while
  # the second %s is the amount of damage blocked.
    :block_text          => "%s blocked %s damage!",            # Normal block
    :critical_block_text => "%s critically blocked %s damage!", # Critical block
    
  } # <-- Do not delete
  
  #--------------------------------------------------------------------------
  #   Enemy Default Block Parameter Formulas
  #--------------------------------------------------------------------------
  # The following settings are formulas used for producing the base values 
  # for blocking parameters. The values produced by these formulas stack 
  # with any bonuses gained from states, etc.
  #
  # Formulas are made within the scope of class Game_Battler. This means
  # parameters such as (but not limited to) atk, def, level, luk, etc. can
  # be used within formulas. If you wish to use the defense parameter
  # "def", you must use the term "self.def" instead.
  #
  # Blocking-specific battler parameters may also be used:
  #   blv : BLock Value
  #   blr : BLock Reduction rate
  #   blc : BLock Chance
  #   cbl : Critical BLock chance
  #
  # :base_blr, :base_blc, and :base_cbl should produce rate values 
  # between 0~100.
  ENEMY_BLOCK_SETTINGS = {
    :base_blv => "(self.def / 5)",  # Base Block Value Formula
    :base_blr => "0",               # Base Block Reduction Rate Formula
    :base_blc => "5",               # Base Block Chance Formula
    :base_cbl => "(blc * 100) / 3", # Base Critical Block Chance Formula
    
  #--------------------------------------------------------------------------
  #   Enemy Maximum Block Parameter Settings
  #--------------------------------------------------------------------------
  # The following settings allow you to set maximum values for any block
  # parameters for enemies.
    :max_blv => 9999,    # Maximum Block Value
    :max_blr => 75,      # Maximum Block Reduction Rate (%)
    :max_blc => 75,       # Maximum Block Chance (%)
    :max_cbl => 50,       # Maximum Critical Block Chance (%)
    
  #--------------------------------------------------------------------------
  #   Enemy Critical Block Multiplier Settings
  #--------------------------------------------------------------------------
  # You can set Block Value and Block Reduction Rate multiplier for
  # enemy Critical Blocks here.
    :critical_blv_multiplier => 2.0, # Block Value Crit Multiplier
    :critical_blr_multiplier => 2.0, # Block Reduction Rate Crit Multiplier
    
  #--------------------------------------------------------------------------
  #   Enemy TP Gain On Block Formula
  #--------------------------------------------------------------------------
  # You may specify the formula used for TP gain whenever a block is made
  # by an enemy. This setting is for advanced users.
  #
  # Data included within the scope of Game_Battler is available which 
  # includes, but is not limited to, atk, mhp, mmp, tp, tcr, etc.
  #
  # "blocked_damage" is available as a variable which holds the total
  # amount of damage that was blocked by the enemy.
    :tp_gain => "40 * (blocked_damage / mhp.to_f) * tcr",

  #--------------------------------------------------------------------------
  #   Enemy Block - Cancel Critical Hits
  #--------------------------------------------------------------------------
  # true  : Prevent critical hits when an attack is blocked.
  # false : Critical hits are not prevented.
    :cancel_critical_hits => true,

  #--------------------------------------------------------------------------
  #   Enemy Block - In-battle Text
  #--------------------------------------------------------------------------
  # These settings allow you to change the in-battle text when a normal 
  # or critical block occurs. The first %s is the enemy's name while
  # the second %s is the amount of damage blocked.
    :block_text          => "%s blocked %s damage!",            # Normal block
    :critical_block_text => "%s critically blocked %s damage!", # Critical block

  } # <-- Do not delete
  
  #--------------------------------------------------------------------------
  #   YEA - Ace Battle Engine - Block Pop-up Text
  #--------------------------------------------------------------------------
  # These settings only apply when YEA - Ace Battle Engine is installed.
  BLOCK_POPUP_TEXT          = "Blocked!"
  CRITICAL_BLOCK_POPUP_TEXT = "Critical Blocked!"
  
  end # module Blocking
end # module Bubs

#==========================================================================
#    END OF USER CUSTOMIZATION MODULE   
#==========================================================================



#==========================================================================
# ++ Bubs::Regexp
#==========================================================================
module Bubs
  module Regexp
    module BaseItem
      CAN_BLOCK = /<(?:BLOCKING|block)>/i
      CAN_CRIT_BLOCK = /<(?:CRITICAL|crit)[\s_](?:BLOCKING|block)>/i
      BLOCK_VALUE = /<(?:BLOCK_VALUE|block value):\s*([-+]?\d+\.?\d*)>/i
      
      BLOCK_REDUCTION_RATE = 
  /<(?:BLOCK[\s_]REDUCTION|block)[\s_]rate:\s*([-+]?\d+\.?\d*)[%%]>/i
     
      BLOCK_CHANCE = 
  /<(?:BLOCK_CHANCE|block chance):\s*([-+]?\d+\.?\d*)[%%]>/i
      
      CRITICAL_BLOCK_CHANCE = 
  /<(?:CRITICAL|crit)[\s_]block[\s_]chance:\s*([-+]?\d+\.?\d*)[%%]>/i
      
    end # module BaseItem

    module UsableItem
      UNBLOCKABLE = /<?:UNBLOCKABLE|unblockable>/i
    end # module UsableItem
  end # module Regexp
end # module Bubs



#==========================================================================
# ++ DataManager
#==========================================================================
module DataManager
  #--------------------------------------------------------------------------
  # alias : load_database
  #--------------------------------------------------------------------------
  class << self; alias load_database_bubs_blocking load_database; end
  def self.load_database
    load_database_bubs_blocking # alias
    load_notetags_bubs_blocking
  end
  
  #--------------------------------------------------------------------------
  # new method : load_notetags_bubs_blocking
  #--------------------------------------------------------------------------
  def self.load_notetags_bubs_blocking
    groups = [$data_actors, $data_classes, $data_skills, $data_items, 
      $data_weapons, $data_armors, $data_enemies, $data_states]
    for group in groups
      for obj in group
        next if obj.nil?
        obj.load_notetags_bubs_blocking
      end # for obj
    end # for group
  end # def
  
end # module DataManager


#==========================================================================
# ++ RPG::BaseItem
#==========================================================================
# A superclass of actor, class, skill, item, weapon, armor, enemy, and state.
class RPG::BaseItem
  #--------------------------------------------------------------------------
  # public instance variables
  #--------------------------------------------------------------------------
  attr_accessor :blocking
  attr_accessor :critical_blocking
  attr_accessor :unblockable
  attr_accessor :block_value
  attr_accessor :block_reduction_rate
  attr_accessor :block_chance
  attr_accessor :critical_block_chance
  
  #--------------------------------------------------------------------------
  # common cache : load_notetags_bubs_blocking
  #--------------------------------------------------------------------------
  def load_notetags_bubs_blocking
    @blocking = false
    @critical_blocking = false
    @unblockable = false
    @block_value = 0.0
    @block_reduction_rate = 0.0
    @block_chance = 0.0
    @critical_block_chance = 0.0
    
    default_block_settings
    
    self.note.split(/[\r\n]+/).each { |line|
      case line

      when Bubs::Regexp::BaseItem::CAN_BLOCK
        @blocking = true
        
      when Bubs::Regexp::BaseItem::CAN_CRIT_BLOCK
        @critical_blocking = true
        
      when Bubs::Regexp::BaseItem::BLOCK_VALUE
        @block_value = $1.to_f
        
      when Bubs::Regexp::BaseItem::BLOCK_REDUCTION_RATE
        @block_reduction_rate = $1.to_f
        
      when Bubs::Regexp::BaseItem::BLOCK_CHANCE
        @block_chance = $1.to_f
        
      when Bubs::Regexp::BaseItem::CRITICAL_BLOCK_CHANCE
        @critical_block_chance = $1.to_f

      end
    } # self.note.split
    
  end # def
  
  #--------------------------------------------------------------------------
  # common cache : default_block_settings
  #--------------------------------------------------------------------------
  def default_block_settings
    if self.is_a?(RPG::Armor)
      @blocking = Bubs::Blocking::BLOCKING_ARMOR_TYPES.include?(@atype_id)
      @critical_blocking = Bubs::Blocking::CRITICAL_BLOCKING_ARMOR_TYPES.include?(@atype_id)
    elsif self.is_a?(RPG::Skill)
      @unblockable = Bubs::Blocking::UNBLOCKABLE_SKILL_TYPES.include?(@stype_id)
    end # self.is_a?(RPG::Armor)
  end # def default_block_settings
end # module RPG::BaseItem



#==========================================================================
# ++ RPG::UsableItem
#==========================================================================
# The Superclass of Skill and Item.
class RPG::UsableItem < RPG::BaseItem
  #--------------------------------------------------------------------------
  # common cache : load_notetags_bubs_blocking
  #--------------------------------------------------------------------------
  def load_notetags_bubs_blocking
    @unblockable = false
    
    default_block_settings
  
    self.note.split(/[\r\n]+/).each { |line|
      case line

      when Bubs::Regexp::UsableItem::UNBLOCKABLE
        @unblockable = true
        
      end
    } # self.note.split
  end # def

end # class RPG::UsableItem



#==============================================================================
# ++ Vocab
#==============================================================================
module Vocab
  # Actor Blocking Text
  ActorBlock = Bubs::Blocking::ACTOR_BLOCK_SETTINGS[:block_text] 
  ActorCritBlock = Bubs::Blocking::ACTOR_BLOCK_SETTINGS[:critical_block_text] 
  
  # Actor Blocking Text
  EnemyBlock = Bubs::Blocking::ENEMY_BLOCK_SETTINGS[:block_text] 
  EnemyCritBlock = Bubs::Blocking::ENEMY_BLOCK_SETTINGS[:critical_block_text] 
  
  ABE_Block = Bubs::Blocking::BLOCK_POPUP_TEXT
  ABE_CritBlock =  Bubs::Blocking::CRITICAL_BLOCK_POPUP_TEXT
  
  # Block Value
  def self.blv; Bubs::Blocking::BLV_VOCAB; end
  def self.blv_a; Bubs::Blocking::BLV_VOCAB_A; end
  # Block Reduction Rate
  def self.blr; Bubs::Blocking::BLR_VOCAB; end
  def self.blr_a; Bubs::Blocking::BLR_VOCAB_A; end
  # Block Chance
  def self.blc; Bubs::Blocking::BLC_VOCAB; end
  def self.blc_a; Bubs::Blocking::BLC_VOCAB_A; end
  # Critical Block Chance
  def self.cbl; Bubs::Blocking::CBL_VOCAB; end
  def self.cbl_a; Bubs::Blocking::CBL_VOCAB_A; end
end # module Vocab
  


#==============================================================================
# ++ Sound
#==============================================================================
module Sound
  # Normal Block SE
  def self.play_block
    Audio.se_play("Audio/SE/" + Bubs::Blocking::NORMAL_BLOCK_SE[0], 
                  Bubs::Blocking::NORMAL_BLOCK_SE[1], 
                  Bubs::Blocking::NORMAL_BLOCK_SE[2]) 
  end
  # Critical Block SE
  def self.play_critical_block
    Audio.se_play("Audio/SE/" + Bubs::Blocking::CRITICAL_BLOCK_SE[0], 
                  Bubs::Blocking::CRITICAL_BLOCK_SE[1], 
                  Bubs::Blocking::CRITICAL_BLOCK_SE[2]) 
  end
end # module Sound



#==========================================================================
# ++ Game_BattlerBase
#==========================================================================
class Game_BattlerBase
  
  #--------------------------------------------------------------------------
  # new method : actor_block_settings
  #--------------------------------------------------------------------------
  def actor_block_settings(key)
    Bubs::Blocking::ACTOR_BLOCK_SETTINGS[key]
  end
  
  #--------------------------------------------------------------------------
  # new method : enemy_block_settings
  #--------------------------------------------------------------------------
  def enemy_block_settings(key)
    Bubs::Blocking::ENEMY_BLOCK_SETTINGS[key]
  end
  
  #--------------------------------------------------------------------------
  # new method : can_block?
  #--------------------------------------------------------------------------
  def can_block?
    blocking? && movable?
  end
  
  #--------------------------------------------------------------------------
  # new method : can_critical_block?
  #--------------------------------------------------------------------------
  def can_critical_block?
    critical_blocking? && movable?
  end

  #--------------------------------------------------------------------------
  # new method : blocking?
  #--------------------------------------------------------------------------
  def blocking?
    if actor?
      return true if self.actor.blocking
      return true if self.class.blocking
      for equip in equips
        next if equip.nil?
        return true if equip.blocking
      end
    else
      return true if self.enemy.blocking
    end
    for state in states
      next if state.nil?
      return true if state.blocking
    end
    return false
  end # def blocking?
  
  #--------------------------------------------------------------------------
  # new method : critical_blocking?
  #--------------------------------------------------------------------------
  def critical_blocking?
    if actor?
      return true if self.actor.critical_blocking
      return true if self.class.critical_blocking
      for equip in equips
        next if equip.nil?
        return true if equip.critical_blocking
      end
    else
      return true if self.enemy.critical_blocking
    end
    for state in states
      next if state.nil?
      return true if state.critical_blocking
    end
    return false
  end # def critical_blocking?
  
  #--------------------------------------------------------------------------
  # new method : unblockable?        # this method is not used by default
  #--------------------------------------------------------------------------
  def unblockable?
    if actor?
      return true if self.actor.unblockable
      return true if self.class.unblockable
      for armor in armors
        next if armor.nil?
        return true if armor.unblockable
      end
    else
      return true if self.enemy.unblockable
    end
    for state in states
      next if state.nil?
      return true if state.unblockable
    end
    return false
  end # def unblockable?
  
  #--------------------------------------------------------------------------
  # new method : blv        # BLock Value
  #--------------------------------------------------------------------------
  def blv 
    n = 0.0
    if actor?
      n += Float(eval(actor_block_settings(:base_blv)))
      n += self.actor.block_value
      n += self.class.block_value
      for equip in equips
        next if equip.nil?
        n += equip.block_value
      end
    else
      n += Float(eval(enemy_block_settings(:base_blv)))
      n += self.enemy.block_value
    end
    for state in states
      next if state.nil?
      n += state.block_value
    end
    # determine maximum block value
    n = [n, blv_max].min
    n = [n, 0].max
    
    return n
  end # def blv
  #--------------------------------------------------------------------------
  # new method : blr        # BLock reduction Rate
  #--------------------------------------------------------------------------
  def blr
    n = 0.0
    if actor?
      n += Float(eval(actor_block_settings(:base_blr)))
      n += self.actor.block_reduction_rate
      n += self.class.block_reduction_rate
      for equip in equips
        next if equip.nil?
        n += equip.block_reduction_rate
      end
    else
      n += Float(eval(enemy_block_settings(:base_blr)))
      n += self.enemy.block_reduction_rate
    end
    for state in states
      next if state.nil?
      n += state.block_reduction_rate
    end
    n *= 0.01
    # determine maximum block rate
    n = [n, blr_max].min    
    n = [n, 0].max
    
    return n
  end # def blr
  
  #--------------------------------------------------------------------------
  # new method : blc        # BLock Chance
  #--------------------------------------------------------------------------
  def blc
    n = 0.0
    if actor?
      n += Float(eval(actor_block_settings(:base_blc)))
      n += self.actor.block_chance
      n += self.class.block_chance
      for equip in equips
        next if equip.nil?
        n += equip.block_chance
      end
    else
      n += Float(eval(enemy_block_settings(:base_blc)))
      n += self.enemy.block_chance
    end
    for state in states
      next if state.nil?
      n += state.block_chance
    end
    n *= 0.01
    # determine maximum block chance
    n = [n, blc_max].min
    n = [n, 0].max
    
    return n
  end # def blc
  
  #--------------------------------------------------------------------------
  # new method : cbl        # Critical BLock chance
  #--------------------------------------------------------------------------
  def cbl
    n = 0.0
    if actor?
      n += Float(eval(actor_block_settings(:base_cbl)))
      n += self.actor.critical_block_chance
      n += self.class.critical_block_chance
      for equip in equips
        next if equip.nil?
        n += equip.critical_block_chance
      end
    else
      n += Float(eval(enemy_block_settings(:base_cbl)))
      n += self.enemy.critical_block_chance
    end
    for state in states
      next if state.nil?
      n += state.critical_block_chance
    end
    n *= 0.01
    # determine maximum critical block chance
    n = [n, cbl_max].min
    n = [n, 0].max
    
    return n
  end # def cbl

  #--------------------------------------------------------------------------
  # new method : blv_max        # BLock Value
  #--------------------------------------------------------------------------
  def blv_max
    return actor_block_settings(:max_blv) if actor?
    return enemy_block_settings(:max_blv)
  end
  
  #--------------------------------------------------------------------------
  # new method : blr_max        # BLock reduction Rate
  #--------------------------------------------------------------------------
  def blr_max
    return actor_block_settings(:max_blr) * 0.01 if actor?
    return enemy_block_settings(:max_blr) * 0.01
  end
  
  #--------------------------------------------------------------------------
  # new method : blc_max        # BLock Chance
  #--------------------------------------------------------------------------
  def blc_max
    return actor_block_settings(:max_blc) * 0.01 if actor?
    return enemy_block_settings(:max_blc) * 0.01
  end
  
  #--------------------------------------------------------------------------
  # new method : cbl_max        # Critical BLock chance
  #--------------------------------------------------------------------------
  def cbl_max
    return actor_block_settings(:max_cbl) * 0.01 if actor?
    return enemy_block_settings(:max_cbl) * 0.01
  end
  
end # class Game_BattlerBase



#==============================================================================
# ++ Game_Battler
#==============================================================================
class Game_Battler < Game_BattlerBase
  #--------------------------------------------------------------------------
  # alias : item_effect_apply
  #--------------------------------------------------------------------------
  alias item_effect_apply_bubs_blocking item_effect_apply
  def item_effect_apply(user, item, effect)
    return if @result.blocked? && @result.hp_damage == 0
    item_effect_apply_bubs_blocking(user, item, effect)
  end
  #--------------------------------------------------------------------------
  # alias : make_damage_value
  #--------------------------------------------------------------------------
  alias make_damage_value_bubs_blocking make_damage_value
  def make_damage_value(user, item)
    check_block(user, item)
    make_damage_value_bubs_blocking(user, item) # alias
  end
  
  #--------------------------------------------------------------------------
  # alias : apply_guard
  #--------------------------------------------------------------------------
  alias apply_guard_bubs_blocking apply_guard
  def apply_guard(damage)
    apply_block(apply_guard_bubs_blocking(damage)) # alias
  end
  
  
  #--------------------------------------------------------------------------
  # alias : execute_damage
  #--------------------------------------------------------------------------
  alias execute_damage_bubs_blocking execute_damage
  def execute_damage(user)
    execute_damage_bubs_blocking(user)
    on_block(user, @result.blocked_damage) if @result.blocked_damage > 0
  end

  #--------------------------------------------------------------------------
  # new method : apply_block
  #--------------------------------------------------------------------------
  def apply_block(damage)
    return damage unless @result.blocked || @result.critical_blocked
    damage = apply_block_value(damage)
    damage = apply_block_reduction_rate(damage)
  end
  
  #--------------------------------------------------------------------------
  # new method : blockable_hit_types
  #--------------------------------------------------------------------------
  def blockable_hit_types
    Bubs::Blocking::BLOCKABLE_HIT_TYPES
  end
  
  #--------------------------------------------------------------------------
  # new method : check_block
  #--------------------------------------------------------------------------
  def check_block(user, item)
    # Avoids block checking more than once
    return if @result.block_checked
    return unless item.damage.to_hp?
    @result.block_checked = true

    # Check for unblockable flag
    return if check_unblockable(user, item)
    
    # Do block checks and rolls
    @result.blocked = (can_block? && block?)
    @result.critical_blocked = (can_critical_block? && critical_block?)
    
    # Cancel out critical if blocked
    if @result.blocked || @result.critical_blocked
      @result.critical = false if cancel_critical_hits?
    end
  end
  
  #--------------------------------------------------------------------------
  # new method : unblockable_elements
  #--------------------------------------------------------------------------
  def unblockable_elements(element_id)
    Bubs::Blocking::UNBLOCKABLE_ELEMENTS.include?(element_id)
  end
  
  #--------------------------------------------------------------------------
  # new method : unblockable_skill_types
  #--------------------------------------------------------------------------
  def unblockable_skill_types(stype_id)
    Bubs::Blocking::UNBLOCKABLE_SKILL_TYPES.include?(stype_id)
  end
  
  #--------------------------------------------------------------------------
  # new method : check_unblockable
  #--------------------------------------------------------------------------
  def check_unblockable(user, item)
    # Unblockable attack check
    return true if item.unblockable
    # Blockable hit type check
    return true unless blockable_hit_types.include?(item.hit_type)
    # Unblockable element check
    return true if unblockable_elements(item.damage.element_id)
    # Unblockable skill type check
    return true if item.is_a?(RPG::Skill) && unblockable_skill_types(item.stype_id)
    return false
  end
  
  #--------------------------------------------------------------------------
  # new method : block?
  #--------------------------------------------------------------------------
  def block?
    rand < blc # Block roll
  end
  
  #--------------------------------------------------------------------------
  # new method : critical_block?
  #--------------------------------------------------------------------------
  def critical_block?
    rand < cbl # Critical block roll
  end
  
  #--------------------------------------------------------------------------
  # new method : apply_block_value
  #--------------------------------------------------------------------------
  def apply_block_value(damage)
    block_variance = Bubs::Blocking::BLV_VARIANCE
    block_value = apply_block_value_variance(blv, block_variance)
    return damage if block_value <= 0
    
    # Apply critical block multiplier
    block_value *= blv_multiplier if @result.critical_blocked
    # Determine min/max block value
    block_value = [[0, block_value].max, blv_max].min
    
    old_damage = damage
    damage = [damage - block_value, 0].max
    # Keep track of amount of damage blocked
    @result.blocked_damage += (old_damage - damage).to_i
    return damage
  end
  
  #--------------------------------------------------------------------------
  # new method : apply_block_reduction_rate
  #--------------------------------------------------------------------------
  def apply_block_reduction_rate(damage)
    block_rate = blr
    return damage if block_rate <= 0
    
    # Apply critical block multiplier
    block_rate *= blr_multiplier if @result.critical_blocked
    # Determine min/max block rate
    block_rate = [[0, block_rate].max, blr_max].min
    # Calculate damage rate
    block_rate = (1 - block_rate)
    old_damage = damage
    # Scale the damage
    damage *= block_rate
    # Keep track of amount of damage blocked
    @result.blocked_damage += (old_damage - damage).to_i
    
    return damage
  end
  
  #--------------------------------------------------------------------------
  # new method : apply_block_value_variance
  #--------------------------------------------------------------------------
  def apply_block_value_variance(block_value, variance)
    amp = [block_value.abs * variance / 100, 0].max.to_i
    var = rand(amp + 1) + rand(amp + 1) - amp
    block_value = block_value + var
  end
  
  #--------------------------------------------------------------------------
  # new method : blv_multiplier     # For critical blocks
  #--------------------------------------------------------------------------
  def blv_multiplier
    return actor_block_settings(:critical_blv_multiplier) if actor? 
    return enemy_block_settings(:critical_blv_multiplier)
  end
  
  #--------------------------------------------------------------------------
  # new method : blr_multiplier     # For critical blocks
  #--------------------------------------------------------------------------
  def blr_multiplier
    return actor_block_settings(:critical_blr_multiplier) if actor? 
    return enemy_block_settings(:critical_blr_multiplier)
  end
  
  #--------------------------------------------------------------------------
  # new method : cancel_critical_hits?
  #--------------------------------------------------------------------------
  def cancel_critical_hits?
    return actor_block_settings(:cancel_critical_hits) if actor? 
    return enemy_block_settings(:cancel_critical_hits)
  end
  
  #--------------------------------------------------------------------------
  # new method : tp_gain_on_block_formula
  #--------------------------------------------------------------------------
  def tp_gain_on_block_formula
    return actor_block_settings(:tp_gain) if actor? 
    return enemy_block_settings(:tp_gain)
  end
  
  #--------------------------------------------------------------------------
  # new method : charge_tp_by_block          # Charge TP by Damage Blocked
  #--------------------------------------------------------------------------
  def charge_tp_by_block(blocked_damage)
    self.tp += Float(eval(tp_gain_on_block_formula))
  end
  
  #--------------------------------------------------------------------------
  # new method : on_block            # Executes whenever damage is blocked
  #--------------------------------------------------------------------------
  def on_block(user, blocked_damage)
    charge_tp_by_block(blocked_damage)
  end

end # class Game_Battler



#==============================================================================
# ++ Game_ActionResult
#==============================================================================
class Game_ActionResult
  #--------------------------------------------------------------------------
  # * Public Instance Variables
  #--------------------------------------------------------------------------
  attr_accessor :blocked                  # block flag
  attr_accessor :critical_blocked         # critical block flag
  attr_accessor :blocked_damage           # total damage blocked
  attr_accessor :block_checked            # block chance check determined flag
  #--------------------------------------------------------------------------
  # alias : clear_hit_flags
  #--------------------------------------------------------------------------
  alias clear_hit_flags_bubs_blocking clear_hit_flags
  def clear_hit_flags
    clear_hit_flags_bubs_blocking # alias
    
    @blocked = false
    @critical_blocked = false
    @block_checked = false
  end
  
  #--------------------------------------------------------------------------
  # alias : clear_damage_values
  #--------------------------------------------------------------------------
  alias clear_damage_values_bubs_blocking clear_damage_values
  def clear_damage_values
    clear_damage_values_bubs_blocking # alias
    
    @blocked_damage = 0
  end
  
  #--------------------------------------------------------------------------
  # new method : blocked?
  #--------------------------------------------------------------------------
  def blocked?
    @blocked || @critical_blocked
  end
  
  #--------------------------------------------------------------------------
  # new method : block_damage_text
  #--------------------------------------------------------------------------
  def block_damage_text
    if @critical_blocked # Critical blocks
      if @battler.actor?
        fmt = Vocab::ActorCritBlock
      else
        fmt = Vocab::EnemyCritBlock
      end
      sprintf(fmt, @battler.name, @blocked_damage.to_i)
    elsif @blocked # Normal blocks
      if @battler.actor?
        fmt = Vocab::ActorBlock
      else
        fmt = Vocab::EnemyBlock
      end
      sprintf(fmt, @battler.name, @blocked_damage.to_i)
    else
      ""
    end
  end # def block_damage_text
  
end # class Game_ActionResult



#==============================================================================
# ++ Window_BattleLog
#==============================================================================
class Window_BattleLog < Window_Selectable
  #--------------------------------------------------------------------------
  # alias : display_hp_damage
  #--------------------------------------------------------------------------
  alias display_hp_damage_bubs_blocking display_hp_damage
  def display_hp_damage(target, item)
    return if item && !item.damage.to_hp?
    
    display_blocked_damage(target, item)
    
    display_hp_damage_bubs_blocking(target, item) # alias
  end
  
  #--------------------------------------------------------------------------
  # alias : display_blocked_damage
  #--------------------------------------------------------------------------
  def display_blocked_damage(target, item)
    if target.result.blocked || target.result.critical_blocked
      # Play SE
      Sound.play_block if target.result.blocked
      Sound.play_critical_block if target.result.critical_blocked
      return if $imported["YEA-BattleEngine"]
      # Block battle text
      add_text(target.result.block_damage_text)
      wait
    end
  end
  
end # class Window_BattleLog



if $imported["YEA-StatusMenu"]
#==============================================================================
# ++ Window_StatusItem
#==============================================================================
class Window_StatusItem < Window_Base
  #--------------------------------------------------------------------------
  # alias : draw_property
  #--------------------------------------------------------------------------
  alias draw_property_bubs_blocking draw_property
  def draw_property(property, dx, dy, dw)
    fmt = "%1.2f%%"
    case property[0]
    #---
    when :blv
      return dy unless $imported["BubsBlocking"]
      fmt = "%d"
      value = sprintf(fmt, @actor.blv)
    when :blr
      return dy unless $imported["BubsBlocking"]
      value = sprintf(fmt, @actor.blr * 100)
    when :blc
      return dy unless $imported["BubsBlocking"]
      value = sprintf(fmt, @actor.blc * 100)
    when :cbl
      return dy unless $imported["BubsBlocking"]
      value = sprintf(fmt, @actor.cbl * 100)
    #---
    else
      return draw_property_bubs_blocking(property, dx, dy, dw) # alias
    end
    colour = Color.new(0, 0, 0, translucent_alpha/2)
    rect = Rect.new(dx+1, dy+1, dw-2, line_height-2)
    contents.fill_rect(rect, colour)
    change_color(system_color)
    draw_text(dx+4, dy, dw-8, line_height, property[1], 0)
    change_color(normal_color)
    draw_text(dx+4, dy, dw-8, line_height, value, 2)
    return dy + line_height
  end
end # class Window_StatusItem

end # if $imported["YEA-StatusMenu"]



if $imported["YEA-BattleEngine"]
#==============================================================================
# ++ Game_BattlerBase
#==============================================================================
class Game_BattlerBase
  #--------------------------------------------------------------------------
  # compatibility alias : make_miss_popups
  #--------------------------------------------------------------------------
  alias make_miss_popups_bubs_blocking make_miss_popups
  def make_miss_popups(user, item)
    make_miss_popups_bubs_blocking(user, item) # alias
    
    if @result.hit? && @result.blocked?
      text = Vocab::ABE_Block
      text = Vocab::ABE_CritBlock if @result.critical_blocked
      rules = "DEFAULT"
      create_popup(text, rules)
    end
  end
end # class Game_BattlerBase

end # if $imported["YEA-BattleEngine"]

 

 

 

Share this post


Link to post
Share on other sites

Before FailBox *cough* sorry, Dropbox, Mr.Bubble used Pastebin.  While it doesn't have his most recent scripts like the ToG Title System, nor does it have the most updated versions of some scripts(The Crafting system posted above for example is newer), it has most everything else which is better than nothing.

 

https://pastebin.com/u/mrbubble

Edited by Selchar

Share this post


Link to post
Share on other sites
5 hours ago, Selchar said:

Before FailBox *cough* sorry, Dropbox, Mr.Bubble used Pastebin.  While it doesn't have his most recent scripts like the ToG Title System, nor does it have the most updated versions of some scripts(The Crafting system posted above for example is newer), it has most everything else which is better than nothing.

 

https://pastebin.com/u/mrbubble

 

Awesome find. Had no idea (and I searched)

Share this post


Link to post
Share on other sites

Spent some time going through what games/projects I could find that credit Mr.Bubble.  Found his Mix FF5 ver 2.0 script that way.

 

 

# ╔═══════════════════════════════════════════════════════╤═══════╤═══════════╗
# ║ FF5 "Mix"                                             │ v2.00 │ (5/25/13) ║
# ╚═══════════════════════════════════════════════════════╧═══════╧═══════════╝
# Script by:
#     Mr. Bubble ( http://mrbubblewand.wordpress.com/ )
#--------------------------------------------------------------------------
# This script is based on the Chemist job class command "Mix" from Final 
# Fantasy 5. Mix allows the user to mix any items from the party's inventory 
# for a variety of effects in battle.
#
# All item combination formulae must be defined in the customization 
# module.
#--------------------------------------------------------------------------
#   ++ Changelog ++ 
#--------------------------------------------------------------------------
# v2.00 : You can now mix any amount of items together.
#       : You can now create mix formulae for any number of items.
#       : Combination search algorithm changed.
#       : The <mix> tag has changed.
#       : Script call 'get_mix_id_result' has changed. (5/25/2013)
# v1.03 : Added developer utility script calls. (8/04/2012)
# v1.02 : Compatibility: "YEA-BattleCommandList" support added.
#       : Compatibility: "YEA-BattleEngine" support added.
#       : Fixed issues related to Attack Times+.
#       : Unused mix items are now properly returned after battle.
#       : Unused mix items are now properly returned when an actor dies.
#       : Unused mix items are now properly returned when switching actors.
#       : Console window now outputs when items are returned to inventory.
#       : Game_Actor#prior_command is no longer aliased.
#       : Comments added/changed. 
#       : Efficiency update. (8/03/2012)
# v1.01 : Compatibility: Mix window properly resized for "YEA-BattleEngine".
#       : Fixed crashes when using items normally. 
#       : Efficiency update with console output. (8/03/2012)
# v1.00 : Initial release. (8/02/2012)
#--------------------------------------------------------------------------
#   ++ Installation ++
#--------------------------------------------------------------------------
# Install this script in the Materials section in your project's
# script editor.
#
# I recommend pasting this script below all other scripts that also
# modify the battle system in your script editor.
#--------------------------------------------------------------------------
#   ++ Usage Notes ++
#--------------------------------------------------------------------------
# --The targeting Scope of the result item will stay intact when made 
#   through mixed items. If the result item requires a player-selected
#   target, the player can do so.
#
# --Spelling is very important with this script. Because of the high 
#   potential for user-errors to occur in regards with spelling errors, 
#   I've provided the option to have messages appear in the Playtest 
#   console window whenever certain errors or spelling mistakes associated 
#   with this script are encountered.
#
# --Item ID combinations will always take precedence over Mix Type 
#   combinations if the selected mix items have a potential result 
#   in both.
#
# --If DEBUG_INFO is true, you will sometimes be informed in the console 
#   window whenever mix items are returned to the party's inventory.
#   Please report to me when items are supposed to be returned to you but
#   are not with information on how to reproduce it.
#=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
#   ++ Notetags ++
#=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
# Note: Some tags are given shorter tags for typing convenience. You only
#       need to use one <tag> from a given group for a notebox. 
#       Use common sense.
#
# The following Notetags are for Skills only:
#
# <mix>
# <mix: n>
#   This tag turns the skill into a Mix skill, where n is the maximum
#   number of items the actor can mix together. When a Mix 
#   skill is selected in battle, a window with all possible mixable items 
#   will appear. The player will not know what item is produced until the
#   item is actually used. Mix skills do not have any special effect 
#   outside of battle. If n is not included with the tag, the default
#   maximum item selection is 2.
#
#--------------------------------------------------------------------------
# The following Notetags are for Items only:
#
# <mixtype: type>
#   This tag defines an item's Mix Type where type is any type name you 
#   defined in MIX_TYPES in the customization module WITHOUT the colon. For 
#   more information about Mix Types, see the comments in the Mix Type 
#   Formulae section in the customization module. If the type in the tag 
#   is not found in MIX_TYPES, a message in the console will tell you.
#
# <unmixable>
# <no mix>
#   This tag will flag the item as unmixable. Items with this tag will
#   not appear in the Mix window.
#
#=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
#   ++ Script Calls ++
#=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
# The following script calls are meant to be used in "Script..." event 
# commands found under Tab 3 when creating a new event command.
#
# output_mix_formulae(:id)
# output_mix_formulae(:type)
#   This script call will output all possible Mix ID formulae or Mix Type 
#   formulae to the console window.
#
# get_mix_id_result(id, id, id...)
#   Get the Item ID result of any given Item IDs where id is
#   Item ID numbers from your database. You can list any number of ID 
#   numbers separated by commas as you like. If a result cannot be found
#   with the given ID number arguments, it will return 0. This script 
#   call is meant to be used in the "Script" box within "Control Variable" 
#   event commands.
#
#--------------------------------------------------------------------------
#   ++ FAQ ++
#--------------------------------------------------------------------------
# --I received the Syntax Error "unexpected tLBRACK, expecting '}'. How 
#   do I fix it?
#
#     This means you forgot the comma after the result_item_id number.
#
# --How do I stop the debug messages from appearing in the console window?
#
#     Set DEBUG_INFO to false in the customization module.
#
#--------------------------------------------------------------------------
#   ++ Compatibility ++
#--------------------------------------------------------------------------
# !! IMPORTANT !!
# Due to the nature of this script, script incompatibilities with other
# scripts is likely and expected. Please do not ask if [insert script here]
# is compatible with this script. You can test it yourself.
# 
# Custom battle systems are very likely to have issues with this script
# especially ones that are not turn-based like the default battle system.
#
# If you run into incompatibilities, please report them to me with a link 
# to the script and I will try to make it compatible.
#
# This script aliases the following default VXA methods:
#
#     DataManager#load_normal_database
#     DataManager#load_battle_test_database
#     DataManager#load_database
#     Game_Action#clear
#     Game_Actor#initialize
#     Game_Actor#use_item
#     Game_Actor#consume_item
#     Game_Actor#on_turn_end
#     Game_Actor#clear_actions
#     Game_Actor#item_conditions_met
#     Scene_Battle#on_skill_ok
#     Scene_Battle#on_enemy_ok
#     Scene_Battle#on_enemy_cancel
#     Scene_Battle#on_actor_ok
#     Scene_Battle#on_actor_cancel
#     Scene_Battle#start_actor_command_selection
#    
# There are no default method overwrites.
#
# This script has built-in compatibility with the following scripts:
#
#     Yanfly Engine Ace – Ace Battle Engine
#     Yanfly Engine Ace – Battle Command List
#
# Requests for compatibility with other scripts are welcome.
#--------------------------------------------------------------------------
#   ++ Terms and Conditions ++
#--------------------------------------------------------------------------
# Please do not repost this script elsewhere without permission. 
# Free for non-commercial use. For commercial use, contact me first.
#
# Newest versions of this script can be found at 
#                                           http://mrbubblewand.wordpress.com/
#==============================================================================

$imported ||= {}
$imported["BubsMix"] = true

#==========================================================================
# ++ START OF USER CUSTOMIZATION MODULE ++
#==========================================================================
module Bubs
  #==========================================================================
  # ++ Mix Settings
  #==========================================================================
  module Mix
  #--------------------------------------------------------------------------
  #   Default Mix Result Item ID
  #--------------------------------------------------------------------------
  # This defines the default item ID that is used when absolutely no 
  # formula is found for a chosen item combination.
  DEFAULT_MIX_RESULT_ITEM_ID = 1
  
  #--------------------------------------------------------------------------
  #   Unmixable Item IDs
  #--------------------------------------------------------------------------
  # This setting allows you define the Item IDs that are ineligible to be
  # selected in a mix combination. You can list as many Item IDs in the 
  # array as you like. This setting has the same effect as the <unmixable> 
  # tag.
  UNMIXABLE_ITEMS = []
  
  #--------------------------------------------------------------------------
  #   Debug Info Setting
  #--------------------------------------------------------------------------
  # This setting determines whether debug messages related to this
  # script will appear in the console window during Playtests.
  #
  # I highly recommend that you keep this setting true until your
  # game is complete.
  DEBUG_INFO = true
  
  #--------------------------------------------------------------------------
  #   Selected Mix Item Color Index
  #--------------------------------------------------------------------------
  # This setting determines the color a selected item in the Mix window
  # turns into. The value is a Window skin color index.
  SELECTED_MIX_ITEM_COLOR = 2 # Default 2 (orange)
  
  #--------------------------------------------------------------------------
  #   Item ID Formulae
  #--------------------------------------------------------------------------
  # This hash is where you define Item ID formulae. The syntax for defining
  # a formula is:
  #
  #       [item_id, item_id] => result_item_id,
  #
  # item_id is any existing item_id from your database. result_item_id is 
  # the item that will be used as a result of combination. The
  # colloquial term for "=>" is "hashrocket". Just think of it as an arrow
  # that points to the result item. The order of item_ids in the array does
  # not matter. That means [1,2] is the same as [2,1].
  #
  # ALWAYS remember the comma at the end of result_item_id or you will get
  # a Syntax Error.
  #
  # You can create mix combinations using any number of items.
  #
  # I *highly* recommend that you include comments for your own formulae 
  # so that you can easily reference them.
  MIX_FORMULA_BY_ID = {
    # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
    #   Create your own formulae starting here.
    # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
    # Potion + Potion = Hi-Potion
    [1, 1] => 2,
    # Potion + Hi-Potion = Stimulant
    [1, 2] => 5,
    # Hi-Potion + Hi-Potion = Full Potion
    [2, 2] => 3,
    # Full Potion + Magic Water = Elixir
    [3, 4] => 8,
    # Antidote + Antidote = Dispel Herb
    [6, 6] => 7,
    # Potion + Potion + Potion = Full Potion
    [1, 1, 1] => 3,
    
    
    
    
    
    # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
  } # <- Do not delete.
  
  #--------------------------------------------------------------------------
  #   Mix Types
  #--------------------------------------------------------------------------
  # This array is where you define Mix Types. Mix Types are basically
  # categories of mix items that you define. Items are assigned Mix Types
  # with the <mixtype: type> tag (see ++ Notetags ++ for more info).
  #
  # You must always add the name of any new Mix Types that you create
  # into this array. If DEBUG_INFO is true, you will be informed of any
  # missing Mix Types.
  # 
  # You can list as many Mix Types in the array separated by commas as 
  # you like.
  #
  # Mix Types are represented by symbols meaning that they begin with a 
  # colon ":". They should appear orange in the script editor. If the 
  # symbol is not orange, you are typing the symbol incorrectly.
  #
  # !! Important !!
  # :none must always be the first symbol listed in this array. However,
  # it can still be used in Mix Type formulae.
  MIX_TYPES = [:none, :potions1, :potions2, :statup]
  
  #--------------------------------------------------------------------------
  #   Mix Type Formulae
  #--------------------------------------------------------------------------
  # This hash is where you define Mix Type formulae. Mix Types are basically
  # categories of mix items that you define. Items are assigned Mix Types
  # with the <mixtype: type> tag (see ++ Notetags ++ for more info).
  #
  # Mix Types were created because it can be daunting to create item mix
  # formulae for every single possible item ID combination in a project.
  # To ease game development, you are able to use general category types 
  # that can combine into different results in the event that a specific 
  # item ID formula is not found.
  #
  # The syntax for defining a formula is:
  #
  #       [:mix_type, :mix_type] => result_item_id,
  #
  # :mix_type is any symbol that you created and defined in the MIX_TYPES
  # array. result_item_id is the item that will be used as a result of 
  # the type combination. The colloquial term for "=>" is "hashrocket". Just 
  # think of it as an arrow that points to the result. The order of the 
  # symbols in the array does not matter. That means [:potions1, :potions2] 
  # is the same as [:potions2, :potions1].
  #
  # ALWAYS remember the comma at the end of result_item_id or you will get
  # a Syntax Error.
  #
  # You can create mix combinations using any number of items.
  #
  # Mix Types are represented by symbols meaning that they begin with 
  # a colon ":". They should appear orange in the script editor. If the
  # symbol is not orange, you are typing the symbol incorrectly.
  MIX_FORMULA_BY_TYPE = {
    # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
    #   Create your own formulae starting here.
    # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
    # Potions 1 + Potions 1 = Hi-Potion
    [:potions1, :potions1] => 2,
    
    # Potions 1 + Potions 2 = Full Potion
    [:potions1, :potions2] => 3,
    
    # Potions 2 + Potions 2 = Full Potion
    [:potions2, :potions2] => 3,
    
    # Potions 1 + Stat Up = Stimulant
    [:potions1, :statup]   => 5,
    
    # Potions 2 + Stat Up = Elixir
    [:potions2, :statup]   => 8,
    
    # Stat Up + Stat Up = Elixir
    [:statup, :statup]     => 8,
        
    # Potions 1 + Potions 1 + Potions 1 = Full Potion
    [:potions1, :potions1, :potions1] => 3,
    
    # Potions 1 + Potinos 1 + Potions 2 = Full Potion
    [:potions1, :potions1, :potions2] => 3,
    
    
    # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
  } # <- Do not delete.

  end # module Mix
end # module Bubs

#==========================================================================
# ++ END OF USER CUSTOMIZATION MODULE ++
#==========================================================================


#==========================================================================
# ++ MixData
#------------------------------------------------------------------------------
#  This class performs formulae initialization defined by the user and 
# is used to compare player mix item choices what is possible. Also handles 
# developer error messages.
#==========================================================================
class MixData
  #--------------------------------------------------------------------------
  # public instance variables
  #--------------------------------------------------------------------------
  attr_reader :id_formula         # stores all id formulae
  attr_reader :type_formula       # stores all mix type formulae
  attr_reader :type_values        # stores mix type integer values
  attr_accessor :debug_info       # debug window message flag
  attr_accessor :default_mix_id   # default item id for failed mixes
  #--------------------------------------------------------------------------
  # initialize
  #--------------------------------------------------------------------------
  def initialize
    @id_formula = {}
    @type_formula = {}
    @type_values = {}
    @debug_info = Bubs::Mix::DEBUG_INFO
    @default_mix_id = Bubs::Mix::DEFAULT_MIX_RESULT_ITEM_ID
    create_type_values
    create_id_formula
    create_type_formula
  end
  
  #--------------------------------------------------------------------------
  # create_type_values
  #--------------------------------------------------------------------------
  def create_type_values
    Bubs::Mix::MIX_TYPES.each_with_index do |symbol, index|
      @type_values[symbol] = index
    end
    # Sets default return value to 0 if key is not found
  end
  
  #--------------------------------------------------------------------------
  # create_id_formula
  #--------------------------------------------------------------------------
  def create_id_formula
    Bubs::Mix::MIX_FORMULA_BY_ID.each do |key, value|
      @id_formula[key.sort] = value
    end
    @id_formula.default = 0
  end
  
  #--------------------------------------------------------------------------
  # create_type_formula
  #--------------------------------------------------------------------------
  def create_type_formula
    Bubs::Mix::MIX_FORMULA_BY_TYPE.each do |key, value|
      key.each { |symbol| output_type_formula_error(symbol) }
      # converts symbols to integer values based on the index of the key
      # in MIX_TYPES
      array = key.collect { |symbol| get_mix_type_value(symbol) }
      array.sort!
      @type_formula[array] = value
    end # do
    @type_formula.default = 0
  end
  
  #--------------------------------------------------------------------------
  # test_item_type_symbol
  #--------------------------------------------------------------------------
  def test_item_type_symbol(item)
    output_mix_type_error(item) unless mix_type_ok?(item)
  end
  
  #--------------------------------------------------------------------------
  # mix_type_ok?
  #--------------------------------------------------------------------------
  # Checks item's mix_type symbol was provided by the user.
  def mix_type_ok?(item)
    Bubs::Mix::MIX_TYPES.include?(item.mix_type)
  end

  #--------------------------------------------------------------------------
  # output_mix_type_error
  #--------------------------------------------------------------------------
  def output_mix_type_error(item)
    return unless $TEST && @debug_info
    p sprintf("An error occurred with Item ID %s: %s", item.id, item.name)
    p sprintf(":%s does not exist in MIX_TYPES", item.mix_type)
  end
  
  #--------------------------------------------------------------------------
  # output_mix_id_result
  #--------------------------------------------------------------------------
  def output_mix_id_result(id_array, result_id) #(item1, item2, result_item)
    return unless $TEST && @debug_info
    names = id_array.collect { |id| $data_items[id].name }.join(" + ")
    # If you get an error on this line, it means that the result item ID
    # doesn't exist in your database.
    result_name = $data_items[result_id].name
    p sprintf("%s = %s", names, result_name)
  end
  
  #--------------------------------------------------------------------------
  # output_mix_type_result
  #--------------------------------------------------------------------------
  def output_mix_type_result(id_array, result_id) #(item1, item2, result_item)
    return unless $TEST && @debug_info
    symbols = id_array.collect { |symbol| symbol.to_s }.join(" + ")
    # If you get an error on this line, it means that the result item ID
    # doesn't exist in your database.
    result_name = $data_items[result_id].name
    p sprintf("%s = %s", symbols, result_name)
  end
  
  #--------------------------------------------------------------------------
  # output_default_result
  #--------------------------------------------------------------------------
  def output_default_result
    return unless $TEST && @debug_info
    name = $data_items[@default_mix_id].name
    p sprintf("Default mix result: %s", name)
  end
  
  #--------------------------------------------------------------------------
  # output_nil_result_error
  #--------------------------------------------------------------------------
  def output_nil_result_error(item, id)
    return unless $TEST && @debug_info
    return unless item.nil?
    p sprintf("Item ID %s doesn't exist in your Database!", id)
  end
  
  #--------------------------------------------------------------------------
  # output_type_formula_error
  #--------------------------------------------------------------------------
  def output_type_formula_error(symbol)
    return unless $TEST && @debug_info
    return if Bubs::Mix::MIX_TYPES.include?(symbol)
    p "An error occurred with a Mix Type formula:"
    p sprintf(":%s does not exist in MIX_TYPES", symbol)
  end
  
  #--------------------------------------------------------------------------
  # output_returned_items
  #--------------------------------------------------------------------------
  def output_returned_items(id_array) #(item1, item2)
    return unless $TEST && @debug_info
    names = id_array.collect { |id| $data_items[id].name }.join(", ")
    p sprintf("Returned mix items: %s ", names)
  end
  
  #--------------------------------------------------------------------------
  # output_all_id_formulae
  #--------------------------------------------------------------------------
  def output_all_id_formulae
    p "--Displaying all Mix Item ID formulae:"
    @id_formula.each do |key, value|
      #result_name = $data_items[value]
      output_mix_id_result(key, value)
    end
  end
  
  #--------------------------------------------------------------------------
  # output_all_type_formulae
  #--------------------------------------------------------------------------
  def output_all_type_formulae
    p "--Displaying all Mix Type formulae:"
    Bubs::Mix::MIX_FORMULA_BY_TYPE.each do |key, value|
      result_name = $data_items[value].name
      names = key.collect {|type| ":" + type.to_s }.join(" + ")
      p sprintf("%s = %s", names, result_name)
    end
  end
  
  #--------------------------------------------------------------------------
  # get_id_result
  #--------------------------------------------------------------------------
  # Used in Game_Interpreter
  def get_id_result(id_array)#(id1, id2)
    return @id_formula[id_array.sort]
  end
    
  #--------------------------------------------------------------------------
  # get_mix_type_value
  #--------------------------------------------------------------------------
  # returns the value the given mix type symbol
  # returns 0 if symbol does not exist
  def get_mix_type_value(symbol)
    @type_values[symbol]
  end
  
  #--------------------------------------------------------------------------
  # determine_id_formula
  #--------------------------------------------------------------------------
  # Compares the pair of item IDs to find any matching mix formula
  # returns 0 if none is found
  def determine_id_formula(id_array) #(item1, item2)
    return @id_formula[id_array.sort]
  end
  
  #--------------------------------------------------------------------------
  # determine_type_formula
  #--------------------------------------------------------------------------
  # Compares the pair of item mix_types to find any matching mix formula
  # returns 0 if none is found
  def determine_type_formula(id_array) #(item1, item2)
    type_array = id_array.collect {|id| $data_items[id].mix_type }
    type_values = type_array.collect {|type| get_mix_type_value(type) }
    type_values.sort!
    return @type_formula[type_values]
  end
  
  #--------------------------------------------------------------------------
  # process_id_formula_result
  #--------------------------------------------------------------------------
  def process_id_formula_result(id_array, result_id) #(item1, item2, id)
    result = $data_items[result_id]
    output_nil_result_error(result, result_id)
    output_mix_id_result(id_array, result_id) #item1, item2, result)
    return result
  end
  
  #--------------------------------------------------------------------------
  # process_type_formula_result
  #--------------------------------------------------------------------------
  def process_type_formula_result(id_array, result_id) #(item1, item2, id)
    result = $data_items[id]
    output_nil_result_error(result, id)
    output_mix_type_result(id_array, result_id)
    return result
  end
  
  #--------------------------------------------------------------------------
  # get_mix_item_result
  #--------------------------------------------------------------------------
  # This should be the most used method from this class. Returns an item 
  # to be used after comparing all possible formulae.
  def get_mix_item_result(id_array) #(item1, item2)
    
    # Checks if id formula exists for the two given item arguments
    id = determine_id_formula(id_array) #(item1, item2)
    return process_id_formula_result(id_array, id) if id > 0
    
    # Checks if type formula exists for the two given item arguments
    id = determine_type_formula(id_array) #(item1, item2)
    return process_type_formula_result(id_array, id) if id > 0

    output_default_result
    # return default item id if no formula is found
    return $data_items[@default_mix_id]
  end

end # class MixData

#==========================================================================
# ++ DataManager
#==========================================================================
module DataManager

  #--------------------------------------------------------------------------
  # alias : load_normal_database
  #--------------------------------------------------------------------------
  class << self; alias load_normal_database_bubs_mix load_normal_database; end
  def self.load_normal_database
    load_normal_database_bubs_mix # alias
    
    $data_mix = MixData.new
  end
  #--------------------------------------------------------------------------
  # alias : load_battle_test_database
  #--------------------------------------------------------------------------
  class << self; alias load_battle_test_database_bubs_mix load_battle_test_database; end
  def self.load_battle_test_database
    load_battle_test_database_bubs_mix # alias
    
    $data_mix = MixData.new
  end

  #--------------------------------------------------------------------------
  # alias : load_database
  #--------------------------------------------------------------------------
  class << self; alias load_database_bubs_mix load_database; end
  def self.load_database
    load_database_bubs_mix # alias
    load_notetags_bubs_mix
  end
  
  #--------------------------------------------------------------------------
  # new method : load_notetags_bubs_mix
  #--------------------------------------------------------------------------
  def self.load_notetags_bubs_mix
    groups = [$data_skills, $data_items]
    for group in groups
      for obj in group
        next if obj.nil?
        obj.load_notetags_bubs_mix
      end # for obj
    end # for group
  end # def
  
end # module DataManager


#==========================================================================
# ++ Bubs::Regexp
#==========================================================================
module Bubs
  module Regexp
    MIX_TAG = /<MIX:?\s*(\d+)?>/i
    MIX_TYPE_TAG = /<MIX[_\s]?TYPE:\s*(\w+)>/i
    UNMIXABLE_TAG = /<(?:UNMIXABLE|no[_\s]?mix)>/i
  end # module Regexp
end # module Bubs


#==========================================================================
# ++ RPG::BaseItem
#==========================================================================
class RPG::BaseItem
  #--------------------------------------------------------------------------
  # public instance variables
  #--------------------------------------------------------------------------
  attr_accessor :mix
  attr_accessor :mix_type
  attr_accessor :mix_max_select
  attr_accessor :unmixable
  #--------------------------------------------------------------------------
  # common cache : load_notetags_bubs_mix
  #--------------------------------------------------------------------------
  def load_notetags_bubs_mix
    @mix = false
    @mix_type = :none
    @unmixable = false
    @mix_max_select = 2
    
    if self.is_a?(RPG::Item)
      @unmixable = Bubs::Mix::UNMIXABLE_ITEMS.include?(self.id)
    end
    
    self.note.split(/[\r\n]+/).each { |line|
      case line
      when Bubs::Regexp::MIX_TAG
        @mix = true
        @mix_max_select = $1.to_i unless $1.nil?
        
      when Bubs::Regexp::MIX_TYPE_TAG
        next unless self.is_a?(RPG::Item)
        @mix_type = $1.to_sym
        $data_mix.test_item_type_symbol(self)
        
      when Bubs::Regexp::UNMIXABLE_TAG
        @unmixable = true
        
      end # case
    } # self.note.split
  end # def

end # class RPG::BaseItem

#==========================================================================
# ++ Game_Action
#==========================================================================
class Game_Action
  #--------------------------------------------------------------------------
  # public instance variables
  #--------------------------------------------------------------------------
  attr_accessor :mixed_item  # flag that determine if action was result of Mix
  #--------------------------------------------------------------------------
  # alias : clear
  #--------------------------------------------------------------------------
  alias clear_bubs_mix clear
  def clear
    clear_bubs_mix
    
    @mixed_item = false
  end
end # class Game_Action


#==========================================================================
# ++ Game_Actor
#==========================================================================
class Game_Actor < Game_Battler
  #--------------------------------------------------------------------------
  # public instance variables
  #--------------------------------------------------------------------------
  attr_accessor :mix_items
  #--------------------------------------------------------------------------
  # alias : initialize
  #--------------------------------------------------------------------------
  alias initialize_bubs_mix initialize
  def initialize(actor_id)
    # Mix item combos are kept as a 2D array [[item1, item2], ...]
    @mix_items = []
    
    initialize_bubs_mix(actor_id) # alias
  end
  
  #--------------------------------------------------------------------------
  # alias : use_item
  #--------------------------------------------------------------------------
  alias use_item_bubs_mix use_item
  def use_item(item)
    # pay the item cost of the mix item
    if $game_party.in_battle && current_action && current_action.mixed_item
      consume_mix_items
    end
    
    use_item_bubs_mix(item) # alias
  end
  
  #--------------------------------------------------------------------------
  # alias : consume_item
  #--------------------------------------------------------------------------
  alias consume_item_bubs_mix consume_item
  def consume_item(item)
    # prevent losing item if it was a mixed item
    return if $game_party.in_battle && current_action && current_action.mixed_item
    consume_item_bubs_mix(item) # alias
  end

  #--------------------------------------------------------------------------
  # alias : on_turn_end
  #--------------------------------------------------------------------------
  alias on_turn_end_bubs_mix on_turn_end
  def on_turn_end
    return_all_mix_items
    
    on_turn_end_bubs_mix # alias
  end
  
  #--------------------------------------------------------------------------
  # alias : clear_actions
  #--------------------------------------------------------------------------
  alias clear_actions_bubs_mix clear_actions
  def clear_actions
    clear_actions_bubs_mix # alias
    
    return_all_mix_items
  end
  
  #--------------------------------------------------------------------------
  # alias : item_conditions_met
  #--------------------------------------------------------------------------
  # Avoids the issue of not being to used mixed items when the player
  # doesn't have one in their inventory
  alias item_conditions_met_bubs_mix item_conditions_met?
  def item_conditions_met?(item)
    if $game_party.in_battle && current_action && current_action.mixed_item
      return usable_item_conditions_met?(item)
    else
      return item_conditions_met_bubs_mix(item) # alias
    end
  end
  
  #--------------------------------------------------------------------------
  # new method : consume_mix_items
  #--------------------------------------------------------------------------
  # Pay the cost of the mixed items
  def consume_mix_items
    @mix_items.shift
  end
  
  #--------------------------------------------------------------------------
  # new method : return_last_mix_items
  #--------------------------------------------------------------------------
  # Return last pair of mix items stored by the actor
  def return_last_mix_items
    return if @mix_items.empty?
    id_array = @mix_items.pop
    items = id_array.collect { |id| $data_items[id] }
    items.each { |item| $game_party.gain_item(item, 1) }
    $data_mix.output_returned_items(id_array)
  end
  
  #--------------------------------------------------------------------------
  # new method : return_all_mix_items
  #--------------------------------------------------------------------------
  # Return all mix items stored by the actor
  def return_all_mix_items
    @mix_items.each do |id_array|
      id_array.each {|id| $game_party.gain_item($data_items[id], 1) }
      $data_mix.output_returned_items(id_array)
    end
    @mix_items.clear
  end
  
end # class Game_Actor


#==============================================================================
# ++ Game_Interpreter
#==============================================================================
class Game_Interpreter
  #--------------------------------------------------------------------------
  # new method : output_mix_formulae
  #--------------------------------------------------------------------------
  def output_mix_formulae(symbol = :id)
    case symbol
    when :id
      $data_mix.output_all_id_formulae
    when :type
      $data_mix.output_all_type_formulae
    end
  end
  
  #--------------------------------------------------------------------------
  # new method : get_mix_id_result
  #--------------------------------------------------------------------------
  def get_mix_id_result(*args)#(id1, id2)
    $data_mix.get_id_result(args)
  end
end


#==============================================================================
# ++ Window_MixItem
#==============================================================================
class Window_MixItem < Window_ItemList
  #--------------------------------------------------------------------------
  # public instance variables
  #--------------------------------------------------------------------------
  attr_accessor :selected_items
  attr_accessor :last_window
  attr_accessor :last_item
  attr_accessor :max_select
  #--------------------------------------------------------------------------
  # initialize
  #--------------------------------------------------------------------------
  def initialize(help_window, info_viewport)
    y = help_window.height
    super(0, y, Graphics.width, info_viewport.rect.y - y)
    self.visible = false
    @last_item = Game_BaseItem.new
    @help_window = help_window
    @info_viewport = info_viewport
    @selected_items = []
    @last_window = :skill_window
    @max_select = 1
  end
  
  #--------------------------------------------------------------------------
  # include?
  #--------------------------------------------------------------------------
  def include?(item)
    return false unless item.is_a?(RPG::Item)
    return false if item.unmixable
    return true
  end
  
  #--------------------------------------------------------------------------
  # enable?                             # Display in Enabled State?
  #--------------------------------------------------------------------------
  def enable?(item)
    return false if item.nil?
    return true
  end

  #--------------------------------------------------------------------------
  # show
  #--------------------------------------------------------------------------
  def show
    @help_window.show
    super
  end
  
  #--------------------------------------------------------------------------
  # hide
  #--------------------------------------------------------------------------
  def hide
    @help_window.hide
    super
  end
  
  #--------------------------------------------------------------------------
  # dispose
  #--------------------------------------------------------------------------
  def dispose
    return_selected_items unless disposed?
    super
  end
  
  #--------------------------------------------------------------------------
  # add_item
  #--------------------------------------------------------------------------
  def add_item
    $game_party.lose_item(item, 1)
    @selected_items.push(item.id)
    refresh
  end
  
  #--------------------------------------------------------------------------
  # remove_item
  #--------------------------------------------------------------------------
  def remove_item
    id = @selected_items.pop
    $game_party.gain_item($data_items[id], 1) if id
    refresh
  end
  
  #--------------------------------------------------------------------------
  # clear_selected_items
  #--------------------------------------------------------------------------
  def clear_selected_items
    @selected_items = []
    refresh
  end
  
  #--------------------------------------------------------------------------
  # return_selected_items
  #--------------------------------------------------------------------------
  def return_selected_items
    @selected_items.size.times do remove_item end
    refresh
  end
  
  #--------------------------------------------------------------------------
  # mix_done?
  #--------------------------------------------------------------------------
  def mix_done?
    @last_item.object = item
    return true if @selected_items.size == @max_select
    return false
  end
  
  #--------------------------------------------------------------------------
  # mix_cancel?
  #--------------------------------------------------------------------------
  def mix_cancel?
    return true if @selected_items.empty?
    remove_item
    refresh
    return false
  end

  #--------------------------------------------------------------------------
  # mix_result
  #--------------------------------------------------------------------------
  def mix_result
    return $data_mix.get_mix_item_result(@selected_items)
  end
  
  #--------------------------------------------------------------------------
  # select_last                   # Restore Previous Selection Position
  #--------------------------------------------------------------------------
  def select_last
    select(@data.index(@last_item.object) || 0)
  end

  #--------------------------------------------------------------------------
  # draw_item_name
  #--------------------------------------------------------------------------
  def draw_item_name(item, x, y, enabled = true, width = 172)
    return unless item
    draw_icon(item.icon_index, x, y, enabled)
    change_color(normal_color, enabled)
    selected_mix_item_color if @selected_items.include?(item.id)
    draw_text(x + 24, y, width, line_height, item.name)
  end
  
  #--------------------------------------------------------------------------
  # selected_mix_item_color
  #--------------------------------------------------------------------------
  def selected_mix_item_color
    change_color(text_color(Bubs::Mix::SELECTED_MIX_ITEM_COLOR)) 
  end
  
  #--------------------------------------------------------------------------
  # inh ov : process_handling
  #--------------------------------------------------------------------------
  def process_handling
    super
    #return unless cursor_movable?
    #return process_confirm if handle?(:confirm) && Input.trigger?(:X)
  end
  
  #--------------------------------------------------------------------------
  # process_confirm       # Processing When OK Button Is Pressed
  #--------------------------------------------------------------------------
  def process_confirm
    if @selected_items.empty?
      Sound.play_buzzer
    else
      Sound.play_ok
      Input.update
      deactivate
      call_confirm_handler
    end
  end
  
  #--------------------------------------------------------------------------
  # call_confirm_handler          # Call OK Handler
  #--------------------------------------------------------------------------
  def call_confirm_handler
    call_handler(:confirm)
  end
  
end # class Window_MixItem

#==============================================================================
# ++ Scene_Battle
#==============================================================================
class Scene_Battle < Scene_Base
  #--------------------------------------------------------------------------
  # alias : create_mix_window
  #--------------------------------------------------------------------------
  alias create_all_windows_bubs_mix create_all_windows
  def create_all_windows
    create_all_windows_bubs_mix # alias
    
    create_mix_window
  end
  
  #--------------------------------------------------------------------------
  # new method : create_mix_window
  #--------------------------------------------------------------------------
  def create_mix_window
    @mix_window = Window_MixItem.new(@help_window, @info_viewport)
    @mix_window.set_handler(:ok,          method(:on_mixitem_ok))
    @mix_window.set_handler(:confirm,     method(:on_mixitem_confirm))
    @mix_window.set_handler(:cancel,      method(:on_mixitem_cancel))
    resize_mix_window_yea_abe
  end
  
  #--------------------------------------------------------------------------
  # new method : on_mixitem_ok
  #--------------------------------------------------------------------------
  def on_mixitem_ok
    @mix_window.add_item
    if @mix_window.mix_done?
      @mix_window.hide
      determine_mix_target
    else
      @mix_window.activate
    end
  end
  
  #--------------------------------------------------------------------------
  # new method : on_mixitem_cancel
  #--------------------------------------------------------------------------
  def on_mixitem_cancel
    case @mix_window.last_window
    when :skill_window
      on_mixitem_cancel_to_skill_window
    when :yea_bcl # $imported["YEA-BattleCommandList"]
      on_mixitem_cancel_to_yea_bcl
    end
  end
  
  #--------------------------------------------------------------------------
  # new method : on_mixitem_confirm
  #--------------------------------------------------------------------------
  def on_mixitem_confirm
    if @mix_window.selected_items.empty?
      @mix_window.activate
    else
      @mix_window.hide
      determine_mix_target
    end
  end
  
  #--------------------------------------------------------------------------
  # alias : on_skill_ok
  #--------------------------------------------------------------------------
  alias on_skill_ok_bubs_mix on_skill_ok
  def on_skill_ok
    @skill = @skill_window.item
    
    # set skill cursor memorization
    BattleManager.actor.last_skill.object = @skill
    
    # override normal skill processing if Mix skill
    if @skill.mix
      @mix_window.return_selected_items
      @mix_window.last_window = :skill_window
      @mixing = true
      @skill_window.hide
      @mix_window.max_select = @skill.mix_max_select
      @mix_window.refresh
      @mix_window.show.activate.select(0)
    else
      on_skill_ok_bubs_mix # alias
    end
  end
  
  #--------------------------------------------------------------------------
  # alias : on_enemy_ok
  #--------------------------------------------------------------------------
  alias on_enemy_ok_bubs_mix on_enemy_ok
  def on_enemy_ok
    set_actor_mix_items if @mixing
    #@mixing = false
    
    on_enemy_ok_bubs_mix # alias
  end
  
  #--------------------------------------------------------------------------
  # alias : on_enemy_cancel
  #--------------------------------------------------------------------------
  alias on_enemy_cancel_bubs_mix on_enemy_cancel
  def on_enemy_cancel
    @enemy_window.hide
    if @mixing
      BattleManager.actor.input.clear
      
      if $imported["YEA-BattleEngine"]
        @status_aid_window.refresh
        @status_window.refresh
      end
      
      @mix_window.remove_item
      @mix_window.refresh
      @mix_window.show.activate
      @mix_window.select_last
    else
      on_enemy_cancel_bubs_mix # alias
    end
  end
  
  #--------------------------------------------------------------------------
  # alias : on_actor_ok
  #--------------------------------------------------------------------------
  alias on_actor_ok_bubs_mix on_actor_ok
  def on_actor_ok
    set_actor_mix_items if @mixing
    #@mixing = false
    
    on_actor_ok_bubs_mix # alias
  end

  #--------------------------------------------------------------------------
  # alias : on_actor_cancel
  #--------------------------------------------------------------------------
  alias on_actor_cancel_bubs_mix on_actor_cancel
  def on_actor_cancel
    @actor_window.hide
    if @mixing
      BattleManager.actor.input.clear
      
      if $imported["YEA-BattleEngine"]
        @status_aid_window.refresh
        @status_window.refresh
      end
      
      @mix_window.remove_item
      @mix_window.refresh
      @mix_window.show.activate
      @mix_window.select_last
    else
      on_actor_cancel_bubs_mix # alias
    end
  end
  
  #--------------------------------------------------------------------------
  # alias : start_actor_command_selection
  #--------------------------------------------------------------------------
  alias start_actor_command_selection_bubs_mix start_actor_command_selection
  def start_actor_command_selection
    @mixing = false
    cancel_mix_items
    
    start_actor_command_selection_bubs_mix # alias
  end
  
  #--------------------------------------------------------------------------
  # new method : cancel_mix_items
  #--------------------------------------------------------------------------
  def cancel_mix_items
    actor = BattleManager.actor
    if actor && actor.input.mixed_item
      BattleManager.actor.return_last_mix_items
      BattleManager.actor.input.mixed_item = false
    end
  end

  #--------------------------------------------------------------------------
  # compatibility method : resize_mix_window_yea_abe
  #--------------------------------------------------------------------------
  def resize_mix_window_yea_abe
    return unless $imported["YEA-BattleEngine"]
    @mix_window.height = @skill_window.height
    @mix_window.width = @skill_window.width
    @mix_window.y = Graphics.height - @item_window.height
  end
  
  #--------------------------------------------------------------------------
  # new method : on_mixitem_cancel
  #--------------------------------------------------------------------------
  def on_mixitem_cancel_to_skill_window
    if @mix_window.mix_cancel?
      # return to @skill_window
      @mixing = false
      @mix_window.hide
      @skill_window.refresh
      @skill_window.show.activate
    else
      @mix_window.activate
    end
  end
  
  #--------------------------------------------------------------------------
  # compatibility method : on_mixitem_cancel_to_yea_bcl
  #--------------------------------------------------------------------------
  def on_mixitem_cancel_to_yea_bcl
    if @mix_window.mix_cancel?
      
      # YEA - Battle Engine Ace
      if $imported["YEA-BattleEngine"]
        @status_window.show
        @actor_command_window.show
        @status_aid_window.hide
      end
      
      # return to @actor_command_window
      @mixing = false
      @mix_window.hide
      @actor_command_window.show.activate
    else
      @mix_window.activate
    end
  end
  
  #--------------------------------------------------------------------------
  # compatibility alias : command_use_skill
  #--------------------------------------------------------------------------
  if $imported["YEA-BattleCommandList"]
  alias command_use_skill_bubs_mix command_use_skill
  def command_use_skill
    @skill = $data_skills[@actor_command_window.current_ext]
    # override normal skill processing if Mix skill
    if @skill.mix
      # set skill cursor memorization
      BattleManager.actor.last_skill.object = @skill
      # from YEA-BattleCommandList
      status_redraw_target(BattleManager.actor)
      
      if $imported["YEA-BattleEngine"]
        @status_window.hide
        @actor_command_window.hide
        @status_aid_window.show
      end
      
      # set last_window symbol for cancel memorization
      @mix_window.last_window = :yea_bcl
      @mix_window.return_selected_items
      @mixing = true
      @mix_window.refresh
      @mix_window.show.activate.select(0)
    else
      command_use_skill_bubs_mix # alias
    end # if
  end # def
  end # $imported["YEA-BattleCommandList"]

  #--------------------------------------------------------------------------
  # new method : determine_mix_target
  #--------------------------------------------------------------------------
  def determine_mix_target
    if $imported["YEA-BattleCommandList"]
      determine_mix_target_yea_bcl
    elsif $imported["YEA-BattleEngine"]
      determine_mix_target_yea_abe
    else # default battle system
      @item = @mix_window.mix_result
      BattleManager.actor.input.set_item(@item.id)
      
      if !@item.need_selection?
        set_actor_mix_items # mix
        next_command
      elsif @item.for_opponent?
        select_enemy_selection
      else
        select_actor_selection
      end # if
    end # if
  end

  #--------------------------------------------------------------------------
  # compatibility method : determine_mix_target_yea_abe
  #--------------------------------------------------------------------------
  # This method is only used when "YEA-BattleEngine" is installed
  def determine_mix_target_yea_abe
    @item = @mix_window.mix_result
    $game_temp.battle_aid = @item
    BattleManager.actor.input.set_item(@item.id)
    if @item.for_opponent?
      select_enemy_selection
    elsif @item.for_friend?
      select_actor_selection
    else
      set_actor_mix_items # mix
      next_command
      $game_temp.battle_aid = nil
    end
  end
  
  #--------------------------------------------------------------------------
  # compatibility method : determine_mix_target_yea_bcl
  #--------------------------------------------------------------------------
  # This method is only used when "YEA-BattleCommandList" is installed
  def determine_mix_target_yea_bcl
    @item = @mix_window.mix_result
    BattleManager.actor.input.set_item(@item.id)

    status_redraw_target(BattleManager.actor)
    if $imported["YEA-BattleEngine"]
      $game_temp.battle_aid = @item
      if @item.for_opponent?
        select_enemy_selection
      elsif @item.for_friend?
        select_actor_selection
      else
        set_actor_mix_items # mix
        next_command
        $game_temp.battle_aid = nil
      end
    else
      if !@item.need_selection?
        set_actor_mix_items # mix
        next_command
      elsif @item.for_opponent?
        select_enemy_selection
      else
        select_actor_selection
      end
    end
  end
  
  #--------------------------------------------------------------------------
  # new method : set_actor_mix_items
  #--------------------------------------------------------------------------
  def set_actor_mix_items
    return if @mix_window.selected_items.empty?
    # push mix item pair into the $game_actor
    BattleManager.actor.mix_items.push(@mix_window.selected_items)
    # set current action flag
    BattleManager.actor.input.mixed_item = true
    # clear @selected_items
    @mix_window.clear_selected_items
    @mixing = false
  end

end # class Scene_Battle

 


Then I found his Load Notes from Text Files script in Crystal Noel's Pokemon engine demo.

 

# +--------------------------------------------------------------------------+
# ¦ Load Notes from Text Files                            ¦ v0.2 ¦ (8/28/12) ¦
# +--------------------------------------------------------------------------+
# Script by:
#     Mr. Bubble ( http://mrbubblewand.wordpress.com/ )
# Thanks:
#     Tsukihime, mentioning notebox management issues
#     Victor Sant, mentioning loading notes from txt files
#--------------------------------------------------------------------------
# This script allows you to use .txt files as an extension for database
# noteboxes in hopes that it will help make notebox management much 
# easier. This script only extends Noteboxes meaning you can 
# still use the database Noteboxes normally if you want. Database 
# objects can even share the same .txt files if desired.
#
# From what I heard, there is already an existing script that does what
# this script does. However, I couldn't find it so I wanted to see if I
# could make it myself with certain ideal options for developers. It 
# turned out pretty simple.
#
# Ironically, this script utilizes notetags.
#--------------------------------------------------------------------------
#   ++ Changelog ++
#--------------------------------------------------------------------------
# v0.2 : Efficiency update. (8/28/2012)
# v0.1 : Testing release. (8/26/2012)
#--------------------------------------------------------------------------
#   ++ Installation ++
#--------------------------------------------------------------------------
# Install this script in the Materials section in your project's
# script editor.
# 
# I recommend placing this script above all other custom scripts in 
# your script edtior.
#=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
#   ++ Notetags ++
#=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
# Note: Some tags are given shorter tags for typing convenience. You only
#       need to use one <tag> from a given group for a notebox. 
#       Use common sense.
#
# The following Notetags are for Actors, Classes, Skills, Items,
# Weapons, Armors, Enemies, States, and Tilesets:
#
# <txtnote: filename>
# <txtnote: filename, path>
#   This tag will append the contents of a .txt file to the database
#   object's Notebox where filename is a .txt file name without an 
#   extension. The default directory that is searched is defined in the
#   customization module. You can use this tag as many times as you like 
#   in the same Notebox with different .txt files. The same .txt file can 
#   be used for multiple database objects. path is the directory path 
#   starting from the project's root folder and is optional in the tag. 
#
#   DO NOT USE THIS TAG WITHIN A LOADED .txt FILE!
#
#   Map noteboxes are not supported.
#
#--------------------------------------------------------------------------
#   ++ Text Files ++
#--------------------------------------------------------------------------
# .txt files do not require any special setup. You can treat them like
# a standard notebox.
#
# Word wrap in txt files is not recommended though.
#--------------------------------------------------------------------------
#   ++ Compatibility ++
#--------------------------------------------------------------------------
# This script aliases the following default VXA methods:
#
#     DataManager#load_normal_database
#     DataManager#load_battle_test_database
#
# There are no default method overwrites.
#
# Requests for compatibility with other scripts are welcome.
#--------------------------------------------------------------------------
#   ++ Terms and Conditions ++
#--------------------------------------------------------------------------
# Please do not repost this script elsewhere without permission.
#
# Free for non-commercial and commercial use.
#
# Newest versions of this script can be found at 
#                                         http://mrbubblewand.wordpress.com/
#=============================================================================

$imported ||= {}
$imported["BubsTxtNote"] = true

#==========================================================================
# ++ START OF USER CUSTOMIZATION MODULE ++
#==========================================================================
module Bubs
  module TxtNote
  #--------------------------------------------------------------------------
  #   Default Text File Directory
  #--------------------------------------------------------------------------
  # This setting determines the default directory for .txt files.
  # The root is the root folder of the project.
  #
  # It is recommended that the folder be within a directory that is 
  # automatically encrypted when compressing game data.
  DIR_DEFAULT = "Data/Notes/"
  
  #--------------------------------------------------------------------------
  #   Error Message Setting
  #--------------------------------------------------------------------------
  # true  : Errors related to this script will appear in the console window.
  # false : Errors will not be shown in the console window.
  SHOW_ERROR_MESSAGES = true
  
  end # module TxtNote
end # module Bubs


#==========================================================================
# ++ END OF USER CUSTOMIZATION MODULE ++
#==========================================================================


#==========================================================================
# ++ TxtNoteAppend
#==========================================================================
module DataManager
  #--------------------------------------------------------------------------
  # alias : load_normal_database
  #--------------------------------------------------------------------------
  class << self; alias load_normal_database_bubs_txtnote load_normal_database; end;
  def self.load_normal_database
    load_normal_database_bubs_txtnote # alias
    load_bubs_txtnote
  end
  #--------------------------------------------------------------------------
  # alias : load_battle_test_database
  #--------------------------------------------------------------------------
  class << self; alias load_battle_test_database_bubs_txtnote load_battle_test_database; end;
  def self.load_battle_test_database
    load_battle_test_database_bubs_txtnote # alias
    load_bubs_txtnote
  end

  #--------------------------------------------------------------------------
  # new method : load_bubs_txtnote
  #--------------------------------------------------------------------------
  def self.load_bubs_txtnote
    $game_txtnote = {} #$TEST ? {} : load_data("Data/Text Note.rvdata2")
    groups = [$data_actors, $data_classes, $data_skills, $data_items,
              $data_weapons, $data_armors, $data_enemies, $data_states,
              $data_tilesets]
    for group in groups
      for obj in group
        next if obj.nil?
        obj.load_bubs_txtnote
      end # for
    end # for
    save_data($game_txtnote, "Data/Text Note.rvdata2") if $TEST
  end # def
  
end # module DataManager


#==========================================================================
# ++ Bubs::Regexp
#==========================================================================
module Bubs
  module Regexp
    TXTNOTE_TAG = /<TXTNOTE:\s*(\w+),?\s*(.+)?\s*>/i
  end # module Regexp
end # module Bubs


#==========================================================================
# ++ TxtNoteAppend
#==========================================================================
module TxtNoteAppend
  #--------------------------------------------------------------------------
  # load_bubs_txtnote
  #--------------------------------------------------------------------------
  def load_bubs_txtnote
    @original_notes = self.note.clone
    self.note.split(/[\r\n]+/).each { |line|
      if line =~ Bubs::Regexp::TXTNOTE_TAG
        begin
          if $TEST
            path = get_txtfile($1, $2)
            File.open(path, "r") { |file| append_note(file) }
            File.open(path, "r") { |file| $game_txtnote[path] ||= file.read }
          else
            path = get_txtfile($1, $2)
            self.note << "\r\n" << $game_txtnote[path]
          end
        rescue
          print_txtnote_error($1, $2) if Bubs::TxtNote::SHOW_ERROR_MESSAGES
        end
      end # if
    } # self.note
  end # def
  
  #--------------------------------------------------------------------------
  # append_note
  #--------------------------------------------------------------------------
  def append_note(file)
    self.note << "\r\n" << file.read
  end
  
  #--------------------------------------------------------------------------
  # get_txtfile
  #--------------------------------------------------------------------------
  def get_txtfile(filename, pathname = false)
    prepend_dir(pathname) << filename << txtnote_ext
  end
  
  #--------------------------------------------------------------------------
  # prepend_dir
  #--------------------------------------------------------------------------
  def prepend_dir(pathname)
    pathname ? pathname : txtnote_dir_default
  end
    
  #--------------------------------------------------------------------------
  # txtnote_dir_default
  #--------------------------------------------------------------------------
  def txtnote_dir_default
    Bubs::TxtNote::DIR_DEFAULT.clone
  end
  
  #--------------------------------------------------------------------------
  # ext_default
  #--------------------------------------------------------------------------
  def txtnote_ext
    return ".txt"
  end
  
  #--------------------------------------------------------------------------
  # print_txtnote_error
  #--------------------------------------------------------------------------
  def print_txtnote_error(filename, pathname = false)
    p "#{get_txtfile(filename, pathname)} not found. #{name} note append skipped."
  end
  
end # module DataManager


#==========================================================================
# ++ RPG::BaseItem
#==========================================================================
class RPG::BaseItem
  include TxtNoteAppend
  attr_accessor :original_notes
end


#==========================================================================
# ++ RPG::Tileset
#==========================================================================
class RPG::Tileset
  include TxtNoteAppend
  attr_accessor :original_notes
end 

 


That leaves the following currently unaccounted for.
Tales of Grace Title System(and premade titles vol 1, 2) 1.02
Arbitrary Records 1.0
Too Much Information Item Scene 1.01
Effect: Void Shift 1.3
Battle Rules Display 1.0
State Descriptions 1.0

And these have more up to date versions somewhere.
Blue Magic 1.1
Dismantle Items 1.3
Real Time Cooldowns 1.3

That's as much as I can do in regards to Mr.Bubble's scripts.

Edited by Selchar

Share this post


Link to post
Share on other sites
On 8/14/2018 at 3:23 AM, Amber said:

Not sure if anyone have XS Equip Requirement I can't find it anywhere?

 

Spoiler

#==============================================================================
#   XaiL System - Equip Requirements
#   Author: Nicke
#   Created: 23/08/2012
#   Edited: 25/08/2012
#   Version: 1.0a
#==============================================================================
# Instructions
# -----------------------------------------------------------------------------
# To install this script, open up your script editor and copy/paste this script
# to an open slot below ? Materials but above ? Main. Remember to save.
#
# To setup a item's requirement do the following in the notetag for the
# specified item:
#
# <req: id, id, id...>
# <req: 1,10,20,10,5,15,15,20,10>
# <REQ: 1,10,20,10,5,15,15,20,10>
# Note: Need to be 9 numbers since it represent each parameters.
#
# The numbers represent the following stats:
# Level, Attack, Defense, Magic, Resistance, Agility, Luck, Max HP, Max MP.
# Set to 0 if you don't want to have a requirement for that parameter.
#
# Note: For each item, weapon and armor the default requirements for every
# parameter is 0.
#
# You can also make skills, weapons and armors as requirements:
#
# <req_skills: id, id, id...>
# <req_skills: 2,3,4>
# <REQ_SKILLS: 25,21,10>
#
# <req_weapons: id, id, id...>
# <req_weapons: 3>
# <REQ_WEAPONS: 3, 2>
# 
# <req_armors: id, id, id...>
# <req_armors: 234, 23, 12, 35, 76>
# <REQ_ARMORS: 234, 23, 12, 35, 76>
#
# Note: For skills the actor need to have the specified skill learned in order
# to equip the item.
# For weapons and armors they need to be in the inventory.
#
# *** Only for RPG Maker VX Ace. ***
#==============================================================================
($imported ||= {})["XAIL-EQUIP-REQ"] = true
# *** Don't edit below unless you know what you are doing. ***
#==============================================================================#
# ** RPG::BaseItem
#==============================================================================#
class RPG::BaseItem
  
  # // Method to check equipment requirements.
  def req_equipment_skills
    return split_note(/<(?:REQ_SKILLS|req_skills):[ ]*(\d+(?:\s*,\s*\d+)*)>/i)
  end
  def req_equipment_weapons 
    return split_note(/<(?:REQ_WEAPONS|req_weapons):[ ]*(\d+(?:\s*,\s*\d+)*)>/i)
  end
  def req_equipment_armors 
    return split_note(/<(?:REQ_ARMORS|req_armors):[ ]*(\d+(?:\s*,\s*\d+)*)>/i)
  end
  def req_equipment
    arr = [0] * 9
    n = /<(?:REQ|req):[ ]*(\d+(?:\s*,\s*\d+)*)>/i
    @note.split(/[\r\n]+/).each { |line|
      case line
      when n
        arr.clear
        $1.scan(/\d+/).each { |num|
        arr.push(num.to_i)
        }
      end
    }
    return arr
  end
  
  def split_note(n)
    # // Method to split a note and return an array.
    arr = []
    @note.split(/[\r\n]+/).each { |line|
      case line
      when n
        $1.scan(/\d+/).each { |num|
        arr.push(num.to_i) if num.to_i > 0
        }
      end
    }
    return arr
  end

end
#==============================================================================#
# ** Game_Actor
#==============================================================================#
class Game_Actor < Game_Battler
  
  def optimize_equipments
    # // Method override optimize equipments.
    clear_equipments
    equip_slots.size.times do |i|
      next if !equip_change_ok?(i)
      items = $game_party.equip_items.select do |item|
        item.etype_id == equip_slots[i] &&
        equippable?(item) && item.performance >= 0 && $game_actors[i+1].level >= item.req_equipment[0] && 
        $game_actors[i+1].atk > item.req_equipment[1] && $game_actors[i+1].def > item.req_equipment[2] && 
        $game_actors[i+1].mat > item.req_equipment[3] && $game_actors[i+1].mdf > item.req_equipment[4] && 
        $game_actors[i+1].agi > item.req_equipment[5] && $game_actors[i+1].luk > item.req_equipment[6] && 
        $game_actors[i+1].mhp > item.req_equipment[7] && $game_actors[i+1].mmp > item.req_equipment[8] &&
        SceneManager.scene.item_window.check_skills?(item) && 
        SceneManager.scene.item_window.check_weapons?(item) && 
        SceneManager.scene.item_window.check_armors?(item)
      end
      change_equip(i, items.max_by {|item| item.performance })
    end
  end
  
end
#==============================================================================#
# ** Window_EquipItem
#==============================================================================#
class Window_EquipItem < Window_ItemList
  
  alias xail_equip_req_win_equip_enable? enable? 
  def enable?(item)
    # // Check if item is equippable.
    if @actor.level < item.req_equipment[0] || @actor.atk < item.req_equipment[1] || 
      @actor.def < item.req_equipment[2] || @actor.mat < item.req_equipment[3] ||
      @actor.mdf < item.req_equipment[4] || @actor.agi < item.req_equipment[5] ||
      @actor.luk < item.req_equipment[6] || @actor.mhp < item.req_equipment[7] ||
      @actor.mmp < item.req_equipment[8] || !check_skills?(item) || 
      !check_weapons?(item) || !check_armors?(item)
      return false
    end unless item.nil?
    xail_equip_req_win_equip_enable?(item)
  end
  
  def check_skills?(item)
    # // Method to check if the specified skill is learned.
    item.req_equipment_skills.each {|skill| 
      return false unless @actor.skill_learn?($data_skills[skill])
    }
  end
  
  def check_weapons?(item)
    # // Method to check if specified weapon is in the inventory.
    item.req_equipment_weapons.each {|weapon|
      weapon = $data_weapons[weapon]
      return false if $game_party.item_number(weapon) <= 0
    }
  end
  
  def check_armors?(item)
    # // Method to check if specified armor is in the inventory.
    item.req_equipment_armors.each {|armor|
      armor = $data_armors[armor]
      return false if $game_party.item_number(armor) <= 0
    }
  end

end 
#==============================================================================#
# ** Scene_Equip
#==============================================================================#
class Scene_Equip < Scene_MenuBase 
  
  attr_reader :item_window
  
end # END OF FILE

#=*==========================================================================*=#
# ** END OF FILE
#=*==========================================================================*=#

 


This be it right here.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

  • Recently Browsing   0 members

    No registered users viewing this page.

×