#==============================================================================
# ** Damage Pop VX
#------------------------------------------------------------------------------
#Â Â by DerVVulfman
#Â Â version 3.1
#Â Â 05-20-2008
#Â Â RGSS2
#==============================================================================
#
#Â INTRODUCTION:
#
#Â This script is a script that reintroduces the classic 'pop-up' display for
#Â damage results. Unlike the original RPGMaker XP system, this also displays
#Â a damage pop for MP (Mana Point) damage, absorbtion and recovery.
#
#------------------------------------------------------------------------------
#
#Â THE CONFIGURABLES:
#
# There are five basic sections in this script's configuration section:
#Â Fonts, Text, Color, Style and Default settings.
#
#Â Fonts
#Â =====
# This section controls the lettering style of the damage pop-up. You can
# set the name of the font, the size of the regular damage on the screen,
#Â the size of the 'Critical Hit' message that appears, whether the text is
# shown in boldface print or if it is italicized. That's really it.
#
#Â Text
#Â =====
#Â In this section, you set the text that appears for messages like 'Miss',
# 'Critical!' and the like. It kinda helps to have it in a configuration
#Â section than having it hardwired like some other scripts. It also allows
#Â you to insert and change the prefix for any health or mana hits applied.
#
#Â Color
#Â =====
# This section allows you to define the color of the damage pop-ups that
# are shown with this script. They are created through the classic r/g/b
# style of the Color.new command. You have six color sequences you have
# to work with: Regular, Recovery, Absorb, MP Damage, MP Recovery and
#Â MP Absorb.
#
#Â Style
#Â =====
# This section controls the way the damage pop-up is displayed. The names
# of these editable values are a little harder to understand, so I will
#Â present you a list of each one and their purpose:
#
# DAMAGE_DBLBOUNCE: This is a true/false switch. If you have it set to
#Â Â Â Â Â Â Â Â Â Â true, the damage popup can permit the popup to bounce
#Â Â Â Â Â Â Â Â Â Â twice rather than once like RMXP's default system. It
#          is dependant on the value held in 'DAMAGE_POP_DIR_Y'
#Â Â Â Â Â Â Â Â Â Â for how high the pop-up bounces.
#
#Â DAMAGE_POP_DELAY:Â This gauges how long (in frames)Â that the damage pop
#          up is shown on the screen. A moderate value of '60'
#          would keep the popup on the screen for one second.
#          You must have a value of 10 or higher. Values below
#Â Â Â Â Â Â Â Â Â Â 10 will result in an error.
#
# DAMAGE_POP_DIR_X: This determines the direction and speed the damage
#          pop will move on the screen. Any positive value here
#          will move the popup to the right and any negative
#          value here will move the popup to the left. The lar-
#          ger the value, the more the value will shift. And a
#          value of '0' will just keep the pop-up from moving.
#          However... If the value is set to 'nil', the damage
#Â Â Â Â Â Â Â Â Â Â pop will randomly move to the left or right.
#Â Â Â Â Â Â Â Â Â Â
#Â DAMAGE_POP_DIR_Y:Â Like DAMAGE_POP_DIR_X, this determines the direction
#          and speed the pop will move on the screen... but in
#          vertical direction.  Positive values make the pop-
#          up raise and then drop in a bouncing manner, while
#          negative values lower and then raise the popup in a
#          sweeping wave pattern. The larger the value, the
#          more the value will shift. And if you have the
#          DAMAGE_DBLBOUNCE value set to true, then the damage
#Â Â Â Â Â Â Â Â Â Â pop will bounce 'twice' based on this set value.
#Â
#Â Default
#Â =======
#Â This final section controls the placement of the damage pop-ups for your
# actors if you do not use any system to add 'actor battler' graphics. In
# cases where you have actor battlers, these values are overwritten. But
#Â if this system is being used alone, this positions where the damage pops
# will show on the screen. The following describes the last three values:
#
# DAMAGE_POP_CENTER: This value is a true/false value that sets whether
#           the battlers line up from the left and space them-
#           selves out in the manner of the default RPGMaker XP
#           or whether the system calculates and centers them
#Â Â Â Â Â Â Â Â Â Â Â across the screen.
#
#Â DAMAGE_POP_PARTY:Â This value establishes how many actors are typically
#           shown in the battlefield. While this is the default
#           value, the maximum value used can be changed with a
#Â Â Â Â Â Â Â Â Â Â Â script call.
#
#Â DAMAGE_POP_Y_POS:Â Finally, the vertical up/down position of the popups
#Â Â Â Â Â Â Â Â Â Â Â can be adjusted by changing the value of this value.
#
#
#------------------------------------------------------------------------------
#
#Â SCRIPT CALLS:
#
#Â There's only one script call that you need to know:
#
# cases where you have actor battlers, these values are overwritten. But
#Â This script lets you have the damage popups spaced out evenly across the
# screen. Under most circumstances, you have four members in your party,
# but this allows you to permit it to space the popups evenly if you have
#Â 5, 6 or even 10 battlers in your battleparty.
#
#Â Now, this system does not increase the number of members in your party,
#Â but it is already set up to adjust the spacing of your members in the
# battlefield. With a simple script call:
#
#Â Â Â Â Â $game_system.dpop_party_max = 7
#
#Â You can make the system space the battlers on the field with the under-
#Â standing that up to 7 members are in the party.
#
#------------------------------------------------------------------------------
#
#Â SCRIPT PLACEMENT:
#
#Â As a core/re-insertion script, it returns the ability to use damage pops
#Â that many users became used to with other RPG gaming systems. Also, this
#Â core script approximates the position of 'actor' battlers if there isn't
#Â another script in use to create visible 'actor' battlers.
#
#Â If this script is being used with any other script that positions and/or
# creates 'actor' battlers, then those scripts will most likely be placed
#Â BELOW 'Damage Pop VX' as they will most likely create their own screen_x
#Â and screen_y methods for Game_Actor.
#
#------------------------------------------------------------------------------
#
#Â EDITS AND MODIFICATIONS:
#Â
#Â This system Aliases the following methods:
# * initialize          (Game_System)
# * clear_sprite_effects     (Game_Battler)
# * initialize          (Sprite_Base)
# * update            (Sprite_Base)
# * setup_new_effect       (Sprite_Battler)
# * display_hp_damage       (Scene_Battle)
# * display_mp_damage       (Scene_Battle)
# * display_evasion        (Scene_Battle)
# * display_miss         (Scene_Battle)
#
#Â This system redefines the following methods:
# * use_sprite?          (Game_Actor)
#
#Â This system adds the following methods:
# * use_sprite?          (Game_Actor)
# * screen_x           (Game_Actor)
# * screen_y           (Game_Actor)
# * screen_z           (Game_Actor)
# * damage            (Sprite_Base)
# * dispose_damage        (Sprite_Base)
#
#------------------------------------------------------------------------------
#
#Â THANKS:
#
# To my old pal, Syvkal, for reminding me that RPGMaker XP's basic DAMAGE
#Â system was built into it's Sprite class. It made it easier to implement.
#
#------------------------------------------------------------------------------
#
#Â TERMS AND CONDITIONS:
#
# Free to use, even in commercial projects. Just note that I'll need some
# form of due credit for myself and anyone else involved in this script's
#Â creation... even a mere mention in some end titles.
#
#==============================================================================
 #========================================================================
 # ** C O N F I G U R A T I O N   S Y S T E M ** #
 #========================================================================Â
