#:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=#
# Blizz-ABS Magic Bars for Enemies Script by TerreAqua
# Version: 1.00
# Type: Blizz-ABS Add-on
# Key Term: Battle Add-on
# Date: 12/05/10
#:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=#
#:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=#
# ~ Plug & Play ~
#:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=#
class Control_Sprite_Character
#----------------------------------------------------------------------------
# create_health_sprite
# Creates a health sprite.
#----------------------------------------------------------------------------
def create_magic_sprite
# if magic bars active and observing enemy
if BlizzABS::Config::ENEMY_HEALTH_BARS > 0 &&
@character.is_a?(Map_Enemy) && !@character.hide_health &&
@character.opacity > 0 && @character.battler.maxsp != 0
# create a sprite
@magic = Sprite.new(@viewport)
# whether ENEMY_HEALTH_BARS_MATCH_WIDTH is active and tile graphic
if @character.tile_id < 384 &&
BlizzABS::Config::ENEMY_HEALTH_BARS_MATCH_WIDTH
# set the width
width = @sprite.bitmap.width / 4
else
# set the width to default
width = 32
end
# x offset
@magic.ox = width / 2
# create bitmap
@magic.bitmap = Bitmap.new(width, 6)
# fill bitmap background for better display
@magic.bitmap.fill_rect(0, 0, width, 6, Color.new(0, 26, 0))
# set magic bar z coordinate
@magic.z = 1
# set magic bar opacity
@magic.opacity = BlizzABS::Config::ENEMY_HEALTH_BARS
end
end
#----------------------------------------------------------------------------
# update_magic
# Handles magic sprite updating.
#----------------------------------------------------------------------------
def update_magic
# move health sprite along with sprite
@magic.x = @sprite.x
@magic.y = @sprite.y - @sprite.oy
@magic.z = @sprite.z + 1
# if enemy SP have changed
if @sp != @character.battler.sp || @battler_id != @character.battler_id
# rate of filling
rate = @character.battler.sp.to_f / @character.battler.maxsp
# get empty bar bitmap
bitmaps = [$BlizzABS.cache.image('empty_enemy_bar'),
$BlizzABS.cache.image('enemy_bar')]
# change hue of bar bitmap
bitmaps[1].hue_change((rate / 0.8 - 1.25) * 120 + 90)
# temporary variable
width = @magic.bitmap.width - 2
# draw empty bar bitmap
@magic.bitmap.stretch_blt(Rect.new(1, 0, width, 6), bitmaps[0],
Rect.new(0, 0, 1, 6))
# draw bar bitmap
@magic.bitmap.stretch_blt(Rect.new(1, 0, rate * width, 6), bitmaps[1],
Rect.new(0, 0, 1, 6))
# store new values
@sp, @battler_id = @character.battler.sp, @character.battler_id
end
end
alias mp_bars_update update
def update
mp_bars_update
# if character within ABSEAL range or special character
if self.character_valid?
# if sprite doesn't exists yet
if @sprite == nil || @sprite.disposed?
# create magic sprite
create_magic_sprite
# update magic bar if health bar exists
update_magic if @magic != nil
else
if @character.is_a?(Map_Battler) && @character.valid? &&
@character.battler.maxsp != 0
# create magic sprite if magic sprite doesn't exist yet
create_magic_sprite if @magic == nil
end
# update magic bar if magic bar exists and character is not dead
update_magic if @magic != nil && !@character.battler.dead?
end
# if sprite exists
elsif @sprite != nil
# delete magic sprite if it exists and not freed yet
@magic.dispose unless @magic == nil || @magic.disposed?
# remove sprite from memory
@magic = @sp = nil
end
end
end