#==============================================================================
# ■ Slot_Machine vol.3.03
#------------------------------------------------------------------------------
# ※『Game_Party_Coin』(必須)
# ※『Window_digits_number』(必須)
# ※『Coin_Game_Base』(必須)より下に挿入
# 11/09/10
#==============================================================================
# イベントコマンド『スクリプト』に make_slot(Type,Pattern) で呼び出し
# ※Type=スロットタイプの設定を参照
# ※Pattern=スロットの絵柄パターンを設定を参照(未設定の場合=デフォルト)
#==============================================================================
module HIDE_SLOT
  #==============================================================================
  # ■ デバッグ(開発者用)
  #==============================================================================
  DEBUG = false # Viewportを可視化
  #==============================================================================
  # ■ グラフィック設定 ※Windowskinsフォルダ内のファイル名を指定
  #==============================================================================
  BACK = "slot_background"        # スロットの背景画像
  GRAPHIC = "slot_pattern"        # スロットのパターン画像
  SLOT_BACK = "slot_back"         # スロットの補助画像
  SLOT_ICON = "slot_icon"         # 獲得コインの一覧に使うアイコン画像
  SLOT_HIT = "slot_hit"           # 当たりのレートの背景画像(当たり効果)
  SWITCH = "slot_switch"          # 開始レバーと停止ボタン
  #==============================================================================
  # ■ 音の設定 ※ファイル名を指定 ※Audioフォルダ内 #()のファイル名
  #==============================================================================
  BGM = "019-Field02"             # スロット実行中のBGM(BGM)
  MOVE_SE = "003-System03"        # スロットの回転音(SE) ※動作重い
  GAIN_COIN_SE = "001-System01"   # 賭けるコインを増やす音(SE)
  LOSE_COIN_SE = "001-System01"   # 賭けるコインを減らす音(SE)
  START_SE = "005-System05"       # スロット開始レバーを引く音(SE)
  PUSH_SE = "002-System02"        # スロット停止ボタンを押す音(SE)
  HIT_ME_MAX = "009-Fanfare03"    # 大当りの効果音(ME)
  HIT_ME = "007-Fanfare01"        # 当りの効果音(ME)
  
  ME_MAX_TIME = 20                # 大当りの待ち時間(HIT_ME_MAXの演奏時間(秒))
  ME_TIME = 4                     # 当りの待ち時間(HIT_MEの演奏時間(秒))
  #==============================================================================
  # ■ スロットタイプの設定
  # COIN,RATE,ME_RATE_MAXを設定
  #==============================================================================
  #--------------------------------------------------------------------------
  # COIN[n] = value
  # n=タイプ番号($game_temp.slot_type から参照される)
  # value=消費コイン数(賭けるコイン枚数)
  # ※↓[0][1][2]はサンプルなので書き換え可
  #--------------------------------------------------------------------------
  COIN = []
  COIN[0] = 100 #※100枚賭け
  COIN[1] = 10
  COIN[2] = 1
  #--------------------------------------------------------------------------
  # RATE[n] = [a,b,c,d,e,f,g,h]
  # n=タイプ番号($game_temp.slot_type から参照される)
  # a=0番絵柄が3枚揃った場合の獲得コイン数
  # b=1番絵柄が3枚揃った場合の獲得コイン数
  # c=2番絵柄...,d=3,e=4
  #--------------------------------------------------------------------------
  RATE = []
  RATE[0] = [300000,100000,50000,30000,10000,5000,3000,1000]
  RATE[1] = [30000,10000,5000,3000,1000,500,300,100]
  RATE[2] = [3000,1000,500,300,100,50,30,10]
  #--------------------------------------------------------------------------
  # ME_RATE_MAX[n] = value
  # n=タイプ番号($game_temp.slot_type から参照される)
  # value=大当りの効果音(HIT_ME_MAX)を演奏する獲得コイン数(value以上)
  #--------------------------------------------------------------------------
  ME_RATE_MAX = []
  ME_RATE_MAX[0] = 30000 #※30000枚以上当たれば、派手なファンファーレ
  ME_RATE_MAX[1] = 3000
  ME_RATE_MAX[2] = 300
  #==============================================================================
  # ■ スロットの絵柄パターンを設定(手動設定)
  #==============================================================================
  # PATTERN[n] = { num=>{ key=>value, ... }, ... }　
  # n=パターン番号($game_temp.slot_pattern から参照される)
  # num=スロット@,A,B = 0,1,2
  # key=(0〜7) スロットの絵柄
  # value=個数 ※valueの合計が3以下は不可(縦3枚の絵柄なので…)
  # ※↓[0][1][2]はサンプルなので書き換え可
  #==============================================================================
  PATTERN = {}
  # □デフォルトと同じパターン(改)
  PATTERN[0] = {
  0=>{0=>3,1=>9,2=>15,3=>21,4=>27,5=>33,6=>39,7=>45},
  1=>{0=>3,1=>9,2=>15,3=>21,4=>27,5=>33,6=>39,7=>45},
  2=>{0=>3,1=>9,2=>15,3=>21,4=>27,5=>33,6=>39,7=>45} }
  # □大当たりが揃い易いパターン
  PATTERN[1] = {
  0=>{0=>15,1=>13,2=>11,3=>9,4=>7,5=>5,6=>3,7=>1},
  1=>{0=>15,1=>13,2=>11,3=>9,4=>7,5=>5,6=>3,7=>1},
  2=>{0=>15,1=>13,2=>11,3=>9,4=>7,5=>5,6=>3,7=>1} }
  # □目押し練習用パターン(※valueの合計が少ないほど目押しできる？)
  PATTERN[2] = {
  0=>{0=>1,1=>1,2=>1,3=>1,4=>1,5=>1,6=>1,7=>1},
  1=>{0=>1,1=>1,2=>1,3=>1,4=>1,5=>1,6=>1,7=>1},
  2=>{0=>1,1=>1,2=>1,3=>1,4=>1,5=>1,6=>1,7=>1} }
