# -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
# Scene_Bonus EX
# Author: Soulpour777
# Web URL: www.infinitytears.wordpress.com
# Version 1.0
# -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
# Description:
# This new added scene allows the player to take a Bonus Item. The Bonus Item
# is only available if the certain computer time is achieved and a certain
# switch is turned on. The switch is automatically turned off when the item
# is taken. This serves as the counter to "Taken" and "Not Taken" for the item.
# -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
# Usage:
#  - To make the bonus item available and be checked if its available, turn
# the switch you indicated below.
#  - To open the Scene Bonus, do this script call:
# SceneManager.call(Scene_SoulpourBonus)
#  - For the NPC face, position and index, look at the variables below and
# set up the set up you desire.
# -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=

#==============================================================================
# ** Soulpour, Scene_Bonus
#------------------------------------------------------------------------------
#  This module configures everything about the Scene Bonus.
#==============================================================================
module Soulpour
  module Scene_Bonus
    # Which switch triggers the bonus to be availabe?
    # This serves as the taken or not taken counter
    Switch = 1
    # What is the amount of items to be given to the player? (Item, Armor, Weapon)
    Item_Amount = 1
    # These are the list of item ids of the bonus items.
    Given_Items = [10, 11, 12, 13, 14, 15]
    # These are the list of armor ids of the bonus armors.
    Given_Armors = [15, 16, 17, 18, 19, 20]
    # These are the list of weapon ids of the bonus weapons.
    Given_Weapons = [21, 22, 23, 24, 25, 26]
    # These are the list of gold amounts that is given during bonus.
    Given_Gold = [100, 200, 300, 400]
    #Which hour should the bonus be available? (1 - 24)
    TimeOfBonus = 18
    # Do you wish to play a different BGM when inside Bonus?
    Bonus_Allow_BGM = false
    # Which BGM should be played when Bonus BGM is allowed?
    Bonus_BGM = "Theme2"
    # Do you wish to play a ME when the Bonus Award is taken?
    Bonus_Allow_ME = true
    # Which ME should be played when the bonus is taken?
    Bonus_ME = "Fanfare1"    
    # What is the name of the picture of the person who gives the bonus?
    Bonus_Picture = "Alice"
    # What is the name of the background you are using?
    Bonus_BG = "Bonus_BG"
    # What is the name of the name of the fog?
    Bonus_Fog = "Bonus_Wave"
    # What is the picture if the bonus is available?
    Bonus_AV = "Available"
    # What is the picture if the bonus is available?
    Bonus_NAV = "Not_Available"    
    # What is the face graphic used for the NPC?
    NPC_Face = "People1"
    # What is the position of the message? (0 - Top, 1 - Middle, 2 - Below)
    Message_Pos = 0
    # What is the index of the face shown? (Starts with 0)
    NPC_Face_Index = 4
    # What is the message given by the NPC?
    NPC_Message = "Thanks for claiming your bonus! Later!"
    #--------------------------------------------------------------------------
    # * Get Item
    #--------------------------------------------------------------------------     
    def self.getItem
      $game_party.gain_item($data_items[Soulpour::Scene_Bonus::Given_Items[rand(Soulpour::Scene_Bonus::Given_Items.size)]], 
      Soulpour::Scene_Bonus::Item_Amount)
    end
    #--------------------------------------------------------------------------
    # * Get Armors
    #--------------------------------------------------------------------------     
    def self.getArmors
      $game_party.gain_item($data_armors[Soulpour::Scene_Bonus::Given_Armors[rand(Soulpour::Scene_Bonus::Given_Armors.size)]], 
      Soulpour::Scene_Bonus::Item_Amount)      
    end
    #--------------------------------------------------------------------------
    # * Get Weapons
    #--------------------------------------------------------------------------     
    def self.getWeapons
      $game_party.gain_item($data_weapons[Soulpour::Scene_Bonus::Given_Weapons[rand(Soulpour::Scene_Bonus::Given_Weapons.size)]], 
      Soulpour::Scene_Bonus::Item_Amount)      
    end
    #--------------------------------------------------------------------------
    # * Get Gold
    #--------------------------------------------------------------------------     
    def self.getGold
      $game_party.gain_gold(Soulpour::Scene_Bonus::Given_Gold[rand(Soulpour::Scene_Bonus::Given_Gold.size)])
    end
    #--------------------------------------------------------------------------
    # * Get Bonus Time
    #--------------------------------------------------------------------------  
    def self.getTime
      bonusTime = Time.now
      case bonusTime.hour
        when Soulpour::Scene_Bonus::TimeOfBonus
          # the movement counter creates a choice between items, armors, weapons
          # or simply gold.
          movement_counter = rand(4)+1
          puts movement_counter
          # Items -----------------------------------------------
            if movement_counter == 1
              Soulpour::Scene_Bonus.playBonusME if Soulpour::Scene_Bonus::Bonus_Allow_ME
              Soulpour::Scene_Bonus.getItem
              SceneManager.goto(Scene_Map)
              Soulpour::Scene_Bonus.giveMessage
              $game_switches[Soulpour::Scene_Bonus::Switch] = false
          # Armors -----------------------------------------------   
            elsif movement_counter == 2
              Soulpour::Scene_Bonus.playBonusME if Soulpour::Scene_Bonus::Bonus_Allow_ME             
             Soulpour::Scene_Bonus.getArmors
             SceneManager.goto(Scene_Map)
             Soulpour::Scene_Bonus.giveMessage
             $game_switches[Soulpour::Scene_Bonus::Switch] = false
          # Weapons -----------------------------------------------   
            elsif movement_counter == 3
              Soulpour::Scene_Bonus.playBonusME if Soulpour::Scene_Bonus::Bonus_Allow_ME           
              Soulpour::Scene_Bonus.getWeapons
              SceneManager.goto(Scene_Map)
              Soulpour::Scene_Bonus.giveMessage
              $game_switches[Soulpour::Scene_Bonus::Switch] = false
          # Gold -----------------------------------------------   
            elsif movement_counter == 4
              Soulpour::Scene_Bonus.playBonusME if Soulpour::Scene_Bonus::Bonus_Allow_ME             
              Soulpour::Scene_Bonus.getGold
              SceneManager.goto(Scene_Map)
              Soulpour::Scene_Bonus.giveMessage
              $game_switches[Soulpour::Scene_Bonus::Switch] = false
            end
        end
    end
    #--------------------------------------------------------------------------
    # * Play ME
    #--------------------------------------------------------------------------    
    def self.playBonusME
      RPG::ME.new(Soulpour::Scene_Bonus::Bonus_ME, 100, 100).play
    end
    
    def self.giveMessage
      $game_message.position = Soulpour::Scene_Bonus::Message_Pos
      $game_message.face_name = Soulpour::Scene_Bonus::NPC_Face
      $game_message.face_index = Soulpour::Scene_Bonus::NPC_Face_Index
      $game_message.add(Soulpour::Scene_Bonus::NPC_Message)
    end
  
  end
  
