=begin
==============================================================================
** HP Shield
Author: Hime
Version: 1.0
Date: May 20, 2012
------------------------------------------------------------------------------
** Change log
1.0 May 20
-Initial release
------------------------------------------------------------------------------
This script allows you to give an actor "hp shields", which increases the
amount of damage that a user can take.
When HP shields are enabled, the shield will take the damage while
the user's HP is protected.
To give an item or skill HP shield effect, tag them with
<shp: n>
Where n is an integer
==============================================================================
=end
$imported = {} if $imported.nil?
$imported["Tsuki_HPShield"] = true
#==============================================================================
# ** Configuration.
#==============================================================================
module Tsuki
module HP_Shield
# adds the shields to your HP display
Show_Shield_Bonus = true
EFFECT_ADD_SHIELDS = 50
Shield_Regex = /<shp:?\s*(.*)\s*>/i
def add_effect(effects, code, data_id, value1=0, value2=0)
effects << RPG::UsableItem::Effect.new(code, data_id, value1, value2)
end
end
end
#==============================================================================
# ** Rest of the script.
#==============================================================================
module RPG
class UsableItem < BaseItem
include Tsuki::HP_Shield
def load_notetags_hp_shield
matches = Shield_Regex.match(self.note)
if matches
add_effect(@effects, EFFECT_ADD_SHIELDS, 0, $1, 0)
end
end
end
end
module DataManager
class << self
alias hp_shield_load_database load_database
alias hp_shield_init init
end
def self.init
hp_shield_init
load_notetags_hp_shield
end
def self.load_database
hp_shield_load_database
if $BTEST
load_notetags_hp_shield
end
end
def self.load_notetags_hp_shield
groups = [$data_skills, $data_items]
for group in groups
for obj in group
next if obj.nil?
obj.load_notetags_hp_shield
end
end
end
end
class Game_BattlerBase
include Tsuki::HP_Shield
attr_accessor :shp
alias th_hp_shield_initialize_bbase initialize
def initialize
th_hp_shield_initialize_bbase
@shp = @mshp = 0
end
def hp
return Show_Shield_Bonus ? [@hp + @shp, 0].max : [@hp, 0].max
end
def mshp
@mshp
end
def shp_rate
mshp > 0 ? @shp.to_f / mshp : 0
end
end
class Game_Battler < Game_BattlerBase
alias th_hp_shield_item_effect_apply item_effect_apply
def item_effect_apply(user, item, effect)
th_hp_shield_item_effect_apply(user, item, effect)
item_effect_apply_ex(user, item, effect)
end
alias :hp_shield_get_method_table :get_method_table if self.method_defined? :get_method_table
def get_method_table
method_table = {
EFFECT_ADD_SHIELDS => :item_effect_add_shields
}
method_table
end
def item_effect_apply_ex(user, item, effect)
method_table = get_method_table
method_name = method_table[effect.code]
send(method_name, user, item, effect) if method_name
end
alias th_hp_shield_execute_damage execute_damage
def execute_damage(user)
if @shp > 0
on_damage(@result.hp_damage) if @result.hp_damage > 0
@shp -= @result.hp_damage
self.mp -= @result.mp_damage
user.hp += @result.hp_drain
user.mp += @result.mp_drain
else
th_hp_shield_execute_damage(user)
end
end
def eval_shield(formula, a, b, v=$game_variables, s=$game_switches)
eval(formula) rescue 0
end
# add shields!
def item_effect_add_shields(user, item, effect)
if @shp <= 0
value = eval_shield(effect.value1, user, self)
value = value.to_i
#@result.hp_damage -= value
@result.success = true
@mshp = value
@shp = value
end
end
end
class Game_Actor < Game_Battler
alias th_hp_shield_exec_floor_dmg execute_floor_damage
def execute_floor_damage
if self.shp > 0
damage = (basic_floor_damage * fdr).to_i
self.shp -= [damage, max_floor_damage].min if self.shp > 0
perform_map_damage_effect if damage > 0
else
th_hp_shield_exec_floor_dmg
end
end
end
class Window_Base < Window
alias th_hp_shield_simple_status draw_actor_simple_status
def draw_actor_simple_status(actor, x, y)
draw_actor_shp(actor, x + 120, y + line_height * 1 - 10)
th_hp_shield_simple_status(actor, x, y)
end
def draw_actor_hp(actor, x, y, width = 124)
draw_gauge(x, y, width, actor.hp_rate, hp_gauge_color1, hp_gauge_color2)
change_color(system_color)
draw_text(x, y, 30, line_height, Vocab::hp_a)
if actor.shp > 0
draw_current_and_max_values(x, y, width, actor.hp, actor.mhp, shp_color(actor), normal_color)
else
draw_current_and_max_values(x, y, width, actor.hp, actor.mhp, hp_color(actor), normal_color)
end
end
def draw_actor_shp(actor, x, y, width = 124)
draw_gauge(x, y, width, actor.shp_rate, shp_gauge_color1, shp_gauge_color2)
end
def shp_color(actor)
text_color(29)#29
end
def shp_gauge_color1
text_color(2)
end
def shp_gauge_color2
text_color(4)
end
end
class Window_BattleStatus < Window_Selectable
alias th_hp_shield_gauge_with_tp draw_gauge_area_with_tp
def draw_gauge_area_with_tp(rect, actor)
draw_actor_shp(actor, rect.x - 82, rect.y - 10, 72)
th_hp_shield_gauge_with_tp(rect, actor)
end
end