end
#==============================================================================
# ■ Window_Slot_hit
#==============================================================================
class Window_Slot_hit
  include HIDE_SLOT
  #--------------------------------------------------------------------------
  # ■ オブジェクト初期化
  #--------------------------------------------------------------------------
  def initialize
    @slot_hit = Sprite.new
    @slot_hit.bitmap = Bitmap.new(580,336)
    @slot_hit.x = 60
    @slot_hit.opacity = 15
    @count_on = false
    @count = 0
    refresh([false]*8,[])
  end
  #--------------------------------------------------------------------------
  # ■ 当りの描画
  #--------------------------------------------------------------------------
  def refresh(hits,slot)
    @count_on = true
    icon = RPG::Cache.windowskin(HIDE_SLOT::SLOT_HIT)
    pic = RPG::Cache.windowskin(HIDE_SLOT::SLOT_BACK)
    h = pic.height/5
    # □当たりの出たレートを点滅
    for i in 0...hits.size
      if hits[i]
        @slot_hit.bitmap.blt(374,84+28*i+8,icon,Rect.new(0,20*i,147,20))
      end
    end
    # □当たりの出た賭けたコイン数を点滅
    for i in slot
      case i
      when 0
        @slot_hit.bitmap.blt(0,80+80+80/2-h/2,pic,Rect.new(80*4,h*0,80,h))
      when 1
        @slot_hit.bitmap.blt(0,80+80/2-h/2,pic,Rect.new(80*4,h*1,80,h))
      when 2
        @slot_hit.bitmap.blt(0,80+80*2+80/2-h/2,pic,Rect.new(80*4,h*2,80,h))
      when 3
        @slot_hit.bitmap.blt(0,80-h+h/2,pic,Rect.new(80*4,h*3,80,h))
      when 4
        @slot_hit.bitmap.blt(0,80+80*3-h/2,pic,Rect.new(80*4,h*4,80,h))
      end
    end
  end
  #--------------------------------------------------------------------------
  # ■ Bitmapの消去
  #--------------------------------------------------------------------------
  def reset
    if @slot_hit.bitmap != nil
      @slot_hit.bitmap.clear
      @slot_hit.opacity = 10
      @count_on = false
    end
  end
  #--------------------------------------------------------------------------
  # ■ 更新
  #--------------------------------------------------------------------------
  def update
    if @count_on
      if @slot_hit.opacity > 10
        @slot_hit.opacity -= 10
      else
        @count_on = false
      end
    else
      if @slot_hit.opacity < 250
        @slot_hit.opacity += 10
      else
        @count_on = true
      end
    end
  end
  #--------------------------------------------------------------------------
  # ■ 透明度を返す(Bitmapの点滅)
  #--------------------------------------------------------------------------
  def opacity?
    return @slot_hit.opacity
  end
  #--------------------------------------------------------------------------
  # ■ 解放
  #--------------------------------------------------------------------------
  def dispose
    if @slot_hit.bitmap != nil
      @slot_hit.bitmap.dispose
    end
    @slot_hit.dispose
  end
