#==============================================================================
# ** Regeneration
#------------------------------------------------------------------------------
#  © Dargor, 2008
# Â 04/11/08
# Â Version 1.0
# Â Requested by shc0023
#------------------------------------------------------------------------------
# Â VERSION HISTORY:
# Â - 1.0 (01/11/08), Initial release
#------------------------------------------------------------------------------
# Â INTRODUCTION:
# Â Â This script will let actors regenerate HP/MP in 3 occasions.
# Â Â Regeneration can occur on map, when defending or at the end of
# Â Â a battle. This system is highly customizable. You can specify any
# Â Â regeneration formula you want, for any actors in any of the 3
# Â Â occasions!
#------------------------------------------------------------------------------
# Â INSTRUCTIONS:
# Â 1) Paste the script above main
# Â 2) Edit the constants in the Regeneration module
#==============================================================================
Â
#==============================================================================
# Â ** Regeneration Configuration Module
#==============================================================================
Â
module Regeneration
 # Regenerate after battles?
 Battle_Regen = false
 # Defense Regen
 Defense_Regen = false
 # Regenerate on map?
 Map_Regen = true
 # On Map Regeneration delay (in frames)
 Map_Regen_Delay = 240
 # End battle results allowed (0: Victory, 1: Escape, 2: Defeated)
 Battle_End = [0]
 # States that prevents from regenerating after battles
 NoRegen_States = [1]
 # Play recovery SE on map?
 Map_Recovery_SE = true
 # Super Guard Regeneration Multiplier
 Super_Guard_Multiplier = 3
 # Battle Regeneration rate formula for HP/MP
 # SYNTAX: {actor_id => "formula"}
 Battle_HP_Formulas = {}
 Battle_MP_Formulas = {}
 # Default formula if none specified
 Battle_HP_Formulas.default = "(self.maxhp / 100) * 6" # 6% of maxhp
 Battle_MP_Formulas.default = "(self.maxmp / 100) * 3" # 3% of maxmp
 # Defense Regeneration rate formula for HP/MP
 # SYNTAX: {actor_id => "formula"}
 Defense_HP_Formulas = {}
 Defense_MP_Formulas = {}
 # Default formula if none specified
 Defense_HP_Formulas.default = "(self.maxhp / 100) * 2" # 2% of maxhp
 Defense_MP_Formulas.default = "(self.maxmp / 100) * 1" # 1% of maxmp
 # Map Regeneration rate formula for HP/MP
 # SYNTAX: {actor_id => "formula"}
 Map_HP_Formulas = {}
 Map_MP_Formulas = {}
 # Default formula if none specified
 Map_HP_Formulas.default = "(self.maxhp / 100) * 2" # 2% of maxhp
 Map_MP_Formulas.default = "(self.maxmp / 100) * 1" # 1% of maxmp
end
Â
#==============================================================================
# ** Game_System
#------------------------------------------------------------------------------
# Â This class handles system-related data. Also manages vehicles and BGM, etc.
# The instance of this class is referenced by $game_system.
#==============================================================================
Â
class Game_System
 #--------------------------------------------------------------------------
 # * Public Instance Variables
 #--------------------------------------------------------------------------
 attr_accessor  :map_regen
 attr_accessor  :battle_regen
 attr_accessor  :defense_regen
 #--------------------------------------------------------------------------
 # * Alias Listing
 #--------------------------------------------------------------------------
 alias dargor_vx_battle_regen_system_initialize initialize
 #--------------------------------------------------------------------------
 # * Object Initialization
 #--------------------------------------------------------------------------
 def initialize
  # The usual
  dargor_vx_battle_regen_system_initialize
  # Map/Battle Regeneration flags
  @battle_regen = Regeneration::Battle_Regen
  @defense_regen = Regeneration::Defense_Regen
  @map_regen = Regeneration::Map_Regen
 end
