=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 = false
EFFECT_ADD_SHIELDS = 50
Shield_Regex = /<shp:?\s*(.*)\s*>/i
Autoshield_Regex = /<autoshield:[ ]*(\d+)>/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
class EquippableItem < 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, $data_weapons, $data_armors]
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 self.shp > 0 && @result.hp_damage > 0
on_damage(@result.hp_damage) if @result.hp_damage > 0
self.hp -= @result.hp_damage - self.shp if @result.hp_damage > self.shp
self.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 self.shp <= 0
value = eval_shield(effect.value1, user, self)
value = value.to_i
/cdn-cgi/l/email-protection<script data-cfhash='f9e31' type="text/javascript">/* */</script>_damage -= value
@result.success = true
@mshp = value
self.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.shp, 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)
end
def shp_gauge_color1
text_color(-3)
end
def shp_gauge_color2
text_color(-3)
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 + 0, rect.y - 10, 72)
th_hp_shield_gauge_with_tp(rect, actor)
draw_actor_shp(actor, rect.x - 82, rect.y - 0, 72)#draw_actor_shp(actor, rect.x + 0, rect.y - 10, 72)
end
end
# modifiche richieste
module BattleManager
class << self
alias hps_battle_end battle_end
alias hps_battle_start battle_start
end
def self.battle_end(result)
hps_battle_end(result)
for actor in $game_party.all_members
next if actor.nil?
actor.shp = 0
actor.mshp = 0
end
end
def self.battle_start
hps_battle_start
for member in $game_party.battle_members
member.shp += member.autostart_shield_bonus
end
member.mshp = member.shp
end
end
class Game_BattlerBase
def shp; @shp ||= 0; end
def shp=(value); @shp = value; end
def mshp; @mshp ||= 0; end
def mshp=(value); @mshp = value; end
end
class Window_Base < Window
alias hps_draw_actor_shp draw_actor_shp unless $@
def draw_actor_shp(actor, x, y, width = 124)
return if actor.shp <= 0
hps_draw_actor_shp(actor, x, y, width)
end
end
module RPG
class EquipItem < BaseItem
attr_reader :autoshield_bonus
include Tsuki::HP_Shield
def load_notetags_hp_shield
return if @autoshield_loaded
@autoshield_loaded = true
@autoshield_bonus = 0
self.note.split(/[\r\n]+/).each { |riga|
if riga =~ Autoshield_Regex
@autoshield_bonus = $1.to_i
end
}
end
def autoshield_bonus
unless @autoshield_bonus
load_notetags_hp_shield
end
@autoshield_bonus
end
end
end
class Game_Actor < Game_Battler
def autostart_shield_bonus
shield = 0
for equip in equips
next if equip.nil?
shield += equip.autoshield_bonus
end
shield
end
end