기타

요리스크립트 (구)

by *ps인간 posted Jan 26, 2009
?

단축키

Prev이전 문서

Next다음 문서

ESC닫기

크게 작게 위로 아래로 댓글로 가기 인쇄


#실패시의 요리 지정.
#set_fail_food_id(을)를 설정합니다.
#기본적으로
#@fail_food_id[0] = 50   # 디폴트치
#의 우측의 숫자 부분에 조금 전 만들어 둔 실패 요리의 아이템ID을 넣어 준다면 좋습니다.
#
#@fail_food_id[1] = 49
#(이)라든지 하면 , 요리마다 실패 요리의 설정이 가능합니다.
#
#
#
#최후입니다.
#역시 , 조금 전의 바로 아래의 것set_visible_Switche을 설정입니다.
#이것은 , 요리를 표시하는지 어떤지의 판정용의 게임 스윗치 넘버의 설정입니다.
#
#@visible_Switche[3] = 20
#
#이 우측의 숫자가 게임 스윗치 넘버입니다.
#위의 예에서는 ,3번째에 표시하는 요리는 게임 스윗치20차례가ON의 때
#표시되게 되어 있습니다.
#
#
#기본적인 설정은 이상입니다.
#
#
#
#○엑터 개별의 요리 난도 보정
#이것은 , 무리에 하지 않아도 좋습니다만 ,
#엑터마다 요리할 수 있도록(듯이) 설정해 있다면 , 설정해 두는 것이 좋다고 생각합니다.
#그렇다고 하는 것보다도 , 모처럼 엑터마다 요리할 수 있는데
#전원 같은 성능이라면 , 완전한 무의미하네요(땀)
#파티 전원이 요리하는 설정의 경우는 , 무시해 좋습니다.
#설정해도 , 의미 없습니다.
#
#·설정의 방법
##--------------------------------------------------------------------------
## ● 엑터별의 숙련 난도 보정의 설정
##--------------------------------------------------------------------------
# def set_actor_cook_difficulty
#↑여기입니다. 조금 전의 바로 아래.
#
#설정한 값이 , 요리 난도(몇회 요리하면(자) 숙련도가 오를까의 기본치)에 가산됩니다.
#마이너스 지정도 가능합니다.
#
#when 1 # 주먹밥
# @actor_cook_difficulty[1] = 0   #아르시스
# @actor_cook_difficulty[2] = 1   #바질
# @actor_cook_difficulty[7] = 0   #그로리아
# @actor_cook_difficulty[8] = 2   #히르다
#
#보일 수 있으면 안다고 생각합니다만 ,[]안의 숫자가 엑터ID로
#오른쪽의 숫자가 , 요리 난도에 가산되는 값입니다.
#
#
#○추가 식품 재료에 대해
#추가 식품 재료란 , 이른바 토핑같은 물건입니다.
#알고 있는 사람은 , 모 「군과 서로 영향을 주는 RPG  」의 아레를 상상해 주세요.
#이라고 할까 , 이 요리 시스템 자체 아레를 참고로 하기도 하는(땀)
#추가 식품 재료를 가지고 있지 않아도 요리는 할 수 있습니다.
#사용하면 , 요리의 효과에 추가 식품 재료의 효과가 추가됩니다.
#설정은 set_add_mate 으로 가고 있습니다.
#최대로 최대 숙련도 + 1 개까지 추가 식품 재료를 설정할 수 있습니다만 ,
#문답 무용으로 식품 재료를 소비해 버리므로 , 너무 많이 설정하면(자)
#반대로 사용하기 어려운 요리가 되어 버릴지도 모릅니다.

class Cook_Data
  #--------------------------------------------------------------------------
  # ● 참조 아이템ID의 설정
  #--------------------------------------------------------------------------
  def set_cookid
    # ↓이하 , 설정용
   
    @cookidset[1] = 51
    @cookidset[2] = 52
    @cookidset[3] = 53
    @cookidset[4] = 54
   
    # ↑여기까지
  end
  #--------------------------------------------------------------------------
  # ● 요리 레시피의 설정
  #--------------------------------------------------------------------------
  def set_cook_recipe
    @recipe[0] = {}   # デフォルト値(디폴트치(만지지 않게))
   
    # ↓이하 , 설정용
   
    @recipe[1] = {41=>1, 43=>1}
    @recipe[2] = {"밥계"=>1, "김계"=>2}
    @recipe[3] = {"야채계"=>2, 41=>1}
    @recipe[4] = {46=>3}
   
    # ↑여기까지
  end
  #--------------------------------------------------------------------------
  # ● 실패시의 요리의 설정
  #--------------------------------------------------------------------------
  def set_fail_food_id
    # ↓이하, 설정용
   
    @fail_food_id[0] = 50   # 디폴트치
   
    # ↑여기까지
  end
  #--------------------------------------------------------------------------
  # ● 요리 가부 판저용ㅇ 스윗치 넘버의 설정
  #--------------------------------------------------------------------------
  def set_visible_Switche
    @visible_Switche[0] = 0 # 디폴트치(만지지 않게)
   
    # ↓이하 , 설정용
   
    @visible_Switche[3] = 20
   
    # ↑여기까지
  end
