Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #==============================================================================
- # MS - Vehicles+
- #------------------------------------------------------------------------------
- # por Masked
- #==============================================================================
- #==============================================================================
- # Instruções
- #------------------------------------------------------------------------------
- # Para criar um evento-veículo, deixe o nome dele dessa forma:
- # vehicle[tipo]
- #
- # Sendo o tipo o nome (sem espaços) do veículo que você configurar, por
- # exemplo:
- # vehicle[horse]
- # ou:
- # vehicle[airship]
- #
- # Para um veículo customizado (que seja usado só uma vez, por exemplo) use
- # o tipo 'custom':
- # vehicle[custom]
- #
- # Dessa forma todas as configurações devem ser feitas por comentários do
- # evento, por exemplo:
- #
- # speed: 4,
- # p_flag: 0x0,
- # max: 0,
- # bgm: 'Ship',
- # flying: false,
- #
- #------------------------------------------------------------------------------
- # Flags de passabilidade
- #------------------------------------------------------------------------------
- # 0x000: Normal
- # 0x001: Passável por baixo
- # 0x002: Passável pela esquerda
- # 0x004: Passável pela direita
- # 0x008: Passável por cima
- # 0x020: Escada
- # 0x040: Arbusto
- # 0x080: Balcão
- # 0x100: Dano
- # 0x200: Bote
- # 0x400: Navio
- # 0x800: Dirigível pode estacionar
- #
- # P.S: Somar as flags é o mesmo que juntar elas, ou seja, se as flag for
- # 0x0800 + 0x0400 o veículo passará tanto por áreas onde dirigíveis podem
- # estacionar quanto em áreas onde o navio pode passar
- #==============================================================================
- ($imported ||= {})[:mbs_vehicles_plus] = true
- #==============================================================================
- # >> MBS
- #==============================================================================
- module MBS
- #============================================================================
- # >> VehiclesPlus
- #============================================================================
- module VehiclesPlus
- #==========================================================================
- # Configurações
- #==========================================================================
- # Definição dos veículos
- @@_vehicles = {
- # Bote
- boat: {
- # Velocidade (4 por padrão)
- speed: 4,
- # Flag de passabilidade (vide lista nas instruções)
- p_flag: 0x0200,
- # Máximo de veículos desse tipo num mapa (0 para ilimitado)
- max: 0,
- # Música de fundo do veículo na pasta Audio/BGM
- bgm: 'Ship',
- # Caso o veículo seja voador, mude para true, se não, false
- flying: false,
- },
- # Navio
- ship: {
- speed: 4,
- p_flag: 0x400,
- max: 0,
- bgm: 'Ship',
- flying: false,
- },
- # Dirigível
- airship: {
- speed: 4,
- p_flag: 0x0,
- max: 0,
- bgm: 'Airship',
- flying: true,
- },
- # Cavalo
- horse: {
- speed: 5,
- p_flag: 0x1 + 0x2 + 0x4 + 0x8,
- max: 0,
- bgm: 'Field1',
- flying: false,
- },
- # Balão
- baloon: {
- speed: 3,
- p_flag: 0x0,
- max: 0,
- bgm: 'Airship',
- flying: true,
- },
- }
- #==========================================================================
- # Fim das configurações
- #==========================================================================
- # Estrutura dos veículos
- Vehicle = Struct.new(:speed, :p_flag, :max, :show_player, :bgm, :flying)
- #--------------------------------------------------------------------------
- # * Aquisição de um veículo
- #--------------------------------------------------------------------------
- def self.vehicle(type)
- v = @@_vehicles[type]
- Vehicle.new(v[:speed], v[:p_flag], v[:max], v[:show_player], v[:bgm], v[:flying])
- end
- #--------------------------------------------------------------------------
- # * Aquisição da configuração do sistema para o veículo
- #--------------------------------------------------------------------------
- def self.system_vehicle(game_vehicle)
- return unless game_vehicle.event
- v = RPG::System::Vehicle.new
- v.character_name = game_vehicle.event.character_name
- v.character_index = game_vehicle.event.character_index
- v.bgm = RPG::BGM.new(vehicle(game_vehicle.type).bgm)
- v.start_map_id = game_vehicle.event.map_id
- v.start_x = game_vehicle.event.x
- v.start_y = game_vehicle.event.y
- v
- end
- #--------------------------------------------------------------------------
- # * Verificação da existência de um veículo
- #--------------------------------------------------------------------------
- def self.has_vehicle?(type)
- @@_vehicles.has_key?(type) || type == CUSTOM
- end
- #--------------------------------------------------------------------------
- # * Definição de um veículo customizado
- #--------------------------------------------------------------------------
- def self.register_custom(event)
- type = "custom_#{@@_vehicles.size}#{rand(999)}".to_sym
- comments = []
- event.list.each do |cmd|
- if cmd.code == 108 || cmd.code == 408
- comments << cmd.parameters[0]
- end
- end
- @@_vehicles[type] = eval("{#{comments.inject(""){|r, v| r + v}}}")
- type
- end
- # Padrão para o nome dos eventos de veículos
- REGEX = /^\s*vehicle[ ]*\[[ ]*(\S+)[ ]*\][ ]*$/i
- # Símbolo para veículos customizados
- CUSTOM = :custom
- end
- end
- #==============================================================================
- # ** Kernel
- #------------------------------------------------------------------------------
- # Atalhos para o alias
- #==============================================================================
- module Kernel
- #--------------------------------------------------------------------------
- # * Cria o alias
- #--------------------------------------------------------------------------
- def mbsalias(method)
- alias_method("mbsvehiclesplus_#{method}".to_sym, method.to_sym)
- end
- #--------------------------------------------------------------------------
- # * Chama o alias
- #--------------------------------------------------------------------------
- def mbscall(method, *a, &b)
- __send__("mbsvehiclesplus_#{method}".to_sym, *a, &b)
- end
- end
- #==============================================================================
- # ** Game_CharacterBase
- #------------------------------------------------------------------------------
- # Aqui são feitas as alterações para colidir com os veículos
- #==============================================================================
- class Game_CharacterBase
- #--------------------------------------------------------------------------
- # * Detectar colisão com veículos
- # x : coordenada X
- # y : coordenada Y
- #--------------------------------------------------------------------------
- def collide_with_vehicles?(x, y)
- $game_map.vehicles.any? {|v| v.pos_nt?(x, y)}
- end
- end
- #==============================================================================
- # ** Game_Player
- #------------------------------------------------------------------------------
- # Aqui são feitas as alterações para o personagem entrar nos veículos
- #==============================================================================
- class Game_Player < Game_Character
- mbsalias :update_vehicle_get_off
- #--------------------------------------------------------------------------
- # * Entrada em veículos
- # Necessário estar fora de um veículo para processar
- #--------------------------------------------------------------------------
- def get_on_vehicle
- front_x = $game_map.round_x_with_direction(@x, @direction)
- front_y = $game_map.round_y_with_direction(@y, @direction)
- $game_map.vehicles.each do |v|
- if v.pos?(front_x, front_y)
- @vehicle_type = v.type
- @vehicle = v
- end
- end
- if vehicle
- @vehicle_getting_on = true
- force_move_forward unless in_airship?
- @followers.gather
- end
- @vehicle_getting_on
- end
- #--------------------------------------------------------------------------
- # * Verificação da passabilidade
- #--------------------------------------------------------------------------
- def map_passable?(x, y, d)
- if !vehicle.nil?
- return vehicle_passable?(x, y, d)
- else
- super
- end
- end
- #--------------------------------------------------------------------------
- # * Verificação da passabilidade para o veículo
- #--------------------------------------------------------------------------
- def vehicle_passable?(x, y, d)
- $game_map.check_passage(x, y, vehicle.p_flag)
- end
- #--------------------------------------------------------------------------
- # * Atualização da saida do veículo
- #--------------------------------------------------------------------------
- def update_vehicle_get_off(*a, &b)
- mbscall(:update_vehicle_get_off, *a, &b)
- if !@followers.gathering? && vehicle.altitude == 0
- @vehicle = nil
- end
- end
- #--------------------------------------------------------------------------
- # * Aquisição do veículo em uso atualmente
- #--------------------------------------------------------------------------
- def vehicle
- @vehicle
- end
- end
- #==============================================================================
- # ** Game_Event
- #------------------------------------------------------------------------------
- # Aqui são feitas as alterações necessárias para se ter acesso às informações
- # requeridas sobre o evento
- #==============================================================================
- class Game_Event < Game_Character
- #--------------------------------------------------------------------------
- # * Definição dos atributos
- #--------------------------------------------------------------------------
- attr_reader :map_id
- #--------------------------------------------------------------------------
- # * Aquisição do nome do evento
- #--------------------------------------------------------------------------
- def name
- @event.name
- end
- end
- #==============================================================================
- # ** Game_Vehicle
- #------------------------------------------------------------------------------
- # Aqui são feitas as modificações para se criar veículos adicionais
- #==============================================================================
- class Game_Vehicle < Game_Character
- #--------------------------------------------------------------------------
- # * Alias
- #--------------------------------------------------------------------------
- mbsalias :initialize
- mbsalias :system_vehicle
- #--------------------------------------------------------------------------
- # * Definição dos atributos
- #--------------------------------------------------------------------------
- attr_accessor :p_flag, :show_player
- attr_reader :event, :type
- #--------------------------------------------------------------------------
- # * Carregamento das configuração do sistema
- #--------------------------------------------------------------------------
- def initialize(type, event, *a, &b)
- @event = event
- mbscall(:initialize, type, *a, &b)
- end
- #--------------------------------------------------------------------------
- # * Inicialização da velocidade de movimento
- #--------------------------------------------------------------------------
- def init_move_speed(*a, &b)
- @move_speed = MBS::VehiclesPlus.vehicle(@type).speed
- end
- #--------------------------------------------------------------------------
- # * Carregamento das configuração do sistema
- #--------------------------------------------------------------------------
- def load_system_settings(*a, &b)
- v = system_vehicle
- @map_id = v.start_map_id
- @real_x = @x = v.start_x
- @real_y = @y = v.start_y
- @character_name = v.character_name
- @character_index = v.character_index
- @p_flag = mbs_vehicle.p_flag
- @show_player = mbs_vehicle.show_player
- end
- #--------------------------------------------------------------------------
- # * Aquisição das configurações do veículo do script
- #--------------------------------------------------------------------------
- def mbs_vehicle
- MBS::VehiclesPlus.vehicle(@type)
- end
- #--------------------------------------------------------------------------
- # * Aquisição das configurações do sistema do veículo
- #--------------------------------------------------------------------------
- def system_vehicle(*a, &b)
- MBS::VehiclesPlus.system_vehicle(self) || mbscall(:system_vehicle, *a, &b)
- end
- #--------------------------------------------------------------------------
- # * Atualização da tela
- #--------------------------------------------------------------------------
- def update(*a, &b)
- super
- update_airship_altitude if mbs_vehicle.flying
- end
- #--------------------------------------------------------------------------
- # * Renovação
- #--------------------------------------------------------------------------
- def refresh(*a, &b)
- if mbs_vehicle.flying
- @priority_type = @driving ? 2 : 0
- else
- @priority_type = 1
- end
- end
- #--------------------------------------------------------------------------
- # * Definição de mobilidade
- #--------------------------------------------------------------------------
- def movable?
- !moving? && !(mbs_vehicle.flying && @altitude < max_altitude)
- end
- #--------------------------------------------------------------------------
- # * Definição de permissão de desembarque
- #--------------------------------------------------------------------------
- def land_ok?(x, y, d)
- if mbs_vehicle.flying
- return false unless $game_map.airship_land_ok?(x, y)
- return false unless $game_map.events_xy(x, y).empty?
- end
- x2 = $game_map.round_x_with_direction(x, d)
- y2 = $game_map.round_y_with_direction(y, d)
- return false unless $game_map.valid?(x2, y2)
- return false unless $game_map.passable?(x2, y2, reverse_dir(d))
- return false if collide_with_characters?(x2, y2)
- return true
- end
- #--------------------------------------------------------------------------
- # * Definição da posição do veículo
- #--------------------------------------------------------------------------
- def moveto(*a, &b)
- set_location(@map_id, *a, &b)
- @real_x = x
- @real_y = y
- end
- end
- #==============================================================================
- # ** Game_Map
- #------------------------------------------------------------------------------
- # Aqui são feitas as modificações para transformar os eventos com nome de
- # veículos em veículos
- #==============================================================================
- class Game_Map
- #--------------------------------------------------------------------------
- # * Alias
- #--------------------------------------------------------------------------
- mbsalias :setup
- mbsalias :events
- mbsalias :referesh_vehicles
- #--------------------------------------------------------------------------
- # * Verificação de se um evento é um veículo
- #--------------------------------------------------------------------------
- def __vehicle?(event)
- return false unless event.name =~ MBS::VehiclesPlus::REGEX
- return MBS::VehiclesPlus.has_vehicle?($1.to_sym)
- end
- private :__vehicle?
- #--------------------------------------------------------------------------
- # * Aquisição dos eventos de veículos
- #--------------------------------------------------------------------------
- def vehicle_events
- r = {}
- @events.each do |id, event|
- if __vehicle?(event)
- r[id] = event
- @events.delete(id)
- end
- end
- r
- end
- #--------------------------------------------------------------------------
- # * Aquisição do hash dos veículos
- #--------------------------------------------------------------------------
- def vehicles_hash
- vehicles.compact.inject({}) do |hash, vehicle|
- hash[vehicle.event.id] = vehicle if vehicle.event
- hash
- end
- end
- #--------------------------------------------------------------------------
- # * Aquisição de todos os eventos
- #--------------------------------------------------------------------------
- def all_events
- events.merge vehicles_hash
- end
- #--------------------------------------------------------------------------
- # * Configuração do mapa
- #--------------------------------------------------------------------------
- def setup(*a, &b)
- mbscall(:setup, *a, &b)
- referesh_vehicles
- end
- #--------------------------------------------------------------------------
- # * Criação dos veículos
- #--------------------------------------------------------------------------
- def create_vehicles
- @vehicles = []
- @vehicles[0] = Game_Vehicle.new(:boat, nil)
- @vehicles[1] = Game_Vehicle.new(:ship, nil)
- @vehicles[2] = Game_Vehicle.new(:airship, nil)
- end
- #--------------------------------------------------------------------------
- # * Atualização dos veículos
- #--------------------------------------------------------------------------
- def referesh_vehicles(*a, &b)
- @vehicles.clear
- @vehicles[0] = Game_Vehicle.new(:boat, nil)
- @vehicles[1] = Game_Vehicle.new(:ship, nil)
- @vehicles[2] = Game_Vehicle.new(:airship, nil)
- count = {}
- vehicle_events.each do |id, e|
- e.name =~ MBS::VehiclesPlus::REGEX
- type = $1.to_sym
- if type == :custom
- type = MBS::VehiclesPlus.register_custom(e)
- end
- v = Game_Vehicle.new(type, e)
- mbs = MBS::VehiclesPlus.vehicle(type)
- if ((count[type] ||= 0) < mbs.max || mbs.max == 0)
- @vehicles << v
- count[type] += 1
- end
- end
- mbscall(:referesh_vehicles, *a, &b)
- end
- #--------------------------------------------------------------------------
- # * Aquisição do veículo
- #--------------------------------------------------------------------------
- def vehicle(type)
- return @vehicles.find {|v| v.type == type}
- end
- end
- #==============================================================================
- # ** Game_Interpreter
- #------------------------------------------------------------------------------
- # Aqui são feitas as modificações para que os comandos de evento que envolvem
- # eventos funcionem com os eventos-veículos
- #==============================================================================
- class Game_Interpreter
- #--------------------------------------------------------------------------
- # * Aquisição do personagem
- #--------------------------------------------------------------------------
- def get_character(param)
- if $game_party.in_battle
- nil
- elsif param < 0
- $game_player
- else
- events = same_map? ? $game_map.all_events : {}
- events[param > 0 ? param : @event_id]
- end
- end
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement