#==============================================================================
# +++ MOG - Enemy HP Meter (v1.1) +++
#==============================================================================
# By Moghunter
# [url]http://www.atelier-rgss.com/[/url]
#==============================================================================
# Apresenta um medidor animado com o HP do inimigo.
#==============================================================================
# Para ocultar o HP do inimigo use a TAG abaixo na caixa de notas.
#
# <Hide HP>
#
#==============================================================================
# Serão necessários as imagens.
#
# Battle_Enemy_HP_Layout.png
# Battle_Enemy_HP_Meter.png
#
#
#==============================================================================
#==============================================================================
# ● Histórico (Version History)
#==============================================================================
# v 1.1 - Corrigido o erro de crash randômico. (relativo a dispose de imagem.)
#==============================================================================
module MOG_ENEMY_HP
#Posição geral do medidor em relação ao battler.
POSITION_CORRECTION = [0,0]
#Posição do medidor de HP.
HP_METER_POSITION = [2,4]
#Prioridade do medidor na tela.
PRIORITY_Z = 101
end
#==============================================================================
# ■ Game Enemy
#==============================================================================
class Game_Enemy < Game_Battler
attr_accessor :hp_meter_active
#--------------------------------------------------------------------------
# ● Initialize
#--------------------------------------------------------------------------
alias mog_enemy_hp_initialize initialize
def initialize(index, enemy_id)
mog_enemy_hp_initialize(index, enemy_id)
hide = enemy.note =~ /<Hide HP>/i ? true : false
@hp_meter_active = [false,hide]
end
end
#==============================================================================
# ■ Game_Battler
#==============================================================================
class Game_Battler < Game_BattlerBase
#--------------------------------------------------------------------------
# ● Item Apply
#--------------------------------------------------------------------------
alias mog_enemy_hp_item_apply item_apply
def item_apply(user, item)
mog_enemy_hp_item_apply(user, item)
if self.is_a?(Game_Enemy)
self.hp_meter_active[0] = true if @result.hp_damage != 0
end
end
#--------------------------------------------------------------------------
# ● Regenerate HP
#--------------------------------------------------------------------------
alias mog_enemy_hp_regenerate_hp regenerate_hp
def regenerate_hp
mog_enemy_hp_regenerate_hp
if self.is_a?(Game_Enemy)
self.hp_meter_active[0] = true if @result.hp_damage != 0
end
end
end
#==============================================================================
# ■ Battle_Hud
#==============================================================================
class Enemy_HP
include MOG_ENEMY_HP
#--------------------------------------------------------------------------
# ● Initialize
#--------------------------------------------------------------------------
def initialize(viewport = nil,enemy)
dispose
@enemy = enemy
@fade_time = -1
create_layout
create_hp_meter
b_pos = [enemy.screen_x - (@layout.width / 2) + POSITION_CORRECTION[0], enemy.screen_y + POSITION_CORRECTION[1] - (@layout.height / 2)]
@layout.opacity = 0
@org_pos1 = [b_pos[0],b_pos[1]]
@layout.x = @org_pos1[0]
@layout.y = @org_pos1[1]
@layout.visible = false
@hp_meter.opacity = 0
@hp_meter.visible = false
@org_pos2 = [b_pos[0] + HP_METER_POSITION[0], b_pos[1] + HP_METER_POSITION[1]]
@hp_meter.x = @org_pos2[0]
@hp_meter.y = @org_pos2[1]
@hp_meter.viewport = viewport
@hp_meter.z = PRIORITY_Z
@layout.viewport = viewport
@layout.z = PRIORITY_Z
@enemy.hp_meter_active[0] = false
@hide = @enemy.hp_meter_active[1]
end
#--------------------------------------------------------------------------
# ● Create HP Meter
#--------------------------------------------------------------------------
def create_layout
@layout = Sprite.new
@layout.bitmap = Cache.system("Battle_Enemy_HP_Layout")
end
#--------------------------------------------------------------------------
# ● Create HP Meter
#--------------------------------------------------------------------------
def create_hp_meter
@meter_image = Cache.system("Battle_Enemy_HP_Meter")
@meter_cw = @meter_image.width
@meter_ch = @meter_image.height / 2
@hp_meter = Sprite.new
@hp_meter.bitmap = Bitmap.new(@meter_cw,@meter_ch)
@hp_width_old = @meter_cw * @enemy.hp / @enemy.mhp
end
#--------------------------------------------------------------------------
# ● Hp Flow Update
#--------------------------------------------------------------------------
def update_hp_flow
return if !@layout.visible
hp_width = @meter_cw * @enemy.hp / @enemy.mhp
@hp_meter.bitmap.clear
execute_damage_flow(hp_width)
hp_src_rect = Rect.new(0, 0,hp_width, @meter_ch)
@hp_meter.bitmap.blt(0,0, @meter_image, hp_src_rect)
end
#--------------------------------------------------------------------------
# ● Execute Damage Flow
#--------------------------------------------------------------------------
def execute_damage_flow(hp_width)
n = (@hp_width_old - hp_width).abs * 3 / 100
damage_flow = [[n, 2].min,0.5].max
@hp_width_old -= damage_flow
if @hp_width_old <= hp_width
@hp_width_old = hp_width
end
src_rect_old = Rect.new(0,@meter_ch,@hp_width_old, @meter_ch)
@hp_meter.bitmap.blt(0,0, @meter_image, src_rect_old)
end
#--------------------------------------------------------------------------
# ● Dispose
#--------------------------------------------------------------------------
def dispose
return if @meter_image == nil
@layout.bitmap.dispose
@layout.dispose
@hp_meter.bitmap.dispose
@hp_meter.dispose
@meter_image.dispose
@meter_image = nil
end
#--------------------------------------------------------------------------
# ● Update
#--------------------------------------------------------------------------
def update
return if @meter_image == nil
return if @hide
update_fade
update_visible
update_hp_flow
refresh if @enemy.hp_meter_active[0]
end
#--------------------------------------------------------------------------
# ● Update Fade
#--------------------------------------------------------------------------
def update_fade
@fade_time -= 1 if @fade_time > 0
return if @fade_time != 0
@layout.opacity -= 10
@hp_meter.opacity -= 10
@layout.x += 1
@hp_meter.x += 1
@fade_time = -1 if @layout.opacity == 0
end
#--------------------------------------------------------------------------
# ● Update Visible
#--------------------------------------------------------------------------
def update_visible
return if !@layout.visible
vis = can_visible?
@layout.visible = vis
@hp_meter.visible = vis
end
#--------------------------------------------------------------------------
# ● Refresh
#--------------------------------------------------------------------------
def refresh
@enemy.hp_meter_active[0] = false
@layout.opacity = 255
@hp_meter.opacity = 255
@layout.visible = true
@hp_meter.visible = true
@fade_time = 60
@layout.x = @org_pos1[0]
@layout.y = @org_pos1[1]
@hp_meter.x = @org_pos2[0]
@hp_meter.y = @org_pos2[1]
hp_width = @meter_cw * @enemy.hp / @enemy.mhp
@hp_width_old = hp_width if @hp_width_old < hp_width
update_hp_flow
end
#--------------------------------------------------------------------------
# ● Can Visible?
#--------------------------------------------------------------------------
def can_visible?
return false if @layout.opacity == 0
return true
end
end
#==============================================================================
# ■ Spriteset Battle
#==============================================================================
class Spriteset_Battle
#--------------------------------------------------------------------------
# ● Initialize
#--------------------------------------------------------------------------
alias mog_enemy_hp_initialize initialize
def initialize
mog_enemy_hp_initialize
create_enemy_hp
end
#--------------------------------------------------------------------------
# ● Create Battle Hud
#--------------------------------------------------------------------------
def create_enemy_hp
dispose_enemy_hp
@enemy_hp = []
for i in $game_troop.members
@enemy_hp.push(Enemy_HP.new(@viewport1,i))
end
end
#--------------------------------------------------------------------------
# ● Dispose
#--------------------------------------------------------------------------
alias mog_enemy_hp_dispose dispose
def dispose
mog_enemy_hp_dispose
dispose_enemy_hp
end
#--------------------------------------------------------------------------
# ● Dispose Enemy HP
#--------------------------------------------------------------------------
def dispose_enemy_hp
return if @enemy_hp == nil
@enemy_hp.each {|sprite| sprite.dispose }
@enemy_hp.clear
@enemy_hp = nil
end
#--------------------------------------------------------------------------
# ● Update
#--------------------------------------------------------------------------
alias mog_enemy_hp_update update
def update
mog_enemy_hp_update
update_enemy_hp
end
#--------------------------------------------------------------------------
# ● Update Enemy HP
#--------------------------------------------------------------------------
def update_enemy_hp
return if @enemy_hp == nil
@enemy_hp.each {|sprite| sprite.update }
end
end
$mog_rgss3_enemy_hp_meter = true