end

class FoodData
  #--------------------------------------------------------------------------
  # ● 엑터별의 숙련 난도 보정의 설정
  #--------------------------------------------------------------------------
  def set_actor_cook_difficulty
    @actor_cook_difficulty = []
    @actor_cook_difficulty[0] = 0 # 데포치(만지지 않게)
   
    # ↓이하 , 설정용
   
    case @id # 요리ID
    when 1 # 주먹밥
      @actor_cook_difficulty[1] = 0   #아르시스
      @actor_cook_difficulty[2] = 1   #바질
      @actor_cook_difficulty[7] = 0   #그로리아
      @actor_cook_difficulty[8] = 2   #히르다
    when 2 # 초결말
      @actor_cook_difficulty[1] = 0   #아르시스
      @actor_cook_difficulty[2] = 1   #바질
      @actor_cook_difficulty[7] = -1  #그로리아
      @actor_cook_difficulty[8] = 2   #히르다
    when 3 # 야채볶음
      @actor_cook_difficulty[1] = -1  #아르시스
      @actor_cook_difficulty[2] = 1   #바질
      @actor_cook_difficulty[7] = 0   #그로리아
      @actor_cook_difficulty[8] = 2   #히르다
    when 4 # 프루츠 펀치
      @actor_cook_difficulty[1] = -1  #아르시스
      @actor_cook_difficulty[2] = 1   #바질
      @actor_cook_difficulty[7] = 3   #그로리아
      @actor_cook_difficulty[8] = -3  #히르다
    end
   
    # ↑여기까지
   
  end
  #--------------------------------------------------------------------------
  # ● 추가 식품 재료의 설정
  #--------------------------------------------------------------------------
  def set_add_mate
    @add_mate = []
    @add_mate[0] = [nil, nil, nil, nil, nil, nil] #デフォ値(こっちはいじらない)
    #데포치는 , 엑터별로 추가 식품 재료를 설정하지 않는 경우에 사용됩니다.
    #따라서 , 그 경우는 @add_mate[0] 만 설정하면 좋습니다.
    #[nil, nil, nil, 45, nil, nil]의 부분에는 식품 재료의 아이템ID을 넣습니다.
    #왼쪽으로부터 숙련도가0,1,2,3,4,5의 때에 추가되는 아이템ID을 넣어 주세요.
    #굳이 추가하고 싶지 않을 때는 nil 을 넣어 주세요.
    #숙련도 기능을 사용하고 있지 않을 때는 숙련도0로서 판정되므로 ,
    #숙련도 기능은 사용하지 않지만 , 엑터별로 추가 식품 재료를 사용하고 싶은
    #이라고 하는 경우는 , 숙련도0의 장소(제일 좌측)으로 추가 식품 재료의 아이템ID을 넣어 주세요.
    #
    #추가 식품 재료가 사용되었을 경우는 ,
    #식품 재료의HPSP회복율 ,HPSP회복치 , 플러스 스테이트 , 마이너스 스테이트
    #가 그대로 요리의 효과에 추가됩니다.
    case @id # 요리ID
    when 1 # 주먹밥
      @add_mate[0] = [44, nil, nil, nil, nil, nil] #데포치
      @add_mate[1] = [45, nil, nil, nil, nil, 46] #아르시스
      @add_mate[2] = [43, nil, nil, nil, nil, nil] #바질
      @add_mate[7] = [nil, nil, nil, nil, nil, nil] #그로리아
      @add_mate[8] = [46, nil, nil, nil, nil, nil] #히다
    when 2 # 초결말
      @add_mate[0] = [41, 42, 43, 44, 45, 46] #데포치
      @add_mate[1] = [41, 42, 43, 44, 45, 46] #아르시스
      @add_mate[2] = [nil, nil, nil, nil, nil, 42] #바질
      @add_mate[7] = [nil, nil, nil, nil, nil, nil] #그로리아
      @add_mate[8] = [46, 46, nil, nil, nil, 46] #히르다
    when 3 # 야채 아픈
      @add_mate[0] = [41, 42, 43, 44, 45, 46] #데포치
      @add_mate[1] = [41, 42, 43, 44, 45, 46] #아르시스
      @add_mate[2] = [nil, nil, nil, nil, nil, 42] #바질
      @add_mate[7] = [nil, nil, nil, nil, nil, nil] #그로리아
      @add_mate[8] = [46, nil, nil, nil, 46, 46] #히르다
    when 4 # 거절하는
      @add_mate[0] = [nil, nil, 43, 44, 45, 46] #데포치
      @add_mate[1] = [nil, nil, 46, nil, nil, nil] #아르시스
      @add_mate[2] = [nil, nil, nil, nil, nil, 42] #바질
      @add_mate[7] = [nil, nil, nil, nil, nil, nil] #그로리아
      @add_mate[8] = [nil, 46, 46, 46, 46, 46] #히르다
    end
  end
end


