#===============================================================================
# 
# Craze's Script Asylum - Boss Options
# Last Date Updated: 2010.05.23
# Level: Easy, Normal
# 
# This script lets you customize boss enemies a little more, and balance
# specific skills so as to remain useful - but not overpowered - against
# your boss enemies. Some features are effective on normal enemies, too.
#
# I will likely update this script fairly often. This is one script that I'd
# really, really like ideas for!
#===============================================================================
# Instructions
# -----------------------------------------------------------------------------
# To install this script, open up your script editor and copy/paste this script
# to an open slot below ▼ Materials and Battle Engine Melody but above ▼ Main. 
# Remember to save. Please check the "Compatibility" section below.
# 
# The following tags are for enemy noteboxes only:
#
# <boss>
# This simple tag lets the game know that this enemy is a boss. It does nothing
# by itself.
#
# <uni dmg: x%>
# This tag affects any damage the enemy takes. It's meant for bosses to have a
# universal barrier, but you can of course use it for any enemy. Damage taken
# is altered by x%.
#
# <uni st: x%>
# This tag affects any states you attempt to inflict on the enemy. Use the state
# tag below if you have a state that isn't marked with "Nonresistance," but you
# don't want <uni st: x%> to affect it. Any states have their infliction chance
# altered by x%.
#
# The following tags are for skills and/or states:
#
# <ignore uni>
# For skills and states. Skills will ignore <uni dmg: x%> and states will ignore
# <uni st: x%> if this tag is applied.
#
# <boss dmg: x%>
# For skills only. This tag will change the damage a skill does after any other
# damage effects (please check the "Compatibility" section below), as long as
# the target has a <boss> tag.
# 
#===============================================================================
# Examples
# -----------------------------------------------------------------------------
# <uni dmg: 200%> 
# The enemy takes double damage from any source.
#
# <boss dmg: 10%>
# This skill (potentially Gravity - 50% Current HP damage) only does 10% of its
# total damage to bosses.
#
# <ignore uni>  <boss dmg: 50%>
# This skill only does half damage to bosses, but ignores any enemy universal
# barriers.
#
# <uni st: 60%>
# This enemy reduces the chance of incoming states being applied by 40%.
#
#===============================================================================
# Compatibility
# -----------------------------------------------------------------------------
# Note: This script requires Yanfly's Battle Engine Melody. Make sure to place
# this script below BEM and any other scripts that affect state probability
# or make changes to damage.
#===============================================================================
 
$imported = {} if $imported == nil
$imported["BossOptions"] = true

if $imported["BattleEngineMelody"]
 
#==============================================================================
# RPG::Enemy
#==============================================================================
 
class RPG::Enemy
  
  #--------------------------------------------------------------------------
  # boss?
  #--------------------------------------------------------------------------

  def boss?
    return @boss if @boss != nil
    @boss = false
    self.note.split(/[\r\n]+/).each { |line|
      case line
      when /<(?:BOSS|boss)/i
          @boss = true
      end
    }
    return @boss
  end
 
  #--------------------------------------------------------------------------
  # uni_dmg_taken_rate
  #--------------------------------------------------------------------------

  def uni_dmg_taken_rate
    return @uni_dmg_take if @uni_dmg_take != nil
    @uni_dmg_take = 100
    self.note.split(/[\r\n]+/).each { |line|
      case line
      when /<(?:UNI_DMG|uni dmg):[ ]*(\d+)([%%])>/i
        @uni_dmg_take = $1.to_i
      end
    }
    return @uni_dmg_take
  end
 
  #--------------------------------------------------------------------------
  # uni_st_taken_rate
  #--------------------------------------------------------------------------

  def uni_st_taken_rate
    return @uni_st_take if @uni_st_take != nil
    @uni_st_take = 100
    self.note.split(/[\r\n]+/).each { |line|
      case line
      when /<(?:UNI_ST|uni st):[ ]*(\d+)([%%])>/i
          @uni_st_take = $1.to_i
      end
    }
    return @uni_st_take
  end
 
