#==============================================================================
# Kingdom Hearts Battle System
#--------------------------------------------------------------------------
# Orginal Battle System Created By Near Fantastica. Give Him most of the credit. My job was easy
# Created By SephirothSpawn (11.30.05)
# Last Updated: 11.30.05
#--------------------------------------------------------------------------
# Instructions:
# ~ Insert Above Main, and Below Nears ABS.
# ~ Delete Scene Battle In Near's Code
# ~ In Scene Map, find the lines and delete them:
# # If B button was pressed
# if Input.trigger?(Input::B)
# # If event is running, or menu is not forbidden
# unless $game_system.map_interpreter.running? or
# $game_system.menu_disabled
# # Set menu calling flag or beep flag
# $game_temp.menu_calling = true
# $game_temp.menu_beep = true
# end
# end
#==============================================================================
#==============================================================================
# ** Class Window_Base
#==============================================================================
class Window_Base
#--------------------------------------------------------------------------
# Draw Inverted Bar
# Credit Near Fantastica for Orginal Script
#--------------------------------------------------------------------------
def draw_invert_bar(x, y, min, max, width = 152, height = 20, bar_color = Color.new(0, 0, 200, 255))
w = width * min / max
for i in 0..height
r = bar_color.red * (height -i)/height + 0 * i/height
g = bar_color.green * (height -i)/height + 0 * i/height
b = bar_color.blue * (height -i)/height + 0 * i/height
a = bar_color.alpha * (height -i)/height + 255 * i/height
self.contents.fill_rect(x - w, y+i, w , 1, Color.new(r, g, b, a))
end
end
#--------------------------------------------------------------------------
# * Draw Face
# actor : actor's face
#--------------------------------------------------------------------------
def draw_face(x, y, actor, border = true)
if border
bitmap = RPG::Cache.character("Faces/Background", 0)
src_rect = Rect.new(0, 0, bitmap.width, bitmap.height)
self.contents.blt(x, y, bitmap, src_rect)
end
bitmap = RPG::Cache.character("Faces/#{actor.character_name}", actor.character_hue)
src_rect = Rect.new(0, 0, bitmap.width, bitmap.height)
self.contents.blt(x, y, bitmap, src_rect)
if border
bitmap = RPG::Cache.character("Faces/Border", 0)
src_rect = Rect.new(0, 0, bitmap.width, bitmap.height)
self.contents.blt(x - 6, y - 6, bitmap, src_rect)
end
end
end
#==============================================================================
# ** Window_Command
#==============================================================================
class Window_Command < Window_Selectable
# Changes Commands to an Accessor, for refreshing
attr_accessor :commands
end
#==============================================================================
# ** Window_ABS_Skill
#==============================================================================
class Window_ABS_Skill < Window_Selectable
#--------------------------------------------------------------------------
# * Object Initialization
# actor : actor
#--------------------------------------------------------------------------
def initialize
super(4, 316, 240, 160)
self.opacity = 175
refresh
self.index = 0
end
#--------------------------------------------------------------------------
# * Acquiring Skill
#--------------------------------------------------------------------------
def skill
return @skills[self.index]
end
#--------------------------------------------------------------------------
# * Refresh
#--------------------------------------------------------------------------
def refresh(actor= $game_party.actors[0])
@actor = actor
if self.contents != nil
self.contents.dispose
self.contents = nil
end
@skills = []
for i in 0...@actor.skills.size
skill = $data_skills[@actor.skills]
if skill != nil
@skills.push(skill)
end
end
# If item count is not 0, make a bit map and draw all items
@item_max = @skills.size
if @item_max > 0
self.contents = Bitmap.new(width - 32, row_max * 32)
for i in 0...@item_max
draw_item(i)
end
end
end
#--------------------------------------------------------------------------
# * Draw Item
# index : item number
#--------------------------------------------------------------------------
def draw_item(index)
skill = @skills[index]
self.contents.font.name = $defaultfonttype
self.contents.font.color = check_skill(skill) ? normal_color : disabled_color
x = 4
y = index * 32
rect = Rect.new(x, y, self.width - 32, 32)
self.contents.fill_rect(rect, Color.new(0, 0, 0, 0))
bitmap = RPG::Cache.icon(skill.icon_name)
opacity = self.contents.font.color == normal_color ? 255 : 128
self.contents.blt(x, y + 4, bitmap, Rect.new(0, 0, 24, 24), opacity)
self.contents.draw_text(x + 28, y, contents.width - 28, 32, skill.name)
self.contents.draw_text(-x, y, contents.width, 32, skill.sp_cost.to_s, 2)
end
#--------------------------------------------------------------------------
# * Check Skill
#--------------------------------------------------------------------------
def check_skill(skill)
actor = $game_party.actors[0]
if skill == nil or not actor.skills.include?(skill.id) or actor.sp < skill.sp_cost
return false
else
return true
end
end
#--------------------------------------------------------------------------
# * Help Text Update
#--------------------------------------------------------------------------
def update_help
@help_window.set_text(self.skill == nil ? "" : self.skill.description)
end
end
#==============================================================================
# ** Window_ABS_Item
#==============================================================================
class Window_ABS_Item < Window_Selectable
#--------------------------------------------------------------------------
# * Object Initialization
#--------------------------------------------------------------------------
def initialize
super(4, 316, 240, 160)
self.opacity = 175
refresh
self.index = 0
end
#--------------------------------------------------------------------------
# * Get Item
#--------------------------------------------------------------------------
def item
return @data[self.index]
end
#--------------------------------------------------------------------------
# * Refresh
#--------------------------------------------------------------------------
def refresh
if self.contents != nil
self.contents.dispose
self.contents = nil
end
@data = []
# Add item
for i in 1...$data_items.size
if $game_party.item_number(i) > 0
@data.push($data_items)
end
end
# If item count is not 0, make a bit map and draw all items
@item_max = @data.size
if @item_max > 0
self.contents = Bitmap.new(width - 32, row_max * 32)
for i in 0...@item_max
draw_item(i)
end
end
end
#--------------------------------------------------------------------------
# * Draw Item
# index : item number
#--------------------------------------------------------------------------
def draw_item(index)
item = @data[index]
number = $game_party.item_number(item.id)
self.contents.font.name = $defaultfonttype
self.contents.font.color = $game_party.item_can_use?(item.id) ? normal_color : disabled_color
x = 4
y = index * 32
rect = Rect.new(x, y, self.width - 32, 32)
self.contents.fill_rect(rect, Color.new(0, 0, 0, 0))
bitmap = RPG::Cache.icon(item.icon_name)
opacity = self.contents.font.color == normal_color ? 255 : 128
self.contents.blt(x, y + 4, bitmap, Rect.new(0, 0, 24, 24), opacity)
self.contents.draw_text(x + 28, y, 212, 32, item.name, 0)
self.contents.draw_text(-x - 28, y, contents.width, 32, ":", 2)
self.contents.draw_text(-x, y, contents.width, 32, number.to_s, 2)
end
#--------------------------------------------------------------------------
# * Help Text Update
#--------------------------------------------------------------------------
def update_help
@help_window.set_text(self.item == nil ? "" : self.item.description)
end
end
#==============================================================================
# ** Window_HotKeys
#==============================================================================
class Window_HotKeys < Window_Base
#--------------------------------------------------------------------------
# * Object Initialization
#--------------------------------------------------------------------------
def initialize
super(200, 160, 240, 160)
self.opacity = 178
self.visible = false
self.contents = Bitmap.new(width - 32, height - 32)
self.contents.font.name = $defaultfonttype
refresh
end
#--------------------------------------------------------------------------
# * Refresh
#--------------------------------------------------------------------------
def refresh
self.contents.clear
# Hot Key 1
unless $ABS.skill_key[1] == 0
skill = $data_skills[$ABS.skill_key[1]]
self.contents.font.color = check_skill(skill) ? normal_color : disabled_color
self.contents.draw_text(4, 0, contents.width, 32, " (H) #{skill.name}")
else
self.contents.font.color = check_skill(skill) ? normal_color : disabled_color
self.contents.draw_text(4, 0, contents.width, 32, " (H) Unassigned Skill")
end
# Hot Key 2
unless $ABS.skill_key[2] == 0
skill = $data_skills[$ABS.skill_key[2]]
self.contents.font.color = check_skill(skill) ? normal_color : disabled_color
self.contents.draw_text(4, 32, contents.width, 32, " (J) #{skill.name}")
else
self.contents.font.color = check_skill(skill) ? normal_color : disabled_color
self.contents.draw_text(4, 32, contents.width, 32, " (J) Unassigned Skill")
end
# Hot Key 3
unless $ABS.skill_key[3] == 0
skill = $data_skills[$ABS.skill_key[3]]
self.contents.font.color = check_skill(skill) ? normal_color : disabled_color
self.contents.draw_text(4, 64, contents.width, 32, " (K) #{skill.name}")
else
self.contents.font.color = check_skill(skill) ? normal_color : disabled_color
self.contents.draw_text(4, 64, contents.width, 32, " (K) Unassigned Skill")
end
# Hot Key 4
unless $ABS.skill_key[4] == 0
skill = $data_skills[$ABS.skill_key[4]]
self.contents.font.color = check_skill(skill) ? normal_color : disabled_color
self.contents.draw_text(4, 96, contents.width, 32, " (L) #{skill.name}")
else
self.contents.font.color = check_skill(skill) ? normal_color : disabled_color
self.contents.draw_text(4, 96, contents.width, 32, " (L) Unassigned Skill")
end
end
#--------------------------------------------------------------------------
# * Check Skill
#--------------------------------------------------------------------------
def check_skill(skill)
actor = $game_party.actors[0]
if skill == nil or not actor.skills.include?(skill.id) or actor.sp < skill.sp_cost
return false
else
return true
end
end
end
#==============================================================================
# ** Window_ABS_Controls
#==============================================================================
class Window_ABS_Controls < Window_Base
#--------------------------------------------------------------------------
# * Object Initialization
#--------------------------------------------------------------------------
def initialize
super(160, 30, 320, 416)
self.opacity = 175
self.z = 1000
self.visible = false
self.contents = Bitmap.new(width - 32, height - 32)
self.contents.font.name = $defaultfonttype
refresh
end
#--------------------------------------------------------------------------
# * Refresh
#--------------------------------------------------------------------------
def refresh
self.contents.clear
contents.font.color = system_color
contents.draw_text(0, 0, contents.width, 24, "Kingdom Hearts Controls", 1)
contents.font.color = normal_color
keys = ["F", "G", "H", "J", "K", "L", "I", "O", "E", "R", "T", "Y", "U", "N", "M"]
controls = ["Melee Attack", "Range Attack", "Skill Key 1", "Skill Key 2",
"Skill Key 3", "Skill Key 4", "Dash", "Sneak", "Change Lead Forward",
"Change Lead Backwards", "Waits Leader", "Waits Allies", "Gathers Allies",
"Wide Follow", "Close Follow"]
for i in 0...keys.size
self.contents.draw_text(4, (i + 1) * 24, contents.width, 24, "(#{keys})")
self.contents.draw_text(40, (i + 1) * 24, contents.width, 24, controls)
end
end
end
#==============================================================================
# ** Window_KH_Controls
#==============================================================================
class Window_KH_Controls < Window_Base
#--------------------------------------------------------------------------
# * Object Initialization
#--------------------------------------------------------------------------
def initialize
super(140, 104, 360, 272)
self.opacity = 175
self.z = 1000
self.visible = false
self.contents = Bitmap.new(width - 32, height - 32)
self.contents.font.name = $defaultfonttype
refresh
end
#--------------------------------------------------------------------------
# * Refresh
#--------------------------------------------------------------------------
def refresh
self.contents.clear
contents.font.color = system_color
contents.draw_text(0, 0, contents.width, 24, "Kingdom Hearts Controls", 1)
contents.font.color = normal_color
keys = ["Enter", "Esc", "Shift", "P", "[", "]", "Q", "W", "A"]
controls = ["Actions From Command", "Returns Previous Menu",
"Activates Command Window", "Toggles Player HUD", "Toggles Ally HUD",
"Toggles Help Window", "Shows ABS Keys", "Shows KH Keys", "Shows Hot Keys"]
for i in 0...keys.size
self.contents.draw_text(4, (i + 1) * 24, contents.width, 24, "(#{keys})")
self.contents.draw_text(80, (i + 1) * 24, contents.width, 24, controls)
end
end
end
#==============================================================================
# ** Window_KH_PlayerHUD
#==============================================================================
class Window_KH_PlayerHUD < Window_Base
#--------------------------------------------------------------------------
# * Object Initialization
#--------------------------------------------------------------------------
def initialize
super(28, 320, 640, 172)
self.opacity = 0
self.contents = Bitmap.new(width - 32, height - 32)
self.contents.font.name = $defaultfonttype
update
end
#--------------------------------------------------------------------------
# * Update
#--------------------------------------------------------------------------
def update
super
self.contents.clear
actor = $game_party.actors[0]
# Draw HP Bar
draw_invert_bar(458, 0, actor.hp, actor.maxhp, actor.maxhp / 25, 34, bar_color = Color.new(0, 255, 0, 255))
# Draw SP Bar
draw_invert_bar(458, 35, actor.sp, actor.maxsp, actor.maxsp / 25, 34, bar_color = Color.new(0, 0, 255, 255))
# Draw Dash Bar
case $ABS.dash_level
when 0 .. 1 ;bar_color = Color.new(255, 255, 0, 255)
when 2 .. 3 ;bar_color = Color.new(255, 150, 0, 255)
else ;bar_color = Color.new(255, 0, 0, 255)
end
draw_invert_bar(458, 70, $ABS.dash_level, 5, 75, 34, bar_color)
# Draw Sneak Bar
case $ABS.sneak_level
when 0 .. 1 ;bar_color = Color.new(255, 255, 0, 255)
when 2 .. 3 ;bar_color = Color.new(255, 150, 0, 255)
else ;bar_color = Color.new(255, 0, 0, 255)
end
draw_invert_bar(458, 105, $ABS.sneak_level, 5, 50, 34, bar_color)
# Draws Face
draw_face(460, 6, actor)
end
end
#==============================================================================
# ** Window_KH_PlayerHUD
#==============================================================================
class Window_KH_AlliesHUD < Window_Base
#--------------------------------------------------------------------------
# * Object Initialization
#--------------------------------------------------------------------------
def initialize
super(158, 0, 482, 80)
self.opacity = 0
self.contents = Bitmap.new(width - 32, height - 32)
self.contents.font.name = $defaultfonttype
update
end
#--------------------------------------------------------------------------
# * Update
#--------------------------------------------------------------------------
def update
self.contents.clear
for i in 1...$game_party.actors.size
x = i * 150 - 16
actor = $game_party.actors
draw_actor_graphic(actor, x, 48)
draw_invert_bar(x - 24, 3, actor.hp, actor.maxhp, 100, 18, bar_color = Color.new(0, 255, 0, 255))
draw_invert_bar(x - 24, 27, actor.sp, actor.maxsp, 100, 18, bar_color = Color.new(0, 0, 255, 255))
end
end
end
#======================================
# ** Scene Map
#======================================
class Scene_Map
#--------------------------------------------------------------------------
alias abs_scene_map_main main
alias abs_scene_map_update update
alias abs_scene_map_transfer_player transfer_player
#--------------------------------------------------------------------------
attr_accessor :spriteset
#--------------------------------------------------------------------------
def main
# Help Window
@help_window = Window_Help.new
@help_window.z = 100
@help_window.opacity = 150
@help_window.visible = false
# Command Window
commands = ["Melee Attack", "Ranged Attack", "Skill", "Item"]
@command_window = Window_Command.new(160, commands)
@command_window.x = 4
@command_window.y = 316
@command_window.opacity = 175
# Skills Window
@skills_window = Window_ABS_Skill.new
@skills_window.active = @skills_window.visible = false
# Items Window
@items_window = Window_ABS_Item.new
@items_window.active = @items_window.visible = false
# Actors Window
commands = []
for actor in $game_party.actors
commands.push(actor.name)
end
@actors_window = Window_Command.new(160, commands)
@actors_window.x = 4
@actors_window.y = 316
@actors_window.opacity = 175
@actors_window.active = @actors_window.visible = false
# Hot Keys Window
@hot_keys_window = Window_HotKeys.new
# ABS Controls Window
@abs_controls_window = Window_ABS_Controls.new
# Window_KH_Controls
@kh_controls_window = Window_KH_Controls.new
# Player HUD
@player_hud = Window_KH_PlayerHUD.new
# Allies HUD
@allies_hud = Window_KH_AlliesHUD.new
# Stores ABS Window Objects
@objects = [@help_window, @command_window, @skills_window,
@items_window, @actors_window, @hot_keys_window, @abs_controls_window,
@kh_controls_window, @player_hud, @allies_hud]
# Default Main Method
abs_scene_map_main
# Disposes ABS Obejcts
@objects.each {|x| x.dispose}
end
#--------------------------------------------------------------------------
def update
# Updates HUD's
@player_hud.update if @player_hud.visible
@allies_hud.update if @allies_hud.visible
# Changes Main Option to Talk if game Event
@command_window.commands[0] = "Melee Attack"
switch = false
for event in $game_map.events.values
unless $ABS.enemies.include?(event.id) || event.is_a?(Game_Ally)
if $ABS.in_range?(event, $game_player, 1)
switch = true
end
end
end
if switch
unless @command_window.commands[0] == "Talk"
@command_window.commands[0] = "Talk"
@command_window.refresh
end
else
unless @command_window.commands == "Melee Attack"
@command_window.commands[0] = "Melee Attack"
@command_window.refresh
end
end
# Update Help Window
if @help_window.visible
if @command_window.active
case @command_window.index
when 0 ;text = "Melee Attack an Enemy with a basic Attack"
when 1 ;text = "Attack Enemy with a ranged Attack"
when 2 ;text = "Select a Skill to use against your enemies"
when 3 ;text = "Use an Item to Support the Battle"
end
@help_window.set_text(text)
elsif @skills_window.active
@skills_window.help_window = @help_window
elsif @items_window.active
@items_window.help_window = @help_window
else
@help_window.set_text("Select Member to Use Item on")
end
end
# Updates Command Window
if Input.press?(Input::A)
@command_window.update if @command_window.active
@skills_window.update if @skills_window.active
@items_window.update if @items_window.active
@actors_window.update if @actors_window.active
end
# Returns to Previous Menu, or Main Menu
if Input.trigger?(Input::B)
if @command_window.active
unless $game_system.map_interpreter.running? or $game_system.menu_disabled
$game_temp.menu_calling = true
$game_temp.menu_beep = true
end
elsif @skills_window.active
@skills_window.active = @skills_window.visible = false
@command_window.active = @command_window.visible = true
elsif @items_window.active
@items_window.active = @items_window.visible = false
@command_window.active = @command_window.visible = true
else
@actors_window.active = @actors_window.visible = false
@items_window.active = @items_window.visible = true
end
end
# Performs Action from Command Window, Skill Window or Item Window
if Input.trigger?(Input::C)
# Command Window
if @command_window.active
case @command_window.index
when 0 # Attack
$ABS.player_attack
when # Ranged Attack
$ABS.player_ranged
when 2 # Open Skills Menu
@command_window.active = @command_window.visible = false
@skills_window.refresh
@skills_window.active = @skills_window.visible = true
when 3 # Open Items Menu
@command_window.active = @command_window.visible = false
@items_window.refresh
@items_window.active = @items_window.visible = true
end
# Skill Window
elsif @skills_window.active
temp = $ABS.skill_key[1]
$ABS.skill_key[1] = $game_party.actors[0].skills[@skills_window.index]
$ABS.player_skill(1)
$ABS.skill_key[1] = temp
@skills_window.refresh
# Item Window
elsif @items_window.active
@item = @items_window.item
unless @item.is_a?(RPG::Item) or $game_party.item_can_use?(@item.id)
$game_system.se_play($data_system.buzzer_se)
return
end
$game_system.se_play($data_system.decision_se)
if @item.scope >= 3
@items_window.active = @items_window.visible = false
@actors_window.active = @actors_window.visible = true
else
if @item.common_event_id > 0
$game_temp.common_event_id = @item.common_event_id
$game_system.se_play(@item.menu_se)
if @item.consumable
$game_party.lose_item(@item.id, 1)
@item_window.draw_item(@item_window.index)
end
end
end
else
target = $game_party.actors[@actors_window.index]
used = target.item_effect(@item)
if used
$game_system.se_play(@item.menu_se)
if @item.consumable
$game_party.lose_item(@item.id, 1)
end
@actors_window.active = @actors_window.visible = false
@command_window.active = @command_window.visible = true
end
unless used
$game_system.se_play($data_system.buzzer_se)
end
end
end
# Toggle HUD Window
if Kboard.keyboard($R_Key_P)
@player_hud.visible = @player_hud.visible ? false : true
end
# Toggle Ally Window
if Kboard.keyboard(0xDB)
@allies_hud.visible = @allies_hud.visible ? false : true
end
# Toggle Help Window
if Kboard.keyboard(0xDD)
@help_window.visible = @help_window.visible ? false : true
end
# Toggles Hot Keys
if Input.press?(Input::X)
@hot_keys_window.visible = true
else
@hot_keys_window.visible = false
end
# Toggles ABS Controls Window
if Input.press?(Input::L)
@abs_controls_window.visible = true
else
@abs_controls_window.visible = false
end
# Toggles KH Controls Window
if Input.press?(Input::R)
@kh_controls_window.visible = true
else
@kh_controls_window.visible = false
end
# F ? Melee Attack
if Kboard.keyboard($R_Key_F)
$ABS.player_attack
end
# G ? Range Attack
if Kboard.keyboard($R_Key_G)
$ABS.player_ranged
end
# H ? Skill Key 1
if Kboard.keyboard($R_Key_H)
$ABS.player_skill(1)
end
# J ? Skill Key 2
if Kboard.keyboard($R_Key_J)
$ABS.player_skill(2)
end
# K ? Skill Key 3
if Kboard.keyboard($R_Key_K)
$ABS.player_skill(3)
end
# L ? Skill Key 4
if Kboard.keyboard($R_Key_L)
$ABS.player_skill(4)
end
# E ? Change Lead Forward
if Kboard.keyboard($R_Key_E)
$game_party.shift_forward
end
# R ? Change Lead Backwards
if Kboard.keyboard($R_Key_R)
$game_party.shift_backward
end
# T ? Waits Leader
if Kboard.keyboard($R_Key_T)
$game_player.wait_command = true
$game_party.shift_forward
end
# Y ? Waits Allies
if Kboard.keyboard($R_Key_Y)
for ally in $game_allies.values
if ally.map_id == $game_map.map_id
ally.wait_command = true
end
end
end
# U ? Gathers Allies
if Kboard.keyboard($R_Key_U)
$ABS.player_engaged = false
for ally in $game_allies.values
if ally.map_id == $game_map.map_id
ally.wait_command = false
ally.under_attack = false
ally.refresh
end
end
end
# N ? Wide Follow
if Kboard.keyboard($R_Key_N)
$ABS.close_follow = true
end
# M ? Close Follow
if Kboard.keyboard($R_Key_M)
$ABS.close_follow = false
end
for key in $game_allies.keys
$game_allies[key].update
end
$ABS.update
if $ABS.transer_player == true
transfer
end
abs_scene_map_update
end
#--------------------------------------------------------------------------
def transfer
$ABS.transer_player = false
$game_map.update
@spriteset.dispose
@spriteset = Spriteset_Map.new
if $game_temp.transition_processing
$game_temp.transition_processing = false
Graphics.transition(20)
end
$game_map.autoplay
Graphics.frame_reset
Input.update
end
#--------------------------------------------------------------------------
def transfer_player
for ally in $game_allies.values
if ally.wait_command == false and ally.dead == false
ally.moveto($game_temp.player_new_x, $game_temp.player_new_y)
ally.map_id = $game_temp.player_new_map_id
end
end
$game_player.map_id = $game_temp.player_new_map_id
abs_scene_map_transfer_player
end
end