end



#==============================================================================
# ** Window_SoulpourBonus
#------------------------------------------------------------------------------
#  This window displays the necessary window for the Scene Bonus.
#==============================================================================

class Window_SoulpourBonus < Window_Base
  
  #--------------------------------------------------------------------------
  # * Object Initialization
  #--------------------------------------------------------------------------
  def initialize
    super(0, 0, window_width, window_height)
    refresh
    self.opacity = 0
  end
  #--------------------------------------------------------------------------
  # * Get Window Width
  #--------------------------------------------------------------------------
  def window_width
    return Graphics.width
  end
  
  #--------------------------------------------------------------------------
  # * Get Window Height
  #--------------------------------------------------------------------------  
  def window_height
    return Graphics.height - 50
  end
  
  #--------------------------------------------------------------------------
  # * Refresh
  #--------------------------------------------------------------------------
  def refresh
    contents.clear
  end

  #--------------------------------------------------------------------------
  # * Open Window
  #--------------------------------------------------------------------------
  def open
    refresh
    super
  end
end

class Soulpour_BonusCommand < Window_Command
  #--------------------------------------------------------------------------
  # * Object Initialization
  #--------------------------------------------------------------------------
  def initialize
    super(0, 365)
    self.opacity = 0
  end
  #--------------------------------------------------------------------------
  # * Get Window Width
  #--------------------------------------------------------------------------
  def window_width
    return Graphics.width
  end
  #--------------------------------------------------------------------------
  # * Get Window Height
  #--------------------------------------------------------------------------
  def window_height
    return 52
  end
  #--------------------------------------------------------------------------
  # * Get Column Max
  #-------------------------------------------------------------------------- 
  def col_max
    return 2
  end
  #--------------------------------------------------------------------------
  # * Get Number of Lines to Show
  #--------------------------------------------------------------------------
  def visible_line_number
    item_max
  end
  #--------------------------------------------------------------------------
  # * Create Command List
  #--------------------------------------------------------------------------
  def make_command_list
    add_main_commands
  end
  #--------------------------------------------------------------------------
  # * Add Main Commands to List
  #--------------------------------------------------------------------------
  def add_main_commands
    add_command("Get Bonus", :get_bonus, if_available)
    add_command("Close", :close_bonus)
  end  
  #--------------------------------------------------------------------------
  # * Gets the Time the bonus is available
  #-------------------------------------------------------------------------- 
  def if_available
    if_bonus_available = Time.now
    return true if if_bonus_available.hour == Soulpour::Scene_Bonus::TimeOfBonus && $game_switches[Soulpour::Scene_Bonus::Switch]
    return false if if_bonus_available.hour != Soulpour::Scene_Bonus::TimeOfBonus
  end
