ALCHEMY = {} # 錬金レシピ。 # ALCHEMY[レシピ] = アイテム で指定。 # アイテムは[種別, ID]で指定し、0がアイテム、1が武器、 2が防具。 ALCHEMY[[[0,1],[0,1]]] = [0, 2] ALCHEMY[[[0,1],[0,1],[0,1]]] = [0, 3] ALCHEMY[[[0,1],[0,2]]] = [0, 3] ALCHEMY[[[0,3],[0,4],[0,4]]] = [0, 8] ALCHEMY[[[0,1],[1,1]]] = [1, 2] class Game_Party < Game_Unit attr_accessor :pot_vol alias alchemy_initialize initialize def initialize alchemy_initialize @pot_vol = 2 # 錬金壺の容量 end end #============================================================================== # ■ Window_AlchemyCategory #============================================================================== class Window_AlchemyCategory < Window_ItemCategory #-------------------------------------------------------------------------- # ● 桁数の取得 #-------------------------------------------------------------------------- def col_max; 3; end #-------------------------------------------------------------------------- # ● コマンドリストの作成 #-------------------------------------------------------------------------- def make_command_list add_command(Vocab::item, :item) add_command(Vocab::weapon, :weapon) add_command(Vocab::armor, :armor) end #-------------------------------------------------------------------------- # ● 決定やキャンセルなどのハンドリング処理 #-------------------------------------------------------------------------- def process_handling return unless open? && active return process_delete if Input.trigger?(:X) super end def process_delete if !@item_window.sub_window.items.empty? Sound.play_cancel Input.update @item_window.sub_window.delete_item @item_window.refresh else Sound.play_buzzer end end #-------------------------------------------------------------------------- # ● フレーム更新 #-------------------------------------------------------------------------- def update super @item_window.category = current_symbol if @item_window if @item_window && self.active text = "決定キーでアイテムを選択して、SHIFTキーで錬成します。\n" text += "Aキーでアイテムの選択をキャンセルできます。" @item_window.help_window.set_text(text) end end end class Window_AlchemyItem < Window_ItemList attr_reader :sub_window #-------------------------------------------------------------------------- # ● オブジェクト初期化 #-------------------------------------------------------------------------- alias alchemy_initialize initialize def initialize(x, y, width, height) alchemy_initialize(x, y, width, height) @sub_window = Window_AlchemyPot.new end def dispose super; @sub_window.dispose end #-------------------------------------------------------------------------- # ● アイテムを許可状態で表示するかどうか #-------------------------------------------------------------------------- def enable?(item); item && @sub_window.items.size < $game_party.pot_vol; end #-------------------------------------------------------------------------- # ● 決定やキャンセルなどのハンドリング処理 #-------------------------------------------------------------------------- def process_handling return unless open? && active return process_start if Input.trigger?(:A) return process_delete if Input.trigger?(:X) super end #-------------------------------------------------------------------------- # ● 決定ハンドラの呼び出し #-------------------------------------------------------------------------- def call_ok_handler @sub_window.add_item(item) activate.refresh end #-------------------------------------------------------------------------- # ● ボタンが押されたときの処理 #-------------------------------------------------------------------------- def process_start if !@sub_window.items.empty? Sound.play_ok Input.update deactivate call_handler(:start) else Sound.play_buzzer end end def process_delete if !@sub_window.items.empty? Sound.play_cancel Input.update @sub_window.delete_item refresh else Sound.play_buzzer end end end class Window_AlchemyPot < Window_Base attr_reader :items def initialize super(Graphics.width - 196, 72, 196, $game_party.pot_vol * line_height + 24) self.z = 200 clear_items end def clear_items @items = []; refresh end def refresh contents.clear @items.each_with_index{|item, index| draw_item_name(item, 0, index * line_height) } end def add_item(item) $game_party.lose_item(item, 1); @items << item; refresh end def delete_item $game_party.gain_item(@items.delete_at(@items.size - 1), 1) refresh end def alchemy_items @items.collect{|i| case i when RPG::Item; k=0; when RPG::Weapon; k=1; when RPG::Armor; k=2; end [k, i.id] }.sort end end #============================================================================== # □ Window_YesNo #============================================================================== class Window_YesNo < Window_HorzCommand #-------------------------------------------------------------------------- # ○ オブジェクト初期化 #-------------------------------------------------------------------------- def initialize(x, y) super self.width = 156; self.height = 48 add_command("はい", :yes); add_command("いいえ", :no) contents.clear; create_contents; draw_all_items end #-------------------------------------------------------------------------- # ○ 桁数の取得 #-------------------------------------------------------------------------- def col_max; 2; end end class Scene_Alchemy < Scene_Item #-------------------------------------------------------------------------- # ● カテゴリウィンドウの作成 #-------------------------------------------------------------------------- def create_category_window @category_window = Window_AlchemyCategory.new @category_window.viewport = @viewport @category_window.help_window = @help_window @category_window.y = @help_window.height @category_window.set_handler(:ok, method(:on_category_ok)) @category_window.set_handler(:cancel, method(:on_category_cancel)) end #-------------------------------------------------------------------------- # ● アイテムウィンドウの作成 #-------------------------------------------------------------------------- def create_item_window wy = @category_window.y + @category_window.height wh = Graphics.height - wy @item_window = Window_AlchemyItem.new(0, wy, Graphics.width, wh) @item_window.viewport = @viewport @item_window.help_window = @help_window @item_window.set_handler(:ok, method(:on_item_ok)) @item_window.set_handler(:cancel, method(:on_item_cancel)) @item_window.set_handler(:start, method(:on_item_start)) @category_window.item_window = @item_window text = "決定キーでアイテムを選択して、SHIFTキーで錬成します。\n" text += "Aキーでアイテムの選択をキャンセルできます。" @help_window.set_text(text) end def update_all_windows super return if !@result_window if Input.trigger?(:C) || Input.trigger?(:B) Sound.play_cancel @result_window.dispose; @result_window = nil @item_window.activate.refresh end end def on_category_cancel if @item_window.sub_window.items.empty? return_scene else @item_window.sub_window.delete_item @item_window.refresh @category_window.activate end end #-------------------------------------------------------------------------- # ● アイテム[キャンセル] #-------------------------------------------------------------------------- def on_item_cancel super text = "決定キーでアイテムを選択して、SHIFTキーで錬成します。\n" text += "Aキーでアイテムの選択をキャンセルできます。" @help_window.set_text(text) end def on_item_start @yesno_window = Window_YesNo.new(192, 180) @yesno_window.set_handler(:ok, method(:yesno_ok)) @yesno_window.set_handler(:cancel, method(:yesno_cancel)) @help_window.set_text("よろしいですか?") @yesno_window.openness = 0; @yesno_window.open; @yesno_window.z = 200 update_basic until @yesno_window.open? end def yesno_ok if @yesno_window.current_symbol == :yes @yesno_window.dispose; @yesno_window = nil @result_window = Window_Base.new(96, 180, 348, 48) @result_window.z = 200 if ALCHEMY.include?(@item_window.sub_window.alchemy_items) ai = ALCHEMY[@item_window.sub_window.alchemy_items] case ai[0] when 0; item = $data_items[ai[1]] when 1; item = $data_weapons[ai[1]] when 2; item = $data_armors[ai[1]] end $game_party.gain_item(item, 1) @item_window.sub_window.clear_items text = "#{item.name}を作成しました!" else @item_window.sub_window.items.size.times{ @item_window.sub_window.delete_item } text = "この組み合わせではアイテムを作れません!" end @result_window.draw_text(0, 0, 324, 24, text) else yesno_cancel end end def yesno_cancel @yesno_window.close; update_basic until @yesno_window.close? @yesno_window.dispose; @yesno_window = nil @item_window.activate end end