end  
#==============================================================================
# ■ Window_Slot_switch
#==============================================================================
class Window_Slot_switch
  include HIDE_SLOT
  attr_accessor :lever_switch
  attr_accessor :lever_count
  attr_accessor :lever_stop
  #--------------------------------------------------------------------------
  # ■ オブジェクト初期化
  #--------------------------------------------------------------------------
  def initialize(i)
    @i = i
    @lever_switch = true
    @lever_count = 0
    @lever_stop = false
    @switch_backs = []
    make_switch?(i)
  end
  #--------------------------------------------------------------------------
  # ■ 各種ボタンの作成
  #--------------------------------------------------------------------------
  def make_switch?(i)
    pic = RPG::Cache.windowskin(HIDE_SLOT::SWITCH)
    @cw = pic.width/4
    @ch = pic.height/4
    case i
    when 0
      sw = 40
    when 1
      sw = 60
    when 2
      sw = 100
    when 3
      sw = 140
    end
    @switch_backs[i] = Sprite.new(Viewport.new(60+80+i*100+80/2-@cw/2-sw,80+320,@cw,@ch))
    if HIDE_SLOT::DEBUG
      @switch_backs[i].viewport.color = Color.new(255,255,255,100)
    end
    @switch_backs[i].bitmap = Bitmap.new(60+@ch,@ch*4*4)
    @switch_backs[i].bitmap.blt(0,0,pic,Rect.new(32*i,0,32,64*4))
  end
  #--------------------------------------------------------------------------
  # ■ スロットボタンのアニメーションを更新
  #--------------------------------------------------------------------------
  def update(n)
    c = 2
    case @lever_count
    when c
      @switch_backs[n].oy = 64*1
    when c*2
      @switch_backs[n].oy = 64*2
    when c*3
      @switch_backs[n].oy = 64*3
      @lever_switch = false
    when c*4
      @switch_backs[n].oy = 64*2
    when c*5
      @switch_backs[n].oy = 64*1
    when c*6
      @switch_backs[n].oy = 64*0
      @lever_stop = true
    end
    @lever_count += 1
  end
  #--------------------------------------------------------------------------
  # ■ スロットボタンのアニメーションを初期化
  #--------------------------------------------------------------------------
  def reset(n)
    if @switch_backs[n] != nil
      @switch_backs[n].oy = 0
      @lever_count = 0
    end
  end
  #--------------------------------------------------------------------------
  # ■ 解放
  #--------------------------------------------------------------------------
  def dispose
    if @switch_backs[@i].bitmap != nil
      @switch_backs[@i].bitmap.dispose
    end
    if @switch_backs[@i].viewport != nil
      @switch_backs[@i].viewport.dispose
    end
    @switch_backs[@i].dispose
  end