class Cook_Data
  attr_reader :cookidset
  attr_reader :recipe
  attr_reader :cookmastery_revise
  attr_reader :cook_difficulty
  attr_reader :fail_food_id
  attr_reader :visible_Switche
  #--------------------------------------------------------------------------
  # ● オブジェクト初期化
  #--------------------------------------------------------------------------
  def initialize
    @cookidset = [0]
    @recipe = []
    @fail_food_id = []
    @visible_Switche = []
    set_cookid
    set_cook_recipe
    set_fail_food_id
    set_visible_Switche
  end
end

class FoodData
  include Cooking_System_Config
  attr_reader :id
  attr_reader :item_id
  attr_reader :name
  attr_reader :icon_name
  attr_reader :description
  attr_reader :recover_hp
  attr_reader :recover_hp_rate
  attr_reader :recover_sp
  attr_reader :recover_sp_rate
  attr_reader :plus_state_set
  attr_reader :minus_state_set
  attr_reader :base_success
  attr_reader :cook_se
  attr_reader :common_event
  attr_reader :recipe
  attr_reader :cookmastery_revise
  attr_reader :cook_difficulty
  attr_reader :fail_food_id
  attr_reader :visible_Switche
  attr_reader :actor_cook_difficulty
  attr_reader :add_mate
  #--------------------------------------------------------------------------
  # ● オブジェクト初期化
  #--------------------------------------------------------------------------
  def initialize(item_id)
    @item_id = item_id               #참조 아이템ID
    @id = set_id                     #요리ID
    @name = ""                       #요리명
    @icon_name = ""                  #요리 아이콘 네임
    @description = ""                #요리 설명
    @recover_hp = 0                  #HP회복치
    @recover_hp_rate = 0             #HP회복%
    @recover_sp = 0                  #SP회복치
    @recover_sp_rate = 0             #SP회복%
    @plus_state_set = []             #추가 스테이트
    @minus_state_set = []            #제거 스테이트
    @base_success = 100              #기본 성공율
    @cook_se = nil                   #요리시SE
    @common_event = 0                #요리시 기동 코먼 이벤트ID
    @cookmastery_revise = []         #회복치 숙련도 보정
    @cook_difficulty = []            #요리 난도
   
    @recipe = {}                     #요리 레시피
    @fail_food_id = []               #실패시의 아이템ID
    @visible_Switche = []            #표시 스윗치 넘버
    @actor_cook_difficulty = []
    @add_mate = []
    #@need_item = {}                 #
    set_up
  end
  #--------------------------------------------------------------------------
  # ● ID를 세트
  #--------------------------------------------------------------------------
  def set_id
    id = $game_temp.cook_system_data.cookidset.index(@item_id)
    return @id = 0 if id == nil
    return id
  end
  #--------------------------------------------------------------------------
  # ● 각 정보의 셋업
  #--------------------------------------------------------------------------
  def set_up
    item = $data_items[@item_id]
    @name = item.name
    @icon_name = item.icon_name
    @description = item.description
    @recover_hp = item.recover_hp
    @recover_hp_rate = item.recover_hp_rate
    @recover_sp = item.recover_sp
    @recover_sp_rate = item.recover_sp_rate
    @plus_state_set = item.plus_state_set
    @minus_state_set = item.minus_state_set
    @base_success = item.hit
    @cook_se = item.menu_se
    @common_event = item.common_event_id
    @cook_difficulty = item.pdef_f
    @cookmastery_revise = item.mdef_f
    @recipe = $game_temp.cook_system_data.recipe[@id]
    if @recipe == nil
      @recipe = {}
    end
    @fail_food_id = $game_temp.cook_system_data.fail_food_id[@id]
    if @fail_food_id == nil
      @fail_food_id = $game_temp.cook_system_data.fail_food_id[0]
    end
    @visible_Switche = $game_temp.cook_system_data.visible_Switche[@id]
    if @visible_Switche == nil
      @visible_Switche = $game_temp.cook_system_data.visible_Switche[0]
    end
    set_actor_cook_difficulty
    set_add_mate
  end
  #--------------------------------------------------------------------------
  # ● 料理の表示可否判定
  #--------------------------------------------------------------------------
  def show?
    return true if @visible_Switche == 0
    return $game_switches[@visible_Switche]
  end
  #--------------------------------------------------------------------------
  # ● 料理?行可否判定
  #--------------------------------------------------------------------------
  def cook_ok?
    need_item = @recipe.keys
    for id in need_item
      if id.is_a?(Numeric)
        return false if $game_party.item_number(id) < @recipe[id]
      elsif id.is_a?(String)
        item_set = food_category(id)
        return false if cook_need_item_number(item_set) < @recipe[id]
      end
    end
  end
  #--------------------------------------------------------------------------
  # ● 料理のカテゴリ名から必要食材を判定し食材IDの配列を返す
  #--------------------------------------------------------------------------
  def food_category(str)
    haveitem = $game_party.items.keys
    #haveitem.sort!
    need_item = []
    for id in haveitem
      next if $game_party.item_number(id) <= 0
      item = $data_items[id]
      for i in 0...item.element_set.size
        if $data_system.elements[item.element_set[i]] == str
          need_item.push(id)
          break
        end
      end
    end
    return need_item
  end
  #--------------------------------------------------------------------------
  # ● 必要食材?を返す
  #--------------------------------------------------------------------------
  def cook_need_item_number(item_set)
    if item_set.is_a?(Numeric)
      return $game_party.item_number(item_set)
    end
    number = 0
    for id in item_set
      number += $game_party.item_number(id)
    end
    return number
  end
  #--------------------------------------------------------------------------
  # ● 食材消費?理
  #--------------------------------------------------------------------------
  def lose_item
    used_item = []
    need_item = @recipe.keys
    for id in need_item
      if id.is_a?(Numeric)
        $game_party.lose_item(id, @recipe[id])
        count = @recipe[id]
        for i in 0...count
          used_item.push(id)
        end
      elsif id.is_a?(String)
        item_set = []
        count = @recipe[id]
        for i in 0...count
          item_set = food_category(id)
          ran = rand(item_set.size)
          $game_party.lose_item(item_set[ran], 1)
          used_item.push(item_set[ran])
        end
      end
    end
    return used_item
  end
  #--------------------------------------------------------------------------
  # ● 料理?果
  #--------------------------------------------------------------------------
  def cook_effect(cook_actor, fail=false, add_food=[])
    cm = cook_actor.cookmastery[@id]
    if cm == nil
      cook_actor.cookmastery[@id] = 0
      cm = 0
    end
    cm_r = cm * @cookmastery_revise
    success = @base_success + cm * COOK_SUCCESS_REVISE
    if fail == false
      return false if rand(100) > success
    end
   
    for actor in $game_party.actors
      actor.states_plus(@plus_state_set)
      actor.states_minus(@minus_state_set)
      recover_hp = actor.maxhp * (@recover_hp_rate + cm_r) / 100 + @recover_hp
      recover_sp = actor.maxsp * (@recover_sp_rate + cm_r) / 100 + @recover_sp
      for id in add_food
        item = $data_items[id]
        actor.states_plus(item.plus_state_set)
        actor.states_minus(item.minus_state_set)
        recover_hp += actor.maxhp * item.recover_hp_rate / 100 + item.recover_hp
        recover_sp += actor.maxsp * item.recover_sp_rate / 100 + item.recover_sp
      end
      actor.hp += recover_hp
      actor.sp += recover_sp
    end
    add_recover_hp_rate = 0
    add_recover_sp_rate = 0
    add_recover_hp = 0
    add_recover_sp = 0
    for id in add_food
      item = $data_items[id]
      add_recover_hp_rate += item.recover_hp_rate
      add_recover_sp_rate += item.recover_sp_rate
      add_recover_hp += item.recover_hp
      add_recover_sp += item.recover_sp
    end
    $game_temp.temp_recover_hp_rate = @recover_hp_rate + cm_r + add_recover_hp_rate
    $game_temp.temp_recover_sp_rate = @recover_sp_rate + cm_r + add_recover_sp_rate
    $game_temp.temp_recover_hp = @recover_hp + add_recover_hp
    $game_temp.temp_recover_sp = @recover_sp + add_recover_sp
   
    # 以下熟練度上昇?理
    if USE_COOK_MASTERY and fail == false
      if cook_actor.cookmastery[@id] < MAX_COOK_MASTERY
        if cook_actor.cookmastery_exp[@id] == nil
          cook_actor.cookmastery_exp[@id] = 1
        else
          cook_actor.cookmastery_exp[@id] += 1
        end
        if COOK_TYPE_SELECT == 1
          actor_difficulty = @actor_cook_difficulty[cook_actor.id]
        else
          actor_difficulty = 0
        end
        if actor_difficulty == nil
          actor_difficulty = @actor_cook_difficulty[0]
        end
        if cook_actor.cookmastery_exp[@id] >= @cook_difficulty + actor_difficulty
          cook_actor.cookmastery[@id] += 1
          cook_actor.cookmastery_exp[@id] = 0
        end
      end
    end
   
    # コモンイベント ID が有?の場合
    if @common_event > 0
      # コモンイベント呼び出し予約
      $game_temp.common_event_id = @common_event
    end
    return true
  end
