SHARE
TWEET

Untitled

marlosgama Mar 17th, 2020 312 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #==============================================================================
  2. # ** Sprite_Character
  3. #------------------------------------------------------------------------------
  4. #  Esta classe lida com a exibição do personagem.
  5. #------------------------------------------------------------------------------
  6. #  Autor: Valentine
  7. #==============================================================================
  8.  
  9. class Sprite_Character < Sprite_Base
  10.  
  11.   def init_sprites
  12.     @damage_duration = 0
  13.     @message_duration = 0
  14.     @paperdoll_sprites = []
  15.     @old_equips = []
  16.     @name_sprite = nil
  17.     @guild_sprite = nil
  18.     @quest_sprite = nil
  19.     @hp_sprite = nil
  20.     @damage_sprite = nil
  21.     @message_sprite = nil
  22.     @old_guild = nil
  23.     @old_hp = nil
  24.     @old_mhp = nil
  25.   end
  26.  
  27.   def dispose_sprites
  28.     dispose_paperdolls
  29.     dispose_name
  30.     dispose_guild_name
  31.     dispose_quest_icon
  32.     dispose_hp_bar
  33.     dispose_damage
  34.     dispose_message
  35.   end
  36.  
  37.   def dispose_paperdolls
  38.     9.times { |slot_id| dispose_paperdoll(slot_id) }
  39.   end
  40.  
  41.   def dispose_paperdoll(slot_id)
  42.     return unless @paperdoll_sprites[slot_id]
  43.     @paperdoll_sprites[slot_id].bitmap.dispose
  44.     @paperdoll_sprites[slot_id].dispose
  45.     @paperdoll_sprites[slot_id] = nil
  46.     @old_equips[slot_id] = nil
  47.   end
  48.  
  49.   def dispose_name
  50.     return unless @name_sprite
  51.     @name_sprite.bitmap.dispose
  52.     @name_sprite.dispose
  53.     @name_sprite = nil
  54.   end
  55.  
  56.   def dispose_guild_name
  57.     return unless @guild_sprite
  58.     @guild_sprite.bitmap.dispose
  59.     @guild_sprite.dispose
  60.     @guild_sprite = nil
  61.   end
  62.  
  63.   def dispose_quest_icon
  64.     return unless @quest_sprite
  65.     @quest_sprite.bitmap.dispose
  66.     @quest_sprite.dispose
  67.     @quest_sprite = nil
  68.   end
  69.  
  70.   def dispose_hp_bar
  71.     return unless @hp_sprite
  72.     @hp_sprite.bitmap.dispose
  73.     @hp_sprite.dispose
  74.     @hp_sprite = nil
  75.   end
  76.  
  77.   def dispose_damage
  78.     return unless @damage_sprite
  79.     @damage_sprite.bitmap.dispose
  80.     @damage_sprite.dispose
  81.     @damage_sprite = nil
  82.   end
  83.  
  84.   def dispose_message
  85.     return unless @message_sprite
  86.     @message_sprite.bitmap.dispose
  87.     @message_sprite.dispose
  88.     @message_sprite = nil
  89.   end
  90.  
  91.   def visible=(visible)
  92.     super
  93.     end_sprites if visible == false
  94.     @quest_sprite.visible = visible if @quest_sprite
  95.     if @name_sprite && @name_sprite.visible != visible
  96.       @name_sprite.visible = visible
  97.       @guild_sprite.visible = visible if @guild_sprite
  98.       @hp_sprite.visible = visible if @hp_sprite
  99.       9.times { |slot_id| @paperdoll_sprites[slot_id].visible = visible if @paperdoll_sprites[slot_id] } unless @paperdoll_sprites.empty?
  100.     end
  101.   end
  102.  
  103.   def end_sprites
  104.     end_animation
  105.     end_balloon
  106.     dispose_damage
  107.     dispose_message
  108.     @balloon_duration = 0
  109.     @damage_duration = 0
  110.     @message_duration = 0
  111.   end
  112.  
  113.   def update_position
  114.     move_animation(@character.screen_x - x, @character.screen_y - y)
  115.     self.x = @character.screen_x
  116.     self.y = @character.screen_y
  117.     self.z = @character.screen_z
  118.   end
  119.  
  120.   def move_animation(dx, dy)
  121.     return unless @animation && @animation.position != 3
  122.     @ani_ox += dx
  123.     @ani_oy += dy
  124.     @ani_sprites.each do |sprite|
  125.       sprite.x += dx
  126.       sprite.y += dy
  127.     end
  128.   end
  129.  
  130.   def update_sprites
  131.     return if @character.is_a?(Game_Vehicle) || @character.is_a?(Game_Follower)
  132.     update_paperdolls unless @character.is_a?(Game_Event)
  133.     if @character.actor? && @character.actor.result.hp_damage
  134.       refresh_damage(@character.actor.result.hp_damage, @character.actor.result.mp_damage, @character.actor.result.critical)
  135.       @character.actor.result.hp_damage = nil
  136.       @character.actor.result.mp_damage = 0
  137.       @character.actor.result.critical = false
  138.     end
  139.     # Se é um inimigo, jogador ou evento não apagado (erased)
  140.     if @character.actor? || @character.event.name.start_with?('$') && !@character.character_name.empty?
  141.       refresh_name if name_changed?
  142.       @name_sprite.x = x
  143.       # Atualiza de acordo com a altura do character
  144.       #que pode ter sido alterada
  145.       @name_sprite.y = y - height
  146.     else
  147.       dispose_name
  148.     end
  149.     if !@character.is_a?(Game_Event) && !@character.actor.guild.empty?
  150.       refresh_guild_name if guild_changed?
  151.       @guild_sprite.x = x
  152.       @guild_sprite.y = y - height
  153.     else
  154.       dispose_guild_name
  155.     end
  156.     if @character.is_a?(Game_Event) && @character.quest_not_started?
  157.       create_quest_icon unless @quest_sprite
  158.       @quest_sprite.x = x
  159.       @quest_sprite.y = y - height
  160.     else
  161.       dispose_quest_icon
  162.     end
  163.     if @character.boss?
  164.       refresh_boss_hp_bar if hp_changed?
  165.       # Possibilita que a barra possa ser arrastada
  166.       @hp_sprite.update
  167.     elsif @character.actor? && @character.actor.hp < @character.actor.mhp
  168.       refresh_hp_bar if hp_changed?
  169.       @hp_sprite.x = x
  170.       @hp_sprite.y = y
  171.     else
  172.       dispose_hp_bar
  173.     end
  174.     unless @character.message.empty?
  175.       create_message(@character.message)
  176.       @character.message.clear
  177.     end
  178.     if @damage_duration > 0
  179.       @damage_sprite.x = x
  180.       @damage_sprite.y = y - height + @damage_duration
  181.       @damage_duration -= 1
  182.     else
  183.       dispose_damage
  184.     end
  185.     if @message_duration > 0
  186.       @message_sprite.x = x
  187.       @message_sprite.y = y
  188.       @message_duration -= 1
  189.     else
  190.       dispose_message
  191.     end
  192.   end
  193.  
  194.   def name_changed?
  195.     return true unless @name_sprite
  196.     return true if @character.actor? && @old_name != @character.actor.name
  197.     return true unless @character.actor? || @old_name == @character.event.name
  198.     return false
  199.   end
  200.  
  201.   def guild_changed?
  202.     return true unless @guild_sprite
  203.     return true unless @old_guild == @character.actor.guild
  204.     return false
  205.   end
  206.  
  207.   def hp_changed?
  208.     return true unless @hp_sprite
  209.     return true unless @old_hp == @character.actor.hp
  210.     return true unless @old_mhp == @character.actor.mhp
  211.     return false
  212.   end
  213.  
  214.   def refresh_damage(hp_damage, mp_damage, critical)
  215.     @damage_sprite ? @damage_sprite.bitmap.clear : create_damage
  216.     damage_text = hp_damage
  217.     color = Font.default_color
  218.     if hp_damage.is_a?(String)
  219.       color = Color::Yellow
  220.     elsif critical
  221.       damage_text = Vocab::Critical
  222.     elsif hp_damage == 0 && mp_damage == 0
  223.       damage_text = Vocab::NoHit
  224.     elsif hp_damage == 0 && mp_damage > 0
  225.       damage_text = "+#{mp_damage}"
  226.       color = Color::Blue
  227.     elsif hp_damage > 0
  228.       damage_text = "+#{hp_damage}"
  229.       color = Color::Green
  230.     else
  231.       color = Color::Red
  232.     end
  233.     @damage_sprite.bitmap.font.color.set(color)
  234.     @damage_sprite.bitmap.draw_text(@damage_sprite.bitmap.rect, damage_text, 1)
  235.     @damage_duration = 30
  236.   end
  237.  
  238.   def create_damage
  239.     @damage_sprite = Sprite.new(viewport)
  240.     @damage_sprite.bitmap = Bitmap.new(160, 20)
  241.     @damage_sprite.bitmap.font.size = 18
  242.     @damage_sprite.bitmap.font.bold = true
  243.     @damage_sprite.ox = 80
  244.     @damage_sprite.oy = 35
  245.     # Deixa o dano em cima de todas as camadas do
  246.     #tileset e do nome do jogador
  247.     @damage_sprite.z = z + 150
  248.   end
  249.  
  250.   def order_equips
  251.     # 0 = Arma
  252.     # 1 = Escudo
  253.     # 2 = Capacete
  254.     # 3 = Armadura
  255.     # 4 = Acessório
  256.     # 5 = Amuleto
  257.     # 6 = Capa
  258.     # 7 = Luva
  259.     # 8 = Bota
  260.     case @character.direction
  261.     when 2 # Frente
  262.       return [3, 5, 2, 7, 6, 8, 1, 0, 4]
  263.     when 4 # Esquerda
  264.       return [7, 0, 3, 5, 2, 6, 8, 1, 4]
  265.     when 6 # Direita
  266.       return [1, 3, 5, 2, 7, 6, 8, 0, 4]
  267.     when 8 # Costas
  268.       return [7, 1, 0, 3, 5, 2, 8, 6, 4]
  269.     end
  270.   end
  271.  
  272.   def update_paperdolls
  273.     order_equips.each_with_index do |slot_id, index|
  274.       if @character.actor.equips[slot_id] && @character.actor.equips[slot_id].paperdoll_name
  275.         refresh_paperdoll(slot_id) unless @old_equips[slot_id] == @character.actor.equips[slot_id]
  276.         pattern = @character.pattern < 3 ? @character.pattern : 1
  277.         sx = (@character.actor.equips[slot_id].paperdoll_index % 4 * 3 + pattern) * @cw
  278.         sy = (@character.actor.equips[slot_id].paperdoll_index / 4 * 4 + (@character.direction - 2) / 2) * @ch
  279.         @paperdoll_sprites[slot_id].src_rect.set(sx, sy, @cw, @ch)
  280.         @paperdoll_sprites[slot_id].x = x
  281.         @paperdoll_sprites[slot_id].y = y
  282.         @paperdoll_sprites[slot_id].z = z + index
  283.       else
  284.         dispose_paperdoll(slot_id)
  285.       end
  286.     end
  287.   end
  288.  
  289.   def refresh_paperdoll(slot_id)
  290.     @old_equips[slot_id] = @character.actor.equips[slot_id]
  291.     bitmap = Cache.paperdoll(@character.actor.equips[slot_id].paperdoll_name)
  292.     @paperdoll_sprites[slot_id] ? @paperdoll_sprites[slot_id].bitmap.clear : create_paperdoll(slot_id, bitmap)
  293.     @paperdoll_sprites[slot_id].bitmap.blt(0, 0, bitmap, bitmap.rect)
  294.     sign = @character.actor.equips[slot_id].paperdoll_name[/^[\!\$]./]
  295.     if sign && sign.include?('$')
  296.       cw = bitmap.width / 3
  297.       ch = bitmap.height / 4
  298.     else
  299.       cw = bitmap.width / 12
  300.       ch = bitmap.height / 8
  301.     end
  302.     @paperdoll_sprites[slot_id].ox = cw / 2
  303.     @paperdoll_sprites[slot_id].oy = ch
  304.   end
  305.  
  306.   def create_paperdoll(slot_id, bitmap)
  307.     @paperdoll_sprites[slot_id] = Sprite.new(viewport)
  308.     @paperdoll_sprites[slot_id].bitmap = Bitmap.new(bitmap.width, bitmap.height)
  309.   end
  310.  
  311.   def refresh_name
  312.     @old_name = @character.actor? ? @character.actor.name : @character.event.name
  313.     @name_sprite ? @name_sprite.bitmap.clear : create_name
  314.     @name_sprite.bitmap.font.color.set(@name_sprite.text_color(name_color))
  315.     @name_sprite.bitmap.draw_text(@name_sprite.bitmap.rect, @old_name.delete('$'), 1)
  316.   end
  317.  
  318.   def create_name
  319.     @name_sprite = Sprite2.new(viewport)
  320.     @name_sprite.bitmap = Bitmap.new(@name_sprite.text_width(@old_name.delete('$')) + 10, 18)
  321.     @name_sprite.ox = @name_sprite.bitmap.width / 2
  322.     @name_sprite.oy = 19
  323.     @name_sprite.z = z + 100
  324.   end
  325.  
  326.   def name_color
  327.     return Configs::ADMIN_COLOR if @character.admin?
  328.     return Configs::MONITOR_COLOR if @character.monitor?
  329.     return Configs::BOSS_COLOR if @character.boss?
  330.     return Configs::ENEMY_COLOR if @character.is_a?(Game_Event) && @character.actor
  331.     return Configs::DEFAULT_COLOR
  332.   end
  333.  
  334.   def refresh_guild_name
  335.     @old_guild = @character.actor.guild
  336.     @guild_sprite ? @guild_sprite.bitmap.clear : create_guild_name
  337.     @guild_sprite.bitmap.draw_text(@guild_sprite.bitmap.rect, "<#{@old_guild}>", 1)
  338.   end
  339.  
  340.   def create_guild_name
  341.     @guild_sprite = Sprite2.new(viewport)
  342.     @guild_sprite.bitmap = Bitmap.new(160, 18)
  343.     @guild_sprite.bitmap.font.color.set(@guild_sprite.text_color(Configs::GUILD_COLOR))
  344.     @guild_sprite.ox = 80
  345.     @guild_sprite.oy = 37
  346.     @guild_sprite.z = z + 100
  347.   end
  348.  
  349.   def create_quest_icon
  350.     @quest_sprite = Sprite.new(viewport)
  351.     @quest_sprite.bitmap = Bitmap.new(24, 24)
  352.     bitmap = Cache.system('Iconset')
  353.     rect = Rect.new(Configs::QUEST_NOT_STARTED_ICON % 16 * 24, Configs::QUEST_NOT_STARTED_ICON / 16 * 24, 24, 24)
  354.     @quest_sprite.bitmap.blt(0, 0, bitmap, rect)
  355.     @quest_sprite.ox = 12
  356.     @quest_sprite.oy = 40
  357.     @quest_sprite.z = z + 100
  358.   end
  359.  
  360.   def refresh_hp_bar
  361.     @old_hp = @character.actor.hp
  362.     @old_mhp = @character.actor.mhp
  363.     @hp_sprite ? @hp_sprite.bitmap.clear : create_hp_bar
  364.     bitmap = Cache.system('HPBar')
  365.     y = @character.actor.mhp / 3 > @character.actor.hp ? 12 : @character.actor.mhp / 1.5 > @character.actor.hp ? 8 : 4
  366.     @hp_sprite.bitmap.blt(0, 0, bitmap, @hp_sprite.bitmap.rect)
  367.     @hp_sprite.bitmap.blt(0, 0, bitmap, Rect.new(0, y, @hp_sprite.bitmap.width * @character.actor.hp / @character.actor.mhp, @hp_sprite.bitmap.height))
  368.   end
  369.  
  370.   def refresh_boss_hp_bar
  371.     @old_hp = @character.actor.hp
  372.     @old_mhp = @character.actor.mhp
  373.     @hp_sprite ? @hp_sprite.bitmap.clear : create_boss_hp_bar
  374.     bitmap = Cache.system('BossHPBar')
  375.     y = @character.actor.mhp / 3 > @character.actor.hp ? 72 : @character.actor.mhp / 1.5 > @character.actor.hp ? 48 : 24
  376.     @hp_sprite.bitmap.blt(0, 18, bitmap, @hp_sprite.bitmap.rect)
  377.     @hp_sprite.bitmap.blt(0, 18, bitmap, Rect.new(0, y, @hp_sprite.bitmap.width * @character.actor.hp / @character.actor.mhp, @hp_sprite.bitmap.height))
  378.     @hp_sprite.bitmap.font.size = 16
  379.     @hp_sprite.bitmap.font.bold = false
  380.     @hp_sprite.bitmap.font.color.set(@hp_sprite.text_color(Configs::BOSS_COLOR))
  381.     @hp_sprite.bitmap.draw_text(0, 0, 200, 18, @character.actor.name)
  382.     @hp_sprite.bitmap.font.size = 18
  383.     @hp_sprite.bitmap.font.bold = true
  384.     @hp_sprite.bitmap.font.color.set(Color::White)
  385.     @hp_sprite.bitmap.draw_text(4, 20, 25, 20, Vocab::hp_a)
  386.     @hp_sprite.bitmap.draw_text(0, 20, 349, 20, "#{@character.actor.hp}/#{@character.actor.mhp}", 2)
  387.   end
  388.  
  389.   def create_hp_bar
  390.     @hp_sprite = Sprite.new(viewport)
  391.     @hp_sprite.bitmap = Bitmap.new(30, 4)
  392.     @hp_sprite.ox = 15
  393.     @hp_sprite.oy = -4
  394.     @hp_sprite.z = z + 100
  395.   end
  396.  
  397.   def create_boss_hp_bar
  398.     @hp_sprite = Sprite2.new
  399.     @hp_sprite.bitmap = Bitmap.new(351, 42)
  400.     @hp_sprite.x = 336
  401.     @hp_sprite.y = 118
  402.     @hp_sprite.z = 50
  403.     @hp_sprite.dragable = true
  404.   end
  405.  
  406.   def create_message(message)
  407.     dispose_message
  408.     b = Bitmap.new(1, 1)
  409.     # Define a largura a partir da matriz com maior
  410.     #quantidade de caracteres
  411.     width = b.text_size(message.max{ |a, b| a.size <=> b.size }).width
  412.     b.dispose
  413.     @message_sprite = Sprite.new(viewport)
  414.     @message_sprite.bitmap = Bitmap.new(width + 18, message.size * 18)
  415.     @message_sprite.bitmap.fill_rect(@message_sprite.bitmap.rect, Color.new(0, 0, 0, 160))
  416.     @message_sprite.bitmap.font.bold = true
  417.     message.each_with_index do |text, i|
  418.       @message_sprite.bitmap.draw_text(0, 18 * i, @message_sprite.bitmap.width, 18, text, 1)
  419.     end
  420.     @message_sprite.ox = @message_sprite.width / 2
  421.     @message_sprite.oy = message.size * 18 + height + 10
  422.     @message_sprite.z = z + 100
  423.     @message_duration = 150
  424.   end
  425.  
  426. end
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
Top