Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #==============================================================================
- # ** Game_Player
- #------------------------------------------------------------------------------
- # Esta classe lida com o jogador. Ela contém dados, como
- # direção, coordenadas x e y.
- #------------------------------------------------------------------------------
- # Autor: Valentine
- #==============================================================================
- class Game_Player < Game_Character
- attr_reader :target
- attr_reader :blocked
- attr_accessor :path
- attr_accessor :item_attack_time
- def init_basic
- @target = nil
- @path = nil
- @lost_path = nil
- @got_drop = false
- @weapon_attack_time = 0
- @item_attack_time = 0
- @try_path = 0
- @blocked = []
- end
- def clear
- @path = nil
- clear_target
- end
- def clear_target
- return unless @target
- $network.send_target(-1, Constants::TARGET_NONE)
- end
- def target=(target)
- @target = target
- #@path = @target if @target && $game_actors[1].weapons[0] && !range_weapon?
- end
- def range_weapon?
- Configs::RANGE_WEAPONS.has_key?($game_actors[1].weapons[0].id)
- end
- def collide_with_characters?(x, y)
- super || collide_with_players?(x, y) && $game_map.pvp
- end
- def quest_in_progress?(quest_id)
- # Reduz o índice que foi configurado com um inteiro
- #a mais nos comandos de evento
- actor.quests.has_key?(quest_id - 1) && actor.quests[quest_id - 1].in_progress?
- end
- def quest_finished?(quest_id)
- actor.quests.has_key?(quest_id - 1) && actor.quests[quest_id - 1].finished?
- end
- def protection_level?(target)
- actor.level < Configs::MIN_LEVEL_PVP || target.actor.level < Configs::MIN_LEVEL_PVP
- end
- def vip?
- $network.vip?
- end
- def in_range?(target, range)
- distance_x_from(target.x).abs <= range && distance_y_from(target.y).abs <= range
- end
- def usable?(item)
- mp_enough?(item) && actor.usable?(item) && (item.for_friend? || valid_target?(item.range))
- end
- def mp_enough?(item)
- if item.is_a?(RPG::Skill) && item.mp_cost > actor.mp
- $windows[:chat].write_message(Vocab::InsufficientMP, Configs::ERROR_COLOR)
- return false
- end
- return true
- end
- def can_attack?
- @weapon_attack_time = Configs::ATTACK_TIME
- return can_attack_range? if $game_actors[1].weapons[0] && range_weapon?
- return can_attack_normal?
- end
- =begin
- def can_attack_normal?
- if !in_range?(@target, 1)
- return false
- elsif @target.admin?
- $windows[:chat].write_message(Vocab::AttackAdmin, Configs::ERROR_COLOR)
- return false
- elsif @target.is_a?(Game_NetPlayer) && !$game_map.pvp
- $windows[:chat].write_message(Vocab::NonPvP, Configs::ERROR_COLOR)
- return false
- elsif @target.is_a?(Game_NetPlayer) && protection_level?(@target)
- $windows[:chat].write_message(Vocab::ProtectionLevel, Configs::ERROR_COLOR)
- return false
- end
- return true
- end
- =end
- def can_attack_normal?
- x = $game_map.round_x_with_direction(@x, @direction)
- y = $game_map.round_y_with_direction(@y, @direction)
- player = collide_with_players?(x, y)
- # Se o evento está em frente ou abaixo do jogador
- if collide_with_events?(x, y) || event_trigger_here?([0])
- return true
- elsif !player
- return false
- elsif player.admin?
- $windows[:chat].write_message(Vocab::AttackAdmin, Configs::ERROR_COLOR)
- return false
- elsif !$game_map.pvp
- $windows[:chat].write_message(Vocab::NonPvP, Configs::ERROR_COLOR)
- return false
- elsif protection_level?(player)
- $windows[:chat].write_message(Vocab::ProtectionLevel, Configs::ERROR_COLOR)
- return false
- end
- return true
- end
- def event_trigger_here?(triggers)
- $game_map.events_xy(@x, @y).any? { |event| event.trigger_in?(triggers) && !event.normal_priority? }
- end
- def can_attack_range?
- range, item_id, mp_cost = Configs::RANGE_WEAPONS[$game_actors[1].weapons[0].id].drop(1)
- x = $game_map.round_x_with_direction(@x, @direction)
- y = $game_map.round_y_with_direction(@y, @direction)
- if collide_with_events?(x, y)
- return true
- elsif item_id > 0 && !$game_party.has_item?($data_items[item_id])
- $windows[:chat].write_message(Vocab::NotAmmunition, Configs::ERROR_COLOR)
- return false
- elsif mp_cost && $game_actors[1].mp < mp_cost
- $windows[:chat].write_message(Vocab::InsufficientMP, Configs::ERROR_COLOR)
- return false
- elsif !valid_target?(range)
- return false
- end
- return true
- end
- def valid_target?(range)
- if !@target
- $windows[:chat].write_message(Vocab::NotTarget, Configs::ERROR_COLOR)
- return false
- elsif !in_range?(@target, range)
- $windows[:chat].write_message(Vocab::TargetNotInRange, Configs::ERROR_COLOR)
- return false
- elsif blocked_passage?
- $windows[:chat].write_message(Vocab::NotSeeTarget, Configs::ERROR_COLOR)
- return false
- elsif @target.admin?
- $windows[:chat].write_message(Vocab::AttackAdmin, Configs::ERROR_COLOR)
- return false
- elsif @target.is_a?(Game_NetPlayer) && !$game_map.pvp
- $windows[:chat].write_message(Vocab::NonPvP, Configs::ERROR_COLOR)
- return false
- elsif @target.is_a?(Game_NetPlayer) && protection_level?(@target)
- $windows[:chat].write_message(Vocab::ProtectionLevel, Configs::ERROR_COLOR)
- return false
- end
- return true
- end
- def blocked_passage?
- # Retorna falso se o jogador e o alvo estiverem nas
- #mesmas coordenadas x e y, pois, nesta versão do Ruby,
- #o atan2 retorna um erro
- return false if pos?(@target.x, @target.y)
- radians = Math.atan2(@target.x - @x, @target.y - @y)
- speed_x = Math.sin(radians)
- speed_y = Math.cos(radians)
- range_x = (@target.x - @x).abs
- range_y = (@target.y - @y).abs
- range_x -= 1 if range_x > 0
- range_y -= 1 if range_y > 0
- result = false
- x = @x
- y = @y
- while true
- # Soma valores decimais
- x += speed_x
- y += speed_y
- x2 = x.to_i
- y2 = y.to_i
- if !$game_map.valid?(x2, y2) || !map_passable?(x2, y2, @direction)
- result = true
- break
- elsif distance_x_from(x2).abs > range_x || distance_y_from(y2).abs > range_y
- break
- end
- end
- result
- end
- def real_move_speed
- @move_speed
- end
- def move_by_input
- return if !movable? || $game_map.interpreter.running?
- send_movement(Input.dir4) if Input.dir4 > 0 && !$typing
- end
- def send_movement(d)
- return if !passable?(@x, @y, d) && @direction == d
- $network.send_player_movement(d)
- move_straight(d)
- end
- def turn_toward_target
- sx = distance_x_from(@@target.x)
- sy = distance_y_from(@@target.y)
- if sx.abs > sy.abs
- d = sx > 0 ? 4 : 6
- set_direction(d)
- $network.send_player_movement(d)
- elsif sy != 0
- d = sy > 0 ? 8 : 2
- set_direction(d)
- $network.send_player_movement(d)
- end
- end
- def update_attack
- if @weapon_attack_time > 0
- @weapon_attack_time -= 1
- return
- end
- # Só começa a contar o tempo do ataque se
- #não tiver ocupado com mensagem
- #$network.send_player_attack if !$game_message.busy? && !$typing && (@@target && in_range?(@@target, 1) || @target && can_attack?)#$game_map.interpreter.running?
- $network.send_player_attack if Input.press?(Configs::ATTACK_KEY) && !$game_message.busy? && can_attack? && !$typing
- end
- def update_nonmoving(last_moving)
- return if $game_map.interpreter.running?
- if last_moving
- $game_party.on_player_walk
- return if check_touch_event
- end
- # Se a tecla é uma letra e a caixa de texto estiver ativa
- if movable? && Input.trigger?(Configs::ATTACK_KEY) && @weapon_attack_time == 0 && !$typing
- #if movable? && @@target && in_range?(@@target, 1) && !$typing
- return if get_on_off_vehicle
- return if check_action_event
- end
- #update_path if @path
- update_encounter if last_moving
- end
- def update_trigger
- clear if Input.trigger?(:B)
- remove_drop if Input.repeat?(Configs::GET_DROP_KEY)#Mouse.click?(:L)
- select_nearest_enemy if Input.trigger?(Configs::SELECT_ENEMY_KEY)
- #find_path if Mouse.click?(:L)
- end
- def remove_drop
- return if $typing
- #@got_drop = false
- $game_map.drops.each_with_index do |drop, i|
- #next unless Mouse.in_tile?(drop)
- #next unless in_range?(drop, 1)
- next unless pos?(drop.x, drop.y)
- $network.send_remove_drop(i)
- #@got_drop = true
- break
- end
- end
- def update_hotbar
- if @item_attack_time > 0
- @item_attack_time -= 1
- return
- end
- use_hotbar
- end
- def use_hotbar
- return if $typing
- actor.hotbar.each_with_index do |item, i|
- next unless Input.press?(Configs::HOTKEYS[i])
- @item_attack_time = Configs::COOLDOWN_SKILL_TIME
- $network.send_use_hotbar(i) if item && usable?(item)
- break
- end
- end
- def select_nearest_enemy
- # Se a tecla é uma letra e a caixa de texto estiver ativa
- return if $typing
- event_id = 0
- sx = 10
- sy = 10
- $game_map.events.each_value do |event|
- # Se é um inimigo que não morreu e está no alcance
- next unless event.actor? && in_range?(event, 10)
- real_distance_x = distance_x_from(event.x).abs
- real_distance_y = distance_y_from(event.y).abs
- if real_distance_x + real_distance_y < sx + sy
- event_id = event.id
- sx = real_distance_x
- sy = real_distance_y
- end
- end
- $network.send_target(event_id, Constants::TARGET_ENEMY) if event_id > 0
- end
- def find_path
- return unless map_passable?(Mouse.tile_x, Mouse.tile_y, @direction)
- return if $game_map.interpreter.running?
- return if over_window?
- return if @got_drop
- return if @@target
- @path = Path.new(Mouse.tile_x, Mouse.tile_y)
- end
- def over_window?
- $windows.each_value do |window|
- if window.is_a?(Window_Chat) && window.opacity > 0 && window.in_area?(0, 0, window.width, window.height + 22)
- return true
- elsif window.is_a?(Window) && window.visible && window.in_area?
- return true
- elsif window.is_a?(Sprite2) && window.in_area?
- return true
- end
- end
- SceneManager.scene.icons.each { |icon| return true if icon.in_area? }
- return false
- end
- =begin
- def update_path
- #if @lost_path
- #update_lost_path
- #else
- update_normal_path
- #end
- end
- def update_normal_path
- sx = distance_x_from(@path.x)
- sy = distance_y_from(@path.y)
- if sx.abs > sy.abs
- d = sx > 0 ? 4 : 6
- send_path_movement(d)
- send_path_movement(sy > 0 ? 8 : 2) if !passable?(@x, @y, d) && sy != 0
- elsif sy != 0
- d = sy > 0 ? 8 : 2
- send_path_movement(d)
- send_path_movement(sx > 0 ? 4 : 6) if !passable?(@x, @y, d) && sx != 0
- end
- #@try_path += pos?(@real_x, @real_y) ? 1 : 0
- @lost_path = pos?(@real_x, @real_y)
- # Se o @path não foi limpado
- @path = nil if @path && pos?(@path.x, @path.y) && !@target
- #@path = nil if (@path && pos?(@path.x, @path.y) || @try_path == 4) && !@target
- end
- def update_lost_path
- if @direction == 4 || @direction == 6
- if passable?(@x, @y, 2)
- send_movement(2)
- @lost_path = false
- elsif passable?(@x, @y, 8)
- send_movement(8)
- @lost_path = false
- else
- send_movement(reverse_dir(@direction))
- end
- elsif @direction == 2 || @direction == 8
- if passable?(@x, @y, 4)
- send_movement(4)
- @lost_path = false
- elsif passable?(@x, @y, 6)
- send_movement(6)
- @lost_path = false
- else
- send_movement(reverse_dir(@direction))
- end
- end
- @try_path += pos?(@real_x, @real_y) ? 1 : 0
- if @try_path == 4
- @path = nil
- @lost_path = false
- end
- end
- =end
- def send_path_movement(d)
- if passable?(@x, @y, d) && !@path.is_a?(Path) && @path.pos?($game_map.round_x_with_direction(@x, @direction), $game_map.round_y_with_direction(@y, @direction))
- @path = nil
- return
- end
- send_movement(d)
- end
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement