class Game_Player < Game_Character
attr_reader :vehicle_type # type of vehicle currenting being ridden
def initialize
super()
@last_vehicle_type = -1
@vehicle_type = -1
@vehicle_getting_on = false # Boarding vehicle flag
@vehicle_getting_off = false # Getting off vehicle flag
@transferring = false # Player transfer flag
@new_map_id = 0 # Destination map ID
@new_x = 0 # Destination X coordinate
@new_y = 0 # Destination Y coordinate
@new_direction = 0 # Post-movement direction
@walking_bgm = nil # For walking BGM memory
end
def passable?(x, y, d)
return false unless $game_map.valid?(x, y)
if $DEBUG and Input.press?(Input::CTRL)
return true
end
if @through
unless $game_player.in_airship?
return true
end
end
return false unless map_passable?(x, y) # Map Impassable?
return true # Passable
end
def map_passable?(x, y)
case @vehicle_type
when 0 # Boat
return $game_map.boat_passable?(x, y)
when 1 # Ship
return $game_map.ship_passable?(x, y)
when 2 # Airship
return $game_map.airship_passable?(x, y)
else # Walking
return Game_Character.new.passabile?(x, y, $game_player.direction)
end
end
def can_walk?(x, y)
@last_vehicle_type = @vehicle_type # Remove vehicle type
@vehicle_type = -1 # Temporarily set to walking
result = Game_Character.new.passabile?(x, y, $game_player.direction) # Determine if passable
@vehicle_type = @last_vehicle_type # Restore vehicle type
return result
end
def airship_land_ok?(x, y)
unless $game_map.airship_land_ok?(x, y)
return false # The tile passable attribute is unlandable
end
unless $game_map.events_xy(x, y).empty?
return false # Cannot land where there is an event
end
return true # Can land
end
def veicolo_utilizzato?
return @last_vehicle_type >= 0
end
def utilizzato_aereo?
return @last_vehicle_type == 2
end
def in_vehicle?
return @vehicle_type >= 0
end
def in_airship?
return @vehicle_type == 2
end
alias player_moveto moveto
def moveto(x, y)
player_moveto(x, y)
if in_vehicle? # Riding in vehicle
vehicle = $game_map.vehicles[@vehicle_type] # Get vehicle
vehicle.refresh # Refresh
end
end
alias player_steps increase_steps
def increase_steps
return if in_vehicle?
player_steps
end
def move_by_input
return unless movable?
return if $game_map.interpreter.running?
case Input.dir4
when 2; move_down
when 4; move_left
when 6; move_right
when 8; move_up
end
end
def movable?
return false if moving? # Moving
return false if @move_route_forcing # On forced move route
return false if @vehicle_getting_on # Boarding vehicle
return false if @vehicle_getting_off # Getting off vehicle
return false if $game_temp.message_window_showing # Displaying a message
return false if in_airship? and not $game_map.airship.movable?
return true
end
def update
last_real_x = @real_x
last_real_y = @real_y
last_moving = moving?
move_by_input
super
update_scroll(last_real_x, last_real_y)
update_vehicle
update_nonmoving(last_moving)
end
def update_scroll(last_real_x, last_real_y)
ax1 = $game_map.adjust_x(last_real_x)
ay1 = $game_map.adjust_y(last_real_y)
ax2 = $game_map.adjust_x(@real_x)
ay2 = $game_map.adjust_y(@real_y)
if ay2 > ay1 and ay2 > CENTER_Y
$game_map.scroll_down(ay2 - ay1)
end
if ax2 < ax1 and ax2 < CENTER_X
$game_map.scroll_left(ax1 - ax2)
end
if ax2 > ax1 and ax2 > CENTER_X
$game_map.scroll_right(ax2 - ax1)
end
if ay2 < ay1 and ay2 < CENTER_Y
$game_map.scroll_up(ay1 - ay2)
end
end
def update_vehicle
return unless in_vehicle?
vehicle = $game_map.vehicles[@vehicle_type]
if @vehicle_getting_on # Boarding?
if not moving?
@direction = vehicle.direction # Change direction
@move_speed = vehicle.speed # Change movement speed
@vehicle_getting_on = false # Finish boarding operation
@transparent = true # Transparency
end
elsif @vehicle_getting_off # Getting off?
if not moving? and vehicle.altitude == 0
@vehicle_getting_off = false # Finish getting off operation
@vehicle_type = -1 # Erase vehicle type
@last_vehicle_type = -1
@transparent = false # Remove transparency
end
else # Riding in vehicle
vehicle.sync_with_player # Move at the same time as player
end
end
def update_nonmoving(last_moving)
return if $game_map.interpreter.running?
return if moving?
return if check_touch_event if last_moving
if not $game_temp.message_window_showing and Input.trigger?(Input::C)
return if get_on_off_vehicle
return if check_action_event
end
update_encounter if last_moving
end
def update_encounter
return if $TEST and Input.press?(Input::CTRL) # During test play?
return if in_vehicle? # Riding in vehicle?
if $game_map.bush?(@x, @y) # If in bush
@encounter_count -= 2 # Reduce encounters by 2
else # If not in bush
@encounter_count -= 1 # Reduce encounters by 1
end
end
def check_touch_event
return false if in_airship?
return check_event_trigger_here([1,2])
end
def check_action_event
return false if in_airship?
return true if check_event_trigger_here([0])
return check_event_trigger_there([0,1,2])
end
def get_on_off_vehicle
return false unless movable?
if in_vehicle?
return get_off_vehicle
else
return get_on_vehicle
end
end
def get_on_vehicle
front_x = $game_map.x_with_direction(@x, @direction)
front_y = $game_map.y_with_direction(@y, @direction)
if $game_map.airship.pos?(@x, @y) # Is it overlapping with airship?
get_on_airship
return true
elsif $game_map.ship.pos?(front_x, front_y) # Is there a ship in front?
get_on_ship
return true
elsif $game_map.boat.pos?(front_x, front_y) # Is there a boat in front?
get_on_boat
return true
end
return false
end
def get_on_boat
@vehicle_getting_on = true # Boarding flag
@vehicle_type = 0 # Set vehicle type
force_move_forward # Move one step forward
@walking_bgm = $game_temp.map_bgm # Memorize walking BGM
$game_map.boat.get_on # Boarding processing
end
def get_on_ship
@vehicle_getting_on = true # Board
@vehicle_type = 1 # Set vehicle type
force_move_forward # Move one step forward
@walking_bgm = $game_temp.map_bgm # Memorize walking BGM
$game_map.ship.get_on # Boarding processing
end
def get_on_airship
@vehicle_getting_on = true # Start boarding operation
@vehicle_type = 2 # Set vehicle type
@through = true # Passage ON
@walking_bgm = $game_temp.map_bgm # Memorize walking BGM
$game_map.airship.get_on # Boarding processing
end
def get_off_vehicle
if in_airship? # Airship
return unless airship_land_ok?(@x, @y) # Can't land?
else # Boat/ship
front_x = $game_map.x_with_direction(@x, @direction)
front_y = $game_map.y_with_direction(@y, @direction)
return unless can_walk?(front_x, front_y) # Can't touch land?
end
$game_map.vehicles[@vehicle_type].get_off # Get off processing
if in_airship? # Airship
@direction = 2 # Face down
else # Boat/ship
force_move_forward # Move one step forward
@transparent = false # Remove transparency
end
@vehicle_getting_off = true # Start getting off operation
@move_speed = 4 # Return move speed
@through = false # Passage OFF
$game_system.bgm_play(@walking_bgm) # Restore walking BGM
make_encounter_count # Initialize encounter
end
def force_move_forward
@through = true # Passage ON
move_forward # Move one step forward
@through = false # Passage OFF
end
end