Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #==============================================================================
- # ■ 物品拾起 by 余音·魔眼
- #------------------------------------------------------------------------------
- # 使用说明:
- # 在空白的事件首行输入<物品类型(空格)物品编号>,
- # 进游戏里,物品就会出现在该事件的位置。
- # 物品类型中,"ITEM"代表物品,"WEAPON"代表武器,"ARMOR"代表护甲,
- # 例:<"ITEM" 1>就代表在该事件位置摆放1号物品恢复剂。
- # 在举起道具的状态时,按下按妞(:B)时,
- # 会使用正在举起的物品(前提是该物品的使用场合必须设置为随时可用),
- # 若该物品是消耗品,使用后将消失,人物也将变回原来的行走状态,
- # 若不是,则没有演出效果。
- # 与NPC对话时,可以把正在举起的物品交给他/她,会赠送物品给他/她。
- # 设置时可用事件脚本clear_item清除主角手中的物品,
- # 可用pick_lift?(物品类型("ITEM"/"WEAPON"/"ARMOR"), 物品编号)
- # 判断正在举起的物品ID。
- #==============================================================================
- module Hawkeye; end
- module Hawkeye::Pick
- #==============================================================================
- # ■ 设定开始
- #==============================================================================
- MoveTime = 10
- #举起或放下物品的时间(帧)
- IncomTime = 12
- #物品放进背包的时间(帧)
- Deviation = 22
- #举起物品时,物品Y坐标与人物正中心的距离
- LiftSuffix = "_Pickup"
- #人物举起物品时的文件后缀
- IncomSuffix = "_Putaway"
- #人物将物品放进背包时的文件后缀
- #==============================================================================
- # ■ 设定结束
- #==============================================================================
- end
- class RPG::Item
- alias hawkeye_pick_item_menu_ok? menu_ok?
- def menu_ok?
- if $game_player.pick_lift?
- @occasion == 0
- else
- hawkeye_pick_item_menu_ok?
- end
- end
- end
- class Game_Actor
- attr_accessor :state
- alias hawkeye_pick_item_conditions_met? item_conditions_met?
- def item_conditions_met?(item)
- if $game_party.in_battle
- hawkeye_pick_item_conditions_met?(item)
- else
- usable_item_conditions_met?(item) && pick_lift?
- end
- end
- def pick_lift?
- @state == :lift
- end
- end
- class Game_Party
- alias hawkeye_pick_consume_item consume_item
- def consume_item(item)
- if in_battle
- hawkeye_pick_consume_item
- else
- return
- end
- end
- end
- class Game_Map
- attr_accessor :map_data, :map, :event
- def setup(map_id)
- @map_data ||= {}
- @map_id = map_id
- @map = @map_data[@map_id] ? @map_data[@map_id] : load_data(sprintf("Data/Map%03d.rvdata2", @map_id))
- @tileset_id = @map.tileset_id
- @display_x = 0
- @display_y = 0
- referesh_vehicles
- setup_events
- setup_scroll
- setup_parallax
- setup_battleback
- @need_refresh = false
- end
- def setup_events
- c_event = current_event
- @events = {}
- @map.events.each do |i, event|
- @events[i] = Game_Event.new(@map_id, event)
- end
- if c_event
- id = @events != {} ? @events.keys.max + 1 : 1
- @map.events[id] = RPG::Event.new(c_event.x, c_event.y)
- @map.events[id].id = id
- @events[id] = c_event
- @events[id].id = id
- c_event = nil
- end
- @common_events = parallel_common_events.collect do |common_event|
- Game_CommonEvent.new(common_event.id)
- end
- refresh_tile_events
- end
- alias hawkeye_pick_passable? passable?
- def passable?(x, y, d)
- return false if item_ly?(x, y)
- hawkeye_pick_passable?(x, y, d)
- end
- def clear_current_event
- event = @events.values.find{|event|event.pick_lift?}
- @events.delete(event.id)
- @map.events.delete(event.id)
- end
- def create_current_event(item)
- id = @events != {} ? @events.keys.max + 1 : 1
- x, y = $game_player.x, $game_player.y
- @map.events[id] = RPG::Event.new(x, y)
- @map.events[id].id = id
- type = {RPG::Item => "ITEM", RPG::Weapon => "WEAPON", RPG::Armor => "ARMOR"}
- @map.events[id].pages[0].list[0].code = 108
- @map.events[id].pages[0].list[0].parameters[0] = "<"+type[item.class]+" "+item.id.to_s+">"
- @events[id] = Game_Event.new(@map_id, RPG::Event.new(x, y))
- lift_deviation = @events[id].lift_deviation
- @events[id].y -= lift_deviation
- @events[id].real_y -= lift_deviation
- @events[id].id = id
- @events[id].priority_type = 2
- @events[id].state = :lift
- @events[id].item = item
- end
- def current_event
- @events.values.find{|event|event.pick_lift?}
- end
- def pick_pos?(event, x, y)
- [event.x, event.y] == [x, y]
- end
- def item_ly?(x, y)
- @events.values.any?{|event|event.pick_ly? && pick_pos?(event, x, y)}
- end
- end
- class Game_Player
- attr_reader :state
- attr_accessor :pattern
- alias hawkeye_pick_initialize initialize
- def initialize
- hawkeye_pick_initialize
- @state = :empty
- end
- alias hawkeye_pick_move_by_input move_by_input
- def move_by_input
- return if pick_wait? || pick_incom?
- hawkeye_pick_move_by_input
- end
- def state=(value)
- @state = value
- actor.state = @state
- end
- def pick_wait?
- @state == :wait
- end
- def pick_incom?
- @state == :incom
- end
- def pick_empty?
- @state == :empty
- end
- def pick_lift?
- @state == :lift
- end
- def perform_transfer
- if transfer?
- set_direction(@new_direction)
- $game_map.map_data[$game_map.map_id] = Marshal.load(Marshal.dump($game_map.map))
- $game_map.map_data[$game_map.map_id].events.each do |id, event|
- $game_map.events[id].create_all_list(event) if !$game_map.events[id].pick_lift?
- end
- if @new_map_id != $game_map.map_id
- $game_map.setup(@new_map_id)
- $game_map.autoplay
- end
- moveto(@new_x, @new_y)
- clear_transfer_info
- end
- end
- end
- class Game_Event
- include Hawkeye::Pick
- attr_accessor :id, :x, :y, :real_x, :real_y, :state, :item, :priority_type
- alias hawkeye_pick_refresh refresh
- def refresh
- return if @state
- hawkeye_pick_refresh
- end
- alias hawkeye_pick_initialize initialize
- def initialize(map_id, event)
- hawkeye_pick_initialize(map_id, event)
- return unless @list
- @list.each do |command|
- if command.code == 108 || command.code == 408
- command.parameters.each do |line|
- if line =~ /<(.+?)[ ]*(\d+)>/i
- @typekey, id = $1.upcase, $2.to_i
- @type = {
- "ITEM" => $data_items[id],
- "WEAPON" => $data_weapons[id],
- "ARMOR" => $data_armors[id]
- }
- init_ly
- break
- end
- end
- end
- end
- end
- def clear_data
- clear_page_settings
- @through = false
- clear_all_list
- @priority_type = 1 if @priority_type != 1
- @trigger = 0
- end
- def init_ly
- @item = @type[@typekey]
- save_all_list
- clear_data
- @state = :ly
- end
- def clear_all_list
- @event.pages.each{|page|page.list = []}
- end
- def save_all_list
- @last_pages = Marshal.load(Marshal.dump(@event.pages))
- end
- def create_all_list(event)
- event.pages = Marshal.load(Marshal.dump(@last_pages)) if @last_pages
- end
- def pick_condition?
- $game_player.movable? && Input.trigger?(:C) &&
- !$game_player.pick_wait? && !moving? &&
- !$game_player.moving?
- end
- def pos_round?(x, y, xl, yl, obj)
- [x, y] == [obj.x + xl, obj.y + yl]
- end
- def get_pos_round_xy(xl, yl, obj)
- @x, @y = obj.x + xl, obj.y + yl
- end
- def get_pos_round_rxry(xl, yl, obj)
- @real_x, @real_y = obj.real_x + xl, obj.real_y + yl
- end
- def orient?(d)
- @last_direction = d
- $game_player.direction == d
- end
- def pick_ly?
- @state == :ly
- end
- def pick_lift?
- @state == :lift
- end
- def pick_up?
- @state == :up
- end
- def pick_down?
- @state == :down
- end
- def ly_condition?
- pick_lift? && $game_player.pick_lift? && @priority_type == 2
- end
- def lift_condition?
- pick_ly? && $game_player.pick_empty? && @priority_type == 1
- end
- def ready_ly
- ready_ly_direction if orient?(4)
- ready_ly_direction if orient?(6)
- ready_ly_direction if orient?(8)
- ready_ly_direction if orient?(2)
- end
- def ready_lift
- @incoord = {4 => 6, 6 => 4, 8 => 2, 2 => 8}
- player = $game_player
- ready_lift_direction if pos_round?(@x, @y, -1, 0, player) && orient?(4)
- ready_lift_direction if pos_round?(@x, @y, 1, 0, player) && orient?(6)
- ready_lift_direction if pos_round?(@x, @y, 0, -1, player) && orient?(8)
- ready_lift_direction if pos_round?(@x, @y, 0, 1, player) && orient?(2)
- end
- def ready_ly_direction
- @state = :down
- $game_player.state = :wait
- move_straight($game_player.direction)
- end
- def ready_lift_direction
- @state = :up
- $game_player.state = :wait
- @priority_type = 2
- move_straight(@incoord[@last_direction])
- end
- def update
- super
- check_event_trigger_auto
- process_pick
- return unless @interpreter
- @interpreter.setup(@list, @event.id) unless @interpreter.running?
- @interpreter.update
- end
- def process_pick
- ready_pick if pick_condition?
- fin_move if $game_player.pick_wait? && !moving?
- track_player if pick_lift?
- end
- def ready_pick
- ready_lift if lift_condition?
- ready_ly if ly_condition?
- end
- def fin_move
- character_name = $game_player.actor.actor.character_name
- name = character_name + LiftSuffix
- get = {
- :up => [name, :lift, :lift],
- :down => [character_name, :ly, :empty]
- }
- if pick_up? || pick_down?
- @priority_type = 1 if @state == :down
- last_state = @state
- $game_player.set_graphic(get[last_state][0], 0)
- @state = get[last_state][1]
- $game_player.state = get[last_state][2]
- end
- end
- def track_player
- rx, ry = @real_x, @real_y
- rx_l, ry_l = 0, -lift_deviation
- player = $game_player
- if !pos_round?(rx, ry, rx_l, ry_l, player)
- get_pos_round_rxry(rx_l, ry_l, player)
- end
- if !$game_player.moving?
- get_pos_round_xy(0, -lift_deviation, player)
- end
- end
- alias hawkeye_pick_distance_per_frame distance_per_frame
- def distance_per_frame
- if $game_player.pick_wait? && (pick_up? || pick_down?)
- return 1.0 / MoveTime
- else
- hawkeye_pick_distance_per_frame
- end
- end
- alias hawkeye_pick_move_straight move_straight
- def move_straight(d, turn_ok = true)
- if pick_down?
- @y += lift_deviation
- if !passable?(@x, @y, d)
- @state = :lift
- $game_player.state = :lift
- @y -= lift_deviation
- return
- end
- end
- hawkeye_pick_move_straight(d)
- @real_y -= lift_deviation if pick_down?
- @y = pick_up? ? @y - lift_deviation : @y if @move_succeed
- $game_map.map.events[id].x, $game_map.map.events[id].y = @x, @y
- end
- def lift_deviation
- return Deviation / 32.0
- end
- end
- class Game_Interpreter
- def clear_item
- SceneManager.scene.clear_item if $game_player.pick_lift?
- end
- def pick_lift?(type, id)
- type_class = {
- "ITEM" => RPG::Item,
- "WEAPON" => RPG::Weapon,
- "ARMOR" => RPG::Armor
- }
- return false unless $game_map.current_event
- return false if type != "ITEM" && type != "WEAPON" && type != "ARMOR"
- item = $game_map.current_event.item
- return item.is_a?(type_class[type.upcase]) && item.id == id
- end
- end
- class Spriteset_Map
- attr_reader :tile_map
- alias hawkeye_pick_create_tilemap create_tilemap
- def create_tilemap
- hawkeye_pick_create_tilemap
- create_items
- end
- def create_items
- @item_sprite = []
- $game_map.events.each_value do |event|
- if (event.pick_ly? || event.pick_lift?) && event.item
- @item_sprite.push(Sprite_Pick.new(event.item, event, @tilemap))
- end
- end
- end
- alias hawkeye_pick_update_tilemap update_tilemap
- def update_tilemap
- hawkeye_pick_update_tilemap
- update_pick
- end
- def update_pick
- refresh_pick if @map_id != $game_map.map_id
- @item_sprite.each{|sprite|sprite.update}
- end
- alias hawkeye_pick_dispose dispose
- def dispose
- hawkeye_pick_dispose
- dispose_pick
- end
- def dispose_pick
- @item_sprite.each{|sprite|sprite.dispose}
- end
- def clear_current_sprite
- current_sprite.dispose
- @item_sprite.delete_if{|sprite|sprite.disposed?}
- end
- def current_sprite
- @item_sprite.find{|sprite|sprite.event.pick_lift?}
- end
- def current_event
- current_sprite.event
- end
- def current_item
- current_event.item
- end
- def refresh_pick
- dispose_pick
- create_items
- end
- def update_tileset
- if @tileset != $game_map.tileset
- load_tileset
- refresh_characters
- refresh_pick
- end
- end
- end
- class Sprite_Pick < Sprite
- attr_reader :event
- def initialize(item, event, tilemap)
- super(nil)
- self.x, self.y, self.z = event.x * 32, event.y * 32, event.screen_z
- self.ox, self.oy = tilemap.ox , tilemap.oy
- self.bitmap = Bitmap.new(32, 32)
- draw_icon(item.icon_index, 4, 4)
- @tilemap = tilemap
- @event = event
- end
- def draw_icon(icon_index, x, y)
- bitmap = Cache.system("Iconset")
- rect = Rect.new(icon_index % 16 * 24, icon_index / 16 * 24, 24, 24)
- self.bitmap.blt(x, y, bitmap, rect)
- end
- def update
- super
- update_placement
- end
- def update_placement
- self.ox = @tilemap.ox if self.ox != @tilemap.ox
- self.oy = @tilemap.oy if self.oy != @tilemap.oy
- get_pick_pos(@event) if !pick_pos?(@event, self.x, self.y)
- self.z = @event.screen_z + 1 if self.z != @event.screen_z + 1 && @event.pick_lift?
- end
- def pick_pos?(event, x, y)
- [x, y] == [event.real_x * 32, event.real_y * 32]
- end
- def get_pick_pos(event)
- self.x, self.y = event.real_x * 32, event.real_y * 32
- end
- end
- class Window_ItemList
- def enable?(item)
- item ? true : false
- end
- end
- class Scene_Map
- attr_reader :spriteset
- include Hawkeye::Pick
- alias hawkeye_pick_update update
- def update
- if $game_player.pick_lift?
- process_use if Input.trigger?(:B)
- incom_bag if Input.trigger?(:A)
- end
- hawkeye_pick_update
- end
- def process_use
- if item_usable?
- use_item
- clear_item if @spriteset.current_item.consumable
- else
- Sound.play_buzzer
- end
- end
- def incom_bag
- $game_party.gain_item(@spriteset.current_item, 1)
- @spriteset.clear_current_sprite
- $game_map.clear_current_event
- $game_player.state = :incom
- @last_direction = $game_player.direction
- $game_player.set_direction(2)
- $game_player.set_graphic(character_name + IncomSuffix, 0)
- end
- alias hawkeye_pick_update_basic update_basic
- def update_basic
- update_wait_incom if $game_player.pick_incom?
- hawkeye_pick_update_basic
- end
- def update_wait_incom
- @count ||= 1
- pattern = {
- IncomTime / 3 * 0 + 1 => 0,
- IncomTime / 3 * 1 + 1 => 0,
- IncomTime / 3 * 2 + 1 => 0,
- }
- $game_player.pattern = pattern[@count] if pattern.keys.include?(@count)
- @count += 1
- fin_move if @count > IncomTime
- end
- def fin_move
- $game_player.state = :empty
- $game_player.set_graphic(character_name, 0)
- $game_player.set_direction(@last_direction)
- @last_direction = nil
- @count = nil
- end
- alias hawkeye_pick_update_call_menu update_call_menu
- def update_call_menu
- return if wait_judge?
- hawkeye_pick_update_call_menu
- end
- alias hawkeye_pick_update_call_debug update_call_debug
- def update_call_debug
- return if wait_judge?
- hawkeye_pick_update_call_debug
- end
- def wait_judge?
- $game_player.pick_lift? || $game_player.pick_wait? || $game_player.pick_incom?
- end
- def character_name
- $game_player.actor.actor.character_name
- end
- def item_usable?
- user.usable?(item) && item_effects_valid?
- end
- def user
- $game_player.actor
- end
- def item_target_actors
- return user
- end
- def item_usable?
- user.usable?(item) && item_effects_valid?
- end
- def item_effects_valid?
- [item_target_actors].any? do |target|
- target.item_test(user, item)
- end
- end
- def use_item
- play_se_for_item
- user.use_item(item)
- use_item_to_actors
- check_common_event
- check_gameover
- end
- def play_se_for_item
- Sound.play_use_item
- end
- def use_item_to_actors
- [item_target_actors].each do |target|
- item.repeats.times { target.item_apply(user, item) }
- end
- end
- def item
- return $game_map.events.values.find{|event|event.pick_lift?}.item
- end
- def check_common_event
- SceneManager.goto(Scene_Map) if $game_temp.common_event_reserved?
- end
- def clear_item
- @spriteset.clear_current_sprite
- $game_map.clear_current_event
- $game_player.set_graphic(character_name, 0)
- $game_player.state = :empty
- end
- end
- class Scene_ItemBase
- include Hawkeye::Pick
- def determine_item
- $game_map.create_current_event(item)
- $game_player.set_graphic(character_name + LiftSuffix, 0)
- $game_player.state = :lift
- $game_party.lose_item(item, 1)
- activate_item_window
- SceneManager.goto(Scene_Map)
- end
- def character_name
- $game_player.actor.actor.character_name
- end
- end
Add Comment
Please, Sign In to add comment