#===============================================================================
# ** Skills : Drain/Osmosis
#===============================================================================
Â
#-------------------------------------------------------------------------------
# * SDK Log
#-------------------------------------------------------------------------------
SDK.log('Skills.Drain/Osmosis', 'Kain Nobel', 2.0, '04.01.2009')
SDK.check_requirements(2.4, [1, 2])
#-------------------------------------------------------------------------------
# * SDK Enabled Test : Begin
#-------------------------------------------------------------------------------
if SDK.enabled?('Skills.Drain/Osmosis')
Â
#===============================================================================
# ** RPG::Skill
#===============================================================================
Â
class RPG::Skill
 #=============================================================================
 # ** RPG::Skill::Drain
 #=============================================================================
 module Drain
  #---------------------------------------------------------------------------
  # * HP Drain Element Tag ID (set inside Database/System tab).
  #---------------------------------------------------------------------------
  HP_Element_Tag = nil
  #---------------------------------------------------------------------------
  # * SP Drain Element Tag ID (set inside Database/System tab).
  #---------------------------------------------------------------------------
  SP_Element_Tag = nil
  #---------------------------------------------------------------------------
  # * Font Name for Drain Damage String.
  #---------------------------------------------------------------------------
  DamageFontName = "Arial Black"
  #---------------------------------------------------------------------------
  # * Font Size for Drain Damage String.
  #---------------------------------------------------------------------------
  DamageFontSize = 28
  #---------------------------------------------------------------------------
  # * Damage font for drain damage is bolded?
  #---------------------------------------------------------------------------
  DamageFontBold = false
  #---------------------------------------------------------------------------
  # * Damage font for drain damage is italicized?
  #---------------------------------------------------------------------------
  DamageFontItal = false
  #---------------------------------------------------------------------------
  # * Color for text outline displaying HP drain value.
  #---------------------------------------------------------------------------
  HP_ColorBack = Color.new(0, 160, 0)
  #---------------------------------------------------------------------------
  # * Color for main text color displaying HP drain value.
  #---------------------------------------------------------------------------
  HP_ColorMain = Color.new(0, 255, 0)
  #---------------------------------------------------------------------------
  # * Color for text outline displaying SP drain value.
  #---------------------------------------------------------------------------
  SP_ColorBack = Color.new(160, 0, 160)
  #---------------------------------------------------------------------------
  # * Color for main text color displaying SP drain value.
  #---------------------------------------------------------------------------
  SP_ColorMain = Color.new(255, 0, 255)
  #---------------------------------------------------------------------------
  # * Reformat the Damage String for draining HP   (ie "HP +[x]") [x] = value
  #---------------------------------------------------------------------------
  HP_DamageFormat = "HP +[x]"
  #---------------------------------------------------------------------------
  # * Reformat the Damage String for draining SP   (ie "HP +[x]") [x] = value
  #---------------------------------------------------------------------------
  SP_DamageFormat = "SP +[x]"
  #---------------------------------------------------------------------------
  # * Animation played to the reciever of drained HP/SP.    (skill_id => n)
  #---------------------------------------------------------------------------
  Animation  = {7 => 15}
  #---------------------------------------------------------------------------
  # * The percent to drain from damage inflicted on HP.    (skill_id => n)
  #---------------------------------------------------------------------------
  HP_Percent  = {7 => 100, 9 => 100}
  #---------------------------------------------------------------------------
  # * A direct value to drain from damage inflicted on HP.   (skill_id => n)
  #---------------------------------------------------------------------------
  HP_Direct  = {}
  #---------------------------------------------------------------------------
  # * Allowed variance to +/- from sub total HP drained.    (skill_id => n)
  #---------------------------------------------------------------------------
  HP_Variance = {}
  #---------------------------------------------------------------------------
  # * The percent to drain from damage inflicted on SP.    (skill_id => n)
  #---------------------------------------------------------------------------
  SP_Percent  = {}
  #---------------------------------------------------------------------------
  # * A direct value to drain from damage inflicted on SP.   (skill_id => n)
  #---------------------------------------------------------------------------
  SP_Direct   = {}
  #---------------------------------------------------------------------------
  # * Allowed variance to +/- from sub total SP drained.    (skill_id => n)
  #---------------------------------------------------------------------------
  SP_Variance = {}
  #---------------------------------------------------------------------------
  # * Critical Flag to be set when draining (this is an scripter thing...)
  #---------------------------------------------------------------------------
  Critical_Flag = "Drain/Osmosis"
  #---------------------------------------------------------------------------
  # * Default Settings (You might not want to modify these...)
  #---------------------------------------------------------------------------
  Animation.default  = 0
  HP_Percent.default  = 0
  HP_Direct.default  = 0
  HP_Variance.default = 0
  SP_Percent.default  = 0
  SP_Direct.default  = 0
  SP_Variance.default = 0
 end
 #-----------------------------------------------------------------------------
 # * Alias Listings
 #-----------------------------------------------------------------------------
 alias_method :drainskill_rpgskill_initialize, :initialize
 #-----------------------------------------------------------------------------
 # * Object Initialization
 #-----------------------------------------------------------------------------
 def initialize
  drainskill_rpgskill_initialize
  if self.drain_hp? && !@element_set.include?(Drain::HP_Element_Tag)
   unless Drain::HP_Element_Tag.nil?
    @element_set << Drain::HP_Element_Tag
   end
  end
  if self.drain_sp? && !@element_set.include?(Drain::SP_Element_Tag)
   unless Drain::SP_Element_Tag.nil?
    @element_set << Drain::SP_Element_Tag
   end
  end
 end
 #-----------------------------------------------------------------------------
 # * Drain Animation
 #-----------------------------------------------------------------------------
 def drain_animation
  return Drain::Animation[@id]
 end
 #-----------------------------------------------------------------------------
 # * HP Drain Percent
 #-----------------------------------------------------------------------------
 def hp_drain_percent
  return Drain::HP_Percent[@id]
 end
 #-----------------------------------------------------------------------------
 # * HP Drain Direct
 #-----------------------------------------------------------------------------
 def hp_drain_direct
  return Drain::HP_Direct[@id]
 end
 #-----------------------------------------------------------------------------
 # * HP Drain Variance
 #-----------------------------------------------------------------------------
 def hp_drain_variance
  return Drain::HP_Variance[@id]
 end
 #-----------------------------------------------------------------------------
 # * SP Drain Percent
 #-----------------------------------------------------------------------------
 def sp_drain_percent
  return Drain::SP_Percent[@id]
 end
 #-----------------------------------------------------------------------------
 # * SP Drain Direct
 #-----------------------------------------------------------------------------
 def sp_drain_direct
  return Drain::SP_Direct[@id]
 end
 #-----------------------------------------------------------------------------
 # * SP Drain Variance
 #-----------------------------------------------------------------------------
 def sp_drain_variance
  return Drain::SP_Variance[@id]
 end
 #-----------------------------------------------------------------------------
 # * HP Drain
 #-----------------------------------------------------------------------------
 def hp_drain(value)
  unless hp_drain_percent.zero?
   value *= hp_drain_percent / 100.0
  end
  value += hp_drain_direct
  value += rand(2).zero? ? -hp_drain_variance : hp_drain_variance
  return Integer(value)
 end
 #-----------------------------------------------------------------------------
 # * SP Drain
 #-----------------------------------------------------------------------------
 def sp_drain(value)
  unless sp_drain_percent.zero?
   value *= sp_drain_percent / 100.0
  end
  value += sp_drain_direct
  value += rand(2).zero? ? -sp_drain_variance : sp_drain_variance
  return Integer(value)
 end
 #-----------------------------------------------------------------------------
 # * Drain?
 #-----------------------------------------------------------------------------
 def drain?
  return (hp_drain? || sp_drain?)
 end
 #-----------------------------------------------------------------------------
 # * HP Drain?
 #-----------------------------------------------------------------------------
 def hp_drain?
  return (!hp_drain_percent.zero? || !hp_drain_direct.zero?)
 end
 #-----------------------------------------------------------------------------
 # * SP Drain?
 #-----------------------------------------------------------------------------
 def sp_drain?
  return (!sp_drain_percent.zero? || !sp_drain_direct.zero?)
 end