end

class Game_Temp
  attr_reader :food_data
  attr_reader :cook_system_data
  attr_accessor :temp_recover_hp
  attr_accessor :temp_recover_hp_rate
  attr_accessor :temp_recover_sp
  attr_accessor :temp_recover_sp_rate
  attr_accessor :cookmastery
  alias temp_cook_system_data_initialize initialize
  def initialize
    temp_cook_system_data_initialize
    @cook_system_data = Cook_Data.new
    @food_data = nil
    @temp_recover_hp = 0
    @temp_recover_hp_rate = 0
    @temp_recover_sp = 0
    @temp_recover_sp_rate = 0
    #set_food_data
  end
  def set_food_data
    @food_data = []
    for i in 1...@cook_system_data.cookidset.size
      @food_data[i] = FoodData.new(@cook_system_data.cookidset[i])
    end
  end
end

class Game_Party
  attr_accessor :cookmastery
  attr_accessor :cookmastery_exp
  attr_accessor :cook_battle_count
  attr_reader :items
  #--------------------------------------------------------------------------
  # ● オブジェクト初期化
  #--------------------------------------------------------------------------
  alias cook_system_game_party_initialize initialize
  def initialize
    cook_system_game_party_initialize
    @cookmastery = {}
    @cookmastery_exp = {}
    @cook_battle_count = 0
  end
