#===============================================================================
# Proto Damage Cap
# Author game_guy
# Version 1.0
#-------------------------------------------------------------------------------
# Intro:
# Applies a simple damage cap like in most rpg's. You can only do 9999 damage
# at the max for example. But in most rpg's you can also break that damage
# cap with certain skills, weapons, or armors.
#
# Features:
# Set damage cap to whatever
# Change damage cap in game
# Toggle damage cap in game
# Excluded weapons, items, armors, and skills and enemies
#
# Instructions:
# Go down to the config below and configure everything there.
#
# Script Calls:
# This can turn the damage cap on or off
# $game_system.cap_on = true/false : true = on, false = off
# This can change the damage cap in game
# $game_system.damage_cap = x : x = a number
#
# Compatibility:
# Not tested with SDK.
# Should work with about every battle system.
#
# Credits:
# game_guy ~ For making it
# GAX72 ~ For requesting it
# anagura.raziel ~ For requesting more features
#===============================================================================
module GG_Cap
  #===========================================
  # This is the max damage cap set for
  # anything. Items, skills, attacks, etc.
  #===========================================
  Damage_Cap          = 9999
  #===========================================
  # Any weapon placed in the array below is
  # equipped, the damage cap won't apply to 
  # that actor.
  #===========================================
  Exclude_Weapons     = [2, 3, 4]
  #===========================================
  # Any armor placed in the array below is
  # equipped, the damage cap won't apply to 
  # that actor.
  #===========================================
  Exclude_Armors      = [1, 2, 3]
  #===========================================
  # Any skill placed in the array below is
  # used, the damage cap won't apply to 
  # that skill.
  #===========================================
  Exclude_Skills      = [7, 8, 9, 57]
  #===========================================
  # Any skill placed in the array below is
  # used, the damage cap won't apply to 
  # that skill.
  #===========================================
  Exclude_Items       = [1, 2, 3] 
  #===========================================
  # Any enemy placed in the array below,
  # the damage cap won't apply to 
  # that enemy. This also means
  # the cap will not apply to any skill
  # that enemy uses.
  #===========================================
  Exclude_Enemies     = [29, 30]
end
class Game_System
  attr_accessor :damage_cap
  attr_accessor :cap_on
  alias gg_init_damage_cap_lat initialize
  def initialize
    @damage_cap = GG_Cap::Damage_Cap
    @cap_on = true
    gg_init_damage_cap_lat
  end
end
class Game_Battler
  include GG_Cap
  alias gg_dmg_cap_atk_effect_lat attack_effect
  def attack_effect(attacker)
    return if !$game_system.cap_on
    dmg = $game_system.damage_cap
    last_hp = self.hp
    result = gg_dmg_cap_atk_effect_lat(attacker)
    if result && self.damage.is_a?(Integer)
      if attacker.is_a?(Game_Actor)
        flag = false
        actor = attacker
        Exclude_Armors.each{|a|
        flag = (actor.armor1_id == a or
        actor.armor2_id == a or
        actor.armor3_id == a or
        actor.armor4_id == a)
        break if flag == true}
        if Exclude_Weapons.include?(attacker.weapon_id)
          flag = true
        end
        unless flag
          self.hp = last_hp
          self.hp = self.hp
          self.damage = [self.damage, dmg].min
          self.hp -= Integer(self.damage)
        end
      elsif attacker.is_a?(Game_Enemy)
        unless Exclude_Enemies.include?(self.id)
          self.hp = last_hp
          self.hp = self.hp
          self.damage = [self.damage, dmg].min
          self.hp -= Integer(self.damage)
        end
      end
    end
    return result
  end
  alias gg_dmg_cap_skil_effect_lat skill_effect
  def skill_effect(user, skill)
    return if !$game_system.cap_on
    dmg = $game_system.damage_cap
    last_hp = self.hp
    result = gg_dmg_cap_skil_effect_lat(user, skill)
    if result && self.damage.is_a?(Integer)
      if user.is_a?(Game_Actor)
        if !Exclude_Skills.include?(skill.id)
          if self.damage < 0
            self.hp = last_hp
            self.hp = self.hp
            self.damage = [self.damage, -dmg].max
            self.hp -= Integer(self.damage)
          else
            self.hp = last_hp
            self.hp = self.hp
            self.damage = [self.damage, dmg].min
            self.hp -= Integer(self.damage)
          end
        end
      elsif user.is_a?(Game_Enemy)
        if !Exclude_Enemies.include?(self.id) || 
           !Exclude_Skills.include?(skill.id)
          if self.damage < 0
            self.hp = last_hp
            self.hp = self.hp
            self.damage = [self.damage, -dmg].max
            self.hp -= Integer(self.damage)
          else
            self.hp = last_hp
            self.hp = self.hp
            self.damage = [self.damage, dmg].min
            self.hp -= Integer(self.damage)
          end
        end
      end
    end
    return result
  end
  alias gg_dmg_cap_item_effect_lat item_effect
  def item_effect(item)
    return if !$game_system.cap_on
    dmg = $game_system.damage_cap
    result = gg_dmg_cap_item_effect(item)
    if result && self.damamge.is_a?(Integer)
      if !Exclude_Items.include?(item.id)
        if self.damage < 0
          self.hp = last_hp
          self.hp = self.hp
          self.damage = [self.damage, -dmg].max
          self.hp -= Integer(self.damage)
        else
          self.hp = last_hp
          self.hp = self.hp
          self.damage = [self.damage, dmg].min
          self.hp -= Integer(self.damage)
        end
      end
    end
  end
end