# # アイテムを使った取引 #  (C)2006 TYPE74RX-T # $rx_item_price = {} #---------------設定ここから--------------- # # 以下の設定はあくまで設定例です。必要に応じて変更、増減して下さい。 # $rx_item_price["フルエリクサー"] = 1 $rx_item_price["ミスリルソード"] = 2 $rx_item_price["デクスリング"] = 4 #---------------設定ここまで--------------- # ★★★★★★★★★★★★★★システムセクション★★★★★★★★★★★★★★ #============================================================================== # ■ Game_Temp #------------------------------------------------------------------------------ #  セーブデータに含まれない、一時的なデータを扱うクラスです。このクラスのイン # スタンスは $game_temp で参照されます。 #============================================================================== class Game_Temp #-------------------------------------------------------------------------- # ● 公開インスタンス変数 #-------------------------------------------------------------------------- attr_accessor :rx_shop_flag # ★ アイテムを使ったショップ取引フラグ attr_accessor :rx_item_id # ★ 取引に使ったアイテム ID attr_accessor :rx_weapon_id # ★ 取引に使った武器 ID attr_accessor :rx_armor_id # ★ 取引に使った防具 ID attr_accessor :rx_item_pos # ★ 取引に使ったアイテムの種類 attr_accessor :rx_item_num # ★ 取引に使ったアイテムの個数 #-------------------------------------------------------------------------- # ● オブジェクト初期化 #-------------------------------------------------------------------------- alias rx_rgssc6_initialize initialize def initialize @rx_shop_flag = false @rx_item_id = 0 @rx_weapon_id = 0 @rx_armor_id = 0 @rx_item_pos = 0 @rx_item_num = 0 rx_rgssc6_initialize end end #============================================================================== # ■ Game_Party #------------------------------------------------------------------------------ #  パーティを扱うクラスです。ゴールドやアイテムなどの情報が含まれます。このク # ラスのインスタンスは $game_party で参照されます。 #============================================================================== class Game_Party #-------------------------------------------------------------------------- # ★ アイテム(武器、防具含む)の増加 (減少) # type : アイテムタイプ # id    : アイテム(武器、防具含む) ID # n : 個数 #-------------------------------------------------------------------------- def rx_gain_items(type, id, n) case type when 0 gain_item(id, n) when 1 gain_weapon(id, n) when 2 gain_armor(id, n) end end end # ★★★★★★★★★★★★★★ウインドウセクション★★★★★★★★★★★★★★ #============================================================================== # ★ Window_RXitem #------------------------------------------------------------------------------ #  取引の対象となるアイテムと個数を表示するウィンドウです。 #============================================================================== class Window_RXitem < Window_Base #-------------------------------------------------------------------------- # ● オブジェクト初期化 #-------------------------------------------------------------------------- def initialize super(0, 0, 320, 64) self.contents = Bitmap.new(width - 32, height - 32) refresh end #-------------------------------------------------------------------------- # ● リフレッシュ #-------------------------------------------------------------------------- def refresh self.contents.clear case $game_temp.rx_item_pos when 0 # アイテム # アイテム情報を取得 item = $data_items[$game_temp.rx_item_id] # 取引対象のアイテム個数を取得 $game_temp.rx_item_num = $game_party.item_number(item.id) when 1 # 武器 # アイテム情報を取得 item = $data_weapons[$game_temp.rx_weapon_id] # 取引対象のアイテム個数を取得 $game_temp.rx_item_num = $game_party.weapon_number(item.id) when 2 # 防具 # アイテム情報を取得 item = $data_armors[$game_temp.rx_armor_id] # 取引対象のアイテム個数を取得 $game_temp.rx_item_num = $game_party.armor_number(item.id) end bitmap = RPG::Cache.icon(item.icon_name) opacity = self.contents.font.color == normal_color ? 255 : 128 self.contents.blt(0, 0 + 4, bitmap, Rect.new(0, 0, 24, 24), opacity) self.contents.draw_text(28, 0, 212, 32, item.name, 0) self.contents.draw_text(240, 0, 16, 32, ":", 1) self.contents.draw_text(256, 0, 24, 32, $game_temp.rx_item_num.to_s, 2) end end #============================================================================== # ★ Window_RX_ShopCommand #------------------------------------------------------------------------------ #  ショップ画面(特殊タイプ)で、用件を選択するウィンドウです。 #============================================================================== class Window_RX_ShopCommand < Window_Selectable #-------------------------------------------------------------------------- # ● オブジェクト初期化 #-------------------------------------------------------------------------- def initialize super(0, 64, 320, 64) self.contents = Bitmap.new(width - 32, height - 32) @item_max = 2 @column_max = 2 @commands = ["交換する", "やめる"] 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 * 160 self.contents.draw_text(x, 0, 128, 32, @commands[index]) end end #============================================================================== # ★ Window_RX_ShopBuy #------------------------------------------------------------------------------ #  ショップ画面で、購入できる商品の一覧を表示するウィンドウです。 #============================================================================== class Window_RX_ShopBuy < Window_Selectable #-------------------------------------------------------------------------- # ● オブジェクト初期化 # shop_goods : 商品 #-------------------------------------------------------------------------- def initialize(shop_goods) super(0, 128, 368, 352) @shop_goods = shop_goods 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 = [] for goods_item in @shop_goods case goods_item[0] when 0 item = $data_items[goods_item[1]] when 1 item = $data_weapons[goods_item[1]] when 2 item = $data_armors[goods_item[1]] end if item != nil @data.push(item) end end # 項目数が 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] # アイテムの所持数を取得 case item when RPG::Item number = $game_party.item_number(item.id) when RPG::Weapon number = $game_party.weapon_number(item.id) when RPG::Armor number = $game_party.armor_number(item.id) end # 未設定警告(強制終了させる) if $rx_item_price[item.name] == nil print "アイテム:" + item.name + "には必要個数の設定がされていません。" exit end # 価格が所持金以下、かつ所持数が 99 でなければ通常文字色に、 # そうでなければ無効文字色に設定 if $rx_item_price[item.name] <= $game_temp.rx_item_num and number < 99 self.contents.font.color = normal_color else self.contents.font.color = disabled_color end x = 4 y = index * 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 = 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) self.contents.draw_text(x + 240, y, 88, 32, $rx_item_price[item.name].to_s, 2) end #-------------------------------------------------------------------------- # ● ヘルプテキスト更新 #-------------------------------------------------------------------------- def update_help @help_window.set_text(self.item == nil ? "" : self.item.description) end end #============================================================================== # ★ Window_ShopNumber #------------------------------------------------------------------------------ #  ショップ画面で、購入または売却するアイテムの個数を入力するウィンドウです。 #============================================================================== class Window_RX_ShopNumber < Window_Base #-------------------------------------------------------------------------- # ● オブジェクト初期化 #-------------------------------------------------------------------------- def initialize super(0, 128, 368, 352) self.contents = Bitmap.new(width - 32, height - 32) @item = nil @max = 1 @price = 0 @number = 1 end #-------------------------------------------------------------------------- # ● アイテム、最大個数、価格の設定 #-------------------------------------------------------------------------- def set(item, max) @item = item @max = max @price = $rx_item_price[item.name] @number = 1 refresh end #-------------------------------------------------------------------------- # ● 入力された個数の設定 #-------------------------------------------------------------------------- def number return @number end #-------------------------------------------------------------------------- # ● リフレッシュ #-------------------------------------------------------------------------- def refresh self.contents.clear draw_item_name(@item, 4, 96) self.contents.font.color = normal_color self.contents.draw_text(272, 96, 32, 32, "×") self.contents.draw_text(308, 96, 24, 32, @number.to_s, 2) self.cursor_rect.set(304, 96, 32, 32) # 合計価格と通貨単位を描画 domination = "個" cx = contents.text_size(domination).width total_price = @price * @number self.contents.font.color = normal_color self.contents.draw_text(4, 160, 328-cx-2, 32, total_price.to_s, 2) self.contents.font.color = system_color self.contents.draw_text(332-cx, 160, cx, 32, "個", 2) end #-------------------------------------------------------------------------- # ● フレーム更新 #-------------------------------------------------------------------------- def update super if self.active # カーソル右 (+1) if Input.repeat?(Input::RIGHT) and @number < @max $game_system.se_play($data_system.cursor_se) @number += 1 refresh end # カーソル左 (-1) if Input.repeat?(Input::LEFT) and @number > 1 $game_system.se_play($data_system.cursor_se) @number -= 1 refresh end # カーソル上 (+10) if Input.repeat?(Input::UP) and @number < @max $game_system.se_play($data_system.cursor_se) @number = [@number + 10, @max].min refresh end # カーソル下 (-10) if Input.repeat?(Input::DOWN) and @number > 1 $game_system.se_play($data_system.cursor_se) @number = [@number - 10, 1].max refresh end end end end # ★★★★★★★★★★★★★★イベントコマンドセクション★★★★★★★★★★★★★★ #============================================================================== # ■ Interpreter (分割定義 1) #------------------------------------------------------------------------------ #  イベントコマンドを実行するインタプリタです。このクラスは Game_System クラ # スや Game_Event クラスの内部で使用されます。 #============================================================================== class Interpreter #-------------------------------------------------------------------------- # ★ 注釈 #-------------------------------------------------------------------------- alias rx_pos_batch_pla_min_command_108 command_108 def command_108 # アイテム取引 if @parameters[0].include?("アイテム取引") # 初期設定 $game_temp.rx_item_id = 0 $game_temp.rx_weapon_id = 0 $game_temp.rx_armor_id = 0 $game_temp.rx_shop_flag = true rx_str = @parameters[0] rx_things = {} # 複数行にわたって設定している場合 # それらを全て変数に代入する。 i = 1 loop do # 次の行に文字列がある場合 if @list[@index+i].code == 408 rx_str += @list[@index+i].parameters[0] i += 1 else break end end # 文字列から名前と数字とに分ける rx_nam = rx_str.split(/[\d\-]+/) # 名前のみ抜き出す rx_pos = rx_str.scan(/[\d\-]+/) # 数字(-含む)のみ抜き出す # 配列変数の初期化 rx_possession = [] # 数字の文字列を数値化 for i in 0...rx_pos.size rx_possession[i] = rx_pos[i].to_i end # アイテムの種類情報を取得 $game_temp.rx_item_pos = rx_possession[0] case rx_possession[0] when 0 # アイテム # ハッシュを生成 for i in 1...$data_items.size rx_things[$data_items[i].name] = $data_items[i].id end # ID 取得処理 $game_temp.rx_item_id = rx_things[rx_nam[1]] # 継続(競合対策) return true when 1 # 武器 # ハッシュを生成 for i in 1...$data_weapons.size rx_things[$data_weapons[i].name] = $data_weapons[i].id end # ID 取得処理 $game_temp.rx_weapon_id = rx_things[rx_nam[1]] # 継続(競合対策) return true when 2 # 防具 # ハッシュを生成 for i in 1...$data_armors.size rx_things[$data_armors[i].name] = $data_armors[i].id end # ID 取得処理 $game_temp.rx_armor_id = rx_things[rx_nam[1]] # 継続(競合対策) return true end end rx_pos_batch_pla_min_command_108 end end # ★★★★★★★★★★★★★★シーンセクション★★★★★★★★★★★★★★ #============================================================================== # ■ Scene_Map #------------------------------------------------------------------------------ #  マップ画面の処理を行うクラスです。 #============================================================================== class Scene_Map #-------------------------------------------------------------------------- # ● ショップの呼び出し #-------------------------------------------------------------------------- alias rx_rgssc6_call_shop call_shop def call_shop # ★ アイテムを使ったショップ取引フラグが立っていれば特殊ショップシーンへ if $game_temp.rx_shop_flag # アイテムを使ったショップ取引フラグをクリア $game_temp.rx_shop_flag = false # ショップ呼び出しフラグをクリア $game_temp.shop_calling = false # プレイヤーの姿勢を矯正 $game_player.straighten # ショップ画面に切り替え $scene = Scene_RXshop.new return end # ショップ呼び出しフラグをクリア $game_temp.shop_calling = false # プレイヤーの姿勢を矯正 $game_player.straighten # ショップ画面に切り替え $scene = Scene_Shop.new end end #============================================================================== # ★ Scene_RXshop #------------------------------------------------------------------------------ #  ショップ画面(特殊タイプ)の処理を行うクラスです。 #============================================================================== class Scene_RXshop #-------------------------------------------------------------------------- # ● メイン処理 #-------------------------------------------------------------------------- def main case $game_temp.rx_item_pos when 0 # アイテム # アイテム情報を取得 @rx_item = $data_items[$game_temp.rx_item_id] # 取引対象のアイテム個数を取得 $game_temp.rx_item_num = $game_party.item_number(@rx_item.id) when 1 # 武器 # アイテム情報を取得 @rx_item = $data_weapons[$game_temp.rx_weapon_id] # 取引対象のアイテム個数を取得 $game_temp.rx_item_num = $game_party.weapon_number(@rx_item.id) when 2 # 防具 # アイテム情報を取得 @rx_item = $data_armors[$game_temp.rx_armor_id] # 取引対象のアイテム個数を取得 $game_temp.rx_item_num = $game_party.armor_number(@rx_item.id) end # ヘルプウィンドウを作成 @help_window = Window_Help.new # コマンドウィンドウを作成 @command_window = Window_RX_ShopCommand.new # ゴールドウィンドウを作成 @gold_window = Window_RXitem.new @gold_window.x = 320 @gold_window.y = 64 # ダミーウィンドウを作成 @dummy_window = Window_Base.new(0, 128, 640, 352) # 購入ウィンドウを作成 @buy_window = Window_RX_ShopBuy.new($game_temp.shop_goods) @buy_window.active = false @buy_window.visible = false @buy_window.help_window = @help_window # 個数入力ウィンドウを作成 @number_window = Window_RX_ShopNumber.new @number_window.active = false @number_window.visible = false # ステータスウィンドウを作成 @status_window = Window_ShopStatus.new @status_window.visible = false # トランジション実行 Graphics.transition # メインループ loop do # ゲーム画面を更新 Graphics.update # 入力情報を更新 Input.update # フレーム更新 update # 画面が切り替わったらループを中断 if $scene != self break end end # トランジション準備 Graphics.freeze # ウィンドウを解放 @help_window.dispose @command_window.dispose @gold_window.dispose @dummy_window.dispose @buy_window.dispose @number_window.dispose @status_window.dispose end #-------------------------------------------------------------------------- # ● フレーム更新 #-------------------------------------------------------------------------- def update # ウィンドウを更新 @help_window.update @command_window.update @gold_window.update @dummy_window.update @buy_window.update @number_window.update @status_window.update # コマンドウィンドウがアクティブの場合: update_command を呼ぶ if @command_window.active update_command return end # 購入ウィンドウがアクティブの場合: update_buy を呼ぶ if @buy_window.active update_buy return end # 個数入力ウィンドウがアクティブの場合: update_number を呼ぶ if @number_window.active update_number return end end #-------------------------------------------------------------------------- # ● フレーム更新 (コマンドウィンドウがアクティブの場合) #-------------------------------------------------------------------------- def update_command # 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) # コマンドウィンドウのカーソル位置で分岐 case @command_window.index when 0 # 購入する # 決定 SE を演奏 $game_system.se_play($data_system.decision_se) # ウィンドウの状態を購入モードへ @command_window.active = false @dummy_window.visible = false @buy_window.active = true @buy_window.visible = true @buy_window.refresh @status_window.visible = true when 1 # やめる # 決定 SE を演奏 $game_system.se_play($data_system.decision_se) # マップ画面に切り替え $scene = Scene_Map.new end return end end #-------------------------------------------------------------------------- # ● フレーム更新 (購入ウィンドウがアクティブの場合) #-------------------------------------------------------------------------- def update_buy # ステータスウィンドウのアイテムを設定 @status_window.item = @buy_window.item # B ボタンが押された場合 if Input.trigger?(Input::B) # キャンセル SE を演奏 $game_system.se_play($data_system.cancel_se) # ウィンドウの状態を初期モードへ @command_window.active = true @dummy_window.visible = true @buy_window.active = false @buy_window.visible = false @status_window.visible = false @status_window.item = nil # ヘルプテキストを消去 @help_window.set_text("") return end # C ボタンが押された場合 if Input.trigger?(Input::C) # アイテムを取得 @item = @buy_window.item # 未設定警告(強制終了させる) if $rx_item_price[@item.name] == nil print "アイテム:" + @item.name + "には必要個数の設定がされていません。" exit end # アイテムが無効の場合、または必要個数がアイテム所持数より上の場合 case $game_temp.rx_item_pos when 0 # アイテム if @item == nil or $rx_item_price[@item.name] > $game_party.item_number(@rx_item.id) # ブザー SE を演奏 $game_system.se_play($data_system.buzzer_se) return end when 1 # 武器 if @item == nil or $rx_item_price[@item.name] > $game_party.weapon_number(@rx_item.id) # ブザー SE を演奏 $game_system.se_play($data_system.buzzer_se) return end when 2 # 防具 if @item == nil or $rx_item_price[@item.name] > $game_party.armor_number(@rx_item.id) # ブザー SE を演奏 $game_system.se_play($data_system.buzzer_se) return end end # アイテムの所持数を取得 case @item when RPG::Item number = $game_party.item_number(@item.id) when RPG::Weapon number = $game_party.weapon_number(@item.id) when RPG::Armor number = $game_party.armor_number(@item.id) end # すでに 99 個所持している場合 if number == 99 # ブザー SE を演奏 $game_system.se_play($data_system.buzzer_se) return end # 決定 SE を演奏 $game_system.se_play($data_system.decision_se) # 最大購入可能個数を計算 case $game_temp.rx_item_pos when 0 # アイテム max = $rx_item_price[@item.name] == 0 ? 99 : $game_party.item_number(@rx_item.id) / $rx_item_price[@item.name] when 1 # 武器 max = $rx_item_price[@item.name] == 0 ? 99 : $game_party.weapon_number(@rx_item.id) / $rx_item_price[@item.name] when 2 # 防具 max = $rx_item_price[@item.name] == 0 ? 99 : $game_party.armor_number(@rx_item.id) / $rx_item_price[@item.name] end max = [max, 99 - number].min # ウィンドウの状態を個数入力モードへ @buy_window.active = false @buy_window.visible = false @number_window.set(@item, max) @number_window.active = true @number_window.visible = true end end #-------------------------------------------------------------------------- # ● フレーム更新 (個数入力ウィンドウがアクティブの場合) #-------------------------------------------------------------------------- def update_number # B ボタンが押された場合 if Input.trigger?(Input::B) # キャンセル SE を演奏 $game_system.se_play($data_system.cancel_se) # 個数入力ウィンドウを非アクティブ・不可視に設定 @number_window.active = false @number_window.visible = false # コマンドウィンドウのカーソル位置で分岐 case @command_window.index when 0 # 購入する # ウィンドウの状態を購入モードへ @buy_window.active = true @buy_window.visible = true end return end # C ボタンが押された場合 if Input.trigger?(Input::C) # ショップ SE を演奏 $game_system.se_play($data_system.shop_se) # 個数入力ウィンドウを非アクティブ・不可視に設定 @number_window.active = false @number_window.visible = false # コマンドウィンドウのカーソル位置で分岐 case @command_window.index when 0 # 購入する # 購入処理 $game_party.rx_gain_items($game_temp.rx_item_pos, @rx_item.id, @number_window.number * -$rx_item_price[@item.name]) $game_temp.rx_item_num = $game_party.item_number(@rx_item.id) case @item when RPG::Item $game_party.gain_item(@item.id, @number_window.number) when RPG::Weapon $game_party.gain_weapon(@item.id, @number_window.number) when RPG::Armor $game_party.gain_armor(@item.id, @number_window.number) end # 各ウィンドウをリフレッシュ @gold_window.refresh @buy_window.refresh @status_window.refresh # ウィンドウの状態を購入モードへ @buy_window.active = true @buy_window.visible = true when 1 # やめる # 決定 SE を演奏 $game_system.se_play($data_system.decision_se) # マップ画面に切り替え $scene = Scene_Map.new end return end end end