end

class Game_Actor < Game_Battler
  attr_accessor :cookmastery
  attr_accessor :cookmastery_exp
  #--------------------------------------------------------------------------
  # ● オブジェクト初期化
  #     actor_id : アクタ? ID
  #--------------------------------------------------------------------------
  alias cook_system_game_actor_initialize initialize
  def initialize(actor_id)
    cook_system_game_actor_initialize(actor_id)
    @cookmastery = {}
    @cookmastery_exp = {}
  end
end

class Scene_Map
  #--------------------------------------------------------------------------
  # ● バトルの呼び出し
  #--------------------------------------------------------------------------
  alias cook_system_call_battle call_battle
  def call_battle
    # 料理可能までのカウント減少
    if $game_party.cook_battle_count != 0
      $game_party.cook_battle_count -= 1
    end
    cook_system_call_battle
  end
end

class Window_CookMenu < Window_Selectable
  attr_reader :data
  #--------------------------------------------------------------------------
  # ● オブジェクト初期化
  #--------------------------------------------------------------------------
  def initialize
    super(0, 288, 640, 192)
    @column_max = 2
    refresh
    self.index = 0
  end
  #--------------------------------------------------------------------------
  # ● アイテムの取得
  #--------------------------------------------------------------------------
  def item
    return @data[self.index]
  end
  #--------------------------------------------------------------------------
  # ● リフレッシュ
  #--------------------------------------------------------------------------
  def refresh
    if self.contents != nil
      self.contents.dispose
      self.contents = nil
    end
    @data = $game_temp.food_data.dup
    @data.shift
    # 項目?が 0 でなければビットマップを作成し、全項目を描?
    @item_max = @data.size
    if @item_max > 0
      self.contents = Bitmap.new(width - 32, row_max * 32)
      for i in 0...@item_max
        draw_item(i)
      end
    end
  end
  #--------------------------------------------------------------------------
  # ● 項目の描?
  #     index : 項目番?
  #--------------------------------------------------------------------------
  def draw_item(index)
    item = @data[index]
    if item.cook_ok?
      self.contents.font.color = normal_color
    else
      self.contents.font.color = disabled_color
    end
    x = 4 + index % 2 * (288 + 32)
    y = index / 2 * 32
    if item.show?
      rect = Rect.new(x, y, self.width / @column_max - 32, 32)
      self.contents.fill_rect(rect, Color.new(0, 0, 0, 0))
      bitmap = RPG::Cache.icon(item.icon_name)
      opacity = self.contents.font.color == normal_color ? 255 : 128
      self.contents.blt(x, y + 4, bitmap, Rect.new(0, 0, 24, 24), opacity)
      self.contents.draw_text(x + 28, y, 212, 32, item.name, 0)
    else
      self.contents.draw_text(x + 28, y, 212, 32, "-----", 0)
    end
  end
  #--------------------------------------------------------------------------
  # ● ヘルプテキスト更新
  #--------------------------------------------------------------------------
  def update_help
    if self.item.show?
      @help_window.set_text(self.item == nil ? "" : self.item.description)
    else
      @help_window.set_text("")
    end
  end
end

class Window_FoodInfo < Window_Base
  #--------------------------------------------------------------------------
  # ● オブジェクト初期化
  #--------------------------------------------------------------------------
  def initialize
    super(0, 128, 640, 160)
    self.contents = Bitmap.new(width - 32, height - 32)
    @item = nil
  end
  #--------------------------------------------------------------------------
  # ● リフレッシュ
  #--------------------------------------------------------------------------
  def refresh
    self.contents.clear
    if @item == nil
      return
    end
    if @item.show? == false
      return
    end
    item_set = @item.recipe.keys
    need_number = []
    for i in item_set
      if i.is_a?(String)
        temp = @item.food_category(i)
        need_number.push(@item.cook_need_item_number(temp))
      else
        need_number.push(@item.cook_need_item_number(i))
      end
    end
    for i in 0...item_set.size
      x = 4 + i % 2 * (288 + 32)
      y = i / 2 * 32
      if item_set[i].is_a?(Numeric)
        now_num = $game_party.item_number(item_set[i])
        max_num = @item.recipe[item_set[i]]
        if now_num < max_num
          self.contents.font.color = disabled_color
          opacity = 128
        else
          self.contents.font.color = normal_color
          opacity = 255
        end
        item = $data_items[item_set[i]]
        name = item.name
        rect = Rect.new(x, y, self.width / 2 - 32, 32)
        self.contents.fill_rect(rect, Color.new(0, 0, 0, 0))
        bitmap = RPG::Cache.icon(item.icon_name)
        self.contents.blt(x, y + 4, bitmap, Rect.new(0, 0, 24, 24), opacity)
        self.contents.draw_text(x + 28, y, 212, 32, name, 0)
      elsif item_set[i].is_a?(String)
        now_num = need_number[i]
        max_num = @item.recipe[item_set[i]]
        if now_num < max_num
          self.contents.font.color = disabled_color
        else
          self.contents.font.color = normal_color
        end
        name = item_set[i].to_s
        self.contents.draw_text(x + 28, y, 212, 32, name, 0)
      end
      self.contents.draw_text(x + 212, y, 24, 32, max_num.to_s, 2)
      self.contents.font.color = normal_color
      self.contents.draw_text(x + 240, y, 16, 32, "/", 1)
      self.contents.draw_text(x + 256, y, 24, 32, now_num.to_s, 2)
    end
  end
  #--------------------------------------------------------------------------
  # ● アイテムの設定
  #     item : 新しいアイテム
  #--------------------------------------------------------------------------
  def item=(item)
    if @item != item
      @item = item
      refresh
    end
  end
