[code]#==============================================================================
# Item System Diablo Style
#------------------------------------------------------------------------------
# By DarkSchneider
#
www.rpg2s.net#------------------------------------------------------------------------------
# Credit to Schwarz for draw_line
#==============================================================================
class Scene_Item2
def initialize(actor_index = 0)
@actor_index = actor_index
end
def main
# Make help window, item window
s1 = "Use"
s2 = "Move"
s3 = "Drop"
@command_window = Window_Command.new(193, [s1, s2 , s3])
@command_window.y = 64
@help_window = Window_Help.new
@grid = Window_Grid.new(@actor_index)
@grid.active = false
# Associate help window
@grid.help_window = @help_window
# Make target window (set to invisible / inactive)
@target_window = Window_Target.new
@target_window.visible = false
@target_window.active = false
@window_pc = Window_Base.new(0,192,193,287)
@window_pc.contents = Bitmap.new(161,255)
@window_pc.draw_actor_name($game_party.actors[@actor_index], 10, 0)
@window_pc.draw_actor_picture($game_party.actors[@actor_index], 80, 250)
# Execute transition
Graphics.transition
# Main loop
loop do
# Update game screen
Graphics.update
# Update input information
Input.update
# Frame update
update
# Abort loop if screen is changed
if $scene != self
break
end
end
# Prepare for transition
Graphics.freeze
@cursor_icon.dispose if @cursor_icon != nil
# Dispose of windows
@command_window.dispose
@help_window.dispose
#@item_window.dispose
@target_window.dispose
@grid.dispose
@window_pc.dispose
end
#--------------------------------------------------------------------------
# * Frame Update
#--------------------------------------------------------------------------
def update
# Update windows
@command_window.update
@help_window.update
@target_window.update
@grid.update
if @command_window.active
update_command
return
end
# If item window is active: call update_item
if @grid.active
case @grid.mode
when 0
update_usa
when 1
@cursor_icon = Cursor_Icon.new if @cursor_icon == nil
@cursor_icon.visible = false
update_muovi
when 2
update_lascia
when 3
@cursor_icon.update
update_muovi2
end
return
end
# If target window is active: call update_target
if @target_window.active
update_target
return
end
end
def update_command
# If B button was pressed
if Input.trigger?(Input::B)
# Play cancel SE
$game_system.se_play($data_system.cancel_se)
# Switch to menu screen
$scene = Scene_Menu.new(0)
return
end
if Input.trigger?(Input::C)
# Branch by command window cursor position
case @command_window.index
when 0 # use
# Play decision SE
$game_system.se_play($data_system.decision_se)
@command_window.active = false
@grid.active = true
@grid.set = 0
@grid.mode = @command_window.index
when 1 # move
# Play decision SE
$game_system.se_play($data_system.decision_se)
# Make status window active
@command_window.active = false
@grid.active = true
@grid.set = 0
@grid.mode = @command_window.index
when 2 # drop
# Play decision SE
$game_system.se_play($data_system.decision_se)
# Make status window active
@command_window.active = false
@grid.active = true
@grid.set = 0
@grid.mode = @command_window.index
end
return
end
end
#--------------------------------------------------------------------------
# * Frame Update (when item window is active)
#--------------------------------------------------------------------------
def update_usa
# If B button was pressed
if Input.trigger?(Input::B)
# Play cancel SE
$game_system.se_play($data_system.cancel_se)
# Switch to menu screen
@command_window.active = true
@grid.active = false
@grid.set = - 1
return
end
# If C button was pressed
if Input.trigger?(Input::C)
# Get currently selected data on the item window
@item = @grid.item
# If not a use item
unless @item.is_a?(RPG::Item)
# Play buzzer SE
$game_system.se_play($data_system.buzzer_se)
return
end
# If it can't be used
unless $game_party.item_can_use?(@item.id)
# Play buzzer SE
$game_system.se_play($data_system.buzzer_se)
return
end
# Play decision SE
$game_system.se_play($data_system.decision_se)
# If effect scope is an ally
if @item.scope >= 3
# Activate target window
@grid.active = false
#@target_window.x = (@item_window.index + 1) % 2 * 304
@target_window.visible = true
@target_window.active = true
# Set cursor position to effect scope (single / all)
if @item.scope == 4 || @item.scope == 6
@target_window.index = -1
else
@target_window.index = 0
end
# If effect scope is other than an ally
else
# If command event ID is valid
if @item.common_event_id > 0
# Command event call reservation
$game_temp.common_event_id = @item.common_event_id
# Play item use SE
$game_system.se_play(@item.menu_se)
# If consumable
if @item.consumable
# Decrease used items by 1
$game_party.lose_item(@item.id, 1, false)
# Draw item window item
@grid.delete_item
end
# Switch to map screen
$scene = Scene_Map.new
return
end
end
return
end
end
#--------------------------------------------------------------------------
# * Frame Update (when target window is active)
#--------------------------------------------------------------------------
def update_target
# If B button was pressed
if Input.trigger?(Input::B)
# Play cancel SE
$game_system.se_play($data_system.cancel_se)
# If unable to use because items ran out
unless $game_party.item_can_use?(@item.id)
# Remake item window contents
@grid.refresh
end
# Erase target window
@grid.active = true
@target_window.visible = false
@target_window.active = false
return
end
# If C button was pressed
if Input.trigger?(Input::C)
# If items are used up
if @grid.item_del?
# Play buzzer SE
$game_system.se_play($data_system.buzzer_se)
return
end
# If target is all
if @target_window.index == -1
# Apply item effects to entire party
used = false
for i in $game_party.actors
used |= i.item_effect(@item)
end
end
# If single target
if @target_window.index >= 0
# Apply item use effects to target actor
target = $game_party.actors[@target_window.index]
used = target.item_effect(@item)
end
# If an item was used
if used
# Play item use SE
$game_system.se_play(@item.menu_se)
# If consumable
if @item.consumable
# Decrease used items by 1
$game_party.lose_item(@item.id, 1, false)
# Redraw item window item
@grid.delete_item
end
# Remake target window contents
@target_window.refresh
# If all party members are dead
if $game_party.all_dead?
# Switch to game over screen
$scene = Scene_Gameover.new
return
end
# If common event ID is valid
if @item.common_event_id > 0
# Common event call reservation
$game_temp.common_event_id = @item.common_event_id
# Switch to map screen
$scene = Scene_Map.new
return
end
end
# If item wasn't used
unless used
# Play buzzer SE
$game_system.se_play($data_system.buzzer_se)
end
return
end
end
def update_muovi
if Input.trigger?(Input::B)
# Play cancel SE
$game_system.se_play($data_system.cancel_se)
# Switch to menu screen
@command_window.active = true
@grid.active = false
@grid.set = - 1
return
end
if Input.trigger?(Input::C)
if @grid.item != nil
@grid.get_item
bitmap = Bitmap.new(32,32)
x = 4 + (@grid.cursor_rect.width == 32 ? 0 : 18)
y = 4 + (@grid.cursor_rect.height == 32 ? 0 : 32)
bitmap.blt(0,0,@grid.contents,Rect.new(@grid.cursor_rect.x + x,
@grid.cursor_rect.y + y,@grid.cursor_rect.width,@grid.cursor_rect.height))
@cursor_icon.refresh(bitmap, @grid.item_saved[1])
@grid.cursor_rect.width = @cursor_icon.bitmap.width
@grid.cursor_rect.height = @cursor_icon.bitmap.height
@cursor_icon.x = @grid.cursor_rect.x + @grid.x + 16
@cursor_icon.y = @grid.cursor_rect.y + @grid.y + 16
@cursor_icon.visible = true
@grid.delete_item
@grid.mode = 3
end
return
end
end
def update_lascia
if Input.trigger?(Input::B)
# Play cancel SE
$game_system.se_play($data_system.cancel_se)
# Switch to menu screen
@command_window.active = true
@grid.active = false
@grid.set = - 1
return
end
if Input.trigger?(Input::C)
if @grid.item != nil
@grid.delete_item
end
return
end
end
def update_muovi2
@grid.cursor_rect.width = @cursor_icon.bitmap.width
@grid.cursor_rect.height = @cursor_icon.bitmap.height
@cursor_icon.x = @grid.cursor_rect.x + @grid.x + 16
@cursor_icon.y = @grid.cursor_rect.y + @grid.y + 16
if @grid.empty?
@cursor_icon.blink_on
@cursor_icon.tone.set(0,0,0,0)
else
@cursor_icon.blink_off
@cursor_icon.tone.set(0,0,0,255)
end
if Input.trigger?(Input::B)
# Play cancel SE
$game_system.se_play($data_system.cancel_se)
# Switch to menu screen
@grid.redraw_item(false)
@grid.mode = 1
return
end
if Input.trigger?(Input::C)
if @grid.empty?
@grid.redraw_item
@cursor_icon.visible = false
@grid.mode = 1
end
return
end
end
end
class Window_Selectable < Window_Base
alias old_initialize initialize
def initialize(x, y, width, height)
old_initialize(x, y, width, height)
if self.is_a?(Window_Grid)
@x = 0
@y = 0
end
end
alias old_update update
def update
if !self.is_a?(Window_Grid)
old_update
return
end
super
item = $game_party.actors[@actor_index].item_grid
# If cursor is movable
if self.active and @item_max > 0 and @x >= 0
# If pressing down on the directional buttons
if Input.repeat?(Input::DOWN)
@y = -1 if @y == item.size - (self.cursor_rect.height == 96 ? 3 : 1)
@y += 2 if item[@y][@x][1] == "w" or item[@y][@x][1] == "a"
if item[@y + 1][@x][1] == "r" and item[@y + 1][@x - 1][1] == "a"
@x -= 1
end
@y += 1
$game_system.se_play($data_system.cursor_se)
end
# If the up directional button was pressed
if Input.repeat?(Input::UP)
@y = item.size if @y - 1 == -1
@y -= 2 if item[@y - 1][@x][1] == "e" or item[@y - 1][@x][1] == "r"
@x -= 1 if item[@y - 1][@x - 1][1] == "a"
@y -= 1
$game_system.se_play($data_system.cursor_se)
end
# If the right directional button was pressed
if Input.repeat?(Input::RIGHT)
if @x + (self.cursor_rect.width == 64 ? 2 : 1) == item[@y].size
@x = 0
@y -= 1 if item[@y - 1][@x][1] == "a"
@y -= 2 if item[@y - 2][@x][1] == "a"
else
@x += 1 if item[@y][@x][1] == "a"
if item[@y][@x + 1][1] == "r"
@y -= 1 if item[@y - 1][@x + 1][1] == "a"
@y -= 2 if item[@y - 2][@x + 1][1] == "a"
end
if item[@y][@x + 1][1] == "e"
@y -= 1
@y -= 1 if item[@y - 1][@x + 1][1] == "w"
end
@x += 1
end
$game_system.se_play($data_system.cursor_se)
end
# If the left directional button was pressed
if Input.repeat?(Input::LEFT)
@x = item[@y].size if @x - 1 == -1
if item[@y][@x - 1][1] == "r"
@x -= 1
@y -= 1 if item[@y - 1][@x - 1][1] == "a"
@y -= 2 if item[@y - 2][@x - 1][1] == "a"
end
if item[@y][@x - 1][1] == "e"
@y -= 1
@y -= 1 if item[@y - 1][@x - 1][1] == "w"
end
@x -= 1
$game_system.se_play($data_system.cursor_se)
end
end
# Update help text (update[/code