#============================================================================== # ■ VX-RGSS2-18 調合屋 [基本クラス] 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 return (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 return $data_items[@id] end def pt_num return $game_party.item_number(obj) end end # 個別データクラス class MixtureData attr_writer :visible 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 = [] for pp in data[1] @cond.push(Condition.new(pp)) end @visible = data[2].nil? ? false : data[2] @status = 0xFF end def id return @id end def size return @cond.size end def obj return $data_items[@id] end def num return $game_party.item_number(obj) end #-------------------------------------------------------------------------- # ● 表示状態 #-------------------------------------------------------------------------- def visible return (@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) for cnd in @cond unless cnd.update_status(n) # make cache @status |= ST_C break end end @status |= ST_N unless num?(n) return visible # @statusではなくvisibleを返す end def enable? return (@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) for cnd in @cond return false unless cnd.enable?(n) # not make cache end return true end def price?(n=1) return ($game_party.gold >= (@price*n)) end def num?(n=1) return ((self.num + n) <= ITM_MAX) 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 return (num-1) end #-------------------------------------------------------------------------- # ● 調合実行 #-------------------------------------------------------------------------- def execute(n) $game_party.lose_gold(@price*n) for cnd in @cond cnd.lose(n) end $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]) return @list[mix_id] end #-------------------------------------------------------------------------- # ● オブジェクト参照 #-------------------------------------------------------------------------- def [](mix_id) return (@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) return @list[id] end #-------------------------------------------------------------------------- # ● オブジェクト参照 #-------------------------------------------------------------------------- def [](id) return (@list[id].nil? ? reset(id) : @list[id]) end #-------------------------------------------------------------------------- # ● リスト数 #-------------------------------------------------------------------------- def size return @list.keys.size end #-------------------------------------------------------------------------- # ● リスト生成 #-------------------------------------------------------------------------- def make_list mlist = [] ids = MIX.keys.sort for id in ids d = self.[](id) mix_ids = MIX[id].keys.sort for mix_id in mix_ids dd = d[mix_id] next unless dd.update_status # リスト作るときにステータス更新 mlist.push(dd) end end return 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 #============================================================================== # ■ Game_Temp #============================================================================== class Game_Temp attr_accessor :call_mixture alias initialize_mixture initialize def initialize initialize_mixture @call_mixture = false end end #============================================================================== # ■ Game_Interpreter #============================================================================== class Game_Interpreter def call_mixture $game_temp.next_scene = "shop" $game_temp.call_mixture = true end end #============================================================================== # ■ Scene_Map #============================================================================== class Scene_Map alias call_mixture call_shop def call_shop if $game_temp.call_mixture $game_temp.next_scene = nil $game_temp.call_mixture = false $scene = Scene_Mixture.new else call_mixture end end end