end

class Window_CookSelect < Window_Selectable
  include Cooking_System_Config
  #--------------------------------------------------------------------------
  # ● オブジェクト初期化
  #--------------------------------------------------------------------------
  def initialize
    super(0, 288, 640, 192)
    @column_max = 2
    self.contents = Bitmap.new(width - 32, height - 32)
    if COOK_TYPE_SELECT == 1
      @data = $game_party.actors
    else
      @data = [$game_party]
    end
    @item_max = @data.size
    @cookitem = nil
    self.index = 0
  end
  #--------------------------------------------------------------------------
  # ● アクタ?取得
  #--------------------------------------------------------------------------
  def actor
    return @data[self.index]
  end
  #--------------------------------------------------------------------------
  # ● リフレッシュ
  #--------------------------------------------------------------------------
  def refresh
    self.contents.clear
    if @cookitem == nil
      return
    end
    for i in 0...@data.size
      actor = @data[i]
      x = 4 + i % 2 * (288 + 32)
      y = i / 2 * 64
      self.contents.font.color = normal_color
      if COOK_TYPE_SELECT == 1
        self.contents.draw_text(x, y, 160, 32, actor.name, 0)
      else
        self.contents.draw_text(x, y, 160, 32, "料理?行", 0)
      end
      if USE_COOK_MASTERY
        cm = actor.cookmastery[@cookitem.id]
        cm = 0 if cm == nil
        hosi = "★" * cm
        hosi2= "☆" * (MAX_COOK_MASTERY - cm)
        self.contents.draw_text(x, y+32, 320, 32, hosi+hosi2, 0)
      end
    end
  end
  #--------------------------------------------------------------------------
  # ● アイテムの設定
  #     item : 新しいアイテム
  #--------------------------------------------------------------------------
  def item=(item)
    if @cookitem != item
      @cookitem = item
      refresh
    end
  end
  #--------------------------------------------------------------------------
  # ● カ?ソルの矩形更新
  #--------------------------------------------------------------------------
  def update_cursor_rect
    if @index < 0
      self.cursor_rect.empty
    else
      x = @index % @column_max * 320
      y = @index / @column_max * 64
      self.cursor_rect.set(x, y, 160, 32)
    end
  end
end

class Window_CookResult < Window_Base
  #--------------------------------------------------------------------------
  # ● オブジェクト初期化
  #--------------------------------------------------------------------------
  def initialize
    super(80, 60, 480, 160)
    self.contents = Bitmap.new(width - 32, height - 32)
  end
  #--------------------------------------------------------------------------
  # ● リフレッシュ
  #--------------------------------------------------------------------------
  def refresh(item, success)
    self.contents.clear
    self.contents.font.color = normal_color
    self.contents.draw_text(4, 0, 64, 32, "料理", 0)
    if success
      self.contents.font.color = system_color
      str = "成功!"
    else
      self.contents.font.color = text_color(2)
      str = "失敗…"
    end
    self.contents.draw_text(4+64, 0, 96, 32, str, 0)
    self.contents.font.color = normal_color
    rect = Rect.new(4, 32, self.width - 32, 32)
    self.contents.fill_rect(rect, Color.new(0, 0, 0, 0))
    bitmap = RPG::Cache.icon(item.icon_name)
    opacity = 255
    hprate = $game_temp.temp_recover_hp_rate
    sprate = $game_temp.temp_recover_sp_rate
    hp = $game_temp.temp_recover_hp
    sp = $game_temp.temp_recover_sp
    self.contents.blt(4, 32 + 4, bitmap, Rect.new(0, 0, 24, 24), opacity)
    self.contents.draw_text(4 + 28, 32, 212, 32, item.name, 0)
    self.contents.draw_text(4 + 240, 32, 96, 32, "が完成!", 0)
    self.contents.draw_text(4, 64, 64, 32, $data_system.words.hp, 0)
    self.contents.draw_text(4 + 96, 64, 64, 32, hprate.to_s+"%", 2)
    self.contents.draw_text(4 + 160, 64, 32, 32, "+", 1)
    self.contents.draw_text(4 + 224, 64, 64, 32, hp.to_s, 2)
    self.contents.draw_text(4, 96, 64, 32, $data_system.words.sp, 0)
    self.contents.draw_text(4 + 96, 96, 64, 32, sprate.to_s+"%", 2)
    self.contents.draw_text(4 + 160, 96, 32, 32, "+", 1)
    self.contents.draw_text(4 + 224, 96, 64, 32, sp.to_s, 2)
  end
end