end
 
#==============================================================================
# RPG::State
#==============================================================================
 
class RPG::State
  
  #--------------------------------------------------------------------------
  # ignore_uni?
  #--------------------------------------------------------------------------

  def ignore_uni?
    return @ig_uni if @ig_uni != nil
    @ig_uni = false
    self.note.split(/[\r\n]+/).each { |line|
      case line
      when /<(?:IGNORE_UNI|ignore uni)/i
          @ig_uni = true
      end
    }
    return @ig_uni
  end
  
end
 
#==============================================================================
# RPG::Skill
#==============================================================================
 
class RPG::Skill < RPG::UsableItem
  
  #--------------------------------------------------------------------------
  # ignore_uni?
  #--------------------------------------------------------------------------

  def ignore_uni?
    return @ig_uni if @ig_uni != nil
    @ig_uni = false
    self.note.split(/[\r\n]+/).each { |line|
      case line
      when /<(?:IGNORE_UNI|ignore uni)/i
          @ig_uni = true
      end
    }
    return @ig_uni
  end
 
  #--------------------------------------------------------------------------
  # boss_dmg_taken_rate
  #--------------------------------------------------------------------------

  def boss_dmg_taken_rate
    return @boss_dmg_take if @boss_dmg_take != nil
    @boss_dmg_take = 100
    self.note.split(/[\r\n]+/).each { |line|
      case line
      when /<(?:BOSS_DMG|boss dmg):[ ]*(\d+)([%%])>/i
        @boss_dmg_take = $1.to_i
      end
    }
    return @boss_dmg_take
  end
  
end
 
#==============================================================================
# Game_Enemy
#==============================================================================

class Game_Enemy
  
  #--------------------------------------------------------------------------
  # new method: boss?
  #--------------------------------------------------------------------------
  
  def boss?
    return enemy.boss?
  end
  
  #--------------------------------------------------------------------------
  # new method: uni_dmg_taken
  #--------------------------------------------------------------------------
  
  def uni_dmg_taken
    return enemy.uni_dmg_taken_rate
  end
  
  #--------------------------------------------------------------------------
  # new method: uni_st_taken
  #--------------------------------------------------------------------------
  
  def uni_st_taken
    return enemy.uni_st_taken_rate
  end
  
end
 
#==============================================================================
# Game_Battler
#==============================================================================
 
class Game_Battler  
 
  #--------------------------------------------------------------------------
  # alias method: execute_damage
  #--------------------------------------------------------------------------
  alias csa_bossopt_execute_damage execute_damage unless $@
  def execute_damage(user)
    skip_uni_dmg = false
    skip_uni_dmg = $data_skills[user.action.skill_id].ignore_uni? if user.action.skill?
    if enemy?
     unless skip_uni_dmg
       @hp_damage = @hp_damage * uni_dmg_taken / 100
       @mp_damage = @mp_damage * uni_dmg_taken / 100
     end
     if boss? and user.action.skill?
       boss_rate = $data_skills[user.action.skill_id].boss_dmg_taken_rate
       @hp_damage = @hp_damage * boss_rate / 100
       @mp_damage = @mp_damage * boss_rate / 100
     end
    end
    csa_bossopt_execute_damage(user)
  end
  
  #--------------------------------------------------------------------------
  # alias method: state_probability_table
  #--------------------------------------------------------------------------
  alias csa_bossopt_state_probability_table state_probability_table unless $@
  def state_probability_table(state_id, rank)
    rate = csa_bossopt_state_probability_table(state_id, rank)
    return rate if $data_states[state_id].nonresistance
    if enemy? and !$data_states[state_id].ignore_uni?
     rate = rate * uni_st_taken / 100
    end
    return [rate, 0].max
  end

end

end # imported["BattleEngineMelody"]
 
#===============================================================================
# 
# END OF FILE
# 
#===============================================================================