#==============================================================================
# ** Lock Pick System
#------------------------------------------------------------------------------
# Author: Dargor
# Edits: Belak51
# Requested by: Isopaha
# Version 1.6
# 25/06/2007
#==============================================================================
# * Instructions
#------------------------------------------------------------------------------
# - Setup an event and use the call script command:
# scene = Scene_LockPick.new(event_id, lock_level, max_try)
# max_try: maximum number of trys before the lock is broken.
# When set to -1, the lock can't be broken
#------------------------------------------------------------------------------
# * Note
#------------------------------------------------------------------------------
# - Thanks to Isopaha for requesting the script! And don't forget to
# give me credits!
#==============================================================================
module Lockpicking
Actors = [1,2]
Classes = [1,2,3]
Use_Actors_Level = [2]
end
#==============================================================================
# ** Game_Temp
#------------------------------------------------------------------------------
# This class handles temporary data that is not included with save data.
# Refer to "$game_temp" for the instance of this class.
#==============================================================================
class Game_Temp
#--------------------------------------------------------------------------
# * Public Instance Variables
#--------------------------------------------------------------------------
attr_accessor :lockpick_success
attr_accessor :lockpick_actor
attr_accessor :lockpick_target_level
attr_accessor :lockpick_levelup_flag
attr_accessor :lockpick_use
#--------------------------------------------------------------------------
# * Alias Listing
#--------------------------------------------------------------------------
alias dargor_lock_temp_initialize initialize
#--------------------------------------------------------------------------
# * Object Initialization
#--------------------------------------------------------------------------
def initialize
dargor_lock_temp_initialize
@lockpick_success = false
@lockpick_actor = nil
@lockpick_target_level = 1
@lockpick_levelup_flag = []
@lockpick_use = 20
end
#--------------------------------------------------------------------------
# * Repair Lock Pick (#use)
#--------------------------------------------------------------------------
def repair_lockpick(value=20)
@lockpick_use = value
end
end
#==============================================================================
# ** Game_System
#------------------------------------------------------------------------------
# This class handles data surrounding the system. Backround music, etc.
# is managed here as well. Refer to "$game_system" for the instance of
# this class.
#==============================================================================
class Game_System
#--------------------------------------------------------------------------
# * Public Instance Variables
#--------------------------------------------------------------------------
attr_accessor :lockpick_id
#--------------------------------------------------------------------------
# * Alias Listing
#--------------------------------------------------------------------------
alias dargor_lock_system_initialize initialize
#--------------------------------------------------------------------------
# * Object Initialization
#--------------------------------------------------------------------------
def initialize
dargor_lock_system_initialize
@lockpick_id = 33
end
end
#==============================================================================
# ** Game_Actor
#------------------------------------------------------------------------------
# This class handles the actor. It's used within the Game_Actors class
# ($game_actors) and refers to the Game_Party class ($game_party).
#==============================================================================
class Game_Actor
#--------------------------------------------------------------------------
# * Public Instance Variables
#--------------------------------------------------------------------------
attr_accessor :lockpicking_level
attr_accessor :lockpicking_level_max
attr_accessor :lockpicking_exp
#--------------------------------------------------------------------------
# * Alias Listing
#--------------------------------------------------------------------------
alias dargor_lock_actor_setup setup
#--------------------------------------------------------------------------
# * Setup
# actor_id : actor ID
#--------------------------------------------------------------------------
def setup(actor_id)
dargor_lock_actor_setup(actor_id)
@lockpicking_level = check_lockpicking_level
@lockpicking_level_max = 100
@lockpicking_exp = 0
end
def can_lockpick?
return (Lockpicking::Actors.include?(id) and
Lockpicking::Classes.include?(@class_id))
end
#--------------------------------------------------------------------------
# * Lock Pick (Lock picking process)
#--------------------------------------------------------------------------
def lockpick
# Store the target lock level into lock_level
lock_level = $game_temp.lockpick_target_level
# Succes rate formula (depends on the lock picking level type)
if Lockpicking::Use_Actors_Level.include?(@id)
success_rate = (@level*100)/lock_level
@lockpicking_level = @level
else
success_rate = (@lockpicking_level*100)/lock_level
end
# If lock pick use is 0, unequip it (Used when lock pick is a RPG::Weapon)
if $game_temp.lockpick_use == 0
#$game_temp.lockpick_actor.equip(0, 0)
#$game_party.lose_weapon($game_system.lockpick_id, 1)
return
else
$game_temp.lockpick_use -= 1
end
# Success Randomization
if rand(100) <= success_rate
# Skip exp/level step if using actor's level instead of
# lock picking level
unless Lockpicking::Use_Actors_Level.include?(@id)
last_level = @lockpicking_level
#@lockpicking_exp = 0 if @lockpicking_exp.nil?
@lockpicking_exp += 20
@lockpicking_level = check_lockpicking_level
# Check for lock picking level up
if last_level < @lockpicking_level
$game_temp.lockpick_levelup_flag[@actor_id] = true
else
$game_temp.lockpick_levelup_flag[@actor_id] = false
end
end
# Success
$game_temp.lockpick_success = true
return
else
# Failure
$game_temp.lockpick_success = false
return
end
end
# Change lockpicking level
# Updated by Belak51
def check_lockpicking_level
if @lockpicking_exp == nil
return 1
else
loopNum = 1
while loopNum <= 100
exp_lvl = (loopNum*(loopNum-1))*10..((loopNum*(loopNum+1))*10)-1
exp_lvl.each { |x| return loopNum if @lockpicking_exp == x}
loopNum = loopNum + 1
end
end
end
end
#==============================================================================
# ** Game_Event
#------------------------------------------------------------------------------
# This class deals with events. It handles functions including event page
# switching via condition determinants, and running parallel process events.
# It's used within the Game_Map class.
#==============================================================================
class Game_Event < Game_Character
#--------------------------------------------------------------------------
# * Public Instance Variables
#--------------------------------------------------------------------------
attr_accessor :broken # broken
#--------------------------------------------------------------------------
# * Alias Listing
#--------------------------------------------------------------------------
alias lockpick_event_initialize initialize
#--------------------------------------------------------------------------
# * Object Initialization
#--------------------------------------------------------------------------
def initialize(map_id, event)
@broken = false
lockpick_event_initialize(map_id, event)
end
#--------------------------------------------------------------------------
# * Broken?
#--------------------------------------------------------------------------
def broken?
return @broken
end
end
#==============================================================================
# ** Window_LockLevel
#------------------------------------------------------------------------------
# This window displays lock picking variables (User level, Target level, #use).
#==============================================================================
class Window_LockLevel < Window_Base
#--------------------------------------------------------------------------
# * Object Initialization
#--------------------------------------------------------------------------
def initialize
super(16,16,240,128)
self.contents = Bitmap.new(width - 32, height - 32)
self.back_opacity = 160
refresh
end
#--------------------------------------------------------------------------
# * Refresh
#--------------------------------------------------------------------------
def refresh
self.contents.clear
if $game_temp.lockpick_actor.nil?
return
end
# Draw User Lock Picking Level
self.contents.font.color = system_color
self.contents.draw_text(0,0,200,32,'Lock Picking Level:')
self.contents.font.color = normal_color
if Lockpicking::Use_Actors_Level.include?($game_temp.lockpick_actor.id)
lockpicking_level = $game_temp.lockpick_actor.level.to_s
self.contents.draw_text(0,0,200,32,lockpicking_level,2)
else
lockpicking_level = $game_temp.lockpick_actor.lockpicking_level.to_s
self.contents.draw_text(0,0,200,32,lockpicking_level,2)
end
# Draw Target Lock Level
self.contents.font.color = system_color
self.contents.draw_text(0,32,160,32,'Target Lock Level:')
self.contents.font.color = normal_color
lock_level = $game_temp.lockpick_target_level.to_s
self.contents.draw_text(0,32,200,32,lock_level,2)
# Draw Lock Pick #use
self.contents.font.color = system_color
self.contents.draw_text(0,64,160,32,'Use:')
self.contents.font.color = normal_color
use = $game_temp.lockpick_use.to_s
self.contents.draw_text(0,64,200,32,use,2)
end
end
#==============================================================================
# ** Scene_LockPick
#------------------------------------------------------------------------------
# This class performs lock picking screen processing.
#==============================================================================
class Scene_LockPick
#--------------------------------------------------------------------------
# * Object Initialization
#--------------------------------------------------------------------------
def initialize(event, level, max_try=-1)
@event = $game_map.events[event]
$game_temp.lockpick_target_level = level
@max_try = max_try
end
#--------------------------------------------------------------------------
# * Main Processing
#--------------------------------------------------------------------------
def main
@step = 0
@spriteset = Spriteset_Map.new
@lockpick_level = Window_LockLevel.new
@lockpick_message = Window_Help.new
@lockpick_message.visible = false
@lockpick_message.y = 416
@lockpick_message.back_opacity = 160
@lockpick_message.pause = true
@commands = []
for i in 0...$game_party.actors.size
actor = $game_party.actors[i]
@commands << actor.name if actor.can_lockpick?
end
@lockpick_commands = Window_Command.new(160,@commands)
@lockpick_commands.x = 16
@lockpick_commands.y = @lockpick_level.y + @lockpick_level.height
@lockpick_commands.back_opacity = 160
# 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
# Refresh map
$game_map.refresh
# Prepare for transition
Graphics.freeze
@spriteset.dispose
# Dispose of windows
@lockpick_commands.dispose
@lockpick_level.dispose
@lockpick_message.dispose
end
#--------------------------------------------------------------------------
# * Frame Update
#--------------------------------------------------------------------------
def update
$game_party.refresh
@lockpick_commands.update
@lockpick_message.update
@lockpick_level.refresh
$game_temp.lockpick_actor = $game_party.actors[@lockpick_commands.index]
unless @lockpick_message.visible
equipped_weapon = $game_temp.lockpick_actor.weapon_id
if Input.trigger?(Input::C) #and equipped_weapon == $game_system.lockpick_id
$game_system.se_play($data_system.decision_se)
$game_temp.lockpick_actor.lockpick
unless @max_try == -1 and not @event.broken
@max_try -= 1
@lockpick_message.visible = true
if @max_try == 0
@lockpick_message.set_text('Lock broken.',1)
@event.broken = true
@step = 3
return
end
end
if $game_temp.lockpick_use == 0
@lockpick_message.set_text('Lock pick used up!',1)
@step = 3
return
end
if $game_temp.lockpick_success
@lockpick_message.set_text('Lock pick success!',1)
key = [$game_map.map_id, @event.id, "A"]
$game_self_switches[key] = true
$game_map.need_refresh = true
if $game_temp.lockpick_levelup_flag[$game_temp.lockpick_actor.id]
@step = 1
else
@step = 2
end
else
@lockpick_message.set_text('Lock pick failed.',1)
@step = 3
end
return
#elsif Input.trigger?(Input::C) and equipped_weapon != $game_system.lockpick_id
# name = $game_temp.lockpick_actor.name
# @lockpick_message.set_text("#{name} doesn't have a lock pick!",1)
# @step = 3
elsif Input.trigger?(Input::B)
$game_temp.lockpick_target_level = nil
$game_temp.lockpick_actor = nil
$scene = Scene_Map.new
return
end
else
actor_id = $game_temp.lockpick_actor.id
if Input.trigger?(Input::C)
#$game_system.se_play($data_system.decision_se)
case @step
when 1
name = $game_temp.lockpick_actor.name
new_level = $game_temp.lockpick_actor.lockpicking_level
@lockpick_message.set_text("#{name}'s lock picking raised to level #{new_level}!",1)
$game_temp.lockpick_levelup_flag[actor_id] == false
@step = 2
when 2
$scene = Scene_Map.new
return
when 3
@step = 0
@lockpick_message.visible = false
end
end
end
end
end