Â
 # ---Font Settings---
 #Â
 DAMAGE_POP_FONT = "Times New Roman" # Name of font used
 DAMAGE_POP_SIZE = 32         # Size of font used
 DAMAGE_POP_SIZE2 = 36         # Size of critical font
 DAMAGE_POP_BOLD = false       # If bold text used
 DAMAGE_POP_ITALIC = true        # If italicized text used
 Â
 # ---Text Settings---
 #Â
 DAMAGE_POP_CRIT = "Critical!"    # Text shown for critical hits
 DAMAGE_POP_MISS = "Miss"       # Text shown for misses
 DAMAGE_POP_FAILED = "Failed"      # Text shown for failed attacks
 DAMAGE_POP_EVADED = "Evaded"      # Text shown for evaded attacks
 DAMAGE_HP_STRING = nil        # Text suffix for HP Damage
 DAMAGE_MP_STRING = "MP"        # Text suffix for MP Damage
Â
 # ---Color Settings---
 #Â
 DAMAGE_POP_COLOR1 = Color.new(255, 255, 255) # HP Damage   (White)
 DAMAGE_POP_COLOR2 = Color.new(127, 255, 127) # HP Recovery  (Med Green)
 DAMAGE_POP_COLOR3 = Color.new(196, 0, 0) # HP Absorb   (Dk Red)
 DAMAGE_POP_COLOR4 = Color.new( 0, 196, 255) # MP Damage   (Lt Blue)
 DAMAGE_POP_COLOR5 = Color.new(255, 255, 96) # MP Recovery  (Yellow)
 DAMAGE_POP_COLOR6 = Color.new(255, 156, 55) # MP Absorb   (Orange)