end
Â
#===============================================================================
# ** Game_BattleAction
#===============================================================================
Â
class Game_BattleAction
 #-----------------------------------------------------------------------------
 # * Public Instance Variables
 #-----------------------------------------------------------------------------
 attr_accessor :drain_hp
 attr_accessor :drain_sp
 #-----------------------------------------------------------------------------
 # * Alias Listings
 #-----------------------------------------------------------------------------
 alias_method :drainskill_gmbtlact_clear, :clear
 #-----------------------------------------------------------------------------
 # * Clear
 #-----------------------------------------------------------------------------
 def clear
  drainskill_gmbtlact_clear
  @drain_hp = 0
  @drain_sp = 0
 end
end
Â
#===============================================================================
# ** Game_Battler
#===============================================================================
Â
class Game_Battler
 #-----------------------------------------------------------------------------
 # * Public Instance Variables
 #-----------------------------------------------------------------------------
 attr_accessor :drain_animation
 #-----------------------------------------------------------------------------
 # * Alias Listings
 #-----------------------------------------------------------------------------
 alias_method :drainskill_gmbtlr_skilleffect, :skill_effect
 #-----------------------------------------------------------------------------
 # * Skill Effect
 #-----------------------------------------------------------------------------
 def skill_effect(user, skill)
  unless skill.drain?
   return drainskill_gmbtlr_skilleffect(user, skill)
  end
  old_hp, old_sp = self.hp, self.sp
  effective = drainskill_gmbtlr_skilleffect(user, skill)
  last_damage = self.damage
  self.damage = 0
  self.critical = [RPG::Skill::Drain::Critical_Flag, self.critical]
  hit, hit_result = skill_effect_first_hit_result(user, skill)
  effective = skill_effect_effective_correction(effective, hit)
  if hit_result
   power = skill_effect_power(user, skill)
   rate = skill_effect_rate(user, skill)
   skill_effect_base_damage(power, rate)
   skill_effect_element_correction(skill)
   if self.damage > 0
    skill_effect_guard_correction
   end
   skill_effect_disperation(skill)
   hit, hit_result = skill_effect_second_hit_result(user, skill)
   effective = skill_effect_effective_correction(effective, hit)
  end
  if hit_result
   effective = true if skill_effect_physical_hit_result(skill)
   last_sp = self.sp
   self.sp -= self.damage
   effective = self.sp != last_sp
   @state_changed = false
   effective |= states_plus(skill.plus_state_set)
   effective |= states_minus(skill.minus_state_set)
   skill_effect_power0(skill)
  else
   skill_effect_miss
  end
  skill_effect_damagefix
  hp_drain = skill.hp_drain(old_hp - self.hp)
  sp_drain = skill.sp_drain(old_sp - self.sp)
  user.hp += hp_drain
  user.sp += sp_drain
  self.damage  = last_damage
  user.critical = RPG::Skill::Drain::Critical_Flag
  user.current_action.drain_hp ||= 0
  user.current_action.drain_sp ||= 0
  user.current_action.drain_hp += hp_drain
  user.current_action.drain_sp += sp_drain
  user.damage = Array.new
  user.damage << user.current_action.drain_hp
  user.damage << user.current_action.drain_sp
  unless skill.drain_animation.zero? || skill.drain_animation.nil?
   user.drain_animation = skill.drain_animation
  end
  return effective
 end
