=begin
护盾系统
by 炽天之咸鱼裁决
本插件基于yanfly引擎编写,没有yanfly也可运行,但是视觉效果会大打折扣
使用方法:此页面手动创建护盾类型,在技能或物品的备注栏调用
<addshield: x(,y,z...)> 为目标添加以下id的护盾
<shielddamage: "(技能公式)"> 用self替换b,用user替换a.技能仅对目标护盾造成此数值的伤害
<realdamage: "(技能公式)"> 用self替换b,用user替换a,技能对目标造成无视护盾的此数值的伤害
(新)重写了敌人盾条的视觉效果
(新)你可以在技能公式里使用“.s”来调用角色护盾数值总量
(新)若攻击全被吸收,则不会显示“0”
护盾参数,除数值外,不需要则无需填写
value:护盾数值,不能为空
status:数组,附加状态,代码来自Ninjamida
fade:护盾每回合增长数值(负数为减少数值)
max:护盾自然增长的最大值
cansave:若为false,脱战后不可保留
protect:若为true,则在破碎后防止额外的伤害
no:编号,拥有编号的护盾生成时会顶替掉同编号的
life:护盾持续最大回合数
death参数已被移除
(新)disappear:字符串,护盾由于击破以外的原因消失后执行以下代码
(新)broken:字符串,护盾被击破后执行以下代码
battlecry:字符串,护盾生成后执行以下代码
element:数组,护盾只对以下属性的伤害有作用
color1/2:color 盾条颜色
(新)heal:布尔,若值为true则治疗量会被转化为盾量
(新)add:布尔,若值为true则新护盾会继承原有同编号护盾的所有属性
(新)hp_heal:(支持使用技能公式)每回合为持有者恢复此数值的hp,负数则为减少
(新)mp_heal:(支持使用技能公式)每回合为持有者恢复此数值的mp,负数则为减少
(新)tp_heal:(支持使用技能公式)每回合为持有者恢复此数值的tp,负数则为减少
(新)onlyattack:若值为true,则无法防御状态造成的伤害
(新)icon:护盾图像的编号
=end
module SHIELD
TAKE_DAM= "吸收"
HP_HEAL = "护盾恢复"
HP_DAM = "护盾反噬"
MP_HEAL = "护盾恢复"
MP_DAM = "护盾反噬"
TP_HEAL = "护盾恢复"
TP_DAM = "护盾反噬"
FADE = "护盾衰减"
BREAK = "护盾破碎"
DISAPPEAR = "护盾消失"
REFRESH = "护盾刷新"
NEW = "护盾"
ADD = "护盾补充"
PROTECT = "保护"
GET_DAM= "吸收"
S_DAM = "碎盾"
R_DAM = "真实伤害"
end
class Battler_shield
attr_accessor :value
attr_accessor :status
attr_accessor :fade
attr_accessor :cansave
attr_accessor :protect
attr_accessor :no
attr_accessor :max
attr_accessor :life
attr_accessor :disappear
attr_accessor :broken
attr_accessor :color1
attr_accessor :color2
attr_accessor :battlecry
attr_accessor :element
attr_accessor :heal
attr_accessor :add
attr_accessor :hp_heal
attr_accessor :mp_heal
attr_accessor :tp_heal
attr_accessor :onlyattack
attr_accessor :icon
def initialize(type,user,target)
@user = user
@target = target
case type
#以如下格式创建自定义的护盾
when 1
@value = user.mhp - user.hp + 30
@max = 0
@cansave = false
@protect = false
@no = 1
@life = 5
@add = true
@onlyattack = true
when 2
@value = user.mhp * 0.25 - user.hp * 0.25 + 200 .to_i
@max = 0
@cansave = false
@protect = false
@no = 1
@life = 5
@add = true
@onlyattack = true
when 3
@value = 10
@max = 0
@cansave = false
@protect = false
@no = 1
@life = 999
@add = true
@onlyattack = true
when 4
@value = 1000
@max = 0
@cansave = false
@protect = true
@no = 1
@life = 7
@add = true
@onlyattack = true
when 5
@value = 30
@max = 0
@cansave = false
@protect = true
@no = 1
@life = 3
@add = true
@onlyattack = true
when 6
@value = 1
@max = 0
@cansave = false
@protect = true
@no = 1
@life = 2
@add = true
@onlyattack = true
when 7
@value = @user.hp
@status = [24]
end
##################################
msgbox("护盾值不能为空") if @value == nil
@value = @value.to_i
end
end
class Sprite_Seed#伴生精灵参数
attr_accessor :icon#图像与色调
attr_accessor :dx#相对战斗者的x值
attr_accessor :dy#相对战斗者的y值
attr_accessor :dz#相对战斗者的z值
attr_accessor :opacity#透明度
attr_accessor :begin#入场动画id
attr_accessor :exist#持续时播放的动画id
attr_accessor :end#退场动画id
def initialize(n)
case n
when 1
@icon = ["terry.png",0]
@dx = 0
@dy = 0
@dz = 0
@opacity = 100
end
end
end
#############################################################################
class RPG::BaseItem
attr_accessor :shield
attr_accessor :s_damage
attr_accessor :r_damage
def shield
if @shield.nil?
@shield = []
if @note =~ /<addshield:[ ](.*)>/i
for x in $1.split(",")
@shield += [x.to_i]
end
end
end
@shield
end
def shield_damage
if @s_damage.nil?
@s_damage = 0
if @note =~ /<shielddamage:[ ](.*)>/i
@s_damage = $1.to_s
end
end
@s_damage
end
def real_damage
if @r_damage.nil?
@r_damage = 0
if @note =~ /<realdamage:[ ](.*)>/i
@r_damage = $1.to_s
end
end
@r_damage
end
end
###############来自Ninjamida#######################
class RPG::BaseItem
def auto_states
if @auto_states.nil?
@auto_states = []
if @note =~ /<auto state:[ ](.*)>/i
for x in $1.split(",")
@auto_states += [x.to_i]
end
end
end
@auto_states
end
end
class Game_Actor < Game_Battler
def auto_states
autostates = self.class.auto_states + actor.auto_states
equips.each do |eq|
autostates += eq.auto_states unless eq.nil?
end
states.each do |st|
autostates += st.auto_states
end
@shield.each{|i|
autostates += i.status if i.status != nil
}
autostates = autostates.uniq
return autostates
end
end
class Game_Enemy < Game_Battler
def auto_states
autostates = enemy.auto_states
states.each do |st|
autostates += st.auto_states
end
@shield.each{|i|
autostates += i.status if i.status != nil
}
autostates = autostates.uniq
return autostates
end
end
class Scene_Battle
alias s_auto_state_battle_start battle_start
def battle_start
s_auto_state_battle_start
$game_party.members.each{|mem|
mem.add_auto_states
status_redraw_target(mem) if $imported["YEA-BattleEngine"]
}
end
end
class Game_Battler
alias s_auto_states_initialize initialize
def initialize
s_auto_states_initialize
@old_auto_states = []
end
def add_auto_states
return if state?(death_state_id)
auto_states.each do |st|
if not state?(st)
add_state(st)
@state_turns[st] = -1
end
end
end
def remove_old_auto_states
auto_states.each do |as|
@old_auto_states.delete(as)
end
@old_auto_states.each do |oas|
remove_state(oas)
end
@old_auto_states = auto_states
end
alias s_auto_state_item_effect_remove_state item_effect_remove_state
def item_effect_remove_state(user, item, effect)
s_auto_state_item_effect_remove_state(user, item, effect) unless auto_states.include?(effect.data_id)
end
alias s_auto_state_refresh refresh
def refresh
s_auto_state_refresh
add_auto_states
remove_old_auto_states
end
end
###############################################################
#读档时为没有护盾属性的角色添加(避免坏档)
module DataManager
class <<self; alias shield_extract_save_contents extract_save_contents; end
def self.extract_save_contents(contents)
shield_extract_save_contents(contents)
$game_actor.each{|a|
a.shield_init
}
end
end
class Game_ActionResult
attr_accessor :s_damage
attr_accessor :r_damage
alias s_clear_damage_values clear_damage_values
def clear_damage_values
s_clear_damage_values
@s_damage = 0
@r_damage = 0
end
alias s_make_damage make_damage
def make_damage(value, item)
s_make_damage(value, item)
@s_damage = item.shield_damage
end
end
class Game_BattlerBase
attr_accessor :shield
attr_accessor :ex_sprite
def shield_add(a,b)
b.value += a.value
b.status += a.status if b.status != nil and a.status != nil
b.status = a.status if b.status == nil
b.element += a.element if b.element != nil and a.element != nil
b.element = a.element if b.element == nil
b.fade += a.fade if b.fade != nil and a.fade != nil
b.fade = a.fade if b.fade == nil
b.cansave = false if a.cansave == false
b.protect = true if a.protect == true
b.max = a.max if b.max == nil
b.life += a.life if b.life != nil and a.life != nil
b.life = a.life if b.life == nil
b.disappear = "#{a.disappear};#{b.disappear}" if b.disappear != nil and a.disappear != nil
b.disappear = a.disappear if b.disappear == nil
b.broken = "#{a.broken};#{b.broken}" if b.broken != nil and a.broken != nil
b.broken = a.broken if b.broken == nil
b.color1 = a.color1 if a.color1
b.color2 = a.color2 if a.color2
b.heal = true if a.heal == true
b.hp_heal += a.hp_heal if b.hp_heal != nil and a.hp_heal != nil
b.hp_heal = a.hp_heal if b.hp_heal == nil
b.mp_heal += a.mp_heal if b.mp_heal != nil and a.mp_heal != nil
b.mp_heal = a.mp_heal if b.mp_heal == nil
b.tp_heal += a.tp_heal if b.tp_heal != nil and a.tp_heal != nil
b.tp_heal = a.tp_heal if b.tp_heal == nil
end
def s
sv = 0
@shield.each{|i|
sv += i.value
}
return sv
end
def shield_init
return if @shield
@shield = []
@ex_sprite = {}
@s = 0
end
alias initializewithshield initialize
def initialize
initializewithshield
shield_init
end
def nocheck(no)
@shield.each_index{|i|
if @shield[i].no == no
@shield.delete_at(i)
break
end
}
end
def shieldtotal
n = 0
@shield.each{|i|
n += i.value}
return n
end
def draw_bar_rate
a = []
b = draw_hp_rate
a << b
s = 1 - b
t = shieldtotal
@shield.each{|i|
r = s * i.value.to_f / t
a << r }
return a
end
def shield_bar_rate
a = []
b = draw_hp_rate
s = 1 - b
t = shieldtotal
@shield.each{|i|
r = s * i.value.to_f / t
a << r }
return a
end
def shield_rate
s = shieldtotal
if @hp + s <= mhp
return s.to_f / mhp
else
return s.to_f / (s + @hp).to_f
end
end
def draw_hp_rate
s = shieldtotal
if @hp + s <= mhp
return @hp.to_f / mhp
else
return @hp.to_f / (s + @hp).to_f
end
end
def draw_shield_rate
s = shieldtotal
if @hp + s <= mhp
return s.to_f / (mhp - @hp)
else
return 1
end
end
end
class Game_Battler < Game_BattlerBase
def shield_heal
shield_hp_heal
shield_mp_heal
shield_tp_heal
end
def shield_hp_heal
@shield.each_index{|i|
if @shield[i].hp_heal != nil
value = @shield[i].hp_heal
value = self.mhp - @hp if (@hp + value) > self.mhp
value = @hp if (@hp + value) < 0
if value > 0
rules = "HP_HEL"
text = SHIELD::HP_HEAL
create_popup(text, rules)
text = "+#{value}"
create_popup(text, rules)
elsif value < 0
rules = "HP_DMG"
text = SHIELD::HP_DAM
create_popup(text, rules)
text = "-#{-value}"
create_popup(text, rules)
end
@hp += value
end
}
end
def shield_mp_heal
@shield.each_index{|i|
if @shield[i].mp_heal != nil
value = @shield[i].mp_heal
value = @self.mmp - @mp if (@mp + value) > self.mmp
value = @mp if (@mp + value) < 0
if value > 0
rules = "MP_HEL"
text = SHIELD::MP_HEAL
create_popup(text, rules)
text = "+#{value}"
create_popup(text, rules)
elsif value < 0
rules = "MP_DMG"
text = SHIELD::MP_DAM
create_popup(text, rules)
text = "-#{-value}"
create_popup(text, rules)
end
@mp += value
end
}
end
def shield_tp_heal
@shield.each_index{|i|
if @shield[i].tp_heal != nil
value = @shield[i].tp_heal
value = 100 - @tp if (@tp + value) > 100
value = @tp if (@tp + value) < 0
if value > 0
rules = "MP_HEL"
text = SHIELD::TP_HEAL
create_popup(text, rules)
text = "+#{value}"
create_popup(text, rules)
elsif value < 0
rules = "MP_DMG"
text = SHIELD::TP_DAM
create_popup(text, rules)
text = "-#{-value}"
create_popup(text, rules)
end
@tp += value
end
}
end
alias shieldon_turn_end on_turn_end
def on_turn_end
shield_heal
s = @shield.size - 1
i = 0
while i <= s
fade = @shield[i].fade
if fade != nil and fade != 0
if @shield[i].max != nil
ts = @shield[i].value + fade
if @shield[i].max > @shield[i].value
fade = @shield[i].max - @shield[i].value if ts > @shield[i].max
else
fade = 0
end
end
rules = "MP_DMG"
text = SHIELD::FADE
create_popup(text, rules)
text = sprintf(+"%s", fade) if fade > 0
text = sprintf("%s", fade) if fade < 0
create_popup(text, rules)
@shield[i].value += fade
end
life = @shield[i].life
if life != nil
@shield[i].life -= 1
end
if @shield[i].value <= 0 or @shield[i].life == 0
shielddisappear(i)
i -= 1
s = @shield.size - 1
end
i += 1
end
shieldon_turn_end
end
def addshield(item,user,target)
return if item.shield == nil
item.shield.each{|i|
s = Battler_shield.new(i,user,target)
if s.no != nil
@shield.each_index{|i|
if @shield[i].no == s.no
shield_add(@shield[i],s) if @shield[i].add == true or s.add == true
@ex_sprite[@shield[i]].kill unless @shield[i].icon.nil?
@shield.delete_at(i)
@s_fresh = true
break
end
}
end
if self.class == Game_Enemy
scene = SceneManager.scene.spriteset.viewport1
else
scene = nil
end
@ex_sprite[s]=Sprite_Battler_Ex.new(scene,Sprite_Seed.new(s.icon),self) unless s.icon.nil?
@s_value << s.value
@shield << s
eval s.battlecry if s.battlecry != nil
}
end
def shielddisappear(i)
$imported = {} if $imported.nil?
if $imported["YEA-BattleEngine"]
if @shield[i].value == 0
rules = "HP_DMG"
text = SHIELD::BREAK
create_popup(text, rules)
else
rules = "HP_DMG"
text = SHIELD::DISAPPEAR
create_popup(text, rules)
end
end
if @shield[i].value == 0
eval @shield[i].broken if @shield[i].broken != nil
else
eval @shield[i].disappear if @shield[i].disappear != nil
end
@ex_sprite[@shield[i]].kill unless @shield[i].icon.nil?
@shield.delete_at(i)
end
def regenerate_hp #状态伤害
damage = -(mhp * hrg).to_i
perform_map_damage_effect if $game_party.in_battle && damage > 0
@result.hp_damage = [damage, max_slip_damage].min
state_shielduse
self.hp -= @result.hp_damage
end
def state_shielduse
return if @result.hp_damage == 0
if @result.hp_damage < 0
healshield
return
end
unless @shield.empty?
size = @shield.size
n = size - 1
while n >= 0
if @s_invalid.include?(n)
n -= 1
next
end
if @shield[n].onlyattack == true
n -= 1
next
end
@result.hp_damage -= @shield[n].value
if @result.hp_damage >= 0 #碎盾
if @shield[n].protect == true
@result.hp_damage = 0
@protect = true
end #碎盾保护
@t_damage += @shield[n].value
shielddisappear(n)
else #未碎盾
@t_damage += @shield[n].value
@t_damage += @result.hp_damage
@shield[n].value = -@result.hp_damage
@result.hp_damage = 0
end
break if @result.hp_damage == 0
n -= 1
end
@useshield = true if @t_damage != 0
end
end
def shielddamage
return if @result.s_damage == 0
@result.s_damage = 0 if @shield.empty?
unless @shield.empty?
dam = @result.s_damage
size = @shield.size
n = size - 1
while n >= 0
@result.s_damage -= @shield[n].value
if @result.s_damage >= 0 #碎盾
@s_damage += @shield[n].value
@shield.delete_at(n)
else #未碎盾
@s_damage += @shield[n].value
@s_damage += @result.s_damage
@shield[n].value = -@result.s_damage
@result.s_damage = 0
end
break if @result.s_damage == 0
n -= 1
end
@result.s_damage = 0 if @result.s_damage < 0
@result.s_damage = dam - @result.s_damage
end
end
def healshield
unless @shield.empty?
size = @shield.size
n = size - 1
while n >= 0
if @shield[n].heal == true
@shield[n].value -= @result.hp_damage
@t_damage = -@result.hp_damage
@result.hp_damage = 0
return
end
n -= 1
end
end
end
def useshield
shielddamage
return if @result.hp_damage == 0
if @result.hp_damage < 0
healshield
return
end
unless @shield.empty?
size = @shield.size
n = size - 1
while n >= 0
if @s_invalid.include?(n)
n -= 1
next
end
@result.hp_damage -= @shield[n].value
if @result.hp_damage >= 0 #碎盾
if @shield[n].protect == true
@result.hp_damage = 0
@protect = true
end #碎盾保护
@t_damage += @shield[n].value
shielddisappear(n)
else #未碎盾
@t_damage += @shield[n].value
@t_damage += @result.hp_damage
@shield[n].value = -@result.hp_damage
@result.hp_damage = 0
end
break if @result.hp_damage == 0
n -= 1
end
@useshield = true if @t_damage != 0
end
end
def s_invalid(user, item)
@s_invalid = []
return if item.damage == nil
@shield.each_index{|n|
if @shield[n].element != nil
@shield[n].element.each{|i|
@s_invalid << n unless user.atk_elements.include?(i) or item.damage.element_id == i
}
end
}
end
def item_element(i)
if item.damage.element_id < 0
user.atk_elements
else
item.damage.element_id
end
end
alias item_applyshield item_apply
def item_apply(user, item)
@s_value = []
s_invalid(user, item)
addshield(item,user,self)
make_damage_popups(user)
item_applyshield(user, item)
end
alias s_make_damage_value make_damage_value
def make_damage_value(user, item)
s_make_damage_value(user, item)
r = eval(item.real_damage.to_s)
@result.r_damage = r.to_i
s = eval(item.s_damage.to_s)
@result.s_damage = s.to_i
end
alias execute_damagewithshield execute_damage
def execute_damage(user)
@t_damage = 0
@s_damage = 0
useshield
self.hp -= [@result.r_damage,self.hp].min
execute_damagewithshield(user)
end
$imported = {} if $imported.nil?
if $imported["YEA-BattleEngine"]
alias shieldmake_damage_popups make_damage_popups
def make_damage_popups(user)
if @s_value != [] and @s_value != nil
if @s_fresh != nil
text = SHIELD::REFRESH
rules = "HP_HEL"
create_popup(text, rules)
@s_fresh = nil
else
text = SHIELD::NEW
rules = "HP_DMG"
create_popup(text, rules)
end
@s_value.each{|i|
value = i.abs
text = sprintf("%s", value.group)
create_popup(text, rules)
}
@s_value = []
end
if @useshield != nil
if @t_damage > 0
if @protect != nil
text = SHIELD::PROTECT
rules = "HP_HEL"
@protect = nil
else
text = SHIELD::GET_DAM
rules = "HP_DMG"
end
create_popup(text, rules)
value = @t_damage.abs
rules = "MP_DMG"
text = sprintf("%s", value.group)
create_popup(text, rules)
elsif @t_damage < 0
text = SHIELD::ADD
rules = "HP_HEL"
@protect = nil
create_popup(text, rules)
value = @t_damage.abs
rules = "MP_DMG"
text = sprintf(+"%s", value.group)
create_popup(text, rules)
end
end
if @result.s_damage != 0
text = SHIELD::S_DAM
rules = "HP_DMG"
create_popup(text, rules)
value = @result.s_damage
text = sprintf("%s", value)
create_popup(text, rules)
@result.s_damage = 0
end
if @result.r_damage != 0
text = SHIELD::R_DAM
rules = "HP_DMG"
create_popup(text, rules)
value = @result.r_damage
text = sprintf("%s", value)
create_popup(text, rules)
@result.r_damage = 0
end
shieldmake_damage_popups(user)
@t_damage = 0
end
def make_miss_popups(user, item)
return if dead?
if @result.missed && item.shield == []
text = YEA::BATTLE::POPUP_SETTINGS[:missed]
rules = "DEFAULT"
create_popup(text, rules)
end
if @result.evaded && item.shield == []
text = YEA::BATTLE::POPUP_SETTINGS[:evaded]
rules = "DEFAULT"
create_popup(text, rules)
end
if @result.hit? && !@result.success && item.shield == []
text = YEA::BATTLE::POPUP_SETTINGS[:failed]
rules = "DEFAULT"
create_popup(text, rules)
end
if @result.hit? && item.damage.to_hp? && @useshield == nil && item.shield == []
if @result.hp_damage == 0 && @result.hp_damage == 0
text = YEA::BATTLE::POPUP_SETTINGS[:nulled]
rules = "DEFAULT"
create_popup(text, rules)
end
end
@useshield = nil
end
end
alias shieldon_battle_end on_battle_end
def on_battle_end
shieldon_battle_end
s = @shield.size - 1
i = 0
while i <= s
if @shield[i].cansave == false
shielddisappear(i)
i -= 1
s = @shield.size - 1
end
i += 1
end
end
end
class Window_BattleStatus
def shield_gauge_color1; text_color(0); end;
def shield_gauge_color2; text_color(8); end;
def draw_actor_hp(actor, dx, dy, width = 124)
s = actor.shieldtotal
draw_gauge(dx, dy, width, actor.draw_hp_rate, hp_gauge_color1, hp_gauge_color2)
draw_actor_shield(actor, dx + width * actor.draw_hp_rate , dy, width)
cy = (Font.default_size - contents.font.size) / 2 + 1
draw_text(dx+2, dy+cy, 30, line_height, Vocab::hp_a)
draw_current_and_max_values(dx, dy+cy, width, actor.hp, actor.mhp,
hp_color(actor), normal_color)
end
def draw_actor_shield(actor, dx, dy, width = 124)
actor.shield.each{|i|
w = width.to_f * (1- actor.draw_hp_rate) * actor.draw_shield_rate * i.value / actor.shieldtotal
c1 = i.color1 ? i.color1 : shield_gauge_color1
c2 = i.color2 ? i.color2 : shield_gauge_color2
draw_gauge(dx, dy, w , 1, c1, c2)
dx += w
}
change_color(system_color)
end
end
class Window_Base
def shield_gauge_color1; text_color(0); end;
def shield_gauge_color2; text_color(8); end;
def draw_actor_hp(actor, dx, dy, width = 124)
s = actor.shieldtotal
draw_gauge(dx, dy, width, actor.draw_hp_rate, hp_gauge_color1, hp_gauge_color2)
draw_actor_shield(actor, dx + width * actor.draw_hp_rate , dy, width)
cy = (Font.default_size - contents.font.size) / 2 + 1
draw_text(dx+2, dy+cy, 30, line_height, Vocab::hp_a)
draw_current_and_max_values(dx, dy+cy, width, actor.hp, actor.mhp,
hp_color(actor), normal_color)
end
def draw_actor_shield(actor, dx, dy, width = 124)
actor.shield.each{|i|
w = width.to_f * (1- actor.draw_hp_rate) * actor.draw_shield_rate * i.value / actor.shieldtotal
c1 = i.color1 ? i.color1 : shield_gauge_color1
c2 = i.color2 ? i.color2 : shield_gauge_color2
draw_gauge(dx, dy, w , 1, c1, c2)
dx += w
}
change_color(system_color)
end
end
#######来自yanfly与DoubleX#############
$imported = {} if $imported.nil?
if $imported["YEA-EnemyHPBars"] and $imported["DoubleX RMVXA Percentage Addon to YEA-EnemyHPBars"]
class Enemy_HP_Gauge_Viewport < Viewport
def initialize(battler, sprite, type)
@battler = battler
@base_sprite = sprite
@type = type
dw = YEA::BATTLE::ENEMY_GAUGE_WIDTH
if @type == :percent && FIX_LARGE_TEXT
dh = [TEXT_SIZE, YEA::BATTLE::ENEMY_GAUGE_HEIGHT].max
else
dh = YEA::BATTLE::ENEMY_GAUGE_HEIGHT
end
if @type != :hp and @type != :shield
dw += 2
dh += 2
end
@start_width = dw
rect = Rect.new(0, 0, dw, dh)
@current_hp = @battler.hp
@current_mhp = @battler.mhp
@current_hr = @battler.draw_hp_rate
@current_sr = @battler.shield_bar_rate
@target_gauge_width = target_gauge_width
@gauge_rate = @current_hr
setup_original_hide_gauge
super(rect)
self.z = 125
create_gauge_sprites
self.visible = false
update_position
self.rect.width = @gauge_width if @type == :hp
end
def target_gauge_rate
return @current_hr
end
def target_gauge_width
return [@current_hr * @start_width, @start_width].min
end
def update_gauge
unless @gauge_width == @target_gauge_width
rate = 3
@target_gauge_width = target_gauge_width
if @gauge_width > @target_gauge_width
@gauge_width = [@gauge_width - rate, @target_gauge_width].max
elsif @gauge_width < @target_gauge_width
@gauge_width = [@gauge_width + rate, @target_gauge_width].min
end
@visible_counter = @gauge_width == 0 ? 10 : 60
rect.width = @gauge_width if @type == :hp
end
shield_update
end
def new_hp_updates
return if @current_hr == @battler.draw_hp_rate and @current_sr == @battler.shield_bar_rate
@current_hp = @battler.hp
@current_mhp = @battler.mhp
@current_hr = @battler.draw_hp_rate
return if @gauge_rate == target_gauge_rate
@gauge_rate = target_gauge_rate
@target_gauge_width = target_gauge_width
@visible_counter = 60
end
def update_percentage
return if @last_hp == @current_hp
@last_hp = @current_hp
set_percentage_font
if ACTUAL_NUMBER
percent = @current_hp.to_i.to_s
else
percent = "#{(@current_hp.to_f / @current_mhp.to_f * 100).to_i.to_s}%"
end
dw = @sprite.bitmap.text_size(percent).width
@sprite.bitmap.clear
@sprite.bitmap.draw_text(YEA::BATTLE::ENEMY_GAUGE_WIDTH + 2 - dw, 1, dw,
@sprite.bitmap.text_size(percent).height, percent)
end
def create_gauge_sprites
@sprite = Plane.new(self)
@sprite.bitmap = Bitmap.new(rect.width * 4, rect.height)
enemy = @battler.enemy
if @type == :back
colour = Colour.text_colour(enemy.back_gauge_colour)
colour1 = colour2 = colour
elsif @type == :hp
colour1 = Colour.text_colour(enemy.hp_gauge_colour1)
colour2 = Colour.text_colour(enemy.hp_gauge_colour2)
elsif @type == :percent
colour1 = colour2 = Color.new(0, 0, 0, 0)
end
dw = rect.width
dw *= @battler.draw_hp_rate
dh = rect.height
@gauge_width = target_gauge_width
if @type == :shield
new_shield
else
@sprite.bitmap.gradient_fill_rect(0, 0, dw, dh, colour1, colour2)
@sprite.bitmap.gradient_fill_rect(dw, 0, dw, dh, colour2, colour1)
end
@visible_counter = 0
end
def new_shield
return if @battler.shield == []
dh = rect.height
dx = @gauge_width
shield = @battler.shield
shield.each_index{|i|
dw = @start_width * @current_sr[i]
dw = @start_width - dx + 3 if i == shield.size - 1
c1 = shield[i].color1 ? shield[i].color1 : Colour.text_colour(0)
c2 = shield[i].color2 ? shield[i].color2 : Colour.text_colour(8)
@sprite.bitmap.gradient_fill_rect(dx, 0, dw, dh, c1, c2)
dx += dw
}
end
def shield_update
if @type == :shield and @battler.shield_bar_rate == []
@sprite.bitmap.clear
end
return if @current_sr == @battler.shield_bar_rate and @gauge_width == @target_gauge_width
@current_sr = @battler.shield_bar_rate
if @type == :shield
dx = @gauge_width
dh = rect.height
shield = @battler.shield
shield.each_index{|i|
dw = @start_width * @current_sr[i]
dw = @start_width - dx + 3 if i == shield.size - 1
c1 = shield[i].color1 ? shield[i].color1 : Colour.text_colour(0)
c2 = shield[i].color2 ? shield[i].color2 : Colour.text_colour(8)
@sprite.bitmap.gradient_fill_rect(dx, 0, dw, dh, c1, c2)
dx += dw
}
end
@visible_counter = 60
end
def update_position
dx = @battler.screen_x
dy = @battler.screen_y
@update_position = false
return if @last_x == dx && @last_y == dy
@last_x = dx
@last_y = dy
@update_position = true
dx -= @start_width / 2
if @type == :percent
dx += TEXT_X_OFFSET
dy += TEXT_Y_OFFSET
end
rect.x = dx
rect.y = dy
dh = rect.height + 1
dh += 2 if @type == :hp or @type == :shield
dy = [dy, Graphics.height - dh - 120].min
dy += 1 if @type == :hp or @type == :shield
#
rect.y = dy
end
end
class Sprite_Battler < Sprite_Base
def create_enemy_gauges
return if @battler.nil?
return if @battler.actor?
return unless @battler.enemy.show_gauge
@back_gauge_viewport = Enemy_HP_Gauge_Viewport.new(@battler, self, :back)
@hp_gauge_viewport = Enemy_HP_Gauge_Viewport.new(@battler, self, :hp)
@shield_gauge_viewport = Enemy_HP_Gauge_Viewport.new(@battler, self, :shield)
return unless @battler && !@battler.actor? && @battler.enemy.show_gauge
@percent_gauge_viewport = Enemy_HP_Gauge_Viewport.new(@battler, self,
:percent)
end
def dispose_enemy_gauges
@back_gauge_viewport.dispose unless @back_gauge_viewport.nil?
@hp_gauge_viewport.dispose unless @hp_gauge_viewport.nil?
@shield_gauge_viewport.dispose unless @shield_gauge_viewport.nil?
@percent_gauge_viewport.dispose if @percent_gauge_viewport
end
def update_enemy_gauges
@back_gauge_viewport.update unless @back_gauge_viewport.nil?
@hp_gauge_viewport.update unless @hp_gauge_viewport.nil?
@shield_gauge_viewport.update unless @shield_gauge_viewport.nil?
@percent_gauge_viewport.update if @percent_gauge_viewport
end
def update_enemy_gauge_value
@back_gauge_viewport.new_hp_updates unless @back_gauge_viewport.nil?
@hp_gauge_viewport.new_hp_updates unless @hp_gauge_viewport.nil?
@shield_gauge_viewport.new_hp_updates unless @shield_gauge_viewport.nil?
@percent_gauge_viewport.new_hp_updates if @percent_gauge_viewport
end
end
end
class Sprite_Battler
alias ex_initialize initialize
def initialize(viewport, battler = nil)
ex_initialize(viewport, battler)
end
alias ex_update update
def update
ex_update
return if self.class == Sprite_Battler_Ex
return if @battler == nil
return if @battler.ex_sprite == {}
@battler.ex_sprite.each_value {|sprite| sprite.update}
end
alias s_start_effect start_effect
def start_effect(effect_type)
s_start_effect(effect_type)
return if self.class == Sprite_Battler_Ex
return if @battler == nil
@battler.ex_sprite.each_value {|sprite| sprite.start_effect(effect_type) } unless @battler.ex_sprite == []
end
alias s_dispose dispose
def dispose
s_dispose
return if self.class == Sprite_Battler_Ex
return if @battler == nil
@battler.ex_sprite.each_value {|sprite| sprite.dispose } unless @battler.ex_sprite == []
end
end
class Sprite_Battler_Ex < Sprite_Battler
def initialize(viewport,sprite,battler)
super(viewport)
@battler = battler
@sprite = sprite
@icon = @sprite.icon
@opacity = @sprite.opacity
@dx = @sprite.dx
@dy = @sprite.dy
@dz = @sprite.dz
@begin = @sprite.begin
@exist = @sprite.exist
@end = @sprite.end
@visible = false
@live = true
@path = "Graphics/Battlers/"
appear
end
def appear
if @sprite.begin != nil
start_animation(@sprite.begin[0], @sprite.begin[1])
else
start_effect(:appear)
end
end
def dispose
bitmap.dispose if bitmap
super
end
def update
super
update_exist
update_bitmap
update_origin
update_position
update_effect
update_kill
end
def update_exist
if @sprite.exist != nil
start_animation(@sprite.exist[0], @sprite.exist[1]) unless animation?
end
end
def update_kill
return if @live == true
@live -= 1
dispose if @live == 0
end
def kill
@life = 60
if @end != nil
start_animation(@end[0], @end[1])
end
start_effect(:disappear)
end
def update_bitmap
new_bitmap = Cache.load_bitmap(@path,@icon[0],@icon[1])
if bitmap != new_bitmap
self.bitmap = new_bitmap
init_visibility
end
end
def init_visibility
@battler_visible = @battler.alive?
self.opacity = 0 unless @battler_visible
end
def update_position
self.x = @battler.screen_x + @sprite.dx
self.y = @battler.screen_y + @sprite.dy
self.z = @battler.screen_z + @sprite.dz
end
def revert_to_normal
self.blend_type = 0
self.color.set(0, 0, 0, 0)
self.opacity = @sprite.opacity
self.ox = bitmap.width / 2 if bitmap
self.src_rect.y = 0
end
end
class Scene_Battle
alias shield_refresh_status refresh_status
def refresh_status
shield_refresh_status
$game_party.members.each{|a|
a.refresh
}
$game_troop.members.each{|e|
e.refresh
}
update_for_wait
end
alias shield_use_item use_item
def use_item
shield_use_item
refresh_status
end
end