end
Â
#==============================================================================
# ** Game_Actor
#------------------------------------------------------------------------------
# Â This class handles actors. It's used within the Game_Actors class
# ($game_actors) and referenced by the Game_Party class ($game_party).
#==============================================================================
Â
class Game_Actor < Game_Battler
Â
 #--------------------------------------------------------------------------
 # * Get Map HP/MP Regeneration Formulas
 #--------------------------------------------------------------------------
 def map_regen_formulas
  hp_formula = nil
  mp_formula = nil
  # Get actor's map hp regen formula
  if Regeneration::Map_HP_Formulas[@actor_id].nil?
   hp_formula = eval(Regeneration::Map_HP_Formulas.default)
  else
   hp_formula = eval(Regeneration::Map_HP_Formulas[@actor_id])
  end
  # Get actor's map mp regen formula
  if Regeneration::Map_MP_Formulas[@actor_id].nil?
   mp_formula = eval(Regeneration::Map_MP_Formulas.default)
  else
   mp_formula = eval(Regeneration::Map_MP_Formulas[@actor_id])
  end
  hp_formula = 1 if hp_formula == 0
  mp_formula = 1 if mp_formula == 0
  return [hp_formula, mp_formula]
 end
 #--------------------------------------------------------------------------
 # * Regenerate on Map
 #--------------------------------------------------------------------------
 def map_regenerate
  # Check if map regeneration is allowed
  if $game_system.map_regen
   # Make sure the actor is not in a NoRegen state
   for state_id in Regeneration::NoRegen_States
    if state?(state_id)
     # Do not regenerate
     return
    end
   end
   # Regenerate
   self.hp += map_regen_formulas[0]
   self.mp += map_regen_formulas[1]
   $scene = scene_map.new
  end
 end
 #--------------------------------------------------------------------------
 # * Get defense HP/MP Regeneration Formulas
 #--------------------------------------------------------------------------
 def defense_regen_formulas
  hp_formula = nil
  mp_formula = nil
  # Get actor's battle hp regen formula
  if Regeneration::Defense_HP_Formulas[@actor_id].nil?
   hp_formula = eval(Regeneration::Defense_HP_Formulas.default)
  else
   hp_formula = eval(Regeneration::Defense_HP_Formulas[@actor_id])
  end
  # Get actor's battle mp regen formula
  if Regeneration::Defense_HP_Formulas[@actor_id].nil?
   mp_formula = eval(Regeneration::Defense_MP_Formulas.default)
  else
   mp_formula = eval(Regeneration::Defense_MP_Formulas[@actor_id])
  end
  hp_formula = 1 if hp_formula == 0
  mp_formula = 1 if mp_formula == 0
  if super_guard
   hp_formula *= Regeneration::Super_Guard_Multiplier
   mp_formula *= Regeneration::Super_Guard_Multiplier
  end
  return [hp_formula, mp_formula]
 end
 #--------------------------------------------------------------------------
 # * Regenerate After Battles
 #--------------------------------------------------------------------------
 def defense_regenerate
  # Check if battle regeneration la allowed
  if $game_system.defense_regen
   # Make sure the actor is not in a NoRegen state
   for state_id in Regeneration::NoRegen_States
    if state?(state_id)
     # Do not regenerate
     return
    end
   end
   end
  @hp_damage = -defense_regen_formulas[0]
  @mp_damage = -defense_regen_formulas[1]
  self.hp -= @hp_damage
  self.mp -= @mp_damage
 end
 #--------------------------------------------------------------------------
 # * Get Battle HP/MP Regeneration Formulas
 #--------------------------------------------------------------------------
 def battle_regen_formulas
  hp_formula = nil
  mp_formula = nil
  # Get actor's battle hp regen formula
  if Regeneration::Battle_HP_Formulas[@actor_id].nil?
   hp_formula = eval(Regeneration::Battle_HP_Formulas.default)
  else
   hp_formula = eval(Regeneration::Battle_HP_Formulas[@actor_id])
  end
  # Get actor's battle mp regen formula
  if Regeneration::Battle_MP_Formulas[@actor_id].nil?
   mp_formula = eval(Regeneration::Battle_MP_Formulas.default)
  else
   mp_formula = eval(Regeneration::Battle_MP_Formulas[@actor_id])
  end
  hp_formula = 1 if hp_formula == 0
  mp_formula = 1 if mp_formula == 0
  return [hp_formula, mp_formula]
 end
 #--------------------------------------------------------------------------
 # * Regenerate After Battles
 #--------------------------------------------------------------------------
 def battle_regenerate
  # Check if battle regeneration is allowed
  if $game_system.battle_regen
   # Make sure the actor is not in a NoRegen state
   for state_id in Regeneration::NoRegen_States
    if state?(state_id)
     # Do not regenerate
     return
    end
   end
  end
  @hp_damage = -battle_regen_formulas[0]
  @mp_damage = -battle_regen_formulas[1]
  self.hp -= @hp_damage
  self.mp -= @mp_damage
 end
end
Â
#==============================================================================
# ** Game_Party
#------------------------------------------------------------------------------
# Â This class handles the party. It includes information on amount of gold
# and items. The instance of this class is referenced by $game_party.
#==============================================================================
Â
class Game_Party
 #--------------------------------------------------------------------------
 # * Regenerate Party
 #--------------------------------------------------------------------------
 def regenerate
  if Graphics.frame_count % Regeneration::Map_Regen_Delay == 0
   for member in members
    total_hp = member.hp
    total_maxhp = member.maxhp
    member.map_regenerate
   end
   Sound.play_recovery unless total_hp == total_maxhp or !Regeneration::Map_Recovery_SE
  end
 end