Â
Â
 # ---Style Settings---
 #Â
 DAMAGE_DBLBOUNCE = false # If doublebounce feature is on
 DAMAGE_POP_DELAY = 50  # Duration of Pop (mist be 10 or higher)
 DAMAGE_POP_DIR_X = nil # Horizontal direction for pop (or nil for random)
 DAMAGE_POP_DIR_Y = 1  # Vertical direction & incrementation for pop
Â
 # --Default Position--
 #
 DAMAGE_POP_CENTER = true  # If true, assumes battler pops are centered
 DAMAGE_POP_PARTY = 4   # Default party Max
 DAMAGE_POP_Y_POS = 280  # Vertical position of party's damage pop Â
Â
Â
Â
Â
#==============================================================================
# ** 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 :dpop_party_max    # Max. size for centered battlers
 #--------------------------------------------------------------------------
 # * Alias Listings
 #--------------------------------------------------------------------------Â
 alias dpop_initialize initialize
 #--------------------------------------------------------------------------
 # * Object Initialization
 #--------------------------------------------------------------------------
 def initialize
  # Perform the original call
  dpop_initialize
  # Set 'Centered' battler max to 4 (default)
  @dpop_party_max = DAMAGE_POP_PARTY
 end
end
#==============================================================================
# ** Game_Battler
#------------------------------------------------------------------------------
#Â This class deals with battlers. It's used as a superclass of the Game_Actor
# and Game_Enemy classes.
#==============================================================================
class Game_Battler
 #--------------------------------------------------------------------------
 # * Alias Listings
 #--------------------------------------------------------------------------Â
 alias dpop_clear_sprite_effects clear_sprite_effects
 #--------------------------------------------------------------------------
 # * Public Instance Variables
 #--------------------------------------------------------------------------
 attr_accessor :damage         # damage popup value
 attr_accessor :damage_type      # damage popup type
 #--------------------------------------------------------------------------
 # * Clear Variable Used for Sprite Communication
 #--------------------------------------------------------------------------
 def clear_sprite_effects
  # Perform the original call
  dpop_clear_sprite_effects
  # Clear damage pop
  @damage = 0
 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
 #--------------------------------------------------------------------------
 # * Public Instance Variables
 #--------------------------------------------------------------------------Â
 attr_accessor :screen_x        # battle screen X coordinate
 attr_accessor :screen_y        # battle screen Y coordinate
 #--------------------------------------------------------------------------
 # * Use Sprites?
 #--------------------------------------------------------------------------
 def use_sprite?
  return true
 endÂ
 #--------------------------------------------------------------------------
 # * Get Battle Screen X-Coordinate
 #--------------------------------------------------------------------------
 def screen_x
  if self.index != nil
   if DAMAGE_POP_CENTER
    # Return after calculating x-coords of centered party members
    return self.index * (544 / $game_system.dpop_party_max) +
       ($game_system.dpop_party_max - $game_party.members.size) *
       (272 / $game_system.dpop_party_max) +
       (272 / $game_system.dpop_party_max)
   else
    # Return after calculating x-coords of default-aligned party members
    return self.index * 136 + 68
   end
  else
   return 0
  end
 end
 #--------------------------------------------------------------------------
 # * Get Battle Screen Y-Coordinate
 #--------------------------------------------------------------------------
 def screen_y
  return DAMAGE_POP_Y_POS
 endÂ
 #--------------------------------------------------------------------------
 # * Get Battle Screen Z-Coordinate
 #--------------------------------------------------------------------------
 def screen_z
  # Return after calculating z-coordinate by order of members in party
  if self.index != nil
   return $game_party.members.size - self.index
  else
   return 0
  end
 end