class Window_Use_CookItem < Window_Base
  #--------------------------------------------------------------------------
  # ● オブジェクト初期化
  #--------------------------------------------------------------------------
  def initialize
    super(80, 220, 480, 192)
    self.contents = Bitmap.new(width - 32, height - 32)
  end
  #--------------------------------------------------------------------------
  # ● リフレッシュ
  #--------------------------------------------------------------------------
  def refresh(useitem, use_add_food)
    self.contents.clear
    self.contents.font.color = normal_color
    self.contents.draw_text(4, 0, 160, 32, "使用した食材", 0)
    total_food = useitem + use_add_food
    for i in 0...total_food.size
      item = $data_items[total_food[i]]
      x = 4  + i % 2 * 240
      y = 32 + i / 2 * 32
      rect = Rect.new(x, y, self.width - 32, 32)
      self.contents.fill_rect(rect, Color.new(0, 0, 0, 0))
      bitmap = RPG::Cache.icon(item.icon_name)
      opacity = 255
      self.contents.blt(x, y + 4, bitmap, Rect.new(0, 0, 24, 24), opacity)
      if i < useitem.size
        self.contents.font.color = normal_color
      else
        self.contents.font.color = text_color(3)
      end
      self.contents.draw_text(x + 28, y, 212, 32, item.name, 0)
    end
  end
end

class Window_Add_Mate < Window_Base
  #--------------------------------------------------------------------------
  # ● オブジェクト初期化
  #--------------------------------------------------------------------------
  def initialize
    super(0, 128, 640, 160)
    self.contents = Bitmap.new(width - 32, height - 32)
  end
 
  #--------------------------------------------------------------------------
  # ● リフレッシュ
  #--------------------------------------------------------------------------
  def refresh(useitem)
    self.contents.clear
    self.contents.font.color = normal_color
    self.contents.draw_text(4, 0, 160, 32, "追加食材", 0)
    for i in 0...useitem.size
      item = $data_items[useitem[i]]
      x = 4  + i % 2 * 240
      y = 32 + i / 2 * 32
      rect = Rect.new(x, y, self.width - 32, 32)
      self.contents.fill_rect(rect, Color.new(0, 0, 0, 0))
      bitmap = RPG::Cache.icon(item.icon_name)
      opacity = 255
      self.contents.blt(x, y + 4, bitmap, Rect.new(0, 0, 24, 24), opacity)
      self.contents.draw_text(x + 28, y, 212, 32, item.name, 0)
    end
  end
end