end
#==============================================================================
# ■ Window_Slot_pattern
#==============================================================================
class Window_Slot_pattern
  include HIDE_SLOT
  attr_accessor :slot_dataes
  attr_accessor :pattern_stop
  #--------------------------------------------------------------------------
  # ■ オブジェクト初期化
  #--------------------------------------------------------------------------
  def initialize(i)
    @i = i
    @slot_backs = []
    @slot_dataes = []
    @pattern_stop = false
    # □絵柄パターンを取得
    if $game_temp.slot_pattern != nil
      @data = random_list?(HIDE_SLOT::PATTERN[$game_temp.slot_pattern][i])
    else
      @data = random_list?
    end
    # ■スロットの絵柄を作成
    make_slot_dataes?(i)
  end
  #--------------------------------------------------------------------------
  # ■ ランダムにスロット絵柄リストを作成
  #--------------------------------------------------------------------------
  def random_list?(list = [],slot = [])
    #…………………………………………………………………………………………………
    # ■スロット絵柄リストの作成
    #…………………………………………………………………………………………………
    if list != []
      # □手動リストの作成
      new_list = []
      for i in list.keys
        new_list += [i]*(list[i])
      end
      list = new_list
    else
      # □デフォルトリストの作成
      for i in 0..7
        list += [i]*((i+1)*3)
      end
    end
    #…………………………………………………………………………………………………
    # ■リストの要素が無くなるまでループ
    #…………………………………………………………………………………………………
    while list.size != 0
      # □ランダムにリスト番号を決定
      n = rand(list.size)
      # □リスト番号を格納
      slot.push(list[n])
      # □リストからリスト番号を削除
      list.slice!(n)
    end
    return slot
  end
  #--------------------------------------------------------------------------
  # ■ スロットの絵柄を作成
  #--------------------------------------------------------------------------
  def make_slot_dataes?(i)
    # □絵柄パターンの前後が繋がるように補正
    max1 = @data[(@data.size - 1)]
    max2 = @data[(@data.size - 2)]
    @data.push(@data[0])
    @data.push(@data[1])
    @data.unshift(max1)
    @data.unshift(max2)
    # □絵柄パターンを代入
    @slot_dataes[i] = @data
    # □スロットの絵柄を作成
    @slot_backs[i] = Sprite.new(Viewport.new(60+80+i*100,80,80,80*3))
    if HIDE_SLOT::DEBUG
      @slot_backs[i].viewport.color = Color.new(255,255,255,100)
    end
    @slot_backs[i].bitmap = Bitmap.new(60+80,80*@slot_dataes[i].size)
    for n in 0...@slot_dataes[i].size
      pic = RPG::Cache.windowskin(HIDE_SLOT::GRAPHIC)
      case @slot_dataes[i][n]
      when 0,1,2,3
        pry = @slot_dataes[i][n]*80
        prx = 0
      else
        pry = (@slot_dataes[i][n]-4)*80
        prx = 80
      end
      @slot_backs[i].bitmap.blt(0,n*80,pic,Rect.new(prx,pry,80,80))
    end
    # □絵柄パターンの初期値をランダムに決定
    @slot_backs[i].oy = (rand(@slot_dataes[i].size-4)) * 80
  end
  #--------------------------------------------------------------------------
  # ■ 現在の絵柄を取得
  #--------------------------------------------------------------------------
  def pattern?(n)
    #□絵柄画像の高さ(80)で割った場合、余りが0ならば停止
    if @slot_backs[n].oy % 80 == 0
      num = @slot_backs[n].oy / 80
      return [@slot_dataes[n][num],@slot_dataes[n][num+1],@slot_dataes[n][num+2]]
    end
    return nil
  end
  #--------------------------------------------------------------------------
  # ■ スロットの停止判定
  #--------------------------------------------------------------------------
  def move?(n,stop)
    if stop == false
      #□絵柄画像の高さ(80)で割った場合、余りが0ならば停止
      if @slot_backs[n].oy % 80 == 0
        @pattern_stop = true
        return false
      else
        return true
      end
    end
    return true
  end
  #--------------------------------------------------------------------------
  # ■ フレーム更新
  #--------------------------------------------------------------------------
  def update(n,switch,stop)
    if @slot_backs[n].oy <= 0
      @slot_backs[n].oy = (@slot_dataes[n].size-4) * 80
    else
      #…………………………………………………………………………………………………
      # ■ 停止ボタンが押された場合
      #…………………………………………………………………………………………………
      if switch && stop
        @slot_backs[n].oy -= 10
      #…………………………………………………………………………………………………
      # ■ 完全に停止する場合
      #…………………………………………………………………………………………………
      elsif switch && stop == false
        @slot_backs[n].oy -= 5
      #…………………………………………………………………………………………………
      # ■ 通常の回転(停止ボタンが押されていない)
      #…………………………………………………………………………………………………
      elsif switch == false && stop
        @slot_backs[n].oy -= 20
      end
      #…………………………………………………………………………………………………
      # ■ スロット回転SEを演奏
      #…………………………………………………………………………………………………
      if @slot_backs[n].oy % 80 == 0 && n == 2
        $game_system.se_play(RPG::AudioFile.new(HIDE_SLOT::MOVE_SE))
      end
      #…………………………………………………………………………………………………
      # ■ バグ対策
      #…………………………………………………………………………………………………
      if @slot_backs[n].oy < 0
        @slot_backs[n].oy = (@slot_dataes[n].size-4) * 80
      end
      if @slot_backs[n].oy > (@slot_dataes[n].size-4) * 80
        @slot_backs[n].oy = (@slot_dataes[n].size-4) * 80
      end
    end
  end
  #--------------------------------------------------------------------------
  # ■ 解放
  #--------------------------------------------------------------------------
  def dispose
    if @slot_backs[@i].bitmap != nil
      @slot_backs[@i].bitmap.dispose
    end
    if @slot_backs[@i].viewport != nil
      @slot_backs[@i].viewport.dispose
    end
    @slot_backs[@i].dispose
  end