end
Â
Â
#==============================================================================
# ** Sprite_Base
#------------------------------------------------------------------------------
#Â A sprite class with animation display processing added.
#==============================================================================
class Sprite_Base < Sprite
 #--------------------------------------------------------------------------
 # * Alias Listings
 #--------------------------------------------------------------------------
 alias dpop_initialize initialize
 alias dpop_update update
 #--------------------------------------------------------------------------
 # * Object Initialization
 #  viewport : viewport
 #--------------------------------------------------------------------------
 def initialize(viewport = nil)
  dpop_initialize(viewport) # Perform the original call
  @_damage_duration = 0   # Remaining damage pop time
 end
 #--------------------------------------------------------------------------
 # * Frame Update
 #--------------------------------------------------------------------------Â
 def update
  # Perform the original call
  dpop_update
  # Obtain delay percentages
  p1 = DAMAGE_POP_DELAY
  if DAMAGE_DBLBOUNCE
   p2 = (DAMAGE_POP_DELAY * 8) / 10
   p3 = (DAMAGE_POP_DELAY * 7) / 10
   p4 = (DAMAGE_POP_DELAY * 6) / 10
   p5 = (DAMAGE_POP_DELAY * 5) / 10
   p6 = (DAMAGE_POP_DELAY * 4) / 10
   p7 = (DAMAGE_POP_DELAY * 3) / 10
   p8 = (DAMAGE_POP_DELAY * 2) / 10
   p9 = (DAMAGE_POP_DELAY * 1) / 10 Â
  else
   p2 = (DAMAGE_POP_DELAY * 8) / 10
   p3 = (DAMAGE_POP_DELAY * 7) / 10
   p4 = (DAMAGE_POP_DELAY * 6) / 10
   p5 = (DAMAGE_POP_DELAY * 5) / 10
  end
  if @_damage_duration > 0
   @_damage_duration -= 1
   @_damage_sprite.x += @_damage_x
   if DAMAGE_DBLBOUNCE
    case @_damage_duration
    when p2..p1
     @_damage_sprite.y -= DAMAGE_POP_DIR_Y * 2
    when p3..p2
     @_damage_sprite.y -= DAMAGE_POP_DIR_Y
    when p4..p3
     @_damage_sprite.y += DAMAGE_POP_DIR_Y
    when p5..p4
     @_damage_sprite.y += DAMAGE_POP_DIR_Y * 4
    when p6..p5
     @_damage_sprite.y -= DAMAGE_POP_DIR_Y
    when p7..p6
     @_damage_sprite.y -= DAMAGE_POP_DIR_Y
    when p8..p7
     @_damage_sprite.y += DAMAGE_POP_DIR_Y * 2
    when p9..p8
     @_damage_sprite.y += DAMAGE_POP_DIR_Y * 4   Â
    end
   else
    case @_damage_duration
    when p2..p1
     @_damage_sprite.y -= DAMAGE_POP_DIR_Y * 2
    when p3..p2
     @_damage_sprite.y -= DAMAGE_POP_DIR_Y
    when p4..p3
     @_damage_sprite.y += DAMAGE_POP_DIR_Y
    when p5..p4
     @_damage_sprite.y += DAMAGE_POP_DIR_Y * 2
    end
   end
   @_damage_sprite.opacity = 256 - (12 - @_damage_duration) * 32
   if @_damage_duration == 0
    dispose_damage
   end
  end
 end
 #--------------------------------------------------------------------------
 # * Damage
 #  value : damage value
 #--------------------------------------------------------------------------
 def damage(value, critical, type)
  dispose_damage
  if value.is_a?(Numeric)
   damage_string = value.abs.to_s
  else
   damage_string = value.to_s
  end
  bitmap = Bitmap.new(160, 48)
  bitmap.font.name = DAMAGE_POP_FONT
  bitmap.font.size = DAMAGE_POP_SIZE
  bitmap.font.bold = DAMAGE_POP_BOLD
  bitmap.font.italic = DAMAGE_POP_ITALIC
  bitmap.font.color.set(0, 0, 0)
  # Apply Regular Damage Text
  bitmap.draw_text(-1, 12-1, 160, 36, damage_string, 1)
  bitmap.draw_text(+1, 12-1, 160, 36, damage_string, 1)
  bitmap.draw_text(-1, 12+1, 160, 36, damage_string, 1)
  bitmap.draw_text(+1, 12+1, 160, 36, damage_string, 1)
  # Apply Critical Text
  if critical
   bitmap.font.size = DAMAGE_POP_SIZE2
   bitmap.draw_text(-1, -1, 160, 20, DAMAGE_POP_CRIT, 1)
   bitmap.draw_text(+1, -1, 160, 20, DAMAGE_POP_CRIT, 1)
   bitmap.draw_text(-1, +1, 160, 20, DAMAGE_POP_CRIT, 1)
   bitmap.draw_text(+1, +1, 160, 20, DAMAGE_POP_CRIT, 1)
  end Â
  # Set Color SchemeÂ
  case type
   when 1; bitmap.font.color = DAMAGE_POP_COLOR4
   when 2; bitmap.font.color = DAMAGE_POP_COLOR2
   when 3; bitmap.font.color = DAMAGE_POP_COLOR3
   when 4; bitmap.font.color = DAMAGE_POP_COLOR5
   when 5; bitmap.font.color = DAMAGE_POP_COLOR6
   else; bitmap.font.color = DAMAGE_POP_COLOR1
  endÂ
  # Reset basic sizeÂ
  bitmap.font.size = DAMAGE_POP_SIZEÂ
  bitmap.draw_text(0, 12, 160, 36, damage_string, 1)
  # Draw Critical Text
  if critical
   bitmap.font.size = DAMAGE_POP_SIZE2
   bitmap.draw_text(0, 0, 160, 20, DAMAGE_POP_CRIT, 1)
  end Â
  @_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 = DAMAGE_POP_DELAY
  if DAMAGE_POP_DIR_X == nil
   @_damage_x = rand(3) - 1
  else
   @_damage_x = DAMAGE_POP_DIR_X
  end Â
 end
 #--------------------------------------------------------------------------
 # * Dispose of Damage
 #-------------------------------------------------------------------------- Â
 def dispose_damage
  if @_damage_sprite != nil
   @_damage_sprite.bitmap.dispose
   @_damage_sprite.dispose
   @_damage_sprite = nil
   @_damage_duration = 0
  end
 end
