#===============================================================================
# Lucky 7777 Damage
# Version 1.2
# Author game_guy
#-------------------------------------------------------------------------------
# Intro:
# Remember in some of the rpg's (I cant remember which ones) but if yod had 7777
# Hp then you would deal 7777 damage. This script does that.
#
# Features:
# Deals custom damage if hp is defined number
# Enemies can deal the 7777 (set on or off)
# Specific enemies and actors cant do it (customizable)
# Customizable font, font size, and font color
# Change the lucky message to whatever you want
#
# Instructions:
# Go down to Begin Config and look at the options there.
#
# Credits:
# game_guy ~ for making it
# Blizzard ~ teaching me a few things I used in here.
#===============================================================================
module GameGuy
#=====================================================
# Begin Config
#=====================================================

  #--------------------------------------------------------------------
  # The background color of the font. 
  #--------------------------------------------------------------------
  BackFontColor   = Color.new(0, 0, 0) # (red, green, blue)
  #--------------------------------------------------------------------
  # The foreground color of the font.
  #--------------------------------------------------------------------
  ForeFontColor   = Color.new(0, 255, 0) # (red, green, blue)
  #--------------------------------------------------------------------
  # The name of the font you want to use.
  #--------------------------------------------------------------------
  FontName        = "Arial"
  #--------------------------------------------------------------------
  # The size of the font you want to use.
  #--------------------------------------------------------------------
  FontSize        = 32 
  #--------------------------------------------------------------------
  # The message you want to pop up when 7777 is dealt.
  #--------------------------------------------------------------------
  LuckyMessage    = "Lucky!"
  #--------------------------------------------------------------------
  # Number that deals that much damage when hp is equal to that number.
  #--------------------------------------------------------------------
  LuckyNumber     = 7777
  #--------------------------------------------------------------------
  # Actors that cant use the lucky 7777.
  #--------------------------------------------------------------------
  CantUseActors   = [8, 9, 10] 
  #--------------------------------------------------------------------
  # If true the enemies can use the lucky 7777.
  #--------------------------------------------------------------------
  EnemiesUse      = false
  #--------------------------------------------------------------------
  # Enemies that cant use the lucky 7777.
  #--------------------------------------------------------------------
  CantUseEnemies  = [1, 2, 3, 4]

#=====================================================
# End Config
#=====================================================
end
module RPG
  class Sprite < ::Sprite
    alias use_7777_text damage
    def damage(value, critical)
      if critical != GameGuy::LuckyNumber
        return use_7777_text(value, critical)
      end
      dispose_damage
      if value.is_a?(Numeric)
        damage_string = value.abs.to_s
      else
        damage_string = value.to_s
      end
      bitmap = Bitmap.new(160, 64)
      bitmap.font.name = GameGuy::FontName
      bitmap.font.size = GameGuy::FontSize
      bitmap.font.color = GameGuy::BackFontColor
      bitmap.draw_text(-1, 22-1, 160, 36, damage_string, 1)
      bitmap.draw_text(+1, 22-1, 160, 36, damage_string, 1)
      bitmap.draw_text(-1, 22+1, 160, 36, damage_string, 1)
      bitmap.draw_text(+1, 22+1, 160, 36, damage_string, 1)
      bitmap.font.color = GameGuy::ForeFontColor
      bitmap.draw_text(0, 22, 160, 36, damage_string, 1)
      bitmap.font.size = GameGuy::FontSize
      bitmap.font.color = GameGuy::BackFontColor
      bitmap.draw_text(-1, -1, 160, 32, GameGuy::LuckyMessage, 1)
      bitmap.draw_text(+1, -1, 160, 32, GameGuy::LuckyMessage, 1)
      bitmap.draw_text(-1, +1, 160, 32, GameGuy::LuckyMessage, 1)
      bitmap.draw_text(+1, +1, 160, 32, GameGuy::LuckyMessage, 1)
      bitmap.font.color = GameGuy::ForeFontColor
      bitmap.draw_text(0, 0, 160, 32, GameGuy::LuckyMessage, 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
end
class Game_Battler
  alias deal_7777_attack attack_effect
  def attack_effect(attacker)
    if attacker.is_a?(Game_Enemy)
      if GameGuy::EnemiesUse != true
        return deal_7777_attack(attacker)
      elsif GameGuy::CantUseEnemies.include?(attacker.id)
        return deal_7777_attack(attacker)
      elsif attacker.hp == GameGuy::LuckyNumber
        result = deal_7777_attack(attacker)
        if result
          self.critical = GameGuy::LuckyNumber
          self.damage = GameGuy::LuckyNumber
          last_hp = self.hp
          self.hp -= self.damage
        else
          self.critical = false
          self.damage = "Miss"
        end
      else
        return deal_7777_attack(attacker)
      end
    end
    if attacker.is_a?(Game_Actor)
      if GameGuy::CantUseActors.include?(attacker.id)
        return deal_7777_attack(attacker)
      elsif attacker.hp == GameGuy::LuckyNumber
        result = deal_7777_attack(attacker)
        if result
          self.critical = GameGuy::LuckyNumber
          self.damage = GameGuy::LuckyNumber
          last_hp = self.hp
          self.hp -= self.damage
        else
          self.critical = false
          self.damage = miss
        end
      else
        return deal_7777_attack(attacker)
      end
    end
  end
end