end
Â
#===============================================================================
# ** Scene_Battle
#===============================================================================
Â
class Scene_Battle < SDK::Scene_Base
 #-----------------------------------------------------------------------------
 # * Alias Listings
 #-----------------------------------------------------------------------------
 alias_method :drainskill_scnbtl_updatep4s6,    :update_phase4_step6
 #-----------------------------------------------------------------------------
 # * Update Phase 4 : Step 6
 #-----------------------------------------------------------------------------
 def update_phase4_step6
  draining_battlers.each do |battler|
   battler.damage_pop = true
   unless battler.drain_animation == 0 || battler.drain_animation.nil?
    battler.animation_id = battler.drain_animation
    battler.animation_hit = true
    battler.drain_animation = nil
   end
  end
  drainskill_scnbtl_updatep4s6
 end
 #-----------------------------------------------------------------------------
 # * Draining Battlers
 #-----------------------------------------------------------------------------
 def draining_battlers
  battlers = Array.new
  $game_party.actors.each do |actor|
   if actor.current_action.drain_hp || actor.current_action.drain_sp
    battlers << actor
   end
  end
  $game_troop.enemies.each do |enemy|
   if enemy.current_action.drain_hp || enemy.current_action.drain_sp
    battlers << enemy
   end
  end
  battlers.each {|battler|
   battler.current_action.drain_hp = nil
   battler.current_action.drain_sp = nil
  }
  return battlers
 end