end

#==============================================================================
# ** Scene_SoulpourBonus
#------------------------------------------------------------------------------
#  This class performs the bonus screen processing.
#==============================================================================

class Scene_SoulpourBonus < Scene_MenuBase
    #--------------------------------------------------------------------------
    # * Start Processing
    #--------------------------------------------------------------------------
    def start
      super
      @bonus_window = Window_SoulpourBonus.new
      create_bonus_commands
      create_bonus_personnel
      create_av if if_available
      create_nav if if_available == false
    end
    #--------------------------------------------------------------------------
    # * Create Bonus Commands
    #--------------------------------------------------------------------------
    def create_bonus_commands
      @bonus_command = Soulpour_BonusCommand.new
      @bonus_command.set_handler(:get_bonus, method(:command_getbonus))
      @bonus_command.set_handler(:close_bonus, method(:command_closebonus))
    end
    #--------------------------------------------------------------------------
    # * Gets the Time the bonus is available
    #-------------------------------------------------------------------------- 
    def if_available
      if_bonus_available = Time.now
      return true if if_bonus_available.hour == Soulpour::Scene_Bonus::TimeOfBonus && $game_switches[Soulpour::Scene_Bonus::Switch]
      return false if if_bonus_available.hour != Soulpour::Scene_Bonus::TimeOfBonus
    end
    #--------------------------------------------------------------------------
    # * Create Background
    #--------------------------------------------------------------------------  
    def create_background
      @background = Plane.new
      @background.bitmap = Cache.picture(Soulpour::Scene_Bonus::Bonus_BG)
      @background.z = 1
      @background_wave = Plane.new
      @background_wave.bitmap = Cache.picture(Soulpour::Scene_Bonus::Bonus_Fog)
      @background_wave.opacity = 40
      @background_wave.z = 2
    end
    #--------------------------------------------------------------------------
    # * Create Bonus Personnel
    #--------------------------------------------------------------------------    
    def create_bonus_personnel
      @bonus_image = Plane.new
      @bonus_image.bitmap = Cache.picture(Soulpour::Scene_Bonus::Bonus_Picture)
      @bonus_image.z = 3
    end
    #--------------------------------------------------------------------------
    # * Available
    #--------------------------------------------------------------------------     
    def create_av
      @bonus_av = Plane.new
      @bonus_av.bitmap = Cache.picture(Soulpour::Scene_Bonus::Bonus_AV)
      @bonus_av.z = 4    
    end
    #--------------------------------------------------------------------------
    # * Not Available
    #--------------------------------------------------------------------------     
    def create_nav
      @bonus_nav = Plane.new
      @bonus_nav.bitmap = Cache.picture(Soulpour::Scene_Bonus::Bonus_NAV)
      @bonus_nav.z = 4   
    end
    #--------------------------------------------------------------------------
    # * Update Frame (Basic)
    #--------------------------------------------------------------------------
    def update_basic
      Graphics.update
      Input.update
      update_all_windows
      @background_wave.ox += 1
    end  
    #--------------------------------------------------------------------------
    # * Dispose Background
    #--------------------------------------------------------------------------  
    def dispose_background
      @background.bitmap.dispose
      @background.dispose
      @background_wave.bitmap.dispose
      @background_wave.dispose
      @bonus_image.bitmap.dispose
      @bonus_image.dispose
      @bonus_av.bitmap.dispose if if_available
      @bonus_av.dispose if if_available
      @bonus_nav.bitmap.dispose if if_available == false   
      @bonus_nav.dispose if if_available == false
    end
    #--------------------------------------------------------------------------
    # * Gets the Bonus
    #--------------------------------------------------------------------------  
    def command_getbonus
      Soulpour::Scene_Bonus.getTime
      @bonus_command.activate
    end
    #--------------------------------------------------------------------------
    # * Close Windows
    #--------------------------------------------------------------------------  
    def command_closebonus
      @bonus_window.dispose
      SceneManager.goto(Scene_Map)
      $game_map.autoplay
    end

end