end
#==============================================================================
# ■ Window_Slot_top
#==============================================================================
class Window_Slot_top
  include HIDE_SLOT
  #--------------------------------------------------------------------------
  # ■ オブジェクト初期化
  #--------------------------------------------------------------------------
  def initialize
    @slot_top = Sprite.new
    @slot_top.x = 140
    @slot_top.y = 80
    @slot_top.bitmap = Bitmap.new(500,240)
    refresh
  end
  #--------------------------------------------------------------------------
  # ■ 文字装飾
  #--------------------------------------------------------------------------
  def text_make?(bitmap,size,c,font,bold = false)
    bitmap.font.size = size
    bitmap.font.bold = bold
    bitmap.font.name = font
    bitmap.font.color = Color.new(c[0],c[1],c[2],c[3])
  end
  #--------------------------------------------------------------------------
  # ■ 更新
  #--------------------------------------------------------------------------
  def refresh
    pic = RPG::Cache.windowskin(HIDE_SLOT::SLOT_BACK)
    @slot_top.bitmap.blt(0,0,pic,Rect.new(80,0,80,80*3))
    @slot_top.bitmap.blt(100,0,pic,Rect.new(80,0,80,80*3))
    @slot_top.bitmap.blt(100*2,0,pic,Rect.new(80,0,80,80*3))
    #…………………………………………………………………………………………………
    # ■ 当りパターンの描画
    #…………………………………………………………………………………………………
    rate = HIDE_SLOT::RATE[$game_temp.slot_type]
    icon = RPG::Cache.windowskin(HIDE_SLOT::SLOT_ICON)
    fonts = Copy_Font.new(22,false,false,true,false,["Georgia","ＭＳ ゴシック"],
    Color.new(40,40,40,255),Color.new(80,80,80,100))
    for i in 0...rate.size
      # □アイコンの描画(3個)
      rect_x = i >= 4 ? 20 : 0
      rect_y = i >= 4 ? (i-4)*20 : i*20
      @slot_top.bitmap.blt(268+30,4+28*i+8,icon,Rect.new(rect_x,rect_y,20,20))
      @slot_top.bitmap.blt(268+50,4+28*i+8,icon,Rect.new(rect_x,rect_y,20,20))
      @slot_top.bitmap.blt(268+70,4+28*i+8,icon,Rect.new(rect_x,rect_y,20,20))
      # □当りパターンの描画
      @slot_top.bitmap.draw_cache_text(268+4,4+28*i,160,32,rate[i].to_s,2,fonts)
    end
  end
  #--------------------------------------------------------------------------
  # ■ 解放
  #--------------------------------------------------------------------------
  def dispose
    if @slot_top.bitmap != nil
      @slot_top.bitmap.dispose
    end
    @slot_top.dispose
  end
end  
#==============================================================================
# ■ Window_Slot_help
#==============================================================================
class Window_Slot_help
  include HIDE_SLOT
  #--------------------------------------------------------------------------
  # ■ オブジェクト初期化
  #--------------------------------------------------------------------------
  def initialize
    # ■スロットヘルプウィンドウを作成
    @help_window = Sprite.new
    @help_window.x = 60
    @help_window.bitmap = Bitmap.new(80,336)
    # ■コイン投入画像とヘルプの更新
    refresh(0)
  end
  #--------------------------------------------------------------------------
  # ■ コイン投入画像とヘルプの更新
  #--------------------------------------------------------------------------
  def refresh(num = 0)
    type = [2]*5
    for i in 0...num
      type[i] = 3
    end
    @help_window.bitmap.clear
    pic = RPG::Cache.windowskin(HIDE_SLOT::SLOT_BACK)
    h = pic.height/5
    @help_window.bitmap.blt(0,80+80+80/2-h/2,pic,Rect.new(80*type[0],h*0,80,h))
    @help_window.bitmap.blt(0,80+80/2-h/2,pic,Rect.new(80*type[1],h*1,80,h))
    @help_window.bitmap.blt(0,80+80*2+80/2-h/2,pic,Rect.new(80*type[2],h*2,80,h))
    @help_window.bitmap.blt(0,80-h+h/2,pic,Rect.new(80*type[3],h*3,80,h))
    @help_window.bitmap.blt(0,80+80*3-h/2,pic,Rect.new(80*type[4],h*4,80,h))
  end
  #--------------------------------------------------------------------------
  # ■ 解放
  #--------------------------------------------------------------------------
  def dispose
    if @help_window.bitmap != nil
      @help_window.bitmap.dispose
    end
    @help_window.dispose
  end