end
Â
#==============================================================================
# ** Game_Player
#------------------------------------------------------------------------------
# Â This class handles maps. It includes event starting determinants and map
# scrolling functions. The instance of this class is referenced by $game_map.
#==============================================================================
Â
class Game_Player < Game_Character
 #--------------------------------------------------------------------------
 # * Alias Listing
 #--------------------------------------------------------------------------
 alias dargor_vx_battle_regen_player_update update
 #--------------------------------------------------------------------------
 # * Frame Update
 #--------------------------------------------------------------------------
 def update
  # If player is free to move
  if movable?
   # Regenerate
   $game_party.regenerate
  end
  # The Usual
  dargor_vx_battle_regen_player_update
 end
end
 Â
#==============================================================================
# ** Scene_Battle
#------------------------------------------------------------------------------
# Â This class performs battle screen processing.
#==============================================================================
Â
class Scene_Battle < Scene_Base
 #--------------------------------------------------------------------------
 # * Alias Listing
 #--------------------------------------------------------------------------
 alias dargor_vx_battle_regen_battle_end battle_end
 alias dargor_vx_battle_regen_execute_action_guard execute_action_guard
 #-----------------------------------------------------------------------------
 # Execute Action_Guard
 #-----------------------------------------------------------------------------
 def execute_action_guard
  # The Usual
  dargor_vx_battle_regen_execute_action_guard
  if $game_system.defense_regen
   # Regenerate actor
   @active_battler.defense_regenerate
   # Display regeneration text
   display_hp_damage(@active_battler)
   wait(45)
   @message_window.back_one
   display_mp_damage(@active_battler)
   wait(45)
   @message_window.clear
  end
 end
 #--------------------------------------------------------------------------
 # * End Battle
 #   result : Results (0: win, 1: escape, 2:lose)
 #--------------------------------------------------------------------------
 def battle_end(result)
  # If regenerating is allowed with this battle end result
  if Regeneration::Battle_End.include?(result)
   for member in $game_party.members
    # Regenerate actor
    member.battle_regenerate
    # Display regeneration text
    Sound.play_recovery
    display_hp_regeneration(member)
    display_mp_regeneration(member)
    wait_for_message
    @message_window.clear
   end
  end
  # The usual
  dargor_vx_battle_regen_battle_end(result)
 end
 #--------------------------------------------------------------------------
 # * Show HP Regeneration
 #   target : Target
 #   obj   : Skill or item
 #--------------------------------------------------------------------------
 def display_hp_regeneration(target)
  if target.hp_damage == 0         # No damage
   fmt = target.actor? ? Vocab::ActorNoDamage : Vocab::EnemyNoDamage
   text = sprintf(fmt, target.name)
  elsif target.absorbed          # Absorb
   fmt = target.actor? ? Vocab::ActorDrain : Vocab::EnemyDrain
   text = sprintf(fmt, target.name, Vocab::hp, target.hp_damage)
  elsif target.hp_damage > 0        # Damage
   if target.actor?
    text = sprintf(Vocab::ActorDamage, target.name, target.hp_damage)
    Sound.play_actor_damage
    $game_troop.screen.start_shake(5, 5, 10)
   else
    text = sprintf(Vocab::EnemyDamage, target.name, target.hp_damage)
    Sound.play_enemy_damage
    target.blink = true
   end
  else                   # Recovery
   fmt = target.actor? ? Vocab::ActorRecovery : Vocab::EnemyRecovery
   text = sprintf(fmt, target.name, Vocab::hp, -target.hp_damage)
  end
  $game_message.texts.push(text)
 end
 #--------------------------------------------------------------------------
 # * Show MP Regeneration
 #   target : Target
 #   obj   : Skill or item
 #--------------------------------------------------------------------------
 def display_mp_regeneration(target)
  return if target.dead?
  return if target.mp_damage == 0
  if target.absorbed            # Absorb
   fmt = target.actor? ? Vocab::ActorDrain : Vocab::EnemyDrain
   text = sprintf(fmt, target.name, Vocab::mp, target.mp_damage)
  elsif target.mp_damage > 0        # Damage
   fmt = target.actor? ? Vocab::ActorLoss : Vocab::EnemyLoss
   text = sprintf(fmt, target.name, Vocab::mp, target.mp_damage)
  else                   # Recovery
   fmt = target.actor? ? Vocab::ActorRecovery : Vocab::EnemyRecovery
   text = sprintf(fmt, target.name, Vocab::mp, -target.mp_damage)
  end
  $game_message.texts.push(text)
 end
end