#============================================================================== # ■ XP-RGSS-68 鑑定屋[ウィンドウ] by Claimh #============================================================================== module Appraise NUM = 99 # メッセージタイプ module MesCmd M_S_C = 0 # 鑑定成功 M_N_P = 10 # お金足りない M_N_N = 12 # アイテムいっぱい end # ● 鑑定アイテム情報クラス class Item attr_reader :rate def initialize(data) @id = data[0] @rate = data[1] end def obj return $data_items[@id] end def pt_num return $game_party.item_number(@id) end def gain return $game_party.gain_item(@id, 1) end end # ● 鑑定アイテム情報クラス class Appraise attr_reader :items attr_reader :cost def initialize(id) @id = id @cost = ITEM[id][0] @items = [] for item in ITEM[id][1] @items.push(Item.new(item)) end end def enable? return ($game_party.gold >= @cost) end def obj return $data_items[@id] end def lose $game_party.lose_item(@id, 1) $game_party.lose_gold(@cost) end def appraise n = 0 for itm in @items n += itm.rate end r = rand(n) rn = 0 for itm in @items if r < (rn+itm.rate) itm.gain lose return itm.obj end rn += itm.rate end p "err. r=#{r} rn=#{rn}", @items #ここにはこないはず return nil end end end #============================================================================== # ■ Window_AppraiseCmd #============================================================================== class Window_AppraiseCmd < Window_Selectable #-------------------------------------------------------------------------- # ● オブジェクト初期化 #-------------------------------------------------------------------------- def initialize super(0, 64, 480, 64) self.contents = Bitmap.new(width - 32, height - 32) @commands = ["鑑定する", "やめる"] @item_max = @column_max = @commands.size refresh self.index = 0 end #-------------------------------------------------------------------------- # ● リフレッシュ #-------------------------------------------------------------------------- def refresh self.contents.clear for i in 0...@item_max draw_item(i) end end #-------------------------------------------------------------------------- # ● 項目の描画 # index : 項目番号 #-------------------------------------------------------------------------- def draw_item(index) x = 4 + index * self.width / @column_max self.contents.draw_text(x, 0, 300, 32, @commands[index]) end end #============================================================================== # ■ Window_AppraiseList #============================================================================== class Window_AppraiseList < Window_Selectable #-------------------------------------------------------------------------- # ● オブジェクト初期化 #-------------------------------------------------------------------------- def initialize super(0, 128, 360, 480-128) self.contents = Bitmap.new(width - 32, height - 32) data_refresh self.index = -1 end #-------------------------------------------------------------------------- # ● リスト初期化 #-------------------------------------------------------------------------- def data_refresh @data = [] key = Appraise::ITEM.keys.sort for id in key n = $game_party.item_number(id) if n > 0 for i in 0...n @data.push(Appraise::Appraise.new(id)) end end end @item_max = @data.size self.contents.dispose self.contents = Bitmap.new(width - 32, [height - 32, @item_max * 32].max) refresh self.index = @data.size - 1 if @index >= @data.size and @data.size > 0 end #-------------------------------------------------------------------------- # ● アイテム取得 #-------------------------------------------------------------------------- def data return @data[@index] end def data_i(index) return @data[index] end def enable? return false if data.nil? return data.enable? end #-------------------------------------------------------------------------- # ● リフレッシュ #-------------------------------------------------------------------------- def refresh self.contents.clear for i in 0...@item_max draw_item(i) end end #-------------------------------------------------------------------------- # ● 項目の描画 # index : 項目番号 #-------------------------------------------------------------------------- def draw_item(index) y = index * 32 item = data_i(index) enable = item.enable? self.contents.font.color.alpha = enable ? 255 : 128 draw_item_name(item.obj, 4, y, enable) self.contents.draw_text(self.contents.width-100-4, y, 100, 32, item.cost.to_s, 2) end #-------------------------------------------------------------------------- # ● アイテム名の描画 #-------------------------------------------------------------------------- def draw_item_name(item, x, y, enable=true) return if item == nil bitmap = RPG::Cache.icon(item.icon_name) self.contents.blt(x, y + 4, bitmap, Rect.new(0, 0, 24, 24), enable ? 255 : 128) self.contents.draw_text(x + 28, y, 212, 32, item.name) end #-------------------------------------------------------------------------- # ● ヘルプテキスト更新 #-------------------------------------------------------------------------- def update_help @help_window.set_text(self.data == nil ? "" : self.data.obj.description) end end #============================================================================== # ■ Window_AppraiseYN #============================================================================== class Window_AppraiseYN < Window_Selectable #-------------------------------------------------------------------------- # ● オブジェクト初期化 #-------------------------------------------------------------------------- def initialize super(360, 260, 280, 64) self.contents = Bitmap.new(width - 32, height - 32) self.z = 200 self.opacity = 0 @commands = ["はい", "いいえ"] @item_max = @column_max = @commands.size refresh disable end def enable self.visible = self.active = true self.index = 0 end def disable self.visible = self.active = false end #-------------------------------------------------------------------------- # ● リフレッシュ #-------------------------------------------------------------------------- def refresh self.contents.clear for i in 0...@item_max draw_item(i) end end #-------------------------------------------------------------------------- # ● 項目の描画 # index : 項目番号 #-------------------------------------------------------------------------- def draw_item(index) x = 4 + index * self.width / @column_max self.contents.draw_text(x, 0, 300, 32, @commands[index]) end end #============================================================================== # ■ Window_AppraiseInfo #============================================================================== class Window_AppraiseInfo < Window_Base #-------------------------------------------------------------------------- # ● オブジェクト初期化 #-------------------------------------------------------------------------- def initialize super(360, 128, 280, 480-128) self.contents = Bitmap.new(width - 32, height - 32) end #-------------------------------------------------------------------------- # ● クリア #-------------------------------------------------------------------------- def clear self.contents.clear end #-------------------------------------------------------------------------- # ● リフレッシュ #-------------------------------------------------------------------------- def refresh clear self.contents.draw_text(0, 80, self.contents.width, 32, "鑑定しますか?", 1) end end #============================================================================== # ■ Window_AppraiseCation #============================================================================== class Window_AppraiseCation < Window_Base include Appraise::MesCmd WAIT_TIME = 40 # 表示ウェイト時間[frame] FADE_F = WAIT_TIME / 4 def xx(w) return (640-w)/2 end #-------------------------------------------------------------------------- # ● オブジェクト初期化 #-------------------------------------------------------------------------- def initialize super(xx(240), 200, 240, 64) self.contents = Bitmap.new(width - 32, height - 32) @wait = 0 self.z = 600 self.visible = false end #-------------------------------------------------------------------------- # ● リフレッシュ #-------------------------------------------------------------------------- def set_text(type, item1=nil, item2=nil) return unless Appraise::MESSAGE case type when M_S_C; text = "#{item1.name}は#{item2.name}だった" when M_N_P; text = "所持金が足りません" when M_N_N; text = "これ以上、持てません" else; p "bad arg", type; return end w = self.contents.text_size(text).width self.width = w + 32 self.x = xx(self.width) self.contents.dispose self.contents = Bitmap.new(w, 32) self.contents.draw_text(0, 0, w, 32, text) @wait = WAIT_TIME self.visible = true self.opacity = self.contents_opacity = 255 end #-------------------------------------------------------------------------- # ● リフレッシュ #-------------------------------------------------------------------------- def update super @wait -= 1 if @wait < FADE_F self.opacity = self.contents_opacity = 255 / FADE_F * @wait self.visible = false if @wait == 0 end end end