end
#==============================================================================
# ■ Scene_Slot
#==============================================================================
class Scene_Slot
  #--------------------------------------------------------------------------
  # ■ オブジェクト初期化
  #--------------------------------------------------------------------------
  def initialize
    @move = @start = @stop0 = @stop1 = @stop2 = false
    @coin_slot = 0
    @old_coin = $game_party.coin
    # □マップ BGM を記憶し、BGM を停止
    $game_temp.map_bgm = $game_system.playing_bgm
    $game_system.bgm_stop
    # □スロット BGM を演奏
    $game_system.bgm_play(RPG::AudioFile.new(HIDE_SLOT::BGM))
  end
  #--------------------------------------------------------------------------
  # ■ メイン処理
  #--------------------------------------------------------------------------
  def main
    # □スロットウィンドウ背景を作成
    @slot_window_back = Window_Coin_Game_back.new(HIDE_SLOT::BACK,"COIN",HIDE_SLOT::COIN[$game_temp.slot_type],408,402)
    pic = RPG::Cache.windowskin(HIDE_SLOT::SLOT_BACK)
    @slot_window_back.draw_rect(60+80,80,pic,Rect.new(0,0,80,80*3))
    @slot_window_back.draw_rect(60+80+100,80,pic,Rect.new(0,0,80,80*3))
    @slot_window_back.draw_rect(60+80+100*2,80,pic,Rect.new(0,0,80,80*3))
    
    # □スロットのボタンを作成
    @slot_switch_backs = []
    for i in 0..3
      @slot_switch_backs.push(Window_Slot_switch.new(i))
    end
    # □スロットの絵柄パターンを作成
    @slot_pattern = []
    for i in 0..2
      @slot_pattern.push(Window_Slot_pattern.new(i))
    end
    # □コイン投入画像ウィンドウの作成
    @help_window = Window_Slot_help.new
    # □当たり演出ウィンドウを作成
    @slot_window_under = Window_Slot_hit.new
    # □スロットの絵柄の枠を作成
    @slot_window_top = Window_Slot_top.new
    # □コイン数値ウィンドウを作成
    fonts = Copy_Font.new(26,true,false,true,false,["Arial","ＭＳ ゴシック"],Color.new(40,40,40,255),Color.new(80,80,80,100))
    @coin_window = Window_digits_number.new(440,416,5000,$game_party.coin,10,10,fonts)
    # トランジション実行
    Graphics.transition
    # メインループ
    loop do
      # ゲーム画面を更新
      Graphics.update
      # 入力情報を更新
      Input.update
      # フレーム更新
      update
      # 画面が切り替わったらループを中断
      if $scene != self
        break
      end
    end
    # トランジション準備
    Graphics.freeze
    # ウィンドウを解放
    @slot_window_back.dispose
    @slot_pattern.each{ |a| a.dispose }
    @slot_switch_backs.each{ |a| a.dispose }
    @slot_window_top.dispose
    @slot_window_under.dispose
    @help_window.dispose
    @coin_window.dispose
  end
  #--------------------------------------------------------------------------
  # ■ コイン配当/当り絵柄を獲得
  #--------------------------------------------------------------------------
  def slot_hit?(n,s0,s1,s2)
    unless s0.include?(nil) && s1.include?(nil) && s2.include?(nil)
      rate = HIDE_SLOT::RATE[$game_temp.slot_type]
      # □[コイン配当,当り絵柄]を獲得
      case n
      when 1 # 真中
        if s0[1] == s1[1] && s0[1] == s2[1]
          return [rate[s0[1]],s0[1]]
        end
      when 2 # 上
        if s0[0] == s1[0] && s0[0] == s2[0]
          return [rate[s0[0]],s0[0]]
        end
      when 3 # 下
        if s0[2] == s1[2] && s0[2] == s2[2]
          return [rate[s0[2]],s0[2]]
        end
      when 4 # 左斜め
        if s0[0] == s1[1] && s0[0] == s2[2]
          return [rate[s0[0]],s0[0]]
        end
      when 5 # 右斜め
        if s0[2] == s1[1] && s0[2] == s2[0]
          return [rate[s0[2]],s0[2]]
        end
      end
    end
    return [0]
  end
  #--------------------------------------------------------------------------
  # ■ スロットの終了
  #--------------------------------------------------------------------------
  def slot_end
    unless @slot_switch_backs[1].lever_switch && @slot_switch_backs[2].lever_switch && 
      @slot_switch_backs[3].lever_switch
      if @stop0 && @stop1 && @stop2
        # □次のスロット開始まで待つ
        time_up = 1
        #…………………………………………………………………………………………………
        # ■ 当り判定
        #…………………………………………………………………………………………………
        s0 = @slot_pattern[0].pattern?(0)
        s1 = @slot_pattern[1].pattern?(1)
        s2 = @slot_pattern[2].pattern?(2)
        gain = 0
        hits = [false]*8
        slot_hits = []
        for i in 1..@coin_slot
          if slot_hit?(i,s0,s1,s2)[0] != 0
            hit = slot_hit?(i,s0,s1,s2)[1]
            hits[hit] = true
            slot_hits.push(i-1)
          end
          gain += slot_hit?(i,s0,s1,s2)[0]
        end
        @slot_window_under.refresh(hits,slot_hits)
        #…………………………………………………………………………………………………
        # ■ 当りの場合の効果音を演奏(ME)
        #…………………………………………………………………………………………………
        if gain > 0
          # □大当たりの場合
          if gain >= HIDE_SLOT::ME_RATE_MAX[$game_temp.slot_type]
            $game_system.me_play(RPG::AudioFile.new(HIDE_SLOT::HIT_ME_MAX))
            # □次のスロット開始まで待つ(MEの演奏時間)
            time_up = HIDE_SLOT::ME_MAX_TIME
          else
            $game_system.me_play(RPG::AudioFile.new(HIDE_SLOT::HIT_ME))
            # □次のスロット開始まで待つ(MEの演奏時間)
            time_up = HIDE_SLOT::ME_TIME
          end
        end
        #…………………………………………………………………………………………………
        # ■ 所持コインを増やす
        #…………………………………………………………………………………………………
        $game_party.gain_coin(gain)
        #…………………………………………………………………………………………………
        # ■ スロットアニメーションの初期化
        #…………………………………………………………………………………………………
        @slot_switch_backs.each{ |a| a.lever_count = 0 }
        @slot_switch_backs.each{ |a| a.lever_switch = true }
        #…………………………………………………………………………………………………
        # ■ 連続ゲームの判定(必要なコインを持っているか)
        #…………………………………………………………………………………………………
        old_coin_slot = @coin_slot
        while $game_party.coin < (HIDE_SLOT::COIN[$game_temp.slot_type] * @coin_slot)
          @coin_slot -= 1
        end
        if old_coin_slot != @coin_slot
          @help_window.refresh(@coin_slot)
        end
        if @coin_slot <= 0
          @coin_slot = 0
          @help_window.refresh(@coin_slot)
        end
        #…………………………………………………………………………………………………
        # ■ 次のスロット開始まで待つ
        #…………………………………………………………………………………………………
        time = 0
        while time < time_up
          # □ゲーム画面を更新
          Graphics.update
          # □回転数値の更新(所持コイン)
          @coin_window.update($game_party.coin)
          # □当りの演出を更新
          @slot_window_under.update
          if @slot_window_under.opacity? <= 10
            time += 1
          end
        end
        #…………………………………………………………………………………………………
        # ■ スロットボタンの初期化
        #…………………………………………………………………………………………………
        @slot_window_under.reset
        @start = @stop0 = @stop1 = @stop2 = false
        @slot_pattern.each{ |a| a.pattern_stop = false}
        for i in 0...@slot_switch_backs.size
          @slot_switch_backs[i].reset(i)
          @slot_switch_backs[i].lever_stop = false
        end
      end
    end
    return
  end
  #--------------------------------------------------------------------------
  # ■ フレーム更新
  #--------------------------------------------------------------------------
  def update
    #…………………………………………………………………………………………………
    # ■ 回転数値の更新(所持コイン)
    #…………………………………………………………………………………………………
    @coin_window.update($game_party.coin)
    #…………………………………………………………………………………………………
    # ■ スロット@ボタンのアニメーション
    #…………………………………………………………………………………………………
    if @stop0 && @slot_switch_backs[1].lever_stop == false
      @slot_switch_backs[1].update(1)
    end
    #…………………………………………………………………………………………………
    # ■ スロットAボタンのアニメーション
    #…………………………………………………………………………………………………
    if @stop1 && @slot_switch_backs[2].lever_stop == false
      @slot_switch_backs[2].update(2)
    end
    #…………………………………………………………………………………………………
    # ■ スロットBボタンのアニメーション
    #…………………………………………………………………………………………………
    if @stop2 && @slot_switch_backs[3].lever_stop == false
      @slot_switch_backs[3].update(3)
    end
    if @coin_slot > 0 && @start
      #…………………………………………………………………………………………………
      # ■ スタートバーのアニメーション
      #…………………………………………………………………………………………………
      if @slot_switch_backs[0].lever_count < 21
        if @slot_switch_backs[0].lever_count == 0
          # □スロット回転の開始SEを演奏
          $game_system.se_play(RPG::AudioFile.new(HIDE_SLOT::START_SE))
          
          # □コインを減らす(賭け金)
          $game_party.lose_coin((HIDE_SLOT::COIN[$game_temp.slot_type] * @coin_slot))
        end
        @slot_switch_backs[0].update(0)
        return
      end
      #…………………………………………………………………………………………………
      # ■ スロット@の回転
      #…………………………………………………………………………………………………
      if @slot_pattern[0].move?(0,@slot_switch_backs[1].lever_switch)
        @slot_pattern[0].update(0,@stop0,@slot_switch_backs[1].lever_switch)
      end
      #…………………………………………………………………………………………………
      # ■ スロットAの回転
      #…………………………………………………………………………………………………
      if @slot_pattern[1].move?(1,@slot_switch_backs[2].lever_switch)
        @slot_pattern[1].update(1,@stop1,@slot_switch_backs[2].lever_switch)
      end
      #…………………………………………………………………………………………………
      # ■ スロットBの回転
      #…………………………………………………………………………………………………
      if @slot_pattern[2].move?(2,@slot_switch_backs[3].lever_switch)
        @slot_pattern[2].update(2,@stop2,@slot_switch_backs[3].lever_switch)
        # □スロット回転中フラグをON
        @move = true
      else
        @move = false
      end
      #…………………………………………………………………………………………………
      # ■ 当り判定
      #…………………………………………………………………………………………………
      if @move == false && @slot_pattern[0].pattern_stop && 
        @slot_pattern[1].pattern_stop && @slot_pattern[2].pattern_stop && 
        @slot_switch_backs[0].lever_stop && @slot_switch_backs[1].lever_stop && 
        @slot_switch_backs[2].lever_stop && @slot_switch_backs[3].lever_stop
        slot_end
        return
      end
    end
    #…………………………………………………………………………………………………
    # ■ B ボタンが押された場合
    #…………………………………………………………………………………………………
    if Input.trigger?(Input::B)
      unless @move
        # キャンセル SE を演奏
        $game_system.se_play($data_system.cancel_se)
        # □スロット開始前の BGM に戻す
        $game_system.bgm_play($game_temp.map_bgm)
        # マップ画面に切り替え
        $scene = Scene_Map.new
        return
      end
    end
    #…………………………………………………………………………………………………
    # ■ 上 ボタンが押された場合
    #…………………………………………………………………………………………………
    if Input.repeat?(Input::UP)
      unless @move
        if @coin_slot < 5 && 
          $game_party.coin >= (HIDE_SLOT::COIN[$game_temp.slot_type] * (@coin_slot+1))
          # □コインを増やすSEを演奏
          $game_system.se_play(RPG::AudioFile.new(HIDE_SLOT::GAIN_COIN_SE))
          @coin_slot += 1
          # □ヘルプの更新
          @help_window.refresh(@coin_slot)
        end
      end
    end
    #…………………………………………………………………………………………………
    # ■ 下 ボタンが押された場合
    #…………………………………………………………………………………………………
    if Input.repeat?(Input::DOWN)
      unless @move
        if @coin_slot > 0
          # □コインを減らすSEを演奏
          $game_system.se_play(RPG::AudioFile.new(HIDE_SLOT::LOSE_COIN_SE))
          @coin_slot -= 1
          # □ヘルプの更新
          @help_window.refresh(@coin_slot)
        end
      end
    end
    #…………………………………………………………………………………………………
    # ■ C ボタンが押された場合
    #…………………………………………………………………………………………………
    if Input.trigger?(Input::C)
      #…………………………………………………………………………………………………
      # ■ スロット回転の開始
      #…………………………………………………………………………………………………
      if @start == false && @coin_slot > 0 && @stop0 == false && @stop1 == false && @stop2 == false
        @start = true
        return
      end
      #…………………………………………………………………………………………………
      # ■ スロット回転の停止
      #…………………………………………………………………………………………………
      if @start
        #…………………………………………………………………………………………………
        # ■ スロット@の停止
        #…………………………………………………………………………………………………
        if @stop0 == false && @stop1 == false && @stop2 == false
          # □スロット回転の停止SEを演奏
          $game_system.se_play(RPG::AudioFile.new(HIDE_SLOT::PUSH_SE))
          @stop0 = true
          return
        end
        #…………………………………………………………………………………………………
        # ■ スロットAの停止
        #…………………………………………………………………………………………………
        if @stop0 && @stop1 == false && @stop2 == false
          # □スロット回転の停止SEを演奏
          $game_system.se_play(RPG::AudioFile.new(HIDE_SLOT::PUSH_SE))
          @stop1 = true
          return
        end
        #…………………………………………………………………………………………………
        # ■ スロットBの停止
        #…………………………………………………………………………………………………
        if @stop0 && @stop1 && @stop2 == false
          # □スロット回転の停止SEを演奏
          $game_system.se_play(RPG::AudioFile.new(HIDE_SLOT::PUSH_SE))
          @stop2 = true
          return
        end
      end
      return
    end
  end
end