#==============================================================================
# +++ MOG - 捡起和丢出事件 (v1.2) +++
#==============================================================================
# By Moghunter
# [url]https://atelierrgss.wordpress.com/[/url]
#==============================================================================
# 玩家可以把事件捡起和丢下,可用于解谜.
#==============================================================================
# 事件名带有↓ 的事件,都可以被玩家捡起和丢下.
#
# <ThrowX>
#
# X 事件被丢出去的距离.
#
# 例子:
#
# Event01<Throw4>
#
#==============================================================================
# 在角色捡起事件时改变自身的行走图(可选)
#==============================================================================
# 你可以在角色捡起事件时改变其行走图,方法是在Character文件夹里放上一张类似以下
# 文件名格式的行走图。
#
# 角色行走图名 + _Pickup
#
# 例子
#
# Actor1_Pickup.png
#==============================================================================
#==============================================================================
# ● Histórico (Version History)
#==============================================================================
# v 1.2 - Melhor codificação.
# v 1.1 - Melhor compatibilidade com scripts de terceiros.
#==============================================================================
module MOG_PICK_THROW
#被捡起事件的位置.
SPRITE_POSITION = 20
#丢出事件时播放的音效.
THROW_SE = "Jump2"
#捡起事件时播放的音效.
PICK_UP_SE = "Jump1"
#关闭本功能的开关.
DISABLE_PICKUP_SWITCH_ID = 100
# 捡起的按键.
PICKUP_BUTTON = Input::C
end
#==============================================================================
# ■ Game_Temp
#==============================================================================
class Game_Temp
attr_accessor :pickup_lock
attr_accessor :pickup_lock_time
attr_accessor :character_pre_name
attr_accessor :can_throw
attr_accessor :throw_position
#--------------------------------------------------------------------------
# ● initialize
#--------------------------------------------------------------------------
alias mog_pick_initialize initialize
def initialize
@pickup_lock = false
@pickup_lock_time = 0
@character_pre_name = ""
@can_throw = true
@throw_position = []
mog_pick_initialize
end
end
#==============================================================================
# ■ Game_Event
#==============================================================================
class Game_Event < Game_Character
attr_reader :jump_count
attr_accessor :x
attr_accessor :y
attr_accessor :bush_depth
attr_accessor :direction
#--------------------------------------------------------------------------
# ● initialize
#--------------------------------------------------------------------------
alias mog_pickup_initialize initialize
def initialize(map_id, event)
mog_pickup_initialize(map_id, event)
@throw_active = false
if event.name =~ /<Throw(\d+)>/i
@throw = $1.to_i
end
end
end
#==============================================================================
# ■ Game_CharacterBase
#==============================================================================
class Game_CharacterBase
attr_accessor :throw_active
attr_accessor :throw
#--------------------------------------------------------------------------
# ● initialize
#--------------------------------------------------------------------------
alias x_pickup_initialize initialize
def initialize
@throw_active = false
@throw = 0
x_pickup_initialize
end
end
#==============================================================================
# ■ Game_Character
#==============================================================================
class Game_Character < Game_CharacterBase
#--------------------------------------------------------------------------
# ● Throw Action
#--------------------------------------------------------------------------
def throw_action(range)
moveto($game_player.x,$game_player.y)
jump_range = range
moveto($game_player.x,$game_player.y)
range.times do
unless jumping?
case $game_player.direction
when 6
jump(jump_range,0) if throw_range?(jump_range,0,jump_range)
when 4
jump(-jump_range,0) if throw_range?(-jump_range,0,jump_range)
when 2
jump(0,jump_range) if throw_range?(0,jump_range,jump_range)
when 8
jump(0,-jump_range) if throw_range?(0,-jump_range,jump_range)
end
if @x == $game_player.x and @y == $game_player.y and jump_range == 1
$game_temp.can_throw = false
end
jump_range -= 1
end
end
end
#--------------------------------------------------------------------------
# ● Throw Range?
#--------------------------------------------------------------------------
def throw_range?(x, y,range )
x = $game_player.x
y = $game_player.y
case $game_player.direction
when 2
y += range
when 6
x += range
when 4
x -= range
when 8
y -= range
end
return false if collide_with_characters?(x, y)
return false unless map_passable?(x, y,$game_player.direction)
return true
end
end
#==============================================================================
# ■ Game_Player
#==============================================================================
class Game_Player < Game_Character
include MOG_PICK_THROW
#--------------------------------------------------------------------------
# ● Update Player Before Movement
#--------------------------------------------------------------------------
alias pickup_update update
def update
pickup_update
update_pickup_command
end
#--------------------------------------------------------------------------
# ● Update Pickup Command
#--------------------------------------------------------------------------
def update_pickup_command
$game_temp.pickup_lock_time -= 1 if $game_temp.pickup_lock_time > 0
return if $game_temp.pickup_lock_time > 0
if Input.trigger?(PICKUP_BUTTON)
throw_event if can_check_throw_event?
check_event_pickup([0,1,2]) if can_check_pickup_event?
end
end
#--------------------------------------------------------------------------
# ● Check Action Event
#--------------------------------------------------------------------------
alias mog_pickup_check_action_event check_action_event
def check_action_event
return if $game_temp.pickup_lock_time > 0 or $game_temp.pickup_lock
mog_pickup_check_action_event
end
#--------------------------------------------------------------------------
# ● Can Check Pickup Event
#--------------------------------------------------------------------------
def can_check_pickup_event?
return false if $game_temp.pickup_lock
return false if $game_temp.pickup_lock_time > 0
return false if $game_map.interpreter.running?
return false if $game_message.visible
return false if $game_switches[DISABLE_PICKUP_SWITCH_ID]
return true
end
#--------------------------------------------------------------------------
# ● Can Check Throw Event
#--------------------------------------------------------------------------
def can_check_throw_event?
return false if $game_temp.pickup_lock == false
return false if $game_temp.pickup_lock_time > 0
return false if $game_map.interpreter.running?
return false if $game_message.visible
return false if $game_switches[DISABLE_PICKUP_SWITCH_ID]
return true
end
#--------------------------------------------------------------------------
# ● Reserve Transfer
#--------------------------------------------------------------------------
alias mog_pickup_reserve_transfer reserve_transfer
def reserve_transfer(map_id, x, y, direction)
if $game_temp.pickup_lock == true
for event in $game_map.events.values
if event.throw_active == true
event.throw_active = false
event.moveto(@x,@y)
case @direction
when 2
event.jump(0,-1)
when 4
event.jump(1,0)
when 6
event.jump(-1,0)
when 8
event.jump(0,1)
end
end
end
$game_temp.pickup_lock = false
$game_temp.pickup_lock_time = 0
@character_name = $game_temp.character_pre_name
end
mog_pickup_reserve_transfer(map_id, x, y, direction)
end
#--------------------------------------------------------------------------
# ● Movable?
#--------------------------------------------------------------------------
alias mog_pickup_movable movable?
def movable?
return false if $game_temp.pickup_lock_time > 0
mog_pickup_movable
end
#--------------------------------------------------------------------------
# ● Throw Event
#--------------------------------------------------------------------------
def throw_event
for event in $game_map.events.values
if event.throw_active and not jumping?
$game_temp.can_throw = true
event.throw_action(event.throw)
return if $game_temp.can_throw == false
$game_temp.pickup_lock_time = event.jump_count
$game_temp.throw_position[0] = event.x
$game_temp.throw_position[1] = event.y
event.throw_active = false
$game_temp.pickup_lock = false
Audio.se_play("Audio/SE/" + THROW_SE, 100, 100)
@character_name = $game_temp.character_pre_name
break
end
end
if event == nil
$game_map.reset_pickup
end
end
#--------------------------------------------------------------------------
# ● Check Event Pickup
#--------------------------------------------------------------------------
def check_event_pickup(triggers)
front_x = $game_map.x_with_direction(@x, @direction)
front_y = $game_map.y_with_direction(@y, @direction)
for event in $game_map.events_xy(front_x, front_y)
if event.throw > 0 and not jumping?
event.throw_active = true
$game_temp.pickup_lock = true
event.jump(0,0)
$game_temp.pickup_lock_time = event.jump_count
event.x = $game_player.x
event.y = $game_player.y
Audio.se_play("Audio/SE/" + PICK_UP_SE, 100, 100)
$game_temp.character_pre_name = @character_name
make_pickup_pose
break
end
end
end
#--------------------------------------------------------------------------
# ● Img Pickup Exist?
#--------------------------------------------------------------------------
def img_pickup_exist?
Cache.character(@character_name + "_Pickup") rescue return false
end
#--------------------------------------------------------------------------
# ● Make Pickup Pose
#--------------------------------------------------------------------------
def make_pickup_pose
@character_name = @character_name + "_Pickup" if img_pickup_exist?
end
end
#==============================================================================
# ■ Sprite_Character
#==============================================================================
class Sprite_Character < Sprite_Base
include MOG_PICK_THROW
#--------------------------------------------------------------------------
# ● Update X Effects
#--------------------------------------------------------------------------
alias mog_pickup_update_position update_position
def update_position
mog_pickup_update_position
update_pickup_position if can_pickup_position?
end
#--------------------------------------------------------------------------
# ● Can Pickup Position
#--------------------------------------------------------------------------
def can_pickup_position?
return false if $game_temp.pickup_lock_time > 0
return false if $game_temp.pickup_lock == false
return false if @character.throw_active == false
return false if @character.is_a?(Game_Player)
return false if @character.jumping?
return true
end
#--------------------------------------------------------------------------
# ● Update Pickup Position
#--------------------------------------------------------------------------
def update_pickup_position
@character.x = $game_player.x
@character.y = $game_player.y
@character.bush_depth = 0
unless @character.direction_fix
@character.direction = $game_player.direction
end
self.x = $game_player.screen_x
self.y = $game_player.screen_y - SPRITE_POSITION
self.z = $game_player.screen_z + 1
end
end
#==============================================================================
# ■ Scene_Map
#==============================================================================
class Scene_Map < Scene_Base
#--------------------------------------------------------------------------
# ● Call Menu
#--------------------------------------------------------------------------
alias mog_pickup_call_menu call_menu
def call_menu
return if $game_temp.pickup_lock == true
mog_pickup_call_menu
end
end
#==============================================================================
# ■ Game Interpreter
#==============================================================================
class Game_Interpreter
#--------------------------------------------------------------------------
# ● Command 352
#--------------------------------------------------------------------------
alias mog_pickup_command_352 command_352
def command_352
return if $game_temp.pickup_lock == true
mog_pickup_command_352
end
end
#==============================================================================
# ■ Game_Map
#==============================================================================
class Game_Map
#--------------------------------------------------------------------------
# ● Setup
#--------------------------------------------------------------------------
alias mog_pickup_setup setup
def setup(map_id)
mog_pickup_setup(map_id)
reset_pickup
end
#--------------------------------------------------------------------------
# ● Reset Pickup
#--------------------------------------------------------------------------
def reset_pickup
for i in $game_map.events.values
if i.throw_active
i.throw_active = false
i.moveto($game_player.x,$game_player.y)
i.jump(0,0)
i.move_backward
$game_player.character_name = $game_temp.character_pre_name
end
end
$game_temp.pickup_lock_time = 0
$game_temp.pickup_lock = false
end
end
$mog_rgss3_pickup_and_throw = true