end
Â
#===============================================================================
# ** RPG::Sprite
#===============================================================================
Â
class RPG::Sprite < ::Sprite
 #-----------------------------------------------------------------------------
 # * Alias Listings
 #-----------------------------------------------------------------------------
 alias_method :drainskill_RPGsprite_damage, :damage
 #-----------------------------------------------------------------------------
 # * Damage
 #-----------------------------------------------------------------------------
 def damage(value, critical)
  unless value.is_a?(Array) || critical == RPG::Skill::Drain::Critical_Flag
   drainskill_RPGsprite_damage(value, critical)
   return
  end
  dispose_damage
  hp_drain = RPG::Skill::Drain::HP_DamageFormat.dup
  hp_drain.gsub!("[x]", "#{value[0]}")
  hp_drain.gsub!("+", "-") if value[0] < 0
  sp_drain = RPG::Skill::Drain::SP_DamageFormat.dup
  sp_drain.gsub!("[x]", "#{value[1]}")
  sp_drain.gsub!("+", "-") if value[1] < 0
  bitmap = Bitmap.new(160, 8 + (RPG::Skill::Drain::DamageFontSize * 2))
  bitmap.font.name   = RPG::Skill::Drain::DamageFontName
  bitmap.font.size   = RPG::Skill::Drain::DamageFontSize
  bitmap.font.bold   = RPG::Skill::Drain::DamageFontBold
  bitmap.font.italic  = RPG::Skill::Drain::DamageFontItal
  bitmap.font.color = RPG::Skill::Drain::HP_ColorBack
  bitmap.draw_text(-1, 12-1, 160, 40, hp_drain, 1)
  bitmap.draw_text(+1, 12-1, 160, 40, hp_drain, 1)
  bitmap.draw_text(-1, 12+1, 160, 40, hp_drain, 1)
  bitmap.draw_text(+1, 12+1, 160, 40, hp_drain, 1)
  bitmap.font.color = RPG::Skill::Drain::HP_ColorMain
  bitmap.draw_text(0, 12, 160, 40, hp_drain, 1)
  bitmap.font.color = RPG::Skill::Drain::SP_ColorBack
  y = bitmap.font.size + 2
  bitmap.draw_text(-1, y-1, 160, 40, sp_drain, 1)
  bitmap.draw_text(+1, y-1, 160, 40, sp_drain, 1)
  bitmap.draw_text(-1, y+1, 160, 40, sp_drain, 1)
  bitmap.draw_text(+1, y+1, 160, 40, sp_drain, 1)
  bitmap.font.color = RPG::Skill::Drain::SP_ColorMain
  bitmap.draw_text(0, y, 160, 40, sp_drain, 1)
  @_damage_sprite = ::Sprite.new(self.viewport)
  @_damage_sprite.bitmap = bitmap
  @_damage_sprite.ox = 80
  @_damage_sprite.oy = 20
  @_damage_sprite.x = self.x
  @_damage_sprite.y = self.y - self.oy / 2
  @_damage_sprite.z = 3000
  @_damage_duration = 40
 end
end
Â
#-------------------------------------------------------------------------------
# * SDK Enabled Test : End
#-------------------------------------------------------------------------------
end