class Scene_Cooking
  include Cooking_System_Config
  #--------------------------------------------------------------------------
  # ● メイン?理
  #--------------------------------------------------------------------------
  def main
    $game_temp.set_food_data if $game_temp.food_data == nil
    # ウィンドウを作成
    @title_window = Window_Base.new(0, 0, 640, 64)
    @title_window.contents = Bitmap.new(640 - 32, 64 - 32)
    @title_window.contents.draw_text(4, 0, 320, 32, "料理", 0)
    @main_window = Window_CookMenu.new
    @main_window.active = true
    @help_window = Window_Help.new
    @help_window.z = 110
    @help_window.y = 64
    @help_window.visible = true
    s1 = "料理?行"
    s2 = "やめる"
    command = [s1, s2]
    @select_window = Window_CookSelect.new #Window_Command.new(160, command)
    @select_window.z = 110
    @select_window.active = false
    @select_window.visible = false
    @add_mate_window = Window_Add_Mate.new
    @add_mate_window.z = 120
    @add_mate_window.visible = false
    # インフォウィンドウを作成
    @info_window = Window_FoodInfo.new
    # ヘルプウィンドウを?連付け
    @main_window.help_window = @help_window
    # トランジション?行
    Graphics.transition
    # メインル?プ
    loop do
      # ゲ?ム?面を更新
      Graphics.update
      # 入力情報を更新
      Input.update
      # フレ?ム更新
      update
      # ?面が切り替わったらル?プを中?
      if $scene != self
        break
      end
    end
    # トランジション準備
    Graphics.freeze
    # ウィンドウを解放
    @title_window.dispose
    @help_window.dispose
    @main_window.dispose
    @select_window.dispose
    @info_window.dispose
    @add_mate_window.dispose
  end
  #--------------------------------------------------------------------------
  # ● フレ?ム更新
  #--------------------------------------------------------------------------
  def update
    # ウィンドウを更新
    @help_window.update
    @main_window.update
    @select_window.update
    @info_window.update
    @add_mate_window.update
    if @result_window != nil
      update_result
      return
    end
    # メインウィンドウがアクティブの場合: update_target を呼ぶ
    if @main_window.active
      update_main
      return
    end
    # 種類ウィンドウがアクティブの場合: update_kind を呼ぶ
    if @select_window.active
      update_select
      return
    end
  end
  #--------------------------------------------------------------------------
  # ● フレ?ム更新 (選?ウィンドウがアクティブの場合)
  #--------------------------------------------------------------------------
  def update_select
    if USE_COOK_MATE_ADD and ADD_MATE_SHOW
      #追加食材ウィンドウを表示
      if @select_window.index != @select_w_last_index
        @add_mate_window.visible = true
        @select_w_last_index = @select_window.index
        add_food = actor_add_mate(@main_window.item, @select_window.actor)
        @add_mate_window.refresh(add_food)
      end
    end
    # C ボタンが押された場合
    if Input.trigger?(Input::C)
      if $game_party.cook_battle_count > 0
        # ブザ? SE を演奏
        $game_system.se_play($data_system.buzzer_se)
        return
      end
      use_item = @main_window.item.lose_item
     
      if USE_COOK_MATE_ADD
        add_food = actor_add_mate(@main_window.item, @select_window.actor)
        have_add_food = []
        for food_id in add_food
          if $game_party.item_number(food_id) > 0
            have_add_food.push(food_id)
            $game_party.lose_item(food_id, 1)
          end
        end
        result = @main_window.item.cook_effect(@select_window.actor, false, have_add_food)
      else
        result = @main_window.item.cook_effect(@select_window.actor)
      end
      if result
        $game_system.se_play(@main_window.item.cook_se)
        @result_window = Window_CookResult.new
        @result_window.refresh(@main_window.item, result)
      else
        @fail_food = FoodData.new(@main_window.item.fail_food_id)
        @fail_food.cook_effect(@select_window.actor, true)
        $game_system.se_play(@fail_food.cook_se)
        @result_window = Window_CookResult.new
        @result_window.refresh(@fail_food, result)
      end
      use_add_food = []
      if USE_COOK_MATE_ADD
        use_add_food = have_add_food
      end
      if use_item.size != 0 or use_add_food.size != 0
        @useitem_window = Window_Use_CookItem.new
        @useitem_window.refresh(use_item, use_add_food)
        @useitem_window.z = 130
      end
      @info_window.refresh
      @result_window.z = 130
      return
    end
    # B ボタンが押された場合
    if Input.trigger?(Input::B)
      # キャンセル SE を演奏
      $game_system.se_play($data_system.cancel_se)
      @main_window.active = true
      @select_window.active = false
      @select_window.visible = false
      @add_mate_window.visible = false
      @select_w_last_index = nil
      return
    end
    if USE_COOK_MATE_ADD and ADD_MATE_SHOW
      # A ボタンが押された場合
      if Input.trigger?(Input::A)
        # 決定 SE を演奏
        $game_system.se_play($data_system.decision_se)
        if @add_mate_window.visible
          @add_mate_window.visible = false
        else
          @add_mate_window.visible = true
        end
        return
      end
    end
  end
  #--------------------------------------------------------------------------
  # ● フレ?ム更新 (メインウィンドウがアクティブの場合)
  #--------------------------------------------------------------------------
  def update_main
    @info_window.item = @main_window.data[@main_window.index]
    # B ボタンが押された場合
    if Input.trigger?(Input::B)
      # キャンセル SE を演奏
      $game_system.se_play($data_system.cancel_se)
      $scene = Scene_Map.new
      return
    end
    # C ボタンが押された場合
    if Input.trigger?(Input::C)
      if @main_window.item == nil or
         @main_window.item.show? == false or
         @main_window.item.cook_ok? == false
        # ブザ? SE を演奏
        $game_system.se_play($data_system.buzzer_se)
        return
      end
      # 決定 SE を演奏
      $game_system.se_play($data_system.decision_se)
      @main_window.active = false
      @select_window.active = true
      @select_window.visible = true
      @select_window.item = @main_window.data[@main_window.index]
      @select_window.refresh
      return
    end
  end
  #--------------------------------------------------------------------------
  # ● 프레임 갱신 (결과 윈도우가 액티브의 경우)
  #--------------------------------------------------------------------------
  def update_result
    # C버튼이 밀렸을 경우
    if Input.trigger?(Input::C)
      # 결정 SE 을 연주
      $game_system.se_play($data_system.decision_se)
      @result_window.dispose
      @result_window = nil
      if @useitem_window != nil
        @useitem_window.dispose
        @useitem_window = nil
      end
      @main_window.active = true
      @main_window.refresh
      @select_window.active = false
      @select_window.visible = false
      @add_mate_window.visible = false
      @select_w_last_index = nil
      $game_party.cook_battle_count = COOK_BATTLE_COUNT
      if $game_temp.common_event_id > 0
        # 맵 화면으로 전환하고
        $scene = Scene_Map.new
        return
      end
    end
  end
  #--------------------------------------------------------------------------
  # ● 추가 식품 재료를 돌려주는
  #--------------------------------------------------------------------------
  def actor_add_mate(food, actor=nil)
    #추가 소재를 취득
    if COOK_TYPE_SELECT == 1
      if USE_ACTOR_MATE_ADD
        useitem = food.add_mate[actor.id]
      else
        useitem = food.add_mate[0]
      end 
    else
      useitem = food.add_mate[0]
    end
    return [] if useitem == nil
    return [] if useitem.size == 0
    #숙련도 기능이 사용되고 있다면 숙련도를 취득
    if USE_COOK_MASTERY
      cm = actor.cookmastery[food.id]
      cm = 0 if cm == nil
    else
      cm = 0
    end
    temp_item = []
    for i in 0..cm
      next if useitem[i] == nil
      temp_item.push(useitem[i])
    end
    return temp_item
  end
end