#==============================================================================
# ** Use Skills/Items as Categories for SubObjects in Battle <VERY WIP>
#------------------------------------------------------------------------------
# © 2023 KotatsuAkira
#------------------------------------------------------------------------------
# Do not redistribute without copyright-notice intact.
# Concept & note-commands based on "Skill Extender" for RPGMV by SumRndmDde.
#------------------------------------------------------------------------------
# Use the notes in skills- and items-database to add properties.
# As this is a WIP code blob, some features are partly or completely broken.
#------------------------------------------------------------------------------
# Make skill a subcategory and add skills #123, #456 and #789 to it:
# <ExtendSkills: 123, 456, 789>
# Change subskills display to just text:
# <ExtendSkillsStyle: SIMPLE>
# Set subskills window custom width (default: half of screen-width):
# <ExtendSkillsWidth: 480>
# Set subskills window simple style text alignment (LEFT/CENTER/RIGHT):
# <ExtendSkillsAlign: CENTER>
# Add condition the actor needs to know subskills before they're available:
# <ExtendSkillsLearned>
#==============================================================================
#==============================================================================
# ** Array
#==============================================================================
class Array
#--------------------------------------------------------------------------
# * Push if not included already
#--------------------------------------------------------------------------
def push_once(*sa)
sa.each {|so| push(so) unless include?(so) }
return self
end
end
#==============================================================================
# ** RPG::UsableItem
#==============================================================================
class RPG::UsableItem < RPG::BaseItem
#--------------------------------------------------------------------------
# * Public Instance Variables
#--------------------------------------------------------------------------
attr_accessor :sub_items
attr_accessor :sub_style
attr_accessor :sub_width
attr_accessor :sub_align
#--------------------------------------------------------------------------
# * Check if Item is a Category
#--------------------------------------------------------------------------
def has_sub?
return sub_items.is_a?(Array) && !sub_items.empty?
end
end
#==============================================================================
# ** RPG::Skill
#==============================================================================
class RPG::Skill < RPG::UsableItem
#--------------------------------------------------------------------------
# * Public Instance Variables
#--------------------------------------------------------------------------
attr_accessor :sub_learn
end
#==============================================================================
# ** DataManager
#==============================================================================
module DataManager
#--------------------------------------------------------------------------
# * Module Constants
#--------------------------------------------------------------------------
ALIGNMENT = { "LEFT" => 0, "CENTER" => 1, "RIGHT" => 2 }
#--------------------------------------------------------------------------
# * Definition Redirects
#--------------------------------------------------------------------------
class << self
alias_method(:__original_load_database__, :load_database) unless $@
end
#--------------------------------------------------------------------------
# * Load Database
#--------------------------------------------------------------------------
def self.load_database
__original_load_database__
load_subskills
load_subitems
end
#--------------------------------------------------------------------------
# * Preprocess SubSkills Data
#--------------------------------------------------------------------------
def self.load_subskills
$excluded_skills_menu = []
$excluded_skills_battle = []
$data_skills.each do |sk|
next unless sk
sk.sub_items = []
sk.sub_style = :skill
sk.sub_align = 0
if sk.note.match(/\<ExtendSkills:\s(.*)\>/im)
sk.sub_items = $1.split(/\s*,\s*/).map(&:to_i)
$excluded_skills_menu.push(sk.id)
$excluded_skills_battle.push_once(*sk.sub_items)
end
if sk.note.match(/\<ExtendSkillsStyle:\s(.*)\>/im)
sk.sub_style = $1.upcase == "SIMPLE" ? :simple : :skill
end
if sk.note.match(/\<ExtendSkillsWidth:\s(.*)\>/im)
sk.sub_width = $1.to_i rescue nil
end
if sk.note.match(/\<ExtendSkillsAlign:\s(.*)\>/im)
sk.sub_align = ALIGNMENT[$1.upcase] || 0
end
if sk.note.match(/\<ExtendSkillsLearned\>/im)
sk.sub_learn = true
end
end
end
#--------------------------------------------------------------------------
# * Preprocess SubItems Data
#--------------------------------------------------------------------------
def self.load_subitems
$excluded_items_menu = []
$excluded_items_battle = []
$data_items.each do |si|
next unless si
si.sub_items = []
si.sub_style = :item
si.sub_align = 0
if si.note.match(/\<ExtendItems:\s(.*)\>/im)
si.sub_items = $1.split(/\s*,\s*/).map(&:to_i)
$excluded_items_menu.push(si.id)
$excluded_items_battle.push_once(*si.sub_items)
end
if si.note.match(/\<ExtendItemsStyle:\s(.*)\>/im)
si.sub_style = $1.upcase == "SIMPLE" ? :simple : :item
end
if si.note.match(/\<ExtendItemsWidth:\s(.*)\>/im)
si.sub_width = $1.to_i rescue nil
end
if si.note.match(/\<ExtendItemsAlign:\s(.*)\>/im)
si.sub_align = ALIGNMENT[$1.upcase] || 0
end
end
end
end
#==============================================================================
# ** Window_SkillList
#==============================================================================
class Window_SkillList < Window_Selectable
#--------------------------------------------------------------------------
# * Check if Skill should be included
#--------------------------------------------------------------------------
def include?(sk)
return false if $excluded_skills_menu.include?(sk.id)
return sk && sk.stype_id == @stype_id
end
end
#==============================================================================
# ** Window_ItemList
#==============================================================================
class Window_ItemList < Window_Selectable
#--------------------------------------------------------------------------
# * Check if Item should be included
#--------------------------------------------------------------------------
alias_method(:__original_include__, :include?) unless $@
def include?(si)
return false if $excluded_items_menu.include?(si.id)
__original_include__(si)
end
end
#==============================================================================
# ** Window_BattleSkill
#==============================================================================
class Window_BattleSkill < Window_SkillList
#--------------------------------------------------------------------------
# * Draw Skill Cost or Category Sign
#--------------------------------------------------------------------------
def draw_skill_cost(sr, sk)
return super unless sk.has_sub? && !is_sub?
draw_text(sr, ">>", 2)
end
#--------------------------------------------------------------------------
# * Define Window not for SubSkills
#--------------------------------------------------------------------------
def is_sub?
return false
end
#--------------------------------------------------------------------------
# * Check if Skill should be included
#--------------------------------------------------------------------------
def include?(sk)
return sk && !$excluded_skills_battle.include?(sk.id)
end
#--------------------------------------------------------------------------
# * Check if Skill is available for Use
#--------------------------------------------------------------------------
def enable?(sk)
return @actor && (@actor.usable?(sk) || sk.has_sub?)
end
#--------------------------------------------------------------------------
# * Hide Window
#--------------------------------------------------------------------------
def hide
@help_window.hide unless is_sub?
super
end
end
#==============================================================================
# ** Window_BattleItem
#==============================================================================
class Window_BattleItem < Window_ItemList
#--------------------------------------------------------------------------
# * Draw Item Number or Category Sign
#--------------------------------------------------------------------------
def draw_item_number(sr, si)
return super unless si.has_sub? && !is_sub?
draw_text(sr, ">>", 2)
end
#--------------------------------------------------------------------------
# * Define Window not for SubItems
#--------------------------------------------------------------------------
def is_sub?
return false
end
#--------------------------------------------------------------------------
# * Check if Item should be included
#--------------------------------------------------------------------------
def include?(si)
return si && !$excluded_items_battle.include?(si.id)
end
#--------------------------------------------------------------------------
# * Check if Item is available for Use
#--------------------------------------------------------------------------
def enable?(si)
return $game_party.usable?(si) || si.has_sub?
end
#--------------------------------------------------------------------------
# * Hide Window
#--------------------------------------------------------------------------
def hide
@help_window.hide unless is_sub?
super
end
end
#==============================================================================
# ** Window_SkillSub
#==============================================================================
class Window_SkillSub < Window_BattleSkill
#--------------------------------------------------------------------------
# * Define Number of selectable Columns
#--------------------------------------------------------------------------
def col_max
return 1
end
#--------------------------------------------------------------------------
# * Define Window for SubSkills
#--------------------------------------------------------------------------
def is_sub?
return true
end
#--------------------------------------------------------------------------
# * Set Actor
#--------------------------------------------------------------------------
def actor=(sa)
@actor = sa
end
#--------------------------------------------------------------------------
# * Set Rows Maximum
#--------------------------------------------------------------------------
def row_max
return @parent ? [[@parent.sub_items.size, 6].min, 1].max : 1
end
#--------------------------------------------------------------------------
# * Define Window Height
#--------------------------------------------------------------------------
def window_height
return fitting_height(1) unless @parent
return fitting_height(row_max)
end
#--------------------------------------------------------------------------
# * Set parent Skill
#--------------------------------------------------------------------------
def parent=(sp)
@parent = sp
sy = (Graphics.height - window_height) / 2
sw = (@parent ? @parent.sub_width : nil) || (Graphics.width / 2)
move((Graphics.width - sw) / 2, sy, sw, window_height)
refresh
end
#--------------------------------------------------------------------------
# * Check if Skill should be included
#--------------------------------------------------------------------------
def include?(sk)
return false unless @actor && @parent
return true unless @parent.sub_learn
return @actor.skill_learn?(sk)
end
#--------------------------------------------------------------------------
# * Check if Skill is available for Use
#--------------------------------------------------------------------------
def enable?(sk)
return false unless @actor
return false if @parent.sub_learn && [email protected]_learn?(sk)
return @actor.usable?(sk)
end
#--------------------------------------------------------------------------
# * Create Skill List Data
#--------------------------------------------------------------------------
def make_item_list
if @parent
st = @parent.sub_items.sort.collect {|i| $data_skills[i] }
@data = st.select {|sk| include?(sk) }
else
@data = []
end
end
#--------------------------------------------------------------------------
# *
#--------------------------------------------------------------------------
def draw_item(sn)
case @parent.sub_style
when :simple
sr = item_rect(sn)
draw_text(sr, @data[sn].name, @parent.sub_align)
when :skill
super
end
end
end
#==============================================================================
# ** Window_ItemSub
#==============================================================================
class Window_ItemSub < Window_BattleItem
#--------------------------------------------------------------------------
# * Define Number of selectable Columns
#--------------------------------------------------------------------------
def col_max
return 1
end
#--------------------------------------------------------------------------
# * Define Window for SubItems
#--------------------------------------------------------------------------
def is_sub?
return true
end
#--------------------------------------------------------------------------
# * Set Rows Maximum
#--------------------------------------------------------------------------
def row_max
return @parent ? [[@parent.sub_items.size, 6].min, 1].max : 1
end
#--------------------------------------------------------------------------
# * Define Window Height
#--------------------------------------------------------------------------
def window_height
return fitting_height(1) unless @parent
return fitting_height(row_max)
end
#--------------------------------------------------------------------------
# * Set parent Item
#--------------------------------------------------------------------------
def parent=(sp)
@parent = sp
sy = (Graphics.height - window_height) / 2
sw = (@parent ? @parent.sub_width : nil) || (Graphics.width / 2)
move((Graphics.width - sw) / 2, sy, sw, window_height)
refresh
end
#--------------------------------------------------------------------------
# * Check if Item should be included
#--------------------------------------------------------------------------
def include?(si)
return false unless @parent
return $game_party.has_item?(si) && $game_party.usable?(si)
end
#--------------------------------------------------------------------------
# * Check if Item is available for Use
#--------------------------------------------------------------------------
def enable?(si)
return $game_party.usable?(si)
end
#--------------------------------------------------------------------------
# * Create Skill List Data
#--------------------------------------------------------------------------
def make_item_list
if @parent
@data = @parent.sub_items.sort.collect {|i| $data_items[i] }
else
@data = []
end
end
#--------------------------------------------------------------------------
# *
#--------------------------------------------------------------------------
def draw_item(sn)
case @parent.sub_style
when :simple
sr = item_rect(sn)
draw_text(sr, @data[sn].name, @parent.sub_align)
when :item
super
end
end
end
#==============================================================================
# ** Scene_Battle
#==============================================================================
class Scene_Battle < Scene_Base
#--------------------------------------------------------------------------
# *
#--------------------------------------------------------------------------
alias_method(:__original_create_windows__, :create_all_windows) unless $@
def create_all_windows
__original_create_windows__
create_subskill_window
create_subitem_window
end
#--------------------------------------------------------------------------
# *
#--------------------------------------------------------------------------
def create_subskill_window
@subskill_window = Window_SkillSub.new(@help_window, @info_viewport)
@subskill_window.set_handler(:ok, method(:on_subskill_ok))
@subskill_window.set_handler(:cancel, method(:on_subskill_cancel))
end
#--------------------------------------------------------------------------
# *
#--------------------------------------------------------------------------
def create_subitem_window
@subitem_window = Window_ItemSub.new(@help_window, @info_viewport)
@subitem_window.set_handler(:ok, method(:on_subitem_ok))
@subitem_window.set_handler(:cancel, method(:on_subitem_cancel))
end
#--------------------------------------------------------------------------
# *
#--------------------------------------------------------------------------
def select_subskill_selection
@subskill_window.actor = BattleManager.actor
@subskill_window.parent = @skill_window.item
@subskill_window.show.activate
end
#--------------------------------------------------------------------------
# *
#--------------------------------------------------------------------------
def select_subitem_selection
@subitem_window.parent = @item_window.item
@subitem_window.show.activate
end
#--------------------------------------------------------------------------
# *
#--------------------------------------------------------------------------
def process_selected_skill
BattleManager.actor.input.set_skill(@skill.id)
BattleManager.actor.last_skill.object = @skill
if [email protected]_selection?
@subskill_window.hide
@skill_window.hide
next_command
elsif @skill.for_opponent?
select_enemy_selection
else
select_actor_selection
end
end
#--------------------------------------------------------------------------
# *
#--------------------------------------------------------------------------
def on_skill_ok
@skill = @skill_window.item
@skill.has_sub? ? select_subskill_selection : process_selected_skill
end
#--------------------------------------------------------------------------
# *
#--------------------------------------------------------------------------
def on_subskill_ok
@skill = @subskill_window.item
process_selected_skill
end
#--------------------------------------------------------------------------
# *
#--------------------------------------------------------------------------
def on_subskill_cancel
@subskill_window.hide
@skill_window.activate
end
#--------------------------------------------------------------------------
# *
#--------------------------------------------------------------------------
def process_selected_item
BattleManager.actor.input.set_item(@item.id)
if [email protected]_selection?
@subitem_window.hide
@item_window.hide
next_command
elsif @item.for_opponent?
select_enemy_selection
else
select_actor_selection
end
$game_party.last_item.object = @item
end
#--------------------------------------------------------------------------
# *
#--------------------------------------------------------------------------
def on_item_ok
@item = @item_window.item
@item.has_sub? ? select_subitem_selection : process_selected_item
end
#--------------------------------------------------------------------------
# *
#--------------------------------------------------------------------------
def on_subitem_ok
@item = @subitem_window.item
process_selected_item
end
#--------------------------------------------------------------------------
# *
#--------------------------------------------------------------------------
def on_subitem_cancel
@subitem_window.hide
@item_window.activate
end
#--------------------------------------------------------------------------
# *
#--------------------------------------------------------------------------
def hide_action_windows
@actor_window.hide
@enemy_window.hide
@skill_window.hide
@item_window.hide
@subskill_window.hide
@subitem_window.hide
end
#--------------------------------------------------------------------------
# *
#--------------------------------------------------------------------------
def back_to_skill_selection
return @subskill_window.activate if @subskill_window.visible
@skill_window.activate
end
#--------------------------------------------------------------------------
# *
#--------------------------------------------------------------------------
def back_to_item_selection
return @subitem_window.activate if @subitem_window.visible
@item_window.activate
end
#--------------------------------------------------------------------------
# *
#--------------------------------------------------------------------------
def on_actor_ok
BattleManager.actor.input.target_index = @actor_window.index
hide_action_windows
next_command
end
#--------------------------------------------------------------------------
# *
#--------------------------------------------------------------------------
def on_actor_cancel
@actor_window.hide
case @actor_command_window.current_symbol
when :skill
back_to_skill_selection
when :item
back_to_item_selection
end
end
#--------------------------------------------------------------------------
# *
#--------------------------------------------------------------------------
def on_enemy_ok
BattleManager.actor.input.target_index = @enemy_window.enemy.index
hide_action_windows
next_command
end
#--------------------------------------------------------------------------
# *
#--------------------------------------------------------------------------
def on_enemy_cancel
@enemy_window.hide
case @actor_command_window.current_symbol
when :attack
@actor_command_window.activate
when :skill
back_to_skill_selection
when :item
back_to_item_selection
end
end
end