#============================================================================== # ■ VXAce-RGSS3-37 調合屋 [基本クラス] by Claimh #============================================================================== module Mixture DBG = false#true # デバッグ用 ITM_MAX = 99 # メッセージタイプ module MesCmd M_S_C = 0 # 調合成功 M_N_P = 10 # お金足りない M_N_I = 11 # アイテム足りない M_N_N = 12 # アイテムいっぱい end # 条件クラス class Condition attr_reader :id # 条件ID attr_reader :num # 条件値 attr_reader :enable def initialize(prm) if prm.empty? @id = 0 @num = 0 @enable = true else @id = prm[0] @num = prm[1] end end def update_status(n=1) return (@enable = enable?(n)) end def enable?(n=1) return true if @id == 0 or @num == 0 (pt_num >= (@num*n)) end def lose(n=1) return if @id == 0 or @num == 0 $game_party.lose_item(obj, @num*n) if obj.consumable # 消耗 end def obj $data_items[@id] end def pt_num $game_party.item_number(obj) end end # 個別データクラス class MixtureData attr_writer :visible attr_reader :id attr_reader :price attr_reader :cond attr_reader :status #-------------------------------------------------------------------------- # ● オブジェクト初期化 #-------------------------------------------------------------------------- def initialize(id, mix_id, data) @id = id @mix_id = mix_id @price = data[0] @cond = data[1].collect {|d| Condition.new(d)} @visible = data[2].nil? ? false : data[2] @status = 0xFF end def size @cond.size end def obj $data_items[@id] end def num $game_party.item_number(obj) end #-------------------------------------------------------------------------- # ● 表示状態 #-------------------------------------------------------------------------- def visible (@visible or DBG) end #-------------------------------------------------------------------------- # ● ステータス更新 #-------------------------------------------------------------------------- ST_P = 0b001 ST_C = 0b010 ST_N = 0b100 def update_status(n=1) @status = 0 @status |= ST_P unless price?(n) @status |= ST_C unless @cond.each {|c| c.update_status(n)}.all? {|c| c.enable} @status |= ST_N unless num?(n) visible # @statusではなくvisibleを返す end def enable? (@status == 0) end def message return MesCmd::M_N_P if (@status & ST_P) == ST_P return MesCmd::M_N_I if (@status & ST_C) == ST_C return MesCmd::M_N_N end #-------------------------------------------------------------------------- # ● 鍛冶可否判定 #-------------------------------------------------------------------------- def cond_enable?(n=1) return true if @cond.empty? @cond.all? {|c| c.enable?(n)} end def price?(n=1) ($game_party.gold >= (@price*n)) end def num?(n=1) ((self.num + n) <= $game_party.max_item_number(obj)) end #-------------------------------------------------------------------------- # ● 調合可能最大数 #-------------------------------------------------------------------------- def enable_num return 0 unless enable? num = 1 loop do break unless price?(num) break unless cond_enable?(num) break unless num?(num) num += 1 end (num-1) end #-------------------------------------------------------------------------- # ● 調合実行 #-------------------------------------------------------------------------- def execute(n) $game_party.lose_gold(@price*n) @cond.each {|c| c.lose(n)} $game_party.gain_item(obj, n) end end # 調合リストクラス class MixtureList #-------------------------------------------------------------------------- # ● オブジェクト初期化 #-------------------------------------------------------------------------- def initialize(id) @id = id reset_all end #-------------------------------------------------------------------------- # ● オブジェクト初期化 #-------------------------------------------------------------------------- def reset_all @list = {} end #-------------------------------------------------------------------------- # ● オブジェクト初期化 #-------------------------------------------------------------------------- def reset(mix_id) @list[mix_id] = MixtureData.new(@id, mix_id, MIX[@id][mix_id]) @list[mix_id] end #-------------------------------------------------------------------------- # ● オブジェクト参照 #-------------------------------------------------------------------------- def [](mix_id) (@list[mix_id].nil? ? reset(mix_id) : @list[mix_id]) end end # アイテムリストクラス class Mixture #-------------------------------------------------------------------------- # ● オブジェクト初期化 #-------------------------------------------------------------------------- def initialize reset_all end #-------------------------------------------------------------------------- # ● オブジェクト初期化 #-------------------------------------------------------------------------- def reset_all @list = {} end #-------------------------------------------------------------------------- # ● オブジェクト初期化 #-------------------------------------------------------------------------- def reset(id) @list[id] = MixtureList.new(id) @list[id] end #-------------------------------------------------------------------------- # ● オブジェクト参照 #-------------------------------------------------------------------------- def [](id) (@list[id].nil? ? reset(id) : @list[id]) end #-------------------------------------------------------------------------- # ● リスト数 #-------------------------------------------------------------------------- def size @list.keys.size end #-------------------------------------------------------------------------- # ● リスト生成 #-------------------------------------------------------------------------- def make_list mlist = [] MIX.keys.sort.each do |id| d = self.[](id) MIX[id].keys.sort.each do |mix_id| dd = d[mix_id] next unless dd.update_status # リスト作るときにステータス更新 mlist.push(dd) end end mlist end end end ## module Mixture #============================================================================== # ■ Game_System #============================================================================== class Game_System attr_reader :mix alias initialize_mixture initialize def initialize initialize_mixture @mix = Mixture::Mixture.new end end