end
#==============================================================================
# ** Sprite_Battler
#------------------------------------------------------------------------------
#Â This sprite is used to display battlers. It observes a instance of the
# Game_Battler class and automatically changes sprite conditions.
#==============================================================================
class Sprite_Battler < Sprite_Base
 #--------------------------------------------------------------------------
 # * Constants
 #--------------------------------------------------------------------------
 DAMAGE = 7
 #--------------------------------------------------------------------------
 # * Alias Listings
 #--------------------------------------------------------------------------
 alias dpop_setup_new_effect setup_new_effect
 #--------------------------------------------------------------------------
 # * Set New Effect
 #--------------------------------------------------------------------------Â
 def setup_new_effect
  # Adding damage pop effect
  if @battler.damage != 0
   damage(@battler.damage, @battler.critical, @battler.damage_type)
   @effect_type = DAMAGE
   @battler.damage = 0
  end
  # Perform the original call
  dpop_setup_new_effect Â
 end
end
#==============================================================================
# ** Scene_Battle
#------------------------------------------------------------------------------
#Â This class performs battle screen processing.
#==============================================================================
class Scene_Battle < Scene_BaseÂ
 #--------------------------------------------------------------------------
 # * Alias Listings
 #--------------------------------------------------------------------------Â
 alias dpop_display_hp_damage display_hp_damage
 alias dpop_display_mp_damage display_mp_damageÂ
 alias dpop_display_evasion display_evasion
 alias dpop_display_miss display_miss
 #--------------------------------------------------------------------------
 # * Show HP Damage
 #  target : Target
 #  obj  : Skill or item
 #--------------------------------------------------------------------------Â
 def display_hp_damage(target, obj = nil)
  # Original call
  dpop_display_hp_damage(target, obj)
  critical = false
  critical = true if target.critical
  if target.hp_damage == 0        # No damage
   text = "skip"
  elsif target.absorbed         # HP Absorb
   text = (target.hp_damage).to_s
   type = 3
  elsif target.hp_damage > 0       # Normal Damage
   text = (target.hp_damage).to_s
   type = 0
  else                  # HP Recovery
   text = (-target.hp_damage).to_s
   type = 2
  end
  # Apply if no change
  if text != "skip"
   # Apply MP string if applicable
   if DAMAGE_HP_STRING != nil
    text = text + " " + DAMAGE_HP_STRING
   end
   target.damage = text
   target.damage_type = type
  end
 end
 #--------------------------------------------------------------------------
 # * Show MP Damage
 #  target : Target
 #  obj  : Skill or item
 #--------------------------------------------------------------------------
 def display_mp_damage(target, obj = nil)
  # Original call
  dpop_display_mp_damage(target, obj)
  critical = false
  critical = true if target.critical
  # Sort Data
  if target.absorbed           # MP Absorb
   text = (target.mp_damage).to_s
   type = 5
  elsif target.mp_damage > 0       # MP Damage
   text = (target.mp_damage).to_s
   type = 1
  elsif target.mp_damage < 0       # MP Recovery
   text = (-target.mp_damage).to_s
   type = 4
  else
   text = "skip"
  end
  # Apply if no change
  if text != "skip"
   # Apply MP string if applicable
   if DAMAGE_MP_STRING != nil
    text = text + " " + DAMAGE_MP_STRING
   end
   target.damage = text
   target.damage_type = type
  end
 endÂ
 #--------------------------------------------------------------------------
 # * Show Escape
 #  target : Target
 #  obj  : Skill or item
 #--------------------------------------------------------------------------
 def display_evasion(target, obj = nil)
  # Original call
  dpop_display_evasion(target, obj) Â
  critical = false
  target.damage = DAMAGE_POP_EVADED
  target.damage_type = 0
 end
 #--------------------------------------------------------------------------
 # * Show Miss
 #  target : Target
 #  obj  : Skill or item
 #--------------------------------------------------------------------------
 def display_miss(target, obj = nil)
  # Original call
  dpop_display_miss(target, obj) Â
  critical = false
  if obj == nil or obj.physical_attack
   text = DAMAGE_POP_MISS
  else
   text = DAMAGE_POP_FAILED
  end
  target.damage = text
  target.damage_type = 0
 end
end