#:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=
# Scene_SoulRage add-on by Blizzard
# Version 6.1
# Type: Additional Scene for SRS
# Date: 13.7.2007
#:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=
#   
#  This work is protected by the following license:
# #----------------------------------------------------------------------------
# #  
# #  Creative Commons - Attribution-NonCommercial-ShareAlike 3.0 Unported
# #  ( http://creativecommons.org/licenses/by-nc-sa/3.0/ )
# #  
# #  You are free:
# #  
# #  to Share - to copy, distribute and transmit the work
# #  to Remix - to adapt the work
# #  
# #  Under the following conditions:
# #  
# #  Attribution. You must attribute the work in the manner specified by the
# #  author or licensor (but not in any way that suggests that they endorse you
# #  or your use of the work).
# #  
# #  Noncommercial. You may not use this work for commercial purposes.
# #  
# #  Share alike. If you alter, transform, or build upon this work, you may
# #  distribute the resulting work only under the same or similar license to
# #  this one.
# #  
# #  - For any reuse or distribution, you must make clear to others the license
# #    terms of this work. The best way to do this is with a link to this web
# #    page.
# #  
# #  - Any of the above conditions can be waived if you get permission from the
# #    copyright holder.
# #  
# #  - Nothing in this license impairs or restricts the author's moral rights.
# #  
# #----------------------------------------------------------------------------
# 
#:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=
#   
#   This Scene provides a menu like in the battle. You can use Soul Rage skills
#   in the menu if you set their occasion in the database to be usuable in the
#   menu. Note that the Scene_SoulRage MUST have its main version the same as
#   the Soul Rage System, otherwise a compatibility CAN NOT be guaranteed!
#   
# Examples:
# 
#   SRS v1.0
#   S_SR v1.0
#   => works
#   
#   SRS v2.2
#   S_SR v1.0
#   => not known
#   
#   SRS v2.9
#   S_SR v2.2
#   => works
#   
#   SRS v2.4
#   S_SR v4.1
#   => not known
#   
#   SRS v3.1
#   S_SR v1.9
#   => not known
#   
#   SRS v1.6
#   S_SR v2.1
#   => not known
#   
#   
# If you find any bugs, please report them here:
# http://forum.chaos-project.com
#:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=

raise 'Scene_SoulRage requires Soul Rage System!' unless $crls

#==============================================================================
# Game_Actor
#==============================================================================

class Game_Actor

  alias sr_can_use_scene_addon? sr_can_use?
  def sr_can_use?(skill_id)
    return false if dead?
    return false if $data_skills[skill_id].atk_f == 0 && self.restriction == 1
    occasion = $data_skills[skill_id].occasion
    if $game_temp.in_battle
      return ([0, 1].include?(occasion) && sr_can_use_scene_addon?(skill_id))
    else
      return ([0, 2].include?(occasion) && sr_can_use_scene_addon?(skill_id))
    end
  end
  
  alias skill_sr_can_use_scene_addon? skill_can_use?
  def skill_can_use?(id)
    return sr_can_use?(id) if $scene.is_a?(Scene_SoulRage)
    return skill_sr_can_use_scene_addon?(id)
  end

end

#==============================================================================
# Window_SoulRageStatus
#==============================================================================

class Window_SoulRageStatus < Window_SkillStatus

  def refresh
    self.contents.clear
    draw_actor_name(@actor, 4, 0)
    draw_actor_state(@actor, 140, 0)
    draw_actor_hp(@actor, 284, 0)
    draw_actor_sr(@actor, 460, 0)
  end
  
end

#==============================================================================
# Scene_SoulRage
#==============================================================================

class Scene_SoulRage < Scene_Skill

  def main
    @actor = $game_party.actors[@actor_index]
    @help_window = Window_Help.new
    @skill_window = Window_SoulRage.new(@actor)
    @status_window = Window_SoulRageStatus.new(@actor)
    @skill_window.y = @help_window.height + @status_window.height
    @skill_window.height = 480 - @skill_window.y
    @skill_window.help_window = @help_window
    @skill_window.index = 0
    @skill_window.update
    @target_window = Window_Target.new
    @target_window.visible = @target_window.active = false
    Graphics.transition
    loop do
      Graphics.update
      Input.update
      update
      break if $scene != self
    end
    Graphics.freeze
    [@help_window, @status_window, @skill_window, @target_window].each {|win|
        win.dispose}
  end
  
  def update
    if defined?(SDK)
      @help_window.update
      @status_window.update
      @skill_window.update
      @target_window.update
    end
    super
  end
  
  def update_target
    sp = @actor.sp
    super
    if Input.trigger?(Input::C) && @actor.sp != sp && @skill != nil
      @actor.sp, @actor.sr = sp, @actor.sr - (sp - @actor.sp) * 10
      [@status_window, @skill_window, @target_window].each {|win| win.refresh}
    end
  end
  
  def update_skill
    sp = @actor.sp
    super
    if Input.trigger?(Input::C) && @actor.sp != sp && @skill != nil
      @actor.sp, @actor.sr = sp, @actor.sr - (sp - @actor.sp) * 10
      [@status_window, @skill_window, @target_window].each {|win| win.refresh}
    end
    if Input.trigger?(Input::B)
      $scene = Scene_Map.new
    elsif Input.trigger?(Input::R) || Input.trigger?(Input::L)
      $scene = Scene_SoulRage.new(@actor_index)
    end
  end
  
end
